Exemplo n.º 1
0
            def reply(ip_address):
                Notification(_("Bluetooth Network"),
                             _("Interface %(0)s bound to IP address %(1)s") % {
                                 "0": device,
                                 "1": ip_address
                             },
                             pixbuf=get_icon("network-workgroup", 48),
                             status_icon=self.Applet.Plugins.StatusIcon)

                self.quering.remove(device)
Exemplo n.º 2
0
            def reply(_obj, result, _user_data):
                logging.info(result)
                Notification(_("Bluetooth Network"),
                             _("Interface %(0)s bound to IP address %(1)s") % {
                                 "0": device,
                                 "1": result
                             },
                             icon_name="network-workgroup").show()

                self.quering.remove(device)
Exemplo n.º 3
0
    def on_connected(self, _obj: Mechanism, result: str, _user_data: None) -> None:
        rfcomm_dev = f"/dev/rfcomm{self.port:d}"
        self.reply_handler(rfcomm_dev)
        for plugin in self.parent.Plugins.get_loaded_plugins(PPPConnectedListener):
            plugin.on_ppp_connected(self.service.device, rfcomm_dev, result)

        msg = _("Successfully connected to <b>DUN</b> service on <b>%(0)s.</b>\n"
                "Network is now available through <b>%(1)s</b>") % {"0": self.service.device['Alias'], "1": result}

        Notification(_("Connected"), msg, icon_name="network-wireless-symbolic").show()
Exemplo n.º 4
0
    def _on_session_removed(self, _manager, _session_path):
        if self._silent_transfers == 0:
            return

        if self._normal_transfers == 0:
            n = Notification(_("Files received"),
                             ngettext("Received %d file in the background", "Received %d files in the background",
                                      self._silent_transfers) % self._silent_transfers,
                             **self._notify_kwargs)

            self._add_open(n, "Open Location", self._config["shared-path"])
            n.show()
        else:
            n = Notification(_("Files received"),
                             ngettext("Received %d more file in the background",
                                      "Received %d more files in the background",
                                      self._silent_transfers) % self._silent_transfers,
                             **self._notify_kwargs)
            self._add_open(n, "Open Location", self._config["shared-path"])
            n.show()
Exemplo n.º 5
0
    def _on_display_passkey(self, device: str, passkey: int, entered: int) -> None:
        logging.info(f"DisplayPasskey ({device}, {passkey:d} {entered:d})")
        dev = Device(obj_path=device)
        self._devhandlerids[device] = dev.connect_signal("property-changed", self._on_device_property_changed)

        key = f"{passkey:06}"
        notify_message = _("Pairing passkey for") + f" {self.get_device_string(device)}: " \
                                                    f"{key[:entered]}<b>{key[entered]}</b>{key[entered+1:]}"
        self._close()
        self._notification = Notification("Bluetooth", notify_message, 0, icon_name="blueman")
        self._notification.show()
Exemplo n.º 6
0
    def on_rfcomm_connected(self, service: SerialService, port: str) -> None:
        device = service.device
        if SERIAL_PORT_SVCLASS_ID == service.short_uuid:
            Notification(
                _("Serial port connected"),
                _("Serial port service on device <b>%s</b> now will be available via <b>%s</b>"
                  ) % (device['Alias'], port),
                icon_name="blueman-serial").show()

            self.call_script(device['Address'], device['Alias'], service.name,
                             service.short_uuid, port)
Exemplo n.º 7
0
    def on_rfcomm_connected(self, service, port):
        device = service.device
        if SERIAL_PORT_SVCLASS_ID == service.short_uuid:
            Notification(
                _("Serial port connected"),
                _("Serial port service on device <b>%s</b> now will be available via <b>%s</b>"
                  ) % (device['Alias'], port),
                icon_name="blueman-serial",
                pos_hint=self.Applet.Plugins.StatusIcon.geometry).show()

            self.call_script(device['Address'], device['Alias'], service.name,
                             service.short_uuid, port)
Exemplo n.º 8
0
 def reply(dev: Optional[Device] = device,
           service_name: str = ServiceUUID(uuid).name) -> None:
     assert isinstance(
         dev, Device)  # https://github.com/python/mypy/issues/2608
     Notification(
         _("Connected"),
         _("Automatically connected to %(service)s on %(device)s") %
         {
             "service": service_name,
             "device": dev["Alias"]
         },
         icon_name=dev["Icon"]).show()
