def clone_connection(context, name, uuid, flags="TO_DISK"): import gi gi.require_version('NM', '1.0') from gi.repository import GLib, NM main_loop = GLib.MainLoop() nm_client = NM.Client.new(None) if uuid == "random": uuid = NM.utils_uuid_generate() elif uuid == "noted": uuid = context.noted['noted-value'] elif uuid.startswith("noted."): index = uuid.replace("noted.","") uuid = context.noted[index] nm_flags = parse_NM_settings_flags_string(NM.SettingsAddConnection2Flags, flags) con2 = NM.SimpleConnection() s_con = NM.SettingConnection(type="802-3-ethernet", id=name, uuid=uuid) con2.add_setting(s_con) result = {} def _add_connection2_cb(cl, async_result, user_data): try: nm_client.add_connection2_finish(async_result) except Exception as e: result['error'] = e main_loop.quit() nm_client.add_connection2(con2.to_dbus(NM.ConnectionSerializationFlags.ALL), nm_flags, None, False, None, _add_connection2_cb, None) main_loop.run() if 'error' in result: raise Exception('add connection %s failed: %s' % (name, result['error']))
def create_connection(self): if not self.Config['apn']: self._raise_or_error_handler( NMConnectionError( 'No apn configured, make sure to configure dialup settings' )) return conn = NM.SimpleConnection() conn_id = 'blueman dun for %s' % self.device['Alias'] conn_uuid = str(uuid.uuid4()) conn_sett = NM.SettingConnection(type='bluetooth', id=conn_id, uuid=conn_uuid, autoconnect=False) conn_sett_bt = NM.SettingBluetooth(type=self.conntype, bdaddr=self.bdaddr) conn_sett_gsm = NM.SettingGsm(apn=self.Config['apn'], number=self.Config['number']) conn.add_setting(conn_sett) conn.add_setting(conn_sett_bt) conn.add_setting(conn_sett_gsm) self.client.add_connection_async(conn, True, None, self._on_connection_added, conn_uuid)
def create_connection(self): conn = NM.SimpleConnection() conn_id = '%s Network' % self.device['Name'] conn_uuid = str(uuid.uuid4()) conn_sett = NM.SettingConnection(type='bluetooth', id=conn_id, uuid=conn_uuid, autoconnect=False) conn_sett_bt = NM.SettingBluetooth(type=self.conntype, bdaddr=self.bdaddr) conn.add_setting(conn_sett) conn.add_setting(conn_sett_bt) self.client.add_connection_async(conn, True, None, self._on_connection_added, conn_uuid)
def connect_to_selection(self): model, iterator = self.get_selection().get_selected() if iterator is None: return parent = model.iter_parent(iterator) if parent: try: devid = model[parent][0] ssid = model[iterator][0] if model[iterator][1]: if not self.nm_client: self.nm_client = NM.Client.new() device = self.nm_client.get_device_by_path(devid) ap = self.find_ap(device, ssid) connection = NM.SimpleConnection() connection.add_setting(NM.SettingConnection( uuid=NM.utils_uuid_generate() )) connection.add_setting(NM.SettingWireless( ssid=ap.get_property("ssid") )) dialog = NMA.WifiDialog.new( self.nm_client, connection, device, ap, False ) dialog.connect("response", self.connect_dialog_cb) dialog.run() else: self.wifi_model.connect_to_ap(devid, ssid) except Exception as e: dialog = Gtk.MessageDialog( None, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "Failed to connect to wireless network" ) dialog.format_secondary_text("{}".format(e)) dialog.run() dialog.hide()