]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Ported to KBookmarkManager::closestBookmark - which even solves another TODO about...
authorDavid Faure <faure@kde.org>
Mon, 26 Mar 2007 23:04:43 +0000 (23:04 +0000)
committerDavid Faure <faure@kde.org>
Mon, 26 Mar 2007 23:04:43 +0000 (23:04 +0000)
Improved urlnavigator API to avoid exposing the full QList (api independent from implementation now).

svn path=/trunk/KDE/kdebase/apps/; revision=646954

src/bookmarkselector.cpp
src/bookmarkselector.h
src/bookmarkssidebarpage.cpp
src/dolphinmainwindow.cpp
src/dolphinview.cpp
src/dolphinview.h
src/treeviewsidebarpage.cpp
src/urlnavigator.cpp
src/urlnavigator.h
src/urlnavigatorbutton.h

index 84ec0fc4ee5606519a8e9e691a8cdae7d2c59e50..1e4aaadc928eb09c604ef7dd106670a670695278 100644 (file)
@@ -75,7 +75,7 @@ BookmarkSelector::~BookmarkSelector()
 
 void BookmarkSelector::updateSelection(const KUrl& url)
 {
-    KBookmark bookmark = baseBookmark(m_bookmarkManager, url);
+    KBookmark bookmark = m_bookmarkManager->root().closestBookmark(url);
     if (!bookmark.isNull()) {
         m_selectedAddress = bookmark.address();
         setIcon(SmallIcon(bookmark.icon()));
@@ -99,34 +99,6 @@ QSize BookmarkSelector::sizeHint() const
     return QSize(height, height);
 }
 
-KBookmark BookmarkSelector::baseBookmark(KBookmarkManager* bookmarkManager, const KUrl& url)
-{
-    const KBookmarkGroup root = bookmarkManager->root();
-    KBookmark bookmark = root.first();
-    KBookmark foundBookmark;
-
-    int maxLength = 0;
-
-    // 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) {
-                foundBookmark = bookmark;
-                maxLength = length;
-            }
-        }
-        bookmark = root.next(bookmark);
-        ++i;
-    }
-
-    return foundBookmark;
-}
-
 void BookmarkSelector::paintEvent(QPaintEvent* /*event*/)
 {
     QPainter painter(this);
index a92f186ecf9186da1f20ca5ae04d00912f29e243..a5f0d434ef36268df2c37ca5ad597b984ee79c01 100644 (file)
@@ -63,22 +63,6 @@ public:
     /** @see QWidget::sizeHint() */
     virtual QSize sizeHint() const;
 
-    /**
-     * Returns the base bookmark for the URL \a url.
-     * The base bookmark is defined as bookmark which is equal to
-     * the URL or at least is a parent URL. If there are more than
-     * one possible parent URL candidates, the bookmark which covers
-     * the bigger range of the URL is returned.
-     *
-     * Example: the url is '/home/peter/Documents/Music. Available
-     * bookmarks are:
-     * - /home/peter
-     * - /home/peter/Documents
-     *
-     * The base URL will be '/home/peter/Documents'.
-     */
-    static KBookmark baseBookmark(KBookmarkManager* bookmarkManager, const KUrl& url);
-
 signals:
     /**
      * Is send when a bookmark has been activated by the user.
index 677d0bd064c489735b7136081c65bab7a24b823f..b68fd58e5a75b82ddd8c7bcd87478deb1e2d9b5c 100644 (file)
@@ -196,41 +196,20 @@ void BookmarksSidebarPage::slotContextMenuRequested(Q3ListBoxItem* item,
 
 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);
index ebf8a3f826c7b6d4698ce8e8b5ebc2a5d82f91d5..e86ad13fac289f7fd62b5699be0e774ea6fb802b 100644 (file)
@@ -1348,11 +1348,10 @@ void DolphinMainWindow::setupDockWidgets()
 void DolphinMainWindow::updateHistory()\r
 {\r
     int index = 0;\r
-    const QList<UrlNavigator::HistoryElem> list = m_activeView->urlHistory(index);\r
 \r
     QAction* backAction = actionCollection()->action("go_back");\r
     if (backAction != 0) {\r
-        backAction->setEnabled(index < static_cast<int>(list.count()) - 1);\r
+        backAction->setEnabled(index < m_activeView->urlNavigator()->historySize() - 1);\r
     }\r
 \r
     QAction* forwardAction = actionCollection()->action("go_forward");\r
index 23c91b9f45f4289d349af9c9722da44051371fb7..17bbd608dd5080287d1ad3e3e1b6a9eeb886eecd 100644 (file)
@@ -454,11 +454,6 @@ void DolphinView::setUrlEditable(bool editable)
     m_urlNavigator->editUrl(editable);
 }
 
-const QList<UrlNavigator::HistoryElem> DolphinView::urlHistory(int& index) const
-{
-    return m_urlNavigator->history(index);
-}
-
 bool DolphinView::hasSelection() const
 {
     return itemView()->selectionModel()->hasSelection();
@@ -771,15 +766,12 @@ void DolphinView::showPreview(const KFileItem* item, const QPixmap& pixmap)
 
 void DolphinView::restoreContentsPos()
 {
-    int index = 0;
-    const QList<UrlNavigator::HistoryElem> history = urlHistory(index);
-    if (!history.isEmpty()) {
+    UrlNavigator::HistoryElem historyItem = m_urlNavigator->currentHistoryItem();
+    if (!historyItem.url().isEmpty()) {
         QAbstractItemView* view = itemView();
-        // TODO: view->setCurrentItem(history[index].currentFileName());
-
-        const UrlNavigator::HistoryElem& it = history[index];
-        view->horizontalScrollBar()->setValue(it.contentsX());
-        view->verticalScrollBar()->setValue(it.contentsY());
+        // TODO: view->setCurrentItem(historyItem.currentFileName());
+        view->horizontalScrollBar()->setValue(historyItem.contentsX());
+        view->verticalScrollBar()->setValue(historyItem.contentsY());
     }
 }
 
index 0bec4824af97cc932d708a02562c05bfba2cd38d..14c8372d3e64de9ad7cb343718a3128c1f464229 100644 (file)
@@ -211,14 +211,6 @@ public:
      */
     void setUrlEditable(bool editable);
 
-    /**
-     * Returns the complete URL history. The index 0 indicates the oldest
-     * history element.
-     * @param index     Output parameter which indicates the current
-     *                  index of the location.
-     */
-    const QList<UrlNavigator::HistoryElem> urlHistory(int& index) const;
-
     /** Returns true, if at least one item is selected. */
     bool hasSelection() const;
 
index aef455c1e35f2efae9e64beed8c6f8b6013fabf0..523e21a7820206ec77024e6171973c60292b2944 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "treeviewsidebarpage.h"
 
-#include "bookmarkselector.h"
+#include "kbookmarkmanager.h"
 #include "dolphinmainwindow.h"
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphinview.h"
@@ -99,7 +99,8 @@ void TreeViewSidebarPage::setUrl(const KUrl& url)
     m_url = url;
 
     // adjust the root of the tree to the base bookmark
-    const KUrl baseUrl = BookmarkSelector::baseBookmark(DolphinSettings::instance().bookmarkManager(), url).url();
+    KBookmarkManager* bookmarkManager = DolphinSettings::instance().bookmarkManager();
+    const KUrl baseUrl = bookmarkManager->root().closestBookmark(url).url();
     if (m_dirLister->url() != baseUrl) {
         m_dirLister->stop();
         m_dirLister->openUrl(baseUrl);
index ca3b1789cbf26ffe3a954d0b4054d2b78df41b90..aa4c94c69712b09b08d7b4c9d53d92ee8fd9e5bf 100644 (file)
@@ -166,10 +166,14 @@ KUrl UrlNavigator::url(int index) const
     return newurl;
 }
 
-const QList<UrlNavigator::HistoryElem>& UrlNavigator::history(int& index) const
+UrlNavigator::HistoryElem UrlNavigator::currentHistoryItem() const
 {
-    index = m_historyIndex;
-    return m_history;
+    return m_history[m_historyIndex];
+}
+
+int UrlNavigator::historySize() const
+{
+    return m_history.count();
 }
 
 void UrlNavigator::goBack()
index aa46709aace8601011b7c055ffa3872de9055188..8a1d2512d46b5731bbc481aa449b007260a96949 100644 (file)
@@ -58,10 +58,7 @@ class ProtocolCombo;
  *
  * The URL navigator also remembers the URL history and allows to go
  * back and forward within this history.
-*/
-
-//typedef QList<KUrl> UrlStack;
-
+ */
 class UrlNavigator : public QWidget
 {
     Q_OBJECT
@@ -107,13 +104,16 @@ public:
     /** Returns the portion of the current active URL up to the button at index. */
     KUrl url(int index) const;
 
+    /** Returns the amount of items in the history */
+    int historySize() const;
+
     /**
-     * Returns the complete URL history. The index 0 indicates the oldest
+     * Returns one item out of the history. The index 0 indicates the oldest
      * history element.
      * @param index     Output parameter which indicates the current
      *                  index of the location.
      */
-    const QList<HistoryElem>& history(int& index) const;
+    HistoryElem currentHistoryItem() const;
 
     /**
      * Goes back one step in the URL history. The signals
@@ -315,7 +315,6 @@ private:
     QLineEdit* m_host;
     QLinkedList<UrlNavigatorButton*> m_navButtons;
     QWidget* m_filler;
-    //UrlStack m_urls;
 };
 
 #endif
index 55e74c46b19f6bad67499a302f92a6f69c8a22a0..335001be264fc3ffbddbbe14345922dd72ac5d00 100644 (file)
@@ -22,7 +22,7 @@
 #define URLNAVIGATORBUTTON_H
 
 #include <kio/global.h>
-#include <urlbutton.h>
+#include "urlbutton.h"
 
 class KJob;
 class KUrl;