示例#1
0
    def on_mm_device_added(self, path, name="org.freedesktop.ModemManager"):
        dprint(path)
        interface = "%s.Modem" % name
        props = self.parent.bus.call_blocking(
            name, path, "org.freedesktop.DBus.Properties", "GetAll", "s",
            [interface])

        try:
            drivers = props["Drivers"]
        except KeyError:
            drivers = [props["Driver"]]

        if self.rfcomm_dev and "bluetooth" in drivers and props[
                "Device"] in self.rfcomm_dev:
            dprint("It's our bluetooth modem!")

            modem = get_icon("modem", 24)
            blueman = get_icon("blueman", 48)

            icon = composite_icon(blueman, [(modem, 24, 24, 255)])

            Notification(
                _("Bluetooth Dialup"),
                _("DUN connection on %s will now be available in Network Manager"
                  ) % self.service.device['Alias'],
                pixbuf=icon,
                status_icon=self.parent.Applet.Plugins.StatusIcon)

            self.reply(self.rfcomm_dev)
            self.cleanup()
示例#2
0
    def _on_session_removed(self, _manager, _session_path):
        if self._silent_transfers == 0:
            return

        try:
            status_icon = self._applet.Plugins.StatusIcon
        except:
            status_icon = None

        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,
                pixbuf=get_icon("blueman", 48),
                status_icon=status_icon,
            )

            self._add_open(n, "Open Location", self._config["shared-path"])
        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,
                pixbuf=get_icon("blueman", 48),
                status_icon=status_icon,
            )
            self._add_open(n, "Open Location", self._config["shared-path"])
示例#3
0
    def on_mm_device_added(self, path):
        dprint(path)
        props = self.parent.bus.call_blocking(
            "org.freedesktop.ModemManager", path,
            "org.freedesktop.DBus.Properties", "GetAll", "s",
            ["org.freedesktop.ModemManager.Modem"])

        if self.rfcomm_dev and props["Driver"] == "bluetooth" and props[
                "Device"] in self.rfcomm_dev:
            dprint("It's our bluetooth modem!")

            modem = get_icon("modem", 24)
            blueman = get_icon("blueman", 48)

            icon = composite_icon(blueman, [(modem, 24, 24, 255)])

            Notification(
                _("Bluetooth Dialup"),
                _("DUN connection on %s will now be available in Network Manager"
                  ) % self.device.Alias,
                pixbuf=icon,
                status_icon=self.parent.Applet.Plugins.StatusIcon)

            self.reply(self.rfcomm_dev)
            self.cleanup()
示例#4
0
    def _on_authorize(self, _agent, transfer_path):
        transfer = obex.Transfer(transfer_path)
        session = obex.Session(transfer.session)
        root = session.root
        address = session.address
        filename = transfer.name
        size = transfer.size

        try:
            device = self._applet.Manager.get_adapter().find_device(address)
            name = device["Alias"]
            trusted = device["Trusted"]
        except Exception as e:
            dprint(e)
            name = address
            trusted = False

        self._pending_transfer = {
            'transfer_path': transfer_path,
            'address': address,
            'root': root,
            'filename': filename,
            'size': size,
            'name': name
        }

        try:
            status_icon = self._applet.Plugins.StatusIcon
        except:
            status_icon = None

        # This device was neither allowed nor is it trusted -> ask for confirmation
        if address not in self._allowed_devices and not (
                self._config['opp-accept'] and trusted):
            self._notification = Notification(
                _("Incoming file over Bluetooth"),
                _("Incoming file %(0)s from %(1)s") % {
                    "0": "<b>" + filename + "</b>",
                    "1": "<b>" + name + "</b>"
                },
                30000, [["accept", _("Accept"), "help-about"],
                        ["reject", _("Reject"), "help-about"]],
                self._on_action,
                pixbuf=get_icon("blueman", 48),
                status_icon=status_icon)
        # Device is trusted or was already allowed, larger file -> display a notification, but auto-accept
        elif size > 350000:
            self._notification = Notification(
                _("Receiving file"),
                _("Receiving file %(0)s from %(1)s") % {
                    "0": "<b>" + filename + "</b>",
                    "1": "<b>" + name + "</b>"
                },
                pixbuf=get_icon("blueman", 48),
                status_icon=status_icon)
            self._on_action(self._notification, 'accept')
        # Device is trusted or was already allowed. very small file -> auto-accept and transfer silently
        else:
            self._notification = None
            self._on_action(self._notification, "accept")
示例#5
0
    def _on_session_removed(self, _manager, _session_path):
        if self._silent_transfers == 0:
            return

        try:
            status_icon = self._applet.Plugins.StatusIcon
        except:
            status_icon = None

        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,
                             pixbuf=get_icon("blueman", 48),
                             status_icon=status_icon)

            self._add_open(n, "Open Location", self._config["shared-path"])
        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,
                pixbuf=get_icon("blueman", 48),
                status_icon=status_icon)
            self._add_open(n, "Open Location", self._config["shared-path"])
示例#6
0
    def on_mm_device_added(self, path):
        dprint(path)
        props = self.parent.bus.call_blocking(
            "org.freedesktop.ModemManager",
            path,
            "org.freedesktop.DBus.Properties",
            "GetAll",
            "s",
            ["org.freedesktop.ModemManager.Modem"],
        )

        if self.rfcomm_dev and props["Driver"] == "bluetooth" and props["Device"] in self.rfcomm_dev:
            dprint("It's our bluetooth modem!")

            modem = get_icon("modem", 24)
            blueman = get_icon("blueman", 48)

            icon = composite_icon(blueman, [(modem, 24, 24, 255)])

            Notification(
                _("Bluetooth Dialup"),
                _("DUN connection on %s will now be available in Network Manager") % self.device.Alias,
                pixbuf=icon,
                status_icon=self.parent.Applet.Plugins.StatusIcon,
            )

            self.reply(self.rfcomm_dev)
            self.cleanup()
