def __init__(self, device, adapter_path, files): super(Sender, self).__init__(title=_("Bluetooth File Transfer")) self.set_name("BluemanSendTo") self.set_position(Gtk.WindowPosition.CENTER) self.set_type_hint(Gdk.WindowTypeHint.DIALOG) self.props.border_width = 5 self.props.icon_name = "blueman" self.props.width_request = 400 self.b_cancel = self.add_button("_Stop", Gtk.ResponseType.CLOSE) self.b_cancel.props.receives_default = True self.b_cancel.props.use_underline = True self.b_cancel.connect("clicked", self.on_cancel) self.Builder = Gtk.Builder() self.Builder.set_translation_domain("blueman") bind_textdomain_codeset("blueman", "UTF-8") self.Builder.add_from_file(UI_PATH + "/send-dialog.ui") grid = self.Builder.get_object("sendto") content_area = self.get_content_area() content_area.add(grid) self.l_dest = self.Builder.get_object("l_dest") self.l_file = self.Builder.get_object("l_file") self.pb = self.Builder.get_object("pb") self.pb.props.text = _("Connecting") self.device = device self.adapter = Adapter(adapter_path) self.files = files self.object_push = None self.transfer = None self.total_bytes = 0 self.total_transferred = 0 self._last_bytes = 0 self._last_update = 0 self.error_dialog = None self.cancelling = False # bytes transferred on a current transfer self.transferred = 0 self.speed = SpeedCalc(6) for i in range(len(self.files) - 1, -1, -1): f = self.files[i] match = re.match("file://(.*)", f) if match: f = self.files[i] = urllib.parse.unquote(match.groups(1)[0]) if os.path.exists(f) and not os.path.isdir(f): f = os.path.abspath(f) self.total_bytes += os.path.getsize(f) else: self.files.remove(f) self.num_files = len(self.files) try: self.client = obex.Client() except GLib.Error as e: if 'StartServiceByName' in e.message: logging.debug(e.message) d = ErrorDialog( _("obexd not available"), _("Failed to autostart obex service. Make sure the obex " "daemon is running")) d.run() d.destroy() exit(1) else: # Fail on anything else raise if self.num_files == 0: exit(1) self.l_file.props.label = os.path.basename(self.files[-1]) self.client.connect('session-created', self.on_session_created) self.client.connect('session-failed', self.on_session_failed) self.client.connect('session-removed', self.on_session_removed) logging.info("Sending to %s" % device['Address']) self.l_dest.props.label = device['Alias'] # Stop discovery if discovering and let adapter settle for a second if self.adapter["Discovering"]: self.adapter.stop_discovery() time.sleep(1) self.create_session() self.show()
def __init__(self, device, adapter_path, files): super().__init__(title=_("Bluetooth File Transfer"), name="BluemanSendTo", icon_name="blueman", border_width=5, default_width=400, window_position=Gtk.WindowPosition.CENTER, type_hint=Gdk.WindowTypeHint.DIALOG) self.b_cancel = self.add_button("_Stop", Gtk.ResponseType.CLOSE) self.b_cancel.props.receives_default = True self.b_cancel.props.use_underline = True self.b_cancel.connect("clicked", self.on_cancel) self.Builder = Gtk.Builder(translation_domain="blueman") # bind_textdomain_codeset("blueman", "UTF-8") self.Builder.add_from_file(UI_PATH + "/send-dialog.ui") grid = self.Builder.get_object("sendto") content_area = self.get_content_area() content_area.add(grid) self.l_dest = self.Builder.get_object("l_dest") self.l_file = self.Builder.get_object("l_file") self.pb = self.Builder.get_object("pb") self.pb.props.text = _("Connecting") self.device = device self.adapter = Adapter(adapter_path) self.manager = Manager() self.files = [] self.num_files = 0 self.object_push = None self.transfer = None self.total_bytes = 0 self.total_transferred = 0 self._last_bytes = 0 self._last_update = 0 self.error_dialog = None self.cancelling = False # bytes transferred on a current transfer self.transferred = 0 self.speed = SpeedCalc(6) for file_name in files: parsed_file = Gio.File.parse_name(file_name) if not parsed_file.query_exists(): logging.info("Skipping non existing file %s" % parsed_file.get_path()) continue file_info = parsed_file.query_info("standard::*", Gio.FileQueryInfoFlags.NONE) if file_info.get_file_type() == Gio.FileType.DIRECTORY: logging.info("Skipping directory %s" % parsed_file.get_path()) continue self.files.append(parsed_file) self.num_files += 1 self.total_bytes += file_info.get_size() if len(self.files) == 0: self.emit("result", False) try: self.client = obex.Client() self.manager.connect_signal('session-added', self.on_session_added) self.manager.connect_signal('session-removed', self.on_session_removed) except GLib.Error as e: if 'StartServiceByName' in e.message: logging.debug(e.message) d = ErrorDialog( _("obexd not available"), _("Failed to autostart obex service. Make sure the obex " "daemon is running"), parent=self.get_toplevel()) d.run() d.destroy() self.emit("result", False) else: # Fail on anything else raise self.l_file.props.label = self.files[-1].get_basename() self.client.connect('session-failed', self.on_session_failed) logging.info("Sending to %s" % device['Address']) self.l_dest.props.label = device['Alias'] # Stop discovery if discovering and let adapter settle for a second if self.adapter["Discovering"]: self.adapter.stop_discovery() time.sleep(1) self.create_session() self.show()
def __init__(self, device, adapter, files): super(Sender, self).__init__(title=_("Bluetooth File Transfer")) self.set_name("BluemanSendTo") self.set_position(Gtk.WindowPosition.CENTER) self.set_type_hint(Gdk.WindowTypeHint.DIALOG) self.props.border_width = 5 self.props.icon_name = "blueman" self.props.width_request = 400 self.b_cancel = self.add_button("_Stop", Gtk.ResponseType.CLOSE) self.b_cancel.props.receives_default = True self.b_cancel.props.use_underline = True self.b_cancel.connect("clicked", self.on_cancel) self.Builder = Gtk.Builder() self.Builder.set_translation_domain("blueman") bind_textdomain_codeset("blueman", "UTF-8") self.Builder.add_from_file(UI_PATH + "/send-dialog.ui") grid = self.Builder.get_object("sendto") content_area = self.get_content_area() content_area.add(grid) self.l_dest = self.Builder.get_object("l_dest") self.l_file = self.Builder.get_object("l_file") self.pb = self.Builder.get_object("pb") self.pb.props.text = _("Connecting") self.device = device self.adapter = Adapter(adapter) self.files = files self.object_push = None self.transfer = None self.total_bytes = 0 self.total_transferred = 0 self._last_bytes = 0 self._last_update = 0 self.error_dialog = None self.cancelling = False #bytes transferred on a current transfer self.transferred = 0 self.speed = SpeedCalc(6) for i in range(len(self.files) - 1, -1, -1): f = self.files[i] match = re.match("file://(.*)", f) if match: f = self.files[i] = urllib.unquote(match.groups(1)[0]) if os.path.exists(f) and not os.path.isdir(f): f = os.path.abspath(f) self.total_bytes += os.path.getsize(f) else: self.files.remove(f) self.num_files = len(self.files) try: self.client = obex.Client() except obex.ObexdNotFoundError: d = Gtk.MessageDialog(self, type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.props.text = _("obexd not available") d.props.secondary_text = _("obexd is probably not installed") d.run() d.destroy() exit(1) if self.num_files == 0: exit(1) self.l_file.props.label = os.path.basename(self.files[-1]) self.client.connect('session-created', self.on_session_created) self.client.connect('session-failed', self.on_session_failed) self.client.connect('session-removed', self.on_session_removed) logging.info("Sending to %s" % device['Address']) self.l_dest.props.label = device['Alias'] self.create_session() self.show()