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")
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")
def _on_authorize(self, parameters, invocation): def on_action(action): logging.info("Action %s" % 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 address = session.address filename = transfer.name size = transfer.size try: adapter = self._applet.Manager.get_adapter() device = self._applet.Manager.find_device(address, adapter.get_object_path()) name = device["Alias"] trusted = device["Trusted"] except Exception as e: logging.exception(e) name = address trusted = False self._pending_transfer = {'transfer_path': transfer_path, 'address': address, 'root': root, 'filename': filename, 'size': size, 'name': name} notif_kwargs = {"icon_name": "blueman"} try: notif_kwargs["pos_hint"] = self._applet.Plugins.StatusIcon.geometry except AttributeError: logging.error("Failed to get StatusIcon") # 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>" + escape(filename) + "</b>", "1": "<b>" + escape(name) + "</b>"}, 30000, [["accept", _("Accept"), "help-about"], ["reject", _("Reject"), "help-about"]], on_action, **notif_kwargs) self._notification.show() # 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>" + escape(filename) + "</b>", "1": "<b>" + escape(name) + "</b>"}, **notif_kwargs) on_action('accept') self._notification.show() # Device is trusted or was already allowed. very small file -> auto-accept and transfer silently else: self._notification = None on_action("accept")