X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/3bd97ea34c72164a2c583ec28eafcdfc887455cf..4eec2a77cfa8719f0cf7f6741c8cfa11b23ebf5b:/src/bookmarkssidebarpage.cpp diff --git a/src/bookmarkssidebarpage.cpp b/src/bookmarkssidebarpage.cpp index 3fb031edc..bf7711aaf 100644 --- a/src/bookmarkssidebarpage.cpp +++ b/src/bookmarkssidebarpage.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -36,11 +36,10 @@ #include #include "dolphinsettings.h" -#include "dolphinmainwindow.h" #include "editbookmarkdialog.h" -BookmarksSidebarPage::BookmarksSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) : - SidebarPage(mainWindow, parent) +BookmarksSidebarPage::BookmarksSidebarPage(QWidget* parent) : + SidebarPage(parent) { Q3VBoxLayout* layout = new Q3VBoxLayout(this); m_bookmarksList = new BookmarksListBox(this); @@ -63,9 +62,12 @@ BookmarksSidebarPage::~BookmarksSidebarPage() { } -void BookmarksSidebarPage::activeViewChanged() +void BookmarksSidebarPage::setUrl(const KUrl& url) { - connectToActiveView(); + if (!m_url.equals(url, KUrl::CompareWithoutTrailingSlash)) { + m_url = url; + adjustSelection(m_url); + } } void BookmarksSidebarPage::updateBookmarks() @@ -85,8 +87,6 @@ void BookmarksSidebarPage::updateBookmarks() bookmark = root.next(bookmark); } - - connectToActiveView(); } void BookmarksSidebarPage::slotMouseButtonClicked(int button, Q3ListBoxItem* item) @@ -97,7 +97,7 @@ void BookmarksSidebarPage::slotMouseButtonClicked(int button, Q3ListBoxItem* ite const int index = m_bookmarksList->index(item); KBookmark bookmark = DolphinSettings::instance().bookmark(index); - mainWindow()->activeView()->setUrl(bookmark.url()); + emit changeUrl(bookmark.url()); } void BookmarksSidebarPage::slotContextMenuRequested(Q3ListBoxItem* item, @@ -108,22 +108,28 @@ void BookmarksSidebarPage::slotContextMenuRequested(Q3ListBoxItem* item, const int deleteID = 3; const int addID = 4; - Q3PopupMenu* popup = new Q3PopupMenu(); + KMenu* popup = new KMenu(); if (item == 0) { - popup->insertItem(SmallIcon("filenew"), i18n("Add Bookmark..."), addID); + QAction *action = popup->addAction(KIcon("document-new"), i18n("Add Bookmark...")); + action->setData(addID); } else { - popup->insertItem(SmallIcon("filenew"), i18n("Insert Bookmark..."), insertID); - popup->insertItem(SmallIcon("edit"), i18n("Edit..."), editID); - popup->insertItem(SmallIcon("editdelete"), i18n("Delete"), deleteID); + QAction *action = popup->addAction(KIcon("document-new"), i18n("Insert Bookmark...")); + action->setData(insertID); + action = popup->addAction(KIcon("edit"), i18n("Edit...")); + action->setData(editID); + action = popup->addAction(KIcon("edit-delete"), i18n("Delete")); + action->setData(deleteID); + } KBookmarkManager* manager = DolphinSettings::instance().bookmarkManager(); KBookmarkGroup root = manager->root(); const int index = m_bookmarksList->index(m_bookmarksList->selectedItem()); - - const int result = popup->exec(pos); - switch (result) { + QAction *result = popup->exec(pos); + if( result) + { + switch(result->data().toInt()) { case insertID: { KBookmark newBookmark = EditBookmarkDialog::getBookmark(i18n("Insert Bookmark"), "New bookmark", @@ -182,70 +188,33 @@ void BookmarksSidebarPage::slotContextMenuRequested(Q3ListBoxItem* item, default: break; } - + } delete popup; popup = 0; - - DolphinView* view = mainWindow()->activeView(); - adjustSelection(view->url()); } void BookmarksSidebarPage::adjustSelection(const KUrl& url) { - // TODO (remarked in dolphin/TODO): the following code is quite equal - // to BookmarkSelector::updateSelection(). - KBookmarkGroup root = DolphinSettings::instance().bookmarkManager()->root(); - KBookmark bookmark = root.first(); - - int maxLength = 0; - int selectedIndex = -1; - - // Search the bookmark which is equal to the Url or at least is a parent Url. - // If there are more than one possible parent Url candidates, choose the bookmark - // which covers the bigger range of the Url. - int i = 0; - while (!bookmark.isNull()) { - const KUrl bookmarkUrl = bookmark.url(); - if (bookmarkUrl.isParentOf(url)) { - const int length = bookmarkUrl.prettyUrl().length(); - if (length > maxLength) { - selectedIndex = i; - maxLength = length; - } - } - bookmark = root.next(bookmark); - ++i; - } + KBookmark bookmark = root.closestBookmark(url); const bool block = m_bookmarksList->signalsBlocked(); m_bookmarksList->blockSignals(true); - if (selectedIndex < 0) { + if (bookmark.isNull()) { // no bookmark matches, hence deactivate any selection const int currentIndex = m_bookmarksList->index(m_bookmarksList->selectedItem()); m_bookmarksList->setSelected(currentIndex, false); } else { // select the bookmark which is part of the current Url + // TODO when porting to QListWidget, use the address as item data? + int selectedIndex = bookmark.address().mid(1).toInt(); // convert "/5" to 5. m_bookmarksList->setSelected(selectedIndex, true); } m_bookmarksList->blockSignals(block); } -void BookmarksSidebarPage::slotUrlChanged(const KUrl& url) -{ - adjustSelection(url); -} - -void BookmarksSidebarPage::connectToActiveView() -{ - DolphinView* view = mainWindow()->activeView(); - adjustSelection(view->url()); - connect(view, SIGNAL(urlChanged(const KUrl&)), - this, SLOT(slotUrlChanged(const KUrl&))); -} - BookmarksListBox::BookmarksListBox(QWidget* parent) : Q3ListBox(parent) {