Beispiel #1
0
    def on_request_menu_items(self, manager_menu, device):
        if BlueZInterface.get_interface_version()[0] < 5:
            return self.on_request_menu_items_bluez4(manager_menu, device)

        items = []
        uuids = device.UUIDs
        appl = AppletService()

        uuids16 = [uuid128_to_uuid16(uuid) for uuid in uuids]

        if set(uuids16) & set(self.connectable_uuids):
            # FIXME: This should only be done once!
            manager_menu.Signals.Handle("bluez", device, manager_menu.service_property_changed, "PropertyChanged")

            if device.get_properties()['Connected']:
                # FIXME: More generic icon
                item = create_menuitem(_("Disconnect"), get_x_icon("mouse", 16))
                manager_menu.Signals.Handle("gobject", item, "activate", manager_menu.on_disconnect, device)
                items.append((item, 100))
            else:
                # FIXME: More generic icon
                item = create_menuitem(_("Connect"), get_icon("mouse", 16))
                manager_menu.Signals.Handle("gobject", item, "activate", manager_menu.on_connect, device)
                items.append((item, 1))

            item.show()

        for name, service in device.Services.items():
            if name == "network":
                manager_menu.Signals.Handle("bluez", service, manager_menu.service_property_changed, "PropertyChanged")
                sprops = service.get_properties()

                if not sprops["Connected"]:
                    for uuid in uuids:
                        uuid16 = uuid128_to_uuid16(uuid)
                        if uuid16 == NAP_SVCLASS_ID or uuid16 == GN_SVCLASS_ID:
                            label = _("Group Network") if uuid16 == GN_SVCLASS_ID else _("Network Access Point")
                            item = create_menuitem(label, get_icon("network-wireless", 16))
                            manager_menu.Signals.Handle("gobject", item, "activate", manager_menu.on_connect,
                                                        device, name, uuid)
                            item.show()
                            items.append((item, 80))
                else:
                    item = create_menuitem(_("Network"), get_x_icon("network-wireless", 16))
                    manager_menu.Signals.Handle("gobject", item, "activate", manager_menu.on_disconnect, device, name)
                    item.show()
                    items.append((item, 101))

                    if "DhcpClient" in appl.QueryPlugins():
                        def renew(x):
                            appl.DhcpClient(sprops["Interface"])

                        item = create_menuitem(_("Renew IP Address"), get_icon("view-refresh", 16))
                        manager_menu.Signals.Handle("gobject", item, "activate", renew)
                        item.show()
                        items.append((item, 201))

        return items
Beispiel #2
0
 def __init__(self, device, uuid, init_legacy_interface=True):
     self.__device = device
     self.__uuid = uuid
     if init_legacy_interface and BlueZInterface.get_interface_version(
     )[0] < 5:
         bus = dbus.SystemBus()
         proxy = bus.get_object("org.bluez",
                                self.__device.get_object_path())
         self._legacy_interface = dbus.Interface(
             proxy, 'org.bluez.%s' % self.__class__.__name__)
Beispiel #3
0
def AgentMethod(func):
    global __SIGNATURES__
    try:
        signatures = __SIGNATURES__[func.__name__]
    except KeyError:
        raise errors.BluezUnavailableAgentMethodError('method name ' + func.__name__ + ' unavailable for agent')
    args = inspect.getargspec(func)[0]
    if len(args) - len(signatures[0]) == 3:
        async_callbacks = (args[-2], args[-1])
    else:
        async_callbacks = None

    if BlueZInterface.get_interface_version()[0] < 5:
        interface = 'org.bluez.Agent'
    else:
        interface = 'org.bluez.Agent1'

    warp = dbus.service.method(interface, in_signature=signatures[0], out_signature=signatures[1],
                               async_callbacks=async_callbacks)
    return warp(func)
Beispiel #4
0
def AgentMethod(func):
    global __SIGNATURES__
    try:
        signatures = __SIGNATURES__[func.__name__]
    except KeyError:
        raise errors.BluezUnavailableAgentMethodError('method name ' + func.__name__ + ' unavailable for agent')
    args = inspect.getargspec(func)[0]
    if len(args) - len(signatures[0]) == 3:
        async_callbacks = (args[-2], args[-1])
    else:
        async_callbacks = None

    if BlueZInterface.get_interface_version()[0] < 5:
        interface = 'org.bluez.Agent'
    else:
        interface = 'org.bluez.Agent1'

    warp = dbus.service.method(interface, in_signature=signatures[0], out_signature=signatures[1],
                               async_callbacks=async_callbacks)
    return warp(func)
