Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ public class Network.Indicator : Wingpanel.Indicator {
popover_widget.notify["extra-info"].connect (on_state_changed);
popover_widget.settings_shown.connect (() => { close (); });

if (is_in_session) {
display_widget.button_press_event.connect ((event) => {
if (event.button == Gdk.BUTTON_MIDDLE) {
try {
popover_widget.nm_client.networking_set_enabled (!popover_widget.nm_client.networking_get_enabled ());
return true;
} catch (Error e) {
warning ("Error setting airplane mode: %s", e.message);
}
}

return false;
});
}

update_tooltip ();
on_state_changed ();
start_monitor ();
Expand Down Expand Up @@ -96,6 +111,7 @@ public class Network.Indicator : Wingpanel.Indicator {
}

private void update_tooltip () {
var tooltip_markup = "";
switch (popover_widget.state) {
case Network.State.CONNECTING_WIRED:
/* If there's only one active ethernet connection,
Expand All @@ -107,22 +123,22 @@ public class Network.Indicator : Wingpanel.Indicator {
string active_wired_name = get_active_wired_name ();

if (active_wired_name == _("Wired")) {
display_widget.tooltip_markup = _("Connecting to wired network");
tooltip_markup = _("Connecting to wired network");
} else {
display_widget.tooltip_markup = _("Connecting to “%s”").printf (active_wired_name);
tooltip_markup = _("Connecting to “%s”").printf (active_wired_name);
}
break;
case Network.State.CONNECTING_WIFI:
case Network.State.CONNECTING_MOBILE:
display_widget.tooltip_markup = _("Connecting to “%s”").printf (get_active_wifi_name ());
tooltip_markup = _("Connecting to “%s”").printf (get_active_wifi_name ());
break;
case Network.State.CONNECTED_WIRED:
string active_wired_name = get_active_wired_name ();

if (active_wired_name == _("Wired")) {
display_widget.tooltip_markup = _("Connected to wired network");
tooltip_markup = _("Connected to wired network");
} else {
display_widget.tooltip_markup = _("Connected to “%s”").printf (active_wired_name);
tooltip_markup = _("Connected to “%s”").printf (active_wired_name);
}
break;
case Network.State.CONNECTED_WIFI_WEAK:
Expand All @@ -133,21 +149,34 @@ public class Network.Indicator : Wingpanel.Indicator {
case Network.State.CONNECTED_MOBILE_OK:
case Network.State.CONNECTED_MOBILE_GOOD:
case Network.State.CONNECTED_MOBILE_EXCELLENT:
display_widget.tooltip_markup = _("Connected to “%s”").printf (get_active_wifi_name ());
tooltip_markup = _("Connected to “%s”").printf (get_active_wifi_name ());
break;
case Network.State.FAILED:
case Network.State.FAILED_WIFI:
case Network.State.FAILED_MOBILE:
display_widget.tooltip_markup = _("Failed to connect");
tooltip_markup = _("Failed to connect");
break;
case Network.State.DISCONNECTED:
case Network.State.DISCONNECTED_AIRPLANE_MODE:
display_widget.tooltip_markup = _("Disconnected");
tooltip_markup = _("Disconnected");
break;
default:
display_widget.tooltip_markup = _("Not connected");
tooltip_markup = _("Not connected");
break;
}

if (is_in_session) {
var middle_click_markup = popover_widget.state == Network.State.DISCONNECTED_AIRPLANE_MODE ?
_("Middle-click to turn airplane mode off") :
_("Middle-click to turn airplane mode on");

display_widget.tooltip_markup = "%s\n%s".printf (
tooltip_markup,
Granite.TOOLTIP_SECONDARY_TEXT_MARKUP.printf (middle_click_markup)
);
} else {
display_widget.tooltip_markup = tooltip_markup;
}
}

private string get_active_wired_name () {
Expand Down
42 changes: 35 additions & 7 deletions src/Widgets/PopoverWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

public class Network.Widgets.PopoverWidget : Gtk.Grid {
private NM.Client nm_client;
public NM.Client nm_client { get; construct; }
private NM.VpnConnection? active_vpn_connection = null;

private GLib.List<WidgetNMInterface>? network_interface;
Expand Down Expand Up @@ -47,6 +47,38 @@ public class Network.Widgets.PopoverWidget : Gtk.Grid {
other_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
wifi_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
vpn_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);

try {
nm_client = new NM.Client ();
} catch (Error e) {
critical (e.message);
}

if (is_in_session) {
var airplane_switch = new Granite.SwitchModelButton (_("Airplane Mode"));
airplane_switch.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL);

var sep = new Gtk.Separator (Gtk.Orientation.HORIZONTAL) {
margin_top = 3,
margin_bottom = 3
};

add (airplane_switch);
add (sep);

airplane_switch.notify["active"].connect (() => {
try {
nm_client.networking_set_enabled (!airplane_switch.active);
} catch (Error e) {
warning (e.message);
}
});

if (!airplane_switch.get_active () && !nm_client.networking_get_enabled ()) {
airplane_switch.activate ();
}
}

add (other_box);
add (wifi_box);
add (vpn_box);
Expand All @@ -63,15 +95,11 @@ public class Network.Widgets.PopoverWidget : Gtk.Grid {
add (show_settings_button);

show_settings_button.clicked.connect (show_settings);
}

/* Monitor network manager */
try {
nm_client = new NM.Client ();
} catch (Error e) {
critical (e.message);

}

/* Monitor network manager */
nm_client.notify["active-connections"].connect (update_vpn_connection);

nm_client.device_added.connect (device_added_cb);
Expand Down