diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2013-11-22 18:07:45 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2013-11-22 18:07:45 +0100 |
commit | cc6fa971a01ebd2f16db11bea99d2e8d008682fc (patch) | |
tree | 768acaa5ed864eebbd27782dfac592233e27a547 | |
parent | Do NOT download everytime engines favicons if present (diff) | |
download | rekonq-cc6fa971a01ebd2f16db11bea99d2e8d008682fc.tar.xz |
improvements on urlbar
STEP 2:
- work & fix on search engine favicons
- simplify code (and remove dead one)
- API clean up
- delete ASAP list items and suggestions
- let the URL in the suggestions be an hard grey
-rw-r--r-- | src/icons/iconmanager.cpp | 11 | ||||
-rw-r--r-- | src/icons/iconmanager.h | 3 | ||||
-rw-r--r-- | src/icons/webicon.cpp | 6 | ||||
-rw-r--r-- | src/urlbar/completionwidget.cpp | 75 | ||||
-rw-r--r-- | src/urlbar/completionwidget.h | 5 | ||||
-rw-r--r-- | src/urlbar/listitem.cpp | 87 | ||||
-rw-r--r-- | src/urlbar/listitem.h | 44 | ||||
-rw-r--r-- | src/urlbar/urlsuggester.cpp | 65 | ||||
-rw-r--r-- | src/urlbar/urlsuggester.h | 10 |
9 files changed, 37 insertions, 269 deletions
diff --git a/src/icons/iconmanager.cpp b/src/icons/iconmanager.cpp index cc09e252..7bc47eec 100644 --- a/src/icons/iconmanager.cpp +++ b/src/icons/iconmanager.cpp @@ -207,18 +207,15 @@ QString IconManager::iconPathForUrl(const KUrl &url) } -void IconManager::provideEngineFavicon(const KUrl &url) -{ - // will autodelete itself when done - new WebIcon(url); -} - - KIcon IconManager::engineFavicon(const KUrl &url) { if (QFile::exists(_faviconsDir + url.host() + QL1S(".png"))) return KIcon(QIcon(_faviconsDir + url.host() + QL1S(".png"))); + // if engine favicon is NOT found, download it + // will autodelete itself when done + new WebIcon(url); + kDebug() << "NO ENGINE FAVICON"; return KIcon("text-html"); } diff --git a/src/icons/iconmanager.h b/src/icons/iconmanager.h index a120be16..659eff88 100644 --- a/src/icons/iconmanager.h +++ b/src/icons/iconmanager.h @@ -60,8 +60,7 @@ public: void saveDesktopIconForUrl(const KUrl &u); - // Engine ToolBar needed methods - void provideEngineFavicon(const KUrl &); + // Engine ToolBar needed method KIcon engineFavicon(const KUrl &); private: diff --git a/src/icons/webicon.cpp b/src/icons/webicon.cpp index 7230b3a6..77973782 100644 --- a/src/icons/webicon.cpp +++ b/src/icons/webicon.cpp @@ -76,12 +76,6 @@ void WebIcon::saveIcon(bool b) QString faviconsDir = KStandardDirs::locateLocal("cache" , "favicons/" , true); QString faviconPath = faviconsDir + m_url.host(); - if ( QFile::exists(faviconPath + QL1S(".png")) ) - { - this->deleteLater(); - return; - } - // dest url KUrl destUrl(faviconPath); kDebug() << "DEST URL: " << destUrl; diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index b7a7bfdb..fc29f089 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -2,7 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2009-2012 by Andrea Diamantini <adjam7 at gmail dot com> +* Copyright (C) 2009-2013 by Andrea Diamantini <adjam7 at gmail dot com> * * * This program is free software; you can redistribute it and/or @@ -74,11 +74,12 @@ void CompletionWidget::insertItems(const UrlSuggestionList &list, const QString& { ListItem *suggestion = ListItemFactory::create(item, text, this); suggestion->setBackgroundRole(offset % 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(updateList()), this, SLOT(updateList())); + connect(this, SIGNAL(nextItemSubChoice()), suggestion, SLOT(nextItemSubChoice())); suggestion->setObjectName(QString::number(offset++)); @@ -88,21 +89,18 @@ void CompletionWidget::insertItems(const UrlSuggestionList &list, const QString& void CompletionWidget::updateSuggestionList(const UrlSuggestionList &list, const QString& text) -{ +{ if (_hasSuggestions || _typedString != text) return; _hasSuggestions = true; - if (_resList.count() > 0) + if (list.count() > 0) { clear(); - insertItems(_resList, text); - _list = _resList; + insertItems(list, text); + _list = list; - UrlSuggestionList sugList = list.mid(0, 4); - insertItems(sugList, text, _list.count()); - _list.append(sugList); popup(); } } @@ -264,39 +262,23 @@ bool CompletionWidget::eventFilter(QObject *obj, QEvent *ev) { w = qobject_cast<UrlBar *>(parent()); - if (!w->text().startsWith(QL1S("http://"), Qt::CaseInsensitive)) + if (kev->modifiers() == Qt::ControlModifier) { - QString append; - if (kev->modifiers() == Qt::ControlModifier) - { - append = QL1S(".com"); - } - else if (kev->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) - { - append = QL1S(".org"); - } - else if (kev->modifiers() == Qt::ShiftModifier) + QString append = QL1S(".com"); + QUrl url(QL1S("http://") + w->text()); + QString host = url.host(); + if (!host.endsWith(append, Qt::CaseInsensitive)) { - append = QL1S(".net"); + host += append; + url.setHost(host); } - if (!append.isEmpty()) + if (url.isValid()) { - QUrl url(QL1S("http://") + w->text()); - QString host = url.host(); - if (!host.endsWith(append, Qt::CaseInsensitive)) - { - host += append; - url.setHost(host); - } - - if (url.isValid()) - { - emit chosenUrl(url, Rekonq::CurrentTab); - kev->accept(); - hide(); - return true; - } + emit chosenUrl(url, Rekonq::CurrentTab); + kev->accept(); + hide(); + return true; } } @@ -314,6 +296,7 @@ bool CompletionWidget::eventFilter(QObject *obj, QEvent *ev) else //the user type too fast (completionwidget not visible or suggestion not downloaded) { urlToLoad = UrlResolver::urlFromTextTyped(w->text()); + kDebug() << "Fast typer for text: " << w->text(); } if (kev->modifiers() == Qt::AltModifier) @@ -356,6 +339,7 @@ void CompletionWidget::setVisible(bool visible) else { qApp->removeEventFilter(this); + clear(); } QFrame::setVisible(visible); @@ -364,7 +348,6 @@ void CompletionWidget::setVisible(bool visible) void CompletionWidget::itemChosen(ListItem *item, Qt::MouseButton button, Qt::KeyboardModifiers modifier) { - hide(); if (button == Qt::MidButton || modifier == Qt::ControlModifier) { @@ -374,12 +357,9 @@ void CompletionWidget::itemChosen(ListItem *item, Qt::MouseButton button, Qt::Ke { emit chosenUrl(item->url(), Rekonq::CurrentTab); } -} - - -void CompletionWidget::updateList() -{ - suggestUrls(_typedString); + + // do it AFTER launching chosenUrl to get sure item exists + hide(); } @@ -398,12 +378,9 @@ void CompletionWidget::suggestUrls(const QString &text) } UrlSuggester *res = new UrlSuggester(text); - connect(res, SIGNAL(suggestionsReady(UrlSuggestionList,QString)), - this, SLOT(updateSuggestionList(UrlSuggestionList,QString))); - _resList = res->orderedSearchItems(); + UrlSuggestionList list = res->computeSuggestions(); - // NOTE: It's important to call this AFTER orderedSearchItems() to let everything work - res->computeSuggestions(); + updateSuggestionList(list, text); delete res; } diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index 57a90b0e..f7ec2582 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -2,7 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2009-2012 by Andrea Diamantini <adjam7 at gmail dot com> +* Copyright (C) 2009-2013 by Andrea Diamantini <adjam7 at gmail dot com> * * * This program is free software; you can redistribute it and/or @@ -61,7 +61,6 @@ public: private Q_SLOTS: void itemChosen(ListItem *item, Qt::MouseButton = Qt::LeftButton, Qt::KeyboardModifiers = Qt::NoModifier); void updateSuggestionList(const UrlSuggestionList &list, const QString& text); - void updateList(); Q_SIGNALS: void chosenUrl(const KUrl &, Rekonq::OpenType); @@ -88,8 +87,6 @@ private: QString _typedString; bool _hasSuggestions; - - UrlSuggestionList _resList; }; #endif // COMPLETION_WIDGET_H diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index b8b980c6..95d8cbb9 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -176,8 +176,6 @@ TypeIconLabel::TypeIconLabel(int type, QWidget *parent) hLayout->addWidget(getIcon("rating")); if (type & UrlSuggestionItem::History) hLayout->addWidget(getIcon("view-history")); - if (type & UrlSuggestionItem::Suggestion) - hLayout->addWidget(getIcon("help-hint")); } @@ -194,27 +192,6 @@ QLabel *TypeIconLabel::getIcon(QString icon) // --------------------------------------------------------------- -IconLabel::IconLabel(const QString &icon, QWidget *parent) - : QLabel(parent) -{ - QPixmap pixmapIcon = IconManager::self()->iconForUrl(KUrl(icon)).pixmap(16); - setFixedSize(16, 16); - setPixmap(pixmapIcon); -} - - -IconLabel::IconLabel(const KIcon &icon, QWidget *parent) - : QLabel(parent) -{ - QPixmap pixmapIcon = icon.pixmap(16); - setFixedSize(16, 16); - setPixmap(pixmapIcon); -} - - -// --------------------------------------------------------------- - - static QString highlightWordsInText(const QString &text, const QStringList &words) { QString ret = text; @@ -275,7 +252,7 @@ TextLabel::TextLabel(const QString &text, const QString &textToPointOut, QWidget QStringList words = Qt::escape(textToPointOut.simplified()).split(QL1C(' ')); t = highlightWordsInText(t, words); if (wasItalic) - t = QL1S("<i>") + t + QL1S("</i>"); + t = QL1S("<i style=color:\"#555\">") + t + QL1S("</i>"); setText(t); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); } @@ -299,26 +276,6 @@ void TextLabel::setEngineText(const QString &engine, const QString &text) // --------------------------------------------------------------- -DescriptionLabel::DescriptionLabel(const QString &text, QWidget *parent) - : QLabel(parent) -{ - QString t = text; - const bool wasItalic = t.startsWith(QL1S("<i>")); - if (wasItalic) - t.remove(QRegExp("<[/ib]*>")); - - if (wasItalic) - t = QL1S("<i>") + t + QL1S("</i>"); - - setWordWrap(false); //NOTE: why setWordWrap(true) make items have a strange behavior ? - setText(t); - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); -} - - -//-------------------------------------------------------------------------------------------- - - PreviewListItem::PreviewListItem(const UrlSuggestionItem &item, const QString &text, QWidget *parent) : ListItem(item, parent) { @@ -424,19 +381,6 @@ EngineBar::EngineBar(KService::Ptr selectedEngine, QWidget *parent) if (SearchEngine::defaultEngine().isNull()) return; - - static bool isFirstExecution = true; - if (isFirstExecution) - { - Q_FOREACH(const KService::Ptr & engine, SearchEngine::favorites()) - { - QUrl u = engine->property("Query").toUrl(); - KUrl url = KUrl(u.toString(QUrl::RemovePath | QUrl::RemoveQuery)); - IconManager::self()->provideEngineFavicon(url); - } - - isFirstExecution = false; - } m_engineGroup->addAction(newEngineAction(SearchEngine::defaultEngine(), selectedEngine)); Q_FOREACH(const KService::Ptr & engine, SearchEngine::favorites()) @@ -497,30 +441,6 @@ void EngineBar::selectNextEngine() // --------------------------------------------------------------- -SuggestionListItem::SuggestionListItem(const UrlSuggestionItem &item, const QString &text, QWidget *parent) - : ListItem(item, parent) - , m_text(item.title) -{ - QHBoxLayout *hLayout = new QHBoxLayout; - hLayout->setSpacing(4); - - hLayout->addWidget(new IconLabel(item.url, this)); - hLayout->addWidget(new TextLabel(item.title, text, this)); - hLayout->addWidget(new TypeIconLabel(item.type, this)); - - setLayout(hLayout); -} - - -QString SuggestionListItem::text() -{ - return m_text; -} - - -// --------------------------------------------------------------- - - BrowseListItem::BrowseListItem(const UrlSuggestionItem &item, const QString &text, QWidget *parent) : ListItem(item, parent) { @@ -559,10 +479,5 @@ ListItem *ListItemFactory::create(const UrlSuggestionItem &item, const QString & return new PreviewListItem(item, text, parent); } - if (item.type & UrlSuggestionItem::Suggestion) - { - return new SuggestionListItem(item, text, parent); - } - return new PreviewListItem(item, text, parent); } diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index f34da334..47d7822d 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -72,7 +72,6 @@ public Q_SLOTS: Q_SIGNALS: void itemClicked(ListItem *item, Qt::MouseButton, Qt::KeyboardModifiers); - void updateList(); protected: virtual void paintEvent(QPaintEvent *event); @@ -106,19 +105,6 @@ private: // ------------------------------------------------------------------------- -class REKONQ_TESTS_EXPORT IconLabel : public QLabel -{ - Q_OBJECT - -public: - explicit IconLabel(const QString &icon, QWidget *parent = 0); - explicit IconLabel(const KIcon &icon, QWidget *parent = 0); -}; - - -// ------------------------------------------------------------------------- - - class REKONQ_TESTS_EXPORT TextLabel : public QLabel { Q_OBJECT @@ -134,18 +120,6 @@ public: // ------------------------------------------------------------------------- -class REKONQ_TESTS_EXPORT DescriptionLabel : public QLabel -{ - Q_OBJECT - -public: - explicit DescriptionLabel(const QString &text, QWidget *parent = 0); -}; - - -// ------------------------------------------------------------------------- - - class REKONQ_TESTS_EXPORT EngineBar : public KToolBar { Q_OBJECT @@ -188,7 +162,6 @@ private Q_SLOTS: private: TextLabel* m_titleLabel; - IconLabel* m_iconLabel; EngineBar* m_engineBar; QString m_text; KService::Ptr m_currentEngine; @@ -198,23 +171,6 @@ private: // ------------------------------------------------------------------------- -class REKONQ_TESTS_EXPORT SuggestionListItem : public ListItem -{ - Q_OBJECT - -public: - SuggestionListItem(const UrlSuggestionItem &item, const QString &text, QWidget *parent = 0); - - QString text(); - -private: - QString m_text; -}; - - -// ------------------------------------------------------------------------- - - class REKONQ_TESTS_EXPORT PreviewListItem : public ListItem { Q_OBJECT diff --git a/src/urlbar/urlsuggester.cpp b/src/urlbar/urlsuggester.cpp index 897b1eb0..aed50c22 100644 --- a/src/urlbar/urlsuggester.cpp +++ b/src/urlbar/urlsuggester.cpp @@ -125,7 +125,8 @@ UrlSuggester::UrlSuggester(const QString &typedUrl) } -UrlSuggestionList UrlSuggester::orderedSearchItems() +// UrlSuggestionList UrlSuggester::orderedSearchItems() +UrlSuggestionList UrlSuggester::computeSuggestions() { if (_typedString.startsWith(QL1S("rekonq:"))) { @@ -363,68 +364,6 @@ void UrlSuggester::computeBookmarks() } -// opensearch suggestion -void UrlSuggester::computeSuggestions() -{ - // NOTE - // This attempt basically cuts out open search suggestions. - UrlSuggestionList list; - emit suggestionsReady(list, _typedString); - return; - -// // if a string startsWith /, it is probably a local path -// // so, no need for suggestions... -// if (_typedString.startsWith('/') || !rApp->opensearchManager()->isSuggestionAvailable()) -// { -// UrlSuggestionList list; -// emit suggestionsReady(list, _typedString); -// return; -// } -// -// QString query = _typedString; -// KService::Ptr engine = SearchEngine::fromString(_typedString); -// if (engine) -// { -// query = query.remove(0, _typedString.indexOf(SearchEngine::delimiter()) + 1); -// setSearchEngine(engine); -// } -// -// connect(rApp->opensearchManager(), -// SIGNAL(suggestionsReceived(QString,ResponseList)), -// this, -// SLOT(suggestionsReceived(QString,ResponseList))); -// -// _typedQuery = query; -// rApp->opensearchManager()->requestSuggestion(query); -} - - -// void UrlSuggester::suggestionsReceived(const QString &text, const ResponseList &suggestions) -// { -// if (text != _typedString) -// return; -// -// UrlSuggestionList sugList; -// QString urlString; -// Q_FOREACH(const Response & i, suggestions) -// { -// if (text == i.title) -// continue; -// -// urlString = i.url; -// if (urlString.isEmpty()) -// { -// urlString = SearchEngine::buildQuery(UrlSuggester::searchEngine(), i.title); -// } -// -// UrlSuggestionItem gItem(UrlSuggestionItem::Suggestion, urlString, i.title, i.description, i.image, i.image_width, i.image_height); -// sugList << gItem; -// } -// emit suggestionsReady(sugList, _typedString); -// this->deleteLater(); -// } - - ////////////////////////////////////////////////////////////////////////// diff --git a/src/urlbar/urlsuggester.h b/src/urlbar/urlsuggester.h index 14df59fc..22bc4320 100644 --- a/src/urlbar/urlsuggester.h +++ b/src/urlbar/urlsuggester.h @@ -50,8 +50,7 @@ public: Search = 0x00000001, Browse = 0x00000010, History = 0x00000100, - Bookmark = 0x00001000, - Suggestion = 0x00010000 + Bookmark = 0x00001000 }; int type; @@ -105,12 +104,7 @@ class UrlSuggester : public QObject public: explicit UrlSuggester(const QString &typedUrl); - UrlSuggestionList orderedSearchItems(); - - void computeSuggestions(); - -Q_SIGNALS: - void suggestionsReady(const UrlSuggestionList &, const QString &); + UrlSuggestionList computeSuggestions(); private: void computeWebSearches(); |