diff options
Diffstat (limited to 'src/bookmarks')
-rw-r--r-- | src/bookmarks/bookmarkcontextmenu.cpp | 27 | ||||
-rw-r--r-- | src/bookmarks/bookmarksmanager.cpp | 97 | ||||
-rw-r--r-- | src/bookmarks/bookmarksmanager.h | 22 | ||||
-rw-r--r-- | src/bookmarks/bookmarkspanel.cpp | 29 | ||||
-rw-r--r-- | src/bookmarks/bookmarksproxy.cpp | 11 | ||||
-rw-r--r-- | src/bookmarks/bookmarksproxy.h | 12 | ||||
-rw-r--r-- | src/bookmarks/bookmarkstreemodel.cpp | 12 |
7 files changed, 136 insertions, 74 deletions
diff --git a/src/bookmarks/bookmarkcontextmenu.cpp b/src/bookmarks/bookmarkcontextmenu.cpp index 96668003..714c8b51 100644 --- a/src/bookmarks/bookmarkcontextmenu.cpp +++ b/src/bookmarks/bookmarkcontextmenu.cpp @@ -212,25 +212,7 @@ void BookmarkContextMenu::copyToClipboard() void BookmarkContextMenu::deleteBookmark() { KBookmark bm = bookmark(); - KBookmarkGroup bmg = bm.parentGroup(); - bool folder = bm.isGroup(); - QString name = QString(bm.fullText()).replace("&&", "&"); - - if (KMessageBox::warningContinueCancel( - QApplication::activeWindow(), - folder ? i18n("Are you sure you wish to remove the bookmark folder\n\"%1\"?", name) - : i18n("Are you sure you wish to remove the bookmark\n\"%1\"?", name), - folder ? i18n("Bookmark Folder Deletion") - : i18n("Bookmark Deletion"), - KStandardGuiItem::del(), - KStandardGuiItem::cancel(), - "bookmarkDeletition_askAgain") - != KMessageBox::Continue - ) - return; - - bmg.deleteBookmark(bm); - manager()->emitChanged(bmg); + Application::bookmarkProvider()->bookmarkOwner()->deleteBookmark(bm); } @@ -268,8 +250,11 @@ void BookmarkContextMenu::newBookmarkGroup() { KBookmark newBk; newBk = dialog->createNewFolder("New folder", selected.parentGroup()); - selected.parentGroup().moveBookmark(newBk, selected); - manager()->emitChanged(newBk.parentGroup()); + if (!newBk.isNull()) + { + selected.parentGroup().moveBookmark(newBk, selected); + manager()->emitChanged(newBk.parentGroup()); + } } } else diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp index 792baaeb..cade77b4 100644 --- a/src/bookmarks/bookmarksmanager.cpp +++ b/src/bookmarks/bookmarksmanager.cpp @@ -75,6 +75,45 @@ void BookmarkOwner::openBookmark(const KBookmark & bookmark, } +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; @@ -99,16 +138,16 @@ void BookmarkOwner::openFolderinTabs(const KBookmarkGroup &bookmark) if (urlList.length() > 8) { - if ( !(KMessageBox::warningContinueCancel( Application::instance()->mainWindow(), + 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?", + "You are about to open %1 tabs.\nAre you sure?", urlList.length()), "", KStandardGuiItem::cont(), KStandardGuiItem::cancel(), "openFolderInTabs_askAgain" - ) == KMessageBox::Continue) + ) == KMessageBox::Continue) ) return; } @@ -335,7 +374,7 @@ void BookmarkToolBar::actionHovered() // ------------------------------------------------------------------------------------------------------ - + BookmarkProvider::BookmarkProvider(QObject *parent) : QObject(parent) , m_manager(0) @@ -388,13 +427,15 @@ BookmarkProvider::~BookmarkProvider() void BookmarkProvider::setupBookmarkBar(BookmarkToolBar *toolbar) { + if (m_bookmarkToolBars.contains(toolbar)) + return; + kDebug() << "new bookmark bar..."; - + m_bookmarkToolBars.append(toolbar); toolbar->setContextMenuPolicy(Qt::CustomContextMenu); connect(toolbar, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenu(const QPoint &))); - - slotBookmarksChanged("", ""); + kDebug() << "new bookmark bar... DONE!"; } @@ -451,7 +492,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); @@ -522,7 +563,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); @@ -591,3 +632,41 @@ void BookmarkProvider::slotPanelChanged() panel->startLoadFoldedState(); } } + + +KBookmark BookmarkProvider::bookmarkForUrl(const KUrl &url) +{ + KBookmark found; + + KBookmarkGroup root = rootGroup(); + if (root.isNull()) + { + return found; + } + + return bookmarkForUrl(root, url); +} + + +KBookmark BookmarkProvider::bookmarkForUrl(const KBookmark &bookmark, const KUrl &url) +{ + KBookmark found; + + if (bookmark.isGroup()) + { + KBookmarkGroup group = bookmark.toGroup(); + KBookmark bookmark = group.first(); + + while (!bookmark.isNull() && found.isNull()) + { + found = bookmarkForUrl(bookmark, url); + bookmark = group.next(bookmark); + } + } + else if (!bookmark.isSeparator() && bookmark.url() == url) + { + found = bookmark; + } + + return found; +} diff --git a/src/bookmarks/bookmarksmanager.h b/src/bookmarks/bookmarksmanager.h index 72ea1c3c..b084b8ee 100644 --- a/src/bookmarks/bookmarksmanager.h +++ b/src/bookmarks/bookmarksmanager.h @@ -89,6 +89,13 @@ public: 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 @@ -206,7 +213,7 @@ private: // ------------------------------------------------------------------------------ - + /** * This class represent the interface to rekonq bookmarks system. * All rekonq needs (Bookmarks Menu, Bookmarks Toolbar) is provided @@ -263,7 +270,7 @@ public: KBookmarkGroup rootGroup(); inline KBookmarkManager *bookmarkManager() { return m_manager; } - + inline BookmarkOwner *bookmarkOwner() { return m_owner; } QList<KBookmark> find(QString text); @@ -271,6 +278,8 @@ public: void registerBookmarkPanel(BookmarksPanel *panel); void removeBookmarkPanel(BookmarksPanel *panel); + KBookmark bookmarkForUrl(const KUrl &url); + signals: /** * @short This signal is emitted when an url has to be loaded @@ -297,20 +306,23 @@ public slots: */ void slotBookmarksChanged(const QString &group, const QString &caller); void fillBookmarkBar(BookmarkToolBar *toolBar); - + private slots: void slotAddBookmark(); void slotPanelChanged(); - + private: QList<KBookmark> find(QList<KBookmark> list, const KBookmark &bookmark, QString text); + QString titleForBookmarkUrl(const KBookmark &bookmark, const QString &url); + KBookmark bookmarkForUrl(const KBookmark &bookmark, const KUrl &url); + KBookmarkManager *m_manager; BookmarkOwner *m_owner; KActionCollection *m_actionCollection; QList<BookmarkToolBar *> m_bookmarkToolBars; QList<BookmarksPanel*> m_bookmarkPanels; - + KActionMenu *_bookmarkActionMenu; }; diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp index 75d8faf3..b49d4f5e 100644 --- a/src/bookmarks/bookmarkspanel.cpp +++ b/src/bookmarks/bookmarkspanel.cpp @@ -201,12 +201,12 @@ void BookmarksPanel::contextMenu(const QPoint &pos) KBookmark selected = bookmarkForIndex(index); - BookmarkContextMenu menu( selected, - Application::bookmarkProvider()->bookmarkManager(), - Application::bookmarkProvider()->bookmarkOwner(), + BookmarkContextMenu menu( selected, + Application::bookmarkProvider()->bookmarkManager(), + Application::bookmarkProvider()->bookmarkOwner(), this ); - + menu.exec(m_treeView->mapToGlobal(pos)); } @@ -218,24 +218,5 @@ void BookmarksPanel::deleteBookmark() return; KBookmark bm = bookmarkForIndex(index); - KBookmarkGroup bmg = bm.parentGroup(); - bool folder = bm.isGroup(); - QString name = QString(bm.fullText()).replace("&&", "&"); - - if (KMessageBox::warningContinueCancel( - QApplication::activeWindow(), - folder ? i18n("Are you sure you wish to remove the bookmark folder\n\"%1\"?", name) - : i18n("Are you sure you wish to remove the bookmark\n\"%1\"?", name), - folder ? i18n("Bookmark Folder Deletion") - : i18n("Bookmark Deletion"), - KStandardGuiItem::del(), - KStandardGuiItem::cancel(), - "bookmarkDeletition_askAgain") - != KMessageBox::Continue - ) - return; - - - bmg.deleteBookmark(bm); - Application::instance()->bookmarkProvider()->bookmarkManager()->emitChanged(bmg); + Application::instance()->bookmarkProvider()->bookmarkOwner()->deleteBookmark(bm); } diff --git a/src/bookmarks/bookmarksproxy.cpp b/src/bookmarks/bookmarksproxy.cpp index 4e4b4f06..1e4da877 100644 --- a/src/bookmarks/bookmarksproxy.cpp +++ b/src/bookmarks/bookmarksproxy.cpp @@ -27,19 +27,18 @@ // Self Includes #include "bookmarksproxy.h" -#include "bookmarksproxy.moc" BookmarksProxy::BookmarksProxy(QObject *parent) : QSortFilterProxyModel(parent) { + setFilterCaseSensitivity(Qt::CaseInsensitive); } -bool BookmarksProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const +bool BookmarksProxy::filterAcceptsRow(const int source_row, const QModelIndex &source_parent) const { - QModelIndex idx = sourceModel()->index(source_row, 0, source_parent); - return recursiveMatch(idx); + return recursiveMatch( sourceModel()->index(source_row, 0, source_parent) ); } @@ -48,10 +47,12 @@ bool BookmarksProxy::recursiveMatch(const QModelIndex &index) const if (index.data().toString().contains(filterRegExp())) return true; - for (int childRow = 0; childRow < sourceModel()->rowCount(index); ++childRow) + int numChildren = sourceModel()->rowCount(index); + for (int childRow = 0; childRow < numChildren; ++childRow) { if (recursiveMatch(sourceModel()->index(childRow, 0, index))) return true; } + return false; } diff --git a/src/bookmarks/bookmarksproxy.h b/src/bookmarks/bookmarksproxy.h index e7b50d8e..b4554d2b 100644 --- a/src/bookmarks/bookmarksproxy.h +++ b/src/bookmarks/bookmarksproxy.h @@ -33,9 +33,13 @@ #include "rekonq_defines.h" // Qt Includes -#include <QSortFilterProxyModel> - +#include <QtGui/QSortFilterProxyModel> +/** + * QSortFilterProxyModel hides all children which parent doesn't + * match the filter. This class is used to change this behavior. + * If a bookmark matches the filter it'll be shown, even if it's parent doesn't match it. + */ class REKONQ_TESTS_EXPORT BookmarksProxy : public QSortFilterProxyModel { Q_OBJECT @@ -45,9 +49,9 @@ public: BookmarksProxy(QObject *parent = 0); protected: - virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; + virtual bool filterAcceptsRow(const int source_row, const QModelIndex &source_parent) const; - // returns true if any child(or children-child...) matches filter + // returns true if index or any of his children match the filter bool recursiveMatch(const QModelIndex &index) const; }; diff --git a/src/bookmarks/bookmarkstreemodel.cpp b/src/bookmarks/bookmarkstreemodel.cpp index 7063bf9b..299efaf0 100644 --- a/src/bookmarks/bookmarkstreemodel.cpp +++ b/src/bookmarks/bookmarkstreemodel.cpp @@ -406,15 +406,15 @@ bool BookmarksTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction acti if (parent.isValid()) root = bookmarkForIndex(parent).toGroup(); - if (!destIndex.isValid()) + if (destIndex.isValid() && row != -1) { - root.deleteBookmark(bookmark); - root.addBookmark(bookmark); - } + root.moveBookmark(bookmark, root.previous(dropDestBookmark)); - else if (row != 1) + } + else { - root.moveBookmark(bookmark, root.previous(dropDestBookmark)); + root.deleteBookmark(bookmark); + root.addBookmark(bookmark); } Application::bookmarkProvider()->bookmarkManager()->emitChanged(); |