diff options
author | Jon Ander Peñalba <jonan88@gmail.com> | 2010-08-17 21:44:27 +0200 |
---|---|---|
committer | Jon Ander Peñalba <jonan88@gmail.com> | 2010-08-19 12:53:51 +0200 |
commit | 3aa717e2c5e91f50648740e6c11e0657d77976fc (patch) | |
tree | eb3e1a7ad649ec8e22e44d80c22a4566ccc83e51 | |
parent | Merge branch 'master' of gitorious.org:rekonq/mainline (diff) | |
download | rekonq-3aa717e2c5e91f50648740e6c11e0657d77976fc.tar.xz |
All insertion and deletion of bookmarks code moved to the same place (BookmarkOwner)
-rw-r--r-- | src/bookmarks/bookmarkscontextmenu.cpp | 89 | ||||
-rw-r--r-- | src/bookmarks/bookmarkscontextmenu.h | 7 | ||||
-rw-r--r-- | src/bookmarks/bookmarksmanager.cpp | 100 | ||||
-rw-r--r-- | src/bookmarks/bookmarksmanager.h | 22 |
4 files changed, 132 insertions, 86 deletions
diff --git a/src/bookmarks/bookmarkscontextmenu.cpp b/src/bookmarks/bookmarkscontextmenu.cpp index c448d293..eaf4a9d9 100644 --- a/src/bookmarks/bookmarkscontextmenu.cpp +++ b/src/bookmarks/bookmarkscontextmenu.cpp @@ -26,16 +26,12 @@ // Self Includes #include "bookmarkscontextmenu.h" -#include "bookmarkscontextmenu.moc" // Local Includes -#include "application.h" #include "bookmarksmanager.h" // KDE Includes -#include <KMessageBox> #include <KActionCollection> -#include <KBookmarkDialog> // Qt Includes #include <QClipboard> @@ -218,12 +214,8 @@ void BookmarksContextMenu::deleteBookmark() void BookmarksContextMenu::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; + KBookmark bm = bookmark(); + Application::bookmarkProvider()->bookmarkOwner()->editBookmark(bm); } @@ -236,86 +228,21 @@ void BookmarksContextMenu::openFolderInTabs() void BookmarksContextMenu::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; + KBookmark bm = bookmark(); + Application::bookmarkProvider()->bookmarkOwner()->newBookmarkFolder(bm); } void BookmarksContextMenu::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()); + KBookmark bm = bookmark(); + Application::bookmarkProvider()->bookmarkOwner()->newSeparator(bm); } void BookmarksContextMenu::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); + KBookmark bm = bookmark(); + Application::bookmarkProvider()->bookmarkOwner()->bookmarkPage(bm); } diff --git a/src/bookmarks/bookmarkscontextmenu.h b/src/bookmarks/bookmarkscontextmenu.h index 2ef8e5a7..c32c5962 100644 --- a/src/bookmarks/bookmarkscontextmenu.h +++ b/src/bookmarks/bookmarkscontextmenu.h @@ -27,10 +27,7 @@ #ifndef BOOKMARKCONTEXTMENU_H #define BOOKMARKCONTEXTMENU_H -// Local Includes -#include "application.h" - -// Qt Includes +// KDE Includes #include <KBookmarkMenu> @@ -41,7 +38,7 @@ class BookmarksContextMenu : public KBookmarkContextMenu public: BookmarksContextMenu(const KBookmark & bk, KBookmarkManager * manager, KBookmarkOwner *owner, QWidget * parent = 0); ~BookmarksContextMenu(); - + virtual void addActions(); private slots: diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp index 221a6db1..d50e9e77 100644 --- a/src/bookmarks/bookmarksmanager.cpp +++ b/src/bookmarks/bookmarksmanager.cpp @@ -41,6 +41,7 @@ // KDE Includes #include <KActionCollection> #include <KBookmarkAction> +#include <KBookmarkDialog> #include <KBookmarkGroup> #include <KToolBar> #include <KMenu> @@ -75,6 +76,105 @@ void BookmarkOwner::openBookmark(const KBookmark & bookmark, } +void BookmarkOwner::bookmarkPage(KBookmark &position) +{ + BookmarkOwner *owner = Application::bookmarkProvider()->bookmarkOwner(); + KBookmarkGroup parent = Application::bookmarkProvider()->rootGroup(); + + if (!position.isNull()) + { + parent = position.parentGroup(); + + if (position.isGroup()) + parent = position.toGroup(); + + KBookmark newBk = parent.addBookmark(owner->currentTitle().replace('&', "&&"), KUrl(owner->currentUrl())); + parent.moveBookmark(newBk, position.parentGroup().previous(position)); + } + + else + { + parent.addBookmark(owner->currentTitle(), KUrl(owner->currentUrl())); + } + + Application::bookmarkProvider()->bookmarkManager()->emitChanged(parent); +} + + +void BookmarkOwner::newBookmarkFolder(KBookmark &position) +{ + BookmarkOwner *owner = Application::bookmarkProvider()->bookmarkOwner(); + KBookmarkManager *manager = Application::bookmarkProvider()->bookmarkManager(); + + KBookmarkDialog *dialog = owner->bookmarkDialog(manager, QApplication::activeWindow()); + + if (!position.isNull()) + { + if (position.isGroup()) + { + dialog->createNewFolder("New folder", position); + } + + else + { + KBookmark newBk; + newBk = dialog->createNewFolder("New folder", position.parentGroup()); + if (!newBk.isNull()) + { + position.parentGroup().moveBookmark(newBk, position); + manager->emitChanged(newBk.parentGroup()); + } + } + } + else + { + dialog->createNewFolder("New folder"); + } + + delete dialog; +} + + +void BookmarkOwner::newSeparator(KBookmark &position) +{ + KBookmark newBk; + + if (!position.isNull()) + { + if (position.isGroup()) + newBk = position.toGroup().createNewSeparator(); + else + newBk = position.parentGroup().createNewSeparator(); + } + + else + { + newBk = Application::bookmarkProvider()->rootGroup().createNewSeparator(); + } + + KBookmarkGroup parent = newBk.parentGroup(); + newBk.setIcon(("edit-clear")); + parent.addBookmark(newBk); + + if (!position.isNull()) + parent.moveBookmark(newBk, position); + + Application::bookmarkProvider()->bookmarkManager()->emitChanged(newBk.parentGroup()); +} + + +void BookmarkOwner::editBookmark(KBookmark &bookmark) +{ + BookmarkOwner *owner = Application::bookmarkProvider()->bookmarkOwner(); + KBookmarkManager *manager = Application::bookmarkProvider()->bookmarkManager(); + bookmark.setFullText(bookmark.fullText().replace("&&", "&")); + KBookmarkDialog *dialog = owner->bookmarkDialog(manager, QApplication::activeWindow()); + dialog->editBookmark(bookmark); + bookmark.setFullText(bookmark.fullText().replace('&', "&&")); + delete dialog; +} + + bool BookmarkOwner::deleteBookmark(KBookmark &bookmark) { QString name = QString(bookmark.fullText()).replace("&&", "&"); diff --git a/src/bookmarks/bookmarksmanager.h b/src/bookmarks/bookmarksmanager.h index 6f97e4ef..19bfe5d2 100644 --- a/src/bookmarks/bookmarksmanager.h +++ b/src/bookmarks/bookmarksmanager.h @@ -90,6 +90,28 @@ public: Qt::MouseButtons mouseButtons, Qt::KeyboardModifiers keyboardModifiers); + + /** + * Bookmarks the current page. + * @param position Where to insert the bookmark. + */ + static void bookmarkPage(KBookmark &position); + /** + * Creates a new bookmark folder. + * @param position Where to insert the folder. + */ + static void newBookmarkFolder(KBookmark &position); + /** + * Creates a new separator. + * @param position Where to insert the separator. + */ + static void newSeparator(KBookmark &position); + + /** + * Opens the edit dialog for a bookmark. + * @param bookmark The bookmark to edit. + */ + static void editBookmark(KBookmark &bookmark); /** * Promps the user to delete a bookmark. * @param bookmark The bookmark to delete. |