summaryrefslogtreecommitdiff
path: root/src/urlbar
diff options
context:
space:
mode:
Diffstat (limited to 'src/urlbar')
-rw-r--r--src/urlbar/completionwidget.cpp56
-rw-r--r--src/urlbar/completionwidget.h4
-rw-r--r--src/urlbar/urlresolver.cpp40
-rw-r--r--src/urlbar/urlresolver.h7
4 files changed, 72 insertions, 35 deletions
diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp
index a9203bf7..c1f5d83b 100644
--- a/src/urlbar/completionwidget.cpp
+++ b/src/urlbar/completionwidget.cpp
@@ -56,6 +56,8 @@ CompletionWidget::CompletionWidget(QWidget *parent)
, _parent(parent)
, _currentIndex(0)
, _searchEngine(SearchEngine::defaultEngine())
+ , _suggestionsNumber(0)
+ , _isSuggesting(false)
{
setFrameStyle(QFrame::Panel);
setLayoutDirection(Qt::LeftToRight);
@@ -79,14 +81,61 @@ void CompletionWidget::insertSearchList(const UrlSearchList &list, const QString
{
ListItem *suggestion = ListItemFactory::create(item, text, this);
suggestion->setBackgroundRole(i % 2 ? QPalette::AlternateBase : QPalette::Base);
- connect(suggestion, SIGNAL(itemClicked(ListItem *, Qt::MouseButton, Qt::KeyboardModifiers)), this, SLOT(itemChosen(ListItem *, Qt::MouseButton, Qt::KeyboardModifiers)));
+ connect(suggestion,
+ SIGNAL(itemClicked(ListItem *, Qt::MouseButton, Qt::KeyboardModifiers)),
+ this,
+ SLOT(itemChosen(ListItem *, Qt::MouseButton, Qt::KeyboardModifiers)));
connect(this, SIGNAL(nextItemSubChoice()), suggestion, SLOT(nextItemSubChoice()));
+
suggestion->setObjectName(QString::number(i++));
layout()->addWidget(suggestion);
}
}
+void CompletionWidget::updateSearchList(const UrlSearchList &list, const QString& text)
+{
+ kDebug() << "TYPED STRING: " << _typedString;
+ kDebug() << "text from suggestion: " << text;
+
+ if(_isSuggesting || !isVisible() || _typedString != text)
+ return;
+
+ _isSuggesting = true;
+
+ // clean up eventual old suggestions
+ if(_suggestionsNumber > 0)
+ {
+ int offset = _list.count();
+ for(int i = offset; i < offset + _suggestionsNumber; ++i)
+ {
+ QLayoutItem *item = layout()->takeAt( i );
+ delete item;
+ }
+ }
+
+ // add new suggestions to the list
+ int i = _list.count();
+ Q_FOREACH(const UrlSearchItem &item, list)
+ {
+ ListItem *suggestion = ListItemFactory::create(item, text, this);
+ suggestion->setBackgroundRole(i % 2 ? QPalette::AlternateBase : QPalette::Base);
+ connect(suggestion,
+ SIGNAL(itemClicked(ListItem *, Qt::MouseButton, Qt::KeyboardModifiers)),
+ this,
+ SLOT(itemChosen(ListItem *, Qt::MouseButton, Qt::KeyboardModifiers)));
+ connect(this, SIGNAL(nextItemSubChoice()), suggestion, SLOT(nextItemSubChoice()));
+
+ suggestion->setObjectName(QString::number(i++));
+ layout()->addWidget(suggestion);
+ }
+ _suggestionsNumber = list.count();
+ _list.append(list);
+ sizeAndPosition();
+ _isSuggesting = false;
+}
+
+
void CompletionWidget::sizeAndPosition()
{
setFixedWidth(_parent->width());
@@ -301,8 +350,9 @@ void CompletionWidget::suggestUrls(const QString &text)
return;
}
- UrlResolver res(text);
- UrlSearchList list = res.orderedSearchItems();
+ UrlResolver *res = new UrlResolver(text);
+ connect(res, SIGNAL(suggestionsReady(const UrlSearchList &, const QString &)), this, SLOT(updateSearchList(const UrlSearchList &, const QString &)));
+ UrlSearchList list = res->orderedSearchItems();
if (list.count() > 0)
{
clear();
diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h
index e14535f4..29f80721 100644
--- a/src/urlbar/completionwidget.h
+++ b/src/urlbar/completionwidget.h
@@ -65,6 +65,7 @@ public:
private slots:
void itemChosen(ListItem *item, Qt::MouseButton = Qt::LeftButton, Qt::KeyboardModifiers = Qt::NoModifier);
+ void updateSearchList(const UrlSearchList &list, const QString& text);
signals:
void chosenUrl(const KUrl &, Rekonq::OpenType);
@@ -72,6 +73,7 @@ signals:
private:
void insertSearchList(const UrlSearchList &list, const QString& text);
+
void popup();
void clear();
@@ -89,6 +91,8 @@ private:
KService::Ptr _searchEngine;
QString _typedString;
+ int _suggestionsNumber;
+ bool _isSuggesting;
};
#endif // COMPLETION_WIDGET_H
diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp
index 84c9e20b..300f33ef 100644
--- a/src/urlbar/urlresolver.cpp
+++ b/src/urlbar/urlresolver.cpp
@@ -131,8 +131,6 @@ UrlSearchList UrlResolver::orderedSearchItems()
return list;
}
- _computedListsCount = 0;
-
//compute lists
computeSuggestions();
computeQurlFromUserInput();
@@ -140,14 +138,6 @@ UrlSearchList UrlResolver::orderedSearchItems()
computeBookmarks();
computeHistory();
- QTime time;
- time.start();
-
- while (_computedListsCount < 5 && time.msec() < 1000)
- {
- Application::instance()->processEvents(QEventLoop::WaitForMoreEvents | QEventLoop::ExcludeUserInputEvents);
- }
-
return orderLists();
}
@@ -331,8 +321,6 @@ void UrlResolver::computeQurlFromUserInput()
UrlSearchItem gItem(UrlSearchItem::Browse, urlFromUserInput.toString(), gTitle);
_qurlFromUserInput << gItem;
}
-
- _computedListsCount++;
}
@@ -340,7 +328,6 @@ void UrlResolver::computeQurlFromUserInput()
void UrlResolver::computeWebSearches()
{
_webSearches = (UrlSearchList() << UrlSearchItem(UrlSearchItem::Search, QString(), QString()));
- _computedListsCount++;
}
@@ -358,8 +345,6 @@ void UrlResolver::computeHistory()
_history << gItem;
}
}
-
- _computedListsCount++;
}
@@ -373,8 +358,6 @@ void UrlResolver::computeBookmarks()
UrlSearchItem gItem(UrlSearchItem::Bookmark, b.url().url(), b.fullText());
_bookmarks << gItem;
}
-
- _computedListsCount++;
}
@@ -384,29 +367,29 @@ void UrlResolver::computeSuggestions()
if (Application::opensearchManager()->isSuggestionAvailable())
{
connect(Application::opensearchManager(),
- SIGNAL(suggestionReceived(const QStringList &)),
+ SIGNAL(suggestionReceived(const QString &, const QStringList &)),
this,
- SLOT(suggestionsReceived(const QStringList &)));
+ SLOT(suggestionsReceived(const QString &, const QStringList &)));
Application::opensearchManager()->requestSuggestion(_typedString);
}
- else
- {
- _computedListsCount++;
- }
}
-void UrlResolver::suggestionsReceived(const QStringList &suggestion)
+void UrlResolver::suggestionsReceived(const QString &text, const QStringList &suggestions)
{
+ if(text != _typedString)
+ return;
+
+ UrlSearchList sugList;
- foreach (QString s, suggestion)
+ Q_FOREACH(const QString &s, suggestions)
{
UrlSearchItem gItem(UrlSearchItem::Suggestion, s, s);
- _suggestions << gItem;
+ sugList << gItem;
}
-
- _computedListsCount++;
+ emit suggestionsReady(sugList, _typedString);
+ this->deleteLater();
}
@@ -420,7 +403,6 @@ UrlSearchItem UrlResolver::privilegedItem(UrlSearchList* list)
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(test1) || item.url.contains(test2))
{
diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h
index f72d6731..4e85e917 100644
--- a/src/urlbar/urlresolver.h
+++ b/src/urlbar/urlresolver.h
@@ -119,8 +119,6 @@ private:
void computeBookmarks();
void computeSuggestions();
- int _computedListsCount;
-
UrlSearchItem privilegedItem(UrlSearchList* list);
UrlSearchList orderLists();
@@ -128,7 +126,10 @@ private:
static QRegExp _searchEnginesRegexp;
private slots:
- void suggestionsReceived(const QStringList &suggestion);
+ void suggestionsReceived(const QString &text, const QStringList &suggestions);
+
+Q_SIGNALS:
+ void suggestionsReady(const UrlSearchList &, const QString &);
};