示例#7
0
    def on_mm_device_added(self, path, name="org.freedesktop.ModemManager"):
        dprint(path)
        interface = "%s.Modem" % name
        props = self.parent.bus.call_blocking(name, path, "org.freedesktop.DBus.Properties", "GetAll", "s", [interface])

        try:
            drivers = props["Drivers"]
        except KeyError:
            drivers = [props["Driver"]]

        if self.rfcomm_dev and "bluetooth" in drivers and props["Device"] in self.rfcomm_dev:
            dprint("It's our bluetooth modem!")

            modem = get_icon("modem", 24)
            blueman = get_icon("blueman", 48)

            icon = composite_icon(blueman, [(modem, 24, 24, 255)])

            Notification(_("Bluetooth Dialup"),
                         _("DUN connection on %s will now be available in Network Manager") % self.service.device.Alias,
                         pixbuf=icon,
                         status_icon=self.parent.Applet.Plugins.StatusIcon)

            self.reply(self.rfcomm_dev)
            self.cleanup()
示例#8
0
 def get_device_icon(self, klass, dev_icon_prop=None):
     if dev_icon_prop is None:
         dev_icon_prop = "blueman"
     try:
         return get_icon("blueman-" + klass.replace(" ", "-").lower(),
                         48,
                         fallback=None)
     except GLib.Error:
         return get_icon(dev_icon_prop, 48, "blueman")
示例#9
0
    def _on_transfer_completed(self, _manager, transfer_path, success):
        try:
            attributes = self._agent.transfers[transfer_path]
        except KeyError:
            # This is probably not an incoming transfer we authorized
            return

        src = attributes['path']
        dest_dir = self._config["shared-path"]
        filename = os.path.basename(src)

        # We get bytes from pygobject under python 2.7
        if hasattr(
                dest_dir,
                "upper",
        ) and hasattr(dest_dir, "decode"):
            dest_dir = dest_dir.decode("UTF-8")

        dest = os.path.join(dest_dir, filename)
        if os.path.exists(dest):
            now = datetime.now()
            filename = "%s_%s" % (now.strftime("%Y%m%d%H%M%S"), filename)
            dprint("Destination file exists, renaming to: %s" % filename)

        shutil.move(src, dest)

        try:
            status_icon = self._applet.Plugins.StatusIcon
        except:
            status_icon = None

        if success:
            n = Notification(_("File received"),
                             _("File %(0)s from %(1)s successfully received") %
                             {
                                 "0": "<b>" + filename + "</b>",
                                 "1": "<b>" + attributes['name'] + "</b>"
                             },
                             pixbuf=get_icon("blueman", 48),
                             status_icon=status_icon)
            self._add_open(n, "Open", dest)
        elif not success:
            Notification(_("Transfer failed"),
                         _("Transfer of file %(0)s failed") % {
                             "0": "<b>" + filename + "</b>",
                             "1": "<b>" + attributes['name'] + "</b>"
                         },
                         pixbuf=get_icon("blueman", 48),
                         status_icon=status_icon)

            if attributes['size'] > 350000:
                self._normal_transfers -= 1
            else:
                self._silent_transfers -= 1

        del self._agent.transfers[transfer_path]
示例#10
0
    def _on_authorize(self, _agent, transfer_path, address=None, filename=None, size=None):
        if address and filename and size:
            # stand-alone obexd
            # FIXME: /tmp is only the default. Can we get the actual root
            # directory from stand-alone obexd?
            root = '/tmp'
        else:
            # BlueZ 5 integrated obexd
            transfer = obex.Transfer(transfer_path)
            session = obex.Session(transfer.session)
            root = session.root
            address = session.address
            filename = transfer.name
            size = transfer.size

        try:
            device = Device(self._applet.Manager.get_adapter().find_device(address))
            name = device.Alias
            trusted = device.Trusted
        except Exception as e:
            dprint(e)
            name = address
            trusted = False

        self._pending_transfer = {'transfer_path': transfer_path, 'address': address, 'root': root,
                                  'filename': filename, 'size': size, 'name': name}

        try:
            status_icon = self._applet.Plugins.StatusIcon
        except:
            status_icon = None

        # This device was neither allowed nor is it trusted -> ask for confirmation
        if address not in self._allowed_devices and not (self._config['opp-accept'] and trusted):
            self._notification = Notification(_("Incoming file over Bluetooth"),
                _("Incoming file %(0)s from %(1)s") % {"0": "<b>" + filename + "</b>",
                                                       "1": "<b>" + name + "</b>"},
                30000, [["accept", _("Accept"), "help-about"], ["reject", _("Reject"), "help-about"]], self._on_action,
                pixbuf=get_icon("blueman", 48), status_icon=status_icon)
        # Device is trusted or was already allowed, larger file -> display a notification, but auto-accept
        elif size > 350000:
            self._notification = Notification(_("Receiving file"),
                _("Receiving file %(0)s from %(1)s") % {"0": "<b>" + filename + "</b>",
                                                        "1": "<b>" + name + "</b>"},
                pixbuf=get_icon("blueman", 48), status_icon=status_icon)
            self._on_action(self._notification, 'accept')
        # Device is trusted or was already allowed. very small file -> auto-accept and transfer silently
        else:
            self._notification = None
            self._on_action(self._notification, "accept")
示例#11
0
    def _on_transfer_completed(self, _manager, transfer_path, success):
        try:
            attributes = self._agent.transfers[transfer_path]
        except KeyError:
            # This is probably not an incoming transfer we authorized
            return

        src = attributes["path"]
        dest_dir = self._config["shared-path"]
        filename = os.path.basename(src)

        if os.path.exists(os.path.join(dest_dir, filename)):
            now = datetime.now()
            filename = "%s_%s" % (now.strftime("%Y%m%d%H%M%S"), filename)
            dprint("Destination file exists, renaming to: %s" % filename)

        dest = os.path.join(dest_dir, filename)
        shutil.move(src, dest)

        try:
            status_icon = self._applet.Plugins.StatusIcon
        except:
            status_icon = None

        if success:
            n = Notification(
                _("File received"),
                _("File %(0)s from %(1)s successfully received")
                % {"0": "<b>" + filename + "</b>", "1": "<b>" + attributes["name"] + "</b>"},
                pixbuf=get_icon("blueman", 48),
                status_icon=status_icon,
            )
            self._add_open(n, "Open", dest)
        elif not success:
            Notification(
                _("Transfer failed"),
                _("Transfer of file %(0)s failed")
                % {"0": "<b>" + filename + "</b>", "1": "<b>" + attributes["name"] + "</b>"},
                pixbuf=get_icon("blueman", 48),
                status_icon=status_icon,
            )

            if attributes["size"] > 350000:
                self._normal_transfers -= 1
            else:
                self._silent_transfers -= 1

        del self._agent.transfers[transfer_path]
