def _createContextMenu(self, pos): menu = QMenu() actNewTab = menu.addAction(IconProvider.newTabIcon(), _("Open in new tab")) actNewWindow = menu.addAction(IconProvider.newWindowIcon(), _("Open in new window")) actNewPrivateWindow = menu.addAction( IconProvider.privateBrowsingIcon(), _("Open in new private window")) menu.addSeparator() actCopyUrl = menu.addAction(_("Copy url"), self._copyUrl) actCopyTitle = menu.addAction(_("Copy title"), self._copyTitle) menu.addSeparator() actDelete = menu.addAction(QIcon.fromTheme("edit-delete"), _("Delete")) actNewTab.triggered.connect(self._openUrlInNewTab) actNewWindow.triggered.connect(self._openUrlInNewWindow) actNewPrivateWindow.triggered.connect(self._openUrlInNewPrivateWindow) actDelete.triggered.connect(self._ui.historyTree.removeSelectedItems) if self._ui.historyTree.selectedUrl().isEmpty(): actNewTab.setDisabled(True) actNewWindow.setDisabled(True) actNewPrivateWindow.setDisabled(True) actCopyTitle.setDisabled(True) actCopyUrl.setDisabled(True) menu.exec_(pos)
def _createContextMenu(self, pos): ''' @param: pos QPoint ''' menu = QMenu() actNewTab = menu.addAction(IconProvider.newTabIcon(), _('Open in new tab')) actNewWindow = menu.addAction(IconProvider.newWindowIcon(), _('Open in new window')) actNewPrivateWindow = menu.addAction( IconProvider.privateBrowsingIcon(), _('Open in new private window')) menu.addSeparator() actDelete = menu.addAction(QIcon.fromTheme('edit-delete'), _('Delete')) actNewTab.triggered.connect(lambda x: self._openUrlInNewTab()) actNewWindow.triggered.connect(lambda x: self._openUrlInNewWindow()) actNewPrivateWindow.triggered.connect( lambda x: self._openUrlInNewPrivateWindow()) actDelete.triggered.connect(self.ui.historyTree.removeSelectedItems) if self.ui.historyTree.selectedUrl().isEmpty(): actNewTab.setDisabled(True) actNewWindow.setDisabled(True) actNewPrivateWindow.setDisabled(True) menu.exec_(pos)
def _contextMenuRequested(self, pos): ''' @param: pos QPoint ''' # BookmarksToolbarButton button = self._buttonAt(pos) if button: self._clickedBookmark = button.bookmark() else: self._clickedBookmark = None menu = QMenu() actNewTab = menu.addAction(IconProvider.newTabIcon(), _('Open in new tab')) actNewWindow = menu.addAction(IconProvider.newWindowIcon(), _('Open in new window')) actNewPrivateWindow = menu.addAction( IconProvider.privateBrowsingIcon(), _('Open in new private window')) menu.addSeparator() actEdit = menu.addAction(_('Edit')) actDelete = menu.addAction(QIcon.fromTheme('edit-delete'), _('Delete')) menu.addSeparator() self._actShowOnlyIcons = menu.addAction(_('Show Only Icons')) self._actShowOnlyIcons.setCheckable(True) self._actShowOnlyIcons.setChecked( self._bookmarks.showOnlyIconsInToolbar()) self._actShowOnlyIcons.toggled.connect(self._showOnlyIconsChanged) self._actShowOnlyText = menu.addAction(_('Show Only Text')) self._actShowOnlyText.setCheckable(True) self._actShowOnlyText.setChecked( self._bookmarks.showOnlyTextInToolbar()) self._actShowOnlyText.toggled.connect(self._showOnlyTextChanged) actNewTab.triggered.connect(self._openBookmarkInNewTab) actNewWindow.triggered.connect(self._openBookmarkInNewWindow) actNewPrivateWindow.triggered.connect( self._openBookmarkInNewPrivateWindow) actEdit.triggered.connect(self._editBookmark) actDelete.triggered.connect(self._deleteBookmark) canBeModify = self._clickedBookmark and self._bookmarks.canBeModified( self._clickedBookmark) actEdit.setEnabled(canBeModify) actDelete.setEnabled(canBeModify) canOpen = self._clickedBookmark and self._clickedBookmark.isUrl() actNewTab.setEnabled(canOpen) actNewWindow.setEnabled(canOpen) actNewPrivateWindow.setEnabled(canOpen) menu.exec_(self.mapToGlobal(pos)) if button: # Clear mouse over state after closing menu button.update() self._clickedBookmark = None self._actShowOnlyIcons = None self._actShowOnlyText = None
def __delete__(self): self._isClosing = True IconProvider.instance().saveIconsToDatabase() # Wait for all QtConcurrent jobs to finish QThreadPool.globalInstance().waitForDone() # Delete all classes that are saving data in destructor self._bookmarks = None self._cookieJar = None Settings.syncSettings()
def _createPageContextMenu(self, menu): ''' @param: menu QMenu ''' action = menu.addAction(_('&Back'), self.back) action.setIcon(IconProvider.standardIcon(QStyle.SP_ArrowBack)) action.setEnabled(self.history().canGoBack()) action = menu.addAction(_('&Forward'), self.forward) action.setIcon(IconProvider.standardIcon(QStyle.SP_ArrowForward)) action.setEnabled(self.history().canGoForward()) # Special menu for Speed Dial page if self.url().toString() == 'app:speeddial': menu.addSeparator() menu.addAction(QIcon.fromTheme('list-add'), _('&Add New Page'), self._addSpeedDial) menu.addAction(IconProvider.settingsIcon(), _('&ConfigureĀ Speed Dial'), self._configureSpeedDial) menu.addSeparator() menu.addAction(QIcon.fromTheme('view-refresh'), _('Reload All Dials'), self._reloadAllSpeedDials) return reloadAct, pageReloadAct = self._addPageActionToMenu(menu, QWebEnginePage.Reload) reloadAct.setVisible(pageReloadAct.isEnabled()) def reloadCb(): reloadAct.setVisible(pageReloadAct.isEnabled()) pageReloadAct.changed.connect(reloadCb) menu.clearActions.append([pageReloadAct.changed, reloadCb]) stopAct, pageStopAct = self._addPageActionToMenu(menu, QWebEnginePage.Stop) stopAct.setVisible(pageStopAct.isEnabled()) def stopCb(): stopAct.setVisible(pageStopAct.isEnabled()) pageStopAct.changed.connect(stopCb) menu.clearActions.append([pageStopAct.changed, stopCb]) menu.addSeparator() menu.addAction(QIcon.fromTheme('bookmark-new'), _('Book&mark page'), self._bookmarkLink) menu.addAction(QIcon.fromTheme('document-save'), _('&Save page as...'), self._savePageAs) act = menu.addAction(QIcon.fromTheme('edit-copy'), _('&Copy page link...'), self._copyLinkToClipboard) act.setData(self.url()) menu.addAction(QIcon.fromTheme('mail-message-new'), _('Send page link...'), self.sendPageByEmail) menu.addSeparator() menu.addAction(QIcon.fromTheme('edit-select-all'), _('Select &all'), self.editSelectAll) menu.addSeparator()
def __init__(self, fileName, downloadItem, parent=None): ''' @param: fileName QString @param: downloadItem QWebEngineDownloadItem @param: parent QWidget ''' super().__init__(parent) self._ui = uic.loadUi('mc/downloads/DownloadOptionsDialog.ui', self) self._downloadItem = downloadItem self._signalEmited = False self._ui.fileName.setText('<b>%s</b>' % fileName) self._ui.fromServer.setText(self._downloadItem.url().host()) fileIcon = IconProvider.standardIcon(QStyle.SP_FileIcon) db = QMimeDatabase() # QMimeType mime = db.mimeTypeForName(downloadItem.mimeType()) if mime.isValid() and not mime.isDefault(): self._ui.mimeName.setText(mime.comment()) self._ui.iconLabel.setPixmap(QIcon.fromTheme(mime.iconName(), fileIcon).pixmap(22)) else: self._ui.mimeFrame.hide() self.iconLabel.setPixmap(fileIcon.pixmap(22)) self.setWindowTitle(_('Opening %s') % fileName) self._ui.buttonBox.setFocus() self._ui.copyDownloadLink.clicked.connect(self._copyDownloadLink) self._ui.finished.connect(self._emitDialogFinished)
def _addCookie(self, cookie): ''' @param: cookie QNetworkCookie ''' item = None # QTreeWidgetItem domain = self._cookieDomain(cookie) findParent = self._domainHash.get(domain) if findParent: item = HashableTreeWidgetItem(findParent) else: newParent = HashableTreeWidgetItem(self._ui.cookieTree) newParent.setText(0, domain) newParent.setIcon(0, IconProvider.standardIcon(QStyle.SP_DirIcon)) newParent.setData(0, Qt.UserRole + 10, cookie.domain()) self._ui.cookieTree.addTopLevelItem(newParent) self._domainHash[domain] = newParent item = HashableTreeWidgetItem(newParent) cookie = QNetworkCookie(cookie) item.setText(0, '.' + domain) item.setText(1, cookie.name().data().decode()) item.setData(0, Qt.UserRole + 10, cookie) self._ui.cookieTree.addTopLevelItem(item) self._itemHash[item] = cookie
def icon(self, allowNull=False): ''' @return: QIcon ''' icon = super().icon() if not icon.isNull(): return icon scheme = self.url().scheme() if scheme == 'ftp': return IconProvider.standardIcon(QStyle.SP_ComputerIcon) if scheme == 'file': return IconProvider.standardIcon(QStyle.SP_DriveHDIcon) return IconProvider.iconForUrl(self.url(), allowNull)
def __init__(self, origin, page, feature): ''' @param origin QUrl @param page QWebEnginePage @param feature QWenEnginePage.Feature ''' super().__init__(AnimatedWidget.Down, 300, None) self._ui = uic.loadUi( 'mc/tools/html5permissions/HTML5PermissionsNotification.ui', self.widget()) self._origin = origin self._page = page # QPointer<QWebEnginePage> self._feature = feature self._ui.close.setIcon( IconProvider.standardIcon(QStyle.SP_DialogCloseButton)) if not self._origin.host(): site = _('this site') else: site = '<b>%s</b>' % self._origin.host() #if feature == QWebEnginePage::Notifications: # ui.textLabel.setText(_("Allow %s to show desktop notifications?") % site) if feature == QWebEnginePage.Geolocation: self._ui.textLabel.setText( _("Allow %s to locate your position?") % site) elif feature == QWebEnginePage.MediaAudioCapture: self._ui.textLabel.setText( _("Allow %s to use your microphone?") % site) elif feature == QWebEnginePage.MediaVideoCapture: self._ui.textLabel.setText( _("Allow %s to use your camera?") % site) elif feature == QWebEnginePage.MediaAudioVideoCapture: self._ui.textLabel.setText( _("Allow %s to use your microphone and camera?") % site) elif feature == QWebEnginePage.MouseLock: self._ui.textLabel.setText( _("Allow %s to hide your pointer?") % site) else: print('WARNING: Unknown feature', feature) self._ui.allow.clicked.connect(self._grantPermissions) self._ui.deny.clicked.connect(self._denyPermissions) self._ui.close.clicked.connect(self._denyPermissions) self._page.loadStarted.connect(self.deleteLater) def cb(origin, feature): ''' @param: origin QUrl @param: feature QWebEnginePage::Feature ''' if origin == self._origin and feature == self._feature: self.deleteLater() self._page.featurePermissionRequestCanceled.connect(cb) self.startAnimation()
def restoreData(self): ''' @return: QJsonArray ''' out = [] idx = 0 for window in self._manager.restoreData().windows: jdx = 0 tabs = [] for tab in window.tabs: icon = tab.icon.isNull() and IconProvider.emptyWebIcon( ) or tab.icon item = {} item['tab'] = jdx item['icon'] = gVar.appTools.pixmapToDataUrl(icon.pixmap(16)) item['title'] = tab.title item['url'] = tab.url.toString() item['pinned'] = tab.isPinned item['current'] = window.currentTab == jdx tabs.append(item) jdx += 1 window = {} window['window'] = idx idx += 1 window['tabs'] = tabs out.append(window) return out
def _restorePage(self): rPage = '' rPage += gVar.appTools.readAllFileContents(":html/restore.html") rPage = rPage.replace( "%IMAGE%", gVar.appTools.pixmapToDataUrl( IconProvider.standardIcon( QStyle.SP_MessageBoxWarning).pixmap(45)).toString()) rPage = rPage.replace("%TITLE%", _("Restore Session")) rPage = rPage.replace("%OOPS%", _("Oops, Falkon crashed.")) rPage = rPage.replace( "%APOLOGIZE%", _("We apologize for this. Would you like to restore the last saved state?" )) rPage = rPage.replace( "%TRY-REMOVING%", _("Try removing one or more tabs that you think cause troubles")) rPage = rPage.replace("%START-NEW%", _("Or you can start completely new session")) rPage = rPage.replace("%WINDOW%", _("Window")) rPage = rPage.replace("%WINDOWS-AND-TABS%", _("Windows and Tabs")) rPage = rPage.replace("%BUTTON-START-NEW%", _("Start New Session")) rPage = rPage.replace("%BUTTON-RESTORE%", _("Restore")) rPage = rPage.replace("%JAVASCRIPT-DISABLED%", _("Requires enabled JavaScript.")) rPage = gVar.appTools.applyDirectionToPage(rPage) return rPage
def _runJob(self): if self._jobCancelled or gVar.app.isClosing(): return if not self._searchString: self._completeMostVisited() else: self._completeFromHistory() # Load all icons into QImage for item in self._items: if self._jobCancelled: return # QUrl url = item.data(LocationCompleterModel.UrlRole) item.setData(IconProvider.imageForUrl(url), LocationCompleterModel.ImageRole) if self._jobCancelled: return # Get domain completion if self._searchString and gVar.appSettings.useInlineCompletion: domainQuery = LocationCompleterModel.createDomainQuery( self._searchString) history = domainQuery.first() if history: self._domainCompletion = QUrl(history.url).host() if self._jobCancelled: return # Add search/visit item if self._searchString: item = QStandardItem() item.setText(self._searchString) item.setData(self._searchString, LocationCompleterModel.UrlRole) item.setData(self._searchString, LocationCompleterModel.SearchStringRole) item.setData(True, LocationCompleterModel.VisitSearchItemRole) if self._domainCompletion: url = QUrl('http://%s' % self._domainCompletion) item.setData(IconProvider.imageForDomain(url), LocationCompleterModel.ImageRole) self._items.insert(0, item)
def icon(self): ''' @return: QIcon ''' # Cache icon for 20 seconds iconCacheTime = 20 * 1000 if self._type == self.Url: if self._iconTime.isNull( ) or self._iconTime.elapsed() > iconCacheTime: self._icon = IconProvider.iconForUrl(self._url) self._iconTime.restart() return self._icon elif self._type == self.Folder: return IconProvider.standardIcon(QStyle.SP_DirIcon) else: return QIcon()
def _init(self): self.setTitle('Hi&story') icon = IconProvider.standardIcon(QStyle.SP_ArrowBack) act = self.addAction(icon, '&Back', self._goBack) act.setShortcut( gVar.appTools.actionShortcut(QKeySequence.Back, Qt.ALT + Qt.Key_Left, QKeySequence.Forward, Qt.ALT + Qt.Key_Right)) icon = IconProvider.standardIcon(QStyle.SP_ArrowForward) act = self.addAction(icon, '&Forward', self._goForward) act.setShortcut( gVar.appTools.actionShortcut(QKeySequence.Forward, Qt.ALT + Qt.Key_Right, QKeySequence.Back, Qt.ALT + Qt.Key_Left)) act = self.addAction(QIcon.fromTheme('go-home'), '&Home', self._goHome) act.setShortcut(QKeySequence(Qt.ALT + Qt.Key_Home)) icon = QIcon.fromTheme('deep-history', QIcon(':/icons/menu/history.svg')) act = self.addAction(icon, 'Show &All History') act.triggered.connect(self._showHistoryManager) act.setShortcut(QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_H)) self.addSeparator() self.aboutToShow.connect(self._aboutToHide) self.aboutToHide.connect(self._aboutToShow) self._menuMostVisited = Menu('Most Visited', self) self._menuMostVisited.aboutToShow.connect(self._aboutToShowMostVisited) self._menuClosedTabs = Menu('Closed Tabs') self._menuClosedTabs.aboutToShow.connect(self._aboutToShowClosedTabs) self._menuClosedWindows = Menu('Closed Windows') self._menuClosedWindows.aboutToShow.connect( self._aboutToShowClosedWindows) self.addMenu(self._menuMostVisited) self.addMenu(self._menuClosedTabs) self.addMenu(self._menuClosedWindows)
def _createContextMenu(self, pos): ''' @param: pos QPoint ''' menu = QMenu() actNewTab = menu.addAction(IconProvider.newTabIcon(), _('Open in new tab')) actNewWindow = menu.addAction(IconProvider.newWindowIcon(), _('Open in new window')) actNewPrivateWindow = menu.addAction(IconProvider.privateBrowsingIcon(), _('Open in new private window')) menu.addSeparator() actNewBookmark = menu.addAction(_('New Bookmark'), self._addBookmark) actNewFolder = menu.addAction(_('New Folder'), self._addFolder) actNewSeparator = menu.addAction(_('New Separator'), self._addSeparator) menu.addSeparator() actDelete = menu.addAction(QIcon.fromTheme('edit-delete'), _('Delete')) actNewTab.triggered.connect(self._openBookmarkInNewTab) actNewWindow.triggered.connect(self._openBookmarkInNewWindow) actNewPrivateWindow.triggered.connect(self._openBookmarkInNewPrivateWindow) actDelete.triggered.connect(self._deleteBookmarks) canBeDelete = False # QList<BookmarkItem> items = self._ui.tree.selectedBookmarks() for item in items: if self._bookmarks.canBeModified(item): canBeDelete = True break if not canBeDelete: actDelete.setDisabled(True) if not self._selectedBookmark or not self._selectedBookmark.isUlr(): actNewTab.setDisabled(True) actNewWindow.setDisabled(True) actNewPrivateWindow.setDisabled(True) if not self._selectedBookmark: actNewBookmark.setDisabled(True) actNewFolder.setDisabled(True) actNewSeparator.setDisabled(True) menu.exec_(pos)
def _optimizeDb(self): gVar.app.setOverrideCursor(Qt.WaitCursor) profilePath = DataPaths.currentProfilePath() sizeBefore = gVar.appTools.fileSizeToString( QFileInfo(profilePath + 'browserdata.db').size()) IconProvider.instance().clearOldIconsInDatabase() sizeAfter = gVar.appTools.fileSizeToString( QFileInfo(profilePath + 'browserdata.db').size()) gVar.app.restoreOverrideCursor() QMessageBox.information( self, _('Database Optimized'), _('Database successfully optimized.<br/><br/><b>Database Size Before: </b>%s<br/><b>Database Size After: </b>%s' ) % # noqa E501 (sizeBefore, sizeAfter))
def __init__(self, parent=None): super().__init__(parent) self._ui = uic.loadUi('mc/network/SslErrorDialog.ui', self) self._result = self.No self._ui.icon.setPixmap(IconProvider.standardIcon(QStyle.SP_MessageBoxCritical).pixmap(52)) # Disabled untile there is reliable way to save certificate error # self._ui.buttonBox.addButton(_('Only for this session'), QDialogButtonBox.ApplyRole) self._ui.buttonBox.button(QDialogButtonBox.No).setFocus() self._ui.buttonBox.clicked.connect(self._buttonClicked)
def _updateSiteIcon(self): if self._completer.isVisible(): self._siteIcon.setIcon( QIcon.fromTheme('edit-find', QIcon(':/icons/menu/search-icon.svg'))) else: icon = IconProvider.emptyWebIcon() secured = self.property('secured') if secured: icon = QIcon.fromTheme('document-encrypted', icon) self._siteIcon.setIcon(icon.pixmap(16))
def __init__(self, title, parent=None): super().__init__(parent) self.ui = uic.loadUi('mc/tools/DockTitleBarWidget.ui', self) self.ui.closeButton.setIcon( QIcon( IconProvider.standardIcon( QStyle.SP_DialogCloseButton).pixmap(16))) self.ui.label.setText(title) self.ui.closeButton.clicked.connect(parent.close) self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
def showCrashHtmlCb(): page = gVar.appTools.readAllFileContents(':html/tabcrash.html') img = gVar.appTools.pixmapToDataUrl(IconProvider.standardIcon( QStyle.SP_MessageBoxWarning).pixmap(45)).toString() page = page.replace("%IMAGE%", img) \ .replace("%TITLE%", _("Failed loading page")) \ .replace("%HEADING%", _("Failed loading page")) \ .replace("%LI-1%", _("Something went wrong while loading this page.")) \ .replace("%LI-2%", _("Try reloading the page or closing some tabs to make more memory available.")) \ .replace("%RELOAD-PAGE%", _("Reload page")) page = gVar.appTool.applyDirectionToPage(page) self.setHtml(page, self.url())
def addCompletions(self, items): ''' @param: items QList<QStandardItem> ''' for item in items: img = item.data(self.ImageRole) if not img: img = QImage() pixmap = QPixmap.fromImage(img) item.setIcon(QIcon(pixmap)) self._setTabPosition(item) if item.icon().isNull(): item.setIcon(IconProvider.emptyWebIcon()) self.appendRow([item])
def _createLinkContextMenu(self, menu, hitTest): ''' @param: menu QMenu @param: hitTest WebHitTestResult ''' menu.addSeparator() act = Action(IconProvider.newTabIcon(), _('Open link in new &tab'), menu) act.setData(hitTest.linkUrl()) act.triggered.connect(lambda: self.userDefinedOpenUrlInNewTab()) act.ctrlTriggered.connect(lambda: self.userDefineOpenUrlInBgTab()) menu.addAction(act) act = menu.addAction(IconProvider.newWindowIcon(), _('Open link in new &window'), self._openUrlInNewWindow) act.setData(hitTest.linkUrl()) act = menu.addAction(IconProvider.privateBrowsingIcon(), _('Open link in &private window'), gVar.app.startPrivateBrowsing) act.setData(hitTest.linkUrl()) menu.addSeparator() bData = [hitTest.linkUrl(), hitTest.linkTitle()] # QVariantList act = menu.addAction(QIcon.fromTheme('bookmark-new'), _('B&ookmark link'), self._bookmarkLink) act.setData(bData) menu.addAction(QIcon.fromTheme('document-save'), _('&Save link as...'), self._downloadLinkToDisk) act = menu.addAction(QIcon.fromTheme('mail-message-new'), _('Send link...'), self._sendTextByMail) act.setData(hitTest.linkUrl().toEncoded()) act = menu.addAction(QIcon.fromTheme('edit-copy'), _('&Copy link address'), self._copyLinkToClipboard) act.setData(hitTest.linkUrl()) menu.addSeparator() if self.selectedText(): menu.addAction(self.pageAction(QWebEnginePage.Copy))
def _aboutToShowMostVisited(self): self._menuMostVisited.clear() mostVisited = gVar.app.history().mostVisited(10) for entry in mostVisited: act = Action(gVar.appTools.truncatedText(entry.title, 40), self._menuMostVisited) act.setData(entry.url) act.setIcon(IconProvider.iconForUrl(entry.url)) act.triggered.connect(self._historyEntryActivated) act.ctrlTriggered.connect(self._historyEntryCtrlActivated) act.shiftTriggered.connect(self._historyEntryShiftActivated) self._menuMostVisited.addAction(act) if self._menuMostVisited.isEmpty(): self._menuMostVisited.addAction('Empty').setEnabled(False)
def addBookmarkDialog(cls, parent, url, title, folder=None): ''' @brief: Add Bookmark Dialogs @param: parent QWidget @param: url QUrl @param: title QString @param: folder BookmarkItem ''' dialog = QDialog(parent) layout = QBoxLayout(QBoxLayout.TopToBottom, dialog) label = QLabel(dialog) edit = QLineEdit(dialog) folderButton = BookmarksFoldersButton(dialog, folder) box = QDialogButtonBox(dialog) box.addButton(QDialogButtonBox.Ok) box.addButton(QDialogButtonBox.Cancel) box.rejected.connect(dialog.reject) box.accepted.connect(dialog.accept) layout.addWidget(label) layout.addWidget(edit) layout.addWidget(folderButton) layout.addWidget(box) label.setText(_('Choose name and location of this bookmark.')) edit.setText(title) edit.setCursorPosition(0) dialog.setWindowIcon(IconProvider.iconForUrl(url)) dialog.setWindowTitle(_('Add New Bookmark')) size = dialog.size() size.setWidth(350) dialog.resize(size) dialog.exec_() if dialog.result() == QDialog.Rejected or not edit.text(): del dialog return False bookmark = BookmarkItem(BookmarkItem.Url) bookmark.setTitle(edit.text()) bookmark.setUrl(url) gVar.app.bookmarks().addBookmark(folderButton.selectedFolder(), bookmark) del dialog return True
def drawRow(self, painter, options, index): ''' @param: painter QPainter @param: options QStyleOptionViewItem @param: index QModelIndex ''' itemTopLevel = index.data(HistoryModel.IsTopLevelRole) # toBool() icon = index.data(HistoryModel.IconRole) iconLoaded = icon and not icon.isNull() if index.isValid() and not itemTopLevel and not iconLoaded: # QPersistentModelIndex _ = QPersistentModelIndex(index) url = index.data(HistoryModel.UrlRole) # toUrl() self.model().setData(index, IconProvider.iconForUrl(url), HistoryModel.IconRole) super().drawRow(painter, options, index)
def __init__(self, window, tabWidget): ''' @param: window BrowserWindow @param: tabWidget TabWidget ''' super(TabBar, self).__init__() self._window = window self._tabWidget = tabWidget self._hideTabBarWithOneTab = False self._showCloseOnInactive = False self._normalTabWidth = 0 self._activeTabWidth = 0 self._dragStartPosition = QPoint() # QPoint self._forceHidden = False self._lastTab = None # QPointer<WebTab> self.setObjectName('tabbar') self.setElideMode(Qt.ElideRight) self.setFocusPolicy(Qt.NoFocus) self.setTabsCloseable(False) self.setMouseTracking(True) self.setDocumentModel(True) self.setAcceptDrops(True) self.setDrawBase(False) self.setMovable(True) self.currentChanged.connect(self._currentTabChanged) # ComboTabBar features self.setUsesScrollButtons(True) self.setCloseButtonsToolTip(_('Close Tab')) self.overFlowChanged.connect(self._overflowChanged) self.tabMetrics().init() if gVar.app.isPrivate(): privateBrowsing = QLabel(self) privateBrowsing.setObjectName('private-browsing-icon') privateBrowsing.setPixmap( IconProvider.privateBrowsingIcon().pixmap(16)) privateBrowsing.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) privateBrowsing.setFixedWidth(30) self.addCornerWidget(privateBrowsing, Qt.TopLeftCorner)
def paintEvent(self, event): ''' @param event QPaintEvent ''' p = QPainter(self) p.setRenderHint(QPainter.Antialiasing) size = 16 pixmapSize = round(size * self.data().animationPixmap.devicePixelRatioF()) # Center the pixmap in rect r = QRect(self.rect()) r.setX((r.width() - size) / 2) r.setY((r.height() - size) / 2) r.setWidth(size) r.setHeight(size) if self._animationRunning: p.drawPixmap( r, self.data().animationPixmap, QRect(self._currentFrame * pixmapSize, 0, pixmapSize, pixmapSize)) elif self._audioIconDisplayed and not self._tab.isPinned(): self._audioIconRect = QRect(r) p.drawPixmap( r, self._tab.isMuted() and self.data().audioMutedPixmap or self.data().audioPlayingPixmap) elif not self._sitePixmap.isNull(): p.drawPixmap(r, self._sitePixmap) elif self._tab and self._tab.isPinned(): p.drawPixmap(r, IconProvider.emptyWebIcon().pixmap(size)) # Draw audio icon on top of site icon for pinned tabs if not self._animationRunning and self._audioIconDisplayed and self._tab.isPinned( ): s = size - 4 r0 = QRect(self.width() - 4, 0, s, s) self._audioIconRect = r0 c = self.palette().color(QPalette.Window) c.setAlpha(180) p.setPen(c) p.setBrush(c) p.drawEllipse(r) p.drawPixmap( r, self._tab.isMuted() and self.data().audioMutedPixmap or self.data().audioPlayingPixmap) # Draw background activity indicator if self._tab and self._tab.isPinned() and self._tab.webView( ).backgroundActivity(): s = 5 # Background r1 = QRect(self.width() - s - 2, self.height() - s - 2, s + 2, s + 2) c1 = self.palette().color(QPalette.Window) c1.setAlpha(180) p.setPen(Qt.transparent) p.setBrush(c1) p.drawEllipse(r1) # Forground r2 = QRect(self.width() - s - 1, self.height() - s - 1, s, s) c2 = self.palette().color(QPalette.Text) p.setPen(Qt.transparent) p.setBrush(c2) p.drawEllipse(r2)
def __init__(self, parent=None): super().__init__(parent) self._ui = uic.loadUi('mc/preferences/PluginsList.ui', self) self._ui.list.setLayoutDirection(Qt.LeftToRight) self._ui.butSettings.setIcon(IconProvider.settingsIcon())
def _init(self): # Standard actions - needed on Mac to be placed correctly in # "application" menu action = QAction(QIcon.fromTheme('help-about'), '&About App', self) action.setMenuRole(QAction.AboutRole) action.triggered.connect(self._showAboutDialog) self._actions['Standard/About'] = action action = QAction(IconProvider.settingsIcon(), 'Pr&eferences', self) action.setMenuRole(QAction.PreferencesRole) action.setShortcut(QKeySequence(QKeySequence.Preferences)) action.triggered.connect(self._showPreferences) self._actions['Standard/Preferences'] = action action = QAction(QIcon.fromTheme('application-exit'), 'Quit', self) action.setMenuRole(QAction.QuitRole) # Shortcut set from browserWindow action.triggered.connect(self._quitApplication) self._actions['Standard/Quit'] = action # File menu self._menuFile = QMenu('&File', self) self._menuFile.aboutToShow.connect(self._aboutToShowFileMenu) self._ADD_ACTION('File/NewTab', self._menuFile, IconProvider.newTabIcon(), 'New Tab', self._newTab, 'Ctrl+T') self._ADD_ACTION('File/NewWindow', self._menuFile, IconProvider.newWindowIcon(), '&New Window', self._newWindow, 'Ctrl+N') self._ADD_ACTION('File/NewPrivateWindow', self._menuFile, IconProvider.privateBrowsingIcon(), 'New &Private Window', self._newPrivateWindow, 'Ctrl+Shift+P') self._ADD_ACTION('File/OpenLocation', self._menuFile, QIcon.fromTheme('document-open-remote'), 'Open Location', self._openLocation, 'Ctrl+L') self._ADD_ACTION('File/OpenFile', self._menuFile, QIcon.fromTheme('document-open'), 'Open &File...', self._openFile, 'Ctrl+O') self._ADD_ACTION('File/CloseWindow', self._menuFile, QIcon.fromTheme('window-close'), 'Close Window', self._closeWindow, 'Ctrl+Shift+W') self._menuFile.addSeparator() sessionManager = gVar.app.sessionManager() if sessionManager: sessionsSubmenu = QMenu('Sessions', self) sessionsSubmenu.aboutToShow.connect(sessionManager._aboutToShowSessionsMenu) self._menuFile.addMenu(sessionsSubmenu) action = QAction('Session Manager', self) action.triggered.connect(sessionManager.openSessionManagerDialog) self._actions['File/SessionManager'] = action self._menuFile.addAction(action) self._menuFile.addSeparator() self._ADD_ACTION('File/SavePageAs', self._menuFile, QIcon.fromTheme('document-save'), '&Save Page As...', self._savePageAs, 'Ctrl+S') self._ADD_ACTION('File/SendLink', self._menuFile, QIcon.fromTheme('mail-message-new'), 'Send Link...', self._sendLink, '') self._ADD_ACTION('File/Print', self._menuFile, QIcon.fromTheme('document-print'), '&Print...', self._printPage, 'Ctrl+P') self._menuFile.addSeparator() self._menuFile.addAction(self._actions['Standard/Quit']) # Edit Menu self._menuEdit = QMenu('&Edit', self) self._menuEdit.aboutToShow.connect(self._aboutToShowEditMenu) action = self._ADD_ACTION('Edit/Undo', self._menuEdit, QIcon.fromTheme('edit-undo'), '&Undo', self._editUndo, 'Ctrl+Z') action.setShortcutContext(Qt.WidgetShortcut) action = self._ADD_ACTION('Edit/Redo', self._menuEdit, QIcon.fromTheme('edit-redo'), '&Redo', self._editRedo, 'Ctrl+Shift+Z') action.setShortcutContext(Qt.WidgetShortcut) self._menuEdit.addSeparator() action = self._ADD_ACTION('Edit/Cut', self._menuEdit, QIcon.fromTheme('edit-cut'), '&Cut', self._editCut, 'Ctrl+X') action.setShortcutContext(Qt.WidgetShortcut) action = self._ADD_ACTION('Edit/Copy', self._menuEdit, QIcon.fromTheme('edit-copy'), 'C&opy', self._editCopy, 'Ctrl+C') action.setShortcutContext(Qt.WidgetShortcut) action = self._ADD_ACTION('Edit/Paste', self._menuEdit, QIcon.fromTheme('edit-paste'), '&Paste', self._editPaste, 'Ctrl+V') action.setShortcutContext(Qt.WidgetShortcut) self._menuEdit.addSeparator() action = self._ADD_ACTION('Edit/SelectAll', self._menuEdit, QIcon.fromTheme('edit-select-all'), 'Select &All', self._editSelectAll, 'Ctrl+A') action.setShortcutContext(Qt.WidgetShortcut) action = self._ADD_ACTION('Edit/Find', self._menuEdit, QIcon.fromTheme('edit-find'), '&Find', self._editFind, 'Ctrl+F') action.setShortcutContext(Qt.WidgetShortcut) self._menuFile.addSeparator() # View menu self._menuView = QMenu('&View', self) self._menuView.aboutToShow.connect(self._aboutToShowViewMenu) toolbarsMenu = QMenu('Toolbars', self._menuView) toolbarsMenu.aboutToShow.connect(self._aboutToShowtoolbarsMenu) sidebarMenu = QMenu('Sidebar', self._menuView) sidebarMenu.aboutToShow.connect(self._aboutToShowSidebarsMenu) encodingMenu = QMenu('Character &Encoding', self._menuView) encodingMenu.aboutToShow.connect(self._aboutToShowEncodingMenu) # Create menus to make shortcuts available event before first showing # the menu self._window.createToolbarsMenu(toolbarsMenu) self._window.createSidebarsMenu(sidebarMenu) self._menuView.addMenu(toolbarsMenu) self._menuView.addMenu(sidebarMenu) self._ADD_CHECKABLE_ACTION('View/ShowStatusBar', self._menuView, QIcon(), 'Sta&tus Bar', self._showStatusBar, '') self._menuView.addSeparator() self._ADD_ACTION('View/Stop', self._menuView, QIcon.fromTheme('process-stop'), '&Stop', self._stop, 'Esc') self._ADD_ACTION('View/Reload', self._menuView, QIcon.fromTheme('view-refresh'), '&Reload', self._reload, 'F5') self._menuView.addSeparator() self._ADD_ACTION('View/ZoomIn', self._menuView, QIcon.fromTheme('zoom-in'), 'Zoom &In', self._zoomIn, 'Ctrl++') self._ADD_ACTION('View/ZoomOut', self._menuView, QIcon.fromTheme('zoom-out'), 'Zoom &Out', self._zoomOut, 'Ctrl+-') self._ADD_ACTION('View/ZoomReset', self._menuView, QIcon.fromTheme('zoom-original'), 'Reset', self._zoomReset, 'Ctrl+0') self._menuView.addSeparator() self._menuView.addMenu(encodingMenu) self._menuView.addSeparator() action = self._ADD_ACTION('View/PageSource', self._menuView, QIcon.fromTheme('text-html'), '&Page Source', self._showPageSource, 'Ctrl+U') action.setShortcutContext(Qt.WidgetShortcut) self._ADD_CHECKABLE_ACTION('View/FullScreen', self._menuView, QIcon.fromTheme('view-fullscreen'), '&FullScreen', self._showFullScreen, 'F11') # Tool menu self._menuTools = QMenu('&Tools', self) self._menuTools.aboutToShow.connect(self._aboutToShowToolsMenu) self._ADD_ACTION('Tools/WebSearch', self._menuTools, QIcon.fromTheme('edit-find'), '&Web Search', self._webSearch, 'Ctrl+K') action = self._ADD_ACTION('Tools/SiteInfo', self._menuTools, QIcon.fromTheme('dialog-information'), 'Site &Info', self._showSiteInfo, 'Ctrl+I') action.setShortcutContext(Qt.WidgetShortcut) self._menuTools.addSeparator() self._ADD_ACTION('Tools/DownloadManager', self._menuTools, QIcon.fromTheme('download'), '&Download Manager', self._showDownloadManager, 'Ctrl+Y') self._ADD_ACTION('Tools/CookiesManager', self._menuTools, QIcon(), '&Cookies Manager', self._showCookieManager, '') self._ADD_ACTION('Tools/WebInspector', self._menuTools, QIcon(), 'Web In&spector', self._toggleWebInspector, 'Ctrl+Shift+I') self._ADD_ACTION('Tools/ClearRecentHistory', self._menuTools, QIcon.fromTheme('edit-clear'), 'Clear Recent &History', self._showClearRecentHistoryDialog, 'Ctrl+Shift+Del') if not WebInspector.isEnabled(): self._actions['Tools/WebInspector'].setVisible(False) self._submenuExtensions = QMenu('&Extensions', self) self._submenuExtensions.menuAction().setVisible(False) self._menuTools.addMenu(self._submenuExtensions) self._menuTools.addSeparator() # Help menu self._menuHelp = QMenu('&Help', self) # ifndef Q_OS_MACOS self._ADD_ACTION('Help/AboutQt', self._menuHelp, QIcon(), 'About &Qt', self._aboutQt, '') self._menuHelp.addAction(self._actions['Standard/About']) self._menuHelp.addSeparator() # endif self._ADD_ACTION('Help/InfoAboutApp', self._menuHelp, QIcon.fromTheme('help-contents'), 'Information about application', self._showInfoAboutApp, '') self._ADD_ACTION('Help/ConfigInfo', self._menuHelp, QIcon(), 'Configuration Information', self._showConfigInfo, '') self._ADD_ACTION('Help/ReportIssue', self._menuHelp, QIcon(), 'Report &Issue', self._reportIssue, '') self._actions['Help/InfoAboutApp'].setShortcut(QKeySequence(QKeySequence.HelpContents)) # History menu self._menuHistory = HistoryMenu() self._menuHistory.setMainWindow(self._window) # Bookmarks menu self._menuBookmarks = BookmarksMenu() self._menuBookmarks.setMainWindow(self._window) # Other actions action = QAction(QIcon.fromTheme('user-trash'), 'Restore &Closed Tab', self) action.setShortcut(QKeySequence('Ctrl+Shift+T')) action.triggered.connect(self._restoreClosedTab) self._actions['Other/RestoreClosedTab'] = action # # ifdef Q_OS_MACOS # self._actions['View/FullScreen'].setShortcut(QKeySequence('Ctrl+Meta+F')) # # Add standard actions to File Menu (as it won't be ever cleared) and # # Mac menubar should move them to "Application" menu # self._menuFile.addAction(self._actions['Standard/About']) # self._menuFile.addAction(self._actions['Standard/Preferences']) # # Prevent ConfigInfo action to be detected as "Preferences..." action in # # Mac # self._actions['Help/ConfigInfo'].setMenuRole(QAction.NoRole) # # Create Dock Menu # dockMenu = QMenu(0) # dockMenu.addAction(self._actions['File/NewTab']) # dockMenu.addAction(self._actions['File/NewWindow']) # dockMenu.addAction(self._actions['File/NewPrivateWindow']) # qt_mac_set_dock_menu(dockMenu) # # endif if const.OS_UNIX and not const.OS_MACOS: self._menuEdit.addAction(self._actions['Standard/Preferences']) elif not const.OS_MACOS: self._menuTools.addAction(self._actions['Standard/Preferences']) self._addActionsToWindow()
def _init(self): tabWidget = self._window.tabWidget() if self._clickedTab != -1: webTab = tabWidget.webTab(self._clickedTab) if not webTab: return if webTab.webView().isLoading(): self.addAction(QIcon.fromTheme('process-stop'), _('&Stop Tab'), self._stopTab) else: self.addAction(QIcon.fromTheme('view-refresh'), _('&Reload Tab'), self._reloadTab) self.addAction(QIcon.fromTheme('tab-duplicate'), _('&Duplicate Tab'), self._duplicateTab) if self._options & self.ShowDetachTabAction and ( gVar.app.windowCount() > 1 or tabWidget.count() > 1): self.addAction(QIcon.fromTheme('tab-detach'), _('D&etach Tab'), self._detachTab) self.addAction( webTab.isPinned() and _('Un&pin Tab') or _('&Pin Tab'), self._pinTab) self.addAction( webTab.isMuted() and _('Un&mute Tab') or _('&Mute Tab'), self._muteTab) if not webTab.isRestored(): self.addAction(_('Load Tab'), self._loadTab) else: self.addAction(_('Unload Tab'), self._unloadTab) self.addSeparator() self.addAction(_('Re&load All Tabs'), tabWidget.reloadAllTabs) self.addAction(_('Bookmark &All Tabs'), self._window.bookmarkAllTabs) self.addSeparator() if self._options & self.ShowCloseOtherTabsActions: self.addAction(_('Close Ot&her Tabs'), self._closeAllButCurrent) self.addAction( self._options & self.HorizontalTabs and _('Close Tabs To The Right') or _('Close Tabs To The Bottom'), self._closeToRight) self.addAction( self._options & self.HorizontalTabs and _('Close Tabs To The Left') or _('Close Tabs To The Top'), self._closeToLeft) self.addSeparator() self.addAction(self._window.action('Other/RestoreClosedTab')) self.addAction(QIcon.fromTheme('window-close'), _('Cl&ose Tab'), self._closeTab) else: self.addAction(IconProvider.newTabIcon(), _('&New tab'), self._window.addTab) self.addSeparator() self.addAction(_('Reloa&d All Tabs'), tabWidget.reloadAllTabs) self.addAction(_('Bookmark &All Tabs'), self._window.bookmarkAllTabs) self.addSeparator() self.addAction(self._window.action('Other/RestoreClosedTab')) self._window.action('Other/RestoreClosedTab').setEnabled( tabWidget.canRestoreTab()) self.aboutToHide.connect(lambda: self._window.action( 'Other/RestoreClosedTab').setEnabled(True))