Skip to content

Commit

Permalink
Avoid compilation warnings about deprecated call
Browse files Browse the repository at this point in the history
As of NM 1.22
  • Loading branch information
milouse committed Aug 7, 2023
1 parent 6ae0265 commit c4dd7ff
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 54 deletions.
16 changes: 11 additions & 5 deletions src/NetworkManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,17 @@ public class Network.NetworkManager : GLib.Object {

public async void deactivate_hotspot (NM.DeviceWifi wifi_device) {
unowned NM.ActiveConnection active_connection = wifi_device.get_active_connection ();
try {
client.deactivate_connection (active_connection);
} catch (Error e) {
critical (e.message);
}
client.deactivate_connection_async.begin (
active_connection,
null,
(obj, res) => {
try {
client.deactivate_connection_async.end (res);
} catch (Error e) {
critical (e.message);
}
}
);
}

private static void set_wpa_key (NM.SettingWirelessSecurity setting, string key) {
Expand Down
56 changes: 33 additions & 23 deletions src/Views/VPNPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public class Network.VPNPage : Network.Widgets.Page {
network_manager.client.get_active_connections ().foreach ((ac) => {
if (ac.get_vpn ()) {
active_connections.add ((NM.VpnConnection) ac);
(ac as NM.VpnConnection).vpn_state_changed.connect (update);
((NM.VpnConnection)ac).vpn_state_changed.connect (update);
}
});
}
Expand All @@ -228,11 +228,16 @@ public class Network.VPNPage : Network.Widgets.Page {
unowned NetworkManager network_manager = NetworkManager.get_default ();
foreach (var ac in active_connections) {
if (ac.get_connection () == item.connection) {
try {
network_manager.client.deactivate_connection (ac);
} catch (Error e) {
warning (e.message);
}
network_manager.client.deactivate_connection_async.begin (
ac, null,
(obj, res) => {
try {
network_manager.client.deactivate_connection_async.end (res);
} catch (Error e) {
warning (e.message);
}
}
);
break;
}
}
Expand Down Expand Up @@ -296,23 +301,28 @@ public class Network.VPNPage : Network.Widgets.Page {
var selected_row = vpn_list.get_selected_row () as VPNMenuItem;
if (selected_row != null && sel_row != null) {
if (sel_row == selected_row) {
try {
selected_row.connection.delete (null);
} catch (Error e) {
warning (e.message);
var dialog = new Granite.MessageDialog (
_("Failed to remove VPN connection"),
"",
new ThemedIcon ("network-vpn"),
Gtk.ButtonsType.CLOSE
) {
badge_icon = new ThemedIcon ("dialog-error"),
transient_for = (Gtk.Window) get_toplevel ()
};
dialog.show_error_details (e.message);
dialog.run ();
dialog.destroy ();
}
selected_row.connection.delete_async.begin (
null,
(obj, res) => {
try {
selected_row.connection.delete_async.end (res);
} catch (Error e) {
warning (e.message);
var dialog = new Granite.MessageDialog (
_("Failed to remove VPN connection"),
"",
new ThemedIcon ("network-vpn"),
Gtk.ButtonsType.CLOSE
) {
badge_icon = new ThemedIcon ("dialog-error"),
transient_for = (Gtk.Window) get_toplevel ()
};
dialog.show_error_details (e.message);
dialog.run ();
dialog.destroy ();
}
}
);
} else {
warning ("Row selection changed between operations. Cancelling removal of VPN.");
GLib.Source.remove (timeout_id);
Expand Down
20 changes: 14 additions & 6 deletions src/Views/WifiPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,16 @@ namespace Network {
};
disconnect_btn.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
disconnect_btn.clicked.connect (() => {
try {
device.disconnect (null);
} catch (Error e) {
warning (e.message);
}
device.disconnect_async.begin (
null,
(obj, res) => {
try {
device.disconnect_async.end (res);
} catch (Error e) {
warning (e.message);
}
}
);
});

settings_btn = new Network.Widgets.SettingsButton.from_device (wifi_device, _("Settings…")) {
Expand Down Expand Up @@ -451,7 +456,10 @@ namespace Network {
if (active == software_locked) {
rfkill.set_software_lock (RFKillDeviceType.WLAN, !active);
unowned NetworkManager network_manager = NetworkManager.get_default ();
network_manager.client.wireless_set_enabled (active);
network_manager.client.dbus_set_property.begin (
NM.DBUS_PATH, NM.DBUS_INTERFACE, "WirelessEnabled",
active, -1, null
);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Widgets/DeviceItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ namespace Network.Widgets {
subtitle = _("Enabled (auto mode)");
status_image.icon_name = "user-available";
break;
default:
// do nothing
return;
}
}

Expand Down
17 changes: 12 additions & 5 deletions src/Widgets/Footer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ namespace Network {
unowned NetworkManager network_manager = NetworkManager.get_default ();
unowned NM.Client client = network_manager.client;
airplane_switch.notify["active"].connect (() => {
try {
client.networking_set_enabled (!airplane_switch.active);
} catch (Error e) {
warning (e.message);
}
client.dbus_call.begin (
NM.DBUS_PATH, NM.DBUS_INTERFACE, "Enable",
new GLib.Variant.tuple ({!airplane_switch.active}),
null, -1, null,
(obj, res) => {
try {
client.dbus_call.end (res);
} catch (Error e) {
warning (e.message);
}
}
);
});

if (!airplane_switch.get_active () && !client.networking_get_enabled ()) {
Expand Down
35 changes: 20 additions & 15 deletions src/Widgets/Page.vala
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,26 @@ namespace Network.Widgets {
}

if (!status_switch.active && device.get_state () == NM.DeviceState.ACTIVATED) {
try {
device.disconnect (null);
} catch (Error e) {
status_switch.active = true;

var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
_("Failed To Disconnect"),
_("Unable to disconnect from the currently connected network"),
"network-error",
Gtk.ButtonsType.CLOSE
);
message_dialog.show_error_details (e.message);
message_dialog.run ();
message_dialog.destroy ();
}
device.disconnect_async.begin (
null,
(obj, res) => {
try {
device.disconnect_async.end (res);
} catch (Error e) {
status_switch.active = true;

var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
_("Failed To Disconnect"),
_("Unable to disconnect from the currently connected network"),
"network-error",
Gtk.ButtonsType.CLOSE
);
message_dialog.show_error_details (e.message);
message_dialog.run ();
message_dialog.destroy ();
}
}
);
} else if (status_switch.active && device.get_state () == NM.DeviceState.DISCONNECTED) {
var connection = NM.SimpleConnection.new ();
var remote_array = device.get_available_connections ();
Expand Down
8 changes: 8 additions & 0 deletions src/Widgets/WifiMenuItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ public class Network.WifiMenuItem : Gtk.ListBoxRow {
case NM.DeviceState.ACTIVATED:
connect_button_revealer.reveal_child = false;
break;
default:
/* Could be a lot of various status (for now, one of:
* `DISCONNECTED', `IP_CHECK', `CONFIG', `UNKNOWN',
* `UNAVAILABLE', `IP_CONFIG', `SECONDARIES', `UNMANAGED',
* `NEED_AUTH', `DEACTIVATING'). Showing the spinner might let
* end-user try to have a look to what is going on. */
spinner.active = true;
break;
}

status_label.label = GLib.Markup.printf_escaped ("<span font_size='small'>%s</span>", state_string);
Expand Down

0 comments on commit c4dd7ff

Please sign in to comment.