summaryrefslogtreecommitdiff
path: root/src/bookmarks/bookmarksmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bookmarks/bookmarksmanager.cpp')
-rw-r--r--src/bookmarks/bookmarksmanager.cpp341
1 files changed, 20 insertions, 321 deletions
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;
}