From 036bd6c5ac265da394472806039ea42823fc4b89 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 15 Feb 2013 17:18:58 +0100 Subject: Restores Bookmarks menu (in 2.x fashion) Cleans up 1.x code about and create a unique bk menu to be shown in rekonq tools menu, (eventually) in the toolbar and in (an ideal) menubar This work starts from Lindsay's review request about. Thanks :) REVIEW: 108729 --- src/CMakeLists.txt | 1 + src/bookmarks/bookmarkmanager.cpp | 20 ++++- src/bookmarks/bookmarkmanager.h | 4 +- src/bookmarks/bookmarksmenu.cpp | 159 +++++++++++++++++++++++++++++++++++++ src/bookmarks/bookmarksmenu.h | 70 ++++++++++++++++ src/bookmarks/bookmarkstoolbar.cpp | 107 +------------------------ src/bookmarks/bookmarkstoolbar.h | 43 ++-------- src/webwindow/rekonqui.rc | 13 +-- src/webwindow/webwindow.cpp | 10 +++ 9 files changed, 273 insertions(+), 154 deletions(-) create mode 100644 src/bookmarks/bookmarksmenu.cpp create mode 100644 src/bookmarks/bookmarksmenu.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1a53c37a..d0984c93 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,6 +27,7 @@ set(rekonq_KDEINIT_SRCS #---------------------------------------- bookmarks/bookmarkmanager.cpp bookmarks/bookmarkscontextmenu.cpp + bookmarks/bookmarksmenu.cpp bookmarks/bookmarkstoolbar.cpp bookmarks/bookmarkowner.cpp #---------------------------------------- diff --git a/src/bookmarks/bookmarkmanager.cpp b/src/bookmarks/bookmarkmanager.cpp index 30a7772a..9c684a01 100644 --- a/src/bookmarks/bookmarkmanager.cpp +++ b/src/bookmarks/bookmarkmanager.cpp @@ -33,8 +33,11 @@ // Local Includes #include "application.h" + +#include "bookmarksmenu.h" #include "bookmarkstoolbar.h" #include "bookmarkowner.h" + #include "iconmanager.h" // KDE Includes @@ -189,8 +192,8 @@ void BookmarkManager::fillBookmarkBar(BookmarkToolBar *toolBar) { KBookmarkActionMenu *menuAction = new KBookmarkActionMenu(bookmark.toGroup(), toolBar); menuAction->setDelayed(false); - BookmarkMenu *bMenu = new BookmarkMenu(m_manager, m_owner, menuAction->menu(), bookmark.address()); - bMenu->setParent(menuAction->menu()); +// BookmarkMenu *bMenu = new BookmarkMenu(m_manager, m_owner, menuAction->menu(), bookmark.address()); +// bMenu->setParent(menuAction->menu()); connect(menuAction->menu(), SIGNAL(aboutToShow()), toolBar, SLOT(menuDisplayed())); connect(menuAction->menu(), SIGNAL(aboutToHide()), toolBar, SLOT(menuHidden())); @@ -314,3 +317,16 @@ void BookmarkManager::emitChanged() { m_manager->emitChanged(); } + +KActionMenu* BookmarkManager::bookmarkActionMenu(QWidget *parent) +{ + KMenu *menu = new KMenu(parent); + KActionMenu *bookmarkActionMenu = new KActionMenu(menu); + bookmarkActionMenu->setMenu(menu); + bookmarkActionMenu->setText(i18n("&Bookmarks")); + BookmarkMenu *bMenu = new BookmarkMenu(m_manager, m_owner, menu, m_actionCollection); + bMenu->setParent(menu); + + return bookmarkActionMenu; +} + diff --git a/src/bookmarks/bookmarkmanager.h b/src/bookmarks/bookmarkmanager.h index c970d390..1a76d0d0 100644 --- a/src/bookmarks/bookmarkmanager.h +++ b/src/bookmarks/bookmarkmanager.h @@ -36,6 +36,7 @@ // KDE Includes #include +#include // Qt Includes #include @@ -44,7 +45,6 @@ // Forward Declarations class BookmarkToolBar; class BookmarkOwner; -class BookmarkMenu; class KAction; class KActionCollection; @@ -121,6 +121,8 @@ public: { return QL1S("application/x-rekonq-bookmark"); } + + KActionMenu* bookmarkActionMenu(QWidget *parent); private: /** diff --git a/src/bookmarks/bookmarksmenu.cpp b/src/bookmarks/bookmarksmenu.cpp new file mode 100644 index 00000000..1f89df04 --- /dev/null +++ b/src/bookmarks/bookmarksmenu.cpp @@ -0,0 +1,159 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2008-2013 by Andrea Diamantini +* Copyright (C) 2010 by Yoann Laissus +* +* +* 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 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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 . +* +* ============================================================ */ + + +// Self Includes +#include "bookmarksmenu.h" +#include "bookmarksmenu.moc" + +// Local Includes +#include "bookmarkscontextmenu.h" +#include "bookmarkmanager.h" +#include "bookmarkowner.h" + +#include "iconmanager.h" +#include "webwindow.h" + +// Qt Includes +#include +#include +#include + + +BookmarkMenu::BookmarkMenu(KBookmarkManager *manager, + KBookmarkOwner *owner, + KMenu *menu, + KActionCollection* actionCollection) + : KBookmarkMenu(manager, owner, menu, actionCollection) +{ +} + + +BookmarkMenu::BookmarkMenu(KBookmarkManager *manager, + KBookmarkOwner *owner, + KMenu *parentMenu, + const QString &parentAddress) + : KBookmarkMenu(manager, owner, parentMenu, parentAddress) +{ +} + + +BookmarkMenu::~BookmarkMenu() +{ + kDebug() << "Deleting BookmarkMenu.. See http://svn.reviewboard.kde.org/r/5606/ about."; +} + + +KMenu * BookmarkMenu::contextMenu(QAction *act) +{ + KBookmarkActionInterface* action = dynamic_cast(act); + if (!action) + return 0; + return new BookmarksContextMenu(action->bookmark(), manager(), static_cast(owner())); +} + + +QAction * BookmarkMenu::actionForBookmark(const KBookmark &bookmark) +{ + if (bookmark.isGroup()) + { + KBookmarkActionMenu *actionMenu = new KBookmarkActionMenu(bookmark, this); + BookmarkMenu *menu = new BookmarkMenu(manager(), owner(), actionMenu->menu(), bookmark.address()); + // An hack to get rid of bug 219274 + connect(actionMenu, SIGNAL(hovered()), menu, SLOT(slotAboutToShow())); + return actionMenu; + } + else if (bookmark.isSeparator()) + { + return KBookmarkMenu::actionForBookmark(bookmark); + } + else + { + KBookmarkAction *action = new KBookmarkAction(bookmark, owner(), this); + action->setIcon(IconManager::self()->iconForUrl(KUrl(bookmark.url()))); + return action; + } +} + + +void BookmarkMenu::refill() +{ + clear(); + + if (isRoot()) + { + addAddBookmark(); + addAddBookmarksList(); + + if (parentMenu()->actions().count() > 0) + parentMenu()->addSeparator(); + + WebWindow *w = qobject_cast(parentMenu()->parent()); + QAction *a; + // bk page + a = w->actionByName(QL1S("open_bookmarks_page")); + parentMenu()->addAction(a); + a = w->actionByName(QL1S("show_bookmarks_toolbar")); + parentMenu()->addAction(a); + + addEditBookmarks(); + + if (parentMenu()->actions().count() > 0) + parentMenu()->addSeparator(); + } + + fillBookmarks(); + + if (!isRoot()) + { + if (parentMenu()->actions().count() > 0) + parentMenu()->addSeparator(); + + addOpenFolderInTabs(); + addAddBookmarksList(); + } +} + + +void BookmarkMenu::addOpenFolderInTabs() +{ + KBookmarkGroup group = manager()->findByAddress(parentAddress()).toGroup(); + + if (!group.first().isNull()) + { + KBookmark bookmark = group.first(); + + while (bookmark.isGroup() || bookmark.isSeparator()) + { + bookmark = group.next(bookmark); + } + + if (!bookmark.isNull()) + { + parentMenu()->addAction(BookmarkManager::self()->owner()->createAction(group, BookmarkOwner::OPEN_FOLDER)); + } + } +} diff --git a/src/bookmarks/bookmarksmenu.h b/src/bookmarks/bookmarksmenu.h new file mode 100644 index 00000000..36b3bca5 --- /dev/null +++ b/src/bookmarks/bookmarksmenu.h @@ -0,0 +1,70 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2008-2013 by Andrea Diamantini +* Copyright (C) 2010 by Yoann Laissus +* +* +* 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 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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 . +* +* ============================================================ */ + + +#ifndef BOOKMARKS_MENU_H +#define BOOKMARKS_MENU_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// KDE Includes +#include + + +/** + * This class represent the rekonq bookmarks menu. + * It's just a simple class inherited from KBookmarkMenu + * + */ +class BookmarkMenu : public KBookmarkMenu +{ + Q_OBJECT + +public: + BookmarkMenu(KBookmarkManager* manager, + KBookmarkOwner* owner, + KMenu* menu, + KActionCollection* actionCollection); + + BookmarkMenu(KBookmarkManager *manager, + KBookmarkOwner *owner, + KMenu *parentMenu, + const QString &parentAddress); + + ~BookmarkMenu(); + +protected: + virtual KMenu * contextMenu(QAction * act); + virtual void refill(); + virtual QAction* actionForBookmark(const KBookmark &bookmark); + +private: + void addOpenFolderInTabs(); +}; + +#endif // BOOKMARKS_MENU_H diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp index c570622f..5c45daeb 100644 --- a/src/bookmarks/bookmarkstoolbar.cpp +++ b/src/bookmarks/bookmarkstoolbar.cpp @@ -2,7 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2008-2012 by Andrea Diamantini +* Copyright (C) 2008-2013 by Andrea Diamantini * Copyright (C) 2010 by Yoann Laissus * * @@ -37,114 +37,15 @@ #include "iconmanager.h" #include "webwindow.h" +// KDE Includes +#include + // Qt Includes #include #include #include -BookmarkMenu::BookmarkMenu(KBookmarkManager *manager, - KBookmarkOwner *owner, - KMenu *menu, - KActionCollection* actionCollection) - : KBookmarkMenu(manager, owner, menu, actionCollection) -{ -} - - -BookmarkMenu::BookmarkMenu(KBookmarkManager *manager, - KBookmarkOwner *owner, - KMenu *parentMenu, - const QString &parentAddress) - : KBookmarkMenu(manager, owner, parentMenu, parentAddress) -{ -} - - -BookmarkMenu::~BookmarkMenu() -{ - kDebug() << "Deleting BookmarkMenu.. See http://svn.reviewboard.kde.org/r/5606/ about."; -} - - -KMenu * BookmarkMenu::contextMenu(QAction *act) -{ - KBookmarkActionInterface* action = dynamic_cast(act); - if (!action) - return 0; - return new BookmarksContextMenu(action->bookmark(), manager(), static_cast(owner())); -} - - -QAction * BookmarkMenu::actionForBookmark(const KBookmark &bookmark) -{ - if (bookmark.isGroup()) - { - KBookmarkActionMenu *actionMenu = new KBookmarkActionMenu(bookmark, this); - BookmarkMenu *menu = new BookmarkMenu(manager(), owner(), actionMenu->menu(), bookmark.address()); - // An hack to get rid of bug 219274 - connect(actionMenu, SIGNAL(hovered()), menu, SLOT(slotAboutToShow())); - return actionMenu; - } - else if (bookmark.isSeparator()) - { - return KBookmarkMenu::actionForBookmark(bookmark); - } - else - { - KBookmarkAction *action = new KBookmarkAction(bookmark, owner(), this); - action->setIcon(IconManager::self()->iconForUrl(KUrl(bookmark.url()))); - connect(action, SIGNAL(hovered()), this, SLOT(actionHovered())); - return action; - } -} - - -void BookmarkMenu::refill() -{ - clear(); - fillBookmarks(); - - if (parentMenu()->actions().count() > 0) - parentMenu()->addSeparator(); - - if (isRoot()) - { - addAddBookmarksList(); - addEditBookmarks(); - } - else - { - addOpenFolderInTabs(); - addAddBookmarksList(); - } -} - - -void BookmarkMenu::addOpenFolderInTabs() -{ - KBookmarkGroup group = manager()->findByAddress(parentAddress()).toGroup(); - - if (!group.first().isNull()) - { - KBookmark bookmark = group.first(); - - while (bookmark.isGroup() || bookmark.isSeparator()) - { - bookmark = group.next(bookmark); - } - - if (!bookmark.isNull()) - { - parentMenu()->addAction(BookmarkManager::self()->owner()->createAction(group, BookmarkOwner::OPEN_FOLDER)); - } - } -} - - -// ------------------------------------------------------------------------------------------------------ - - BookmarkToolBar::BookmarkToolBar(QWidget *parent) : KToolBar(parent, false, false) , m_currentMenu(0) diff --git a/src/bookmarks/bookmarkstoolbar.h b/src/bookmarks/bookmarkstoolbar.h index bca7864f..104debce 100644 --- a/src/bookmarks/bookmarkstoolbar.h +++ b/src/bookmarks/bookmarkstoolbar.h @@ -2,7 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2008-2012 by Andrea Diamantini +* Copyright (C) 2008-2013 by Andrea Diamantini * Copyright (C) 2010 by Yoann Laissus * * @@ -24,6 +24,7 @@ * * ============================================================ */ + #ifndef BOOKMARKSTOOLBAR_H #define BOOKMARKSTOOLBAR_H @@ -31,46 +32,12 @@ // Rekonq Includes #include "rekonq_defines.h" -// KDE Includes -#include - -/** - * This class represent the rekonq bookmarks menu. - * It's just a simple class inherited from KBookmarkMenu - * - */ -class BookmarkMenu : public KBookmarkMenu -{ - Q_OBJECT - -public: - BookmarkMenu(KBookmarkManager* manager, - KBookmarkOwner* owner, - KMenu* menu, - KActionCollection* actionCollection); - BookmarkMenu(KBookmarkManager *manager, - KBookmarkOwner *owner, - KMenu *parentMenu, - const QString &parentAddress); - ~BookmarkMenu(); - -protected: - virtual KMenu * contextMenu(QAction * act); - virtual void refill(); - virtual QAction* actionForBookmark(const KBookmark &bookmark); - -private: - void addOpenFolderInTabs(); - -}; - - -// ------------------------------------------------------------------------------ - - // KDE Includes #include +// Forward Declarations +class KMenu; + /** * This class manage the bookmark toolbar. diff --git a/src/webwindow/rekonqui.rc b/src/webwindow/rekonqui.rc index ea068e56..190111d9 100644 --- a/src/webwindow/rekonqui.rc +++ b/src/webwindow/rekonqui.rc @@ -1,6 +1,6 @@ - + @@ -41,15 +41,8 @@ - - &Bookmarks - - - - - - - + + diff --git a/src/webwindow/webwindow.cpp b/src/webwindow/webwindow.cpp index faf919a7..75636dbd 100644 --- a/src/webwindow/webwindow.cpp +++ b/src/webwindow/webwindow.cpp @@ -62,7 +62,9 @@ #include #include #include +#include +// Qt Includes #include #include #include @@ -303,6 +305,14 @@ void WebWindow::setupActions() // Edit bookmarks a = KStandardAction::editBookmarks(BookmarkManager::self(), SLOT(slotEditBookmarks()), actionCollection()); + + // Bookmark Menu + KActionMenu *bmMenu = BookmarkManager::self()->bookmarkActionMenu(this); + bmMenu->setIcon(KIcon("bookmarks")); + bmMenu->setDelayed(false); + bmMenu->setShortcutConfigurable(true); + bmMenu->setShortcut(KShortcut(Qt::ALT + Qt::Key_B)); + actionCollection()->addAction(QL1S("bookmarksActionMenu"), bmMenu); // User Agent a = new KAction(KIcon("preferences-web-browser-identification"), i18n("Browser Identification"), this); -- cgit v1.2.1