summaryrefslogtreecommitdiff
path: root/src/urlbar
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-06-04 23:21:46 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-06-05 00:49:37 +0200
commitdeab0dd37edbc4007a3c2cf32d31811aff0e7e2d (patch)
treeb2a2884a69dd03428cdb9bcf15150a17ebbff867 /src/urlbar
parentThis should fix the Ctrl+w bug. Anyway, it really doesn't solve it: there is ... (diff)
downloadrekonq-deab0dd37edbc4007a3c2cf32d31811aff0e7e2d.tar.xz
Awesome bar speed up
This commit introduces notable changes and needs a lot of tests Courtesy patch from Mathias Kraus. Thanks :) BUG: 237390
Diffstat (limited to 'src/urlbar')
-rw-r--r--src/urlbar/listitem.cpp16
-rw-r--r--src/urlbar/urlresolver.cpp337
-rw-r--r--src/urlbar/urlresolver.h84
3 files changed, 344 insertions, 93 deletions
diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp
index a8878418..c0d163c9 100644
--- a/src/urlbar/listitem.cpp
+++ b/src/urlbar/listitem.cpp
@@ -212,8 +212,8 @@ PreviewListItem::PreviewListItem(const UrlSearchItem &item, const QString &text,
QLabel *previewLabelIcon = new QLabel(this);
previewLabelIcon->setFixedSize(45, 33);
- new PreviewLabel(item.url.url(), 38, 29, previewLabelIcon);
- IconLabel* icon = new IconLabel(item.url.url(), previewLabelIcon);
+ new PreviewLabel(item.url, 38, 29, previewLabelIcon);
+ IconLabel* icon = new IconLabel(item.url, previewLabelIcon);
icon->move(27, 16);
hLayout->addWidget(previewLabelIcon);
@@ -223,13 +223,13 @@ PreviewListItem::PreviewListItem(const UrlSearchItem &item, const QString &text,
QString title = item.title;
if (title.isEmpty())
{
- title = item.url.url();
+ title = item.url;
title = title.remove("http://");
- title.truncate(title.indexOf("/"));
+ title.truncate(title.indexOf("/"));
}
vLayout->addWidget(new TextLabel(title, text, this));
- vLayout->addWidget(new TextLabel("<i>" + item.url.url() + "</i>", text, this));
+ vLayout->addWidget(new TextLabel("<i>" + item.url + "</i>", text, this));
hLayout->addLayout(vLayout);
@@ -278,7 +278,7 @@ SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, Q
m_url = SearchEngine::buildQuery(engine, query);
- m_iconLabel = new IconLabel("edit-find", this); //TODO: get the default engine icon
+ m_iconLabel = new IconLabel("edit-find", this); //TODO: get the default engine icon (will be easy in KDE SC 4.5)
m_titleLabel = new TextLabel(searchItemTitle(engine->name(), query), QString(), this);
m_engineBar = new EngineBar(engine, parent);
@@ -397,8 +397,8 @@ BrowseListItem::BrowseListItem(const UrlSearchItem &item, const QString &text, Q
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->setSpacing(4);
- hLayout->addWidget(new IconLabel(item.url.url(), this));
- hLayout->addWidget(new TextLabel(item.url.url(), text, this));
+ hLayout->addWidget(new IconLabel(item.url, this));
+ hLayout->addWidget(new TextLabel(item.url, text, this));
hLayout->addWidget(new TypeIconLabel(item.type, this));
setLayout(hLayout);
diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp
index 7333e305..7131766b 100644
--- a/src/urlbar/urlresolver.cpp
+++ b/src/urlbar/urlresolver.cpp
@@ -43,7 +43,7 @@
#include <QByteArray>
// defines
-#define MAX_ELEMENTS 9
+#define MAX_ELEMENTS 10
// NOTE
@@ -55,12 +55,6 @@
// 5. "fixhosturifilter"
-bool UrlSearchItem::operator==(const UrlSearchItem &i) const
-{
- return url == i.url;
-}
-
-
// ------------------------------------------------------------------------
@@ -99,27 +93,31 @@ UrlResolver::UrlResolver(const QString &typedUrl)
UrlSearchList UrlResolver::orderedSearchItems()
{
- // NOTE: the logic here is : "we wanna suggest (at least) 9 elements"
- // so we have (more or less) 3 from first results (1 from QUrl Resolutions, 2 from
- // default search engines).
- // There are 6 remaining: if bookmarkResults + historyResults <= 6, catch all, else
- // catch first 3 results from the two resulting lists :)
-
+ // 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;
if( _typedString == QL1S("about:") )
{
- UrlSearchItem home(UrlSearchItem::Browse, KUrl("about:home"), QL1S("home") );
+ UrlSearchItem home(UrlSearchItem::Browse, QString("about:home"), QL1S("home") );
list << home;
- UrlSearchItem favs(UrlSearchItem::Browse, KUrl("about:favorites"), QL1S("favorites") );
+ UrlSearchItem favs(UrlSearchItem::Browse, QString("about:favorites"), QL1S("favorites") );
list << favs;
- UrlSearchItem clos(UrlSearchItem::Browse, KUrl("about:closedTabs"), QL1S("closed tabs") );
+ UrlSearchItem clos(UrlSearchItem::Browse, QString("about:closedTabs"), QL1S("closed tabs") );
list << clos;
- UrlSearchItem book(UrlSearchItem::Browse, KUrl("about:bookmarks"), QL1S("bookmarks") );
+ UrlSearchItem book(UrlSearchItem::Browse, QString("about:bookmarks"), QL1S("bookmarks") );
list << book;
- UrlSearchItem hist(UrlSearchItem::Browse, KUrl("about:history"), QL1S("history") );
+ UrlSearchItem hist(UrlSearchItem::Browse, QString("about:history"), QL1S("history") );
list << hist;
- UrlSearchItem down(UrlSearchItem::Browse, KUrl("about:downloads"), QL1S("downloads") );
+ UrlSearchItem down(UrlSearchItem::Browse, QString("about:downloads"), QL1S("downloads") );
list << down;
return list;
@@ -136,59 +134,135 @@ 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
+ //if there are more than 1000 bookmark results, the performance impact is noticeable
+ if(bookmarksResults < 1000)
{
- 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++)
{
- list << i;
+ if (bookmarksList.removeOne(historyList.at(i)))
+ {
+ urlSearchItem = historyList.takeAt(i);
+ urlSearchItem.type |= UrlSearchItem::Bookmark;
+ commonList << urlSearchItem;
+ commonResutls++;
+ if(commonResutls >= availableEntries)
+ {
+ break;
+ }
+ }
}
- else
+
+ commonResutls = commonList.count();
+ if(commonResutls >= availableEntries)
+ {
+ commonList = commonList.mid(0, availableEntries);
+ historyList = UrlSearchList();
+ bookmarksList = UrlSearchList();
+ availableEntries = 0;
+ }
+ 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;
+ qWarning() << "orderedSearchItems leave: " << " elapsed: " << myTime.elapsed();
+
return list;
}
@@ -206,7 +280,7 @@ UrlSearchList UrlResolver::qurlFromUserInputResolution()
if (urlFromUserInput.isValid())
{
QString gTitle = i18nc("Browse a website", "Browse");
- UrlSearchItem gItem(UrlSearchItem::Browse, urlFromUserInput, gTitle);
+ UrlSearchItem gItem(UrlSearchItem::Browse, urlFromUserInput.toString(), gTitle);
list << gItem;
}
@@ -217,57 +291,166 @@ UrlSearchList UrlResolver::qurlFromUserInputResolution()
// STEP 2 = Web Searches
UrlSearchList UrlResolver::webSearchesResolution()
{
- return UrlSearchList() << UrlSearchItem(UrlSearchItem::Search, KUrl(), QString());
+ return UrlSearchList() << UrlSearchItem(UrlSearchItem::Search, QString(), QString());
}
// STEP 3 = history completion
UrlSearchList UrlResolver::historyResolution()
{
- UrlSearchList list;
+ AwesomeUrlCompletion *historyCompletion = Application::historyManager()->completionObject();
+ return historyCompletion->substringCompletion(_typedString);
+}
+
+
+// STEP 4 = bookmarks completion
+UrlSearchList UrlResolver::bookmarksResolution()
+{
+ AwesomeUrlCompletion *bookmarkCompletion = Application::bookmarkProvider()->completionObject();
+ return bookmarkCompletion->substringCompletion(_typedString);
+}
+
+
+UrlSearchItem UrlResolver::privilegedItem(UrlSearchList* list)
+{
+ UrlSearchItem item;
+ QString dot;
+ if(!_typedString.endsWith(QL1C('.')))
+ {
+ dot = QString(QL1C('.'));
+ }
+
+ for(int i = 0; i<list->count(); i++)
+ {
+ item = list->at(i);
+ //kDebug() << item.url.host();
+ //TODO: move this to AwesomeUrlCompletion::substringCompletion and add a priviledged flag to UrlSearchItem
+ if (item.url.contains(_typedString + dot))
+ {
+ list->removeAt(i);
+ return item;
+ }
+ }
+ return UrlSearchItem();
+}
+
+// ------------------------------------------------------------------------------------------------------
+
+
+AwesomeUrlCompletion::AwesomeUrlCompletion()
+{
+ m_resetCompletion = true;
+}
+
+
+AwesomeUrlCompletion::~AwesomeUrlCompletion()
+{
+
+}
+
- KCompletion *historyCompletion = Application::historyManager()->completionObject();
- QStringList historyResults = historyCompletion->substringCompletion(_typedString);
- Q_FOREACH(const QString &s, historyResults)
+void AwesomeUrlCompletion::addItem(const UrlSearchItem& itemToAdd)
+{
+ bool match = false;
+ QTime myTime;
+ myTime.start();
+ for(int i = 0; i < m_items.count(); i++)
{
- UrlSearchItem it(UrlSearchItem::History, KUrl(s), Application::historyManager()->titleForHistoryUrl(s));
- list << it;
+ //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;
+}
- return list;
+
+void AwesomeUrlCompletion::removeItem(const UrlSearchItem& item)
+{
+ m_resetCompletion = m_items.removeOne(item);
}
-// STEP 4 = bookmarks completion
-UrlSearchList UrlResolver::bookmarksResolution()
+void AwesomeUrlCompletion::setOrder(KCompletion::CompOrder)
{
- UrlSearchList list;
+ //TODO
+}
- KCompletion *bookmarkCompletion = Application::bookmarkProvider()->completionObject();
- QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_typedString);
- Q_FOREACH(const QString &s, bookmarkResults)
+
+void AwesomeUrlCompletion::updateTitle(const UrlSearchItem& item, const QString& newTitle)
+{
+ foreach(UrlSearchItem i, m_items)
{
- UrlSearchItem it(UrlSearchItem::Bookmark, KUrl(s), Application::bookmarkProvider()->titleForBookmarkUrl(s));
- list << it;
+ if(i == item)
+ {
+ i.title = newTitle;
+ }
}
+ m_resetCompletion = true;
+}
- return list;
+
+void AwesomeUrlCompletion::clear()
+{
+ m_items.clear();
+ m_resetCompletion = true;
}
-UrlSearchItem UrlResolver::privilegedItem(UrlSearchList* list)
+UrlSearchList AwesomeUrlCompletion::substringCompletion(const QString& completionString)
{
- int i=0;
- while(i<list->count())
+ UrlSearchList* searchList;
+ UrlSearchList tempList;
+
+ if(!m_resetCompletion)
{
- UrlSearchItem item = list->at(i);
- kDebug() << item.url.host();
- if (item.url.host().contains( _typedString + QL1C('.') ) )
+ if(completionString.length() <= 1)
{
- list->removeAt(i);
- return item;
+ 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;
}
- i++;
}
- return UrlSearchItem();
+
+ 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 2249ea32..83228140 100644
--- a/src/urlbar/urlresolver.h
+++ b/src/urlbar/urlresolver.h
@@ -33,11 +33,14 @@
// KDE Includes
#include <KUrl>
+#include <KCompletion>
// Qt Includes
#include <QString>
#include <QList>
+#include <QDateTime>
+class AwesomeUrlCompletion;
class UrlSearchItem
{
@@ -53,22 +56,62 @@ public:
};
int type;
- KUrl url;
+ 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)
+ 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)
{};
- UrlSearchItem()
- : type(UrlSearchItem::Undefined), url(KUrl()), title("")
+ UrlSearchItem() : type(UrlSearchItem::Undefined),
+ url(QString()),
+ title(QString()),
+ visitDateTime(QDateTime()),
+ visitCount(0),
+ description(QString()),
+ bookmarkPath(QString())
{};
- UrlSearchItem(const int &_type, const KUrl &_url, const QString &_title = QString())
- : type(_type), url(_url), title(_title)
+ 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()
+ )
+ : type(_type),
+ url(_url),
+ title(_title),
+ visitDateTime(visitDateTime),
+ visitCount(visitCount),
+ description(description),
+ bookmarkPath(bookmarkPath)
{};
- bool operator==(const UrlSearchItem &i) const;
+ 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;
@@ -96,4 +139,29 @@ private:
static QRegExp _browseRegexp;
};
+// ------------------------------------------------------------------------------
+
+
+/**
+ * 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