hi,

I was looking for a fix to bug #237390 (will soon send a patch) and discovered 
that somethimes there are only a few history entries even if there could be up 
to six as the code states. another issue was, that the insertion and removal 
of a privileged entry makes the list jump.
the patch tries to keep always 9 entries in the awesomebar.
if there is a privileged entry, there are another 3 history entries and 3 
bookmark entries. if not, there are 4 history entries and 3 bookmark entries.
in the case that there are less than 4 history or 3 bookmark entries, the 
awesomebar is filled with either bookmark or history entries.
furthermore, it prefers entries which are history items as well as bookmark 
items.

what do you think?

regards,
mathias
diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp
index 7333e30..9c347da 100644
--- a/src/urlbar/urlresolver.cpp
+++ b/src/urlbar/urlresolver.cpp
@@ -136,59 +136,134 @@ UrlSearchList UrlResolver::orderedSearchItems()
         list << qurlFromUserInputResolution();
     }
 
-    
-    int firstResults = list.count();
-    int checkPoint = 9 - firstResults;
-
+    //find the history items that match the typed string
     UrlSearchList historyList = historyResolution();
     UrlSearchItem privileged = privilegedItem(&historyList);
     int historyResults = historyList.count();
     
-    UrlSearchList bookmarksList = bookmarksResolution(); 
+    //find the bookmarks items that match the typed string
+    UrlSearchList bookmarksList = bookmarksResolution();
     if (privileged.type == UrlSearchItem::Undefined)
     {
         privileged = privilegedItem(&bookmarksList);
     }
-    
-    if (privileged.type != UrlSearchItem::Undefined)
+    else if(privileged.type == UrlSearchItem::History && bookmarksList.removeOne(privileged))
     {
-        list.insert(0,privileged);
+        privileged.type |= UrlSearchItem::Bookmark;
     }
-
     int bookmarksResults = bookmarksList.count();
-
-    if (historyResults + bookmarksResults > checkPoint)
+    
+    if (privileged.type != UrlSearchItem::Undefined)
     {
-        historyList = historyList.mid(0, 3);
-        bookmarksList = bookmarksList.mid(0, 3);
+        list.prepend(privileged);
     }
-
-    QList<UrlSearchItem> common;
-
-    foreach(UrlSearchItem i, historyList)
+    
+    int availableEntries = MAX_ELEMENTS - list.count();
+    
+    UrlSearchList commonList;
+    int commonResutls = 0;
+    
+    //prefer items which are history items als well bookmarks item
+    //because of the current speed issues only if there are less than 100 results
+    if(bookmarksResults < 100)//TODO:1000 after the speed issue is solved
     {
-        if (!bookmarksList.contains(i))
+        //add as many items to the common list as there are available entries in the dropdown list
+        UrlSearchItem urlSearchItem;
+        for(int i = 0; i < historyList.count(); i++)
+        {
+            if (bookmarksList.removeOne(historyList.at(i)))
+            {
+                urlSearchItem = historyList.takeAt(i);
+                urlSearchItem.type |= UrlSearchItem::Bookmark;
+                commonList << urlSearchItem;
+                commonResutls++;
+                if(commonResutls >= availableEntries)
+                {
+                    break;
+                }
+            }
+        }
+        
+        commonResutls = commonList.count();
+        if(commonResutls >= availableEntries)
         {
-            list << i;
+            commonList = commonList.mid(0, availableEntries);
+            historyList = UrlSearchList();
+            bookmarksList = UrlSearchList();
+            availableEntries = 0;
         }
-        else
+        else        //remove all items from the history and bookmarks list up to the remaining entries in the dropdown list
         {
-            i.type |= UrlSearchItem::Bookmark;
-            common << i;
+            availableEntries -= commonResutls;
+            if(historyResults >= availableEntries)
+            {
+                historyList = historyList.mid(0, availableEntries);
+            }
+            if(bookmarksResults >= availableEntries)
+            {
+                bookmarksList = bookmarksList.mid(0, availableEntries);
+            }
         }
     }
-
-    foreach(const UrlSearchItem &i, common)
+    else        //if there are too many bookmarks items, remove all items up to the remaining entries in the dropdown list
     {
-        list << i;
-    }
+        
+        if(historyResults >= availableEntries)
+        {
+            historyList = historyList.mid(0, availableEntries);
+        }
+        if(bookmarksResults >= availableEntries)
+        {
+            bookmarksList = bookmarksList.mid(0, availableEntries);
+        }
 
-    foreach(const UrlSearchItem &i, bookmarksList)
+        UrlSearchItem urlSearchItem;
+        for(int i = 0; i < historyList.count(); i++)
+        {
+            if (bookmarksList.removeOne(historyList.at(i)))
+            {
+                urlSearchItem = historyList.takeAt(i);
+                urlSearchItem.type |= UrlSearchItem::Bookmark;
+                commonList << urlSearchItem;
+            }
+        }
+        
+        availableEntries -= commonList.count();
+    }
+    
+    historyResults = historyList.count();
+    bookmarksResults = bookmarksList.count();
+    commonResutls = commonList.count();
+    
+    //now fill the list to MAX_ELEMENTS
+    if(availableEntries > 0)
     {
-        if (!common.contains(i))
-            list << i;
+        int historyEntries = ((int) (availableEntries / 2)) + availableEntries % 2;
+        int bookmarksEntries = availableEntries - historyEntries;
+        
+        if (historyResults >= historyEntries && bookmarksResults >= bookmarksEntries)
+        {
+            historyList = historyList.mid(0, historyEntries);
+            bookmarksList = bookmarksList.mid(0, bookmarksEntries);
+        }
+        else if (historyResults < historyEntries && bookmarksResults >= bookmarksEntries)
+        {
+            if(historyResults + bookmarksResults > availableEntries)
+            {
+                bookmarksList = bookmarksList.mid(0, availableEntries - historyResults);
+            }
+        }
+        else if (historyResults >= historyEntries && bookmarksResults < bookmarksEntries)
+        {
+            if(historyResults + bookmarksResults > availableEntries)
+            {
+                historyList = historyList.mid(0, availableEntries - bookmarksResults);
+            }
+        }
     }
-
+    
+    list = list + historyList + commonList + bookmarksList;
+    
     return list;
 }
 
@@ -257,17 +332,22 @@ UrlSearchList UrlResolver::bookmarksResolution()
 
 UrlSearchItem UrlResolver::privilegedItem(UrlSearchList* list)
 {
-    int i=0;
-    while(i<list->count())
+    UrlSearchItem item;
+    QString dot;
+    if(!_typedString.endsWith(QL1C('.')))
+    {
+        dot = QString(QL1C('.'));
+    }
+    
+    for(int i = 0; i<list->count(); i++)
     {
-        UrlSearchItem item = list->at(i);
-        kDebug() << item.url.host();
-        if (item.url.host().contains( _typedString + QL1C('.') ) )
+        item = list->at(i);
+        //kDebug() << item.url.host();
+        if (item.url.host().contains(_typedString + dot))
         {
             list->removeAt(i);
             return item;
         }
-        i++;
     }
     return UrlSearchItem();
 }
_______________________________________________
rekonq mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/rekonq

Reply via email to