def submit_torrent(self): p = Path(self._download_dir) try: name = self._torrent_filepath.name.replace('.torrent', '') pFinal = p.joinpath(name) pFinal.mkdir(parents=True, exist_ok=True) self._torrent_info.download_dir = str(pFinal) except Exception: messageBox('Cannot create torrent destination directory') return self._control.last_download_dir = os.path.abspath(self._download_dir) file_paths = [] for node, item in self._file_items: if item.checkState(0) == Qt.Checked: file_paths.append(node.path) if not self._torrent_info.download_info.single_file_mode: self._torrent_info.download_info.select_files( file_paths, 'whitelist') if self._ipfsadd_checkbox.checkState() == Qt.Checked: log.debug('Importing torrent to IPFS when complete') self._torrent_info.ipfsImportWhenComplete = True self._control_thread.loop.call_soon_threadsafe(self._control.add, self._torrent_info) self.close()
async def importVideoRecord(self, ipfsop, videoPath, name): fModel = ipfsop.ctx.currentProfile.filesModel entry = await ipfsop.addPath(str(videoPath), wrap=True, pin=self.ui.pinVideo.isChecked()) if entry: # Can remove it from disk now try: videoPath.unlink() except Exception: log.debug(f'Could not remove video {videoPath}') if self.ui.copyVideoToMfs.isChecked(): await ipfsop.filesLink(entry, fModel.itemVideos.path, name=f'{name}.dirw') self.app.mainWindow.fileManagerWidget.refreshItem( fModel.itemVideos) if self.ui.copyVideoCidToClipboard.isChecked(): try: # Copy the video's CID listing = await ipfsop.listObject(entry['Hash']) links = listing['Objects'].pop()['Links'] videoCid = links.pop()['Hash'] self.app.setClipboardText(videoCid) except Exception: # Fall back to copying the directory wrapper self.app.setClipboardText(entry['Hash']) else: messageBox('Could not import video')
def _add_magnet_triggered(self, *a): if self.magnetConverter.available: clipText = self.app.getClipboardText() magnetLink = inputTextCustom( label=iBtAddFromMagnetLink(), text=clipText if isMagnetLink(clipText) else '') if isMagnetLink(magnetLink): ensure(self.add_from_magnet(magnetLink)) else: messageBox('Invalid magnet link')
async def stop(self): self.mediaRecorder.stop() self.ui.statusbar.showMessage('') if self.videoLocation and await questionBoxAsync( 'Video import', 'Import video to your repository ?'): filePath = self.videoLocation.toLocalFile() if not os.path.isfile(filePath): return messageBox('Could not find captured video') basename = os.path.basename(filePath) name = inputTextCustom('Video import', 'Video filename', text=basename) if not name: return if name != basename: dst = Path(os.path.dirname(filePath)).joinpath(name) shutil.move(filePath, str(dst)) else: dst = Path(filePath) if name: ensure(self.importVideoRecord(dst, name))
def onSave(self): fPath = saveFileSelect() if fPath: file = QSaveFile(fPath) if not file.open(QIODevice.WriteOnly): return messageBox('Cannot open file for writing') file.write(self.logZone.toPlainText().encode()) file.commit()
def onPinRecursiveParent(self): if not self.ipfsPath: return messageBox(iNotAnIpfsResource()) parent = self.ipfsPath.parent() if parent and parent.valid: self.pinPath(parent.objPath, recursive=True) else: self.pinPath(self.ipfsPath.objPath, recursive=True)
async def onIpfsImport(self, ipfsop, *a): dialog = TorrentTransferDialog(self._state.suggested_name, self.state.download_dir, self.state.info_hash) await runDialogAsync(dialog) if dialog.result() == 1: opts = dialog.options() self._ipfs_import_button.setEnabled(False) if opts['removeTorrent']: log.debug(f'Removing torrent {self.state.info_hash}') if not self.waiting_control_action: self.waiting_control_action = True await self.control.remove(self.state.info_hash, purgeFiles=True) else: messageBox('Failed to import files')
async def importImageBuffer(self, ipfsop, buffer, extension): fModel = ipfsop.ctx.currentProfile.filesModel entry = await ipfsop.addBytes(bytes(buffer.data()), pin=self.ui.pinCapturedPhoto.isChecked()) if entry: if self.ui.copyPhotoToMfs.isChecked(): await ipfsop.filesLink(entry, fModel.itemPictures.path, name='camshot-{id}.{ext}'.format( id=int(time.time()), ext=extension)) self.app.mainWindow.fileManagerWidget.refreshItem( fModel.itemPictures) if self.ui.copyPhotoCidToClipboard.isChecked(): self.app.setClipboardText(entry['Hash']) else: messageBox('Could not import image')
def onCameraError(self): messageBox('Camera Error: {}'.format(self.camera.errorString()))
def onRecorderError(self): messageBox('Capture Error: {}'.format( self.mediaRecorder.errorString()))
def onPinPageLinks(self): if not self.ipfsPath: return messageBox(iNotAnIpfsResource()) ensure(self.sPinPageLinksRequested.emit(self.ipfsPath))
def onUnpin(self): if not self.ipfsPath: return messageBox(iNotAnIpfsResource()) ensure(self.unpinPath(self.ipfsPath))
def onPinRecursive(self): if not self.ipfsPath: return messageBox(iNotAnIpfsResource()) self.pinPath(self.ipfsPath.objPath, recursive=True)