Exemplo n.º 9
0
    def _on_display_pin_code(self, device: str, pin_code: str) -> None:
        logging.info(f'DisplayPinCode ({device}, {pin_code})')
        dev = Device(obj_path=device)
        self._devhandlerids[device] = dev.connect_signal(
            "property-changed", self._on_device_property_changed)

        notify_message = _("Pairing PIN code for"
                           ) + f" {self.get_device_string(device)}: {pin_code}"
        self._notification = Notification("Bluetooth",
                                          notify_message,
                                          0,
                                          icon_name="blueman")
        self._notification.show()
Exemplo n.º 10
0
    def DisplayPinCode(self, device, pin_code):
        dprint('DisplayPinCode (%s, %s)' % (device, pin_code))
        dev = Bluez.Device(device)
        self.signal_id = dev.connect_signal("property-changed",
                                            self._on_device_property_changed)

        notify_message = _("Pairing PIN code for") + " %s: %s" % (
            self.get_device_alias(device), pin_code)
        self.n = Notification("Bluetooth",
                              notify_message,
                              0,
                              pixbuf=get_icon("blueman", 48),
                              status_icon=self.status_icon)
Exemplo n.º 11
0
    def _on_display_passkey(self, device, passkey, _entered):
        logging.info('DisplayPasskey (%s, %d)' % (device, passkey))
        dev = bluez.Device(device)
        dev.connect_signal("property-changed",
                           self._on_device_property_changed)

        notify_message = _("Pairing passkey for") + " %s: %s" % (
            self.get_device_string(device), passkey)
        self.n = Notification("Bluetooth",
                              notify_message,
                              0,
                              icon_name="blueman")
        self.n.show()
Exemplo n.º 12
0
    def _on_display_passkey(self, device, passkey, _entered):
        logging.info(f"DisplayPasskey ({device}, {passkey:d})")
        dev = Device(obj_path=device)
        self._devhandlerids[device] = dev.connect_signal(
            "property-changed", self._on_device_property_changed)

        notify_message = _("Pairing passkey for"
                           ) + f" {self.get_device_string(device)}: {passkey}"
        self.n = Notification("Bluetooth",
                              notify_message,
                              0,
                              icon_name="blueman")
        self.n.show()
Exemplo n.º 13
0
    def on_connected(self, _obj, result, _user_data):
        self.reply_handler(self.port)
        self.parent.Plugins.run("on_ppp_connected", self.service.device,
                                self.port, result)

        msg = _(
            "Successfully connected to <b>DUN</b> service on <b>%(0)s.</b>\n"
            "Network is now available through <b>%(1)s</b>") % {
                "0": self.service.device['Alias'],
                "1": result
            }

        Notification(_("Connected"), msg, icon_name="network-wireless").show()
Exemplo n.º 14
0
    def on_rfcomm_connected(self, device, port, uuid):
        uuid16 = sdp_get_serial_type(device.Address, uuid)
        if SERIAL_PORT_SVCLASS_ID in uuid16:
            Notification(
                _("Serial port connected"),
                _("Serial port service on device <b>%s</b> now will be available via <b>%s</b>"
                  ) % (device.Alias, port),
                pixbuf=get_icon("blueman-serial", 48),
                status_icon=self.Applet.Plugins.StatusIcon)

            self.call_script(device.Address, device.Alias,
                             sdp_get_serial_name(device.Address, uuid), uuid16,
                             port)
Exemplo n.º 15
0
    def _on_display_pin_code(self, device, pin_code):
        logging.info('DisplayPinCode (%s, %s)' % (device, pin_code))
        dev = Device(obj_path=device)
        self._devhandlerids[device] = dev.connect_signal(
            "property-changed", self._on_device_property_changed)

        notify_message = _("Pairing PIN code for") + " %s: %s" % (
            self.get_device_string(device), pin_code)
        self.n = Notification("Bluetooth",
                              notify_message,
                              0,
                              icon_name="blueman")
        self.n.show()
