def on_nm_ppp_stats(self, down, up, path): if path not in self.nm_paths: props = self.bus.call_blocking("org.freedesktop.NetworkManager", path, "org.freedesktop.DBus.Properties", "GetAll", "s", ["org.freedesktop.NetworkManager.Device"]) if props["Driver"] == "bluetooth" and "rfcomm" in props["Interface"]: self.nm_paths[path] = True portid = int(props["Interface"].strip("rfcomm")) ls = rfcomm_list() for dev in ls: if dev["id"] == portid: adapter = self.Applet.Manager.get_adapter(dev["src"]) device = adapter.find_device(dev["dst"]) self.monitor_interface(NMMonitor, device, path) return else: self.nm_paths[path] = False
def on_nm_ppp_stats(self, down, up, path): if path not in self.nm_paths: props = self.bus.call_blocking("org.freedesktop.NetworkManager", path, "org.freedesktop.DBus.Properties", "GetAll", "s", ["org.freedesktop.NetworkManager.Device"]) if props["Driver"] == "bluetooth" and "rfcomm" in props["Interface"]: self.nm_paths[path] = True portid = int(props["Interface"].strip("rfcomm")) ls = rfcomm_list() for dev in ls: if dev["id"] == portid: adapter = self.Applet.Manager.get_adapter(dev["src"]) device = self.Applet.Manager.find_device(dev["dst"], adapter.get_object_path()) self.monitor_interface(NMMonitor, device, path) return else: self.nm_paths[path] = False
def on_device_disconnect(self, device): self.terminate_all_scripts(device['Address']) serial_services = [service for service in get_services(device) if service.group == 'serial'] if not serial_services: return ports = rfcomm_list() def flt(dev): if dev["dst"] == device['Address'] and dev["state"] == "connected": return dev["id"] active_ports = map(flt, ports) for port in active_ports: if not port: continue name = "/dev/rfcomm%d" % port try: dprint("Disconnecting", name) serial_services[0].disconnect(port) except Exception as e: dprint("Failed to disconnect", name) dprint(e)
def on_device_disconnect(self, device): self.terminate_all_scripts(device.Address) serial_services = [ service for service in device.get_services() if service.group == 'serial' ] if not serial_services: return ports = rfcomm_list() def flt(dev): if dev["dst"] == device.Address and dev["state"] == "connected": return dev["id"] active_ports = map(flt, ports) for port in active_ports: name = "/dev/rfcomm%d" % port try: dprint("Disconnecting", name) serial_services[0].disconnect(name) except: dprint("Failed to disconnect", name)
def on_device_disconnect(self, device): self.terminate_all_scripts(device['Address']) serial_services = [service for service in get_services(device) if service.group == 'serial'] if not serial_services: return ports = rfcomm_list() def flt(dev): if dev["dst"] == device['Address'] and dev["state"] == "connected": return dev["id"] active_ports = map(flt, ports) for port in active_ports: if port is None: continue name = "/dev/rfcomm%d" % port try: logging.info("Disconnecting %s" % name) serial_services[0].disconnect(port) except Exception: logging.error("Failed to disconnect %s" % name, exc_info=True)
def on_device_disconnect(self, device): self.terminate_all_scripts(device['Address']) serial_services = [ service for service in get_services(device) if service.group == 'serial' ] if not serial_services: return ports = rfcomm_list() def flt(dev): if dev["dst"] == device['Address'] and dev["state"] == "connected": return dev["id"] active_ports = map(flt, ports) for port in active_ports: if port is None: continue name = "/dev/rfcomm%d" % port try: logging.info("Disconnecting %s" % name) serial_services[0].disconnect(port) except Exception: logging.error("Failed to disconnect %s" % name, exc_info=True)
def on_device_disconnect(self, device): serial_services = [service for service in get_services(device) if service.group == 'serial'] if not serial_services: return active_ports = [rfcomm['id'] for rfcomm in rfcomm_list() if rfcomm['dst'] == device['Address']] for port in active_ports: name = "/dev/rfcomm%d" % port try: logging.info("Disconnecting %s" % name) serial_services[0].disconnect(port) except GLib.Error: logging.error("Failed to disconnect %s" % name, exc_info=True)
def on_device_disconnect(self, device): serial_services = [service for service in get_services(device) if isinstance(service, SerialService)] if not serial_services: return active_ports = [rfcomm['id'] for rfcomm in rfcomm_list() if rfcomm['dst'] == device['Address']] for port in active_ports: name = "/dev/rfcomm%d" % port try: logging.info(f"Disconnecting {name}") serial_services[0].disconnect(port) except GLib.Error: logging.error(f"Failed to disconnect {name}", exc_info=True)
def on_request_menu_items( self, manager_menu: ManagerDeviceMenu, device: Device) -> List[Tuple[Gtk.MenuItem, int]]: items: List[Tuple[Gtk.MenuItem, int]] = [] appl = AppletService() self.has_dun = False serial_items: List[Gtk.MenuItem] = [] def add_menu_item(manager_menu: ManagerDeviceMenu, service: Service) -> None: if service.connected: surface = self._make_x_icon(service.icon, 16) item = create_menuitem(service.name, surface=surface) item.connect("activate", manager_menu.on_disconnect, service) items.append((item, service.priority + 100)) else: item = create_menuitem(service.name, service.icon) if service.description: item.props.tooltip_text = service.description item.connect("activate", manager_menu.on_connect, service) if isinstance(service, SerialService): serial_items.append(item) if isinstance(service, DialupNetwork): self.has_dun = True else: items.append((item, service.priority)) item.props.sensitive = service.available item.show() for service in get_services(device): add_menu_item(manager_menu, service) if isinstance(service, SerialService): for dev in rfcomm_list(): if dev["dst"] == device['Address'] and dev[ "state"] == "connected": devname = _("Serial Port %s") % "rfcomm%d" % dev["id"] surface = self._make_x_icon("modem", 16) item: Gtk.MenuItem = create_menuitem(devname, surface=surface) item.connect("activate", manager_menu.on_disconnect, service, dev["id"]) items.append((item, 120)) item.show() if isinstance(service, NetworkService) and service.connected: if "DhcpClient" in appl.QueryPlugins(): def renew(_item: Gtk.MenuItem) -> None: appl.DhcpClient('(s)', device.get_object_path()) item = create_menuitem(_("Renew IP Address"), "view-refresh") item.connect("activate", renew) item.show() items.append((item, 201)) if self.has_dun and ('PPPSupport' in appl.QueryPlugins() or 'NMDUNSupport' in appl.QueryPlugins()): def open_settings(_item: Gtk.MenuItem, device: Device) -> None: from blueman.gui.GsmSettings import GsmSettings d = GsmSettings(device['Address']) d.run() d.destroy() item = Gtk.SeparatorMenuItem() item.show() serial_items.append(item) item = create_menuitem(_("Dialup Settings"), "preferences-other") serial_items.append(item) item.show() item.connect("activate", open_settings, device) if len(serial_items) > 1: sub = Gtk.Menu() sub.show() item = create_menuitem(_("Serial Ports"), "modem") item.set_submenu(sub) item.show() items.append((item, 90)) for item in serial_items: sub.append(item) else: for item in serial_items: items.append((item, 80)) return items
def on_request_menu_items(self, manager_menu, device): items = [] appl = AppletService() self.has_dun = False serial_items = [] def add_menu_item(manager_menu, service): if service.connected: item = create_menuitem(service.name, get_x_icon(service.icon, 16)) item.connect("activate", manager_menu.on_disconnect, service) items.append((item, service.priority + 100)) else: item = create_menuitem(service.name, get_icon(service.icon, 16)) if service.description: item.props.tooltip_text = service.description item.connect("activate", manager_menu.on_connect, service) if service.group == 'serial': serial_items.append(item) if isinstance(service, DialupNetwork): self.has_dun = True else: items.append((item, service.priority)) item.show() for service in get_services(device): try: add_menu_item(manager_menu, service) except Exception as e: dprint("Failed to load service %s" % service.name) traceback.print_exc() continue if service.group == 'serial': for dev in rfcomm_list(): if dev["dst"] == device['Address'] and dev["state"] == "connected": devname = _("Serial Port %s") % "rfcomm%d" % dev["id"] item = create_menuitem(devname, get_x_icon("modem", 16)) item.connect("activate", manager_menu.on_disconnect, service, dev["id"]) items.append((item, 120)) item.show() if service.group == 'network' and service.connected: if "DhcpClient" in appl.QueryPlugins(): def renew(x): appl.DhcpClient('(s)', Network(device.get_object_path()).get_properties()["Interface"]) item = create_menuitem(_("Renew IP Address"), get_icon("view-refresh", 16)) item.connect("activate", renew) item.show() items.append((item, 201)) if self.has_dun and "PPPSupport" in appl.QueryPlugins(): def open_settings(i, device): from blueman.gui.GsmSettings import GsmSettings d = GsmSettings(device['Address']) d.run() d.destroy() item = Gtk.SeparatorMenuItem() item.show() serial_items.append(item) item = create_menuitem(_("Dialup Settings"), get_icon("gtk-preferences", 16)) serial_items.append(item) item.show() item.connect("activate", open_settings, device) if len(serial_items) > 1: sub = Gtk.Menu() sub.show() item = create_menuitem(_("Serial Ports"), get_icon("modem", 16)) item.set_submenu(sub) item.show() items.append((item, 90)) for item in serial_items: sub.append(item) else: for item in serial_items: items.append((item, 80)) return items
def connected_instances(self) -> List[Instance]: return [ Instance(_("Serial Port %s") % "rfcomm%d" % dev["id"], dev["id"]) for dev in rfcomm_list() if dev["dst"] == self.device['Address'] and dev["state"] == "connected" ]
def serial_port_id(self, channel): for dev in rfcomm_list(): if dev["dst"] == self.device['Address'] and dev[ "state"] == "connected" and dev["channel"] == channel: return dev["id"]
def serial_port_id(self, channel): for dev in rfcomm_list(): if dev["dst"] == self.device['Address'] and dev["state"] == "connected" and dev["channel"] == channel: return dev["id"]
def on_request_menu_items(self, manager_menu, device): items = [] appl = AppletService() self.has_dun = False serial_items = [] def add_menu_item(manager_menu, service): if service.connected: item = create_menuitem(service.name, get_x_icon(service.icon, 16)) item.connect("activate", manager_menu.on_disconnect, service) items.append((item, service.priority + 100)) else: item = create_menuitem(service.name, get_icon(service.icon, 16)) if service.description: item.props.tooltip_text = service.description item.connect("activate", manager_menu.on_connect, service) if service.group == 'serial': serial_items.append(item) if isinstance(service, DialupNetwork): self.has_dun = True else: items.append((item, service.priority)) item.show() for service in device.get_services(): try: add_menu_item(manager_menu, service) except Exception as e: dprint("Failed to load service %s" % service.name) traceback.print_exc() continue if service.group == 'serial': for dev in rfcomm_list(): if dev["dst"] == device.Address and dev["state"] == "connected": devname = _("Serial Port %s") % "rfcomm%d" % dev["id"] item = create_menuitem(devname, get_x_icon("modem", 16)) item.connect("activate", manager_menu.on_disconnect, service, dev["id"]) items.append((item, 120)) item.show() if service.group == 'network' and service.connected: if "DhcpClient" in appl.QueryPlugins(): def renew(x): appl.DhcpClient(Network(device.get_object_path()).get_properties()["Interface"]) item = create_menuitem(_("Renew IP Address"), get_icon("view-refresh", 16)) item.connect("activate", renew) item.show() items.append((item, 201)) if self.has_dun and "PPPSupport" in appl.QueryPlugins(): def open_settings(i, device): from blueman.gui.GsmSettings import GsmSettings d = GsmSettings(device.Address) d.run() d.destroy() item = Gtk.SeparatorMenuItem() item.show() serial_items.append(item) item = create_menuitem(_("Dialup Settings"), get_icon("gtk-preferences", 16)) serial_items.append(item) item.show() item.connect("activate", open_settings, device) if len(serial_items) > 1: sub = Gtk.Menu() sub.show() item = create_menuitem(_("Serial Ports"), get_icon("modem", 16)) item.set_submenu(sub) item.show() items.append((item, 90)) for item in serial_items: sub.append(item) else: for item in serial_items: items.append((item, 80)) return items