示例#12
0
    def _on_authorize_service(self, parameters, invocation):
        def on_auth_action(n, action):
            dprint(action)

            #self.applet.status_icon.set_blinking(False)
            if action == "always":
                device = Bluez.Device(n._device)
                device.set("Trusted", True)
            if action == "always" or action == "accept":
                invocation.return_value(GLib.Variant('()', ()))
            else:
                invocation.return_dbus_error('org.bluez.Error.Rejected', 'Rejected')

            self.n = None

        device, uuid = parameters.unpack()

        dprint("Agent.Authorize")
        alias = self.get_device_alias(device)
        uuid16 = uuid128_to_uuid16(uuid)
        service = uuid16_to_name(uuid16)
        notify_message = (_("Authorization request for:") + "\n%s\n" + _("Service:") + " <b>%s</b>") % (alias, service)
        actions = [["always", _("Always accept")],
                   ["accept", _("Accept")],
                   ["deny", _("Deny")]]

        n = Notification(_("Bluetooth Authentication"), notify_message, 0,
                         actions, on_auth_action,
                         pixbuf=get_icon("blueman", 48), status_icon=self.status_icon)
        n._device = device
示例#13
0
    def _on_request_confirmation(self, parameters, invocation):
        def on_confirm_action(n, action):
            if action == "confirm":
                invocation.return_value(GLib.Variant('()', ()))
            else:
                invocation.return_dbus_error('org.bluez.Error.Canceled',
                                             "User canceled pairing")

        params = parameters.unpack()
        if len(params) < 2:
            device_path = params[0]
            passkey = None
        else:
            device_path, passkey = params

        dprint("Agent.RequestConfirmation")
        alias = self.get_device_alias(device_path)
        notify_message = _("Pairing request for:") + "\n%s" % alias
        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,
                              pixbuf=get_icon("blueman", 48),
                              status_icon=self.status_icon)
示例#14
0
    def Authorize(self, device, uuid, ok, err):
        def on_auth_action(n, action):
            dprint(action)

            #self.applet.status_icon.set_blinking(False)
            if action == "always":
                device = Bluez.Device(n._device)
                device.set("Trusted", True)
            if action == "always" or action == "accept":
                ok()
            else:
                err(AgentErrorRejected())

            self.n = None

        dprint("Agent.Authorize")
        alias = self.get_device_alias(device)
        uuid16 = uuid128_to_uuid16(uuid)
        service = uuid16_to_name(uuid16)
        notify_message = (_("Authorization request for:") + "\n%s\n" +
                          _("Service:") + " <b>%s</b>") % (alias, service)
        actions = [["always", _("Always accept")], ["accept",
                                                    _("Accept")],
                   ["deny", _("Deny")]]

        n = Notification(_("Bluetooth Authentication"),
                         notify_message,
                         0,
                         actions,
                         on_auth_action,
                         pixbuf=get_icon("blueman", 48),
                         status_icon=self.status_icon)
        n._device = device
示例#15
0
    def Authorize(self, device, uuid, ok, err):

        def on_auth_action(n, action):
            dprint(action)

            #self.applet.status_icon.set_blinking(False)
            if action == "always":
                device = Bluez.Device(n._device)
                device.set("Trusted", True)
            if action == "always" or action == "accept":
                ok()
            else:
                err(AgentErrorRejected())

            self.n = None

        dprint("Agent.Authorize")
        alias = self.get_device_alias(device)
        uuid16 = uuid128_to_uuid16(uuid)
        service = uuid16_to_name(uuid16)
        notify_message = (_("Authorization request for:") + "\n%s\n" + _("Service:") + " <b>%s</b>") % (alias, service)
        actions = [["always", _("Always accept"), "blueman-trust"],
                   ["accept", _("Accept"), "help-about"],
                   ["deny", _("Deny"), "help-about"]]

        n = Notification(_("Bluetooth Authentication"), notify_message, 0,
                         actions, on_auth_action,
                         pixbuf=get_icon("blueman", 48), status_icon=self.status_icon)
        n._device = device
示例#16
0
    def on_load(self, applet):
        self.Applet = applet

        applet.Plugins.Menu.Register(self, Gtk.SeparatorMenuItem(), 21)

        self.new_dev = create_menuitem(_("_Setup New Device") + "...", get_icon("document-new", 16))
        self.new_dev.connect("activate", self.on_setup_new)

        self.Applet.Plugins.Menu.Register(self, self.new_dev, 30)

        self.Applet.Plugins.Menu.Register(self, Gtk.SeparatorMenuItem(), 31)

        self.send = create_menuitem(_("Send _Files to Device") + "...", get_icon("blueman-send-file", 16))
        self.send.connect("activate", self.on_send)

        self.Applet.Plugins.Menu.Register(self, self.send, 40)

        self.browse = create_menuitem(_("_Browse Files on Device") + "...", get_icon("document-open", 16))
        self.browse.connect("activate", self.on_browse)

        self.Applet.Plugins.Menu.Register(self, self.browse, 50)

        self.Applet.Plugins.Menu.Register(self, Gtk.SeparatorMenuItem(), 51)

        self.devices = create_menuitem(_("_Devices") + "...", get_icon("blueman", 16))
        self.devices.connect("activate", self.on_devices)

        self.Applet.Plugins.Menu.Register(self, self.devices, 60)

        self.adapters = create_menuitem(_("Adap_ters") + "...", get_icon("blueman-device", 16))
        self.adapters.connect("activate", self.on_adapters)

        self.Applet.Plugins.Menu.Register(self, self.adapters, 70)

        self.services = create_menuitem(_("_Local Services") + "...", get_icon("preferences-desktop", 16))
        self.services.connect("activate", self.on_local_services)

        self.Applet.Plugins.Menu.Register(self, self.services, 80)

        self.Applet.Plugins.Menu.Register(self, Gtk.SeparatorMenuItem(), 81)

        about = create_menuitem("_Help", get_icon('help-about', 16))
        self.Applet.Plugins.Menu.Register(self, about, 90)

        self.plugins = create_menuitem(_("_Plugins"), get_icon("blueman-plugin", 16))
        self.plugins.connect("activate", self.on_plugins)

        self.Applet.Plugins.Menu.Register(self, self.plugins, 85)

        about.connect("activate", self.on_about)

        def on_activate(status_icon):
            self.on_devices(None)


        self.Applet.Plugins.StatusIcon.connect("activate", on_activate)
