summaryrefslogtreecommitdiff
path: root/src/urlbar
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
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')
-rw-r--r--src/urlbar/urlresolver.cpp163
-rw-r--r--src/urlbar/urlresolver.h65
2 files changed, 44 insertions, 184 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;
-}
diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h
index 83228140..c79ce184 100644
--- a/src/urlbar/urlresolver.h
+++ b/src/urlbar/urlresolver.h
@@ -33,14 +33,11 @@
// KDE Includes
#include <KUrl>
-#include <KCompletion>
+
// Qt Includes
#include <QString>
#include <QList>
-#include <QDateTime>
-
-class AwesomeUrlCompletion;
class UrlSearchItem
{
@@ -58,60 +55,36 @@ public:
int type;
QString url;
QString title;
- QDateTime visitDateTime;
- int visitCount;
QString description;
QString bookmarkPath;
UrlSearchItem(const UrlSearchItem &item) : type(item.type),
url(item.url),
title(item.title),
- visitDateTime(item.visitDateTime),
- visitCount(item.visitCount),
- description(item.description),
- bookmarkPath(item.bookmarkPath)
+ description(item.description)
{};
-
+
UrlSearchItem() : type(UrlSearchItem::Undefined),
url(QString()),
title(QString()),
- visitDateTime(QDateTime()),
- visitCount(0),
- description(QString()),
- bookmarkPath(QString())
+ description(QString())
{};
UrlSearchItem(const int &_type,
const QString &_url,
const QString &_title = QString(),
- const QDateTime &visitDateTime = QDateTime(),
- const int &visitCount = 0,
- const QString &description = QString(),
- const QString &bookmarkPath = QString()
+ const QString &description = QString()
)
: type(_type),
url(_url),
title(_title),
- visitDateTime(visitDateTime),
- visitCount(visitCount),
- description(description),
- bookmarkPath(bookmarkPath)
+ description(description)
{};
inline bool operator==(const UrlSearchItem &i) const
{
return i.url == url;//TODO && i.title == title;
- }
-
- inline bool operator <(const UrlSearchItem &i) const
- {
- return visitDateTime < i.visitDateTime;
- }
-
- inline bool operator >(const UrlSearchItem &i) const
- {
- return visitDateTime > i.visitDateTime;
- }
+ }
};
typedef QList <UrlSearchItem> UrlSearchList;
@@ -137,31 +110,9 @@ private:
UrlSearchItem privilegedItem(UrlSearchList* list);
static QRegExp _browseRegexp;
+ static QRegExp _searchEnginesRegexp;
};
// ------------------------------------------------------------------------------
-
-/**
- * This class represents all searchable item for the awesomebar.
- */
-class AwesomeUrlCompletion// : public KCompletion
-{
-public:
- AwesomeUrlCompletion();
- ~AwesomeUrlCompletion();
- void addItem(const UrlSearchItem& item);
- void removeItem(const UrlSearchItem& item);
- void setOrder(KCompletion::CompOrder);
- void updateTitle(const UrlSearchItem& item, const QString& newTitle);
- void clear();
- UrlSearchList substringCompletion(const QString& completionString);
-
-private:
- UrlSearchList m_items;
- UrlSearchList m_filteredItems;
- bool m_resetCompletion;
- QString m_lastCompletionString;
-};
-
#endif // URL_RESOLVER_H