def create_widget(self, parent): from file_transfer.file_transfer_widget import FileTransferWidget from file_transfer.file_transfer_handler import FileTransferHandler if canUseBackgroundQThreads(): from PyQt4.QtCore import QThread self._handlerThread = QThread() else: self._handlerThread = None self._handler = FileTransferHandler(self.logger, self.get_option(u"download_dir"), self.get_option(u"overwrite"), self.get_option(u"compression")) if self._handlerThread is not None: self._handlerThread.moveToThread(self._handlerThread) self._handlerThread.start() self._gui = FileTransferWidget(parent, self.logger, self) self._toolWindow = FileTransferWidget(parent, self.logger, self, asWindow=True) self._toolWindow.setWindowTitle("File Transfers") for gui in (self._gui, self._toolWindow): gui.retry.connect(self._handler.retrySendFileToPeer) gui.cancel.connect(self._handler.cancelOutgoingTransfer) self._handler.startOutgoingTransfer.connect(gui.startOutgoingTransfer) self._handler.outgoingTransferStarted.connect(gui.outgoingTransferStarted) self._handler.outgoingTransferCanceled.connect(gui.outgoingTransferCanceled) self._handler.incomingTransferStarted.connect(gui.incomingTransferStarted) return self._gui
class file_transfer(iface_gui_plugin): VERSION_INITIAL = 0 VERSION_CURRENT = VERSION_INITIAL def __init__(self): super(file_transfer, self).__init__() self.options = [((u"download_dir", u"Save received files in directory", self._downloadDirChanged), os.path.join(os.path.expanduser("~"), "Downloads")), ((u"overwrite", u"Overwrite existing files", self._overwriteChanged), False), ((u"compression", u"Use compression when sending", self._compressionChanged, (u"No", u"GZip", u"BZip2")), u"No")] def get_displayed_name(self): return u"File Transfer" def activate(self): iface_gui_plugin.activate(self) self._sendFileAction = _TransferFileAction() def deactivate(self): iface_gui_plugin.deactivate(self) def create_widget(self, parent): from file_transfer.file_transfer_widget import FileTransferWidget from file_transfer.file_transfer_handler import FileTransferHandler if canUseBackgroundQThreads(): from PyQt4.QtCore import QThread self._handlerThread = QThread() else: self._handlerThread = None self._handler = FileTransferHandler(self.logger, self.get_option(u"download_dir"), self.get_option(u"overwrite"), self.get_option(u"compression")) if self._handlerThread is not None: self._handlerThread.moveToThread(self._handlerThread) self._handlerThread.start() self._gui = FileTransferWidget(parent, self.logger, self) self._toolWindow = FileTransferWidget(parent, self.logger, self, asWindow=True) self._toolWindow.setWindowTitle("File Transfers") for gui in (self._gui, self._toolWindow): gui.retry.connect(self._handler.retrySendFileToPeer) gui.cancel.connect(self._handler.cancelOutgoingTransfer) self._handler.startOutgoingTransfer.connect(gui.startOutgoingTransfer) self._handler.outgoingTransferStarted.connect(gui.outgoingTransferStarted) self._handler.outgoingTransferCanceled.connect(gui.outgoingTransferCanceled) self._handler.incomingTransferStarted.connect(gui.incomingTransferStarted) return self._gui def destroy_widget(self): for gui in (self._gui, self._toolWindow): gui.retry.disconnect(self._handler.retrySendFileToPeer) gui.cancel.disconnect(self._handler.cancelOutgoingTransfer) self._handler.startOutgoingTransfer.disconnect(gui.startOutgoingTransfer) self._handler.outgoingTransferStarted.disconnect(gui.outgoingTransferStarted) self._handler.outgoingTransferCanceled.disconnect(gui.outgoingTransferCanceled) self._handler.incomingTransferStarted.disconnect(gui.incomingTransferStarted) self._handler.deactivate() if self._handlerThread is not None: self._handlerThread.quit() self._handlerThread.wait() self._handlerThread.deleteLater() self._handlerThread = None self._handler = None iface_gui_plugin.destroy_widget(self) def extendsInfoDict(self): # do not except file transfers without GUI return lunchinator_has_gui() def extendInfoDict(self, infoDict): infoDict[u"FT_v"] = self.VERSION_CURRENT def get_peer_actions(self): return [self._sendFileAction] def process_event(self, cmd, value, peerIP, peerInfo, preprocessedData=None): if not cmd.startswith(u"HELO_FT"): return peerID = peerInfo[u"ID"] subcmd = cmd[7:] if subcmd == u"": self._handler.processSendRequest(peerID, peerIP, value, preprocessedData) elif subcmd == u"_ACK": self._handler.processAck(peerID, peerIP, value) elif subcmd == u"_CANCEL": self._handler.processCancel(peerID, value) def getSendFileAction(self): return self._sendFileAction def chooseAndSendFilesToPeer(self, peerID, parent): from PyQt4.QtGui import QFileDialog selectedFiles = QFileDialog.getOpenFileNames(parent, u"Chooses files to upload") if len(selectedFiles) > 0: self._handler.sendFilesToPeer([convert_string(f) for f in selectedFiles], peerID) def sendFilesToPeer(self, toSend, peerID): self._handler.sendFilesToPeer([convert_string(f) for f in toSend], peerID) def _downloadDirChanged(self, _setting, newVal): self._handler.downloadDirChanged(newVal) return newVal def _overwriteChanged(self, _setting, newVal): self._handler.overwriteChanged(newVal) return newVal def _compressionChanged(self, _setting, newVal): self._handler.compressionChanged(newVal) return newVal