Beispiel #5
0
    def Generate(self):
        self.clear()

        appl = AppletService()

        items = []

        if not self.is_popup or self.props.visible:
            selected = self.Blueman.List.selected()
            if not selected:
                return
            device = self.Blueman.List.get(selected, "device")["device"]
        else:
            (x, y) = self.Blueman.List.get_pointer()
            path = self.Blueman.List.get_path_at_pos(x, y)
            if path != None:
                device = self.Blueman.List.get(path[0], "device")["device"]
            else:
                return

        if not device.Valid:
            return
        self.SelectedDevice = device

        op = self.get_op(device)

        if op != None:
            item = create_menuitem(op, get_icon("gtk-connect", 16))
            item.props.sensitive = False
            item.show()
            self.append(item)
            return

        rets = self.Blueman.Plugins.Run("on_request_menu_items", self, device)

        for ret in rets:
            if ret:
                for (item, pos) in ret:
                    items.append((pos, item))

        if device.Fake:
            item = create_menuitem(_("_Add Device"), get_icon("gtk-add", 16))
            self.Signals.Handle("gobject", item, "activate",
                                lambda x: self.Blueman.add_device(device))
            item.show()
            self.append(item)
            item.props.tooltip_text = _(
                "Add this device to known devices list")

            item = create_menuitem(_("_Setup..."),
                                   get_icon("gtk-properties", 16))
            self.append(item)
            self.Signals.Handle("gobject", item, "activate",
                                lambda x: self.Blueman.setup(device))
            item.show()
            item.props.tooltip_text = _(
                "Run the setup assistant for this device")

            item = create_menuitem(_("_Pair"),
                                   get_icon("gtk-dialog-authentication", 16))
            self.Signals.Handle("gobject", item, "activate",
                                lambda x: self.Blueman.bond(device))
            self.append(item)
            item.show()
            item.props.tooltip_text = _("Pair with the device")

            item = Gtk.SeparatorMenuItem()
            item.show()
            self.append(item)

            send_item = create_menuitem(_("Send a _File..."),
                                        get_icon("gtk-copy", 16))
            self.Signals.Handle("gobject", send_item, "activate",
                                lambda x: self.Blueman.send(device))
            send_item.show()
            self.append(send_item)

        else:
            dprint(device.Alias)

            item = None

            have_disconnectables = False
            have_connectables = False

            if True in map(lambda x: x[0] >= 100 and x[0] < 200, items):
                have_disconnectables = True

            if True in map(lambda x: x[0] < 100, items):
                have_connectables = True

            if True in map(lambda x: x[0] >= 200,
                           items) and (have_connectables
                                       or have_disconnectables):
                item = Gtk.SeparatorMenuItem()
                item.show()
                items.append((199, item))

            if have_connectables:
                item = Gtk.MenuItem()
                label = Gtk.Label()
                label.set_markup(_("<b>Connect To:</b>"))
                label.props.xalign = 0.0

                label.show()
                item.add(label)
                item.props.sensitive = False
                item.show()
                items.append((0, item))

            if have_disconnectables:
                item = Gtk.MenuItem()
                label = Gtk.Label()
                label.set_markup(_("<b>Disconnect:</b>"))
                label.props.xalign = 0.0

                label.show()
                item.add(label)
                item.props.sensitive = False
                item.show()
                items.append((99, item))

            items.sort(lambda a, b: cmp(a[0], b[0]))
            for priority, item in items:
                self.append(item)

            if items != []:
                item = Gtk.SeparatorMenuItem()
                item.show()
                self.append(item)

            del items

            send_item = create_menuitem(_("Send a _File..."),
                                        get_icon("gtk-copy", 16))
            send_item.props.sensitive = False
            self.append(send_item)
            send_item.show()

            browse_item = create_menuitem(_("_Browse Device..."),
                                          get_icon("gtk-open", 16))
            browse_item.props.sensitive = False
            self.append(browse_item)
            browse_item.show()

            uuids = device.UUIDs
            for uuid in uuids:
                uuid16 = uuid128_to_uuid16(uuid)
                if uuid16 == OBEX_OBJPUSH_SVCLASS_ID:
                    self.Signals.Handle("gobject", send_item, "activate",
                                        lambda x: self.Blueman.send(device))
                    send_item.props.sensitive = True

                if uuid16 == OBEX_FILETRANS_SVCLASS_ID:
                    self.Signals.Handle("gobject", browse_item, "activate",
                                        lambda x: self.Blueman.browse(device))
                    browse_item.props.sensitive = True

            item = Gtk.SeparatorMenuItem()
            item.show()
            self.append(item)

            item = create_menuitem(_("_Pair"),
                                   get_icon("gtk-dialog-authentication", 16))
            item.props.tooltip_text = _("Create pairing with the device")
            self.append(item)
            item.show()
            if not device.Paired:
                self.Signals.Handle("gobject", item, "activate",
                                    lambda x: self.Blueman.bond(device))
            else:
                item.props.sensitive = False

            if not device.Trusted:
                item = create_menuitem(_("_Trust"),
                                       get_icon("blueman-trust", 16))
                self.Signals.Handle(
                    "gobject", item, "activate",
                    lambda x: self.Blueman.toggle_trust(device))
                self.append(item)
                item.show()
            else:
                item = create_menuitem(_("_Untrust"),
                                       get_icon("blueman-untrust", 16))
                self.append(item)
                self.Signals.Handle(
                    "gobject", item, "activate",
                    lambda x: self.Blueman.toggle_trust(device))
                item.show()
            item.props.tooltip_text = _("Mark/Unmark this device as trusted")

            item = create_menuitem(_("_Setup..."),
                                   get_icon("gtk-properties", 16))
            self.append(item)
            self.Signals.Handle("gobject", item, "activate",
                                lambda x: self.Blueman.setup(device))
            item.show()
            item.props.tooltip_text = _(
                "Run the setup assistant for this device")

            if BlueZInterface.get_interface_version()[0] < 5:

                def update_services(item):
                    def reply():
                        self.unset_op(device)
                        prog.message(_("Success!"))
                        MessageArea.close()

                    def error(*args):
                        self.unset_op(device)
                        prog.message(_("Fail"))
                        MessageArea.show_message(e_(str(args[0])))

                    prog = ManagerProgressbar(self.Blueman, False,
                                              _("Refreshing"))
                    prog.start()
                    self.set_op(device, _("Refreshing Services..."))
                    appl.RefreshServices(device.get_object_path(),
                                         reply_handler=reply,
                                         error_handler=error)

                item = create_menuitem(_("Refresh Services"),
                                       get_icon("gtk-refresh", 16))
                self.append(item)
                self.Signals.Handle(item, "activate", update_services)
                item.show()

            item = Gtk.SeparatorMenuItem()
            item.show()
            self.append(item)

            item = create_menuitem(_("_Remove..."), get_icon("gtk-delete", 16))
            self.Signals.Handle(item, "activate",
                                lambda x: self.Blueman.remove(device))
            self.append(item)
            item.show()
            item.props.tooltip_text = _(
                "Remove this device from the known devices list")

            item = Gtk.SeparatorMenuItem()
            item.show()
            self.append(item)

            item = create_menuitem(_("_Disconnect"),
                                   get_icon("gtk-disconnect", 16))
            item.props.tooltip_text = _("Forcefully disconnect the device")

            self.append(item)
            item.show()

            def on_disconnect(item):
                def finished(*args):
                    self.unset_op(device)

                self.set_op(device, _("Disconnecting..."))
                self.Blueman.disconnect(device,
                                        reply_handler=finished,
                                        error_handler=finished)

            if device.Connected:
                self.Signals.Handle(item, "activate", on_disconnect)

            else:
                item.props.sensitive = False
