From 5cf7d0b9a9bba792f1f686921399ebe5770ddbdb Mon Sep 17 00:00:00 2001 From: nowrep Date: Sat, 22 Feb 2014 15:20:54 +0100 Subject: [PATCH] [Bookmarks] Add new action to open bookmarks in private window Closes #995 --- src/lib/app/browserwindow.cpp | 2 +- src/lib/app/mainapplication.cpp | 4 ++-- src/lib/app/mainapplication.h | 2 +- src/lib/bookmarks/bookmarksmanager.cpp | 10 ++++++++++ src/lib/bookmarks/bookmarksmanager.h | 1 + src/lib/bookmarks/bookmarkstools.cpp | 10 ++++++++++ src/lib/bookmarks/bookmarkstools.h | 1 + src/lib/sidebar/bookmarkssidebar.cpp | 10 ++++++++++ src/lib/sidebar/bookmarkssidebar.h | 1 + 9 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/lib/app/browserwindow.cpp b/src/lib/app/browserwindow.cpp index d639126b7..391eb7b69 100644 --- a/src/lib/app/browserwindow.cpp +++ b/src/lib/app/browserwindow.cpp @@ -703,7 +703,7 @@ void BrowserWindow::setupOtherActions() } QKeySequence BrowserWindow::actionShortcut(QKeySequence shortcut, QKeySequence fallBack, - QKeySequence shortcutRTL, QKeySequence fallbackRTL) + QKeySequence shortcutRTL, QKeySequence fallbackRTL) { if (isRightToLeft() && (!shortcutRTL.isEmpty() || !fallbackRTL.isEmpty())) { return (shortcutRTL.isEmpty() ? fallbackRTL : shortcutRTL); diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index 506e52c92..d93c37029 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -1062,9 +1062,9 @@ Speller* MainApplication::speller() } #endif -void MainApplication::startPrivateBrowsing() +void MainApplication::startPrivateBrowsing(const QUrl &startUrl) { - const QUrl url = qobject_cast(sender())->data().toUrl(); + const QUrl url = !startUrl.isEmpty() ? startUrl : qobject_cast(sender())->data().toUrl(); QStringList args; foreach (const QString &arg, arguments()) { diff --git a/src/lib/app/mainapplication.h b/src/lib/app/mainapplication.h index 80e3b11c2..56eb17b5c 100644 --- a/src/lib/app/mainapplication.h +++ b/src/lib/app/mainapplication.h @@ -144,7 +144,7 @@ public slots: void setStateChanged(); void addNewTab(const QUrl &url = QUrl()); - void startPrivateBrowsing(); + void startPrivateBrowsing(const QUrl &startUrl = QUrl()); void reloadUserStyleSheet(); bool checkDefaultWebBrowser(); diff --git a/src/lib/bookmarks/bookmarksmanager.cpp b/src/lib/bookmarks/bookmarksmanager.cpp index 2494af377..d181cb2ed 100644 --- a/src/lib/bookmarks/bookmarksmanager.cpp +++ b/src/lib/bookmarks/bookmarksmanager.cpp @@ -103,6 +103,8 @@ void BookmarksManager::createContextMenu(const QPoint &pos) QMenu menu; QAction* actNewTab = menu.addAction(QIcon::fromTheme("tab-new", QIcon(":/icons/menu/tab-new.png")), tr("Open in new tab")); QAction* actNewWindow = menu.addAction(QIcon::fromTheme("window-new"), tr("Open in new window")); + QAction* actNewPrivateWindow = menu.addAction(QIcon(":icons/locationbar/privatebrowsing.png"), tr("Open in new private window")); + menu.addSeparator(); menu.addAction(tr("New Bookmark"), this, SLOT(addBookmark())); menu.addAction(tr("New Folder"), this, SLOT(addFolder())); @@ -112,6 +114,7 @@ void BookmarksManager::createContextMenu(const QPoint &pos) connect(actNewTab, SIGNAL(triggered()), this, SLOT(openBookmarkInNewTab())); connect(actNewWindow, SIGNAL(triggered()), this, SLOT(openBookmarkInNewWindow())); + connect(actNewPrivateWindow, SIGNAL(triggered()), this, SLOT(openBookmarkInNewPrivateWindow())); connect(actDelete, SIGNAL(triggered()), this, SLOT(deleteBookmarks())); bool canBeDeleted = false; @@ -131,6 +134,7 @@ void BookmarksManager::createContextMenu(const QPoint &pos) if (!m_selectedBookmark || !m_selectedBookmark->isUrl()) { actNewTab->setDisabled(true); actNewWindow->setDisabled(true); + actNewPrivateWindow->setDisabled(true); } menu.exec(pos); @@ -154,6 +158,12 @@ void BookmarksManager::openBookmarkInNewWindow(BookmarkItem* item) BookmarksTools::openBookmarkInNewWindow(item); } +void BookmarksManager::openBookmarkInNewPrivateWindow(BookmarkItem* item) +{ + item = item ? item : m_selectedBookmark; + BookmarksTools::openBookmarkInNewPrivateWindow(item); +} + void BookmarksManager::addBookmark() { BookmarkItem* item = new BookmarkItem(BookmarkItem::Url); diff --git a/src/lib/bookmarks/bookmarksmanager.h b/src/lib/bookmarks/bookmarksmanager.h index f253dce75..67c299211 100644 --- a/src/lib/bookmarks/bookmarksmanager.h +++ b/src/lib/bookmarks/bookmarksmanager.h @@ -57,6 +57,7 @@ private slots: void openBookmark(BookmarkItem* item = 0); void openBookmarkInNewTab(BookmarkItem* item = 0); void openBookmarkInNewWindow(BookmarkItem* item = 0); + void openBookmarkInNewPrivateWindow(BookmarkItem* item = 0); void addBookmark(); void addFolder(); diff --git a/src/lib/bookmarks/bookmarkstools.cpp b/src/lib/bookmarks/bookmarkstools.cpp index 9691fcd8e..a6c951e0c 100644 --- a/src/lib/bookmarks/bookmarkstools.cpp +++ b/src/lib/bookmarks/bookmarkstools.cpp @@ -259,6 +259,16 @@ void BookmarksTools::openBookmarkInNewWindow(BookmarkItem* item) mApp->makeNewWindow(Qz::BW_NewWindow, item->url()); } +void BookmarksTools::openBookmarkInNewPrivateWindow(BookmarkItem* item) +{ + if (!item->isUrl()) { + return; + } + + item->setVisitCount(item->visitCount() + 1); + mApp->startPrivateBrowsing(item->url()); +} + void BookmarksTools::openFolderInTabs(BrowserWindow* window, BookmarkItem* folder) { Q_ASSERT(window); diff --git a/src/lib/bookmarks/bookmarkstools.h b/src/lib/bookmarks/bookmarkstools.h index 1cc573637..99e24d704 100644 --- a/src/lib/bookmarks/bookmarkstools.h +++ b/src/lib/bookmarks/bookmarkstools.h @@ -86,6 +86,7 @@ public: static void openBookmark(BrowserWindow* window, BookmarkItem* item); static void openBookmarkInNewTab(BrowserWindow* window, BookmarkItem* item); static void openBookmarkInNewWindow(BookmarkItem* item); + static void openBookmarkInNewPrivateWindow(BookmarkItem* item); static void openFolderInTabs(BrowserWindow* window, BookmarkItem* folder); // Create Menu diff --git a/src/lib/sidebar/bookmarkssidebar.cpp b/src/lib/sidebar/bookmarkssidebar.cpp index b94258120..30102f035 100644 --- a/src/lib/sidebar/bookmarkssidebar.cpp +++ b/src/lib/sidebar/bookmarkssidebar.cpp @@ -79,6 +79,12 @@ void BookmarksSidebar::openBookmarkInNewWindow(BookmarkItem* item) BookmarksTools::openBookmarkInNewWindow(item); } +void BookmarksSidebar::openBookmarkInNewPrivateWindow(BookmarkItem* item) +{ + item = item ? item : ui->tree->selectedBookmark(); + BookmarksTools::openBookmarkInNewPrivateWindow(item); +} + void BookmarksSidebar::deleteBookmarks() { QList items = ui->tree->selectedBookmarks(); @@ -95,11 +101,14 @@ void BookmarksSidebar::createContextMenu(const QPoint &pos) QMenu menu; QAction* actNewTab = menu.addAction(QIcon::fromTheme("tab-new", QIcon(":/icons/menu/tab-new.png")), tr("Open in new tab")); QAction* actNewWindow = menu.addAction(QIcon::fromTheme("window-new"), tr("Open in new window")); + QAction* actNewPrivateWindow = menu.addAction(QIcon(":icons/locationbar/privatebrowsing.png"), tr("Open in new private window")); + menu.addSeparator(); QAction* actDelete = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); connect(actNewTab, SIGNAL(triggered()), this, SLOT(openBookmarkInNewTab())); connect(actNewWindow, SIGNAL(triggered()), this, SLOT(openBookmarkInNewWindow())); + connect(actNewPrivateWindow, SIGNAL(triggered()), this, SLOT(openBookmarkInNewPrivateWindow())); connect(actDelete, SIGNAL(triggered()), this, SLOT(deleteBookmarks())); bool canBeDeleted = false; @@ -119,6 +128,7 @@ void BookmarksSidebar::createContextMenu(const QPoint &pos) if (!ui->tree->selectedBookmark() || !ui->tree->selectedBookmark()->isUrl()) { actNewTab->setDisabled(true); actNewWindow->setDisabled(true); + actNewPrivateWindow->setDisabled(true); } menu.exec(pos); diff --git a/src/lib/sidebar/bookmarkssidebar.h b/src/lib/sidebar/bookmarkssidebar.h index cbbd6bf96..208f2ae20 100644 --- a/src/lib/sidebar/bookmarkssidebar.h +++ b/src/lib/sidebar/bookmarkssidebar.h @@ -47,6 +47,7 @@ private slots: void openBookmark(BookmarkItem* item = 0); void openBookmarkInNewTab(BookmarkItem* item = 0); void openBookmarkInNewWindow(BookmarkItem* item = 0); + void openBookmarkInNewPrivateWindow(BookmarkItem* item = 0); void deleteBookmarks(); void createContextMenu(const QPoint &pos);