summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bookmarks/bookmarksmanager.cpp44
-rw-r--r--src/bookmarks/bookmarksmanager.h10
-rw-r--r--src/history/historymanager.cpp88
-rw-r--r--src/history/historymanager.h39
-rw-r--r--src/urlbar/urlresolver.cpp163
-rw-r--r--src/urlbar/urlresolver.h65
6 files changed, 144 insertions, 265 deletions
diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp
index 57a29907..d0062ae1 100644
--- a/src/bookmarks/bookmarksmanager.cpp
+++ b/src/bookmarks/bookmarksmanager.cpp
@@ -185,8 +185,6 @@ QAction * BookmarkMenu::actionForBookmark(const KBookmark &bookmark)
}
else
{
- UrlSearchItem urlSearchItem(UrlSearchItem::Bookmark, bookmark.url().prettyUrl() , bookmark.fullText(), QDateTime(), 1, bookmark.description(), QString());
- Application::bookmarkProvider()->completionObject()->addItem(urlSearchItem);
return new KBookmarkAction(bookmark, owner(), this);
}
}
@@ -250,13 +248,9 @@ BookmarkProvider::BookmarkProvider(QObject *parent)
, m_manager(0)
, m_owner(0)
, m_actionCollection(new KActionCollection(this))
- , m_completion(0)
, _bookmarkActionMenu(0)
{
kDebug() << "Loading Bookmarks Manager...";
- // take care of the completion object
- m_completion = new AwesomeUrlCompletion;
- m_completion->setOrder(KCompletion::Weighted);
KUrl bookfile = KUrl("~/.kde/share/apps/konqueror/bookmarks.xml"); // share konqueror bookmarks
@@ -296,8 +290,6 @@ BookmarkProvider::~BookmarkProvider()
delete m_actionCollection;
delete m_owner;
delete m_manager;
-
- delete m_completion;
}
@@ -324,8 +316,6 @@ void BookmarkProvider::slotBookmarksChanged(const QString &group, const QString
Q_UNUSED(group)
Q_UNUSED(caller)
- m_completion->clear();
-
foreach(KToolBar *bookmarkToolBar, m_bookmarkToolBars)
{
if (bookmarkToolBar)
@@ -334,7 +324,6 @@ void BookmarkProvider::slotBookmarksChanged(const QString &group, const QString
fillBookmarkBar(bookmarkToolBar);
}
}
- //TODO: also change completion object
}
@@ -429,51 +418,44 @@ KBookmarkGroup BookmarkProvider::rootGroup()
}
-AwesomeUrlCompletion *BookmarkProvider::completionObject() const
-{
- return m_completion;
-}
-
-
-QString BookmarkProvider::titleForBookmarkUrl(QString url)
+QList<KBookmark> BookmarkProvider::find(QString text)
{
- QString title = "";
+ QList<KBookmark> list;
KBookmarkGroup bookGroup = Application::bookmarkProvider()->rootGroup();
if (bookGroup.isNull())
{
- return title;
+ return list;
}
- KBookmark bookmark = bookGroup.first();
- while (!bookmark.isNull() && title.isEmpty())
+ KBookmark bookmark = bookGroup.first();
+ while (!bookmark.isNull())
{
- title = titleForBookmarkUrl(bookmark, url);
+ list = find(list, bookmark, text);
bookmark = bookGroup.next(bookmark);
}
- return title;
+ return list;
}
-QString BookmarkProvider::titleForBookmarkUrl(const KBookmark &bookmark, QString url)
+QList<KBookmark> BookmarkProvider::find(QList<KBookmark> list, const KBookmark &bookmark, QString text)
{
- QString title = "";
if (bookmark.isGroup())
{
KBookmarkGroup group = bookmark.toGroup();
KBookmark bm = group.first();
- while (!bm.isNull() && title.isEmpty())
+ while (!bm.isNull())
{
- title = titleForBookmarkUrl(bm, url); // it is .bookfolder
+ list = find(list, bm, text); // it is .bookfolder
bm = group.next(bm);
}
}
- else if (!bookmark.isSeparator() && bookmark.url() == url)
+ else if (bookmark.url().url().contains(text) || bookmark.fullText().contains(text))
{
- title = bookmark.fullText();
+ list << bookmark;
}
- return title;
+ return list;
}
diff --git a/src/bookmarks/bookmarksmanager.h b/src/bookmarks/bookmarksmanager.h
index 0915e894..64945eab 100644
--- a/src/bookmarks/bookmarksmanager.h
+++ b/src/bookmarks/bookmarksmanager.h
@@ -228,12 +228,7 @@ public:
inline BookmarkOwner *bookmarkOwner() { return m_owner; }
- /**
- * @returns the AwesomeUrlCompletion object.
- */
- AwesomeUrlCompletion *completionObject() const;
-
- QString titleForBookmarkUrl(QString url);
+ QList<KBookmark> find(QString text);
void registerBookmarkPanel(BookmarksPanel *panel);
void removeBookmarkPanel(BookmarksPanel *panel);
@@ -271,14 +266,13 @@ private slots:
private:
void fillBookmarkBar(KToolBar *toolBar);
- QString titleForBookmarkUrl(const KBookmark &bookmark, QString url);
+ QList<KBookmark> find(QList<KBookmark> list, const KBookmark &bookmark, QString text);
KBookmarkManager *m_manager;
BookmarkOwner *m_owner;
KActionCollection *m_actionCollection;
QList<KToolBar*> m_bookmarkToolBars;
QList<BookmarksPanel*> m_bookmarkPanels;
- AwesomeUrlCompletion *m_completion;
KActionMenu *_bookmarkActionMenu;
};
diff --git a/src/history/historymanager.cpp b/src/history/historymanager.cpp
index 13c3df24..966487a9 100644
--- a/src/history/historymanager.cpp
+++ b/src/history/historymanager.cpp
@@ -69,11 +69,8 @@ HistoryManager::HistoryManager(QObject *parent)
, m_historyModel(0)
, m_historyFilterModel(0)
, m_historyTreeModel(0)
- , m_completion(new AwesomeUrlCompletion)
{
kDebug() << "Loading HistoryManager...";
- // take care of the completion object
- m_completion->setOrder(KCompletion::Weighted);
m_expiredTimer.setSingleShot(true);
connect(&m_expiredTimer, SIGNAL(timeout()), this, SLOT(checkForExpired()));
@@ -95,7 +92,6 @@ HistoryManager::HistoryManager(QObject *parent)
HistoryManager::~HistoryManager()
{
m_saveTimer->saveIfNeccessary();
- delete m_completion;
delete m_saveTimer;
@@ -113,7 +109,7 @@ QList<HistoryItem> HistoryManager::history() const
bool HistoryManager::historyContains(const QString &url) const
{
- return m_historyFilterModel->historyContains(url);
+ return m_hash.contains(url) && m_hash[url].savedCount>0;
}
@@ -134,16 +130,11 @@ void HistoryManager::addHistoryEntry(const QString &url)
HistoryItem item(cleanUrl.toString(), QDateTime::currentDateTime());
m_history.prepend(item);
+ addHistoryHashEntry(item);
emit entryAdded(item);
if (m_history.count() == 1)
checkForExpired();
-
- // Add item to completion object
- QString _url(url);
- _url.remove(QRegExp("^http://|/$"));
- UrlSearchItem urlSearchItem(UrlSearchItem::History, _url, QString(), item.dateTime, 1, QString(), QString());
- m_completion->addItem(urlSearchItem);
}
@@ -151,6 +142,13 @@ void HistoryManager::setHistory(const QList<HistoryItem> &history, bool loadedAn
{
m_history = history;
+ //TODO: is there a way to really memorize the visitCount instead of recount it at startup ?
+ m_hash.clear();
+ foreach(HistoryItem i, m_history)
+ {
+ addHistoryHashEntry(i);
+ }
+
// verify that it is sorted by date
if (!loadedAndSorted)
qSort(m_history.begin(), m_history.end());
@@ -222,6 +220,25 @@ void HistoryManager::checkForExpired()
}
+void HistoryManager::addHistoryHashEntry(const HistoryItem &item)
+{
+ if (m_hash.contains(item.url))
+ {
+ m_hash[item.url].visitCount++;
+ m_hash[item.url].dateTime = item.dateTime; //store last visit date
+ if (!item.title.isEmpty())
+ {
+ m_hash[item.url].title = item.title; //store last title if not empty
+ }
+ }
+ else
+ {
+ m_hash[item.url] = HistoryHashItem(item.url, item.dateTime, item.title);
+ }
+ m_hash[item.url].savedCount++;
+}
+
+
void HistoryManager::updateHistoryEntry(const KUrl &url, const QString &title)
{
for (int i = 0; i < m_history.count(); ++i)
@@ -232,6 +249,11 @@ void HistoryManager::updateHistoryEntry(const KUrl &url, const QString &title)
m_saveTimer->changeOccurred();
if (m_lastSavedUrl.isEmpty())
m_lastSavedUrl = m_history.at(i).url;
+
+ if (m_hash.contains(url.url()) && !title.isEmpty())
+ {
+ m_hash[url.url()].title = title;
+ }
emit entryUpdated(i);
break;
}
@@ -254,10 +276,29 @@ void HistoryManager::removeHistoryEntry(const KUrl &url, const QString &title)
break;
}
}
+}
+
- // Remove item from completion object
- UrlSearchItem urlSearchItem(UrlSearchItem::History, item.url, item.title, item.dateTime, 0, QString(), QString());
- m_completion->removeItem(urlSearchItem);
+HistoryHashItem HistoryManager::get(const QString &url)
+{
+ return m_hash[url];
+}
+
+
+QList<HistoryHashItem> HistoryManager::find(const QString &text)
+{
+ QList<HistoryHashItem> list;
+
+ QString url;
+ foreach(url, m_hash.keys())
+ {
+ if (url.contains(text) || m_hash[url].title.contains(text))
+ {
+ list << m_hash[url];
+ }
+ }
+
+ return list;
}
@@ -358,12 +399,6 @@ void HistoryManager::load()
list.prepend(item);
lastInsertedItem = item;
-
- // Add item to completion object
- //QString _url = item.url;
- //_url.remove(QRegExp("^http://|/$"));
- UrlSearchItem urlSearchItem(UrlSearchItem::History, item.url, item.title, item.dateTime, 1, QString(), QString());
- m_completion->addItem(urlSearchItem);
}
if (needToSort)
qSort(list.begin(), list.end());
@@ -445,16 +480,3 @@ void HistoryManager::save()
}
m_lastSavedUrl = m_history.value(0).url;
}
-
-
-AwesomeUrlCompletion * HistoryManager::completionObject() const
-{
- return m_completion;
-}
-
-
-QString HistoryManager::titleForHistoryUrl(const QString &url)
-{
- return history().at(m_historyFilterModel->historyLocation(url)).title;
-}
-
diff --git a/src/history/historymanager.h b/src/history/historymanager.h
index ce712919..85702b84 100644
--- a/src/history/historymanager.h
+++ b/src/history/historymanager.h
@@ -84,6 +84,32 @@ public:
// ---------------------------------------------------------------------------------------------------------------
+class HistoryHashItem : public HistoryItem
+{
+public:
+ HistoryHashItem() {}
+ explicit HistoryHashItem(const QString &u
+ ,const QDateTime &d = QDateTime()
+ ,const QString &t = QString()
+ )
+ : HistoryItem(u, d, t)
+ ,visitCount(1)
+ ,savedCount(0)
+ {}
+
+ inline bool operator <(const HistoryHashItem &other) const
+ {
+ return visitCount > other.visitCount;
+ }
+
+ int visitCount;
+ int savedCount;
+};
+
+
+// ---------------------------------------------------------------------------------------------------------------
+
+
// Forward Declarations
class AutoSaver;
class HistoryModel;
@@ -115,7 +141,8 @@ public:
void updateHistoryEntry(const KUrl &url, const QString &title);
void removeHistoryEntry(const KUrl &url, const QString &title = QString());
- QString titleForHistoryUrl(const QString &url);
+ HistoryHashItem get(const QString &url);
+ QList<HistoryHashItem> find(const QString &text);
int historyLimit() const;
void setHistoryLimit(int limit);
@@ -128,11 +155,6 @@ public:
HistoryFilterModel *historyFilterModel() const;
HistoryTreeModel *historyTreeModel() const;
- /**
- * @returns the AwesomeUrlCompletion object.
- */
- AwesomeUrlCompletion *completionObject() const;
-
public slots:
void clear();
void loadSettings();
@@ -142,20 +164,19 @@ private slots:
void checkForExpired();
private:
+ void addHistoryHashEntry(const HistoryItem &item);
void load();
AutoSaver *m_saveTimer;
int m_historyLimit;
QTimer m_expiredTimer;
QList<HistoryItem> m_history;
+ QHash<QString, HistoryHashItem> m_hash;
QString m_lastSavedUrl;
HistoryModel *m_historyModel;
HistoryFilterModel *m_historyFilterModel;
HistoryTreeModel *m_historyTreeModel;
-
- // the completion object we sync with
- AwesomeUrlCompletion *m_completion;
};
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