diff options
-rw-r--r-- | src/CMakeLists.txt | 14 | ||||
-rw-r--r-- | src/bookmarks/bookmarkcontextmenu.cpp | 321 | ||||
-rw-r--r-- | src/bookmarks/bookmarkowner.cpp | 351 | ||||
-rw-r--r-- | src/bookmarks/bookmarkowner.h | 147 | ||||
-rw-r--r-- | src/bookmarks/bookmarkscontextmenu.cpp | 127 | ||||
-rw-r--r-- | src/bookmarks/bookmarkscontextmenu.h (renamed from src/bookmarks/bookmarkcontextmenu.h) | 33 | ||||
-rw-r--r-- | src/bookmarks/bookmarksmanager.cpp | 344 | ||||
-rw-r--r-- | src/bookmarks/bookmarksmanager.h | 178 | ||||
-rw-r--r-- | src/bookmarks/bookmarkspanel.cpp | 8 | ||||
-rw-r--r-- | src/bookmarks/bookmarkstoolbar.cpp | 437 | ||||
-rw-r--r-- | src/bookmarks/bookmarkstoolbar.h | 120 | ||||
-rw-r--r-- | src/data/rekonq.desktop | 1 | ||||
-rw-r--r-- | src/mainwindow.cpp | 131 | ||||
-rw-r--r-- | src/urlbar/bookmarkwidget.cpp | 12 |
14 files changed, 1289 insertions, 935 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e873052b..151906b9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,13 +7,13 @@ ADD_SUBDIRECTORY( tests ) ### ------- SETTING REKONQ FILES.. SET( rekonq_KDEINIT_SRCS - application.cpp + application.cpp clicktoflash.cpp filterurljob.cpp findbar.cpp zoombar.cpp mainview.cpp - mainwindow.cpp + mainwindow.cpp networkaccessmanager.cpp newtabpage.cpp paneltreeview.cpp @@ -31,7 +31,7 @@ SET( rekonq_KDEINIT_SRCS webtab.cpp searchengine.cpp #---------------------------------------- - history/autosaver.cpp + history/autosaver.cpp history/historymanager.cpp history/historymodels.cpp history/historypanel.cpp @@ -48,7 +48,9 @@ SET( rekonq_KDEINIT_SRCS bookmarks/bookmarkspanel.cpp bookmarks/bookmarkstreemodel.cpp bookmarks/bookmarksproxy.cpp - bookmarks/bookmarkcontextmenu.cpp + bookmarks/bookmarkscontextmenu.cpp + bookmarks/bookmarkstoolbar.cpp + bookmarks/bookmarkowner.cpp #---------------------------------------- adblock/adblockhostmatcher.cpp adblock/adblockmanager.cpp @@ -110,8 +112,8 @@ KDE4_ADD_KDEINIT_EXECUTABLE( rekonq ${rekonq_KDEINIT_SRCS} main.cpp ) ### --------------- TARGETTING LINK LIBRARIES... TARGET_LINK_LIBRARIES ( kdeinit_rekonq - ${QT_LIBRARIES} - ${QT_QTWEBKIT_LIBRARY} + ${QT_LIBRARIES} + ${QT_QTWEBKIT_LIBRARY} ${KDE4_KDEWEBKIT_LIBS} ${KDE4_KUTILS_LIBS} ${KDE4_KDEUI_LIBS} diff --git a/src/bookmarks/bookmarkcontextmenu.cpp b/src/bookmarks/bookmarkcontextmenu.cpp deleted file mode 100644 index 714c8b51..00000000 --- a/src/bookmarks/bookmarkcontextmenu.cpp +++ /dev/null @@ -1,321 +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(); - Application::bookmarkProvider()->bookmarkOwner()->deleteBookmark(bm); -} - - -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..fb7c737e --- /dev/null +++ b/src/bookmarks/bookmarkowner.cpp @@ -0,0 +1,351 @@ +/* ============================================================ +* +* 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) + , actions(QVector<KAction*>(NUM_ACTIONS)) +{ + setupActions(); +} + + +KAction* BookmarkOwner::action(const BookmarkAction &bmAction) +{ + return static_cast<KAction*>(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) +{ + bookmarkSelected(bookmark); + if (keyboardModifiers & Qt::ControlModifier || mouseButtons & Qt::MidButton) + { + openBookmarkInNewTab(); + } + else + { + 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<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; + } + + foreach (KUrl url, urlList) + { + emit openUrl(url, Rekonq::NewFocusedTab); + } +} + + +void BookmarkOwner::bookmarkCurrentPage() +{ + 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() +{ + 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() +{ + 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() +{ + if (selected.isNull()) + return; + + QApplication::clipboard()->setText(selected.url().url()); +} + + +void BookmarkOwner::editBookmark() +{ + 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() +{ + 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); + 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..abb65c36 --- /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 bookmarkSelected(const KBookmark &bookmark); + + void openBookmark(); + void openBookmarkInNewTab(); + void openBookmarkInNewWindow(); + void openBookmarkFolder(); + void bookmarkCurrentPage(); + void newBookmarkFolder(); + void newSeparator(); + void copyLink(); + void editBookmark(); + bool deleteBookmark(); + +private: + KBookmarkManager *m_manager; + + QVector<KAction*> actions; + KBookmark selected; + + 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..45b7f563 --- /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->bookmarkSelected(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..424f8da4 100644 --- a/src/bookmarks/bookmarkcontextmenu.h +++ b/src/bookmarks/bookmarkscontextmenu.h @@ -27,42 +27,27 @@ #ifndef BOOKMARKCONTEXTMENU_H #define BOOKMARKCONTEXTMENU_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 diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp index cade77b4..0c3284bb 100644 --- a/src/bookmarks/bookmarksmanager.cpp +++ b/src/bookmarks/bookmarksmanager.cpp @@ -29,350 +29,20 @@ // 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::deleteBookmark(KBookmark &bookmark) -{ - QString name = QString(bookmark.fullText()).replace("&&", "&"); - QString dialogCaption, dialogText; - - if (bookmark.isGroup()) - { - dialogCaption = i18n("Bookmark Folder Deletion"); - dialogText = i18n("Are you sure you wish to remove the bookmark folder\n\"%1\"?", name); - } - else if (bookmark.isSeparator()) - { - dialogCaption = i18n("Separator Deletion"); - dialogText = i18n("Are you sure you wish to remove this separator?", name); - } - 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; - - KBookmarkGroup bmg = bookmark.parentGroup(); - bmg.deleteBookmark(bookmark); - Application::bookmarkProvider()->bookmarkManager()->emitChanged(bmg); - return true; -} - - -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) @@ -407,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); @@ -484,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)); } diff --git a/src/bookmarks/bookmarksmanager.h b/src/bookmarks/bookmarksmanager.h index b084b8ee..49073b2a 100644 --- a/src/bookmarks/bookmarksmanager.h +++ b/src/bookmarks/bookmarksmanager.h @@ -34,184 +34,14 @@ // 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); - - /** - * Promps the user to delete a bookmark. - * @param bookmark The bookmark to delete. - * @return true if the bookmark was deleted, false if canceled. - */ - static bool deleteBookmark(KBookmark &bookmark); - - - /** - * 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; /** diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp index b49d4f5e..231df638 100644 --- a/src/bookmarks/bookmarkspanel.cpp +++ b/src/bookmarks/bookmarkspanel.cpp @@ -33,7 +33,8 @@ #include "bookmarksmanager.h" #include "bookmarkstreemodel.h" #include "bookmarksproxy.h" -#include "bookmarkcontextmenu.h" +#include "bookmarkscontextmenu.h" +#include "bookmarkowner.h" // Auto Includes #include "rekonq.h" @@ -201,7 +202,7 @@ void BookmarksPanel::contextMenu(const QPoint &pos) KBookmark selected = bookmarkForIndex(index); - BookmarkContextMenu menu( selected, + BookmarksContextMenu menu( selected, Application::bookmarkProvider()->bookmarkManager(), Application::bookmarkProvider()->bookmarkOwner(), this @@ -218,5 +219,6 @@ void BookmarksPanel::deleteBookmark() return; KBookmark bm = bookmarkForIndex(index); - Application::instance()->bookmarkProvider()->bookmarkOwner()->deleteBookmark(bm); + Application::instance()->bookmarkProvider()->bookmarkOwner()->bookmarkSelected(bm); + Application::instance()->bookmarkProvider()->bookmarkOwner()->deleteBookmark(); } diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp new file mode 100644 index 00000000..3f103104 --- /dev/null +++ b/src/bookmarks/bookmarkstoolbar.cpp @@ -0,0 +1,437 @@ +/* ============================================================ +* +* 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> + + +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()); +} + + +// ------------------------------------------------------------------------------------------------------ + +#include <QActionEvent> + +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) + , m_dragAction(0) + , m_dropAction(0) +{ + connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(QString, QString)), this, SLOT(hideMenu())); + setAcceptDrops(true); +} + + +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) +{ + + if (m_currentMenu && m_currentMenu->isVisible()) + { + // To switch root folders as in a menubar + KBookmarkActionMenu* act = dynamic_cast<KBookmarkActionMenu *>(this->actionAt(this->mapFromGlobal(QCursor::pos()))); + if (event->type() == QEvent::MouseMove && act && m_currentMenu && act->menu() != m_currentMenu) + { + m_currentMenu->hide(); + QPoint pos = mapToGlobal(widgetForAction(act)->pos()); + act->menu()->popup(QPoint(pos.x(), pos.y() + widgetForAction(act)->height())); + } + } + else + { + // Drag handling + if (event->type() == QEvent::MouseButtonPress) + { + QPoint pos = mapFromGlobal(QCursor::pos()); + KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(actionAt(pos)); + + if (action && !action->bookmark().isGroup()) + { + m_dragAction = actionAt(pos); + m_startDragPos = pos; + } + } + else if (event->type() == QEvent::MouseMove) + { + int distance = (mapFromGlobal(QCursor::pos()) - m_startDragPos).manhattanLength(); + if (distance >= QApplication::startDragDistance()) + { + startDrag(); + } + } + } + return KToolBar::eventFilter(watched, event); +} + + +void BookmarkToolBar::actionHovered() +{ + KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(sender()); + if (action) + Application::instance()->mainWindow()->notifyMessage(action->bookmark().url().url()); +} + + +void BookmarkToolBar::actionEvent(QActionEvent *event) +{ + KToolBar::actionEvent(event); + + QWidget *widget = widgetForAction(event->action()); + if (!widget || event->action() == m_dropAction) + return; + + if (event->type() == QEvent::ActionAdded) + { + widget->installEventFilter(this); + } + else if (event->type() == QEvent::ActionRemoved) + { + widget->removeEventFilter(this); + } + else if (event->type() == QEvent::ParentChange) + { + widget->removeEventFilter(this); + } +} + + +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(this); + 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::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasFormat("application/rekonq-bookmark")) + { + QByteArray addresses = event->mimeData()->data("application/rekonq-bookmark"); + KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data())); + + if (!bookmark.isNull()) + { + QFrame* dropIndicatorWidget = new QFrame(this); + dropIndicatorWidget->setFrameShape(QFrame::VLine); + m_dropAction = insertWidget(actionAt(event->pos()), dropIndicatorWidget); + + event->accept(); + } + } + + KToolBar::dragEnterEvent(event); +} + + +void BookmarkToolBar::dragMoveEvent(QDragMoveEvent *event) +{ + if (event->mimeData()->hasFormat("application/rekonq-bookmark")) + { + QByteArray addresses = event->mimeData()->data("application/rekonq-bookmark"); + KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data())); + QAction *overAction = actionAt(event->pos()); + KBookmarkActionInterface *overActionBK = dynamic_cast<KBookmarkActionInterface*>(overAction); + QWidget *widgetAction = widgetForAction(overAction); + + if (!bookmark.isNull() && overAction != m_dropAction && overActionBK && widgetAction && m_dropAction) + { + removeAction(m_dropAction); + + if ((event->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2)) + { + if (actions().count() > actions().indexOf(overAction) + 1) + { + insertAction(actions().at(actions().indexOf(overAction) + 1), m_dropAction); + } + else + { + addAction(m_dropAction); + } + } + else + { + insertAction(overAction, m_dropAction); + } + + event->accept(); + } + } + + KToolBar::dragMoveEvent(event); +} + + +void BookmarkToolBar::dragLeaveEvent(QDragLeaveEvent *event) +{ + delete m_dropAction; + m_dropAction = 0; + event->accept(); + KToolBar::dragLeaveEvent(event); +} + + +void BookmarkToolBar::dropEvent(QDropEvent *event) +{ + if (event->mimeData()->hasFormat("application/rekonq-bookmark")) + { + QByteArray addresses = event->mimeData()->data("application/rekonq-bookmark"); + KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data())); + + QAction *destAction = actionAt(event->pos()); + if (destAction && destAction == m_dropAction) + { + if (actions().indexOf(m_dropAction) > 0) + { + destAction = actions().at(actions().indexOf(m_dropAction) - 1); + } + else + { + destAction = actions().at(1); + } + } + + KBookmarkActionInterface *destBookmarkAction = dynamic_cast<KBookmarkActionInterface *>(destAction); + QWidget *widgetAction = 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 ((event->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2)) + { + root.moveBookmark(bookmark, destBookmark); + } + else + { + root.moveBookmark(bookmark, destBookmark.parentGroup().previous(destBookmark)); + } + + Application::bookmarkProvider()->bookmarkManager()->emitChanged(); + event->accept(); + } + } + + KToolBar::dropEvent(event); +} + + +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..cf7b62cc --- /dev/null +++ b/src/bookmarks/bookmarkstoolbar.h @@ -0,0 +1,120 @@ +/* ============================================================ +* +* 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 + +// Local Includes + + +// Qt Includes + + +// KDE Includes +#include <KBookmarkMenu> +#include <KToolBar> + + + +/** + * 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); + void dragEnterEvent(QDragEnterEvent *event); + void dragMoveEvent(QDragMoveEvent *event); + void dragLeaveEvent(QDragLeaveEvent *event); + void dropEvent(QDropEvent *event); + void actionEvent(QActionEvent *event); + +private slots: + void actionHovered(); + void menuDisplayed(); + void menuHidden(); + void hideMenu(); + void dragDestroyed(); + +private: + void startDrag(); + + bool m_filled; + KMenu *m_currentMenu; + QPoint m_startDragPos; + QAction *m_dragAction; + QAction *m_dropAction; +}; + +#endif // BOOKMARKSTOOLBAR_H diff --git a/src/data/rekonq.desktop b/src/data/rekonq.desktop index f8a78960..7c45af77 100644 --- a/src/data/rekonq.desktop +++ b/src/data/rekonq.desktop @@ -37,6 +37,7 @@ GenericName[fr]=Navigateur web GenericName[it]=Browser Web GenericName[pt]=Navegador Web GenericName[pt_BR]=Navegador Web +GenericName[ru]=Веб-браузер GenericName[sr]=Веб прегледач GenericName[sr@ijekavian]=Веб прегледач GenericName[sr@ijekavianlatin]=Veb pregledač diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 73779627..1479e477 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -38,6 +38,7 @@ #include "settingsdialog.h" #include "historymanager.h" #include "bookmarksmanager.h" +#include "bookmarkstoolbar.h" #include "webtab.h" #include "mainview.h" #include "findbar.h" @@ -139,16 +140,16 @@ MainWindow::MainWindow() // setting up rekonq toolbar(s) setupToolbars(); - // a call to KXmlGuiWindow::setupGUI() populates the GUI - // with actions, using KXMLGUI. - // It also applies the saved mainwindow settings, if any, and ask the - // mainwindow to automatically save settings if changed: window size, - // toolbar position, icon size, etc. + // a call to KXmlGuiWindow::setupGUI() populates the GUI + // with actions, using KXMLGUI. + // It also applies the saved mainwindow settings, if any, and ask the + // mainwindow to automatically save settings if changed: window size, + // toolbar position, icon size, etc. setupGUI(); - + // no menu bar in rekonq: we have other plans.. menuBar()->setVisible(false); - + // no more status bar.. setStatusBar(0); @@ -164,7 +165,7 @@ MainWindow::~MainWindow() Application::bookmarkProvider()->removeToolBar(m_bookmarksBar); Application::bookmarkProvider()->removeBookmarkPanel(m_bookmarksPanel); Application::instance()->removeMainWindow(this); - + delete m_view; delete m_findBar; delete m_zoomBar; @@ -187,7 +188,7 @@ MainWindow::~MainWindow() void MainWindow::setupToolbars() { kDebug() << "setup toolbars..."; - + KAction *a; // location bar @@ -212,7 +213,7 @@ void MainWindow::setupToolbars() void MainWindow::postLaunch() { setupBookmarksAndToolsShortcuts(); - + // setting popup notification m_popup->setAutoDelete(false); connect(Application::instance(), SIGNAL(focusChanged(QWidget*, QWidget*)), m_popup, SLOT(hide())); @@ -246,7 +247,7 @@ void MainWindow::postLaunch() connect(m_view, SIGNAL(currentChanged(int)), m_zoomBar, SLOT(updateSlider(int))); // Ctrl + wheel handling connect(this->currentTab()->view(), SIGNAL(zoomChanged(int)), m_zoomBar, SLOT(setValue(int))); - + // setting up toolbars to NOT have context menu enabled setContextMenuPolicy(Qt::DefaultContextMenu); @@ -266,7 +267,7 @@ QSize MainWindow::sizeHint() const void MainWindow::setupActions() { kDebug() << "setup actions..."; - + // this let shortcuts work.. actionCollection()->addAssociatedWidget(this); @@ -377,7 +378,7 @@ void MainWindow::setupActions() a->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() : KStandardShortcut::tabPrev()); actionCollection()->addAction(QL1S("show_prev_tab"), a); connect(a, SIGNAL(triggered(bool)), m_view, SLOT(previousTab())); - + a = new KAction(KIcon("tab-new"), i18n("Open Closed Tabs"), this); a->setShortcut(KShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_T)); actionCollection()->addAction(QL1S("open_closed_tabs"), a); @@ -443,7 +444,7 @@ void MainWindow::setupTools() toolsMenu->setDelayed(false); toolsMenu->setShortcutConfigurable(true); toolsMenu->setShortcut( KShortcut(Qt::ALT + Qt::Key_T) ); - + toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Open))); toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::SaveAs))); toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Print))); @@ -535,7 +536,7 @@ void MainWindow::setupPanels() addDockWidget(Qt::BottomDockWidgetArea, m_webInspectorPanel); m_webInspectorPanel->hide(); - + // STEP 4 // Setup Network analyzer panel m_analyzerPanel = new NetworkAnalyzerPanel( i18n("Network Analyzer"), this); @@ -572,7 +573,7 @@ void MainWindow::fileSaveAs() srcUrl = w->url(); } kDebug() << "URL to save: " << srcUrl; - + QString name = srcUrl.fileName(); if (name.isNull()) { @@ -609,7 +610,7 @@ void MainWindow::updateActions() { kDebug() << "updating actions.."; bool rekonqPage = currentTab()->page()->isOnRekonqPage(); - + QAction *historyBackAction = actionByName(KStandardAction::name(KStandardAction::Back)); if( rekonqPage && currentTab()->view()->history()->count() > 0 ) historyBackAction->setEnabled(true); @@ -825,7 +826,7 @@ void MainWindow::setWidgetsVisible(bool makeVisible) KToolBar *mainBar = toolBar("mainToolBar"); KToolBar *bookBar = toolBar("bookmarksToolBar"); - + if (!makeVisible) { // save current state, if in windowed mode @@ -873,10 +874,10 @@ void MainWindow::viewPageSource() void MainWindow::homePage(Qt::MouseButtons mouseButtons, Qt::KeyboardModifiers keyboardModifiers) { - KUrl homeUrl = ReKonfig::useNewTabPage() + KUrl homeUrl = ReKonfig::useNewTabPage() ? KUrl( QL1S("about:home") ) : KUrl( ReKonfig::homePage() ); - + if (mouseButtons == Qt::MidButton || keyboardModifiers == Qt::ControlModifier) Application::instance()->loadUrl( homeUrl, Rekonq::NewTab); else @@ -918,7 +919,7 @@ void MainWindow::openPrevious(Qt::MouseButtons mouseButtons, Qt::KeyboardModifie { QWebHistory *history = currentTab()->view()->history(); QWebHistoryItem *item = 0; - + if (currentTab()->page()->isOnRekonqPage()) { item = new QWebHistoryItem(history->currentItem()); @@ -934,7 +935,7 @@ void MainWindow::openPrevious(Qt::MouseButtons mouseButtons, Qt::KeyboardModifie if(!item) return; - + if (mouseButtons == Qt::MidButton || keyboardModifiers == Qt::ControlModifier) { Application::instance()->loadUrl(item->url(), Rekonq::NewTab); @@ -965,10 +966,10 @@ void MainWindow::openNext(Qt::MouseButtons mouseButtons, Qt::KeyboardModifiers k item = new QWebHistoryItem(history->forwardItem()); } } - + if(!item) return; - + if (mouseButtons == Qt::MidButton || keyboardModifiers == Qt::ControlModifier) { Application::instance()->loadUrl(item->url(), Rekonq::NewTab); @@ -977,7 +978,7 @@ void MainWindow::openNext(Qt::MouseButtons mouseButtons, Qt::KeyboardModifiers k { history->goToItem(*item); } - + updateActions(); } @@ -1169,7 +1170,7 @@ void MainWindow::aboutToShowBackMenu() offset = pivot - 8; /* - * Need a bug report upstream. + * Need a bug report upstream. * Seems setHtml() do some garbage in history * Here history->currentItem() have backItem url and currentItem (error page) title */ @@ -1183,7 +1184,7 @@ void MainWindow::aboutToShowBackMenu() action->setText(item.title()); m_historyBackMenu->addAction(action); } - + for (int i = listCount - 1; i >= 0; --i) { QWebHistoryItem item = historyList.at(i); @@ -1224,7 +1225,7 @@ void MainWindow::setEncoding(QAction *qa) currentTab()->view()->reload(); return; } - + currentTab()->view()->settings()->setDefaultTextEncoding(currentCodec); currentTab()->view()->reload(); } @@ -1234,7 +1235,7 @@ void MainWindow::populateEncodingMenu() { QStringList codecs; QList<int> mibs = QTextCodec::availableMibs(); - Q_FOREACH (const int &mib, mibs) + Q_FOREACH (const int &mib, mibs) { QString codec = QLatin1String(QTextCodec::codecForMib(mib)->name()); codecs.append(codec); @@ -1249,13 +1250,13 @@ void MainWindow::populateEncodingMenu() KMenu *isciiMenu = new KMenu( QL1S("ISCII"), m_encodingMenu); KMenu *uniMenu = new KMenu( QL1S("Unicode"), m_encodingMenu); KMenu *otherMenu = new KMenu( i18n("Other"), m_encodingMenu); - + QAction *a; bool isDefaultCodecUsed = true; - + Q_FOREACH(const QString &codec, codecs) { - + if( codec.startsWith( QL1S("ISO"), Qt::CaseInsensitive ) ) a = isoMenu->addAction(codec); else if( codec.startsWith( QL1S("win") ) ) @@ -1264,9 +1265,9 @@ void MainWindow::populateEncodingMenu() a = isciiMenu->addAction(codec); else if( codec.startsWith( QL1S("UT") ) ) a = uniMenu->addAction(codec); - else + else a = otherMenu->addAction(codec); - + a->setCheckable(true); if (currentCodec == codec) { @@ -1274,11 +1275,11 @@ void MainWindow::populateEncodingMenu() isDefaultCodecUsed = false; } } - + a = new QAction( i18nc("Default website encoding", "Default"), this); a->setCheckable(true); a->setChecked(isDefaultCodecUsed); - + m_encodingMenu->addAction( a ); m_encodingMenu->addMenu( isoMenu ); m_encodingMenu->addMenu( winMenu ); @@ -1300,36 +1301,36 @@ bool MainWindow::queryClose() // this should fux bug 240432 if(Application::instance()->sessionSaving()) return true; - - if (m_view->count() > 1) + + if (m_view->count() > 1) { - int answer = KMessageBox::questionYesNoCancel( - this, + int answer = KMessageBox::questionYesNoCancel( + this, i18np("Are you sure you want to close the window?\n" "You have 1 tab open.", - "Are you sure you want to close the window?\n" "You have %1 tabs open.", + "Are you sure you want to close the window?\n" "You have %1 tabs open.", m_view->count()), - i18n("Are you sure you want to close the window?"), - KStandardGuiItem::quit(), - KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")), - KStandardGuiItem::cancel(), - "confirmClosingMultipleTabs" - ); - - switch (answer) - { - case KMessageBox::Yes: - // Quit - return true; - - case KMessageBox::No: - // Close only the current tab + i18n("Are you sure you want to close the window?"), + KStandardGuiItem::quit(), + KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")), + KStandardGuiItem::cancel(), + "confirmClosingMultipleTabs" + ); + + switch (answer) + { + case KMessageBox::Yes: + // Quit + return true; + + case KMessageBox::No: + // Close only the current tab m_view->closeTab(); - - default: - return false; - } - } - return true; + + default: + return false; + } + } + return true; } @@ -1343,16 +1344,16 @@ void MainWindow::saveNewToolbarConfig() void MainWindow::setupBookmarksAndToolsShortcuts() { KToolBar *mainBar = toolBar("mainToolBar"); - + QToolButton *bookmarksButton = qobject_cast<QToolButton*>(mainBar->widgetForAction(actionByName( QL1S("bookmarksActionMenu") ))); if(bookmarksButton) { connect(actionByName(QL1S("bookmarksActionMenu")), SIGNAL(triggered()), bookmarksButton, SLOT(showMenu())); } - + QToolButton *toolsButton = qobject_cast<QToolButton*>(mainBar->widgetForAction(actionByName( QL1S("rekonq_tools") ))); if(toolsButton) { connect(actionByName(QL1S("rekonq_tools")), SIGNAL(triggered()), toolsButton, SLOT(showMenu())); - } + } } diff --git a/src/urlbar/bookmarkwidget.cpp b/src/urlbar/bookmarkwidget.cpp index ccfe4914..5a2e6434 100644 --- a/src/urlbar/bookmarkwidget.cpp +++ b/src/urlbar/bookmarkwidget.cpp @@ -31,6 +31,7 @@ // Local includes #include "application.h" #include "bookmarksmanager.h" +#include "bookmarkowner.h" // KDE Includes #include <KLocalizedString> @@ -57,12 +58,12 @@ BookmarkWidget::BookmarkWidget(const KBookmark &bookmark, QWidget *parent) setLayout(layout); QHBoxLayout *hLayout = new QHBoxLayout(); - + QLabel *bookmarkIcon = new QLabel(this); bookmarkIcon->setPixmap(KIcon("bookmarks").pixmap(32, 32)); hLayout->addWidget(bookmarkIcon); hLayout->setSpacing(10); - + QVBoxLayout *vLayout = new QVBoxLayout(); QLabel *bookmarkInfo = new QLabel(this); @@ -70,13 +71,13 @@ BookmarkWidget::BookmarkWidget(const KBookmark &bookmark, QWidget *parent) QFont font; font.setPointSize(font.pointSize() + 2); bookmarkInfo->setFont(font); - + vLayout->addWidget(bookmarkInfo); QPushButton *removeButton = new QPushButton(this); removeButton->setText(i18n("Remove this Bookmark")); connect(removeButton, SIGNAL(clicked()), this, SLOT(removeBookmark())); - + vLayout->addWidget(removeButton); hLayout->addLayout(vLayout); layout->addItem(hLayout); @@ -152,6 +153,7 @@ void BookmarkWidget::showAt(const QPoint &pos) void BookmarkWidget::removeBookmark() { - Application::bookmarkProvider()->bookmarkOwner()->deleteBookmark(m_bookmark); + Application::bookmarkProvider()->bookmarkOwner()->bookmarkSelected(m_bookmark); + Application::bookmarkProvider()->bookmarkOwner()->deleteBookmark(); reject(); } |