summaryrefslogtreecommitdiff
path: root/src/bookmarks
diff options
context:
space:
mode:
Diffstat (limited to 'src/bookmarks')
-rw-r--r--src/bookmarks/bookmarkcontextmenu.cpp339
-rw-r--r--src/bookmarks/bookmarkowner.cpp359
-rw-r--r--src/bookmarks/bookmarkowner.h147
-rw-r--r--src/bookmarks/bookmarkscontextmenu.cpp127
-rw-r--r--src/bookmarks/bookmarkscontextmenu.h (renamed from src/bookmarks/bookmarkcontextmenu.h)39
-rw-r--r--src/bookmarks/bookmarksmanager.cpp341
-rw-r--r--src/bookmarks/bookmarksmanager.h185
-rw-r--r--src/bookmarks/bookmarkspanel.cpp208
-rw-r--r--src/bookmarks/bookmarkspanel.h19
-rw-r--r--src/bookmarks/bookmarksproxy.cpp11
-rw-r--r--src/bookmarks/bookmarksproxy.h12
-rw-r--r--src/bookmarks/bookmarkstoolbar.cpp435
-rw-r--r--src/bookmarks/bookmarkstoolbar.h111
-rw-r--r--src/bookmarks/bookmarkstreemodel.cpp181
-rw-r--r--src/bookmarks/bookmarkstreemodel.h22
15 files changed, 1420 insertions, 1116 deletions
diff --git a/src/bookmarks/bookmarkcontextmenu.cpp b/src/bookmarks/bookmarkcontextmenu.cpp
deleted file mode 100644
index 019d9eb9..00000000
--- a/src/bookmarks/bookmarkcontextmenu.cpp
+++ /dev/null
@@ -1,339 +0,0 @@
-/* ============================================================
-*
-* This file is a part of the rekonq project
-*
-* Copyright (C) 2010 by Yoann Laissus <yoann dot laissus at gmail dot 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 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 <http://www.gnu.org/licenses/>.
-*
-* ============================================================ */
-
-
-// Self Includes
-#include "bookmarkcontextmenu.h"
-#include "bookmarkcontextmenu.moc"
-
-// Local Includes
-#include "application.h"
-#include "bookmarksmanager.h"
-
-// KDE Includes
-#include <KMessageBox>
-#include <KActionCollection>
-#include <KBookmarkDialog>
-
-// Qt Includes
-#include <QClipboard>
-
-
-BookmarkContextMenu::BookmarkContextMenu(const KBookmark & bookmark, KBookmarkManager *manager, KBookmarkOwner *owner, QWidget *parent)
- : KBookmarkContextMenu(bookmark, manager, owner, parent)
- , m_ac(new KActionCollection(this))
-{
- setupActions();
-}
-
-
-BookmarkContextMenu::~BookmarkContextMenu()
-{
- delete m_ac;
-}
-
-
-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::NewTab);
-}
-
-
-void BookmarkContextMenu::openInNewWindow()
-{
- Application::instance()->loadUrl(bookmark().url(), Rekonq::NewWindow);
-}
-
-
-void BookmarkContextMenu::copyToClipboard()
-{
- if (bookmark().isNull())
- return;
-
- QClipboard *cb = QApplication::clipboard();
- cb->setText(bookmark().url().url());
-}
-
-
-void BookmarkContextMenu::deleteBookmark()
-{
- KBookmark bm = bookmark();
- KBookmarkGroup bmg = bm.parentGroup();
- bool folder = bm.isGroup();
- QString name = QString(bm.fullText()).replace("&&", "&");
-
- if (KMessageBox::warningContinueCancel(
- QApplication::activeWindow(),
- folder ? i18n("Are you sure you wish to remove the bookmark folder\n\"%1\"?", name)
- : i18n("Are you sure you wish to remove the bookmark\n\"%1\"?", name),
- folder ? i18n("Bookmark Folder Deletion")
- : i18n("Bookmark Deletion"),
- KStandardGuiItem::del(),
- KStandardGuiItem::cancel(),
- "bookmarkDeletition_askAgain")
- != KMessageBox::Continue
- )
- return;
-
- bmg.deleteBookmark(bm);
- manager()->emitChanged(bmg);
-}
-
-
-void BookmarkContextMenu::editBookmark()
-{
- KBookmark selected = bookmark();
- selected.setFullText(selected.fullText().replace("&&", "&"));
- KBookmarkDialog *dialog = owner()->bookmarkDialog(manager(), QApplication::activeWindow());
- dialog->editBookmark(selected);
- selected.setFullText(selected.fullText().replace('&', "&&"));
- delete dialog;
-}
-
-
-void BookmarkContextMenu::openFolderInTabs()
-{
- if (bookmark().isGroup())
- owner()->openFolderinTabs(bookmark().toGroup());
-}
-
-
-void BookmarkContextMenu::newBookmarkGroup()
-{
- KBookmark selected = bookmark();
- KBookmarkDialog *dialog = owner()->bookmarkDialog(manager(), QApplication::activeWindow());
-
- if (!selected.isNull())
- {
- if (selected.isGroup())
- {
- dialog->createNewFolder("New folder", selected);
- }
-
- else
- {
- KBookmark newBk;
- newBk = dialog->createNewFolder("New folder", selected.parentGroup());
- if (!newBk.isNull())
- {
- selected.parentGroup().moveBookmark(newBk, selected);
- manager()->emitChanged(newBk.parentGroup());
- }
- }
- }
- 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(newBk.parentGroup());
-}
-
-
-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().replace('&', "&&"), KUrl(owner()->currentUrl()));
- parent.moveBookmark(newBk, selected.parentGroup().previous(selected));
- }
-
- else
- {
- parent.addBookmark(owner()->currentTitle(), KUrl(owner()->currentUrl()));
- }
-
- manager()->emitChanged(parent);
-}
-
diff --git a/src/bookmarks/bookmarkowner.cpp b/src/bookmarks/bookmarkowner.cpp
new file mode 100644
index 00000000..d9df6e82
--- /dev/null
+++ b/src/bookmarks/bookmarkowner.cpp
@@ -0,0 +1,359 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2008-2010 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com>
+* Copyright (C) 2009-2010 by Lionel Chauvin <megabigbug@yahoo.fr>
+* Copyright (C) 2010 by Yoann Laissus <yoann dot laissus at gmail dot 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 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 <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+// Self Includes
+#include "bookmarkowner.h"
+
+// Local Includes
+#include "application.h"
+#include "bookmarksmanager.h"
+#include "mainwindow.h"
+#include "webtab.h"
+#include "mainview.h"
+
+// KDE Includes
+#include <KBookmarkDialog>
+#include <KMessageBox>
+
+// Qt Includes
+#include <QtGui/QClipboard>
+
+
+BookmarkOwner::BookmarkOwner(KBookmarkManager *manager, QObject *parent)
+ : QObject(parent)
+ , KBookmarkOwner()
+ , m_manager(manager)
+ , m_actions(QVector<KAction*>(NUM_ACTIONS))
+{
+ setupActions();
+}
+
+
+KAction* BookmarkOwner::action(const BookmarkAction &bmAction)
+{
+ return static_cast<KAction*>(m_actions.at(bmAction));
+}
+
+
+QString BookmarkOwner::currentTitle() const
+{
+ return Application::instance()->mainWindow()->currentTab()->view()->title();
+}
+
+
+QString BookmarkOwner::currentUrl() const
+{
+ return Application::instance()->mainWindow()->currentTab()->url().url();
+}
+
+
+bool BookmarkOwner::supportsTabs() const
+{
+ return true;
+}
+
+
+QList< QPair<QString, QString> > BookmarkOwner::currentBookmarkList() const
+{
+ QList< QPair<QString, QString> > bkList;
+ MainView *view = Application::instance()->mainWindow()->mainView();
+ int tabNumber = view->count();
+
+ for (int i = 0; i < tabNumber; ++i)
+ {
+ QPair<QString, QString> item;
+ item.first = view->webTab(i)->view()->title();
+ item.second = view->webTab(i)->url().url();
+ bkList << item;
+ }
+
+ return bkList;
+}
+
+
+void BookmarkOwner::openBookmark(const KBookmark &bookmark,
+ Qt::MouseButtons mouseButtons,
+ Qt::KeyboardModifiers keyboardModifiers)
+{
+ if (keyboardModifiers & Qt::ControlModifier || mouseButtons & Qt::MidButton)
+ {
+ openBookmarkInNewTab(bookmark);
+ }
+ else
+ {
+ openBookmark(bookmark);
+ }
+}
+
+
+void BookmarkOwner::openFolderinTabs(const KBookmarkGroup &bookmark)
+{
+ openBookmarkFolder(bookmark);
+}
+
+
+void BookmarkOwner::setCurrentBookmark(const KBookmark &bookmark)
+{
+ m_currentBookmark = bookmark;
+}
+
+
+void BookmarkOwner::openBookmark(const KBookmark &bookmark)
+{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
+ emit openUrl(selected.url(), Rekonq::CurrentTab);
+}
+
+
+void BookmarkOwner::openBookmarkInNewTab(const KBookmark &bookmark)
+{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
+ emit openUrl(selected.url(), Rekonq::NewTab);
+}
+
+
+void BookmarkOwner::openBookmarkInNewWindow(const KBookmark &bookmark)
+{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
+ emit openUrl(selected.url(), Rekonq::NewWindow);
+}
+
+
+void BookmarkOwner::openBookmarkFolder(const KBookmark &bookmark)
+{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
+ if (!selected.isGroup())
+ return;
+
+ QList<KUrl> urlList = selected.toGroup().groupUrlList();
+
+ if (urlList.length() > 8)
+ {
+ if (KMessageBox::warningContinueCancel(
+ Application::instance()->mainWindow(),
+ i18n("You are about to open %1 tabs.\nAre you sure?", urlList.length()))
+ != KMessageBox::Continue
+ )
+ return;
+ }
+
+ Q_FOREACH(const KUrl &url, urlList)
+ {
+ emit openUrl(url, Rekonq::NewFocusedTab);
+ }
+}
+
+
+void BookmarkOwner::bookmarkCurrentPage(const KBookmark &bookmark)
+{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
+ KBookmarkGroup parent;
+
+ if (!selected.isNull())
+ {
+ if (selected.isGroup())
+ parent = selected.toGroup();
+ else
+ parent = selected.parentGroup();
+
+ KBookmark newBk = parent.addBookmark(currentTitle().replace('&', "&&"), KUrl(currentUrl()));
+ parent.moveBookmark(newBk, selected);
+ }
+ else
+ {
+ parent = Application::bookmarkProvider()->rootGroup();
+ parent.addBookmark(currentTitle(), KUrl(currentUrl()));
+ }
+
+ m_manager->emitChanged(parent);
+}
+
+
+void BookmarkOwner::newBookmarkFolder(const KBookmark &bookmark)
+{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
+ KBookmarkDialog *dialog = bookmarkDialog(m_manager, QApplication::activeWindow());
+ QString folderName = i18n("New folder");
+
+ if (!selected.isNull())
+ {
+ if (selected.isGroup())
+ {
+ dialog->createNewFolder(folderName, selected);
+ }
+ else
+ {
+ KBookmark newBk = dialog->createNewFolder(folderName, selected.parentGroup());
+ if (!newBk.isNull())
+ {
+ KBookmarkGroup parent = newBk.parentGroup();
+ parent.moveBookmark(newBk, selected);
+ m_manager->emitChanged(parent);
+ }
+ }
+ }
+ else
+ {
+ dialog->createNewFolder(folderName);
+ }
+
+ delete dialog;
+}
+
+
+void BookmarkOwner::newSeparator(const KBookmark &bookmark)
+{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
+ KBookmark newBk;
+
+ if (!selected.isNull())
+ {
+ if (selected.isGroup())
+ {
+ newBk = selected.toGroup().createNewSeparator();
+ }
+ else
+ {
+ newBk = selected.parentGroup().createNewSeparator();
+ newBk.parentGroup().moveBookmark(newBk, selected);
+ }
+ }
+ else
+ {
+ newBk = Application::bookmarkProvider()->rootGroup().createNewSeparator();
+ }
+
+ newBk.setIcon(("edit-clear"));
+
+ m_manager->emitChanged(newBk.parentGroup());
+}
+
+
+void BookmarkOwner::copyLink(const KBookmark &bookmark)
+{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
+ if (selected.isNull())
+ return;
+
+ QApplication::clipboard()->setText(selected.url().url());
+}
+
+
+void BookmarkOwner::editBookmark(KBookmark bookmark)
+{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
+ if (selected.isNull())
+ return;
+
+ selected.setFullText(selected.fullText().replace("&&", "&"));
+ KBookmarkDialog *dialog = bookmarkDialog(m_manager, QApplication::activeWindow());
+
+ dialog->editBookmark(selected);
+ selected.setFullText(selected.fullText().replace('&', "&&"));
+
+ delete dialog;
+}
+
+
+bool BookmarkOwner::deleteBookmark(KBookmark bookmark)
+{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
+ if (selected.isNull())
+ return false;
+
+ KBookmarkGroup bmg = selected.parentGroup();
+ QString name = QString(selected.fullText()).replace("&&", "&");
+ QString dialogCaption, dialogText;
+
+ if (selected.isGroup())
+ {
+ dialogCaption = i18n("Bookmark Folder Deletion");
+ dialogText = i18n("Are you sure you wish to remove the bookmark folder\n\"%1\"?", name);
+ }
+ else if (selected.isSeparator())
+ {
+ dialogCaption = i18n("Separator Deletion");
+ dialogText = i18n("Are you sure you wish to remove this separator?");
+ }
+ else
+ {
+ dialogCaption = i18n("Bookmark Deletion");
+ dialogText = i18n("Are you sure you wish to remove the bookmark\n\"%1\"?", name);
+ }
+
+ if (KMessageBox::warningContinueCancel(
+ QApplication::activeWindow(),
+ dialogText,
+ dialogCaption,
+ KStandardGuiItem::del(),
+ KStandardGuiItem::cancel(),
+ "bookmarkDeletition_askAgain")
+ != KMessageBox::Continue
+ )
+ return false;
+
+ bmg.deleteBookmark(selected);
+ m_manager->emitChanged(bmg);
+ return true;
+}
+
+
+void BookmarkOwner::setupActions()
+{
+ createAction(OPEN, i18n("Open"), "tab-new",
+ i18n("Open bookmark in current tab"), SLOT(openBookmark()));
+ createAction(OPEN_IN_TAB, i18n("Open in New Tab"), "tab-new",
+ i18n("Open bookmark in new tab"), SLOT(openBookmarkInNewTab()));
+ createAction(OPEN_IN_WINDOW, i18n("Open in New Window"), "window-new",
+ i18n("Open bookmark in new window"), SLOT(openBookmarkInNewWindow()));
+ createAction(OPEN_FOLDER, i18n("Open Folder in Tabs"), "tab-new",
+ i18n("Open all the bookmarks in folder in tabs"), SLOT(openBookmarkFolder()));
+ createAction(BOOKMARK_PAGE, i18n("Add Bookmark"), "bookmark-new",
+ i18n("Bookmark current page"), SLOT(bookmarkCurrentPage()));
+ createAction(NEW_FOLDER, i18n("New Folder"), "folder-new",
+ i18n("Create a new bookmark folder"), SLOT(newBookmarkFolder()));
+ createAction(NEW_SEPARATOR, i18n("New Separator"), "edit-clear",
+ i18n("Create a new bookmark separatork"), SLOT(newSeparator()));
+ createAction(COPY, i18n("Copy Link"), "edit-copy",
+ i18n("Copy the bookmark's link address"), SLOT(copyLink()));
+ createAction(EDIT, i18n("Edit"), "configure",
+ i18n("Edit the bookmark"), SLOT(editBookmark()));
+ createAction(DELETE, i18n("Delete"), "edit-delete",
+ i18n("Delete the bookmark"), SLOT(deleteBookmark()));
+}
+
+
+void BookmarkOwner::createAction(const BookmarkAction &action, const QString &text,
+ const QString &icon, const QString &help, const char *slot)
+{
+ KAction *act = new KAction(KIcon(icon), text, this);
+ act->setHelpText(help);
+ m_actions[action] = act;
+ connect(act, SIGNAL(triggered()), this, slot);
+}
diff --git a/src/bookmarks/bookmarkowner.h b/src/bookmarks/bookmarkowner.h
new file mode 100644
index 00000000..e0c2a8ad
--- /dev/null
+++ b/src/bookmarks/bookmarkowner.h
@@ -0,0 +1,147 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2008-2010 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com>
+* Copyright (C) 2009-2010 by Lionel Chauvin <megabigbug@yahoo.fr>
+* Copyright (C) 2010 by Yoann Laissus <yoann dot laissus at gmail dot 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 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 <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+#ifndef BOOKMARKOWNER_H
+#define BOOKMARKOWNER_H
+
+
+// Rekonq Includes
+#include "rekonq_defines.h"
+
+// KDE Includes
+#include <KBookmarkOwner>
+
+// Forward Declarations
+class KAction;
+
+/**
+ * Reimplementation of KBookmarkOwner, this class allows to manage
+ * bookmarks as actions.
+ */
+class REKONQ_TESTS_EXPORT BookmarkOwner : public QObject, public KBookmarkOwner
+{
+ Q_OBJECT
+
+public:
+ explicit BookmarkOwner(KBookmarkManager *manager, QObject *parent = 0);
+ virtual ~BookmarkOwner() {}
+
+ enum BookmarkAction
+ {
+ OPEN = 0,
+ OPEN_IN_TAB,
+ OPEN_IN_WINDOW,
+ OPEN_FOLDER,
+ BOOKMARK_PAGE,
+ NEW_FOLDER,
+ NEW_SEPARATOR,
+ COPY,
+ EDIT,
+ DELETE,
+ NUM_ACTIONS
+ };
+
+ /**
+ * @return the action or 0 if it doesn't exist.
+ */
+ KAction* action(const BookmarkAction &bmAction);
+
+ /**
+ * @return the current page's title.
+ */
+ virtual QString currentTitle() const;
+ /**
+ * @return the current page's URL.
+ */
+ virtual QString currentUrl() const;
+
+ /**
+ * @return whether the owner supports tabs.
+ */
+ virtual bool supportsTabs() const;
+
+ /**
+ * @return list of title, URL pairs of the open tabs.
+ */
+ virtual QList< QPair<QString, QString> > currentBookmarkList() const;
+
+ /**
+ * This function is called when a bookmark is selected and belongs to
+ * the ancestor class.
+ * This method actually emits signal to load bookmark's url.
+ *
+ * @param bookmark the bookmark to open
+ * @param mouseButtons the mouse buttons clicked to select the bookmark
+ * @param keyboardModifiers the keyboard modifiers pushed when the bookmark was selected
+ */
+ virtual void openBookmark(const KBookmark &bookmark,
+ Qt::MouseButtons mouseButtons,
+ Qt::KeyboardModifiers keyboardModifiers);
+
+ /**
+ * Called if the user wants to open every bookmark in this folder in a new tab.
+ * The default implementation does nothing.
+ * This is only called if supportsTabs() returns true
+ */
+ virtual void openFolderinTabs(const KBookmarkGroup &bookmark);
+
+signals:
+ /**
+ * This signal is emitted when an url has to be loaded
+ * @param url the URL to load
+ */
+ void openUrl(const KUrl &, const Rekonq::OpenType &);
+
+public slots:
+ void setCurrentBookmark(const KBookmark &bookmark);
+
+ void openBookmark(const KBookmark &bookmark = KBookmark());
+ void openBookmarkInNewTab(const KBookmark &bookmark = KBookmark());
+ void openBookmarkInNewWindow(const KBookmark &bookmark = KBookmark());
+ void openBookmarkFolder(const KBookmark &bookmark = KBookmark());
+ void bookmarkCurrentPage(const KBookmark &bookmark = KBookmark());
+ void newBookmarkFolder(const KBookmark &bookmark = KBookmark());
+ void newSeparator(const KBookmark &bookmark = KBookmark());
+ void copyLink(const KBookmark &bookmark = KBookmark());
+ void editBookmark(KBookmark bookmark = KBookmark());
+ bool deleteBookmark(KBookmark bookmark = KBookmark());
+
+private:
+ KBookmarkManager *m_manager;
+
+ QVector<KAction*> m_actions;
+ KBookmark m_currentBookmark;
+
+ void setupActions();
+ void createAction(const BookmarkAction &action,
+ const QString &text, const QString &icon,
+ const QString &help, const char *slot);
+};
+
+#endif // BOOKMARKOWNER_H
diff --git a/src/bookmarks/bookmarkscontextmenu.cpp b/src/bookmarks/bookmarkscontextmenu.cpp
new file mode 100644
index 00000000..a473966a
--- /dev/null
+++ b/src/bookmarks/bookmarkscontextmenu.cpp
@@ -0,0 +1,127 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2010 by Yoann Laissus <yoann dot laissus at gmail dot 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 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 <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+// Self Includes
+#include "bookmarkscontextmenu.h"
+
+// Local Includes
+#include "bookmarkowner.h"
+
+
+BookmarksContextMenu::BookmarksContextMenu(const KBookmark &bookmark, KBookmarkManager *manager, BookmarkOwner *owner, QWidget *parent)
+ : KBookmarkContextMenu(bookmark, manager, owner, parent)
+ , bmOwner(owner)
+{
+ bmOwner->setCurrentBookmark(bookmark);
+}
+
+
+BookmarksContextMenu::~BookmarksContextMenu()
+{
+}
+
+
+void BookmarksContextMenu::addBookmarkActions()
+{
+ addAction(bmOwner->action(BookmarkOwner::OPEN));
+ addAction(bmOwner->action(BookmarkOwner::OPEN_IN_TAB));
+ addAction(bmOwner->action(BookmarkOwner::OPEN_IN_WINDOW));
+
+ addSeparator();
+
+ addAction(bmOwner->action(BookmarkOwner::BOOKMARK_PAGE));
+ addAction(bmOwner->action(BookmarkOwner::NEW_FOLDER));
+ addAction(bmOwner->action(BookmarkOwner::NEW_SEPARATOR));
+
+ addSeparator();
+
+ addAction(bmOwner->action(BookmarkOwner::COPY));
+
+ addSeparator();
+
+ addAction(bmOwner->action(BookmarkOwner::EDIT));
+ addAction(bmOwner->action(BookmarkOwner::DELETE));
+}
+
+
+void BookmarksContextMenu::addFolderActions()
+{
+ if (!bookmark().toGroup().first().isNull())
+ {
+ addAction(bmOwner->action(BookmarkOwner::OPEN_FOLDER));
+ addSeparator();
+ }
+
+ addAction(bmOwner->action(BookmarkOwner::BOOKMARK_PAGE));
+ addAction(bmOwner->action(BookmarkOwner::NEW_FOLDER));
+ addAction(bmOwner->action(BookmarkOwner::NEW_SEPARATOR));
+
+ addSeparator();
+
+ addAction(bmOwner->action(BookmarkOwner::EDIT));
+ addAction(bmOwner->action(BookmarkOwner::DELETE));
+}
+
+
+void BookmarksContextMenu::addSeparatorActions()
+{
+ addAction(bmOwner->action(BookmarkOwner::BOOKMARK_PAGE));
+ addAction(bmOwner->action(BookmarkOwner::NEW_FOLDER));
+ addAction(bmOwner->action(BookmarkOwner::NEW_SEPARATOR));
+
+ addSeparator();
+
+ addAction(bmOwner->action(BookmarkOwner::DELETE));
+}
+
+
+void BookmarksContextMenu::addNullActions()
+{
+ addAction(bmOwner->action(BookmarkOwner::BOOKMARK_PAGE));
+ addAction(bmOwner->action(BookmarkOwner::NEW_FOLDER));
+ addAction(bmOwner->action(BookmarkOwner::NEW_SEPARATOR));
+}
+
+
+void BookmarksContextMenu::addActions()
+{
+ if (bookmark().isGroup())
+ {
+ addFolderActions();
+ }
+ else if (bookmark().isSeparator())
+ {
+ addSeparatorActions();
+ }
+ else if (bookmark().isNull())
+ {
+ addNullActions();
+ }
+ else
+ {
+ addBookmarkActions();
+ }
+}
diff --git a/src/bookmarks/bookmarkcontextmenu.h b/src/bookmarks/bookmarkscontextmenu.h
index ebbfd6e8..a6691fdd 100644
--- a/src/bookmarks/bookmarkcontextmenu.h
+++ b/src/bookmarks/bookmarkscontextmenu.h
@@ -24,45 +24,30 @@
* ============================================================ */
-#ifndef BOOKMARKCONTEXTMENU_H
-#define BOOKMARKCONTEXTMENU_H
+#ifndef BOOKMARKS_CONTEXT_MENU_H
+#define BOOKMARKS_CONTEXT_MENU_H
-// Local Includes
-#include "application.h"
-
-// Qt Includes
+// KDE Includes
#include <KBookmarkMenu>
+// Forward Declarations
+class BookmarkOwner;
-class BookmarkContextMenu : public KBookmarkContextMenu
+class BookmarksContextMenu : public KBookmarkContextMenu
{
- Q_OBJECT
-
public:
- BookmarkContextMenu(const KBookmark & bk, KBookmarkManager * manager, KBookmarkOwner *owner, QWidget * parent = 0);
- ~BookmarkContextMenu();
-
- virtual void addActions();
+ BookmarksContextMenu(const KBookmark &bookmark, KBookmarkManager *manager, BookmarkOwner *owner, QWidget *parent = 0);
+ virtual ~BookmarksContextMenu();
-private slots:
- void openInCurrentTab();
- void openInNewTab();
- void openInNewWindow();
- void copyToClipboard();
- void deleteBookmark();
- void openFolderInTabs();
- void editBookmark();
- void newBookmarkGroup();
- void newSeparator();
- void bookmarkCurrentPage();
+ virtual void addActions();
private:
- void setupActions();
void addFolderActions();
void addBookmarkActions();
void addSeparatorActions();
+ void addNullActions();
- KActionCollection *m_ac;
+ BookmarkOwner *bmOwner;
};
-#endif // BOOKMARKCONTEXTMENU_H
+#endif // BOOKMARKS_CONTEXT_MENU_H
diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp
index bba9dd77..ea7b313d 100644
--- a/src/bookmarks/bookmarksmanager.cpp
+++ b/src/bookmarks/bookmarksmanager.cpp
@@ -29,313 +29,22 @@
// Self Includes
#include "bookmarksmanager.h"
-#include "bookmarksmanager.moc"
// Local Includes
+#include "application.h"
#include "mainwindow.h"
-#include "webtab.h"
-#include "webview.h"
-#include "mainview.h"
-#include "bookmarkcontextmenu.h"
+#include "bookmarkspanel.h"
+#include "bookmarkscontextmenu.h"
+#include "bookmarkstoolbar.h"
+#include "bookmarkowner.h"
// KDE Includes
-#include <KActionCollection>
-#include <KBookmarkAction>
-#include <KBookmarkGroup>
-#include <KToolBar>
-#include <KMenu>
#include <KStandardDirs>
-#include <KUrl>
-#include <KMessageBox>
// Qt Includes
#include <QtCore/QFile>
-#include <QtGui/QActionGroup>
-BookmarkOwner::BookmarkOwner(QObject *parent)
- : QObject(parent)
- , KBookmarkOwner()
-{
-}
-
-
-void BookmarkOwner::openBookmark(const KBookmark & bookmark,
- Qt::MouseButtons mouseButtons,
- Qt::KeyboardModifiers keyboardModifiers)
-{
- if (keyboardModifiers & Qt::ControlModifier || mouseButtons == Qt::MidButton)
- {
- emit openUrl(bookmark.url(), Rekonq::NewTab);
- }
- else
- {
- emit openUrl(bookmark.url(), Rekonq::CurrentTab);
- }
-}
-
-
-bool BookmarkOwner::supportsTabs() const
-{
- return true;
-}
-
-
-QString BookmarkOwner::currentUrl() const
-{
- return Application::instance()->mainWindow()->currentTab()->url().url();
-}
-
-
-QString BookmarkOwner::currentTitle() const
-{
- return Application::instance()->mainWindow()->currentTab()->view()->title();
-}
-
-
-void BookmarkOwner::openFolderinTabs(const KBookmarkGroup &bookmark)
-{
- QList<KUrl> urlList = bookmark.groupUrlList();
-
- if (urlList.length() > 8)
- {
- if ( !(KMessageBox::warningContinueCancel( Application::instance()->mainWindow(),
- i18ncp("%1=Number of tabs. Value is always >=8",
- "You are about to open %1 tabs.\nAre you sure?",
- "You are about to open %1 tabs.\nAre you sure?",
- urlList.length()),
- "",
- KStandardGuiItem::cont(),
- KStandardGuiItem::cancel(),
- "openFolderInTabs_askAgain"
- ) == KMessageBox::Continue)
- )
- return;
- }
-
- QList<KUrl>::iterator url;
- for (url = urlList.begin(); url != urlList.end(); ++url)
- {
- emit openUrl(*url, Rekonq::NewFocusedTab);
- }
-}
-
-
-QList< QPair<QString, QString> > BookmarkOwner::currentBookmarkList() const
-{
- QList< QPair<QString, QString> > bkList;
- int tabNumber = Application::instance()->mainWindow()->mainView()->count();
-
- for (int i = 0; i < tabNumber; i++)
- {
- QPair<QString, QString> item;
- item.first = Application::instance()->mainWindow()->mainView()->webTab(i)->view()->title();
- item.second = Application::instance()->mainWindow()->mainView()->webTab(i)->url().url();
- bkList += item;
- }
- return bkList;
-}
-
-
-// ------------------------------------------------------------------------------------------------------
-
-
-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()
-{
-}
-
-
-KMenu * BookmarkMenu::contextMenu(QAction *act)
-{
-
- KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(act);
- if (!action)
- return 0;
- return new BookmarkContextMenu(action->bookmark(), manager(), 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());
- 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);
- connect(action, SIGNAL(hovered()), this, SLOT(actionHovered()));
- return action;
- }
-}
-
-
-void BookmarkMenu::refill()
-{
- clear();
- fillBookmarks();
-
- if (parentMenu()->actions().count() > 0)
- parentMenu()->addSeparator();
-
- if (isRoot())
- {
- addAddBookmark();
- addAddBookmarksList();
- addNewFolder();
- addEditBookmarks();
- }
- else
- {
- addOpenFolderInTabs();
- addAddBookmark();
- addAddBookmarksList();
- addNewFolder();
- }
-}
-
-
-void BookmarkMenu::addOpenFolderInTabs()
-{
- KAction *action;
- 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())
- {
- action = new KAction(KIcon("tab-new"), i18n("Open Folder in Tabs"), this);
- action->setHelpText(i18n("Open all bookmarks in this folder as new tabs."));
- connect(action, SIGNAL(triggered(bool)), this, SLOT(slotOpenFolderInTabs()));
- parentMenu()->addAction(action);
- }
- }
-}
-
-
-void BookmarkMenu::actionHovered()
-{
- KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(sender());
- if (action)
- Application::instance()->mainWindow()->notifyMessage(action->bookmark().url().url());
-}
-
-
-// ------------------------------------------------------------------------------------------------------
-
-
-BookmarkToolBar::BookmarkToolBar( const QString &objectName,
- QMainWindow *parentWindow,
- Qt::ToolBarArea area,
- bool newLine,
- bool isMainToolBar,
- bool readConfig
- )
- : KToolBar(objectName, parentWindow, area, newLine, isMainToolBar, readConfig)
- , m_filled(false)
- , m_currentMenu(0)
-{
- connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(QString,QString)), this, SLOT(hideMenu()));
-}
-
-
-BookmarkToolBar::~BookmarkToolBar()
-{
-}
-
-
-void BookmarkToolBar::setVisible(bool visible)
-{
- if (visible && !m_filled)
- {
- m_filled = true;
- Application::bookmarkProvider()->fillBookmarkBar(this);
- }
- KToolBar::setVisible(visible);
-}
-
-
-void BookmarkToolBar::menuDisplayed()
-{
- qApp->installEventFilter(this);
- m_currentMenu = qobject_cast<KMenu*>(sender());
-}
-
-
-void BookmarkToolBar::menuHidden()
-{
- qApp->removeEventFilter(this);
- m_currentMenu = 0;
-}
-
-
-void BookmarkToolBar::hideMenu()
-{
- if(m_currentMenu)
- m_currentMenu->hide();
-}
-
-
-bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event)
-{
- // To switch root folders as in a menubar
- if (event->type() == QEvent::MouseMove && m_currentMenu)
- {
- KBookmarkActionMenu* act = dynamic_cast<KBookmarkActionMenu *>(this->actionAt(this->mapFromGlobal(QCursor::pos())));
- if (act && act->menu() != m_currentMenu)
- {
- m_currentMenu->hide();
- QPoint pos = mapToGlobal(widgetForAction(act)->pos());
- act->menu()->popup(QPoint(pos.x(), pos.y() + widgetForAction(act)->height()));
- }
- }
- return KToolBar::eventFilter(watched, event);
-}
-
-
-void BookmarkToolBar::actionHovered()
-{
- KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(sender());
- if (action)
- Application::instance()->mainWindow()->notifyMessage(action->bookmark().url().url());
-}
-
-// ------------------------------------------------------------------------------------------------------
-
-
-
BookmarkProvider::BookmarkProvider(QObject *parent)
: QObject(parent)
, m_manager(0)
@@ -368,7 +77,7 @@ BookmarkProvider::BookmarkProvider(QObject *parent)
this, SLOT(slotBookmarksChanged(const QString &, const QString &)));
// setup menu
- m_owner = new BookmarkOwner(this);
+ m_owner = new BookmarkOwner(m_manager, this);
connect(m_owner, SIGNAL(openUrl(const KUrl&, const Rekonq::OpenType &)), this, SIGNAL(openUrl(const KUrl&, const Rekonq::OpenType &)));
KAction *a = KStandardAction::addBookmark(this, SLOT(slotAddBookmark()), this);
@@ -386,7 +95,7 @@ BookmarkProvider::~BookmarkProvider()
}
-void BookmarkProvider::setupBookmarkBar(BookmarkToolBar *toolbar)
+void BookmarkProvider::registerBookmarkBar(BookmarkToolBar *toolbar)
{
if (m_bookmarkToolBars.contains(toolbar))
return;
@@ -394,9 +103,9 @@ void BookmarkProvider::setupBookmarkBar(BookmarkToolBar *toolbar)
kDebug() << "new bookmark bar...";
m_bookmarkToolBars.append(toolbar);
- toolbar->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(toolbar, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenu(const QPoint &)));
-
+ toolbar->toolBar()->setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(toolbar->toolBar(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenu(const QPoint &)));
+
kDebug() << "new bookmark bar... DONE!";
}
@@ -416,7 +125,7 @@ void BookmarkProvider::slotBookmarksChanged(const QString &group, const QString
{
if (bookmarkToolBar)
{
- bookmarkToolBar->clear();
+ bookmarkToolBar->toolBar()->clear();
fillBookmarkBar(bookmarkToolBar);
}
}
@@ -437,7 +146,7 @@ void BookmarkProvider::contextMenu(const QPoint &point)
if (m_bookmarkToolBars.isEmpty())
return;
- KToolBar *bookmarkToolBar = m_bookmarkToolBars.at(0);
+ KToolBar *bookmarkToolBar = m_bookmarkToolBars.at(0)->toolBar();
if (!bookmarkToolBar)
return;
@@ -445,7 +154,7 @@ void BookmarkProvider::contextMenu(const QPoint &point)
if (!action)
return;
- BookmarkContextMenu menu(action->bookmark(), bookmarkManager(), bookmarkOwner());
+ BookmarksContextMenu menu(action->bookmark(), bookmarkManager(), bookmarkOwner());
menu.exec(bookmarkToolBar->mapToGlobal(point));
}
@@ -453,7 +162,7 @@ void BookmarkProvider::contextMenu(const QPoint &point)
KActionMenu* BookmarkProvider::bookmarkActionMenu(QWidget *parent)
{
kDebug() << "new Bookmarks Menu...";
-
+
KMenu *menu = new KMenu(parent);
_bookmarkActionMenu = new KActionMenu(parent);
_bookmarkActionMenu->setMenu(menu);
@@ -465,16 +174,6 @@ KActionMenu* BookmarkProvider::bookmarkActionMenu(QWidget *parent)
}
-KAction* BookmarkProvider::bookmarkToolBarAction(KToolBar *t)
-{
- KAction *bookmarkToolBarAction = new KAction(this);
- bookmarkToolBarAction->setDefaultWidget(t); // The ownership is transferred to action
- bookmarkToolBarAction->setText(i18n("Bookmarks Bar"));
- bookmarkToolBarAction->setShortcutConfigurable(false);
- return bookmarkToolBarAction;
-}
-
-
void BookmarkProvider::fillBookmarkBar(BookmarkToolBar *toolBar)
{
KBookmarkGroup root = m_manager->toolbar();
@@ -490,12 +189,12 @@ void BookmarkProvider::fillBookmarkBar(BookmarkToolBar *toolBar)
new BookmarkMenu(bookmarkManager(), bookmarkOwner(), menuAction->menu(), bookmark.address());
connect(menuAction->menu(), SIGNAL(aboutToShow()), toolBar, SLOT(menuDisplayed()));
connect(menuAction->menu(), SIGNAL(aboutToHide()), toolBar, SLOT(menuHidden()));
- toolBar->addAction(menuAction);
+ toolBar->toolBar()->addAction(menuAction);
}
else if (bookmark.isSeparator())
{
- toolBar->addSeparator();
+ toolBar->toolBar()->addSeparator();
}
else
@@ -503,7 +202,8 @@ void BookmarkProvider::fillBookmarkBar(BookmarkToolBar *toolBar)
KBookmarkAction* action = new KBookmarkAction(bookmark, m_owner, this);
action->setIconText(action->iconText().replace('&', "&&"));
connect(action, SIGNAL(hovered()), toolBar, SLOT(actionHovered()));
- toolBar->addAction(action);
+ toolBar->toolBar()->addAction(action);
+ toolBar->toolBar()->widgetForAction(action)->installEventFilter(toolBar);
}
}
}
@@ -524,7 +224,7 @@ QList<KBookmark> BookmarkProvider::find(QString text)
return list;
}
- KBookmark bookmark = bookGroup.first();
+ KBookmark bookmark = bookGroup.first();
while (!bookmark.isNull())
{
list = find(list, bookmark, text);
@@ -597,11 +297,10 @@ void BookmarkProvider::slotPanelChanged()
KBookmark BookmarkProvider::bookmarkForUrl(const KUrl &url)
{
- KBookmark found;
-
KBookmarkGroup root = rootGroup();
if (root.isNull())
{
+ KBookmark found;
return found;
}
diff --git a/src/bookmarks/bookmarksmanager.h b/src/bookmarks/bookmarksmanager.h
index eeb5391d..0c2b9ee2 100644
--- a/src/bookmarks/bookmarksmanager.h
+++ b/src/bookmarks/bookmarksmanager.h
@@ -34,179 +34,16 @@
// Rekonq Includes
#include "rekonq_defines.h"
-// Local Includes
-#include "application.h"
-#include "urlresolver.h"
-#include "bookmarkspanel.h"
-
-// Qt Includes
-#include <QWidget>
-
-// KDE Includes
-#include <KBookmarkOwner>
-
-// Forward Declarations
-class BookmarkProvider;
-
-class KAction;
-class KActionCollection;
-class KActionMenu;
-class KUrl;
-class KToolBar;
-class KBookmarkManager;
-
-
-/**
- * Reimplementation of KBookmarkOwner, this class allows to manage
- * bookmarks as actions
- *
- */
-class REKONQ_TESTS_EXPORT BookmarkOwner : public QObject , public KBookmarkOwner
-{
- Q_OBJECT
-
-public:
-
- /**
- * @short The class constructor.
- *
- * @param parent the pointer parent Bookmark provider. We need it
- * to get pointer to MainWindow
- */
- BookmarkOwner(QObject *parent = 0);
- virtual ~BookmarkOwner() {}
-
- /**
- * This function is called when a bookmark is selected and belongs to
- * the ancestor class.
- * This method actually emits signal to load bookmark's url.
- *
- * @param bookmark the bookmark to open
- * @param mouseButtons the mouse buttons clicked to select the bookmark
- * @param keyboardModifiers the keyboard modifiers pushed when the bookmark was selected
- */
- virtual void openBookmark(const KBookmark &bookmark,
- Qt::MouseButtons mouseButtons,
- Qt::KeyboardModifiers keyboardModifiers);
-
-
- /**
- * this method, from KBookmarkOwner interface, allows to add the current page
- * to the bookmark list, returning the URL page as QString.
- *
- * @return the current page's URL
- */
- virtual QString currentUrl() const;
-
- /**
- * this method, from KBookmarkOwner interface, allows to add the current page
- * to the bookmark list, returning the title's page as QString.
- *
- * @return the current page's title
- */
- virtual QString currentTitle() const;
-
- /**
- * This function returns whether the owner supports tabs.
- */
- virtual bool supportsTabs() const;
-
- /**
- * Called if the user wants to open every bookmark in this folder in a new tab.
- * The default implementation does nothing.
- * This is only called if supportsTabs() returns true
- */
- virtual void openFolderinTabs(const KBookmarkGroup &bookmark);
-
- virtual QList< QPair<QString, QString> > currentBookmarkList() const;
-
-signals:
- /**
- * This signal is emitted when an url has to be loaded
- *
- * @param url the URL to load
- *
- */
- void openUrl(const KUrl &, const Rekonq::OpenType &);
-};
-
-// ------------------------------------------------------------------------------
-
-
// KDE Includes
#include <KBookmarkMenu>
-
-/**
- * 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 slots:
- void actionHovered();
-
-private:
- void addOpenFolderInTabs();
-
-};
-
-
-// ------------------------------------------------------------------------------
-
#include <KToolBar>
-class BookmarkToolBar : public KToolBar
-{
- Q_OBJECT
-
-public:
-BookmarkToolBar(const QString &objectName,
- QMainWindow *parentWindow,
- Qt::ToolBarArea area,
- bool newLine = false,
- bool isMainToolBar = false,
- bool readConfig = true);
-~BookmarkToolBar();
-
-virtual void setVisible(bool visible);
-
-protected:
- bool eventFilter(QObject *watched, QEvent *event);
-
-private slots:
- void actionHovered();
- void menuDisplayed();
- void menuHidden();
- void hideMenu();
-
-private:
- bool m_filled;
- KMenu *m_currentMenu;
-};
-
+// Forward Declarations
+class BookmarksPanel;
+class BookmarkToolBar;
+class BookmarkOwner;
-// ------------------------------------------------------------------------------
-
/**
* This class represent the interface to rekonq bookmarks system.
* All rekonq needs (Bookmarks Menu, Bookmarks Toolbar) is provided
@@ -237,12 +74,10 @@ public:
*/
KActionMenu *bookmarkActionMenu(QWidget *parent);
- KAction *bookmarkToolBarAction(KToolBar *t);
-
/**
* @short set the Bookmarks Toolbar Action
*/
- void setupBookmarkBar(BookmarkToolBar *);
+ void registerBookmarkBar(BookmarkToolBar *);
void removeToolBar(BookmarkToolBar *);
@@ -263,7 +98,7 @@ public:
KBookmarkGroup rootGroup();
inline KBookmarkManager *bookmarkManager() { return m_manager; }
-
+
inline BookmarkOwner *bookmarkOwner() { return m_owner; }
QList<KBookmark> find(QString text);
@@ -272,7 +107,7 @@ public:
void removeBookmarkPanel(BookmarksPanel *panel);
KBookmark bookmarkForUrl(const KUrl &url);
-
+
signals:
/**
* @short This signal is emitted when an url has to be loaded
@@ -299,11 +134,11 @@ public slots:
*/
void slotBookmarksChanged(const QString &group, const QString &caller);
void fillBookmarkBar(BookmarkToolBar *toolBar);
-
+
private slots:
void slotAddBookmark();
void slotPanelChanged();
-
+
private:
QList<KBookmark> find(QList<KBookmark> list, const KBookmark &bookmark, QString text);
@@ -315,7 +150,7 @@ private:
KActionCollection *m_actionCollection;
QList<BookmarkToolBar *> m_bookmarkToolBars;
QList<BookmarksPanel*> m_bookmarkPanels;
-
+
KActionMenu *_bookmarkActionMenu;
};
diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp
index 75d8faf3..1b561515 100644
--- a/src/bookmarks/bookmarkspanel.cpp
+++ b/src/bookmarks/bookmarkspanel.cpp
@@ -27,57 +27,129 @@
// Self Includes
#include "bookmarkspanel.h"
-#include "bookmarkspanel.moc"
// Local Includes
+#include "application.h"
#include "bookmarksmanager.h"
#include "bookmarkstreemodel.h"
#include "bookmarksproxy.h"
-#include "bookmarkcontextmenu.h"
+#include "bookmarkscontextmenu.h"
+#include "bookmarkowner.h"
+#include "paneltreeview.h"
// Auto Includes
#include "rekonq.h"
// Qt includes
-#include <QHBoxLayout>
-#include <QLabel>
-#include <QHeaderView>
+#include <QtGui/QHBoxLayout>
+#include <QtGui/QLabel>
+#include <QtGui/QHeaderView>
// KDE includes
#include <KLineEdit>
-#include <KLocalizedString>
-#include <KMenu>
-#include <KMessageBox>
-
BookmarksPanel::BookmarksPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags)
: QDockWidget(title, parent, flags)
, m_treeView(new PanelTreeView(this))
, m_loadingState(false)
- , _loaded(false)
+ , m_loaded(false)
{
setObjectName("bookmarksPanel");
setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
connect(this, SIGNAL(visibilityChanged(bool)), this, SLOT(showing(bool)));
- setShown(ReKonfig::showBookmarksPanel());
+ setVisible(ReKonfig::showBookmarksPanel());
}
BookmarksPanel::~BookmarksPanel()
{
- ReKonfig::setShowBookmarksPanel(!isHidden());
+ ReKonfig::setShowBookmarksPanel(false);
}
void BookmarksPanel::showing(bool b)
{
- if(b && !_loaded)
+ if(b && !m_loaded)
setup();
}
+void BookmarksPanel::startLoadFoldedState()
+{
+ m_loadingState = true;
+ loadFoldedState(QModelIndex());
+ m_loadingState = false;
+}
+
+
+void BookmarksPanel::contextMenu(const QPoint &pos)
+{
+ if (m_loadingState)
+ return;
+
+ BookmarksContextMenu menu(bookmarkForIndex( m_treeView->indexAt(pos) ),
+ Application::bookmarkProvider()->bookmarkManager(),
+ Application::bookmarkProvider()->bookmarkOwner(),
+ this
+ );
+
+ menu.exec(m_treeView->mapToGlobal(pos));
+}
+
+
+void BookmarksPanel::deleteBookmark()
+{
+ QModelIndex index = m_treeView->currentIndex();
+ if (m_loadingState || !index.isValid())
+ return;
+
+ Application::bookmarkProvider()->bookmarkOwner()->deleteBookmark(bookmarkForIndex(index));
+}
+
+
+void BookmarksPanel::onCollapse(const QModelIndex &index)
+{
+ if (m_loadingState)
+ return;
+
+ bookmarkForIndex(index).internalElement().setAttribute("folded", "yes");
+ emit expansionChanged();
+}
+
+
+void BookmarksPanel::onExpand(const QModelIndex &index)
+{
+ if (m_loadingState)
+ return;
+
+ bookmarkForIndex(index).internalElement().setAttribute("folded", "no");
+ emit expansionChanged();
+}
+
+
+void BookmarksPanel::loadFoldedState(const QModelIndex &root)
+{
+ int count = m_treeView->model()->rowCount(root);
+ QModelIndex index;
+
+ for (int i = 0; i < count; ++i)
+ {
+ index = m_treeView->model()->index(i, 0, root);
+ if (index.isValid())
+ {
+ KBookmark bm = bookmarkForIndex(index);
+ if (bm.isGroup())
+ {
+ m_treeView->setExpanded(index, bm.toGroup().isOpen());
+ loadFoldedState(index);
+ }
+ }
+ }
+}
+
+
void BookmarksPanel::setup()
{
kDebug() << "Loading bookmarks panel setup...";
@@ -96,8 +168,6 @@ void BookmarksPanel::setup()
// setup tree view
m_treeView->setUniformRowHeights(true);
- m_treeView->setTextElideMode(Qt::ElideMiddle);
- m_treeView->setAlternatingRowColors(true);
m_treeView->header()->hide();
m_treeView->setDragEnabled(true);
m_treeView->setAutoExpandDelay(750);
@@ -119,16 +189,20 @@ void BookmarksPanel::setup()
proxy->setSourceModel(model);
m_treeView->setModel(proxy);
+ connect(search, SIGNAL(textChanged(const QString &)), proxy, SLOT(setFilterFixedString(const QString &)));
+
+ connect(model, SIGNAL(bookmarksUpdated()), this, SLOT(startLoadFoldedState()));
+
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 &)));
- connect(search, SIGNAL(textChanged(const QString &)), proxy, SLOT(setFilterFixedString(const QString &)));
+
startLoadFoldedState();
- _loaded = true;
+ m_loaded = true;
}
@@ -137,105 +211,9 @@ KBookmark BookmarksPanel::bookmarkForIndex(const QModelIndex &index)
if (!index.isValid())
return KBookmark();
- const QAbstractProxyModel* proxyModel = dynamic_cast< const QAbstractProxyModel* >(index.model());
+ const BookmarksProxy *proxyModel = static_cast<const BookmarksProxy*>(index.model());
QModelIndex originalIndex = proxyModel->mapToSource(index);
- BtmItem *node = static_cast< BtmItem* >(originalIndex.internalPointer());
+ BtmItem *node = static_cast<BtmItem*>(originalIndex.internalPointer());
return node->getBkm();
}
-
-
-void BookmarksPanel::onCollapse(const QModelIndex &index)
-{
- if (m_loadingState)
- return;
-
- KBookmark bookmark = bookmarkForIndex(index);
- bookmark.internalElement().setAttribute("folded", "yes");
- emit expansionChanged();
-}
-
-
-void BookmarksPanel::onExpand(const QModelIndex &index)
-{
- if (m_loadingState)
- return;
-
- KBookmark bookmark = bookmarkForIndex(index);
- bookmark.internalElement().setAttribute("folded", "no");
- emit expansionChanged();
-}
-
-
-void BookmarksPanel::startLoadFoldedState()
-{
- m_loadingState = true;
- loadFoldedState(QModelIndex());
- m_loadingState = false;
-}
-
-
-void BookmarksPanel::loadFoldedState(const QModelIndex &root)
-{
-
- int count = m_treeView->model()->rowCount(root);
- QModelIndex index;
-
- for (int i = 0; i < count; i++)
- {
- index = m_treeView->model()->index(i, 0, root);
- if (index.isValid() && bookmarkForIndex(index).isGroup())
- {
- m_treeView->setExpanded(index, bookmarkForIndex(index).toGroup().isOpen());
- loadFoldedState(index);
- }
- }
-}
-
-
-void BookmarksPanel::contextMenu(const QPoint &pos)
-{
- QModelIndex index = m_treeView->indexAt(pos);
- if (m_loadingState)
- return;
-
- KBookmark selected = bookmarkForIndex(index);
-
- BookmarkContextMenu menu( selected,
- Application::bookmarkProvider()->bookmarkManager(),
- Application::bookmarkProvider()->bookmarkOwner(),
- this
- );
-
- menu.exec(m_treeView->mapToGlobal(pos));
-}
-
-
-void BookmarksPanel::deleteBookmark()
-{
- QModelIndex index = m_treeView->currentIndex();
- if (!index.isValid())
- return;
-
- KBookmark bm = bookmarkForIndex(index);
- KBookmarkGroup bmg = bm.parentGroup();
- bool folder = bm.isGroup();
- QString name = QString(bm.fullText()).replace("&&", "&");
-
- if (KMessageBox::warningContinueCancel(
- QApplication::activeWindow(),
- folder ? i18n("Are you sure you wish to remove the bookmark folder\n\"%1\"?", name)
- : i18n("Are you sure you wish to remove the bookmark\n\"%1\"?", name),
- folder ? i18n("Bookmark Folder Deletion")
- : i18n("Bookmark Deletion"),
- KStandardGuiItem::del(),
- KStandardGuiItem::cancel(),
- "bookmarkDeletition_askAgain")
- != KMessageBox::Continue
- )
- return;
-
-
- bmg.deleteBookmark(bm);
- Application::instance()->bookmarkProvider()->bookmarkManager()->emitChanged(bmg);
-}
diff --git a/src/bookmarks/bookmarkspanel.h b/src/bookmarks/bookmarkspanel.h
index d94f2b99..4afa953b 100644
--- a/src/bookmarks/bookmarkspanel.h
+++ b/src/bookmarks/bookmarkspanel.h
@@ -33,28 +33,21 @@
// Rekonq Includes
#include "rekonq_defines.h"
-// Local Includes
-#include "application.h"
-#include "paneltreeview.h"
-
// Qt Includes
#include <QDockWidget>
-// KDE Includes
-#include <KBookmark>
-
// Forward Declarations
-class KUrl;
+class PanelTreeView;
+class KBookmark;
class QModelIndex;
-
class REKONQ_TESTS_EXPORT BookmarksPanel : public QDockWidget
{
Q_OBJECT
public:
explicit BookmarksPanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0);
- ~BookmarksPanel();
+ virtual ~BookmarksPanel();
signals:
void openUrl(const KUrl &, const Rekonq::OpenType &);
@@ -64,7 +57,7 @@ signals:
public slots:
void showing(bool);
void startLoadFoldedState();
-
+
private slots:
void contextMenu(const QPoint &pos);
@@ -78,9 +71,7 @@ private:
KBookmark bookmarkForIndex(const QModelIndex &index);
PanelTreeView *m_treeView;
- bool m_loadingState;
-
- bool _loaded;
+ bool m_loadingState, m_loaded;
};
#endif // BOOKMARKSPANEL_H
diff --git a/src/bookmarks/bookmarksproxy.cpp b/src/bookmarks/bookmarksproxy.cpp
index 4e4b4f06..1e4da877 100644
--- a/src/bookmarks/bookmarksproxy.cpp
+++ b/src/bookmarks/bookmarksproxy.cpp
@@ -27,19 +27,18 @@
// Self Includes
#include "bookmarksproxy.h"
-#include "bookmarksproxy.moc"
BookmarksProxy::BookmarksProxy(QObject *parent)
: QSortFilterProxyModel(parent)
{
+ setFilterCaseSensitivity(Qt::CaseInsensitive);
}
-bool BookmarksProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
+bool BookmarksProxy::filterAcceptsRow(const int source_row, const QModelIndex &source_parent) const
{
- QModelIndex idx = sourceModel()->index(source_row, 0, source_parent);
- return recursiveMatch(idx);
+ return recursiveMatch( sourceModel()->index(source_row, 0, source_parent) );
}
@@ -48,10 +47,12 @@ bool BookmarksProxy::recursiveMatch(const QModelIndex &index) const
if (index.data().toString().contains(filterRegExp()))
return true;
- for (int childRow = 0; childRow < sourceModel()->rowCount(index); ++childRow)
+ int numChildren = sourceModel()->rowCount(index);
+ for (int childRow = 0; childRow < numChildren; ++childRow)
{
if (recursiveMatch(sourceModel()->index(childRow, 0, index)))
return true;
}
+
return false;
}
diff --git a/src/bookmarks/bookmarksproxy.h b/src/bookmarks/bookmarksproxy.h
index e7b50d8e..b4554d2b 100644
--- a/src/bookmarks/bookmarksproxy.h
+++ b/src/bookmarks/bookmarksproxy.h
@@ -33,9 +33,13 @@
#include "rekonq_defines.h"
// Qt Includes
-#include <QSortFilterProxyModel>
-
+#include <QtGui/QSortFilterProxyModel>
+/**
+ * QSortFilterProxyModel hides all children which parent doesn't
+ * match the filter. This class is used to change this behavior.
+ * If a bookmark matches the filter it'll be shown, even if it's parent doesn't match it.
+ */
class REKONQ_TESTS_EXPORT BookmarksProxy : public QSortFilterProxyModel
{
Q_OBJECT
@@ -45,9 +49,9 @@ public:
BookmarksProxy(QObject *parent = 0);
protected:
- virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
+ virtual bool filterAcceptsRow(const int source_row, const QModelIndex &source_parent) const;
- // returns true if any child(or children-child...) matches filter
+ // returns true if index or any of his children match the filter
bool recursiveMatch(const QModelIndex &index) const;
};
diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp
new file mode 100644
index 00000000..bce2bd1e
--- /dev/null
+++ b/src/bookmarks/bookmarkstoolbar.cpp
@@ -0,0 +1,435 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2008-2010 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2010 by Yoann Laissus <yoann dot laissus at gmail dot 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 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 <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+// Self Includes
+#include "bookmarkstoolbar.h"
+#include "bookmarkstoolbar.moc"
+
+// Local Includes
+#include "bookmarkscontextmenu.h"
+#include "mainwindow.h"
+#include "application.h"
+#include "bookmarksmanager.h"
+#include "bookmarkowner.h"
+
+// Qt Includes
+#include <QtGui/QFrame>
+#include <QActionEvent>
+
+
+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()
+{
+}
+
+
+KMenu * BookmarkMenu::contextMenu(QAction *act)
+{
+
+ KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(act);
+ if (!action)
+ return 0;
+ return new BookmarksContextMenu(action->bookmark(), manager(), static_cast<BookmarkOwner*>(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);
+ connect(action, SIGNAL(hovered()), this, SLOT(actionHovered()));
+ return action;
+ }
+}
+
+
+void BookmarkMenu::refill()
+{
+ clear();
+ fillBookmarks();
+
+ if (parentMenu()->actions().count() > 0)
+ parentMenu()->addSeparator();
+
+ if (isRoot())
+ {
+ addAddBookmark();
+ addAddBookmarksList();
+ addNewFolder();
+ addEditBookmarks();
+ }
+ else
+ {
+ addOpenFolderInTabs();
+ addAddBookmark();
+ addAddBookmarksList();
+ addNewFolder();
+ }
+}
+
+
+void BookmarkMenu::addOpenFolderInTabs()
+{
+ KAction *action;
+ 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())
+ {
+ action = new KAction(KIcon("tab-new"), i18n("Open Folder in Tabs"), this);
+ action->setHelpText(i18n("Open all bookmarks in this folder as new tabs."));
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(slotOpenFolderInTabs()));
+ parentMenu()->addAction(action);
+ }
+ }
+}
+
+
+void BookmarkMenu::actionHovered()
+{
+ KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(sender());
+ if (action)
+ Application::instance()->mainWindow()->notifyMessage(action->bookmark().url().url());
+}
+
+
+// ------------------------------------------------------------------------------------------------------
+
+
+BookmarkToolBar::BookmarkToolBar(KToolBar *toolBar, QObject *parent)
+ : QObject(parent)
+ , m_toolBar(toolBar)
+ , m_currentMenu(0)
+ , m_dragAction(0)
+ , m_dropAction(0)
+ , m_filled(false)
+{
+ connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(QString, QString)), this, SLOT(hideMenu()));
+ toolBar->setAcceptDrops(true);
+ toolBar->installEventFilter(this);
+
+ if (toolBar->isVisible())
+ {
+ Application::bookmarkProvider()->fillBookmarkBar(this);
+ m_filled = true;
+ }
+}
+
+
+BookmarkToolBar::~BookmarkToolBar()
+{
+}
+
+
+KToolBar* BookmarkToolBar::toolBar()
+{
+ return m_toolBar;
+}
+
+
+void BookmarkToolBar::menuDisplayed()
+{
+ qApp->installEventFilter(this);
+ m_currentMenu = qobject_cast<KMenu*>(sender());
+}
+
+
+void BookmarkToolBar::menuHidden()
+{
+ qApp->removeEventFilter(this);
+ m_currentMenu = 0;
+}
+
+
+void BookmarkToolBar::hideMenu()
+{
+ if(m_currentMenu)
+ m_currentMenu->hide();
+}
+
+
+bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event)
+{
+ if (m_currentMenu && m_currentMenu->isVisible())
+ {
+ // To switch root folders as in a menubar
+ KBookmarkActionMenu* act = dynamic_cast<KBookmarkActionMenu *>(toolBar()->actionAt(toolBar()->mapFromGlobal(QCursor::pos())));
+ if (event->type() == QEvent::MouseMove && act && m_currentMenu && act->menu() != m_currentMenu)
+ {
+ m_currentMenu->hide();
+ QPoint pos = toolBar()->mapToGlobal(toolBar()->widgetForAction(act)->pos());
+ act->menu()->popup(QPoint(pos.x(), pos.y() + toolBar()->widgetForAction(act)->height()));
+ }
+ }
+ else if (watched == toolBar())
+ {
+ if (event->type() == QEvent::Show)
+ {
+ if (!m_filled)
+ {
+ Application::bookmarkProvider()->fillBookmarkBar(this);
+ m_filled = true;
+ }
+ }
+ if (event->type() == QEvent::ActionRemoved)
+ {
+ QActionEvent *actionEvent = static_cast<QActionEvent*>(event);
+ if (actionEvent && actionEvent->action() != m_dropAction)
+ {
+ QWidget *widget = toolBar()->widgetForAction(actionEvent->action());
+ if (widget)
+ {
+ widget->removeEventFilter(this);
+ }
+ }
+ }
+ else if (event->type() == QEvent::ParentChange)
+ {
+ QActionEvent *actionEvent = static_cast<QActionEvent*>(event);
+ if (actionEvent && actionEvent->action() != m_dropAction)
+ {
+ QWidget *widget = toolBar()->widgetForAction(actionEvent->action());
+ if (widget)
+ {
+ widget->removeEventFilter(this);
+ }
+ }
+ }
+ else if (event->type() == QEvent::DragEnter)
+ {
+ QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent*>(event);
+ if (dragEvent->mimeData()->hasFormat("application/rekonq-bookmark"))
+ {
+ QByteArray addresses = dragEvent->mimeData()->data("application/rekonq-bookmark");
+ KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
+
+ if (!bookmark.isNull())
+ {
+ QFrame* dropIndicatorWidget = new QFrame(toolBar());
+ dropIndicatorWidget->setFrameShape(QFrame::VLine);
+ m_dropAction = toolBar()->insertWidget(toolBar()->actionAt(dragEvent->pos()), dropIndicatorWidget);
+
+ dragEvent->accept();
+ }
+ }
+ }
+ else if (event->type() == QEvent::DragMove)
+ {
+ QDragMoveEvent *dragEvent = static_cast<QDragMoveEvent*>(event);
+ if (dragEvent->mimeData()->hasFormat("application/rekonq-bookmark"))
+ {
+ QByteArray addresses = dragEvent->mimeData()->data("application/rekonq-bookmark");
+ KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
+ QAction *overAction = toolBar()->actionAt(dragEvent->pos());
+ KBookmarkActionInterface *overActionBK = dynamic_cast<KBookmarkActionInterface*>(overAction);
+ QWidget *widgetAction = toolBar()->widgetForAction(overAction);
+
+ if (!bookmark.isNull() && overAction != m_dropAction && overActionBK && widgetAction && m_dropAction)
+ {
+ toolBar()->removeAction(m_dropAction);
+
+ if ((dragEvent->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2))
+ {
+ if (toolBar()->actions().count() > toolBar()->actions().indexOf(overAction) + 1)
+ {
+ toolBar()->insertAction(toolBar()->actions().at(toolBar()->actions().indexOf(overAction) + 1), m_dropAction);
+ }
+ else
+ {
+ toolBar()->addAction(m_dropAction);
+ }
+ }
+ else
+ {
+ toolBar()->insertAction(overAction, m_dropAction);
+ }
+
+ dragEvent->accept();
+ }
+ }
+ }
+ else if (event->type() == QEvent::DragLeave)
+ {
+ QDragLeaveEvent *dragEvent = static_cast<QDragLeaveEvent*>(event);
+ delete m_dropAction;
+ m_dropAction = 0;
+ dragEvent->accept();
+ }
+ else if (event->type() == QEvent::Drop)
+ {
+ QDropEvent *dropEvent = static_cast<QDropEvent*>(event);
+ if (dropEvent->mimeData()->hasFormat("application/rekonq-bookmark"))
+ {
+ QByteArray addresses = dropEvent->mimeData()->data("application/rekonq-bookmark");
+ KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
+
+ QAction *destAction = toolBar()->actionAt(dropEvent->pos());
+ if (destAction && destAction == m_dropAction)
+ {
+ if (toolBar()->actions().indexOf(m_dropAction) > 0)
+ {
+ destAction = toolBar()->actions().at(toolBar()->actions().indexOf(m_dropAction) - 1);
+ }
+ else
+ {
+ destAction = toolBar()->actions().at(1);
+ }
+ }
+
+ KBookmarkActionInterface *destBookmarkAction = dynamic_cast<KBookmarkActionInterface *>(destAction);
+ QWidget *widgetAction = toolBar()->widgetForAction(destAction);
+
+ if (!bookmark.isNull() && destBookmarkAction && !destBookmarkAction->bookmark().isNull()
+ && widgetAction && bookmark.address() != destBookmarkAction->bookmark().address())
+ {
+ KBookmarkGroup root = Application::bookmarkProvider()->rootGroup();
+ KBookmark destBookmark = destBookmarkAction->bookmark();
+ // To fix an issue with panel's drags
+ root.deleteBookmark(bookmark);
+
+ if ((dropEvent->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2))
+ {
+ root.moveBookmark(bookmark, destBookmark);
+ }
+ else
+ {
+ root.moveBookmark(bookmark, destBookmark.parentGroup().previous(destBookmark));
+ }
+
+ Application::bookmarkProvider()->bookmarkManager()->emitChanged();
+ dropEvent->accept();
+ }
+ }
+ }
+ }
+ else
+ {
+ // Drag handling
+ if (event->type() == QEvent::MouseButtonPress)
+ {//QMessageBox::information(NULL, "", "");
+ QPoint pos = toolBar()->mapFromGlobal(QCursor::pos());
+ KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(toolBar()->actionAt(pos));
+
+ if (action && !action->bookmark().isGroup())
+ {
+ m_dragAction = toolBar()->actionAt(pos);
+ m_startDragPos = pos;
+ }
+ }
+ else if (event->type() == QEvent::MouseMove)
+ {
+ int distance = (toolBar()->mapFromGlobal(QCursor::pos()) - m_startDragPos).manhattanLength();
+ if (distance >= QApplication::startDragDistance())
+ {
+ startDrag();
+ }
+ }
+ }
+
+ return QObject::eventFilter(watched, event);
+}
+
+
+void BookmarkToolBar::actionHovered()
+{
+ KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(sender());
+ if (action)
+ Application::instance()->mainWindow()->notifyMessage(action->bookmark().url().url());
+}
+
+
+void BookmarkToolBar::startDrag()
+{
+ KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(m_dragAction);
+ if (action && !action->bookmark().isGroup())
+ {
+ QMimeData *mimeData = new QMimeData;
+
+ QByteArray address = action->bookmark().address().toLatin1();
+ mimeData->setData("application/rekonq-bookmark", address);
+ action->bookmark().populateMimeData(mimeData);
+
+ QDrag *drag = new QDrag(toolBar());
+ drag->setMimeData(mimeData);
+ drag->setPixmap(KIcon(action->bookmark().icon()).pixmap(24, 24));
+
+ drag->start(Qt::MoveAction);
+ connect(drag, SIGNAL(destroyed()), this, SLOT(dragDestroyed()));
+ }
+}
+
+
+void BookmarkToolBar::dragDestroyed()
+{
+ // A workaround to get rid of the checked state of the dragged action
+ if (m_dragAction)
+ {
+ m_dragAction->setVisible(false);
+ m_dragAction->setVisible(true);
+ m_dragAction = 0;
+ }
+ delete m_dropAction;
+ m_dropAction = 0;
+}
diff --git a/src/bookmarks/bookmarkstoolbar.h b/src/bookmarks/bookmarkstoolbar.h
new file mode 100644
index 00000000..54a430e3
--- /dev/null
+++ b/src/bookmarks/bookmarkstoolbar.h
@@ -0,0 +1,111 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2008-2010 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2010 by Yoann Laissus <yoann dot laissus at gmail dot 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 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 <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+#ifndef BOOKMARKSTOOLBAR_H
+#define BOOKMARKSTOOLBAR_H
+
+
+// KDE Includes
+#include <KBookmarkMenu>
+
+/**
+ * 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 slots:
+ void actionHovered();
+
+private:
+ void addOpenFolderInTabs();
+
+};
+
+
+// ------------------------------------------------------------------------------
+
+
+// KDE Includes
+#include <KToolBar>
+
+
+/**
+ * This class manage the bookmark toolbar.
+ * Some events from the toolbar are handled to allow the drag and drop
+ */
+
+class BookmarkToolBar : public QObject
+{
+ Q_OBJECT
+
+public:
+BookmarkToolBar(KToolBar *toolBar, QObject *parent);
+~BookmarkToolBar();
+
+KToolBar* toolBar();
+
+protected:
+ bool eventFilter(QObject *watched, QEvent *event);
+
+private slots:
+ void actionHovered();
+ void menuDisplayed();
+ void menuHidden();
+ void hideMenu();
+ void dragDestroyed();
+
+private:
+ void startDrag();
+
+ KToolBar *m_toolBar;
+ KMenu *m_currentMenu;
+ QPoint m_startDragPos;
+ QAction *m_dragAction;
+ QAction *m_dropAction;
+ bool m_filled;
+};
+
+#endif // BOOKMARKSTOOLBAR_H
diff --git a/src/bookmarks/bookmarkstreemodel.cpp b/src/bookmarks/bookmarkstreemodel.cpp
index 299efaf0..7f0bf66f 100644
--- a/src/bookmarks/bookmarkstreemodel.cpp
+++ b/src/bookmarks/bookmarkstreemodel.cpp
@@ -27,18 +27,13 @@
// Self Includes
#include "bookmarkstreemodel.h"
-#include "bookmarkstreemodel.moc"
// Local Includes
#include "application.h"
#include "bookmarksmanager.h"
// Qt Includes
-#include <QMimeData>
-
-// KDE includes
-#include <KBookmarkGroup>
-#include <KLocalizedString>
+#include <QtCore/QMimeData>
BtmItem::BtmItem(const KBookmark &bm)
@@ -140,6 +135,7 @@ KBookmark BtmItem::getBkm() const
return m_kbm;
}
+
// -------------------------------------------------------------------------------------
@@ -149,7 +145,6 @@ BookmarksTreeModel::BookmarksTreeModel(QObject *parent)
{
resetModel();
connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(const QString &, const QString &)), this, SLOT(bookmarksChanged(const QString &)));
- connect(this, SIGNAL(bookmarksUpdated()), parent, SLOT(startLoadFoldedState()));
}
@@ -168,33 +163,19 @@ int BookmarksTreeModel::rowCount(const QModelIndex &parent) const
}
else
{
- parentItem = static_cast< BtmItem* >(parent.internalPointer());
+ parentItem = static_cast<BtmItem*>(parent.internalPointer());
}
return parentItem->childCount();
}
-int BookmarksTreeModel::columnCount(const QModelIndex &parent) const
+int BookmarksTreeModel::columnCount(const QModelIndex& /*parent*/) const
{
- Q_UNUSED(parent)
- // name
return 1;
}
-QVariant BookmarksTreeModel::headerData(int section, Qt::Orientation orientation, int role) const
-{
- if (orientation == Qt::Horizontal
- && role == Qt::DisplayRole
- && section == 0
- )
- return i18n("Bookmark");
-
- return QVariant();
-}
-
-
Qt::ItemFlags BookmarksTreeModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
@@ -214,26 +195,18 @@ Qt::ItemFlags BookmarksTreeModel::flags(const QModelIndex &index) const
QModelIndex BookmarksTreeModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
- {
return QModelIndex();
- }
BtmItem *parentItem;
if (!parent.isValid())
- {
parentItem = m_root;
- }
else
- {
- parentItem = static_cast< BtmItem* >(parent.internalPointer());
- }
+ parentItem = static_cast<BtmItem*>(parent.internalPointer());
BtmItem *childItem = parentItem->child(row);
if (childItem)
- {
return createIndex(row, column, childItem);
- }
return QModelIndex();
}
@@ -242,17 +215,13 @@ QModelIndex BookmarksTreeModel::index(int row, int column, const QModelIndex &pa
QModelIndex BookmarksTreeModel::parent(const QModelIndex &index) const
{
if (!index.isValid())
- {
return QModelIndex();
- }
- BtmItem *childItem = static_cast< BtmItem* >(index.internalPointer());
+ BtmItem *childItem = static_cast<BtmItem*>(index.internalPointer());
BtmItem *parentItem = childItem->parent();
if (parentItem == m_root)
- {
return QModelIndex();
- }
return createIndex(parentItem->row(), 0, parentItem);
}
@@ -261,11 +230,9 @@ QModelIndex BookmarksTreeModel::parent(const QModelIndex &index) const
QVariant BookmarksTreeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
- {
return QVariant();
- }
- BtmItem *node = static_cast< BtmItem* >(index.internalPointer());
+ BtmItem *node = static_cast<BtmItem*>(index.internalPointer());
if (node && node == m_root)
{
if (role == Qt::DisplayRole)
@@ -283,12 +250,67 @@ QVariant BookmarksTreeModel::data(const QModelIndex &index, int role) const
}
+QStringList BookmarksTreeModel::mimeTypes() const
+{
+ return KBookmark::List::mimeDataTypes();
+}
+
+
+bool BookmarksTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
+{
+ if (action != Qt::MoveAction || !data->hasFormat("application/rekonq-bookmark"))
+ return false;
+
+ QByteArray addresses = data->data("application/rekonq-bookmark");
+ KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
+
+ KBookmarkGroup root;
+ if (parent.isValid())
+ root = bookmarkForIndex(parent).toGroup();
+ else
+ root = Application::bookmarkProvider()->rootGroup();
+
+ QModelIndex destIndex = index(row, column, parent);
+
+ if (destIndex.isValid() && row != -1)
+ {
+ root.moveBookmark(bookmark, root.previous(bookmarkForIndex(destIndex)));
+ }
+ else
+ {
+ root.deleteBookmark(bookmark);
+ root.addBookmark(bookmark);
+ }
+
+ Application::bookmarkProvider()->bookmarkManager()->emitChanged();
+
+ return true;
+}
+
+
+Qt::DropActions BookmarksTreeModel::supportedDropActions() const
+{
+ return Qt::MoveAction;
+}
+
+
+QMimeData* BookmarksTreeModel::mimeData(const QModelIndexList &indexes) const
+{
+ QMimeData *mimeData = new QMimeData;
+
+ QByteArray address = bookmarkForIndex(indexes.first()).address().toLatin1();
+ mimeData->setData("application/rekonq-bookmark", address);
+ bookmarkForIndex(indexes.first()).populateMimeData(mimeData);
+
+ return mimeData;
+}
+
+
void BookmarksTreeModel::bookmarksChanged(const QString &groupAddress)
{
if (groupAddress.isEmpty())
{
resetModel();
- emit bookmarksUpdated();
}
else
{
@@ -296,11 +318,12 @@ void BookmarksTreeModel::bookmarksChanged(const QString &groupAddress)
BtmItem *node = m_root;
QModelIndex nodeIndex;
- QStringList indexChain( groupAddress.split( '/', QString::SkipEmptyParts) );
- foreach( const QString &sIndex, indexChain )
+ QStringList indexChain( groupAddress.split('/', QString::SkipEmptyParts) );
+ bool ok;
+ int i;
+ foreach (const QString &sIndex, indexChain)
{
- bool ok;
- int i = sIndex.toInt( &ok );
+ i = sIndex.toInt( &ok );
if( !ok )
break;
@@ -312,8 +335,9 @@ void BookmarksTreeModel::bookmarksChanged(const QString &groupAddress)
}
populate(node, Application::bookmarkProvider()->bookmarkManager()->findByAddress(groupAddress).toGroup());
endResetModel();
- emit bookmarksUpdated();
}
+
+ emit bookmarksUpdated();
}
@@ -328,10 +352,6 @@ void BookmarksTreeModel::setRoot(KBookmarkGroup bmg)
beginResetModel();
delete m_root;
m_root = new BtmItem(KBookmark());
-
- if (bmg.isNull())
- return;
-
populate(m_root, bmg);
endResetModel();
}
@@ -361,64 +381,3 @@ KBookmark BookmarksTreeModel::bookmarkForIndex(const QModelIndex &index) const
{
return static_cast<BtmItem*>(index.internalPointer())->getBkm();
}
-
-
-Qt::DropActions BookmarksTreeModel::supportedDropActions() const
-{
- return Qt::MoveAction;
-}
-
-
-QStringList BookmarksTreeModel::mimeTypes() const
-{
- return KBookmark::List::mimeDataTypes();
-}
-
-
-QMimeData* BookmarksTreeModel::mimeData(const QModelIndexList & indexes) const
-{
- QMimeData *mimeData = new QMimeData;
-
- QByteArray address = bookmarkForIndex(indexes.first()).address().toLatin1();
- mimeData->setData("application/rekonq-bookmark", address);
- bookmarkForIndex(indexes.first()).populateMimeData(mimeData);
-
- return mimeData;
-}
-
-
-bool BookmarksTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex & parent)
-{
- if (action == Qt::MoveAction)
- {
- if (data->hasFormat("application/rekonq-bookmark"))
- {
- QByteArray addresses = data->data("application/rekonq-bookmark");
- KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
-
- QModelIndex destIndex = index(row, column, parent);
-
- KBookmark dropDestBookmark;
- if (destIndex.isValid())
- dropDestBookmark = bookmarkForIndex(destIndex);
-
- KBookmarkGroup root = Application::bookmarkProvider()->rootGroup();
- if (parent.isValid())
- root = bookmarkForIndex(parent).toGroup();
-
- if (destIndex.isValid() && row != -1)
- {
- root.moveBookmark(bookmark, root.previous(dropDestBookmark));
-
- }
- else
- {
- root.deleteBookmark(bookmark);
- root.addBookmark(bookmark);
- }
-
- Application::bookmarkProvider()->bookmarkManager()->emitChanged();
- }
- }
- return true;
-}
diff --git a/src/bookmarks/bookmarkstreemodel.h b/src/bookmarks/bookmarkstreemodel.h
index c509840b..6b85365b 100644
--- a/src/bookmarks/bookmarkstreemodel.h
+++ b/src/bookmarks/bookmarkstreemodel.h
@@ -36,13 +36,14 @@
#include <KBookmark>
// Qt Includes
-#include <QAbstractItemModel>
+#include <QtCore/QAbstractItemModel>
class BtmItem
{
public:
BtmItem(const KBookmark &bm);
~BtmItem();
+
QVariant data(int role = Qt::DisplayRole) const;
int row() const;
int childCount() const;
@@ -66,22 +67,33 @@ class REKONQ_TESTS_EXPORT BookmarksTreeModel : public QAbstractItemModel
public:
explicit BookmarksTreeModel(QObject *parent = 0);
- ~BookmarksTreeModel();
+ virtual ~BookmarksTreeModel();
+ /**
+ * @return number of rows under the given parent.
+ */
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ /**
+ * @return number of columns (always 1).
+ */
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
- virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+ /**
+ * @return index in the model specified by the given row, column and parent.
+ */
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
+ /**
+ * @return parent of the given index.
+ */
virtual QModelIndex parent(const QModelIndex &index) const;
virtual QVariant data(const QModelIndex &index, int role) const;
virtual QStringList mimeTypes() const;
- virtual bool dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent);
+ virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
virtual Qt::DropActions supportedDropActions() const;
- virtual QMimeData *mimeData(const QModelIndexList & indexes) const;
+ virtual QMimeData *mimeData(const QModelIndexList &indexes) const;
private slots:
void bookmarksChanged(const QString &groupAddress);