def StartTransfer(self, request, context): start_time = GLib.get_monotonic_time() op = self.remote_machines[request.connect_name].lookup_op( request.timestamp) cancellable = threading.Event() op.file_send_cancellable = cancellable op.set_status(OpStatus.TRANSFERRING) op.progress_tracker = transfers.OpProgressTracker(op) op.current_progress_report = None sender = transfers.FileSender(op, self.service_name, request.timestamp, cancellable) def transfer_done(): if sender.error != None: op.set_error(sender.error) op.stop_transfer() op.set_status(OpStatus.FAILED_UNRECOVERABLE) elif op.file_send_cancellable.is_set(): print("File send cancelled") else: print("Transfer of %s files (%s) finished in %s" % \ (op.total_count, GLib.format_size(op.total_size),\ util.precise_format_time_span(GLib.get_monotonic_time() - start_time))) context.add_callback(transfer_done) return sender.read_chunks()
def StartTransfer(self, request, context): logging.debug("Server RPC: StartTransfer from '%s'" % request.readable_name) start_time = GLib.get_monotonic_time() try: remote = self.remote_machines[request.ident] except KeyError as e: logging.warning( "Server: start transfer is from unknown remote: %s" % e) return try: op = self.remote_machines[request.ident].lookup_op( request.timestamp) except KeyError as e: logging.warning("Server: start transfer for unknowns op: %s" % e) return cancellable = threading.Event() op.file_send_cancellable = cancellable op.set_status(OpStatus.TRANSFERRING) op.progress_tracker = transfers.OpProgressTracker(op) op.current_progress_report = None sender = transfers.FileSender(op, request.timestamp, cancellable) def transfer_done(): if sender.error != None: op.set_error(sender.error) op.stop_transfer() op.set_status(OpStatus.FAILED_UNRECOVERABLE) elif op.file_send_cancellable.is_set(): logging.debug("Server: file send cancelled") else: logging.debug("Server: transfer of %s files (%s) finished in %s" % \ (op.total_count, GLib.format_size(op.total_size),\ util.precise_format_time_span(GLib.get_monotonic_time() - start_time))) context.add_callback(transfer_done) return sender.read_chunks()
def __init__(self, app_name, app_nick, proxy_name, proxy, proxy_ip, proxy_port): super(ProxyItem, self).__init__() self.app_name = app_name self.app_nick = app_nick self.proxy = proxy self.proxy_name = proxy_name self.proxy_nick = "" self.proxy_ip = proxy_ip self.proxy_port = proxy_port self.sort_key = proxy_name self.send_stat_delay_timer = 0 self.receive_stat_delay_timer = 0 self.dropping = False self.sort_order = 0 # Don't allow the local user to drop more files if we're already waiting on a previous request self.blocking_new_sends = False self.active_receive_request = None self.builder = Gtk.Builder.new_from_file( os.path.join(config.pkgdatadir, "warp-window.ui")) self.widget = self.builder.get_object("proxy_widget") self.page_stack = self.builder.get_object("page_stack") self.status_page = self.builder.get_object("status_page") self.nick_label = self.builder.get_object("nick_label") self.progress_box = self.builder.get_object("progress_box") self.send_progress_bar = self.builder.get_object("send_progress_bar") self.receive_progress_bar = self.builder.get_object( "receive_progress_bar") self.sender_awaiting_approval_label = self.builder.get_object( "sender_awaiting_approval_label") self.sender_awaiting_approval_cancel_button = self.builder.get_object( "sender_awaiting_approval_cancel_button") self.send_file_menu_button = self.builder.get_object( "send_file_menu_button") self.req_transfer_label = self.builder.get_object("req_transfer_label") self.problem_info_label = self.builder.get_object("problem_info_label") self.problem_more_info_label = self.builder.get_object( "problem_more_info_label") self.connecting_label = self.builder.get_object("connecting_label") self.sender_awaiting_approval_cancel_button.connect( "clicked", self.cancel_send_request) self.recent_menu = Gtk.RecentChooserMenu( show_tips=True, sort_type=Gtk.RecentSortType.MRU, show_not_found=False) self.recent_menu.connect("item-activated", self.recent_item_selected) self.send_file_menu_button.set_popup(self.recent_menu) self.recent_menu.add(Gtk.SeparatorMenuItem(visible=True)) picker = Gtk.MenuItem(label=_("Browse..."), visible=True) picker.connect("activate", self.open_file_picker) self.recent_menu.add(picker) self.proxy.lock = threading.Lock() self.file_sender = transfers.FileSender(self.app_name, self.proxy_name, self.proxy_nick, self.proxy, self.send_progress_callback) entry = Gtk.TargetEntry.new("text/uri-list", 0, 0) self.status_page.drag_dest_set(Gtk.DestDefaults.ALL, (entry, ), Gdk.DragAction.COPY) self.status_page.connect("drag-drop", self.on_drag_drop) self.status_page.connect("drag-data-received", self.on_drag_data_received) self.status_page.connect("drag-motion", self.on_drag_motion) self.show_connecting() self.pulse = pulse.Pulse(self.proxy, self.proxy_ip, self.proxy_port) self.pulse.connect("state-changed", self.pulse_state_changed) self.pulse.start() self.hide_receive_stats() self.hide_send_stats() self.widget.show_all()