2014-02-09 01:09:08 +01:00
|
|
|
/* ============================================================
|
2017-08-25 17:11:29 +02:00
|
|
|
* Falkon - Qt web browser
|
2014-02-09 01:09:08 +01:00
|
|
|
* Copyright (C) 2014 David Rosca <nowrep@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "bookmarksmenu.h"
|
|
|
|
#include "bookmarkstools.h"
|
|
|
|
#include "bookmarkitem.h"
|
|
|
|
#include "bookmarks.h"
|
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "browsinglibrary.h"
|
2014-02-19 22:07:21 +01:00
|
|
|
#include "browserwindow.h"
|
2014-02-09 01:09:08 +01:00
|
|
|
#include "qzsettings.h"
|
|
|
|
#include "tabwidget.h"
|
2016-12-11 09:40:57 +01:00
|
|
|
#include "iconprovider.h"
|
2014-02-09 01:09:08 +01:00
|
|
|
|
|
|
|
BookmarksMenu::BookmarksMenu(QWidget* parent)
|
|
|
|
: Menu(parent)
|
|
|
|
, m_window(0)
|
|
|
|
, m_changed(true)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
|
|
|
|
connect(mApp->bookmarks(), SIGNAL(bookmarkAdded(BookmarkItem*)), this, SLOT(bookmarksChanged()));
|
|
|
|
connect(mApp->bookmarks(), SIGNAL(bookmarkRemoved(BookmarkItem*)), this, SLOT(bookmarksChanged()));
|
|
|
|
connect(mApp->bookmarks(), SIGNAL(bookmarkChanged(BookmarkItem*)), this, SLOT(bookmarksChanged()));
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BookmarksMenu::setMainWindow(BrowserWindow* window)
|
2014-02-09 01:09:08 +01:00
|
|
|
{
|
2014-02-27 22:53:56 +01:00
|
|
|
Q_ASSERT(window);
|
|
|
|
|
2014-02-09 01:09:08 +01:00
|
|
|
m_window = window;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksMenu::bookmarkPage()
|
|
|
|
{
|
|
|
|
if (m_window) {
|
|
|
|
m_window->bookmarkPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksMenu::bookmarkAllTabs()
|
|
|
|
{
|
|
|
|
if (m_window) {
|
|
|
|
BookmarksTools::bookmarkAllTabsDialog(m_window, m_window->tabWidget());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksMenu::showBookmarksManager()
|
|
|
|
{
|
|
|
|
if (m_window) {
|
|
|
|
mApp->browsingLibrary()->showBookmarks(m_window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksMenu::bookmarksChanged()
|
|
|
|
{
|
|
|
|
m_changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksMenu::aboutToShow()
|
|
|
|
{
|
|
|
|
if (m_changed) {
|
|
|
|
refresh();
|
|
|
|
m_changed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-11 09:40:57 +01:00
|
|
|
void BookmarksMenu::menuAboutToShow()
|
|
|
|
{
|
|
|
|
Q_ASSERT(qobject_cast<Menu*>(sender()));
|
|
|
|
Menu *menu = static_cast<Menu*>(sender());
|
|
|
|
|
|
|
|
foreach (QAction *action, menu->actions()) {
|
|
|
|
BookmarkItem *item = static_cast<BookmarkItem*>(action->data().value<void*>());
|
|
|
|
if (item && item->type() == BookmarkItem::Url && action->icon().isNull()) {
|
2016-12-20 12:16:12 +01:00
|
|
|
action->setIcon(item->icon());
|
2016-12-11 09:40:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 11:54:58 +01:00
|
|
|
void BookmarksMenu::menuMiddleClicked(Menu* menu)
|
2014-02-09 01:09:08 +01:00
|
|
|
{
|
|
|
|
BookmarkItem* item = static_cast<BookmarkItem*>(menu->menuAction()->data().value<void*>());
|
|
|
|
Q_ASSERT(item);
|
|
|
|
openFolder(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksMenu::bookmarkActivated()
|
|
|
|
{
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
|
|
|
BookmarkItem* item = static_cast<BookmarkItem*>(action->data().value<void*>());
|
|
|
|
Q_ASSERT(item);
|
|
|
|
openBookmark(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksMenu::bookmarkCtrlActivated()
|
|
|
|
{
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
|
|
|
BookmarkItem* item = static_cast<BookmarkItem*>(action->data().value<void*>());
|
|
|
|
Q_ASSERT(item);
|
|
|
|
openBookmarkInNewTab(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksMenu::bookmarkShiftActivated()
|
|
|
|
{
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
|
|
|
BookmarkItem* item = static_cast<BookmarkItem*>(action->data().value<void*>());
|
|
|
|
Q_ASSERT(item);
|
|
|
|
openBookmarkInNewWindow(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksMenu::openFolder(BookmarkItem* item)
|
|
|
|
{
|
|
|
|
Q_ASSERT(item->isFolder());
|
|
|
|
|
2014-02-09 15:07:19 +01:00
|
|
|
if (m_window) {
|
|
|
|
BookmarksTools::openFolderInTabs(m_window, item);
|
2014-02-09 01:09:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksMenu::openBookmark(BookmarkItem* item)
|
|
|
|
{
|
|
|
|
Q_ASSERT(item->isUrl());
|
|
|
|
|
|
|
|
if (m_window) {
|
2014-02-09 11:02:51 +01:00
|
|
|
BookmarksTools::openBookmark(m_window, item);
|
2014-02-09 01:09:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksMenu::openBookmarkInNewTab(BookmarkItem* item)
|
|
|
|
{
|
|
|
|
Q_ASSERT(item->isUrl());
|
|
|
|
|
|
|
|
if (m_window) {
|
2014-02-09 11:02:51 +01:00
|
|
|
BookmarksTools::openBookmarkInNewTab(m_window, item);
|
2014-02-09 01:09:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksMenu::openBookmarkInNewWindow(BookmarkItem* item)
|
|
|
|
{
|
|
|
|
Q_ASSERT(item->isUrl());
|
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
BookmarksTools::openBookmarkInNewWindow(item);
|
2014-02-09 01:09:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksMenu::init()
|
|
|
|
{
|
|
|
|
setTitle(tr("&Bookmarks"));
|
|
|
|
|
2016-12-31 14:32:48 +01:00
|
|
|
addAction(tr("Bookmark &This Page"), this, SLOT(bookmarkPage()))->setShortcut(QKeySequence("Ctrl+D"));
|
|
|
|
addAction(tr("Bookmark &All Tabs"), this, SLOT(bookmarkAllTabs()));
|
2014-03-24 16:08:33 +01:00
|
|
|
addAction(QIcon::fromTheme("bookmarks-organize"), tr("Organize &Bookmarks"), this, SLOT(showBookmarksManager()))->setShortcut(QKeySequence("Ctrl+Shift+O"));
|
2014-02-09 01:09:08 +01:00
|
|
|
addSeparator();
|
|
|
|
|
|
|
|
connect(this, SIGNAL(aboutToShow()), this, SLOT(aboutToShow()));
|
2016-12-11 09:40:57 +01:00
|
|
|
connect(this, SIGNAL(aboutToShow()), this, SLOT(menuAboutToShow()));
|
2014-02-10 11:54:58 +01:00
|
|
|
connect(this, SIGNAL(menuMiddleClicked(Menu*)), this, SLOT(menuMiddleClicked(Menu*)));
|
2014-02-09 01:09:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksMenu::refresh()
|
|
|
|
{
|
|
|
|
while (actions().count() != 4) {
|
|
|
|
QAction* act = actions().at(4);
|
|
|
|
if (act->menu()) {
|
|
|
|
act->menu()->clear();
|
|
|
|
}
|
|
|
|
removeAction(act);
|
|
|
|
delete act;
|
|
|
|
}
|
|
|
|
|
2014-02-10 11:54:58 +01:00
|
|
|
BookmarksTools::addActionToMenu(this, this, mApp->bookmarks()->toolbarFolder());
|
2014-02-09 01:09:08 +01:00
|
|
|
addSeparator();
|
|
|
|
|
|
|
|
foreach (BookmarkItem* child, mApp->bookmarks()->menuFolder()->children()) {
|
2014-02-10 11:54:58 +01:00
|
|
|
BookmarksTools::addActionToMenu(this, this, child);
|
2014-02-09 01:09:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
addSeparator();
|
2014-02-10 11:54:58 +01:00
|
|
|
BookmarksTools::addActionToMenu(this, this, mApp->bookmarks()->unsortedFolder());
|
2014-02-09 01:09:08 +01:00
|
|
|
}
|