Beispiel #6
0
    def Generate(self):
        self.clear()

        appl = AppletService()

        items = []

        if not self.is_popup or self.props.visible:
            selected = self.Blueman.List.selected()
            if not selected:
                return
            device = self.Blueman.List.get(selected, "device")["device"]
        else:
            (x, y) = self.Blueman.List.get_pointer()
            path = self.Blueman.List.get_path_at_pos(x, y)
            if path != None:
                device = self.Blueman.List.get(path[0], "device")["device"]
            else:
                return

        if not device.Valid:
            return
        self.SelectedDevice = device

        op = self.get_op(device)

        if op != None:
            item = create_menuitem(op, get_icon("network-transmit-recieve", 16))
            item.props.sensitive = False
            item.show()
            self.append(item)
            return

        rets = self.Blueman.Plugins.Run("on_request_menu_items", self, device)

        for ret in rets:
            if ret:
                for (item, pos) in ret:
                    items.append((pos, item))

        if device.Fake:
            item = create_menuitem(_("_Add Device"), get_icon("list-add", 16))
            self.Signals.Handle("gobject", item, "activate",
                                lambda x: self.Blueman.add_device(device))
            item.show()
            self.append(item)
            item.props.tooltip_text = _("Add this device to known devices list")

            item = create_menuitem(_("_Setup..."), get_icon("document-properties", 16))
            self.append(item)
            self.Signals.Handle("gobject", item, "activate",
                                lambda x: self.Blueman.setup(device))
            item.show()
            item.props.tooltip_text = _("Run the setup assistant for this device")

            item = create_menuitem(_("_Pair"), get_icon("dialog-password", 16))
            self.Signals.Handle("gobject", item, "activate",
                                lambda x: self.Blueman.bond(device))
            self.append(item)
            item.show()
            item.props.tooltip_text = _("Pair with the device")

            item = Gtk.SeparatorMenuItem()
            item.show()
            self.append(item)

            send_item = create_menuitem(_("Send a _File..."), get_icon("edit-copy", 16))
            self.Signals.Handle("gobject", send_item, "activate",
                                lambda x: self.Blueman.send(device))
            send_item.show()
            self.append(send_item)



        else:
            dprint(device.Alias)

            item = None

            have_disconnectables = False
            have_connectables = False

            if True in map(lambda x: x[0] >= 100 and x[0] < 200, items):
                have_disconnectables = True

            if True in map(lambda x: x[0] < 100, items):
                have_connectables = True

            if True in map(lambda x: x[0] >= 200, items) and (have_connectables or have_disconnectables):
                item = Gtk.SeparatorMenuItem()
                item.show()
                items.append((199, item))

            if have_connectables:
                item = Gtk.MenuItem()
                label = Gtk.Label()
                label.set_markup(_("<b>Connect To:</b>"))
                label.props.xalign = 0.0

                label.show()
                item.add(label)
                item.props.sensitive = False
                item.show()
                items.append((0, item))

            if have_disconnectables:
                item = Gtk.MenuItem()
                label = Gtk.Label()
                label.set_markup(_("<b>Disconnect:</b>"))
                label.props.xalign = 0.0

                label.show()
                item.add(label)
                item.props.sensitive = False
                item.show()
                items.append((99, item))

            items.sort(lambda a, b: cmp(a[0], b[0]))
            for priority, item in items:
                self.append(item)

            if items != []:
                item = Gtk.SeparatorMenuItem()
                item.show()
                self.append(item)

            del items

            send_item = create_menuitem(_("Send a _File..."), get_icon("edit-copy", 16))
            send_item.props.sensitive = False
            self.append(send_item)
            send_item.show()

            browse_item = create_menuitem(_("_Browse Device..."), get_icon("document-open", 16))
            browse_item.props.sensitive = False
            self.append(browse_item)
            browse_item.show()

            uuids = device.UUIDs
            for uuid in uuids:
                uuid16 = uuid128_to_uuid16(uuid)
                if uuid16 == OBEX_OBJPUSH_SVCLASS_ID:
                    self.Signals.Handle("gobject", send_item, "activate", lambda x: self.Blueman.send(device))
                    send_item.props.sensitive = True

                if uuid16 == OBEX_FILETRANS_SVCLASS_ID:
                    self.Signals.Handle("gobject", browse_item, "activate", lambda x: self.Blueman.browse(device))
                    browse_item.props.sensitive = True

            item = Gtk.SeparatorMenuItem()
            item.show()
            self.append(item)

            item = create_menuitem(_("_Pair"), get_icon("dialog-password", 16))
            item.props.tooltip_text = _("Create pairing with the device")
            self.append(item)
            item.show()
            if not device.Paired:
                self.Signals.Handle("gobject", item, "activate", lambda x: self.Blueman.bond(device))
            else:
                item.props.sensitive = False

            if not device.Trusted:
                item = create_menuitem(_("_Trust"), get_icon("blueman-trust", 16))
                self.Signals.Handle("gobject", item, "activate", lambda x: self.Blueman.toggle_trust(device))
                self.append(item)
                item.show()
            else:
                item = create_menuitem(_("_Untrust"), get_icon("blueman-untrust", 16))
                self.append(item)
                self.Signals.Handle("gobject", item, "activate", lambda x: self.Blueman.toggle_trust(device))
                item.show()
            item.props.tooltip_text = _("Mark/Unmark this device as trusted")

            item = create_menuitem(_("_Setup..."), get_icon("document-properties", 16))
            self.append(item)
            self.Signals.Handle("gobject", item, "activate", lambda x: self.Blueman.setup(device))
            item.show()
            item.props.tooltip_text = _("Run the setup assistant for this device")

            if BlueZInterface.get_interface_version()[0] < 5:
                def update_services(item):
                    def reply():
                        self.unset_op(device)
                        prog.message(_("Success!"))
                        MessageArea.close()

                    def error(*args):
                        self.unset_op(device)
                        prog.message(_("Fail"))
                        MessageArea.show_message(e_(str(args[0])))

                    prog = ManagerProgressbar(self.Blueman, False, _("Refreshing"))
                    prog.start()
                    self.set_op(device, _("Refreshing Services..."))
                    appl.RefreshServices(device.get_object_path(), reply_handler=reply, error_handler=error)

                item = create_menuitem(_("Refresh Services"), get_icon("view-refresh", 16))
                self.append(item)
                self.Signals.Handle(item, "activate", update_services)
                item.show()

            item = Gtk.SeparatorMenuItem()
            item.show()
            self.append(item)

            item = create_menuitem(_("_Remove..."), get_icon("edit-delete", 16))
            self.Signals.Handle(item, "activate", lambda x: self.Blueman.remove(device))
            self.append(item)
            item.show()
            item.props.tooltip_text = _("Remove this device from the known devices list")

            item = Gtk.SeparatorMenuItem()
            item.show()
            self.append(item)

            item = create_menuitem(_("_Disconnect"), get_icon("network-offline", 16))
            item.props.tooltip_text = _("Forcefully disconnect the device")

            self.append(item)
            item.show()

            def on_disconnect(item):
                def finished(*args):
                    self.unset_op(device)

                self.set_op(device, _("Disconnecting..."))
                self.Blueman.disconnect(device,
                                        reply_handler=finished,
                                        error_handler=finished)

            if device.Connected:
                self.Signals.Handle(item, "activate", on_disconnect)

            else:
                item.props.sensitive = False
