def new_connection_cb(self, path): self.init_nmobject_with_properties() conn = get_cache().getobject(path) if conn.settings_dict["connection"]['type'] == 'vpn': nm_events.emit("vpn-new-added", conn) return if conn.settings_dict["connection"]['type'] == 'pppoe': nm_events.emit("dsl-new-added", conn) return
def emit_in_time(self, *args): if args[1] != self.new_state and self.new_state != 0: if self.state_id: glib.source_remove(self.state_id) self.state_id = 0 if self.state_id > 0: return else: if self.is_dsl: #print "Debug[nmdevice]+ dsl", args, self.state_id nm_events.emit("dsl-" + args[0], args[1:]) else: #print "Debug[nmdevice]", args, self.state_id self.emit(*args) if args[1] != 100 and args[1] != 40: self.is_dsl = False self.state_id = glib.timeout_add(300, self.emit_cb) self.new_state = args[1]
def removed_cb(self): self.emit("removed", self.object_path) if self.settings_dict["connection"]["type"] == "vpn": nm_events.emit("vpn-connection-removed", None) return if self.settings_dict["connection"]["type"] == "pppoe": nm_events.emit("dsl-connection-removed", None) return nm_remote_settings = get_cache().getobject("/org/freedesktop/NetworkManager/Settings") hidden_items = dict(nm_remote_settings.cf.items('hidden')).values() if self.settings_dict["connection"]["uuid"] in hidden_items: nm_events.emit("hidden-connection-removed", None)
def removed_cb(self): self.emit("removed", self.object_path) if self.settings_dict["connection"]["type"] == "vpn": nm_events.emit("vpn-connection-removed", None) return if self.settings_dict["connection"]["type"] == "pppoe": nm_events.emit("dsl-connection-removed", None) return nm_remote_settings = get_cache().getobject( "/org/freedesktop/NetworkManager/Settings") hidden_items = dict(nm_remote_settings.cf.items('hidden')).values() if self.settings_dict["connection"]["uuid"] in hidden_items: nm_events.emit("hidden-connection-removed", None)
def vpn_state_changed_cb(self, state, reason): #print state, reason self.init_nmobject_with_properties() nm_remote_settings = get_cache().getobject("/org/freedesktop/NetworkManager/Settings") if state in [1, 2, 3, 4]: #self.emit("vpn-connecting") nm_events.emit('vpn-connecting', self.object_path) print "vpn-connecting" elif state == 5: #self.emit("vpn-connected") #print "vpn-connected" nm_events.emit('vpn-connected', self.object_path) conn_uuid = get_cache().getobject(self.object_path).get_connection().settings_dict["connection"]["uuid"] try: priority = int(nm_remote_settings.cf.getint("conn_priority", conn_uuid)) + 1 except: priority = 1 nm_remote_settings.cf.set("conn_priority", conn_uuid, priority) nm_remote_settings.cf.write(open(nm_remote_settings.config_file, "w")) #elif state == 7: #nm_events.emit('vpn-user-disconnect', self.object_path) else: nm_events.emit('vpn-disconnected', self.object_path)
def properties_changed_cb(self, prop_dict): if "ActiveConnections" in prop_dict.keys() and len(prop_dict["ActiveConnections"]) != len(self.properties["ActiveConnections"]): print TypeConvert.dbus_dictionary_2py(prop_dict)["ActiveConnections"] prop_dict = map(lambda x: get_cache().getobject(x), TypeConvert.dbus_dictionary_2py(prop_dict)["ActiveConnections"]) nm_events.emit("properties_changed", prop_dict, obj=self) self.init_nmobject_with_properties()