示例#17
0
    def _on_display_pin_code(self, parameters, invocation):
        device, pin_code = parameters.unpack()
        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)
示例#18
0
 def DisplayPasskey(self, device, passkey, entered):
     dprint('DisplayPasskey (%s, %d)' % (device, passkey))
     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)
示例#19
0
 def DisplayPinCode(self, device, pin_code):
     dprint('DisplayPinCode (%s, %s)' % (device, pin_code))
     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)
示例#20
0
	def __init__(self, blueman, cancellable=True, text=_("Connecting")):
		def on_enter(evbox, event):
			c = Gdk.Cursor.new(Gdk.CursorType.HAND2)
			self.window.get_window().set_cursor(c)
		
		def on_leave(evbox, event):
			self.window.get_window().set_cursor(None)
			
		def on_clicked(evbox, event):
			self.eventbox.props.sensitive = False
			self.emit("cancelled")
		
		GObject.GObject.__init__(self)
		self.Blueman = blueman
		
		self.cancellable = cancellable
		
		self.hbox = hbox = blueman.Builder.get_object("statusbar1")
		
		self.progressbar = Gtk.ProgressBar()
		
		self.signals = SignalTracker()

		self.button = Gtk.Image.new_from_pixbuf(get_icon("gtk-stop", 16))
	
		self.eventbox = eventbox = Gtk.EventBox()
		eventbox.add(self.button)
		eventbox.props.tooltip_text = _("Cancel Operation")
		self.signals.Handle(eventbox, "enter-notify-event", on_enter)
		self.signals.Handle(eventbox, "leave-notify-event", on_leave)
		self.signals.Handle(eventbox, "button-press-event", on_clicked)

		
		self.progressbar.set_size_request(100, 15)
		self.progressbar.set_ellipsize(Pango.EllipsizeMode.END)
		self.progressbar.set_text(text)
		self.progressbar.set_pulse_step(0.05)
		
		self.window = blueman.Builder.get_object("window")

		hbox.pack_end(eventbox, True, False, 0)
		hbox.pack_end(self.progressbar, False, False, 0)

		if ManagerProgressbar.__instances__ != []:
			dprint("hiding", ManagerProgressbar.__instances__[-1])
			ManagerProgressbar.__instances__[-1].hide()
		
		self.show()
		if not self.cancellable:
			self.eventbox.props.sensitive = False
		
		self.gsource = None
		self.finalized = False
		
		ManagerProgressbar.__instances__.append(self)
示例#21
0
    def __init__(self, blueman, cancellable=True, text=_("Connecting")):
        def on_enter(evbox, event):
            c = Gdk.Cursor.new(Gdk.CursorType.HAND2)
            self.window.get_window().set_cursor(c)

        def on_leave(evbox, event):
            self.window.get_window().set_cursor(None)

        def on_clicked(evbox, event):
            self.eventbox.props.sensitive = False
            self.emit("cancelled")

        GObject.GObject.__init__(self)
        self.Blueman = blueman

        self.cancellable = cancellable

        self.hbox = hbox = blueman.Builder.get_object("statusbar1")

        self.progressbar = Gtk.ProgressBar()

        self._signals = []

        self.button = Gtk.Image.new_from_pixbuf(get_icon("process-stop", 16))

        self.eventbox = eventbox = Gtk.EventBox()
        eventbox.add(self.button)
        eventbox.props.tooltip_text = _("Cancel Operation")
        eventbox.connect("enter-notify-event", on_enter)
        eventbox.connect("leave-notify-event", on_leave)
        eventbox.connect("button-press-event", on_clicked)

        self.progressbar.set_size_request(100, 15)
        self.progressbar.set_ellipsize(Pango.EllipsizeMode.END)
        self.progressbar.set_text(text)
        self.progressbar.set_pulse_step(0.05)

        self.window = blueman.Builder.get_object("window")

        hbox.pack_end(eventbox, True, False, 0)
        hbox.pack_end(self.progressbar, False, False, 0)

        if ManagerProgressbar.__instances__ != []:
            dprint("hiding", ManagerProgressbar.__instances__[-1])
            ManagerProgressbar.__instances__[-1].hide()

        self.show()
        if not self.cancellable:
            self.eventbox.props.sensitive = False

        self.gsource = None
        self.finalized = False

        ManagerProgressbar.__instances__.append(self)
示例#22
0
    def make_device_icon(self,
                         target,
                         is_bonded=False,
                         is_trusted=False,
                         is_discovered=False,
                         opacity=255):
        if opacity != 255:
            target = opacify_pixbuf(target, opacity)

        sources = []
        if is_bonded:
            sources.append((get_icon("dialog-password", 16), 0, 0, 200))

        if is_trusted:
            sources.append((get_icon("blueman-trust", 16), 0, 32, 200))

        if is_discovered:
            sources.append((get_icon("edit-find", 24), 24, 0, 255))

        return composite_icon(target, sources)
示例#23
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)
示例#24
0
    def row_setup_event(self, tree_iter, device):
        if not self.get(tree_iter, "initial_anim")["initial_anim"]:
            cell_fader = CellFade(self, self.props.model.get_path(tree_iter),
                                  [2, 3, 4])
            row_fader = TreeRowFade(self, self.props.model.get_path(tree_iter))

            has_objpush = self._has_objpush(device)

            self.set(tree_iter,
                     row_fader=row_fader,
                     cell_fader=cell_fader,
                     levels_visible=False,
                     objpush=has_objpush)

            cell_fader.freeze()

            def on_finished(fader):
                fader.disconnect(signal)
                fader.freeze()

            signal = row_fader.connect("animation-finished", on_finished)
            row_fader.set_state(0.0)
            row_fader.animate(start=0.0, end=1.0, duration=500)

            self.set(tree_iter, initial_anim=True)

        klass = get_minor_class(device['Class'])
        if klass != "uncategorized":
            icon = self.get_device_icon(klass, device["Icon"])
            # get translated version
            klass = get_minor_class(device['Class'], True)
        else:
            icon = get_icon(device['Icon'], 48, "blueman")
            klass = get_major_class(device['Class'])

        name = device['Alias']
        address = device['Address']

        caption = self.make_caption(name, klass, address)

        # caption = "<span size='x-large'>%(0)s</span>\n<span size='small'>%(1)s</span>\n<i>%(2)s</i>" % {"0":name, "1":klass.capitalize(), "2":address}
        self.set(tree_iter, caption=caption, orig_icon=icon, alias=name)

        try:
            self.row_update_event(tree_iter, "Trusted", device['Trusted'])
        except Exception as e:
            logging.exception(e)
        try:
            self.row_update_event(tree_iter, "Paired", device['Paired'])
        except Exception as e:
            logging.exception(e)
