summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-04-19 09:54:44 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-04-19 09:54:44 +0200
commitc4e852c17c4c6c73baf73a7e5d50ddbbc296e39a (patch)
tree21a2865c4021e57538542ed8966cc59f17f3f133
parentMerge commit 'refs/merge-requests/2242' of git://gitorious.org/rekonq/mainlin... (diff)
parentFix compile (diff)
downloadrekonq-c4e852c17c4c6c73baf73a7e5d50ddbbc296e39a.tar.xz
Merge commit 'refs/merge-requests/2243' of git://gitorious.org/rekonq/mainline into m2243
-rw-r--r--src/bookmarks/bookmarksmanager.cpp180
-rw-r--r--src/bookmarks/bookmarksmanager.h36
-rw-r--r--src/mainwindow.cpp1
3 files changed, 113 insertions, 104 deletions
diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp
index 7e933599..df6bc54b 100644
--- a/src/bookmarks/bookmarksmanager.cpp
+++ b/src/bookmarks/bookmarksmanager.cpp
@@ -94,9 +94,9 @@ QString BookmarkOwner::currentTitle() const
}
-void BookmarkOwner::openFolderinTabs(const KBookmarkGroup &bm)
+void BookmarkOwner::openFolderinTabs(const KBookmarkGroup &bookmark)
{
- QList<KUrl> urlList = bm.groupUrlList();
+ QList<KUrl> urlList = bookmark.groupUrlList();
if(urlList.length() > 8)
{
@@ -107,7 +107,7 @@ void BookmarkOwner::openFolderinTabs(const KBookmarkGroup &bm)
QList<KUrl>::iterator url;
for (url = urlList.begin(); url != urlList.end(); ++url)
{
- Application::instance()->loadUrl(*url, Rekonq::NewCurrentTab);
+ emit openUrl(*url, Rekonq::NewCurrentTab);
}
}
@@ -136,23 +136,35 @@ BookmarkMenu::BookmarkMenu(KBookmarkManager *manager,
KMenu *menu,
KActionCollection* actionCollection)
: KBookmarkMenu(manager, owner, menu, actionCollection)
-
{
KAction *a = KStandardAction::addBookmark(this, SLOT(slotAddBookmark()), this);
actionCollection->addAction(QLatin1String("rekonq_add_bookmark"),a);
+ refill();
+}
+
+
+BookmarkMenu::BookmarkMenu(KBookmarkManager *manager,
+ KBookmarkOwner *owner,
+ KMenu *parentMenu,
+ const QString &parentAddress)
+ : KBookmarkMenu(manager, owner, parentMenu, parentAddress)
+{
+ refill();
}
+
BookmarkMenu::~BookmarkMenu()
{
}
-KMenu *BookmarkMenu::viewContextMenu(QAction *action)
+KMenu * BookmarkMenu::contextMenu(QAction *act)
{
- KBookmarkActionInterface* act = dynamic_cast<KBookmarkActionInterface *>(action);
- if (!act)
+
+ KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(act);
+ if (!action)
return 0;
- return new BookmarkContextMenu(act->bookmark(), manager(), owner());
+ return new BookmarkContextMenu(action->bookmark(), manager(), owner());
}
@@ -172,6 +184,76 @@ void BookmarkMenu::slotAddBookmark()
}
+QAction * BookmarkMenu::actionForBookmark(const KBookmark &bookmark)
+{
+ if(bookmark.isGroup())
+ {
+ KBookmarkActionMenu *actionMenu = new KBookmarkActionMenu(bookmark, this);
+ new BookmarkMenu(manager(), owner(), actionMenu->menu(), bookmark.address());
+ return actionMenu;
+ }
+ else if(bookmark.isSeparator())
+ {
+ return KBookmarkMenu::actionForBookmark(bookmark);
+ }
+ else
+ {
+ Application::bookmarkProvider()->completionObject()->addItem(bookmark.url().url());
+ return new KBookmarkAction( bookmark, owner(), this );
+ }
+}
+
+
+void BookmarkMenu::refill()
+{
+ 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 a new tab." ) );
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(slotOpenFolderInTabs()));
+ parentMenu()->addAction(action);
+ }
+ }
+}
+
+
// ------------------------------------------------------------------------------------------------------
@@ -203,7 +285,7 @@ BookmarkProvider::BookmarkProvider(QObject *parent)
bookfile = KUrl(bookmarksPath);
}
}
- // A workaround to avoid a long delay between the two changed signals of the bookmark manager
+
m_manager = KBookmarkManager::managerForFile(bookfile.path(), "rekonq");
connect(m_manager, SIGNAL(changed(const QString &, const QString &)),
@@ -227,7 +309,8 @@ BookmarkProvider::~BookmarkProvider()
void BookmarkProvider::setupBookmarkBar(KToolBar *toolbar)
{
KToolBar *bookmarkToolBar = toolbar;
- m_bookmarkToolBars.append(toolbar);
+ m_bookmarkToolBars.append(bookmarkToolBar);
+ bookmarkToolBar->setContextMenuPolicy(Qt::CustomContextMenu);
connect(bookmarkToolBar, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(contextMenu(const QPoint &)));
@@ -246,6 +329,8 @@ void BookmarkProvider::slotBookmarksChanged(const QString &group, const QString
Q_UNUSED(group)
Q_UNUSED(caller)
+ m_completion->clear();
+
foreach(KToolBar *bookmarkToolBar, m_bookmarkToolBars)
{
if (bookmarkToolBar)
@@ -255,7 +340,6 @@ void BookmarkProvider::slotBookmarksChanged(const QString &group, const QString
return;
bookmarkToolBar->clear();
- m_completion->clear();
KBookmark bookmark = toolBarGroup.first();
while (!bookmark.isNull())
@@ -286,11 +370,11 @@ void BookmarkProvider::contextMenu(const QPoint &point)
if(!bookmarkToolBar)
return;
- KAction* action = dynamic_cast<KAction*>(bookmarkToolBar->actionAt(point));
+ KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(bookmarkToolBar->actionAt(point));
if (!action)
return;
- KMenu *menu = m_bookmarkMenu->viewContextMenu(action);
+ KMenu *menu = new BookmarkContextMenu(action->bookmark(), bookmarkManager(), bookmarkOwner());
if (!menu)
return;
@@ -313,17 +397,10 @@ KAction *BookmarkProvider::fillBookmarkBar(const KBookmark &bookmark)
{
if (bookmark.isGroup())
{
- KBookmarkGroup group = bookmark.toGroup();
- KBookmark bm = group.first();
- BookmarkActionMenu *menuAction = new BookmarkActionMenu(group, this);
-
- while (!bm.isNull())
- {
- menuAction->addAction(fillBookmarkBar(bm));
- bm = group.next(bm);
- }
+ KBookmarkActionMenu *menuAction = new KBookmarkActionMenu(bookmark.toGroup(), this);
+ menuAction->setDelayed(false);
+ new BookmarkMenu(bookmarkManager(), bookmarkOwner(), menuAction->menu(), bookmark.address());
- menuAction->addFolderActions();
return menuAction;
}
@@ -336,8 +413,7 @@ KAction *BookmarkProvider::fillBookmarkBar(const KBookmark &bookmark)
return a;
}
else
- {
- m_completion->addItem(bookmark.url().url());
+ {
return new KBookmarkAction(bookmark, m_owner, this);
}
}
@@ -400,57 +476,3 @@ QString BookmarkProvider::titleForBookmarkUrl(const KBookmark &bookmark, QString
return title;
}
-
-
-// ----------------------------------------------------------------------------------------------
-
-
-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())
- {
- KBookmark bookmark = m_group.first();
-
- while(bookmark.isGroup() || bookmark.isSeparator())
- {
- bookmark = m_group.next(bookmark);
- }
-
- if(!bookmark.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 7fb02970..8d09e122 100644
--- a/src/bookmarks/bookmarksmanager.h
+++ b/src/bookmarks/bookmarksmanager.h
@@ -113,7 +113,7 @@ public:
* The default implementation does nothing.
* This is only called if supportsTabs() returns true
*/
- virtual void openFolderinTabs(const KBookmarkGroup &bm);
+ virtual void openFolderinTabs(const KBookmarkGroup &bookmark);
virtual QList< QPair<QString, QString> > currentBookmarkList() const;
@@ -133,7 +133,6 @@ signals:
// KDE Includes
#include <KBookmarkMenu>
-
/**
* This class represent the rekonq bookmarks menu.
* It's just a simple class inherited from KBookmarkMenu
@@ -148,13 +147,23 @@ public:
KBookmarkOwner* owner,
KMenu* menu,
KActionCollection* actionCollection);
+ BookmarkMenu(KBookmarkManager *manager,
+ KBookmarkOwner *owner,
+ KMenu *parentMenu,
+ const QString &parentAddress);
~BookmarkMenu();
- virtual KMenu *viewContextMenu(QAction* action);
+protected:
+ virtual KMenu * contextMenu(QAction * act);
+ virtual void refill();
+ virtual QAction* actionForBookmark(const KBookmark &bookmark);
protected slots:
void slotAddBookmark();
+private:
+ void addOpenFolderInTabs();
+
};
@@ -265,25 +274,4 @@ private:
};
-// ------------------------------------------------------------------------------------------
-
-
-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/mainwindow.cpp b/src/mainwindow.cpp
index 898aa842..3c8874e1 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -187,7 +187,6 @@ void MainWindow::setupToolbars()
// =========== Bookmarks ToolBar ================================
m_bmBar->setAcceptDrops(true);
- m_bmBar->setContextMenuPolicy(Qt::CustomContextMenu);
Application::bookmarkProvider()->setupBookmarkBar(m_bmBar);
if(ReKonfig::firstExecution())