Exemplo n.º 16
0
    def _on_session_removed(self, _manager, _session_path):
        if self._silent_transfers == 0:
            return

        share_path, ignored = self._make_share_path()
        if self._normal_transfers == 0:
            self._notification = Notification(_("Files received"),
                                              ngettext("Received %(files)d file in the background",
                                                       "Received %(files)d files in the background",
                                                       self._silent_transfers) % {"files": self._silent_transfers},
                                              **self._notify_kwargs)

            self._add_open(self._notification, "Open Location", share_path)
            self._notification.show()
        else:
            self._notification = Notification(_("Files received"),
                                              ngettext("Received %(files)d more file in the background",
                                                       "Received %(files)d more files in the background",
                                                       self._silent_transfers) % {"files": self._silent_transfers},
                                              **self._notify_kwargs)
            self._add_open(self._notification, "Open Location", share_path)
            self._notification.show()
Exemplo n.º 17
0
    def on_rfcomm_connected(self, service, port):
        device = service.device
        uuid16 = uuid128_to_uuid16(service.uuid)
        if SERIAL_PORT_SVCLASS_ID == uuid16:
            Notification(
                _("Serial port connected"),
                _("Serial port service on device <b>%s</b> now will be available via <b>%s</b>"
                  ) % (device.Alias, port),
                pixbuf=get_icon("blueman-serial", 48),
                status_icon=self.Applet.Plugins.StatusIcon)

            self.call_script(device.Address, device.Alias,
                             uuid16_to_name(uuid16), uuid16, port)
Exemplo n.º 18
0
    def on_device_property_changed(self, path: str, key: str,
                                   value: Any) -> None:
        device = Device(obj_path=path)
        battery = Battery(obj_path=path)

        if key == "Connected":
            if value:
                self._notifications[path] = notification = Notification(
                    device["Alias"], _('Connected'), icon_name=device["Icon"])
                notification.show()

                sig = battery.connect_signal("property-changed",
                                             self._on_battery_property_changed)

                def disconnect_signal() -> bool:
                    battery.disconnect_signal(sig)
                    return False

                GLib.timeout_add_seconds(5, disconnect_signal)
            else:
                Notification(device["Alias"],
                             _('Disconnected'),
                             icon_name=device["Icon"]).show()
Exemplo n.º 19
0
    def _on_display_passkey(self, parameters, invocation):
        device, passkey, entered = parameters.unpack()
        dprint('DisplayPasskey (%s, %d)' % (device, passkey))
        dev = Bluez.Device(device)
        self.signal_id = dev.connect_signal("property-changed",
                                            self._on_device_property_changed)

        notify_message = _("Pairing passkey for") + " %s: %s" % (
            self.get_device_alias(device), passkey)
        self.n = Notification("Bluetooth",
                              notify_message,
                              0,
                              pixbuf=get_icon("blueman", 48),
                              status_icon=self.status_icon)
Exemplo n.º 20
0
    def on_connected(self, iface):
        self.reply_handler(self.port)
        self.Applet.Plugins.Run("on_ppp_connected", self.device, self.port,
                                iface)

        Notification(
            _("Connected"),
            _("Successfully connected to <b>DUN</b> service on <b>%(0)s.</b>\nNetwork is now available through <b>%(1)s</b>"
              ) % {
                  "0": self.device.Alias,
                  "1": iface
              },
            pixbuf=get_icon("network-wireless", 48),
            status_icon=self.Applet.Plugins.StatusIcon)
Exemplo n.º 21
0
    def _on_display_passkey(self, parameters, invocation):
        device, passkey, entered = parameters.unpack()
        logging.info('DisplayPasskey (%s, %d)' % (device, passkey))
        dev = Bluez.Device(device)
        self.signal_id = dev.connect_signal("property-changed",
                                            self._on_device_property_changed)

        notify_message = _("Pairing passkey for") + " %s: %s" % (
            self.get_device_string(device), passkey)
        self.n = Notification("Bluetooth",
                              notify_message,
                              0,
                              icon_name="blueman",
                              pos_hint=self.status_icon.geometry)
        self.n.show()
