def __init__(self, sWidget, parent=None): super().__init__(sWidget) self.app = runningApp() self.currentServiceItem = None self.sWidget = sWidget if 0: self.sWidget.ui.vLayout.insertWidget( 0, LabelWithURLOpener('<a href="manual:/pinning.html#remote">' 'Remote pinning manual' '</a>')) self.sWidget.ui.removeService.setEnabled(False) self.sWidget.ui.rServiceConfigGroup.setEnabled(False) self.sWidget.ui.rPinServiceAddButton.clicked.connect( partialEnsure(self.onNewRemoteService)) self.sWidget.ui.removeService.clicked.connect( partialEnsure(self.onRemoveService)) self.sWidget.ui.rPinServices.currentItemChanged.connect( self.onCurrentServiceChanged) self.iconSelector = IconSelector() self.sWidget.ui.srvGridLayout.addWidget(self.iconSelector, 1, 1) self.sWidget.ui.rpsPriority.valueChanged.connect(self.servicePatch) self.iconSelector.iconSelected.connect(self.servicePatch)
def __init__(self, parent=None): super().__init__(parent) self.app = runningApp() self.ui = ui_dmessenger.Ui_MessengerForm() self.ui.setupUi(self) self.modelContacts = BMContactsModel(self) self.messenger = Messenger(self.ui.mailBoxStack, self) self.messageView = MessageViewer(self) self.messageView.msgReplyStart.connect(self.onReplyToMessage) self.messageView.msgComposeNewReq.connect(self.composeMessage) self.messageComposer = MessageComposer(bmModel=self.modelContacts, parent=self) self.messageComposer.cancelled.connect(self.setDefaultView) self.messageComposer.sendSuccess.connect(self.onSendSuccess) self.sIdxView = self.ui.mailStack.addWidget(self.messageView) self.sIdxCompose = self.ui.mailStack.addWidget(self.messageComposer) self.ui.createMailboxButton.clicked.connect( partialEnsure(self.onCreateMailbox)) self.ui.copyBmKeyButton.clicked.connect(partialEnsure( self.onCopyBmKey)) self.ui.composeButton.clicked.connect(self.onComposeClicked) self.ui.curMailboxCombo.currentIndexChanged.connect( partialEnsure(self.onMailBoxSelect)) self.setDefaultView()
def setupWorkspace(self): super().setupWorkspace() fileManager = self.app.mainWindow.fileManagerWidget self.fileManagerTab = files.FileManagerTab( self.app.mainWindow, fileManager=fileManager ) self.seedsTab = seeds.SeedsTrackerTab(self.app.mainWindow) icon = getIcon('folder-open.png') self.wsRegisterTab(self.fileManagerTab, iFileManager(), icon) self.wsRegisterTab(self.seedsTab, iFileSharing(), getIcon('fileshare.png')) self.wsAddAction(fileManager.addFilesAction) self.wsAddAction(fileManager.addDirectoryAction) self.wsAddAction(fileManager.newSeedAction) self.actionTorrentClient = self.wsAddCustomAction( iBitTorrentClient(), getIcon('torrent.png'), iBitTorrentClient(), partialEnsure(self.onStartTorrentClient) ) self.actionGc = self.wsAddCustomAction( 'gc', getIcon('clear-all.png'), iGarbageCollectRun(), partialEnsure(self.onRunGC) )
def setupWorkspace(self): # Workspace's tab widget and toolbars self.tabWidget = MainTabWidget(self) self.wLayout.addWidget(self.tabWidget) self.tabWidget.setElideMode(Qt.ElideMiddle) self.tabWidget.setUsesScrollButtons(True) self.tabWidget.onTabRemoved.connect( partialEnsure(self.wsTabRemoved)) self.tabWidget.currentChanged.connect( partialEnsure(self.wsTabChanged)) self.tabWidget.tabCloseRequested.connect( partialEnsure(self.onTabCloseRequest)) self.tabWidget.tabBarDoubleClicked.connect( partialEnsure(self.onTabDoubleClicked)) if self.app.system != 'Darwin': self.tabWidget.setDocumentMode(True) # Set the corner widgets # Workspace actions on the left, the right toolbar is unused for now self.setCornerRight(self.toolBarCtrl) self.setCornerLeft(self.toolBarActions)
async def loadDidFromGraph(self, ipfsop, peerId: str, did: str, sHandle: str): loadTimeout = cGet('peers.didLoadTimeout') loadAttempts = cGet('peers.didLoadAttempts') peersService = ipfsop.ctx.pubsub.byTopic(TOPIC_PEERS) for attempt in range(0, max(2, loadAttempts)): ipid = await self.app.ipidManager.load( did, track=True, timeout=loadTimeout, localIdentifier=(peerId == ipfsop.ctx.node.id) ) if not ipid: log.debug(f'Cannot load IPID: {did}, attempt {attempt}') await ipfsop.sleep(cGet('peers.didFail.sleepInterval')) continue else: break if not ipid: log.debug(f'Cannot load IPID: {did}, bailing out') self._didGraphLStatus.remove(did) return False piCtx = PeerIdentityCtx( self.ctx, sHandle.peer, str(sHandle), ipid, validated=True, authenticated=True ) ipid.sChanged.connectTo(partialEnsure( self.onPeerDidModified, piCtx)) piCtx.sStatusChanged.connectTo(partialEnsure( self.peerModified.emit, piCtx)) async with self.lock.writer_lock: self._byHandle[str(sHandle)] = piCtx if piCtx.peerId not in self._byPeerId: self._byPeerId[piCtx.peerId] = piCtx log.debug(f'Loaded IPID from graph: {did}') await self.peerAdded.emit(piCtx) await ipfsop.sleep(1) await peersService.sendIdentReq(piCtx.peerId) self._didGraphLStatus.remove(did) return True
def onContextMenu(self, point): idx = self.ui.treeFeeds.indexAt(point) if not idx.isValid(): return item = self.model.itemFromIndex(idx) if isinstance(item, AtomFeedItem): menu = QMenu(self) menu.addAction('Mark all as read', partialEnsure(self.onMarkAllRead, item)) menu.addAction('Remove feed', partialEnsure(self.onRemoveFeed, item)) menu.addSeparator() menu.exec(self.ui.treeFeeds.mapToGlobal(point))
def __init__(self, treeItem, obj, parent=None): super().__init__(parent) self.sDownload = AsyncSignal() self.treeItem = treeItem self.obj = obj self.ipfsPath = IPFSPath(self.obj.get('path')) self.hlayout = QHBoxLayout(self) self.setLayout(self.hlayout) self.btnOpen = QPushButton(iOpen()) self.btnOpen.setText(iOpen()) self.btnOpen.setIcon(getIcon('open.png')) self.btnOpen.clicked.connect(partialEnsure(self.onOpen)) self.btnHashmark = HashmarkThisButton(self.ipfsPath) self.btnClipboard = IPFSPathClipboardButton(self.ipfsPath) self.btnDownload = QToolButton(self) self.btnDownload.setText('Download') self.btnDownload.clicked.connect(self.onDl) self.btnDownload.hide() self.hlayout.addWidget(self.btnClipboard) self.hlayout.addWidget(self.btnHashmark) self.hlayout.addWidget(self.btnOpen) self.hlayout.addWidget(self.btnDownload)
async def onNeedUserConfirm(self, ipfsPath, mimeType, secureFlag): await runDialogAsync(ResourceOpenConfirmDialog, ipfsPath, mimeType, secureFlag, accepted=partialEnsure(self.onOpenConfirmed, ipfsPath, mimeType))
def setupWorkspace(self): super().setupWorkspace() self.pinStatusTab = pinstatus.PinStatusWidget( self.app.mainWindow, sticky=True) self.wsRegisterTab( self.pinStatusTab, iPinningStatus(), icon=getIcon('pin-zoom.png')) self.wsRegisterTab( self.settingsCenter, iSettings(), icon=getIcon('settings.png') ) self.actionConfigure = self.wsAddCustomAction( 'config', getIcon('settings.png'), iConfigurationEditor(), self.openConfigEditor ) if shutil.which('dot'): # Only if we have graphviz's dot self.wsAddCustomAction( 'app-graph', getIcon('ipld.png'), 'Application graph', partialEnsure(self.openAppGraph) )
def __init__(self, channel, psService, gWindow): super(ChatRoomWidget, self).__init__(gWindow) self.lock = asyncio.Lock() self.participantsModel = ParticipantsModel(self) self.participantsModel.setHorizontalHeaderLabels(['SpaceHandle', 'HB']) self.channel = channel self.subscriber = psSubscriber(psService.topic) self.psService = psService self.subscriber.add_async_listener(self.psService.psKey, self.onChatMessageReceived) self.chatWidget = QWidget() self.vLayout.addWidget(self.chatWidget) self.ui = ui_chatroom.Ui_Form() self.ui.setupUi(self.chatWidget) self.ui.chatLog.setOpenExternalLinks(False) self.ui.chatLog.setOpenLinks(False) self.ui.chatLog.anchorClicked.connect( partialEnsure(self.onAnchorClicked)) self.ui.sendButton.clicked.connect(self.onSendMessage) self.ui.message.returnPressed.connect(self.onSendMessage) self.ui.message.setFocusPolicy(Qt.StrongFocus) self.ui.chatLog.setFocusPolicy(Qt.NoFocus) self.ui.usersView.setModel(self.participantsModel) self.ui.usersView.hideColumn(0)
def __init__(self, profile, parent=None): super().__init__(parent) self.setObjectName('profileEditDialog') self.app = QApplication.instance() self.profile = profile self.ui = ui_profileeditdialog.Ui_ProfileEditDialog() self.ui.setupUi(self) self.ui.pEditTabWidget.setCurrentIndex(0) self.updateProfile() self.ui.labelWarning.setStyleSheet('QLabel { font-weight: bold; }') self.ui.labelInfo.setStyleSheet('QLabel { font-weight: bold; }') self.ui.labelWarning.linkActivated.connect(self.onLabelAnchorClicked) self.ui.profileDid.setText('<b>{0}</b>'.format( self.profile.userInfo.personDid)) self.ui.lockButton.toggled.connect(self.onLockChange) self.ui.lockButton.setChecked(True) self.ui.changeIconButton.clicked.connect(self.changeIcon) self.ui.closeButton.clicked.connect(self.close) self.ui.generateIdentityButton.clicked.connect( partialEnsure(self.onNewIdentity)) self.reloadIcon()
async def runDialogAsync(dlgarg, *args, **kw): title = kw.pop('title', None) accepted = kw.pop('accepted', None) if inspect.isclass(dlgarg): dlgW = dlgarg(*args, **kw) else: dlgW = dlgarg if hasattr(dlgW, 'initDialog') and asyncio.iscoroutinefunction( dlgW.initDialog): await dlgW.initDialog() if title: dlgW.setWindowTitle(title) if accepted: if asyncio.iscoroutinefunction(accepted): dlgW.accepted.connect(partialEnsure(accepted, dlgW)) else: dlgW.accepted.connect(functools.partial(accepted, dlgW)) dlgW.show() if hasattr(dlgW, 'preExecDialog') and asyncio.iscoroutinefunction( dlgW.preExecDialog): await dlgW.preExecDialog() await threadExec(dlgW.exec_) return dlgW
async def onShowChannels(self, ipfsop): dagChannels = ipfsop.ctx.currentProfile.dagChatChannels self.chanMenu.clear() for channel in dagChannels.channels: self.chanMenu.addAction( getIcon('qta:mdi.chat'), channel, partialEnsure(self.chans.onJoinChannel, channel))
def __init__(self, seed, *args): super().__init__(seed, *args, type=seedingItemType) self.app = QApplication.instance() self.tasks = [] self.ctrl = StoredSeedActionsWidget(self) self.ctrl.seedRemove.connect(partialEnsure(self.onRemove)) self.objActiveCount = 0
async def populateRpsQuick(self, menu): srvCount = 0 actionPinRpsAll = QAction(self.iconPinRed, iPinToAllRps(), self) actionPinRpsAll.setToolTip(iPinToAllRpsToolTip()) actionPinRpsAll.triggered.connect(partialEnsure(self.onPinToRpsAll)) for srv in cfgpinning.rpsList(): actionPinS = QAction(self.iconPinRed, iPinToRps(srv.displayName), self) actionPinS.setToolTip(iPinToRpsToolTip(srv.displayName)) actionPinS.triggered.connect(partialEnsure(self.onPinToRps, srv)) actionUnpin = QAction(getIcon('cancel.png'), iUnpinFromRps(srv.displayName), self) actionUnpin.setToolTip(iUnpinFromRpsToolTip(srv.displayName)) actionUnpin.triggered.connect( partialEnsure(self.onUnpinFromRps, srv)) actionPinC = QAction(self.iconPinRed, iPinToRpsWithName(srv.displayName), self) actionPinC.setToolTip(iPinToRpsToolTip(srv.displayName)) actionPinC.triggered.connect( partialEnsure(self.onPinToRpsWithName, srv)) sMenu = QMenu(srv.displayName, menu) sMenu.setIcon(self.iconPinRed) menu.addAction(actionPinS) menu.addSeparator() menu.addAction(actionUnpin) menu.addSeparator() # menu.addAction(actionPinC) # menu.addSeparator() srvCount += 1 if srvCount > 0: menu.addAction(actionPinRpsAll) menu.addSeparator()
def __init__(self, gWindow): super().__init__(gWindow) self.app = QApplication.instance() self.posting = 0 buttonBox = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self) self.title = QLineEdit() self.title.setMaximumWidth(600) self.title.setAlignment(Qt.AlignCenter) self.title.textEdited.connect(self.onTitleEdited) regexp = QRegExp(r"[\w_-\s.,:;\"'?]+") self.title.setValidator(QRegExpValidator(regexp)) self.title.setMaxLength(128) titleLayout = QHBoxLayout() titleLayout.setSpacing(64) titleLayout.addItem( QSpacerItem(100, 10, QSizePolicy.Minimum, QSizePolicy.Minimum)) titleLayout.addWidget(QLabel('Title')) titleLayout.addWidget(self.title) titleLayout.addItem( QSpacerItem(10, 10, QSizePolicy.Expanding, QSizePolicy.Minimum)) self.markdownInput = MarkdownInputWidget() self.vLayout.setContentsMargins(20, 20, 20, 20) self.vLayout.addLayout(titleLayout) self.vLayout.addWidget(self.markdownInput) self.vLayout.addWidget(buttonBox, 0, Qt.AlignCenter) buttonBox.accepted.connect(partialEnsure(self.process)) buttonBox.rejected.connect(partialEnsure(self.postCancelled)) self.title.setFocus(Qt.OtherFocusReason)
def __init__(self, parent=None): super().__init__(parent) self.app = runningApp() self.ui = ui_dmessenger_messageview.Ui_MessengerMailView() self.ui.setupUi(self) self.ui.replyButton.setEnabled(False) self.ui.replyButton.clicked.connect(self.onReply) self.browser.setOpenExternalLinks(False) self.browser.setOpenLinks(False) self.browser.anchorClicked.connect( partialEnsure(self.onOpenMessageLink))
async def onShowPopularTags(self): self.popularTagsMenu.clear() tags = await database.hashmarksPopularTags(limit=20) for tag in tags: menu = QMenu(tag.name, self.popularTagsMenu) menu.setIcon(getIcon('ipfs-logo-128-white.png')) menu.menuAction().setData(tag) menu.triggered.connect( lambda action: ensure(self.linkActivated(action))) self.popularTagsMenu.addMenu(menu) menu.aboutToShow.connect( partialEnsure(self.onShowTagHashmarks, menu))
async def onShowTagHashmarks(self, menu): menu.clear() menu.setToolTipsVisible(True) tag = menu.menuAction().data() if 0: menu.addAction(self.icon(), 'Follow this tag', lambda: partialEnsure(self.onFollowTag, tag.name)) hashmarks = await database.hashmarksByTags([tag.name], strict=True, limit=30) for hashmark in hashmarks: await hashmark._fetch_all() menu.addAction(self.makeHashmarkAction(hashmark))
def __init__(self, bmModel=None, parent=None): super().__init__(parent) self.app = runningApp() self.completer = ComposeRecipientCompleter(self) self.completer.setCompletionMode(QCompleter.PopupCompletion) self.completer.setCaseSensitivity(Qt.CaseInsensitive) self.completer.setCompletionColumn(1) self.completer.setModel(bmModel) self.ui = ui_dmessenger_compose.Ui_MessageComposerForm() self.ui.setupUi(self) self.ui.sendButton.clicked.connect(partialEnsure(self.onSend)) self.ui.cancelButton.clicked.connect(self.onCancelClicked) self.ui.msgTo.setCompleter(self.completer) self.ui.msgTo.textChanged.connect(self.onRecpChanged)
def viewHash(self, hashRef, addClose=False, autoOpenFolders=False, parentView=None): view = IPFSHashExplorerWidget(hashRef, parent=self, addClose=addClose, showCidLabel=True, autoOpenFolders=autoOpenFolders, parentView=parentView) view.closeRequest.connect(partialEnsure(self.remove, view)) view.directoryOpenRequest.connect(lambda nView, cid: self.viewHash( cid, addClose=True, parentView=nView)) self.stack.insertWidget(self.stack.count(), view) self.stack.setCurrentWidget(view) view.reFocus() return True
def setupMenu(self): self.menu.setObjectName('hashmarksMgrMenu') self.menu.setToolTipsVisible(True) self.sourcesMenu = QMenu(iHashmarkSources()) self.sourcesMenu.setIcon(self.icon()) self.popularTagsMenu = QMenu('Popular Tags') self.popularTagsMenu.setObjectName('popularTagsMenu') self.popularTagsMenu.setIcon(getIcon('hash.png')) self.popularTagsMenu.aboutToShow.connect( partialEnsure(self.onShowPopularTags)) self.syncAction = QAction( self.icon(), iHashmarkSourcesDbSync(), self.sourcesMenu, triggered=lambda: ensure(self.onSynchronize())) self.addGitSourceAction = QAction( self.icon(), iHashmarkSourcesAddGitRepo(), self.sourcesMenu, triggered=self.onAddGitHashmarkSource) self.addIpfsMarksSourceAction = QAction( self.icon(), iHashmarkSourcesAddLegacyIpfsMarks(), self.sourcesMenu, triggered=lambda: ensure(self.onAddIpfsMarksSource())) self.sourcesMenu.addAction(self.syncAction) self.sourcesMenu.addSeparator() self.sourcesMenu.addAction(self.addGitSourceAction) self.sourcesMenu.addSeparator() self.sourcesMenu.addAction(self.addIpfsMarksSourceAction) self.menu.addMenu(self.sourcesMenu) self.menu.addSeparator() self.menu.addMenu(self.popularTagsMenu) self.menu.addSeparator() self.app.hmSynchronizer.syncing.connectTo(self.onSynchronizing)
def __init__(self, treeItem, seed, parent=None): super().__init__(parent) self.treeItem = treeItem self.seedDag = seed layout = QHBoxLayout(self) self.setLayout(layout) icon = getIcon('pin.png') combo = QComboBox() combo.setObjectName('seedActionsCombo') combo.addItem(icon, iPin()) combo.addItem(icon, iPinAndDownload()) combo.addItem(getIcon('download.png'), iDownloadOnly()) combo.activated.connect(partialEnsure(self.onComboActivated)) layout.addWidget(combo) layout.addItem( QSpacerItem(10, 10, QSizePolicy.Expanding, QSizePolicy.Minimum))
def tabSetup(self): self.setContentsMargins(8, 8, 8, 8) self.wLabel = QLabel(iConfigurationEditorWarning()) self.tree = QTreeWidget(self) self.delegate = ConfigItemDelegate(self.tree) self.delegate.attributeChanged.connect(self.onAttrChanged) self.tree.setColumnCount(3) self.tree.setHeaderLabels(['Setting', 'Value', '']) self.tree.setHeaderHidden(True) self.tree.setItemDelegateForColumn(1, self.delegate) self.tree.itemDoubleClicked.connect(partialEnsure(self.onDoubleClick)) self.tree.header().setSectionResizeMode(QHeaderView.ResizeToContents) self.tree.header().setStretchLastSection(False) self.addToLayout(self.wLabel) self.addToLayout(self.tree) self.setEnabled(False) ensureSafe(self.load())
def singleContextMenu(self, point, rows): item = self.model.getUnixFSEntryInfoFromIdx(rows.pop()) menu = QMenu(self) pinAction = PinObjectAction(item.ipfsPath, parent=menu, pinQueueName='unixfs', buttonStyle='iconAndText') def download(): dirSel = directorySelect() self.app.task(self.getResource, item.getFullPath(), dirSel) menu.addAction(pinAction) menu.addSeparator() menu.addAction(getIcon('clipboard.png'), iCopyCIDToClipboard(), functools.partial(self.app.setClipboardText, item.cid)) menu.addAction( getIcon('clipboard.png'), iCopyPathToClipboard(), functools.partial(self.app.setClipboardText, item.getFullPath())) menu.addAction( getIcon('clipboard.png'), iCopyPubGwUrlToClipboard(), functools.partial(self.app.setClipboardText, item.ipfsPath.publicGwUrl)) menu.addSeparator() menu.addAction( getIcon('hashmarks.png'), iHashmark(), partialEnsure(addHashmarkAsync, item.ipfsPath.objPath, item.filename)) menu.addSeparator() menu.addAction(iDownload(), download) menu.exec(self.dirListView.mapToGlobal(point))
def __init__(self, manager=None, parent=None): super().__init__(parent) self.manager = manager self.setWindowTitle(iNewBlogPost()) self.app = QApplication.instance() self.contents = None buttonBox = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self) mainLayout = QVBoxLayout() self.title = QLineEdit() regexp = QRegExp(r"[\w_-\s@\'\",\.]+") self.title.setValidator(QRegExpValidator(regexp)) self.title.setMaxLength(92) titleLayout = QHBoxLayout() titleLayout.addWidget(QLabel('Title')) titleLayout.addWidget(self.title) self.markdownInput = MarkdownInputWidget(self) mainLayout.addLayout(titleLayout) mainLayout.addWidget( QLabel('''<p align="center">You can drag-and-drop IPFS files in the Markdown input editor</p>''')) mainLayout.addWidget(self.markdownInput) mainLayout.addWidget(buttonBox) self.setLayout(mainLayout) buttonBox.accepted.connect(partialEnsure(self.accept)) buttonBox.rejected.connect(self.reject) self.title.setFocus(Qt.OtherFocusReason)
def __init__(self, maildir: BitMessageMailDir, parent=None): super().__init__(parent) self.app = QApplication.instance() self.maildir = maildir self.currentItemChanged.connect(partialEnsure( self.onCurMessageChanged)) self.setColumnCount(2) self.setHeaderLabels(['Subject', 'Date']) self.setHeaderHidden(True) self.setSortingEnabled(True) self.sMessageNeedsDisplay = AsyncSignal(MaildirMessage) self.viewActive.connect(self.onViewSwitched) self.fontNoBold = QFont(self.font()) self.fontNoBold.setBold(False) self.fontBold = QFont(self.font()) self.fontBold.setBold(True) self.header().setSectionResizeMode(0, QHeaderView.ResizeToContents) self.hideColumn(1)
def onFsViewRightClicked(self, idx, event, fInfo): pos = event.globalPos() fullPath = fInfo.absoluteFilePath() _path = Path(fullPath) menu = QMenu(self) if not _path.exists() or _path.is_dir(): menu.addAction( self.strokeIcon, iAddNewFile(), functools.partial( self.fsAddFile, fullPath)) menu.addSeparator() menu.addAction( self.strokeIcon, iAddNewDir(), functools.partial( self.fsAddDirectory, fullPath)) menu.addSeparator() menu.addAction( self.strokeIcon, iImportFile(), functools.partial( self.fsImportFile, fullPath)) menu.addSeparator() menu.addAction( self.strokeIcon, iImportDir(), functools.partial( self.fsImportDirectory, fullPath)) menu.addSeparator() menu.addAction( getIcon('clear-all.png'), 'Delete', partialEnsure(self.fsDelete, fullPath) ) menu.exec_(pos)
def onPinStatusChanged(self, qname, path, statusInfo): nodesProcessed = statusInfo['status'].get('Progress', iUnknown()) idx = self.getIndexFromPath(path) if not idx: # Register it btnCancel = QToolButton() btnCancel.setIcon(getIcon('cancel.png')) btnCancel.setText(iCancel()) btnCancel.clicked.connect(partialEnsure(self.onCancel, qname, path)) btnCancel.setFixedWidth(140) displayPath = path if len(displayPath) > 64: displayPath = displayPath[0:64] + ' ..' itemTs = UneditableItem(str(statusInfo['ts_queued'])) itemQ = UneditableItem(qname) itemP = UneditableItem(displayPath) itemP.setData(path, PinObjectPathRole) itemP.setToolTip(path) itemP.lastProgressUpdate = time.time() itemStatus = UneditableItem(iPinning()) itemProgress = UneditableItem(str(nodesProcessed)) itemC = UneditableItem('') self.model.invisibleRootItem().appendRow( [itemTs, itemQ, itemP, itemStatus, itemProgress, itemC]) idx = self.model.indexFromItem(itemC) self.tree.setIndexWidget(idx, btnCancel) self.resort() else: self.updatePinStatus(path, iPinning(), str(nodesProcessed))
async def registerFromIdent(self, ipfsop, sender, iMsg): profile = ipfsop.ctx.currentProfile log.debug(f'registerFromIdent ({iMsg.peer}): ' f'DID: {iMsg.personDid}, handle: {iMsg.iphandle}') try: inGraph = await profile.dagNetwork.byDid(iMsg.personDid) except Exception: # network dag not ready .. log.debug(f'registerFromIdent {iMsg.personDid}: ' 'network DAG not loaded yet ?') return if not inGraph: if isinstance(iMsg, PeerIdentMessageV4) and \ sender != ipfsop.ctx.node.id: pubKeyPem = await ipfsop.rsaPubKeyCheckImport( iMsg.defaultRsaPubKeyCid) if not pubKeyPem: log.debug( f'Invalid RSA pub key .. {iMsg.defaultRsaPubKeyCid}') return sigBlob = await ipfsop.catObject(iMsg.pssSigCurDid) if sigBlob is None: log.debug( f'Cannot get pss SIG {iMsg.pssSigCurDid}') return if not await ipfsop.ctx.rsaExec.pssVerif( iMsg.personDid.encode(), sigBlob, pubKeyPem ): log.debug(f'Invalid PSS sig for peer {sender}') return else: log.debug(f'Valid PSS sig for {sender} !') peerValidated = False personDid = iMsg.personDid if not ipidFormatValid(personDid): log.debug('Invalid DID: {}'.format(personDid)) return inProgress = self._didAuthInp.get(personDid, False) if inProgress is True: log.debug(f'registerFromIdent {iMsg.personDid}: ' f'authentication in progress') return self._didAuthInp[personDid] = True try: mType, stat = await self.app.rscAnalyzer(iMsg.iphandleqrpngcid) except Exception: log.debug('Cannot stat QR: {}'.format(iMsg.iphandleqrpngcid)) self._didAuthInp[personDid] = False return else: statInfo = StatInfo(stat) if not statInfo.valid or statInfo.dataLargerThan( kilobytes(512)) or not mType or not mType.isImage: log.debug('Invalid stat for QR: {}'.format( iMsg.iphandleqrpngcid)) self._didAuthInp[personDid] = False return if not await self.validateQr( iMsg.iphandleqrpngcid, iMsg) is True: log.debug('Invalid QR: {}'.format(iMsg.iphandleqrpngcid)) peerValidated = False self._didAuthInp[personDid] = False return else: log.debug('Ident QR {qr} for {peer} seems valid'.format( qr=iMsg.iphandleqrpngcid, peer=iMsg.peer)) peerValidated = True await ipfsop.ctx.pin(iMsg.iphandleqrpngcid) # Load the IPID loadAttempts = cGet('peers.didLoadAttempts') for attempt in range(0, loadAttempts): ipid = await self.app.ipidManager.load( personDid, localIdentifier=(iMsg.peer == ipfsop.ctx.node.id) ) if ipid: break if not ipid: log.debug(f'Cannot load DID: {personDid}') self._didAuthInp[personDid] = False return async with self.lock.writer_lock: piCtx = self.getByHandle(iMsg.iphandle) if not piCtx: log.debug(f'Creating new PeerIdentityCtx for ' f'{iMsg.iphandle} ({personDid})') piCtx = PeerIdentityCtx( self.ctx, iMsg.peer, iMsg.iphandle, ipid, validated=peerValidated ) ipid.sChanged.connectTo(partialEnsure( self.onPeerDidModified, piCtx)) piCtx.sStatusChanged.connectTo(partialEnsure( self.peerModified.emit, piCtx)) piCtx.ident = iMsg if not piCtx.authFailedRecently: ensure(self.didPerformAuth(piCtx, iMsg)) self._byHandle[iMsg.iphandle] = piCtx else: # This peer is already registered in the network graph # What we ought to do here is just to refresh the DID document async with self.lock.writer_lock: piCtx = self.getByHandle(iMsg.iphandle) if piCtx: self._byPeerId[piCtx.peerId] = piCtx piCtx.ident = iMsg await piCtx.ipid.refresh() await self.peerModified.emit(piCtx) await self.changed.emit()