1 #ifndef WIDGETS_NETWORK_HPP
2 #define WIDGETS_NETWORK_HPP
3 
4 #include <giomm/dbusproxy.h>
5 #include <giomm/dbusconnection.h>
6 #include <gtkmm/button.h>
7 #include <gtkmm/image.h>
8 #include <gtkmm/label.h>
9 
10 #include "../widget.hpp"
11 
12 using DBusConnection = Glib::RefPtr<Gio::DBus::Connection>;
13 using DBusProxy = Glib::RefPtr<Gio::DBus::Proxy>;
14 
15 using DBusPropMap = const Gio::DBus::Proxy::MapChangedProperties&;
16 using DBusPropList = const std::vector<Glib::ustring>&;
17 
18 enum WfConnectionState // NmActiveConnectionState
19 {
20     CSTATE_UNKNOWN = 0,
21     CSTATE_ACTIVATING = 1,
22     CSTATE_ACTIVATED = 2,
23     CSTATE_DEACTIVATING = 3,
24     CSTATE_DEACTIVATED = 4
25 };
26 
27 struct WfNetworkConnectionInfo
28 {
29     std::string connection_name;
30 
31     virtual void spawn_control_center(DBusProxy& nm);
32     virtual std::string get_control_center_section(DBusProxy& nm);
33 
get_connection_nameWfNetworkConnectionInfo34     virtual std::string get_connection_name() { return connection_name; }
35     virtual std::string get_icon_name(WfConnectionState state) = 0;
36     virtual int get_connection_strength() = 0;
37     virtual std::string get_ip() = 0;
38 
~WfNetworkConnectionInfoWfNetworkConnectionInfo39     virtual ~WfNetworkConnectionInfo() {}
40 };
41 
42 enum WfNetworkStatusDescription
43 {
44     NETWORK_STATUS_ICON      = 0,
45     NETWORK_STATUS_CONN_NAME = 1,
46     NETWORK_STATUS_NAME_IP   = 2
47 };
48 
49 class WayfireNetworkInfo : public WayfireWidget
50 {
51     DBusConnection connection;
52     DBusProxy nm_proxy, active_connection_proxy;
53 
54     std::unique_ptr<WfNetworkConnectionInfo> info;
55 
56     Gtk::Button button;
57     Gtk::HBox button_content;
58     Gtk::Image icon;
59     Gtk::Label status;
60 
61     bool enabled = true;
62     WfOption<int> status_opt{"panel/network_status"};
63     WfOption<int> icon_size_opt{"panel/network_icon_size"};
64     WfOption<bool> icon_invert_opt{"panel/network_icon_invert_color"};
65     WfOption<bool> status_color_opt{"panel/network_status_use_color"};
66     WfOption<std::string> status_font_opt{"panel/network_status_font"};
67 
68     bool setup_dbus();
69     void update_active_connection();
70     void on_nm_properties_changed(DBusPropMap properties,
71                                   DBusPropList invalidated);
72 
73     void on_click();
74 
75     public:
76     void update_icon();
77     void update_status();
78 
79     void init(Gtk::HBox *container);
80     void handle_config_reload();
81     virtual ~WayfireNetworkInfo();
82 };
83 
84 #endif /* end of include guard: WIDGETS_NETWORK_HPP */
85 
86