summaryrefslogtreecommitdiff
path: root/src/urlbar/urlresolver.cpp
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-07-22 01:00:40 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-07-22 01:00:40 +0200
commitbbab050a3b1c6a631aed8fdf5b0ab484378e0cef (patch)
tree10798d78258216ebdfabc8ba6c04b8034dc9dd4e /src/urlbar/urlresolver.cpp
parentMerge commit 'refs/merge-requests/152' of git://gitorious.org/rekonq/mainline (diff)
parentfix suggestion type (diff)
downloadrekonq-bbab050a3b1c6a631aed8fdf5b0ab484378e0cef.tar.xz
Merge commit 'refs/merge-requests/153' of git://gitorious.org/rekonq/mainline into m153
Conflicts: src/history/historymanager.cpp src/history/historymanager.h
Diffstat (limited to 'src/urlbar/urlresolver.cpp')
-rw-r--r--src/urlbar/urlresolver.cpp163
1 files changed, 36 insertions, 127 deletions
diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp
index d457e1fb..f0fd257b 100644
--- a/src/urlbar/urlresolver.cpp
+++ b/src/urlbar/urlresolver.cpp
@@ -31,6 +31,7 @@
#include "application.h"
#include "historymanager.h"
#include "bookmarksmanager.h"
+#include "searchengine.h"
// KDE Includes
#include <KUriFilter>
@@ -59,7 +60,7 @@
QRegExp UrlResolver::_browseRegexp;
-
+QRegExp UrlResolver::_searchEnginesRegexp;
UrlResolver::UrlResolver(const QString &typedUrl)
: _typedString(typedUrl.trimmed())
@@ -90,6 +91,18 @@ UrlResolver::UrlResolver(const QString &typedUrl)
_browseRegexp = QRegExp('(' + protocol + ")|(" + localhost + ")|(" + local + ")|(" + address + ")|(" + ipv6 + ")|(" + ipv4 +')');
}
+ if ( _searchEnginesRegexp.isEmpty() )
+ {
+ QString reg;
+ QString engineUrl;
+ foreach(KService::Ptr s, SearchEngine::favorites())
+ {
+ engineUrl = QRegExp::escape(s->property("Query").toString()).replace("\\\\\\{@\\}","[\\d\\w-.]+");
+ if (reg.isEmpty()) reg = "(" + engineUrl + ")";
+ else reg = reg + "|(" + engineUrl + ")";
+ }
+ _searchEnginesRegexp = QRegExp(reg);
+ }
}
@@ -162,7 +175,7 @@ UrlSearchList UrlResolver::orderedSearchItems()
UrlSearchList commonList;
int commonResutls = 0;
-
+
//prefer items which are history items als well bookmarks item
//if there are more than 1000 bookmark results, the performance impact is noticeable
if(bookmarksResults < 1000)
@@ -300,16 +313,33 @@ UrlSearchList UrlResolver::webSearchesResolution()
// STEP 3 = history completion
UrlSearchList UrlResolver::historyResolution()
{
- AwesomeUrlCompletion *historyCompletion = Application::historyManager()->completionObject();
- return historyCompletion->substringCompletion(_typedString);
+ QList<HistoryHashItem> found = Application::historyManager()->find(_typedString);
+ qSort(found);
+
+ UrlSearchList list;
+ foreach (HistoryHashItem i, found)
+ {
+ if (_searchEnginesRegexp.indexIn(i.url) == -1) //filter all urls that are search engine results
+ {
+ UrlSearchItem gItem(UrlSearchItem::History, i.url, i.title);
+ list << gItem;
+ }
+ }
+ return list;
}
// STEP 4 = bookmarks completion
UrlSearchList UrlResolver::bookmarksResolution()
{
- AwesomeUrlCompletion *bookmarkCompletion = Application::bookmarkProvider()->completionObject();
- return bookmarkCompletion->substringCompletion(_typedString);
+ UrlSearchList list;
+ QList<KBookmark> found = Application::bookmarkProvider()->find(_typedString);
+ foreach (KBookmark b, found)
+ {
+ UrlSearchItem gItem(UrlSearchItem::Bookmark, b.url().url(), b.fullText());
+ list << gItem;
+ }
+ return list;
}
@@ -333,124 +363,3 @@ UrlSearchItem UrlResolver::privilegedItem(UrlSearchList* list)
}
return UrlSearchItem();
}
-
-// ------------------------------------------------------------------------------------------------------
-
-
-AwesomeUrlCompletion::AwesomeUrlCompletion()
-{
- m_resetCompletion = true;
-}
-
-
-AwesomeUrlCompletion::~AwesomeUrlCompletion()
-{
-
-}
-
-
-void AwesomeUrlCompletion::addItem(const UrlSearchItem& itemToAdd)
-{
- bool match = false;
- QTime myTime;
- myTime.start();
- for(int i = 0; i < m_items.count(); i++)
- {
- //check if item is already in list; the items are equal if the url and the title are equal
- if(m_items[i] == itemToAdd)
- {
- match = true;
- //TODO: check what to do if comment or bookmarkPath are different
- if(m_items[i] < itemToAdd)
- {
- m_items[i].visitDateTime = itemToAdd.visitDateTime;
- }
- m_items[i].visitCount += itemToAdd.visitCount;
- }
- }
- if(!match)
- {
- m_items.append(itemToAdd);
- }
- m_resetCompletion = true;
-}
-
-
-void AwesomeUrlCompletion::removeItem(const UrlSearchItem& item)
-{
- m_resetCompletion = m_items.removeOne(item);
-}
-
-
-void AwesomeUrlCompletion::setOrder(KCompletion::CompOrder)
-{
- //TODO
-}
-
-
-void AwesomeUrlCompletion::updateTitle(const UrlSearchItem& item, const QString& newTitle)
-{
- foreach(UrlSearchItem i, m_items)
- {
- if(i == item)
- {
- i.title = newTitle;
- }
- }
- m_resetCompletion = true;
-}
-
-
-void AwesomeUrlCompletion::clear()
-{
- m_items.clear();
- m_resetCompletion = true;
-}
-
-
-UrlSearchList AwesomeUrlCompletion::substringCompletion(const QString& completionString)
-{
- UrlSearchList* searchList;
- UrlSearchList tempList;
-
- if(!m_resetCompletion)
- {
- if(completionString.length() <= 1)
- {
- m_resetCompletion = true;
- }
- if(!m_resetCompletion && completionString.length() < m_lastCompletionString.length())
- {
- m_resetCompletion = true;
- }
- if(!m_resetCompletion && !completionString.startsWith(m_lastCompletionString, Qt::CaseInsensitive))
- {
- m_resetCompletion = true;
- }
- }
-
- if(m_resetCompletion)
- {
- searchList = &m_items;
- m_resetCompletion = false;
- }
- else
- {
- searchList = &m_filteredItems;
- }
-
- Q_FOREACH(const UrlSearchItem &i, *searchList)
- {
- //TODO: split string and also search for each word if the are more than one word separated with space
- if( i.url.contains(completionString, Qt::CaseInsensitive)
- || i.title.contains(completionString, Qt::CaseInsensitive)
- || i.description.contains(completionString, Qt::CaseInsensitive)
- )
- {
- tempList.append(i);
- }
- }
- m_lastCompletionString = completionString;
- m_filteredItems = tempList;
- return m_filteredItems;
-}