Exemplo n.º 22
0
    def ask_passkey(self, dialog_msg, notify_msg, is_numeric, notification,
                    parameters, invocation):
        device_path = parameters.unpack()[0]

        def on_notification_close(n, action):
            if action != "closed":
                self.dialog.present()
            else:
                if self.dialog:
                    self.dialog.response(Gtk.ResponseType.REJECT)
                #self.applet.status_icon.set_blinking(False)

        def passkey_dialog_cb(dialog, response_id):
            if response_id == Gtk.ResponseType.ACCEPT:
                ret = pin_entry.get_text()
                if is_numeric:
                    ret = GLib.Variant('(u)', int(ret))
                invocation.return_value(GLib.Variant('(s)', (ret, )))
            else:
                invocation.return_dbus_error('org.bluez.Error.Rejected',
                                             'Rejected')
            dialog.destroy()
            self.dialog = None

        dev_str = self.get_device_string(device_path)
        notify_message = _("Pairing request for %s") % dev_str

        if self.dialog:
            logging.info("Agent: Another dialog still active, cancelling")
            invocation.return_dbus_error('org.bluez.Error.Canceled',
                                         'Canceled')

        self.dialog, pin_entry = self.build_passkey_dialog(
            dev_str, dialog_msg, is_numeric)
        if not self.dialog:
            logging.error("Agent: Failed to build dialog")
            invocation.return_dbus_error('org.bluez.Error.Canceled',
                                         'Canceled')

        if notification:
            Notification(_("Bluetooth Authentication"),
                         notify_message,
                         icon_name="blueman",
                         pos_hint=self.status_icon.geometry)
        #self.applet.status_icon.set_blinking(True)

        self.dialog.connect("response", passkey_dialog_cb)
        self.dialog.present()
Exemplo n.º 23
0
    def _on_display_pin_code(self, parameters, invocation):
        device, pin_code = parameters.unpack()
        logging.info('DisplayPinCode (%s, %s)' % (device, pin_code))
        dev = bluez.Device(device)
        self.signal_id = dev.connect_signal("property-changed",
                                            self._on_device_property_changed)

        notify_message = _("Pairing PIN code for") + " %s: %s" % (
            self.get_device_string(device), pin_code)
        self.n = Notification("Bluetooth",
                              notify_message,
                              0,
                              icon_name="blueman")
        self.n.show()

        invocation.return_value(None)
Exemplo n.º 24
0
    def _on_request_confirmation(self, device_path, passkey, ok, err):
        def on_confirm_action(action):
            if action == "confirm":
                ok()
            else:
                err(BluezErrorCanceled("User canceled pairing"))

        logging.info("Agent.RequestConfirmation")
        notify_message = _("Pairing request for:") + "\n%s" % self.get_device_string(device_path)

        if passkey:
            notify_message += "\n" + _("Confirm value for authentication:") + " <b>%s</b>" % passkey
        actions = [["confirm", _("Confirm")], ["deny", _("Deny")]]

        self.n = Notification("Bluetooth", notify_message, 0, actions, on_confirm_action, icon_name="blueman")
        self.n.show()
Exemplo n.º 25
0
    def call_script(self, address, name, sv_name, uuid16, node):
        c = self.get_option("script")
        if c and c != "":
            args = c.split(" ")
            try:
                args += [address, name, sv_name, "%s" % hex(uuid16), node]
                dprint(args)
                p = Popen(args, preexec_fn=lambda: os.setpgid(0, 0))

                self.manage_script(address, node, p)

            except Exception as e:
                Notification(_("Serial port connection script failed"),
                             _("There was a problem launching script %s\n"
                               "%s") % (c, str(e)),
                             pixbuf=get_icon("blueman-serial", 48),
                             status_icon=self.Applet.Plugins.StatusIcon)
Exemplo n.º 26
0
    def RequestConfirmation(self, device, passkey, ok, err):
        def on_confirm_action(n, action):
            #self.applet.status_icon.set_blinking(False)
            if action == "confirm":
                ok()
            else:
                err(AgentErrorRejected())

        dprint("Agent.RequestConfirmation")
        alias = self.get_device_alias(device)
        notify_message = (_("Pairing request for:") + "\n%s\n" + _(
            "Confirm value for authentication:") + " <b>%s</b>") % (alias, passkey)
        actions = [["confirm", _("Confirm"), "gtk-yes"], ["deny", _("Deny"), "gtk-no"]]

        Notification("Bluetooth", notify_message, 0,
                     actions, on_confirm_action,
                     pixbuf=get_icon("blueman", 48), status_icon=self.status_icon)
