X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/7fec7ff9a096d288b66fce2699c7b8bc71f6fbbb..4eec2a77cfa8719f0cf7f6741c8cfa11b23ebf5b:/src/bookmarkssidebarpage.cpp diff --git a/src/bookmarkssidebarpage.cpp b/src/bookmarkssidebarpage.cpp index b3861aa2f..bf7711aaf 100644 --- a/src/bookmarkssidebarpage.cpp +++ b/src/bookmarkssidebarpage.cpp @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "bookmarkssidebarpage.h" @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -36,8 +36,6 @@ #include #include "dolphinsettings.h" -#include "dolphin.h" -#include "dolphinview.h" #include "editbookmarkdialog.h" BookmarksSidebarPage::BookmarksSidebarPage(QWidget* parent) : @@ -45,7 +43,7 @@ BookmarksSidebarPage::BookmarksSidebarPage(QWidget* parent) : { Q3VBoxLayout* layout = new Q3VBoxLayout(this); m_bookmarksList = new BookmarksListBox(this); - m_bookmarksList->setPaletteBackgroundColor(colorGroup().background()); + m_bookmarksList->setPaletteBackgroundColor(palette().brush(QPalette::Background).color()); layout->addWidget(m_bookmarksList); connect(m_bookmarksList, SIGNAL(mouseButtonClicked(int, Q3ListBoxItem*, const QPoint&)), @@ -64,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() @@ -86,8 +87,6 @@ void BookmarksSidebarPage::updateBookmarks() bookmark = root.next(bookmark); } - - connectToActiveView(); } void BookmarksSidebarPage::slotMouseButtonClicked(int button, Q3ListBoxItem* item) @@ -98,7 +97,7 @@ void BookmarksSidebarPage::slotMouseButtonClicked(int button, Q3ListBoxItem* ite const int index = m_bookmarksList->index(item); KBookmark bookmark = DolphinSettings::instance().bookmark(index); - Dolphin::mainWin().activeView()->setUrl(bookmark.url()); + emit changeUrl(bookmark.url()); } void BookmarksSidebarPage::slotContextMenuRequested(Q3ListBoxItem* item, @@ -109,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", @@ -183,70 +188,33 @@ void BookmarksSidebarPage::slotContextMenuRequested(Q3ListBoxItem* item, default: break; } - + } delete popup; popup = 0; - - DolphinView* view = Dolphin::mainWin().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 = Dolphin::mainWin().activeView(); - adjustSelection(view->url()); - connect(view, SIGNAL(signalUrlChanged(const KUrl&)), - this, SLOT(slotUrlChanged(const KUrl&))); -} - BookmarksListBox::BookmarksListBox(QWidget* parent) : Q3ListBox(parent) {