Beispiel #7
0
    def on_request_menu_items(self, manager_menu, device):
        if BlueZInterface.get_interface_version()[0] < 5:
            return self.on_request_menu_items_bluez4(manager_menu, device)

        items = []
        uuids = device.UUIDs
        appl = AppletService()

        uuids16 = [uuid128_to_uuid16(uuid) for uuid in uuids]

        if set(uuids16) & set(self.connectable_uuids):
            # FIXME: This should only be done once!
            manager_menu.Signals.Handle("bluez", device,
                                        manager_menu.service_property_changed,
                                        "PropertyChanged")

            if device.get_properties()['Connected']:
                # FIXME: More generic icon
                item = create_menuitem(_("_Disconnect"),
                                       get_x_icon("mouse", 16))
                manager_menu.Signals.Handle("gobject", item, "activate",
                                            manager_menu.on_disconnect, device)
                items.append((item, 100))
            else:
                # FIXME: More generic icon
                item = create_menuitem(_("_Connect"), get_icon("mouse", 16))
                manager_menu.Signals.Handle("gobject", item, "activate",
                                            manager_menu.on_connect, device)
                items.append((item, 1))

            item.show()

        for name, service in device.Services.items():
            if name == "network":
                manager_menu.Signals.Handle(
                    "bluez", service, manager_menu.service_property_changed,
                    "PropertyChanged")
                sprops = service.get_properties()

                if not sprops["Connected"]:
                    for uuid in uuids:
                        uuid16 = uuid128_to_uuid16(uuid)
                        if uuid16 == NAP_SVCLASS_ID or uuid16 == GN_SVCLASS_ID:
                            label = _("Group Network"
                                      ) if uuid16 == GN_SVCLASS_ID else _(
                                          "Network Access _Point")
                            item = create_menuitem(
                                label, get_icon("network-wireless", 16))
                            manager_menu.Signals.Handle(
                                "gobject", item, "activate",
                                manager_menu.on_connect, device, name, uuid)
                            item.show()
                            items.append((item, 80))
                else:
                    item = create_menuitem(_("Network"),
                                           get_x_icon("network-wireless", 16))
                    manager_menu.Signals.Handle("gobject", item, "activate",
                                                manager_menu.on_disconnect,
                                                device, name)
                    item.show()
                    items.append((item, 101))

                    if "DhcpClient" in appl.QueryPlugins():

                        def renew(x):
                            appl.DhcpClient(sprops["Interface"])

                        item = create_menuitem(_("Renew IP Address"),
                                               get_icon("view-refresh", 16))
                        manager_menu.Signals.Handle("gobject", item,
                                                    "activate", renew)
                        item.show()
                        items.append((item, 201))

        return items