Exemplo n.º 27
0
    def call_script(self, address, name, sv_name, uuid16, node):
        c = self.get_option("script")
        if c and c != "":
            args = c.split(" ")
            try:
                args += [address, name, sv_name, "%s" % hex(uuid16), node]
                logging.debug(" ".join(args))
                p = Popen(args, preexec_fn=lambda: os.setpgid(0, 0))

                self.manage_script(address, node, p)

            except Exception as e:
                logging.debug(str(e))
                Notification(_("Serial port connection script failed"),
                             _("There was a problem launching script %s\n"
                               "%s") % (c, str(e)),
                             icon_name="blueman-serial").show()
Exemplo n.º 28
0
    def _on_request_confirmation(self, device_path: str, passkey: Optional[int], ok: Callable[[], None],
                                 err: Callable[[BluezErrorCanceled], None]) -> None:
        def on_confirm_action(action: str) -> None:
            if action == "confirm":
                ok()
            else:
                err(BluezErrorCanceled("User canceled pairing"))

        logging.info("Agent.RequestConfirmation")
        notify_message = _("Pairing request for:") + f"\n{self.get_device_string(device_path)}"

        if passkey:
            notify_message += "\n" + _("Confirm value for authentication:") + f" <b>{passkey:06}</b>"
        actions = [("confirm", _("Confirm")), ("deny", _("Deny"))]

        self._notification = Notification("Bluetooth", notify_message, 0, actions, on_confirm_action,
                                          icon_name="blueman")
        self._notification.show()
Exemplo n.º 29
0
    def ask_passkey(self, device_path, dialog_msg, notify_msg, is_numeric,
                    notification, ok, err):
        def on_notification_close(n, action):
            if action != "closed":
                self.dialog.present()
            else:
                if self.dialog:
                    self.dialog.response(Gtk.ResponseType.REJECT)
                #self.applet.status_icon.set_blinking(False)

        def passkey_dialog_cb(dialog, response_id):
            if response_id == Gtk.ResponseType.ACCEPT:
                ret = pin_entry.get_text()
                if is_numeric:
                    ret = int(ret)
                ok(ret)
            else:
                err(AgentErrorRejected())
            dialog.destroy()
            self.dialog = None

        alias = self.get_device_alias(device_path)
        notify_message = _("Pairing request for %s") % (alias)

        if self.dialog:
            dprint("Agent: Another dialog still active, cancelling")
            err(AgentErrorCanceled())

        self.dialog, pin_entry = self.build_passkey_dialog(
            alias, dialog_msg, is_numeric)
        if not self.dialog:
            dprint("Agent: Failed to build dialog")
            err(AgentErrorCanceled())

        if notification:
            Notification(_("Bluetooth Authentication"),
                         notify_message,
                         pixbuf=get_icon("blueman", 48),
                         status_icon=self.status_icon)
        #self.applet.status_icon.set_blinking(True)

        self.dialog.connect("response", passkey_dialog_cb)
        self.dialog.present()
Exemplo n.º 30
0
    def dhcp_acquire(self, object_path: str) -> None:
        device = Network(obj_path=object_path)["Interface"]

        if device not in self.quering:
            self.quering.append(device)
        else:
            return

        if device != "":

            def reply(_obj: Mechanism, result: str, _user_data: None) -> None:
                logging.info(result)
                Notification(_("Bluetooth Network"),
                             _("Interface %(0)s bound to IP address %(1)s") % {
                                 "0": device,
                                 "1": result
                             },
                             icon_name="network-workgroup").show()

                self.quering.remove(device)

            def err(_obj: Mechanism, result: GLib.Error,
                    _user_data: None) -> None:
                logging.warning(result)
                Notification(_("Bluetooth Network"),
                             _("Failed to obtain an IP address on %s") %
                             device,
                             icon_name="network-workgroup").show()

                self.quering.remove(device)

            Notification(
                _("Bluetooth Network"),
                _("Trying to obtain an IP address on %s\nPlease wait…" %
                  device),
                icon_name="network-workgroup").show()

            m = Mechanism()
            m.DhcpClient('(s)',
                         object_path,
                         result_handler=reply,
                         error_handler=err,
                         timeout=120 * 1000)