示例#25
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)
示例#26
0
    def on_mm_device_added(self, path, name="org.freedesktop.ModemManager"):
        logging.info(path)
        interface = "%s.Modem" % name
        res = self.parent._bus.call_sync(name, path, 'org.freedesktop.DBus.Properties', "GetAll",
                                         GLib.Variant("(s)", (interface,)),
                                         None, Gio.DBusCallFlags.NONE, GLib.MAXINT, None)
        props = res.unpack()[0]

        if self.rfcomm_dev and "bluetooth" in props["Drivers"] and self.rfcomm_dev.split('/')[-1] in props["Device"]:
            logging.info("It's our bluetooth modem!")

            modem = get_icon("modem", 24)
            blueman = get_icon("blueman", 48)

            icon = composite_icon(blueman, [(modem, 24, 24, 255)])

            Notification(
                _("Bluetooth Dialup"),
                _("DUN connection on %s will now be available in Network Manager") % self.service.device['Alias'],
                image_data=icon).show()

            self.reply(self.rfcomm_dev)
            self.cleanup()
示例#27
0
    def on_load(self, applet):
        self.Applet = applet

        applet.Plugins.Menu.Register(self, Gtk.SeparatorMenuItem(), 21)

        self.new_dev = create_menuitem(_("_Setup New Device") + "...", get_icon("document-new", 16))
        self.new_dev.connect("activate", self.on_setup_new)

        self.Applet.Plugins.Menu.Register(self, self.new_dev, 30)

        self.Applet.Plugins.Menu.Register(self, Gtk.SeparatorMenuItem(), 31)

        self.send = create_menuitem(_("Send _Files to Device") + "...", get_icon("blueman-send-file", 16))
        self.send.connect("activate", self.on_send)

        self.Applet.Plugins.Menu.Register(self, self.send, 40)

        self.Applet.Plugins.Menu.Register(self, Gtk.SeparatorMenuItem(), 51)

        self.devices = create_menuitem(_("_Devices") + "...", get_icon("blueman", 16))
        self.devices.connect("activate", self.on_devices)

        self.Applet.Plugins.Menu.Register(self, self.devices, 60)

        self.adapters = create_menuitem(_("Adap_ters") + "...", get_icon("blueman-device", 16))
        self.adapters.connect("activate", self.on_adapters)

        self.Applet.Plugins.Menu.Register(self, self.adapters, 70)

        self.services = create_menuitem(_("_Local Services") + "...", get_icon("preferences-desktop", 16))
        self.services.connect("activate", self.on_local_services)

        self.Applet.Plugins.Menu.Register(self, self.services, 80)

        self.Applet.Plugins.Menu.Register(self, Gtk.SeparatorMenuItem(), 81)

        about = create_menuitem("_Help", get_icon('help-about', 16))
        self.Applet.Plugins.Menu.Register(self, about, 90)

        self.plugins = create_menuitem(_("_Plugins"), get_icon("blueman-plugin", 16))
        self.plugins.connect("activate", self.on_plugins)

        self.Applet.Plugins.Menu.Register(self, self.plugins, 85)

        about.connect("activate", self.on_about)

        def on_activate(status_icon):
            self.on_devices(None)


        self.Applet.Plugins.StatusIcon.connect("activate", on_activate)
示例#28
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

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

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

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

        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()
示例#29
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)
示例#30
0
 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()
示例#31
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)
示例#32
0
文件: Services.py 项目: latot/blueman
 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()
示例#33
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()
示例#34
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()
示例#35
0
    def __init__(self, blueman, cancellable=True, text=_("Connecting")):
        super(ManagerProgressbar, self).__init__()
        self.Blueman = blueman

        self.cancellable = cancellable

        self.hbox = hbox = blueman.Builder.get_object("status_data")

        self.progressbar = Gtk.ProgressBar()
        self.progressbar.set_name("ManagerProgressbar")

        self._signals = []

        self.button = Gtk.Image.new_from_pixbuf(get_icon("process-stop", 16))

        self.eventbox = eventbox = Gtk.EventBox()
        eventbox.add(self.button)
        eventbox.props.tooltip_text = _("Cancel Operation")
        eventbox.connect("enter-notify-event", self._on_enter)
        eventbox.connect("leave-notify-event", self._on_leave)
        eventbox.connect("button-press-event", self._on_clicked)

        self.progressbar.set_size_request(100, 15)
        self.progressbar.set_ellipsize(Pango.EllipsizeMode.END)
        self.progressbar.set_text(text)
        self.progressbar.set_pulse_step(0.05)

        hbox.pack_end(eventbox, True, False, 0)
        hbox.pack_end(self.progressbar, False, False, 0)

        if ManagerProgressbar.__instances__:
            dprint("hiding", ManagerProgressbar.__instances__[-1])
            ManagerProgressbar.__instances__[-1].hide()

        self.show()
        if not self.cancellable:
            self.eventbox.props.sensitive = False

        self.gsource = None
        self.finalized = False

        ManagerProgressbar.__instances__.append(self)
