From a48a5a4157e9af22adb3a7673203ed8ced5ceeab Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Tue, 6 Apr 2010 12:43:21 +0200 Subject: - Enable context menu for folders and separators of the bookmark bar - Use the same context menu for the bookmark panel and the bookmark bar - Use a list to store the different bookmark bars - Fix the different crashes when there are more than one window - When the bookmarks are changed, all the bars are refreshed --- src/bookmarks/bookmarkcontextmenu.cpp | 309 ++++++++++++++++++++++++++++++++++ src/bookmarks/bookmarkcontextmenu.h | 63 +++++++ src/bookmarks/bookmarksmanager.cpp | 132 +++++++++++---- src/bookmarks/bookmarksmanager.h | 27 ++- src/bookmarks/bookmarkspanel.cpp | 307 +++------------------------------ src/bookmarks/bookmarkspanel.h | 14 +- 6 files changed, 518 insertions(+), 334 deletions(-) create mode 100644 src/bookmarks/bookmarkcontextmenu.cpp create mode 100644 src/bookmarks/bookmarkcontextmenu.h (limited to 'src/bookmarks') diff --git a/src/bookmarks/bookmarkcontextmenu.cpp b/src/bookmarks/bookmarkcontextmenu.cpp new file mode 100644 index 00000000..ccb63143 --- /dev/null +++ b/src/bookmarks/bookmarkcontextmenu.cpp @@ -0,0 +1,309 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* 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 "bookmarkcontextmenu.h" + +// Local Includes +#include "application.h" +#include "bookmarksmanager.h" + +// KDE Includes +#include +#include +#include + + +BookmarkContextMenu::BookmarkContextMenu(const KBookmark & bookmark, KBookmarkManager *manager, KBookmarkOwner *owner, QWidget *parent) + : KBookmarkContextMenu(bookmark, manager, owner, parent) + , m_ac(new KActionCollection(this)) +{ + setupActions(); +} + + +void BookmarkContextMenu::setupActions() +{ + KAction* action; + + action = new KAction(KIcon("tab-new"), i18n("Open"), this); + connect(action, SIGNAL(triggered()), this, SLOT(openInCurrentTab())); + m_ac->addAction("open", action); + + action = new KAction(KIcon("tab-new"), i18n("Open in New Tab"), this); + connect(action, SIGNAL(triggered()), this, SLOT(openInNewTab())); + m_ac->addAction("open_tab", action); + + action = new KAction(KIcon("window-new"), i18n("Open in New Window"), this); + connect(action, SIGNAL(triggered()), this, SLOT(openInNewWindow())); + m_ac->addAction("open_window", action); + + action = new KAction(KIcon("bookmark-new"), i18n("Add Bookmark Here"), this); + connect(action, SIGNAL(triggered()), this, SLOT(bookmarkCurrentPage())); + m_ac->addAction("bookmark_page", action); + + action = new KAction(KIcon("folder-new"), i18n("New Bookmark Folder"), this); + connect(action, SIGNAL(triggered()), this, SLOT(newBookmarkGroup())); + m_ac->addAction("folder_new", action); + + action = new KAction(KIcon("edit-clear"), i18n("New Separator"), this); + connect(action, SIGNAL(triggered()), this, SLOT(newSeparator())); + m_ac->addAction("separator_new", action); + + action = new KAction(KIcon("edit-copy"), i18n("Copy Link Address"), this); + connect(action, SIGNAL(triggered()), this, SLOT(copyToClipboard())); + m_ac->addAction("copy", action); + + action = new KAction(KIcon("edit-delete"), i18n("Delete Bookmark"), this); + connect(action, SIGNAL(triggered()), this, SLOT(deleteBookmark())); + m_ac->addAction("delete", action); + + action = new KAction(KIcon("configure"), i18n("Properties"), this); + connect(action, SIGNAL(triggered()), this, SLOT(editBookmark())); + m_ac->addAction("properties", action); + + action = new KAction(KIcon("tab-new"), i18n("Open Folder in Tabs"), this); + connect(action, SIGNAL(triggered()), this, SLOT(openFolderInTabs())); + m_ac->addAction("open_all", action); +} + + +void BookmarkContextMenu::addBookmarkActions() +{ + addAction(m_ac->action("open")); + addAction(m_ac->action("open_tab")); + addAction(m_ac->action("open_window")); + + addSeparator(); + + addAction(m_ac->action("bookmark_page")); + addAction(m_ac->action("folder_new")); + addAction(m_ac->action("separator_new")); + + addSeparator(); + + addAction(m_ac->action("copy")); + + addSeparator(); + + addAction(m_ac->action("delete")); + addAction(m_ac->action("properties")); +} + + +void BookmarkContextMenu::addFolderActions() +{ + if(!bookmark().toGroup().first().isNull()) + { + addAction(m_ac->action("open_all")); + addSeparator(); + } + + addAction(m_ac->action("bookmark_page")); + addAction(m_ac->action("folder_new")); + addAction(m_ac->action("separator_new")); + + addSeparator(); + + addAction(m_ac->action("delete")); + addAction(m_ac->action("properties")); +} + + +void BookmarkContextMenu::addSeparatorActions() +{ + addAction(m_ac->action("bookmark_page")); + addAction(m_ac->action("folder_new")); + addAction(m_ac->action("separator_new")); + + addSeparator(); + + addAction(m_ac->action("delete")); +} + + +void BookmarkContextMenu::addActions() +{ + if(bookmark().isGroup()) + { + addFolderActions(); + } + + else if(bookmark().isSeparator()) + { + addSeparatorActions(); + } + + else if(bookmark().isNull()) + { + addAction(m_ac->action("bookmark_page")); + addAction(m_ac->action("folder_new")); + addAction(m_ac->action("separator_new")); + } + + else + { + addBookmarkActions(); + } +} + + +void BookmarkContextMenu::openInCurrentTab() +{ + Application::instance()->loadUrl(bookmark().url()); +} + + +void BookmarkContextMenu::openInNewTab() +{ + Application::instance()->loadUrl(bookmark().url(), Rekonq::SettingOpenTab); +} + + +void BookmarkContextMenu::openInNewWindow() +{ + Application::instance()->loadUrl(bookmark().url(), Rekonq::NewWindow); +} + +void BookmarkContextMenu::deleteBookmark() +{ + KBookmark bm = bookmark(); + bool folder = bm.isGroup(); + + if (KMessageBox::warningContinueCancel( + QApplication::activeWindow(), + folder ? i18n("Are you sure you wish to remove the bookmark folder\n\"%1\"?", bm.text()) + : i18n("Are you sure you wish to remove the bookmark\n\"%1\"?", bm.text()), + folder ? i18n("Bookmark Folder Deletion") + : i18n("Bookmark Deletion"), + KStandardGuiItem::del()) + != KMessageBox::Continue + ) + return; + + bm.parentGroup().deleteBookmark(bm); + manager()->emitChanged(); +} + + +void BookmarkContextMenu::editBookmark() +{ + KBookmark selected = bookmark(); + + KBookmarkDialog *dialog = owner()->bookmarkDialog(manager(), QApplication::activeWindow()); + dialog->editBookmark(selected); + delete dialog; +} + + +void BookmarkContextMenu::openFolderInTabs() +{ + if(bookmark().isGroup()) + owner()->openFolderinTabs(bookmark().toGroup()); +} + + +void BookmarkContextMenu::newBookmarkGroup() +{ + KBookmark newBk; + KBookmark selected = bookmark(); + KBookmarkDialog *dialog = owner()->bookmarkDialog(manager(), QApplication::activeWindow()); + + if(!selected.isNull()) + { + if(selected.isGroup()) + { + newBk = dialog->createNewFolder("New folder", selected); + } + + else + { + newBk = dialog->createNewFolder("New folder", selected.parentGroup()); + selected.parentGroup().moveBookmark(newBk, selected); + manager()->emitChanged(); + } + } + else + { + dialog->createNewFolder("New folder"); + } + + delete dialog; +} + + +void BookmarkContextMenu::newSeparator() +{ + KBookmark selected = bookmark(); + KBookmark newBk; + + if(!selected.isNull()) + { + if(selected.isGroup()) + newBk = selected.toGroup().createNewSeparator(); + else + newBk = selected.parentGroup().createNewSeparator(); + } + + else + { + newBk = Application::bookmarkProvider()->rootGroup().createNewSeparator(); + } + + KBookmarkGroup parent = newBk.parentGroup(); + newBk.setIcon(("edit-clear")); + parent.addBookmark(newBk); + + if(!selected.isNull()) + parent.moveBookmark(newBk, selected); + + manager()->emitChanged(); +} + + +void BookmarkContextMenu::bookmarkCurrentPage() +{ + KBookmarkGroup parent = Application::bookmarkProvider()->rootGroup(); + KBookmark selected = bookmark(); + + if(!selected.isNull()) + { + parent = selected.parentGroup(); + + if(selected.isGroup()) + parent = selected.toGroup(); + + KBookmark newBk = parent.addBookmark(owner()->currentTitle(), KUrl(owner()->currentUrl()), "text-html"); + parent.moveBookmark(newBk, selected.parentGroup().previous(selected)); + } + + else + { + parent.addBookmark(owner()->currentTitle(), KUrl(owner()->currentUrl()), "text-html"); + } + + manager()->emitChanged(); +} diff --git a/src/bookmarks/bookmarkcontextmenu.h b/src/bookmarks/bookmarkcontextmenu.h new file mode 100644 index 00000000..38fbc71a --- /dev/null +++ b/src/bookmarks/bookmarkcontextmenu.h @@ -0,0 +1,63 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* 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 BOOKMARKCONTEXTMENU_H +#define BOOKMARKCONTEXTMENU_H + +// Local Includes +#include "application.h" + +// Qt Includes +#include + + +class BookmarkContextMenu : public KBookmarkContextMenu +{ + Q_OBJECT +public: + BookmarkContextMenu(const KBookmark & bk, KBookmarkManager * manager, KBookmarkOwner *owner, QWidget * parent = 0); + virtual void addActions(); + +private slots: + void openInCurrentTab(); + void openInNewTab(); + void openInNewWindow(); + void deleteBookmark(); + void openFolderInTabs(); + void editBookmark(); + void newBookmarkGroup(); + void newSeparator(); + void bookmarkCurrentPage(); + +private: + void setupActions(); + void addFolderActions(); + void addBookmarkActions(); + void addSeparatorActions(); + KActionCollection *m_ac; +}; + +#endif // BOOKMARKCONTEXTMENU_H diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp index 6a5417fc..8cdc5d8e 100644 --- a/src/bookmarks/bookmarksmanager.cpp +++ b/src/bookmarks/bookmarksmanager.cpp @@ -34,18 +34,18 @@ #include "mainwindow.h" #include "webtab.h" #include "webview.h" +#include "bookmarkcontextmenu.h" // KDE Includes #include -#include #include #include -#include #include #include #include #include #include +#include // Qt Includes #include @@ -96,6 +96,13 @@ QString BookmarkOwner::currentTitle() const void BookmarkOwner::openFolderinTabs(const KBookmarkGroup &bm) { QList urlList = bm.groupUrlList(); + + if(urlList.length() > 8) + { + if(!(KMessageBox::warningContinueCancel(Application::instance()->mainWindow(), i18n("You are about to open %1 tabs.\nAre you sure ?", QString::number(urlList.length()))) == KMessageBox::Continue)) + return; + } + QList::iterator url; for (url = urlList.begin(); url != urlList.end(); ++url) { @@ -126,12 +133,10 @@ BookmarkMenu::~BookmarkMenu() KMenu *BookmarkMenu::viewContextMenu(QAction *action) { - // contextMenu() returns an invalid KMenu (seg fault) for the folders in the toolbar - KMenu *menu = contextMenu(action); - if(menu) - return menu; - - return 0; // new KMenu(); + KBookmarkActionInterface* act = dynamic_cast(action); + if (!act) + return 0; + return new BookmarkContextMenu(act->bookmark(), manager(), owner()); } @@ -160,7 +165,6 @@ BookmarkProvider::BookmarkProvider(QObject *parent) , m_owner(0) , m_actionCollection(new KActionCollection(this)) , m_bookmarkMenu(0) - , m_bookmarkToolBar(0) , m_completion(0) { // take care of the completion object @@ -204,36 +208,44 @@ BookmarkProvider::~BookmarkProvider() } -void BookmarkProvider::setupBookmarkBar(KToolBar *t) +void BookmarkProvider::setupBookmarkBar(KToolBar *toolbar) { - m_bookmarkToolBar = t; - connect(m_bookmarkToolBar, SIGNAL(customContextMenuRequested(const QPoint &)), + KToolBar *bookmarkToolBar = toolbar; + m_bookmarkToolBars.append(toolbar); + connect(bookmarkToolBar, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenu(const QPoint &))); slotBookmarksChanged("", ""); } +void BookmarkProvider::removeToolBar(KToolBar *toolbar) +{ + m_bookmarkToolBars.removeOne(toolbar); +} void BookmarkProvider::slotBookmarksChanged(const QString &group, const QString &caller) { Q_UNUSED(group) Q_UNUSED(caller) - if (!m_bookmarkToolBar) - return; - - KBookmarkGroup toolBarGroup = m_manager->toolbar(); - if (toolBarGroup.isNull()) - return; - - m_bookmarkToolBar->clear(); // FIXME CRASH - m_completion->clear(); - - KBookmark bookmark = toolBarGroup.first(); - while (!bookmark.isNull()) + foreach(KToolBar *bookmarkToolBar, m_bookmarkToolBars) { - m_bookmarkToolBar->addAction(fillBookmarkBar(bookmark)); - bookmark = toolBarGroup.next(bookmark); + if (bookmarkToolBar) + { + KBookmarkGroup toolBarGroup = m_manager->toolbar(); + if (toolBarGroup.isNull()) + return; + + bookmarkToolBar->clear(); + m_completion->clear(); + + KBookmark bookmark = toolBarGroup.first(); + while (!bookmark.isNull()) + { + bookmarkToolBar->addAction(fillBookmarkBar(bookmark)); + bookmark = toolBarGroup.next(bookmark); + } + } } } @@ -249,13 +261,22 @@ QAction *BookmarkProvider::actionByName(const QString &name) void BookmarkProvider::contextMenu(const QPoint &point) { - KAction* action = dynamic_cast(m_bookmarkToolBar->actionAt(point)); + if(m_bookmarkToolBars.isEmpty()) + return; + + KToolBar *bookmarkToolBar = m_bookmarkToolBars.at(0); + if(!bookmarkToolBar) + return; + + KAction* action = dynamic_cast(bookmarkToolBar->actionAt(point)); if (!action) return; + KMenu *menu = m_bookmarkMenu->viewContextMenu(action); if (!menu) return; - menu->popup(m_bookmarkToolBar->mapToGlobal(point)); + + menu->popup(bookmarkToolBar->mapToGlobal(point)); } @@ -276,19 +297,23 @@ KAction *BookmarkProvider::fillBookmarkBar(const KBookmark &bookmark) { KBookmarkGroup group = bookmark.toGroup(); KBookmark bm = group.first(); - KActionMenu *menuAction = new KActionMenu(KIcon(bookmark.icon()), bookmark.text(), this); - menuAction->setDelayed(false); + BookmarkActionMenu *menuAction = new BookmarkActionMenu(group, this); + while (!bm.isNull()) { menuAction->addAction(fillBookmarkBar(bm)); bm = group.next(bm); } + + menuAction->addFolderActions(); return menuAction; } if(bookmark.isSeparator()) { - KAction *a = new KAction(this); + KAction *a = new KBookmarkAction(bookmark, m_owner, this); + a->setText(""); + a->setIcon(QIcon()); a->setSeparator(true); return a; } @@ -305,15 +330,13 @@ KBookmarkGroup BookmarkProvider::rootGroup() return m_manager->root(); } + KCompletion *BookmarkProvider::completionObject() const { return m_completion; } - - - QString BookmarkProvider::titleForBookmarkUrl(QString url) { QString title = ""; @@ -361,4 +384,45 @@ QString BookmarkProvider::titleForBookmarkUrl(const KBookmark &bookmark, QString } +// ---------------------------------------------------------------------------------------------- + + +BookmarkActionMenu::BookmarkActionMenu(const KBookmarkGroup &bm, QObject *parent) + : KBookmarkActionMenu(bm, bm.text(), parent) + , m_group(bm) +{ + setIcon(KIcon(bm.icon())); + setDelayed(false); +} + + +void BookmarkActionMenu::addFolderActions() +{ + addSeparator(); + KAction *action; + + if(!m_group.first().isNull()) + { + action = new KAction(KIcon("tab-new"), i18n("Open Folder in Tabs"), this); + connect(action, SIGNAL(triggered(bool)), this, SLOT(openActionInTabs())); + addAction(action); + } + + action = new KAction(KIcon("bookmark-new"), i18n("Add Bookmark Here"), this); + connect(action, SIGNAL(triggered(bool)), this, SLOT(bookmarkCurrentPage())); + addAction(action); +} + + +void BookmarkActionMenu::bookmarkCurrentPage() +{ + m_group.addBookmark(Application::bookmarkProvider()->bookmarkOwner()->currentTitle(), KUrl(Application::bookmarkProvider()->bookmarkOwner()->currentUrl())); + Application::bookmarkProvider()->bookmarkManager()->emitChanged(); +} + +void BookmarkActionMenu::openActionInTabs() +{ + if(!m_group.isNull()) + Application::bookmarkProvider()->bookmarkOwner()->openFolderinTabs(m_group); +} diff --git a/src/bookmarks/bookmarksmanager.h b/src/bookmarks/bookmarksmanager.h index ace06e95..3c21bc67 100644 --- a/src/bookmarks/bookmarksmanager.h +++ b/src/bookmarks/bookmarksmanager.h @@ -194,6 +194,7 @@ public: */ void setupBookmarkBar(KToolBar *); + void removeToolBar(KToolBar*); /** * @short Get action by name @@ -220,7 +221,7 @@ public: KCompletion *completionObject() const; QString titleForBookmarkUrl(QString url); - + signals: /** * @short This signal is emitted when an url has to be loaded @@ -256,8 +257,30 @@ private: BookmarkOwner *m_owner; KActionCollection *m_actionCollection; BookmarkMenu *m_bookmarkMenu; - KToolBar *m_bookmarkToolBar; + QList m_bookmarkToolBars; KCompletion *m_completion; }; + +// ------------------------------------------------------------------------------------------ + + +class BookmarkActionMenu : public KBookmarkActionMenu +{ + Q_OBJECT + +public: + BookmarkActionMenu (const KBookmarkGroup &bm, QObject *parent); + void addFolderActions(); + +private slots: + void openActionInTabs(); + void bookmarkCurrentPage(); + +private: + KBookmarkGroup m_group; + +}; + + #endif diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp index 2f530c6c..6360b313 100644 --- a/src/bookmarks/bookmarkspanel.cpp +++ b/src/bookmarks/bookmarkspanel.cpp @@ -32,6 +32,7 @@ #include "bookmarksmanager.h" #include "bookmarkstreemodel.h" #include "bookmarksproxy.h" +#include "bookmarkcontextmenu.h" // Auto Includes #include "rekonq.h" @@ -39,26 +40,21 @@ // Qt includes #include #include -#include #include // KDE includes #include #include -#include #include -#include #include BookmarksPanel::BookmarksPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags) : QDockWidget(title, parent, flags), m_treeView(new UrlTreeView(this)), - m_ac(new KActionCollection(this)), m_loadingState(false) { setup(); - setupActions(); setShown(ReKonfig::showBookmarksPanel()); } @@ -111,9 +107,9 @@ void BookmarksPanel::setup() proxy->setSourceModel( model ); m_treeView->setModel( proxy ); - connect(m_treeView, SIGNAL(contextMenuItemRequested(const QPoint &)), this, SLOT(contextMenuBk(const QPoint &))); - connect(m_treeView, SIGNAL(contextMenuGroupRequested(const QPoint &)), this, SLOT(contextMenuBkGroup(const QPoint &))); - connect(m_treeView, SIGNAL(contextMenuEmptyRequested(const QPoint &)), this, SLOT(contextMenuBlank(const QPoint &))); + connect(m_treeView, SIGNAL(contextMenuItemRequested(const QPoint &)), this, SLOT(contextMenu(const QPoint &))); + connect(m_treeView, SIGNAL(contextMenuGroupRequested(const QPoint &)), this, SLOT(contextMenu(const QPoint &))); + connect(m_treeView, SIGNAL(contextMenuEmptyRequested(const QPoint &)), this, SLOT(contextMenu(const QPoint &))); connect(m_treeView, SIGNAL(delKeyPressed()), this, SLOT(deleteBookmark())); connect(m_treeView, SIGNAL(collapsed(const QModelIndex &)), this, SLOT(onCollapse(const QModelIndex &))); connect(m_treeView, SIGNAL(expanded(const QModelIndex &)), this, SLOT(onExpand(const QModelIndex &))); @@ -122,6 +118,19 @@ void BookmarksPanel::setup() } +KBookmark BookmarksPanel::bookmarkForIndex(const QModelIndex &index) +{ + if(!index.isValid()) + return KBookmark(); + + const QAbstractProxyModel* proxyModel = dynamic_cast< const QAbstractProxyModel* >(index.model()); + QModelIndex originalIndex = proxyModel->mapToSource(index); + + BtmItem *node = static_cast< BtmItem* >( originalIndex.internalPointer() ); + return node->getBkm(); +} + + void BookmarksPanel::onCollapse(const QModelIndex &index) { if(m_loadingState) @@ -170,165 +179,16 @@ void BookmarksPanel::loadFoldedState(const QModelIndex &root) } -void BookmarksPanel::setupActions() +void BookmarksPanel::contextMenu(const QPoint &pos) { - KAction* action; - - action = new KAction(KIcon("tab-new"), i18n("Open"), this); - connect(action, SIGNAL(triggered()), m_treeView, SLOT(openInCurrentTab())); - m_ac->addAction("open", action); - - action = new KAction(KIcon("tab-new"), i18n("Open in New Tab"), this); - connect(action, SIGNAL(triggered()), m_treeView, SLOT(openInNewTab())); - m_ac->addAction("open_tab", action); - - action = new KAction(KIcon("window-new"), i18n("Open in New Window"), this); - connect(action, SIGNAL(triggered()), m_treeView, SLOT(openInNewWindow())); - m_ac->addAction("open_window", action); - - action = new KAction(KIcon("bookmark-new"), i18n("Add Bookmark Here"), this); - connect(action, SIGNAL(triggered()), this, SLOT(bookmarkCurrentPage())); - m_ac->addAction("bookmark_page", action); - - action = new KAction(KIcon("folder-new"), i18n("New Bookmark Folder"), this); - connect(action, SIGNAL(triggered()), this, SLOT(newBookmarkGroup())); - m_ac->addAction("folder_new", action); - - action = new KAction(KIcon("edit-clear"), i18n("New Separator"), this); - connect(action, SIGNAL(triggered()), this, SLOT(newSeparator())); - m_ac->addAction("separator_new", action); - - action = new KAction(KIcon("edit-copy"), i18n("Copy Link Address"), this); - connect(action, SIGNAL(triggered()), m_treeView, SLOT(copyToClipboard())); - m_ac->addAction("copy", action); - - action = new KAction(KIcon("edit-delete"), i18n("Delete Bookmark"), this); - connect(action, SIGNAL(triggered()), this, SLOT(deleteBookmark())); - m_ac->addAction("delete", action); - - action = new KAction(KIcon("configure"), i18n("Properties"), this); - connect(action, SIGNAL(triggered()), this, SLOT(editBookmark())); - m_ac->addAction("properties", action); - - action = new KAction(KIcon("tab-new"), i18n("Open Folder in Tabs"), this); - connect(action, SIGNAL(triggered()), this, SLOT(openFolderInTabs())); - m_ac->addAction("open_all", action); -} - - -KBookmark BookmarksPanel::bookmarkForIndex(const QModelIndex &index) -{ - if(!index.isValid()) - return KBookmark(); - - const QAbstractProxyModel* proxyModel = dynamic_cast< const QAbstractProxyModel* >(index.model()); - QModelIndex originalIndex = proxyModel->mapToSource(index); - - BtmItem *node = static_cast< BtmItem* >( originalIndex.internalPointer() ); - return node->getBkm(); -} - - -void BookmarksPanel::contextMenuBk(const QPoint &pos) -{ - QPoint position = m_treeView->mapToGlobal(pos); QModelIndex index = m_treeView->indexAt(pos); - if(!index.isValid() || m_loadingState) - return; - - KBookmark selected = bookmarkForIndex(index); - - if(selected.isGroup()) - { - contextMenuBkGroup(pos, true); - return; - } - - if(selected.isSeparator()) - { - contextMenuSeparator(pos); - return; - } - - KMenu *menu = new KMenu(this); - - menu->addAction(m_ac->action("open")); - menu->addAction(m_ac->action("open_tab")); - menu->addAction(m_ac->action("open_window")); - - menu->addSeparator(); - - menu->addAction(m_ac->action("bookmark_page")); - menu->addAction(m_ac->action("folder_new")); - menu->addAction(m_ac->action("separator_new")); - - menu->addSeparator(); - - menu->addAction(m_ac->action("copy")); - - menu->addSeparator(); - - menu->addAction(m_ac->action("delete")); - menu->addAction(m_ac->action("properties")); - - menu->popup(position); -} - - -void BookmarksPanel::contextMenuBkGroup(const QPoint &pos, bool emptyGroup) -{ if(m_loadingState) return; - QPoint position = m_treeView->mapToGlobal(pos); - KMenu *menu = new KMenu(this); - - if(!emptyGroup) - { - menu->addAction(m_ac->action("open_all")); - menu->addSeparator(); - } - - menu->addAction(m_ac->action("bookmark_page")); - menu->addAction(m_ac->action("folder_new")); - menu->addAction(m_ac->action("separator_new")); - - menu->addSeparator(); - - menu->addAction(m_ac->action("delete")); - menu->addAction(m_ac->action("properties")); - - menu->popup(position); -} - - -void BookmarksPanel::contextMenuSeparator(const QPoint &pos) -{ - QPoint position = m_treeView->mapToGlobal(pos); - KMenu *menu = new KMenu(this); - - menu->addAction(m_ac->action("bookmark_page")); - menu->addAction(m_ac->action("folder_new")); - menu->addAction(m_ac->action("separator_new")); - - menu->addSeparator(); - - menu->addAction(m_ac->action("delete")); - - menu->popup(position); -} - - -void BookmarksPanel::contextMenuBlank(const QPoint &pos) -{ - QPoint position = m_treeView->mapToGlobal(pos); - KMenu *menu = new KMenu(this); - - menu->addAction(m_ac->action("bookmark_page")); - menu->addAction(m_ac->action("folder_new")); - menu->addAction(m_ac->action("separator_new")); + KBookmark selected = bookmarkForIndex(index); - menu->popup(position); + BookmarkContextMenu *menu = new BookmarkContextMenu(selected, Application::bookmarkProvider()->bookmarkManager(), Application::bookmarkProvider()->bookmarkOwner(), this); + menu->popup(m_treeView->mapToGlobal(pos)); } @@ -356,128 +216,3 @@ void BookmarksPanel::deleteBookmark() bm.parentGroup().deleteBookmark(bm); Application::instance()->bookmarkProvider()->bookmarkManager()->emitChanged(); } - - -void BookmarksPanel::editBookmark() -{ - QModelIndex index = m_treeView->currentIndex(); - if(!index.isValid()) - return; - - KBookmark selected = bookmarkForIndex(index); - - KBookmarkDialog *dialog = Application::bookmarkProvider()->bookmarkOwner()->bookmarkDialog(Application::bookmarkProvider()->bookmarkManager(), QApplication::activeWindow()); - dialog->editBookmark(selected); - delete dialog; -} - - -void BookmarksPanel::openFolderInTabs() -{ - QModelIndex index = m_treeView->currentIndex(); - if(!index.isValid() || !bookmarkForIndex(index).isGroup()) - return; - - QList allChild = bookmarkForIndex(index).toGroup().groupUrlList(); - - if(allChild.length() > 8) // 8, a good choice ? - { - if(!(KMessageBox::warningContinueCancel(this, i18n("You are about to open a lot of tabs : %1\nAre you sure ?", QString::number(allChild.length()))) == KMessageBox::Continue)) - return; - } - - for(int i = 0; i < allChild.length(); i++) - emit openUrl(allChild.at(i).url(), Rekonq::SettingOpenTab); -} - - -void BookmarksPanel::newBookmarkGroup() -{ - QModelIndex index = m_treeView->currentIndex(); - KBookmark newBk; - - KBookmarkDialog *dialog = Application::bookmarkProvider()->bookmarkOwner()->bookmarkDialog(Application::bookmarkProvider()->bookmarkManager(), QApplication::activeWindow()); - - if(index.isValid()) - { - KBookmark selected = bookmarkForIndex(index); - - if(selected.isGroup()) - { - newBk = dialog->createNewFolder("New folder", selected); - } - - else - { - newBk = dialog->createNewFolder("New folder", selected.parentGroup()); - selected.parentGroup().moveBookmark(newBk, selected); - Application::bookmarkProvider()->bookmarkManager()->emitChanged(); - } - } - - else - { - dialog->createNewFolder("New folder"); - } - - delete dialog; -} - - -void BookmarksPanel::newSeparator() -{ - QModelIndex index = m_treeView->currentIndex(); - - KBookmark selected; - KBookmark newBk; - - if(index.isValid()) - { - selected = bookmarkForIndex(index); - - if(selected.isGroup()) - newBk = selected.toGroup().createNewSeparator(); - else - newBk = selected.parentGroup().createNewSeparator(); - } - - else - { - newBk = Application::bookmarkProvider()->rootGroup().createNewSeparator(); - } - - KBookmarkGroup parent = newBk.parentGroup(); - newBk.setIcon(("edit-clear")); - parent.addBookmark(newBk); - - if(index.isValid()) - parent.moveBookmark(newBk, selected); - - Application::bookmarkProvider()->bookmarkManager()->emitChanged(); -} - - -void BookmarksPanel::bookmarkCurrentPage() -{ - QModelIndex index = m_treeView->currentIndex(); - KBookmarkGroup parent = Application::bookmarkProvider()->rootGroup(); - - if(index.isValid()) - { - KBookmark selected = bookmarkForIndex(index); - parent = selected.parentGroup(); - - if(selected.isGroup()) - parent = selected.toGroup(); - - KBookmark newBk = parent.addBookmark(Application::bookmarkProvider()->bookmarkOwner()->currentTitle(), KUrl(Application::bookmarkProvider()->bookmarkOwner()->currentUrl()), "text-html"); - parent.moveBookmark(newBk, selected.parentGroup().previous(selected)); - } - - else - { - parent.addBookmark(Application::bookmarkProvider()->bookmarkOwner()->currentTitle(), KUrl(Application::bookmarkProvider()->bookmarkOwner()->currentUrl()), "text-html"); - } - - Application::bookmarkProvider()->bookmarkManager()->emitChanged(); -} diff --git a/src/bookmarks/bookmarkspanel.h b/src/bookmarks/bookmarkspanel.h index f8528b71..374c48f4 100644 --- a/src/bookmarks/bookmarkspanel.h +++ b/src/bookmarks/bookmarkspanel.h @@ -39,7 +39,6 @@ // KDE Includes #include -#include // Forward Declarations class KUrl; @@ -60,29 +59,20 @@ signals: void saveOnlyRequested(); private slots: - void contextMenuBk(const QPoint &pos); - void contextMenuBkGroup(const QPoint &pos, const bool emptyGroup = false); - void contextMenuBlank(const QPoint &pos); + void contextMenu(const QPoint &pos); + void deleteBookmark(); - void openFolderInTabs(); - void editBookmark(); - void newBookmarkGroup(); - void newSeparator(); void onCollapse(const QModelIndex &index); void onExpand(const QModelIndex &index); - void bookmarkCurrentPage(); void loadFoldedState(const QModelIndex &root); void loadFoldedState(); private: void setup(); - void setupActions(); - void contextMenuSeparator(const QPoint &pos); KBookmark bookmarkForIndex(const QModelIndex &index); UrlTreeView *m_treeView; - KActionCollection *m_ac; bool m_loadingState; }; -- cgit v1.2.1