]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/urlnavigator.cpp
Ported to KBookmarkManager::closestBookmark - which even solves another TODO about...
[dolphin.git] / src / urlnavigator.cpp
index ee06f558a101898950f9e4c5c14f0915b9c6a7d0..aa4c94c69712b09b08d7b4c9d53d92ee8fd9e5bf 100644 (file)
@@ -65,7 +65,8 @@ UrlNavigator::HistoryElem::~HistoryElem()
 {
 }
 
-UrlNavigator::UrlNavigator(const KUrl& url,
+UrlNavigator::UrlNavigator(KBookmarkManager* bookmarkManager,
+                           const KUrl& url,
                            QWidget* parent) :
     QWidget(parent),
     m_active(true),
@@ -101,7 +102,7 @@ UrlNavigator::UrlNavigator(const KUrl& url,
     }
 
     // initialize the bookmark selector
-    m_bookmarkSelector = new BookmarkSelector(this);
+    m_bookmarkSelector = new BookmarkSelector(this, bookmarkManager);
     connect(m_bookmarkSelector, SIGNAL(bookmarkActivated(const KUrl&)),
             this, SLOT(setUrl(const KUrl&)));
 
@@ -142,9 +143,7 @@ UrlNavigator::~UrlNavigator()
 const KUrl& UrlNavigator::url() const
 {
     assert(!m_history.empty());
-    QLinkedList<HistoryElem>::const_iterator it = m_history.begin();
-    it += m_historyIndex;
-    return (*it).url();
+    return m_history[m_historyIndex].url();
 }
 
 KUrl UrlNavigator::url(int index) const
@@ -152,7 +151,8 @@ KUrl UrlNavigator::url(int index) const
     assert(index >= 0);
     // keep scheme, hostname etc. maybe we will need this in the future
     // for e.g. browsing ftp repositories.
-    QString pre(((QUrl)url()).toString(QUrl::RemovePath));
+    KUrl newurl(url());
+    newurl.setPath(QString());
     QString path(url().path());
 
     if (!path.isEmpty()) {
@@ -162,13 +162,18 @@ KUrl UrlNavigator::url(int index) const
             path = path.section('/', 0, index);
     }
 
-    return KUrl(pre + path);
+    newurl.setPath(path);
+    return newurl;
 }
 
-const QLinkedList<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()
@@ -271,26 +276,22 @@ void UrlNavigator::setUrl(const KUrl& url)
         // Check whether the previous element of the history has the same Url.
         // If yes, just go forward instead of inserting a duplicate history
         // element.
-        QLinkedList<HistoryElem>::const_iterator it = m_history.begin();
-        it += m_historyIndex - 1;
-        const KUrl& nextUrl = (*it).url();
-        if (transformedUrl == nextUrl) {
+        HistoryElem& prevHistoryElem = m_history[m_historyIndex - 1];
+        if (transformedUrl == prevHistoryElem.url()) {
             goForward();
 //             kDebug() << "goin' forward in history" << endl;
             return;
         }
     }
 
-    QLinkedList<HistoryElem>::iterator it = m_history.begin() + m_historyIndex;
-    const KUrl& currUrl = (*it).url();
-    if (currUrl == transformedUrl) {
+    if (this->url() == transformedUrl) {
         // don't insert duplicate history elements
-//         kDebug() << "currUrl == transformedUrl" << endl;
+//         kDebug() << "current url == transformedUrl" << endl;
         return;
     }
 
     updateHistoryElem();
-    m_history.insert(it, HistoryElem(transformedUrl));
+    m_history.insert(m_historyIndex, HistoryElem(transformedUrl));
 
     updateContent();
 
@@ -300,7 +301,7 @@ void UrlNavigator::setUrl(const KUrl& url)
     // Prevent an endless growing of the history: remembering
     // the last 100 Urls should be enough...
     if (m_historyIndex > 100) {
-        m_history.erase(m_history.begin());
+        m_history.removeFirst();
         --m_historyIndex;
     }
 
@@ -324,9 +325,9 @@ void UrlNavigator::requestActivation()
 
 void UrlNavigator::storeContentsPosition(int x, int y)
 {
-    QLinkedList<HistoryElem>::iterator it = m_history.begin() + m_historyIndex;
-    (*it).setContentsX(x);
-    (*it).setContentsY(y);
+    HistoryElem& hist = m_history[m_historyIndex];
+    hist.setContentsX(x);
+    hist.setContentsY(y);
 }
 
 void UrlNavigator::keyReleaseEvent(QKeyEvent* event)
@@ -496,8 +497,8 @@ void UrlNavigator::updateHistoryElem()
     assert(m_historyIndex >= 0);
     const KFileItem* item = 0; // TODO: m_dolphinView->currentFileItem();
     if (item != 0) {
-        QLinkedList<HistoryElem>::iterator it = m_history.begin() + m_historyIndex;
-        (*it).setCurrentFileName(item->name());
+        HistoryElem& hist = m_history[m_historyIndex];
+        hist.setCurrentFileName(item->name());
     }
 }
 
@@ -536,7 +537,6 @@ void UrlNavigator::updateContent()
 
         // get the data from the currently selected bookmark
         KBookmark bookmark = m_bookmarkSelector->selectedBookmark();
-        //int bookmarkIndex = m_bookmarkSelector->selectedIndex();
 
         QString bookmarkPath;
         if (bookmark.isNull()) {