From f411d70b9fdd33bfc88d4fa458af2670e6350ae7 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Fri, 6 Jul 2018 09:38:56 +0100 Subject: [PATCH 1/4] Network applet: Port to libnm --- configure.ac | 2 +- .../applets/network@cinnamon.org/applet.js | 293 ++++++++++----------- js/misc/modemManager.js | 4 +- src/Makefile.am | 2 +- 4 files changed, 139 insertions(+), 162 deletions(-) diff --git a/configure.ac b/configure.ac index c8f251911..ade112733 100644 --- a/configure.ac +++ b/configure.ac @@ -77,7 +77,7 @@ PKG_CHECK_MODULES(CINNAMON, gio-2.0 >= $GIO_MIN_VERSION libstartup-notification-1.0 >= $STARTUP_NOTIFICATION_MIN_VERSION gobject-introspection-1.0 >= $GOBJECT_INTROSPECTION_MIN_VERSION polkit-agent-1 >= $POLKIT_MIN_VERSION xfixes - libnm-glib libnm-util atk-bridge-2.0) + libnm atk-bridge-2.0) PKG_CHECK_MODULES(CINNAMON_PERF_HELPER, gtk+-3.0 gio-2.0) diff --git a/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js b/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js index ddea51a36..c6c63646d 100644 --- a/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js +++ b/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js @@ -2,8 +2,7 @@ const Applet = imports.ui.applet; const GLib = imports.gi.GLib; const GObject = imports.gi.GObject; const Lang = imports.lang; -const NetworkManager = imports.gi.NetworkManager; -const NMClient = imports.gi.NMClient; +const NM = imports.gi.NM; const Signals = imports.signals; const St = imports.gi.St; const Mainloop = imports.mainloop; @@ -35,26 +34,14 @@ const NMAccessPointSecurity = { }; // small optimization, to avoid using [] all the time -const NM80211Mode = NetworkManager['80211Mode']; -const NM80211ApFlags = NetworkManager['80211ApFlags']; -const NM80211ApSecurityFlags = NetworkManager['80211ApSecurityFlags']; +const NM80211Mode = NM['80211Mode']; +const NM80211ApFlags = NM['80211ApFlags']; +const NM80211ApSecurityFlags = NM['80211ApSecurityFlags']; // number of wireless networks that should be visible // (the remaining are placed into More...) const NUM_VISIBLE_NETWORKS = 5; -function ssidCompare(one, two) { - if (!one || !two) - return false; - if (one.length != two.length) - return false; - for (let i = 0; i < one.length; i++) { - if (one[i] != two[i]) - return false; - } - return true; -} - // shared between NMNetworkMenuItem and NMDeviceWWAN function signalToIcon(value) { if (value > 80) @@ -76,7 +63,7 @@ function sortAccessPoints(accessPoints) { } function ssidToLabel(ssid) { - let label = NetworkManager.utils_ssid_to_utf8(ssid); + let label = NM.utils_ssid_to_utf8(ssid.get_data()); if (!label) label = _(""); return label; @@ -200,8 +187,10 @@ NMWiredSectionTitleMenuItem.prototype = { this.setToggleState(device.connected); // if this device is not controllable, hide the switch this._switch.actor.visible = device.controllable; - } else + } else { this.setStatus(''); + this._switch.actor.visible = false; + } }, activate: function(event) { @@ -386,7 +375,7 @@ NMDevice.prototype = { }, deactivate: function() { - this.device.disconnect(function() {}); + this.device.disconnect_async(null, null); }, activate: function() { @@ -397,16 +386,16 @@ NMDevice.prototype = { // pick the most recently used connection and connect to that // or if no connections ever set, create an automatic one if (this._connections.length > 0) { - this._client.activate_connection(this._connections[0].connection, this.device, null, null); + this._client.activate_connection_async(this._connections[0].connection, this.device, null, null, null); } else if (this._autoConnectionName) { let connection = this._createAutomaticConnection(); if (connection) - this._client.add_and_activate_connection(connection, this.device, null, null); + this._client.add_and_activate_connection_async(connection, this.device, null, null, null); } }, get connected() { - return this.device.state == NetworkManager.DeviceState.ACTIVATED; + return this.device.state == NM.DeviceState.ACTIVATED; }, setActiveConnection: function(activeConnection) { @@ -493,25 +482,25 @@ NMDevice.prototype = { get statusLabel(){ switch(this.device.state) { - case NetworkManager.DeviceState.DISCONNECTED: - case NetworkManager.DeviceState.ACTIVATED: + case NM.DeviceState.DISCONNECTED: + case NM.DeviceState.ACTIVATED: return null; - case NetworkManager.DeviceState.UNMANAGED: + case NM.DeviceState.UNMANAGED: /* Translators: this is for network devices that are physically present but are not under NetworkManager's control (and thus cannot be used in the menu) */ return _("unmanaged"); - case NetworkManager.DeviceState.DEACTIVATING: + case NM.DeviceState.DEACTIVATING: return _("disconnecting..."); - case NetworkManager.DeviceState.PREPARE: - case NetworkManager.DeviceState.CONFIG: - case NetworkManager.DeviceState.IP_CONFIG: - case NetworkManager.DeviceState.IP_CHECK: - case NetworkManager.DeviceState.SECONDARIES: + case NM.DeviceState.PREPARE: + case NM.DeviceState.CONFIG: + case NM.DeviceState.IP_CONFIG: + case NM.DeviceState.IP_CHECK: + case NM.DeviceState.SECONDARIES: return _("connecting..."); - case NetworkManager.DeviceState.NEED_AUTH: + case NM.DeviceState.NEED_AUTH: /* Translators: this is for network connections that require some kind of key or password */ return _("authentication required"); - case NetworkManager.DeviceState.UNAVAILABLE: + case NM.DeviceState.UNAVAILABLE: // This state is actually a compound of various states (generically unavailable, // firmware missing, carrier not available), that are exposed by different properties // (whose state may or may not updated when we receive state-changed). @@ -522,7 +511,7 @@ NMDevice.prototype = { module, which is missing */ return _("firmware missing"); } - if (this.device.capabilities & NetworkManager.DeviceCapabilities.CARRIER_DETECT) { + if (this.device.capabilities & NM.DeviceCapabilities.CARRIER_DETECT) { if (!this._carrierChangedId) this._carrierChangedId = this.device.connect('notify::carrier', Lang.bind(this, this._substateChanged)); if (!this.carrier) { @@ -533,7 +522,7 @@ NMDevice.prototype = { /* Translators: this is for a network device that cannot be activated (for example it is disabled by rfkill, or it has no coverage */ return _("unavailable"); - case NetworkManager.DeviceState.FAILED: + case NM.DeviceState.FAILED: return _("connection failed"); default: log('Device state invalid, is %d'.format(this.device.state)); @@ -543,7 +532,7 @@ NMDevice.prototype = { get controllable(){ // controllable for every state except unavailable or unmanaged - if(this.device.state === NetworkManager.DeviceState.UNAVAILABLE || this.device.state === NetworkManager.DeviceState.UNMANAGED) + if(this.device.state === NM.DeviceState.UNAVAILABLE || this.device.state === NM.DeviceState.UNMANAGED) return false; return true; @@ -575,7 +564,7 @@ NMDevice.prototype = { }, _shouldShowConnectionList: function() { - return (this.device.state >= NetworkManager.DeviceState.DISCONNECTED); + return (this.device.state >= NM.DeviceState.DISCONNECTED); }, _createSection: function() { @@ -592,7 +581,7 @@ NMDevice.prototype = { for(let j = 0; j < this._connections.length; ++j) { let obj = this._connections[j]; if (this._activeConnection && - obj.connection == this._activeConnection._connection) + obj.connection == this._activeConnection.connection) continue; obj.item = this._createConnectionItem(obj); @@ -610,7 +599,7 @@ NMDevice.prototype = { this._autoConnectionItem.connect('activate', Lang.bind(this, function() { let connection = this._createAutomaticConnection(); if (connection) - this._client.add_and_activate_connection(connection, this.device, null, null); + this._client.add_and_activate_connection_async(connection, this.device, null, null, null); })); this.section.addMenuItem(this._autoConnectionItem); } @@ -621,14 +610,14 @@ NMDevice.prototype = { let item = new PopupMenu.PopupMenuItem(obj.name); item.connect('activate', Lang.bind(this, function() { - this._client.activate_connection(connection, this.device, null, null); + this._client.activate_connection_async(connection, this.device, null, null, null); })); return item; }, _createActiveConnectionItem: function() { let title; - let active = this._activeConnection._connection; + let active = this._activeConnection.connection; if (active) { title = active._name; } else { @@ -646,11 +635,11 @@ NMDevice.prototype = { return; } - if (oldstate == NetworkManager.DeviceState.ACTIVATED) { + if (oldstate == NM.DeviceState.ACTIVATED) { this.emit('network-lost'); } - if (newstate == NetworkManager.DeviceState.FAILED) { + if (newstate == NM.DeviceState.FAILED) { this.emit('activation-failed', reason); } @@ -694,10 +683,10 @@ NMDevice.prototype = { } else { switch (this.device.get_device_type()) { - case NetworkManager.DeviceType.ETHERNET: return _("Ethernet"); - case NetworkManager.DeviceType.WIFI: return _("Wifi"); - case NetworkManager.DeviceType.MODEM: return _("Modem"); - case NetworkManager.DeviceType.BT: return _("Bluetooth"); + case NM.DeviceType.ETHERNET: return _("Ethernet"); + case NM.DeviceType.WIFI: return _("Wifi"); + case NM.DeviceType.MODEM: return _("Modem"); + case NM.DeviceType.BT: return _("Bluetooth"); default: return ""; } } @@ -748,13 +737,13 @@ NMDeviceWired.prototype = { }, _createAutomaticConnection: function() { - let connection = new NetworkManager.Connection(); - connection._uuid = NetworkManager.utils_uuid_generate(); - connection.add_setting(new NetworkManager.SettingWired()); - connection.add_setting(new NetworkManager.SettingConnection({ + let connection = new NM.SimpleConnection(); + connection._uuid = NM.utils_uuid_generate(); + connection.add_setting(new NM.SettingWired()); + connection.add_setting(new NM.SettingConnection({ uuid: connection._uuid, id: this._autoConnectionName, - type: NetworkManager.SETTING_WIRED_SETTING_NAME, + type: NM.SETTING_WIRED_SETTING_NAME, autoconnect: true })); return connection; @@ -781,26 +770,26 @@ NMDeviceModem.prototype = { try { is_wwan = true; this.mobileDevice = new ModemManager.BroadbandModem(device.udi, device.current_capabilities); - if (this._capabilities & NetworkManager.DeviceModemCapabilities.GSM_UMTS) { - this._connectionType = NetworkManager.SETTING_GSM_SETTING_NAME; - } else if (this._capabilities & NetworkManager.DeviceModemCapabilities.LTE) { - this._connectionType = NetworkManager.SETTING_GSM_SETTING_NAME; - } else if (this._capabilities & NetworkManager.DeviceModemCapabilities.CDMA_EVDO) { - this._connectionType = NetworkManager.SETTING_CDMA_SETTING_NAME; + if (this._capabilities & NM.DeviceModemCapabilities.GSM_UMTS) { + this._connectionType = NM.SETTING_GSM_SETTING_NAME; + } else if (this._capabilities & NM.DeviceModemCapabilities.LTE) { + this._connectionType = NM.SETTING_GSM_SETTING_NAME; + } else if (this._capabilities & NM.DeviceModemCapabilities.CDMA_EVDO) { + this._connectionType = NM.SETTING_CDMA_SETTING_NAME; } } catch (e){ global.logError(e); } - } else if (this._capabilities & NetworkManager.DeviceModemCapabilities.GSM_UMTS) { + } else if (this._capabilities & NM.DeviceModemCapabilities.GSM_UMTS) { is_wwan = true; this.mobileDevice = new ModemManager.ModemGsm(device.udi); - this._connectionType = NetworkManager.SETTING_GSM_SETTING_NAME; - } else if (this._capabilities & NetworkManager.DeviceModemCapabilities.CDMA_EVDO) { + this._connectionType = NM.SETTING_GSM_SETTING_NAME; + } else if (this._capabilities & NM.DeviceModemCapabilities.CDMA_EVDO) { is_wwan = true; this.mobileDevice = new ModemManager.ModemCdma(device.udi); - this._connectionType = NetworkManager.SETTING_CDMA_SETTING_NAME; - } else if (this._capabilities & NetworkManager.DeviceModemCapabilities.LTE) { + this._connectionType = NM.SETTING_CDMA_SETTING_NAME; + } else if (this._capabilities & NM.DeviceModemCapabilities.LTE) { is_wwan = true; // FIXME: support signal quality } @@ -848,7 +837,7 @@ NMDeviceModem.prototype = { }, get connected() { - return this._enabled && this.device.state == NetworkManager.DeviceState.ACTIVATED; + return this._enabled && this.device.state == NM.DeviceState.ACTIVATED; }, destroy: function() { @@ -917,13 +906,13 @@ NMDeviceBluetooth.prototype = { }, _createAutomaticConnection: function() { - let connection = new NetworkManager.Connection(); - connection._uuid = NetworkManager.utils_uuid_generate(); - connection.add_setting(new NetworkManager.SettingBluetooth()); - connection.add_setting(new NetworkManager.SettingConnection({ + let connection = new NM.SimpleConnection(); + connection._uuid = NM.utils_uuid_generate(); + connection.add_setting(new NM.SettingBluetooth()); + connection.add_setting(new NM.SettingConnection({ uuid: connection._uuid, id: this._autoConnectionName, - type: NetworkManager.SETTING_BLUETOOTH_SETTING_NAME, + type: NM.SETTING_BLUETOOTH_SETTING_NAME, autoconnect: false })); return connection; @@ -963,7 +952,7 @@ NMDeviceVPN.prototype = { }, connectionValid: function(connection) { - return connection._type == NetworkManager.SETTING_VPN_SETTING_NAME; + return connection._type == NM.SETTING_VPN_SETTING_NAME; }, get empty() { @@ -986,7 +975,7 @@ NMDeviceVPN.prototype = { deactivate: function() { if (this._activeConnection) - this._client.deactivate_connection(this._activeConnection); + this._client.deactivate_connection(this._activeConnection, null); }, statusLabel: null, @@ -1128,7 +1117,7 @@ NMDeviceWireless.prototype = { for (let i = 0; i < bestApObj.accessPoints.length; i++) { let ap = bestApObj.accessPoints[i]; if (ap.connection_valid(best)) { - this._client.activate_connection(best, this.device, ap.dbus_path, null); + this._client.activate_connection_async(best, this.device, ap.path, null, null); break; } } @@ -1142,7 +1131,7 @@ NMDeviceWireless.prototype = { if (this._networks.length > 0) { let connection = this._createAutomaticConnection(this._networks[0]); let accessPoints = sortAccessPoints(this._networks[0].accessPoints); - this._client.add_and_activate_connection(connection, this.device, accessPoints[0].dbus_path, null); + this._client.add_and_activate_connection_async(connection, this.device, accessPoints[0].path, null, null); } }, @@ -1229,7 +1218,7 @@ NMDeviceWireless.prototype = { }, _networkCompare: function(network, accessPoint) { - if (!ssidCompare(network.ssid, accessPoint.get_ssid())) + if (!network.ssid.equal (accessPoint.get_ssid())) return false; if (network.mode != accessPoint.mode) return false; @@ -1396,7 +1385,7 @@ NMDeviceWireless.prototype = { let accessPoints = sortAccessPoints(accessPointObj.accessPoints); for (let i = 0; i < accessPoints.length; i++) { if (accessPoints[i].connection_valid(connection)) { - this._client.activate_connection(connection, this.device, accessPoints[i].dbus_path, null); + this._client.activate_connection_async(connection, this.device, accessPoints[i].path, null, null); break; } } @@ -1503,8 +1492,7 @@ NMDeviceWireless.prototype = { }, _createActiveConnectionItem: function() { - if (this._activeConnection._connection) { - let connection = this._activeConnection._connection; + if (this._activeConnection.connection) { if (!this._activeNetwork) { if (this.device.active_access_point) { let networkPos = this._findNetwork(this.device.active_access_point); @@ -1520,7 +1508,7 @@ NMDeviceWireless.prototype = { if (this._activeNetwork) this._activeConnectionItem = new NMNetworkMenuItem(this._activeNetwork.accessPoints, undefined, { reactive: false }); else - this._activeConnectionItem = new PopupMenu.PopupImageMenuItem(connection._name, 'network-wireless-connected', { reactive: false }); + this._activeConnectionItem = new PopupMenu.PopupImageMenuItem(this._activeConnection.connection._name, 'network-wireless-connected', { reactive: false }); } else { // We cannot read the connection (due to ACL, or API incompatibility), but we still show signal if we have it if (this._activeNetwork) @@ -1536,25 +1524,26 @@ NMDeviceWireless.prototype = { _createAutomaticConnection: function(apObj) { let name; - let ssid = NetworkManager.utils_ssid_to_utf8(apObj.ssid); + let ssid = NM.utils_ssid_to_utf8(apObj.ssid.get_data()); if (ssid) { /* TRANSLATORS: this the automatic wireless connection name (including the network name) */ name = _("Auto %s").format(ssid); } else name = _("Auto wireless"); - let connection = new NetworkManager.Connection(); - connection.add_setting(new NetworkManager.SettingWireless()); - connection.add_setting(new NetworkManager.SettingConnection({ + let connection = new NM.SimpleConnection(); + connection.add_setting(new NM.SettingWireless()); + connection.add_setting(new NM.SettingConnection({ id: name, autoconnect: true, // NetworkManager will know to ignore this if appropriate - uuid: NetworkManager.utils_uuid_generate(), - type: NetworkManager.SETTING_WIRELESS_SETTING_NAME + uuid: NM.utils_uuid_generate(), + type: NM.SETTING_WIRELESS_SETTING_NAME })); return connection; }, _createNetworkItem: function(apObj, position) { + if(!apObj.accessPoints || apObj.accessPoints.length == 0) { // this should not happen, but I have no idea why it happens return; @@ -1578,10 +1567,10 @@ NMDeviceWireless.prototype = { // 802.1x-enabled APs require further configuration, so they're // handled in cinnamon-settings Util.spawn(['cinnamon-settings', 'network', 'connect-8021x-wifi', - this.device.get_path(), accessPoints[0].dbus_path]); + this.device.get_path(), accessPoints[0].path]); } else { let connection = this._createAutomaticConnection(apObj); - this._client.add_and_activate_connection(connection, this.device, accessPoints[0].dbus_path, null); + this._client.add_and_activate_connection_async(connection, this.device, accessPoints[0].path, null, null); } })); } @@ -1684,7 +1673,16 @@ CinnamonNetworkApplet.prototype = { this._currentIconName = undefined; this._setIcon('network-offline'); - this._client = NMClient.Client.new(); + NM.Client.new_async(null, Lang.bind(this, this._clientGot)); + } + catch (e) { + global.logError(e); + } + }, + + _clientGot: function(obj, result) { + try { + this._client = NM.Client.new_finish(result); this._statusSection = new PopupMenu.PopupMenuSection(); this._statusItem = new PopupMenu.PopupMenuItem('', { style_class: 'popup-inactive-menu-item', reactive: false }); @@ -1750,7 +1748,7 @@ CinnamonNetworkApplet.prototype = { let devices = this._devices.wireless.devices; for (let i = 0; i < devices.length; i++) { - devices[i].device.request_scan_simple(null); + devices[i].device.request_scan(null); } })); @@ -1773,42 +1771,36 @@ CinnamonNetworkApplet.prototype = { // Device types this._dtypes = { }; - this._dtypes[NetworkManager.DeviceType.ETHERNET] = NMDeviceWired; - this._dtypes[NetworkManager.DeviceType.WIFI] = NMDeviceWireless; - this._dtypes[NetworkManager.DeviceType.MODEM] = NMDeviceModem; - this._dtypes[NetworkManager.DeviceType.BT] = NMDeviceBluetooth; - // TODO: WiMax support + this._dtypes[NM.DeviceType.ETHERNET] = NMDeviceWired; + this._dtypes[NM.DeviceType.WIFI] = NMDeviceWireless; + this._dtypes[NM.DeviceType.MODEM] = NMDeviceModem; + this._dtypes[NM.DeviceType.BT] = NMDeviceBluetooth; // Connection types this._ctypes = { }; - this._ctypes[NetworkManager.SETTING_WIRELESS_SETTING_NAME] = NMConnectionCategory.WIRELESS; - this._ctypes[NetworkManager.SETTING_WIRED_SETTING_NAME] = NMConnectionCategory.WIRED; - this._ctypes[NetworkManager.SETTING_PPPOE_SETTING_NAME] = NMConnectionCategory.WIRED; - this._ctypes[NetworkManager.SETTING_PPP_SETTING_NAME] = NMConnectionCategory.WIRED; - this._ctypes[NetworkManager.SETTING_BLUETOOTH_SETTING_NAME] = NMConnectionCategory.WWAN; - this._ctypes[NetworkManager.SETTING_CDMA_SETTING_NAME] = NMConnectionCategory.WWAN; - this._ctypes[NetworkManager.SETTING_GSM_SETTING_NAME] = NMConnectionCategory.WWAN; - this._ctypes[NetworkManager.SETTING_VPN_SETTING_NAME] = NMConnectionCategory.VPN; - - this._settings = NMClient.RemoteSettings.new(null); - this._connectionsReadId = this._settings.connect('connections-read', Lang.bind(this, function() { - this._readConnections(); - this._readDevices(); - this._syncNMState(); - - // Connect to signals late so that early signals don't find in inconsistent state - // and connect only once (this signal handler can be called again if NetworkManager goes up and down) - if (!this._inited) { - this._inited = true; - this._client.connect('notify::manager-running', Lang.bind(this, this._syncNMState)); - this._client.connect('notify::networking-enabled', Lang.bind(this, this._syncNMState)); - this._client.connect('notify::state', Lang.bind(this, this._syncNMState)); - this._client.connect('notify::active-connections', Lang.bind(this, this._updateIcon)); - this._client.connect('device-added', Lang.bind(this, this._deviceAdded)); - this._client.connect('device-removed', Lang.bind(this, this._deviceRemoved)); - this._settings.connect('new-connection', Lang.bind(this, this._newConnection)); - } - })); + this._ctypes[NM.SETTING_WIRELESS_SETTING_NAME] = NMConnectionCategory.WIRELESS; + this._ctypes[NM.SETTING_WIRED_SETTING_NAME] = NMConnectionCategory.WIRED; + this._ctypes[NM.SETTING_PPPOE_SETTING_NAME] = NMConnectionCategory.WIRED; + this._ctypes[NM.SETTING_PPP_SETTING_NAME] = NMConnectionCategory.WIRED; + this._ctypes[NM.SETTING_BLUETOOTH_SETTING_NAME] = NMConnectionCategory.WWAN; + this._ctypes[NM.SETTING_CDMA_SETTING_NAME] = NMConnectionCategory.WWAN; + this._ctypes[NM.SETTING_GSM_SETTING_NAME] = NMConnectionCategory.WWAN; + this._ctypes[NM.SETTING_VPN_SETTING_NAME] = NMConnectionCategory.VPN; + + this._readConnections(); + this._readDevices(); + this._syncNMState(); + + this._client.connect('notify::nm-running', Lang.bind(this, this._syncNMState)); + this._client.connect('notify::networking-enabled', Lang.bind(this, this._syncNMState)); + this._client.connect('notify::state', Lang.bind(this, this._syncNMState)); + this._client.connect('notify::active-connections', Lang.bind(this, this._updateIcon)); + this._client.connect('device-added', Lang.bind(this, this._deviceAdded)); + this._client.connect('device-removed', Lang.bind(this, this._deviceRemoved)); + this._client.connect('connection-added', Lang.bind(this, this._connectionAdded)); + this._client.connect('connection-removed', Lang.bind(this, this._connectionRemoved)); + + this._inited = true; this._periodicUpdateIcon(); @@ -1951,7 +1943,7 @@ CinnamonNetworkApplet.prototype = { this._syncSectionTitle(wrapper.category); } else - log('Invalid network device type, is ' + device.get_device_type()); + log('Unknown network device type, is ' + device.get_device_type()); }, _deviceRemoved: function(client, device) { @@ -2009,24 +2001,12 @@ CinnamonNetworkApplet.prototype = { a._inited = true; } - if (!a._connection) { - a._connection = this._settings.get_connection_by_path(a.connection); - - if (a._connection) { - a._type = a._connection._type; - a._section = this._ctypes[a._type]; - if (a._errorLogged) { - log('network applet: Found connection for active'); - a._errorLogged = false; - } - } else { - a._connection = null; - a._type = null; - a._section = null; - if (!a._errorLogged) { - a._errorLogged = true; - log('network applet: Cannot find connection for active (or connection cannot be read)'); - } + if (!a._type) { + a._type = a.connection._type; + a._section = this._ctypes[a._type]; + if (a._errorLogged) { + log('network applet: Found connection for active'); + a._errorLogged = false; } } @@ -2036,7 +2016,7 @@ CinnamonNetworkApplet.prototype = { continue; } - if (a.state == NetworkManager.ActiveConnectionState.ACTIVATED) { + if (a.state == NM.ActiveConnectionState.ACTIVATED) { if (!default_ip4) { // We didn't find the default IPV4 device yet.. if (!default_ip6) { @@ -2051,7 +2031,7 @@ CinnamonNetworkApplet.prototype = { } } } - if (a.state == NetworkManager.ActiveConnectionState.ACTIVATING) { + if (a.state == NM.ActiveConnectionState.ACTIVATING) { activating = a; } @@ -2063,7 +2043,7 @@ CinnamonNetworkApplet.prototype = { } if (!a._primaryDevice) { - if (a._type != NetworkManager.SETTING_VPN_SETTING_NAME) { + if (a._type != NM.SETTING_VPN_SETTING_NAME) { // find a good device to be considered primary a._primaryDevice = null; let devices = a.get_devices() || [ ]; @@ -2080,7 +2060,7 @@ CinnamonNetworkApplet.prototype = { if (a._primaryDevice) a._primaryDevice.setActiveConnection(a); - if (a.state == NetworkManager.ActiveConnectionState.ACTIVATED && + if (a.state == NM.ActiveConnectionState.ACTIVATED && a._primaryDevice && a._primaryDevice._notification) { a._primaryDevice._notification.destroy(); a._primaryDevice._notification = null; @@ -2092,7 +2072,7 @@ CinnamonNetworkApplet.prototype = { }, _notifyActivated: function(activeConnection) { - if (activeConnection.state == NetworkManager.ActiveConnectionState.ACTIVATED && + if (activeConnection.state == NM.ActiveConnectionState.ACTIVATED && activeConnection._primaryDevice && activeConnection._primaryDevice._notification) { activeConnection._primaryDevice._notification.destroy(); activeConnection._primaryDevice._notification = null; @@ -2102,29 +2082,27 @@ CinnamonNetworkApplet.prototype = { }, _readConnections: function() { - let connections = this._settings.list_connections(); + let connections = this._client.get_connections(); for (let i = 0; i < connections.length; i++) { let connection = connections[i]; if (connection._uuid) { // connection was already seen (for example because NetworkManager was restarted) continue; } - connection._removedId = connection.connect('removed', Lang.bind(this, this._connectionRemoved)); - connection._updatedId = connection.connect('updated', Lang.bind(this, this._updateConnection)); + connection._updatedId = connection.connect('changed', Lang.bind(this, this._updateConnection)); this._updateConnection(connection); this._connections.push(connection); } }, - _newConnection: function(settings, connection) { + _connectionAdded: function(client, connection) { if (connection._uuid) { // connection was already seen return; } - connection._removedId = connection.connect('removed', Lang.bind(this, this._connectionRemoved)); - connection._updatedId = connection.connect('updated', Lang.bind(this, this._updateConnection)); + connection._updatedId = connection.connect('changed', Lang.bind(this, this._updateConnection)); this._updateConnection(connection); this._connections.push(connection); @@ -2132,7 +2110,7 @@ CinnamonNetworkApplet.prototype = { this._updateIcon(); }, - _connectionRemoved: function(connection) { + _connectionRemoved: function(client, connection) { let pos = this._connections.indexOf(connection); if (pos != -1) this._connections.splice(pos); @@ -2150,12 +2128,11 @@ CinnamonNetworkApplet.prototype = { } connection._uuid = null; - connection.disconnect(connection._removedId); connection.disconnect(connection._updatedId); }, _updateConnection: function(connection) { - let connectionSettings = connection.get_setting_by_name(NetworkManager.SETTING_CONNECTION_SETTING_NAME); + let connectionSettings = connection.get_setting_by_name(NM.SETTING_CONNECTION_SETTING_NAME); connection._type = connectionSettings.type; connection._section = this._ctypes[connection._type] || NMConnectionCategory.INVALID; @@ -2201,7 +2178,7 @@ CinnamonNetworkApplet.prototype = { }, _syncNMState: function() { - if (!this._client.manager_running) { + if (!this._client.nm_running) { log('NetworkManager is not running, hiding...'); this.menu.close(); this.actor.hide(); @@ -2231,7 +2208,7 @@ CinnamonNetworkApplet.prototype = { if (!mc) { this._setIcon('network-offline'); this.set_applet_tooltip(_("No connection")); - } else if (mc.state == NetworkManager.ActiveConnectionState.ACTIVATING) { + } else if (mc.state == NM.ActiveConnectionState.ACTIVATING) { new_delay = FAST_PERIODIC_UPDATE_FREQUENCY_SECONDS; switch (mc._section) { case NMConnectionCategory.WWAN: @@ -2273,7 +2250,7 @@ CinnamonNetworkApplet.prototype = { this.set_applet_tooltip(_("Connected to the wireless network")); } else { this._setIcon('network-wireless-signal-' + signalToIcon(ap.strength)); - this.set_applet_tooltip(_("Wireless connection") + ": " + ap.get_ssid() + " ("+ ap.strength +"%)"); + this.set_applet_tooltip(_("Wireless connection") + ": " + ssidToLabel(ap.get_ssid()) + " ("+ ap.strength +"%)"); } } else { log('Active connection with no primary device?'); diff --git a/js/misc/modemManager.js b/js/misc/modemManager.js index 6f95ead2a..b7d455ff3 100644 --- a/js/misc/modemManager.js +++ b/js/misc/modemManager.js @@ -2,7 +2,7 @@ const Gio = imports.gi.Gio; const Lang = imports.lang; -const NMGtk = imports.gi.NMGtk; +const NMA = imports.gi.NMA; const Signals = imports.signals; // _getMobileProvidersDatabase: @@ -14,7 +14,7 @@ let _mpd; function _getMobileProvidersDatabase() { if (_mpd == null) { try { - _mpd = new NMGtk.MobileProvidersDatabase(); + _mpd = new NMA.MobileProvidersDatabase(); _mpd.init(null); } catch (e) { log(e.message); diff --git a/src/Makefile.am b/src/Makefile.am index 9fdfe0a06..ad314d8ba 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -222,7 +222,7 @@ libcinnamon_la_LIBADD = \ libcinnamon_la_CPPFLAGS = $(cinnamon_cflags) Cinnamon-0.1.gir: libcinnamon.la St-1.0.gir -Cinnamon_0_1_gir_INCLUDES = Clutter-1.0 ClutterX11-1.0 Meta-Muffin.0 Soup-2.4 CMenu-3.0 NetworkManager-1.0 NMClient-1.0 +Cinnamon_0_1_gir_INCLUDES = Clutter-1.0 ClutterX11-1.0 Meta-Muffin.0 Soup-2.4 CMenu-3.0 NM-1.0 Cinnamon_0_1_gir_CFLAGS = $(libcinnamon_la_CPPFLAGS) -I $(srcdir) Cinnamon_0_1_gir_LIBS = libcinnamon.la Cinnamon_0_1_gir_FILES = $(libcinnamon_la_gir_sources) From 7555c8d67802abc143ed27ddee190ef567837415 Mon Sep 17 00:00:00 2001 From: ?UTF-8?q?Bj=C3=B6rn=20Esser?= Date: Fri, 6 Jul 2018 09:41:10 +0100 Subject: [PATCH 2/4] network: Support user connections --- .../applets/network@cinnamon.org/applet.js | 32 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js b/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js index c6c63646d..ca441cd58 100644 --- a/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js +++ b/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js @@ -73,6 +73,11 @@ function NMNetworkMenuItem() { this._init.apply(this, arguments); } +function default_to_private_connections(client) { + let perms = client.get_permission_result (NM.Client.ClientPermission.SETTINGS_MODIFY_SYSTEM); + return (perms != NM.Client.ClientPermissionResult.YES); +} + NMNetworkMenuItem.prototype = { __proto__: PopupMenu.PopupBaseMenuItem.prototype, @@ -740,12 +745,14 @@ NMDeviceWired.prototype = { let connection = new NM.SimpleConnection(); connection._uuid = NM.utils_uuid_generate(); connection.add_setting(new NM.SettingWired()); - connection.add_setting(new NM.SettingConnection({ + let setting_conn = new NM.SettingConnection({ uuid: connection._uuid, id: this._autoConnectionName, type: NM.SETTING_WIRED_SETTING_NAME, autoconnect: true - })); + }); + setting_conn.add_permission('user', GLib.get_user_name(), null); + connection.add_setting(setting_conn); return connection; } }; @@ -995,6 +1002,8 @@ NMDeviceWireless.prototype = { this._overflowItem = null; this._networks = [ ]; + this._client = client; + // breaking the layers with this, but cannot call // this.connectionValid until I have a device this.device = device; @@ -1533,12 +1542,27 @@ NMDeviceWireless.prototype = { let connection = new NM.SimpleConnection(); connection.add_setting(new NM.SettingWireless()); - connection.add_setting(new NM.SettingConnection({ + let setting_conn = new NM.SettingConnection({ id: name, autoconnect: true, // NetworkManager will know to ignore this if appropriate uuid: NM.utils_uuid_generate(), type: NM.SETTING_WIRELESS_SETTING_NAME - })); + }); + if (default_to_private_connections(this._client)) { + setting_conn.add_permission('user', GLib.get_user_name(), null); + if (apObj.security == NMAccessPointSecurity.WPA2_PSK || + apObj.security == NMAccessPointSecurity.WPA_PSK) { + connection.add_setting(new NM.SettingWirelessSecurity({ + psk_flags: NM.SettingSecretFlags.AGENT_OWNED + })); + } + if (apObj.security == NMAccessPointSecurity.WEP) { + connection.add_setting(new NM.SettingWirelessSecurity({ + wep_key_flags: NM.SettingSecretFlags.AGENT_OWNED + })); + } + } + connection.add_setting(setting_conn); return connection; }, From fa508106d085e48b722049570ca29554e5468fba Mon Sep 17 00:00:00 2001 From: Maximiliano Curia Date: Fri, 6 Jul 2018 09:53:10 +0100 Subject: [PATCH 3/4] Adjust Debian Control --- debian/control | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/debian/control b/debian/control index 83f743041..a7fd7413a 100644 --- a/debian/control +++ b/debian/control @@ -28,7 +28,8 @@ Build-Depends: libgudev-1.0-dev, libjson-glib-dev (>= 0.13.2), libmuffin-dev (>= 3.8), - libnm-glib-dev (>= 0.8.999), + libnm-dev (>= 1.6) [linux-any], + libnma-dev [linux-any], libpolkit-agent-1-dev (>= 0.100), libpulse-dev, librsvg2-dev, @@ -63,8 +64,8 @@ Depends: gir1.2-gtkclutter-1.0, gir1.2-keybinder-3.0, gir1.2-meta-muffin-0.0 (>= ${cinnamon:Version}), - gir1.2-networkmanager-1.0, - gir1.2-nmgtk-1.0, + gir1.2-nm-1.0 [linux-any] | gir1.2-networkmanager-1.0 [linux-any], + gir1.2-nma-1.0 [linux-any], gir1.2-notify-0.7, gir1.2-polkit-1.0, gir1.2-soup-2.4, @@ -84,7 +85,7 @@ Depends: mesa-utils, metacity, nemo (>= ${cinnamon:Version}), - network-manager-gnome, + network-manager-gnome [linux-any], policykit-1-gnome, python3, python3-dbus, From c30f921431e02a2f35e6234c5500592b46f52f4e Mon Sep 17 00:00:00 2001 From: Leigh Scott Date: Sun, 22 Jul 2018 12:58:32 +0100 Subject: [PATCH 4/4] Fix mistake --- files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js b/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js index ca441cd58..3d6015099 100644 --- a/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js +++ b/files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js @@ -74,8 +74,8 @@ function NMNetworkMenuItem() { } function default_to_private_connections(client) { - let perms = client.get_permission_result (NM.Client.ClientPermission.SETTINGS_MODIFY_SYSTEM); - return (perms != NM.Client.ClientPermissionResult.YES); + let perms = client.get_permission_result (NM.ClientPermission.SETTINGS_MODIFY_SYSTEM); + return (perms != NM.ClientPermissionResult.YES); } NMNetworkMenuItem.prototype = {