示例#36
0
    def __init__(self, blueman, cancellable=True, text=_("Connecting")):
        super(ManagerProgressbar, self).__init__()
        self.Blueman = blueman

        self.cancellable = cancellable

        self.hbox = hbox = blueman.Builder.get_object("status_data")

        self.progressbar = Gtk.ProgressBar()
        self.progressbar.set_name("ManagerProgressbar")

        self._signals = []

        self.button = Gtk.Image.new_from_pixbuf(get_icon("process-stop", 16))

        self.eventbox = eventbox = Gtk.EventBox()
        eventbox.add(self.button)
        eventbox.props.tooltip_text = _("Cancel Operation")
        eventbox.connect("enter-notify-event", self._on_enter)
        eventbox.connect("leave-notify-event", self._on_leave)
        eventbox.connect("button-press-event", self._on_clicked)

        self.progressbar.set_size_request(100, 15)
        self.progressbar.set_ellipsize(Pango.EllipsizeMode.END)
        self.progressbar.set_text(text)
        self.progressbar.set_pulse_step(0.05)

        hbox.pack_end(eventbox, True, False, 0)
        hbox.pack_end(self.progressbar, False, False, 0)

        if ManagerProgressbar.__instances__:
            logging.info("hiding %s" % ManagerProgressbar.__instances__[-1])
            ManagerProgressbar.__instances__[-1].hide()

        self.show()
        if not self.cancellable:
            self.eventbox.props.sensitive = False

        self.gsource = None
        self.finalized = False

        ManagerProgressbar.__instances__.append(self)
示例#37
0
    def on_request_menu_items(self, manager_menu, device):

        if self.is_connected(device):
            pa = PulseAudioUtils()
            if not pa.connected:
                self.deferred.append(device)
                return

            self.item = create_menuitem(_("Audio Profile"), get_icon("audio-card", 16))
            self.item.props.tooltip_text = _("Select audio profile for PulseAudio")

            if not device.Address in self.devices:
                self.query_pa(device)
            else:
                self.generate_menu(device)

        else:
            return

        return [(self.item, 300)]
示例#38
0
    def on_request_menu_items(self, manager_menu, device):

        if self.is_connected(device):
            pa = PulseAudioUtils()
            if not pa.connected:
                self.deferred.append(device)
                return

            self.item = create_menuitem(_("Audio Profile"), get_icon("audio-card", 16))
            self.item.props.tooltip_text = _("Select audio profile for PulseAudio")

            if not device.Address in self.devices:
                self.query_pa(device)
            else:
                self.generate_menu(device)

        else:
            return

        return [(self.item, 300)]
示例#39
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

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

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

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

        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()
示例#40
0
    def _on_request_confirmation(self, parameters, invocation):
        def on_confirm_action(n, action):
            if action == "confirm":
                invocation.return_value(GLib.Variant('()', ()))
            else:
                invocation.return_dbus_error('org.bluez.Error.Canceled', "User canceled pairing")

        params = parameters.unpack()
        if len(params) < 2:
            device_path = params[0]
            passkey = None
        else:
            device_path, passkey = params

        dprint("Agent.RequestConfirmation")
        alias = self.get_device_alias(device_path)
        notify_message = _("Pairing request for:") + "\n%s" % alias
        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,
                              pixbuf=get_icon("blueman", 48), status_icon=self.status_icon)
示例#41
0
    def _on_authorize_service(self, parameters, invocation):
        def on_auth_action(n, action):
            dprint(action)

            #self.applet.status_icon.set_blinking(False)
            if action == "always":
                device = Bluez.Device(n._device)
                device.set("Trusted", True)
            if action == "always" or action == "accept":
                invocation.return_value(GLib.Variant('()', ()))
            else:
                invocation.return_dbus_error('org.bluez.Error.Rejected',
                                             'Rejected')

            self.n = None

        device, uuid = parameters.unpack()

        dprint("Agent.Authorize")
        alias = self.get_device_alias(device)
        uuid16 = uuid128_to_uuid16(uuid)
        service = uuid16_to_name(uuid16)
        notify_message = (_("Authorization request for:") + "\n%s\n" +
                          _("Service:") + " <b>%s</b>") % (alias, service)
        actions = [["always", _("Always accept")], ["accept",
                                                    _("Accept")],
                   ["deny", _("Deny")]]

        n = Notification(_("Bluetooth Authentication"),
                         notify_message,
                         0,
                         actions,
                         on_auth_action,
                         pixbuf=get_icon("blueman", 48),
                         status_icon=self.status_icon)
        n._device = device
示例#42
0
    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
示例#43
0
def get_x_icon(icon_name, size):
    ic = get_icon(icon_name, size)
    x = get_icon("blueman-x", size)
    pixbuf = composite_icon(ic, [(x, 0, 0, 255)])

    return pixbuf
示例#44
0
    def __init__(self, blueman):

        blueman.List.connect("adapter-changed", self.on_adapter_changed)

        if blueman.List.Adapter:
            self.hci = adapter_path_to_name(blueman.List.Adapter.get_object_path())
        else:
            self.hci = None

        self.time = None

        self.up_speed = SpeedCalc()
        self.down_speed = SpeedCalc()

        up = get_icon("blueman-up-inactive", 15)
        down = get_icon("blueman-down-inactive", 15)
        self.im_upload = Gtk.Image()
        self.im_upload.set_tooltip_text(_("Data activity indication"))
        self.im_upload.set_from_pixbuf(up)
        self.im_download = Gtk.Image()
        self.im_download.set_tooltip_text(_("Data activity indication"))
        self.im_download.set_from_pixbuf(down)
        self.im_upload.set_alignment(1, 0.5)
        self.im_download.set_alignment(1, 0.5)

        self.down_rate = Gtk.Label()
        self.down_rate.show()
        self.down_rate.set_alignment(1, 0.5)
        self.down_rate.set_tooltip_text(_("Total data received and rate of transmission"))

        self.up_rate = Gtk.Label()
        self.up_rate.show()
        self.up_rate.set_alignment(1, 0.5)
        self.up_rate.set_tooltip_text(_("Total data sent and rate of transmission"))

        self.uparrow = Gtk.Image()
        self.uparrow.set_tooltip_text(_("Total data sent and rate of transmission"))
        self.uparrow.set_from_icon_name("go-up", 1)
        self.uparrow.set_alignment(1, 0.5)

        self.downarrow = Gtk.Image()
        self.downarrow.set_tooltip_text(_("Total data received and rate of transmission"))
        self.downarrow.set_from_icon_name("go-down", 1)

        self.hbox = hbox = blueman.Builder.get_object("statusbar2")

        hbox.pack_start(self.uparrow, True, False, 0)
        hbox.pack_start(self.up_rate, False, False, 0)

        hbox.pack_start(self.downarrow, False, False, 0)
        hbox.pack_start(self.down_rate, False, False, 0)

        hbox.pack_start(Gtk.VSeparator(), False, False, 0)

        hbox.pack_start(self.im_upload, False, False, 0)
        hbox.pack_start(self.im_download, False, False, 0)
        hbox.show_all()
        self.on_adapter_changed(blueman.List, blueman.List.GetAdapterPath())

        self.up_blinker = Animation(self.im_upload,
                                    [get_icon("blueman-up-inactive", 15), get_icon("blueman-up-active", 15)])
        #self.down_blinker = Animation(self.im_download, ["/down_inactive.png", "/down_active.png"])
        self.down_blinker = Animation(self.im_download,
                                      [get_icon("blueman-down-inactive", 16), get_icon("blueman-down-active", 16)])

        self.start_update()
