From f09caa376e40678fff10525b7249455a819337c4 Mon Sep 17 00:00:00 2001
From: Yoann Laissus <yoann.laissus@gmail.com>
Date: Fri, 17 Aug 2012 10:00:55 +0200
Subject: BookmarkWidget:

Don't display an empty entry if the bookmark is in the root folder
Improve the code to choose the current index

Add an icon for the toolbar root entry in the BookmarkWidget
Don't duplicate the toolbar root entry in some cases

Clean up setupFolderComboBox()

--- Imported from rekonq code by adjam :)
---
 src/urlbar/bookmarkwidget.cpp | 41 ++++++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 19 deletions(-)

(limited to 'src')

diff --git a/src/urlbar/bookmarkwidget.cpp b/src/urlbar/bookmarkwidget.cpp
index 1a69c052..6c6763b0 100644
--- a/src/urlbar/bookmarkwidget.cpp
+++ b/src/urlbar/bookmarkwidget.cpp
@@ -236,44 +236,47 @@ void BookmarkWidget::accept()
 
 void BookmarkWidget::setupFolderComboBox()
 {
-    KBookmarkGroup root = BookmarkManager::self()->manager()->toolbar();
+    KBookmarkGroup toolBarRoot = BookmarkManager::self()->manager()->toolbar();
+    KBookmarkGroup root = BookmarkManager::self()->rootGroup();
 
-    if (BookmarkManager::self()->manager()->toolbar().address() == BookmarkManager::self()->manager()->root().address())
+    if (toolBarRoot.address() == root.address())
     {
-        m_folder->addItem(i18n("Bookmark Toolbar"),
-                          BookmarkManager::self()->manager()->toolbar().address());
+        m_folder->addItem(KIcon("bookmark-toolbar"),
+                          i18n("Bookmark Toolbar"),
+                          toolBarRoot.address());
     }
     else
     {
-        m_folder->addItem(BookmarkManager::self()->manager()->toolbar().text(),
-                          BookmarkManager::self()->manager()->toolbar().address());
+        m_folder->addItem(KIcon("bookmark-toolbar"),
+                          toolBarRoot.text(),
+                          toolBarRoot.address());
     }
     m_folder->insertSeparator(1);
 
-    if (m_bookmark->parentGroup().address() != BookmarkManager::self()->manager()->toolbar().address())
+    if (m_bookmark->parentGroup().address() != toolBarRoot.address())
     {
-        m_folder->addItem(m_bookmark->parentGroup().text(),
+        QString parentText = m_bookmark->parentGroup().text();
+
+        if (m_bookmark->parentGroup().address() == root.address())
+        {
+            parentText = i18n("Root folder");
+        }
+
+        m_folder->addItem(parentText,
                           m_bookmark->parentGroup().address());
         m_folder->insertSeparator(3);
     }
 
-    for (KBookmark bookmark = root.first(); !bookmark.isNull(); bookmark = root.next(bookmark))
+    for (KBookmark bookmark = toolBarRoot.first(); !bookmark.isNull(); bookmark = toolBarRoot.next(bookmark))
     {
-        if (bookmark.isGroup())
+        if (bookmark.isGroup() && bookmark.address() != m_bookmark->parentGroup().address())
         {
             m_folder->addItem(bookmark.text(), bookmark.address());
         }
     }
 
-    if (m_bookmark->parentGroup().address() == root.address())
-    {
-        m_folder->setCurrentIndex(0);
-    }
-    else
-    {
-        int index = m_folder->findText(m_bookmark->parentGroup().text());
-        m_folder->setCurrentIndex(index);
-    }
+    int index =  m_folder->findData(m_bookmark->parentGroup().address());
+    m_folder->setCurrentIndex(index);
 }
 
 
-- 
cgit v1.2.1