From aaa673a3e43ae0d309a9428d3e62d9f350137acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Ander=20Pe=C3=B1alba?= Date: Tue, 17 Aug 2010 23:48:10 +0200 Subject: BookmarkOwner class clean-up --- src/bookmarks/bookmarkowner.cpp | 230 ++++++++++++++++++---------------------- src/bookmarks/bookmarkowner.h | 52 ++++----- 2 files changed, 128 insertions(+), 154 deletions(-) (limited to 'src') diff --git a/src/bookmarks/bookmarkowner.cpp b/src/bookmarks/bookmarkowner.cpp index 6c55f724..fb7c737e 100644 --- a/src/bookmarks/bookmarkowner.cpp +++ b/src/bookmarks/bookmarkowner.cpp @@ -61,17 +61,109 @@ KAction* BookmarkOwner::action(const BookmarkAction &bmAction) } -void BookmarkOwner::openBookmark(const KBookmark & bookmark, +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 > BookmarkOwner::currentBookmarkList() const +{ + QList< QPair > bkList; + MainView *view = Application::instance()->mainWindow()->mainView(); + int tabNumber = view->count(); + + for (int i = 0; i < tabNumber; ++i) + { + QPair 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) + bookmarkSelected(bookmark); + if (keyboardModifiers & Qt::ControlModifier || mouseButtons & Qt::MidButton) { - emit openUrl(bookmark.url(), Rekonq::NewTab); + openBookmarkInNewTab(); } else { - emit openUrl(bookmark.url(), Rekonq::CurrentTab); + openBookmark(); + } +} + + +void BookmarkOwner::openFolderinTabs(const KBookmarkGroup &bookmark) +{ + bookmarkSelected(bookmark); + openBookmarkFolder(); +} + + +void BookmarkOwner::bookmarkSelected(const KBookmark &bookmark) +{ + selected = bookmark; +} + + +void BookmarkOwner::openBookmark() +{ + emit openUrl(selected.url(), Rekonq::CurrentTab); +} + + +void BookmarkOwner::openBookmarkInNewTab() +{ + emit openUrl(selected.url(), Rekonq::NewTab); +} + + +void BookmarkOwner::openBookmarkInNewWindow() +{ + emit openUrl(selected.url(), Rekonq::NewWindow); +} + + +void BookmarkOwner::openBookmarkFolder() +{ + if (!selected.isGroup()) + return; + + QList 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; + } + + foreach (KUrl url, urlList) + { + emit openUrl(url, Rekonq::NewFocusedTab); } } @@ -158,6 +250,15 @@ void BookmarkOwner::newSeparator() } +void BookmarkOwner::copyLink() +{ + if (selected.isNull()) + return; + + QApplication::clipboard()->setText(selected.url().url()); +} + + void BookmarkOwner::editBookmark() { if (selected.isNull()) @@ -190,7 +291,7 @@ bool BookmarkOwner::deleteBookmark() else if (selected.isSeparator()) { dialogCaption = i18n("Separator Deletion"); - dialogText = i18n("Are you sure you wish to remove this separator?", name); + dialogText = i18n("Are you sure you wish to remove this separator?"); } else { @@ -215,125 +316,6 @@ bool BookmarkOwner::deleteBookmark() } -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 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::iterator url; - for (url = urlList.begin(); url != urlList.end(); ++url) - { - emit openUrl(*url, Rekonq::NewFocusedTab); - } -} - - -QList< QPair > BookmarkOwner::currentBookmarkList() const -{ - QList< QPair > bkList; - int tabNumber = Application::instance()->mainWindow()->mainView()->count(); - - for (int i = 0; i < tabNumber; i++) - { - QPair 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; -} - - -void BookmarkOwner::bookmarkSelected(const KBookmark &bookmark) -{ - selected = bookmark; -} - - -void BookmarkOwner::openBookmark() -{ - emit openUrl(selected.url(), Rekonq::CurrentTab); -} - - -void BookmarkOwner::openBookmarkInNewTab() -{ - emit openUrl(selected.url(), Rekonq::NewTab); -} - - -void BookmarkOwner::openBookmarkInNewWindow() -{ - emit openUrl(selected.url(), Rekonq::NewWindow); -} - - -void BookmarkOwner::openBookmarkFolder() -{ - if (!selected.isGroup()) - return; - - QList 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; - } - - foreach (KUrl url, urlList) - { - emit openUrl(url, Rekonq::NewFocusedTab); - } -} - - -void BookmarkOwner::copyLink() -{ - if (selected.isNull()) - return; - - QApplication::clipboard()->setText(selected.url().url()); -} - - void BookmarkOwner::setupActions() { createAction(OPEN, i18n("Open"), "tab-new", diff --git a/src/bookmarks/bookmarkowner.h b/src/bookmarks/bookmarkowner.h index 395edf54..abb65c36 100644 --- a/src/bookmarks/bookmarkowner.h +++ b/src/bookmarks/bookmarkowner.h @@ -37,15 +37,14 @@ // KDE Includes #include +// Forward Declarations class KAction; - /** * Reimplementation of KBookmarkOwner, this class allows to manage - * bookmarks as actions - * + * bookmarks as actions. */ -class REKONQ_TESTS_EXPORT BookmarkOwner : public QObject , public KBookmarkOwner +class REKONQ_TESTS_EXPORT BookmarkOwner : public QObject, public KBookmarkOwner { Q_OBJECT @@ -73,6 +72,25 @@ public: */ 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 > currentBookmarkList() const; + /** * This function is called when a bookmark is selected and belongs to * the ancestor class. @@ -86,28 +104,6 @@ public: 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. @@ -115,14 +111,10 @@ public: */ virtual void openFolderinTabs(const KBookmarkGroup &bookmark); - virtual QList< QPair > 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 &); -- cgit v1.2.1