示例#45
0
文件: Services.py 项目: latot/blueman
    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
示例#46
0
 def on_request_menu_items(self, manager_menu, device):
     item = create_menuitem(_("Info"), get_icon("info", 16))
     item.props.tooltip_text = _("Show device information")
     item.connect('activate', lambda x: show_info(device, manager_menu.get_toplevel()))
     return [(item, 400)]
示例#47
0
文件: Notes.py 项目: srpatcha/blueman
 def on_request_menu_items(self, manager_menu, device):
     item = create_menuitem(_("Send _note"), get_icon("info", 16))
     item.props.tooltip_text = _("Send a text note")
     item.connect('activate', lambda x: send_note(device, manager_menu.get_toplevel()))
     return [(item, 500)]
示例#48
0
    def _on_authorize(self, parameters, invocation):
        def on_action(_notification, action):
            dprint(action)

            if action == "accept":
                self.transfers[self._pending_transfer['transfer_path']] = {
                    'path':
                    self._pending_transfer['root'] + '/' +
                    os.path.basename(self._pending_transfer['filename']),
                    'size':
                    self._pending_transfer['size'],
                    'name':
                    self._pending_transfer['name']
                }

                param = GLib.Variant('(s)', (self.transfers[
                    self._pending_transfer['transfer_path']]['path'], ))
                invocation.return_value(param)

                self._allowed_devices.append(self._pending_transfer['address'])
                GLib.timeout_add(60000, self._allowed_devices.remove,
                                 self._pending_transfer['address'])
            else:
                invocation.return_dbus_error('org.bluez.obex.Error.Rejected',
                                             'Rejected')

        transfer_path = parameters.unpack()[0]

        transfer = obex.Transfer(transfer_path)
        session = obex.Session(transfer.session)
        root = session.root[0]
        address = session.address[0]
        filename = transfer.name
        size = transfer.size

        try:
            device = self._applet.Manager.get_adapter().find_device(address)
            name = device["Alias"]
            trusted = device["Trusted"]
        except Exception as e:
            dprint(e)
            name = address
            trusted = False

        self._pending_transfer = {
            'transfer_path': transfer_path,
            'address': address,
            'root': root,
            'filename': filename,
            'size': size,
            'name': name
        }

        try:
            status_icon = self._applet.Plugins.StatusIcon
        except:
            status_icon = None

        # This device was neither allowed nor is it trusted -> ask for confirmation
        if address not in self._allowed_devices and not (
                self._config['opp-accept'] and trusted):
            self._notification = Notification(
                _("Incoming file over Bluetooth"),
                _("Incoming file %(0)s from %(1)s") % {
                    "0": "<b>" + filename + "</b>",
                    "1": "<b>" + name + "</b>"
                },
                30000, [["accept", _("Accept"), "help-about"],
                        ["reject", _("Reject"), "help-about"]],
                on_action,
                pixbuf=get_icon("blueman", 48),
                status_icon=status_icon)
        # Device is trusted or was already allowed, larger file -> display a notification, but auto-accept
        elif size > 350000:
            self._notification = Notification(
                _("Receiving file"),
                _("Receiving file %(0)s from %(1)s") % {
                    "0": "<b>" + filename + "</b>",
                    "1": "<b>" + name + "</b>"
                },
                pixbuf=get_icon("blueman", 48),
                status_icon=status_icon)
            on_action(self._notification, 'accept')
        # Device is trusted or was already allowed. very small file -> auto-accept and transfer silently
        else:
            self._notification = None
            on_action(self._notification, "accept")
示例#49
0
    def __init__(self, blueman):

        blueman.List.connect("adapter-changed", self.on_adapter_changed)

        if blueman.List.Adapter:
            self.hci = adapter_path_to_name(
                blueman.List.Adapter.GetObjectPath())
        else:
            self.hci = None

        self.time = None

        self.up_speed = SpeedCalc()
        self.down_speed = SpeedCalc()

        up = get_icon("blueman-up-inactive", 15)
        down = get_icon("blueman-down-inactive", 15)
        self.im_upload = gtk.Image()
        self.im_upload.set_tooltip_text(_("Data activity indication"))
        self.im_upload.set_from_pixbuf(up)
        self.im_download = gtk.Image()
        self.im_download.set_tooltip_text(_("Data activity indication"))
        self.im_download.set_from_pixbuf(down)
        self.im_upload.set_alignment(1, 0.5)
        self.im_download.set_alignment(1, 0.5)

        self.down_rate = gtk.Label()
        self.down_rate.show()
        self.down_rate.set_alignment(1, 0.5)
        self.down_rate.set_tooltip_text(
            _("Total data received and rate of transmission"))

        self.up_rate = gtk.Label()
        self.up_rate.show()
        self.up_rate.set_alignment(1, 0.5)
        self.up_rate.set_tooltip_text(
            _("Total data sent and rate of transmission"))

        self.uparrow = gtk.Image()
        self.uparrow.set_tooltip_text(
            _("Total data sent and rate of transmission"))
        self.uparrow.set_from_stock(gtk.STOCK_GO_UP, 1)
        self.uparrow.set_alignment(1, 0.5)

        self.downarrow = gtk.Image()
        self.downarrow.set_tooltip_text(
            _("Total data received and rate of transmission"))
        self.downarrow.set_from_stock(gtk.STOCK_GO_DOWN, 1)

        self.hbox = hbox = blueman.Builder.get_object("statusbar2")

        hbox.pack_start(self.uparrow, True, False)
        hbox.pack_start(self.up_rate, False, False)

        hbox.pack_start(self.downarrow, False, False)
        hbox.pack_start(self.down_rate, False, False)

        hbox.pack_start(gtk.VSeparator(), False, False)

        hbox.pack_start(self.im_upload, False, False)
        hbox.pack_start(self.im_download, False, False)
        hbox.show_all()
        self.on_adapter_changed(blueman.List, blueman.List.GetAdapterPath())

        self.up_blinker = Animation(self.im_upload, [
            get_icon("blueman-up-inactive", 15),
            get_icon("blueman-up-active", 15)
        ])
        #self.down_blinker = Animation(self.im_download, ["/down_inactive.png", "/down_active.png"])
        self.down_blinker = Animation(self.im_download, [
            get_icon("blueman-down-inactive", 16),
            get_icon("blueman-down-active", 16)
        ])

        self.start_update()
