summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/urlbar/urlresolver.cpp164
1 files changed, 51 insertions, 113 deletions
diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp
index 1da3e78f..18c74661 100644
--- a/src/urlbar/urlresolver.cpp
+++ b/src/urlbar/urlresolver.cpp
@@ -45,9 +45,6 @@
// Qt Includes
#include <QByteArray>
-// defines
-#define MAX_ELEMENTS 8
-#define MIN_SUGGESTIONS 2
// NOTE
// default kurifilter plugin list (at least in my box):
@@ -157,144 +154,85 @@ UrlSearchList UrlResolver::orderedSearchItems()
UrlSearchList UrlResolver::orderLists()
{
// NOTE
- // the logic here is : "we wanna suggest (at least) 10 elements"
- // so we have (more or less) 2 from first results (1 from QUrl Resolutions, 1 from
- // search engines).
- // There are 8 remaining: if bookmarkResults + historyResults <= 8, catch all, else
- // catch first 4 results from the two resulting lists :)
-
- QTime myTime;
- myTime.start();
-
- UrlSearchList list;
+ // The const int here decides the number of proper suggestions, taken from history & bookmarks
+ // You have to add here the "browse & search" options, always available.
+ const int availableEntries = 8;
+ // Browse & Search results
+ UrlSearchList browseSearch;
if (_browseRegexp.indexIn(_typedString) != -1)
{
- list << _qurlFromUserInput;
- list << _webSearches;
+ browseSearch << _qurlFromUserInput;
+ browseSearch << _webSearches;
}
else
{
- list << _webSearches;
- list << _qurlFromUserInput;
+ browseSearch << _webSearches;
+ browseSearch << _qurlFromUserInput;
}
- int historyCount = _history.count();
- int bookmarksCount = _bookmarks.count();
-
- int availableEntries = MAX_ELEMENTS - list.count() - MIN_SUGGESTIONS;
- UrlSearchList common;
- int commonCount = 0;
+ // find relevant items (the one you are more probably searching...)
+ UrlSearchList relevant;
- // prefer items which are history items as well bookmarks item
- // if there are more than 1000 bookmark results, the performance impact is noticeable
- if (bookmarksCount < 1000)
+ // history
+ Q_FOREACH(const UrlSearchItem & item, _history)
{
- //add as many items to the common list as there are available entries in the dropdown list
- UrlSearchItem urlSearchItem;
- for (int i = 0; i < _history.count(); i++)
+ QString hst = KUrl(item.url).host();
+ if (item.url.startsWith(_typedString)
+ || hst.startsWith(_typedString)
+ || hst.remove("www.").startsWith(_typedString))
{
- if (_bookmarks.removeOne(_history.at(i)))
- {
- urlSearchItem = _history.takeAt(i);
- urlSearchItem.type |= UrlSearchItem::Bookmark;
- common << urlSearchItem;
- commonCount++;
- if (commonCount >= availableEntries)
- {
- break;
- }
- }
+ relevant << item;
+ _history.removeOne(item);
+ break;
}
+ }
- commonCount = common.count();
- if (commonCount >= availableEntries)
- {
- common = common.mid(0, availableEntries);
- _history = UrlSearchList();
- _bookmarks = UrlSearchList();
- availableEntries = 0;
- }
- else //remove all items from the history and bookmarks list up to the remaining entries in the dropdown list
+ // bookmarks
+ Q_FOREACH(const UrlSearchItem & item, _bookmarks)
+ {
+ QString hst = KUrl(item.url).host();
+ if (item.url.startsWith(_typedString)
+ || hst.startsWith(_typedString)
+ || hst.remove("www.").startsWith(_typedString))
{
- availableEntries -= commonCount;
- if (historyCount >= availableEntries)
- {
- _history = _history.mid(0, availableEntries);
- }
- if (bookmarksCount >= availableEntries)
- {
- _bookmarks = _bookmarks.mid(0, availableEntries);
- }
+ relevant << item;
+ _bookmarks.removeOne(item);
+ break;
}
}
- else //if there are too many bookmarks items, remove all items up to the remaining entries in the dropdown list
- {
- if (historyCount >= availableEntries)
- {
- _history = _history.mid(0, availableEntries);
- }
- if (bookmarksCount >= availableEntries)
- {
- _bookmarks = _bookmarks.mid(0, availableEntries);
- }
+ // decide history & bookmarks number
+ int historyCount = _history.count();
+ int bookmarksCount = _bookmarks.count();
+ int relevantCount = relevant.count();
- UrlSearchItem urlSearchItem;
- for (int i = 0; i < _history.count(); i++)
- {
- if (_bookmarks.removeOne(_history.at(i)))
- {
- urlSearchItem = _history.takeAt(i);
- urlSearchItem.type |= UrlSearchItem::Bookmark;
- common << urlSearchItem;
- }
- }
+ const int historyEntries = (availableEntries - relevantCount) / 2;
+ const int bookmarksEntries = availableEntries - relevantCount - historyEntries;
- availableEntries -= common.count();
+ if (historyCount >= historyEntries && bookmarksCount >= bookmarksEntries)
+ {
+ _history = _history.mid(0, historyEntries);
+ _bookmarks = _bookmarks.mid(0, bookmarksEntries);
}
-
- historyCount = _history.count();
- bookmarksCount = _bookmarks.count();
- commonCount = common.count();
-
- //now fill the list to MAX_ELEMENTS
- if (availableEntries > 0)
+ else if (historyCount < historyEntries && bookmarksCount >= bookmarksEntries)
{
- int historyEntries = ((int)(availableEntries / 2)) + availableEntries % 2;
- int bookmarksEntries = availableEntries - historyEntries;
-
- if (historyCount >= historyEntries && bookmarksCount >= bookmarksEntries)
+ if (historyCount + bookmarksCount > availableEntries)
{
- _history = _history.mid(0, historyEntries);
- _bookmarks = _bookmarks.mid(0, bookmarksEntries);
- }
- else if (historyCount < historyEntries && bookmarksCount >= bookmarksEntries)
- {
- if (historyCount + bookmarksCount > availableEntries)
- {
- _bookmarks = _bookmarks.mid(0, availableEntries - historyCount);
- }
- }
- else if (historyCount >= historyEntries && bookmarksCount < bookmarksEntries)
- {
- if (historyCount + bookmarksCount > availableEntries)
- {
- _history = _history.mid(0, availableEntries - bookmarksCount);
- }
+ _bookmarks = _bookmarks.mid(0, availableEntries - historyCount);
}
}
-
- availableEntries -= _history.count();
- availableEntries -= _bookmarks.count();
-
- if (_suggestions.count() > availableEntries + MIN_SUGGESTIONS)
+ else if (historyCount >= historyEntries && bookmarksCount < bookmarksEntries)
{
- _suggestions = _suggestions.mid(0, availableEntries + MIN_SUGGESTIONS);
+ if (historyCount + bookmarksCount > availableEntries)
+ {
+ _history = _history.mid(0, availableEntries - bookmarksCount);
+ }
}
- list = list + _history + common + _bookmarks + _suggestions;
+ // and finally, results
+ UrlSearchList list = relevant + browseSearch + _history + _bookmarks;
return list;
}