示例#50
0
    def __init__(self,
                 summary,
                 message,
                 timeout=-1,
                 actions=None,
                 actions_cb=None,
                 icon_name=None,
                 image_data=None,
                 pos_hint=None):
        super(_NotificationDialog,
              self).__init__(parent=None,
                             flags=0,
                             type=Gtk.MessageType.QUESTION,
                             buttons=Gtk.ButtonsType.NONE,
                             message_format=None)

        self.set_name("NotificationDialog")
        i = 100
        self.actions_supported = True
        self.actions = {}
        self.callback = actions_cb
        if actions:
            for a in actions:
                action_id = a[0]
                action_name = a[1]

                self.actions[i] = action_id
                self.add_button(action_name, i)
                i += 1

        self.actions[Gtk.ResponseType.DELETE_EVENT] = "close"

        self.props.secondary_use_markup = True
        self.resize(350, 50)

        self.fader = Fade(self)

        self.props.skip_taskbar_hint = False

        self.props.title = summary
        self.props.text = summary
        self.props.secondary_text = message

        self.props.window_position = Gtk.WindowPosition.CENTER

        if icon_name:
            self.set_icon_from_pixbuf(get_icon(icon_name, 48))
        elif image_data:
            self.set_icon_from_pixbuf(image_data)

        self.connect("response", self.dialog_response)
        self.props.icon_name = "blueman"

        self.entered = False

        def on_enter(widget, event):
            if self.get_window() == Gdk.Window.at_pointer(
            )[0] or not self.entered:
                self.fader.animate(start=self.fader.get_state(),
                                   end=1.0,
                                   duration=500)
                self.entered = True

        def on_leave(widget, event):
            if not Gdk.Window.at_pointer():
                self.entered = False
                self.fader.animate(start=self.fader.get_state(),
                                   end=OPACITY_START,
                                   duration=500)

        self.connect("enter-notify-event", on_enter)
        self.connect("leave-notify-event", on_leave)
示例#51
0
 def DisplayPasskey(self, device, passkey, entered):
     dprint('DisplayPasskey (%s, %d)' % (device, passkey))
     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)
示例#52
0
 def on_load(self, applet):
     item = create_menuitem("_Exit", get_icon("application-exit", 16))
     item.connect("activate", lambda x: Gtk.main_quit())
     applet.Plugins.Menu.Register(self, item, 100)
示例#53
0
 def DisplayPinCode(self, device, pin_code):
     dprint('DisplayPinCode (%s, %s)' % (device, pin_code))
     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)
示例#54
0
    def _on_authorize(self, parameters, invocation):
        def on_action(_notification, action):
            dprint(action)

            if action == "accept":
                self.transfers[self._pending_transfer['transfer_path']] = {
                    'path': self._pending_transfer['root'] + '/' + os.path.basename(self._pending_transfer['filename']),
                    'size': self._pending_transfer['size'],
                    'name': self._pending_transfer['name']
                }

                param = GLib.Variant('(s)', (self.transfers[self._pending_transfer['transfer_path']]['path'],))
                invocation.return_value(param)

                self._allowed_devices.append(self._pending_transfer['address'])
                GLib.timeout_add(60000, self._allowed_devices.remove, self._pending_transfer['address'])
            else:
                invocation.return_dbus_error('org.bluez.obex.Error.Rejected', 'Rejected')

        transfer_path = parameters.unpack()[0]

        transfer = obex.Transfer(transfer_path)
        session = obex.Session(transfer.session)
        root = session.root[0]
        address = session.address[0]
        filename = transfer.name
        size = transfer.size

        try:
            device = self._applet.Manager.get_adapter().find_device(address)
            name = device["Alias"]
            trusted = device["Trusted"]
        except Exception as e:
            dprint(e)
            name = address
            trusted = False

        self._pending_transfer = {'transfer_path': transfer_path, 'address': address, 'root': root,
                                  'filename': filename, 'size': size, 'name': name}

        try:
            status_icon = self._applet.Plugins.StatusIcon
        except:
            status_icon = None

        # This device was neither allowed nor is it trusted -> ask for confirmation
        if address not in self._allowed_devices and not (self._config['opp-accept'] and trusted):
            self._notification = Notification(_("Incoming file over Bluetooth"),
                _("Incoming file %(0)s from %(1)s") % {"0": "<b>" + filename + "</b>",
                                                       "1": "<b>" + name + "</b>"},
                30000, [["accept", _("Accept"), "help-about"], ["reject", _("Reject"), "help-about"]], on_action,
                pixbuf=get_icon("blueman", 48), status_icon=status_icon)
        # Device is trusted or was already allowed, larger file -> display a notification, but auto-accept
        elif size > 350000:
            self._notification = Notification(_("Receiving file"),
                _("Receiving file %(0)s from %(1)s") % {"0": "<b>" + filename + "</b>",
                                                        "1": "<b>" + name + "</b>"},
                pixbuf=get_icon("blueman", 48), status_icon=status_icon)
            on_action(self._notification, 'accept')
        # Device is trusted or was already allowed. very small file -> auto-accept and transfer silently
        else:
            self._notification = None
            on_action(self._notification, "accept")