From 65e287ee4a68dcd5019d3fad13b3ebfdd1ef23d4 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 7 Nov 2010 16:35:41 +0100 Subject: First bunch of fixes for the suggestions. We are now respecting users setting on default engines (if someone chooses NONE default search engines, searches are NOT performed) --- src/application.cpp | 1 - src/data/wikipedia.xml | 10 +++++----- src/opensearch/searchengine.cpp | 10 +++++----- src/urlbar/completionwidget.cpp | 3 +++ src/urlbar/listitem.cpp | 31 +++++++++++++++++++------------ src/urlbar/urlresolver.cpp | 24 ++++++++++++++++-------- src/urlbar/urlresolver.h | 7 +++++-- 7 files changed, 53 insertions(+), 33 deletions(-) diff --git a/src/application.cpp b/src/application.cpp index cadfa50f..2efb62c0 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -310,7 +310,6 @@ OpenSearchManager *Application::opensearchManager() if (s_opensearchManager.isNull()) { s_opensearchManager = new OpenSearchManager(instance()); - s_opensearchManager.data()->setSearchProvider("google"); //TODO: use other suggestion engines } return s_opensearchManager.data(); } diff --git a/src/data/wikipedia.xml b/src/data/wikipedia.xml index 6f200a25..4e152087 100644 --- a/src/data/wikipedia.xml +++ b/src/data/wikipedia.xml @@ -1,8 +1,8 @@ - Wikipédia (fr) - Wikipédia (fr) - - - http://fr.wikipedia.org/favicon.ico + Wikipedia + Wikipedia + + + http://en.wikipedia.org/favicon.ico diff --git a/src/opensearch/searchengine.cpp b/src/opensearch/searchengine.cpp index 415e5b35..44e35e33 100644 --- a/src/opensearch/searchengine.cpp +++ b/src/opensearch/searchengine.cpp @@ -74,11 +74,11 @@ void SearchEngine::reload() //load default engine QString d = cg.readEntry("DefaultSearchEngine"); m_defaultEngine = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d)); - if (!m_defaultEngine) - { - d = QL1S("google"); - m_defaultEngine = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d)); - } +// if (!m_defaultEngine) +// { +// d = QL1S("google"); +// m_defaultEngine = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d)); +// } m_loaded = true; } diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index f8bf6ee2..a42433b7 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -311,6 +311,9 @@ bool CompletionWidget::eventFilter(QObject *obj, QEvent *ev) child = findChild(QString::number(_currentIndex)); if(child && _currentIndex!=0) //the completionwidget is visible and the user had press down { + kDebug() << "USING LISTITEM URL: " << child->url(); + kDebug() << "USING LISTITEM TITLE: " << child->text(); + //we can use the url of the listitem emit chosenUrl(child->url(), Rekonq::CurrentTab); } diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 5fa46470..a0462e76 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -58,6 +58,7 @@ #include #include + ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) : QWidget(parent) , m_option() @@ -81,7 +82,6 @@ ListItem::~ListItem() } - void ListItem::activate() { m_option.state |= QStyle::State_Selected; @@ -166,11 +166,16 @@ TypeIconLabel::TypeIconLabel(int type, QWidget *parent) hLayout->setAlignment(Qt::AlignRight); setLayout(hLayout); - if (type & UrlSearchItem::Search) hLayout->addWidget(getIcon("edit-find")); - if (type & UrlSearchItem::Browse) hLayout->addWidget(getIcon("applications-internet")); - if (type & UrlSearchItem::Bookmark) hLayout->addWidget(getIcon("rating")); - if (type & UrlSearchItem::History) hLayout->addWidget(getIcon("view-history")); - if (type & UrlSearchItem::Suggestion) hLayout->addWidget(getIcon("help-hint")); + if (type & UrlSearchItem::Search) + hLayout->addWidget(getIcon("edit-find")); + if (type & UrlSearchItem::Browse) + hLayout->addWidget(getIcon("applications-internet")); + if (type & UrlSearchItem::Bookmark) + hLayout->addWidget(getIcon("rating")); + if (type & UrlSearchItem::History) + hLayout->addWidget(getIcon("view-history")); + if (type & UrlSearchItem::Suggestion) + hLayout->addWidget(getIcon("help-hint")); } @@ -204,8 +209,10 @@ IconLabel::IconLabel(const KIcon &icon, QWidget *parent) setPixmap(pixmapIcon); } + // --------------------------------------------------------------- + static QString highlightWordsInText(const QString &text, const QStringList &words) { QString ret = text; @@ -241,6 +248,7 @@ static QString highlightWordsInText(const QString &text, const QStringList &word return ret; } + TextLabel::TextLabel(const QString &text, const QString &textToPointOut, QWidget *parent) : QLabel(parent) { @@ -274,6 +282,7 @@ void TextLabel::setEngineText(const QString &engine, const QString &text) setText( i18nc("%1=search engine, e.g. Google, Wikipedia %2=text to search for", "Search %1 for %2", engine, Qt::escape(text) ) ); } + // --------------------------------------------------------------- @@ -350,6 +359,7 @@ PreviewLabel::PreviewLabel(const QString &url, int width, int height, QWidget *p } } + // --------------------------------------------------------------- @@ -382,6 +392,7 @@ void ImageLabel::slotResult(KJob *) setPixmap(pix); } + // --------------------------------------------------------------- @@ -416,12 +427,6 @@ QString SearchListItem::text() } -// QString SearchListItem::searchItemTitle(QString engine, QString text) -// { -// return QString(i18nc("%1=search engine, e.g. Google, Wikipedia %2=text to search for", "Search %1 for %2", engine, text)); -// } - - void SearchListItem::changeSearchEngine(KService::Ptr engine) { m_titleLabel->setEngineText(engine->name(), m_text); @@ -575,6 +580,7 @@ QString VisualSuggestionListItem::text() return m_text; } + // --------------------------------------------------------------- @@ -627,6 +633,7 @@ ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text if (item.type & UrlSearchItem::Suggestion) { + kDebug() << "ITEM URL: " << item.url; if (item.description.isEmpty()) { kDebug() << "Suggestion"; diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index c3efb903..c95557cf 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -70,7 +70,8 @@ UrlResolver::UrlResolver(const QString &typedUrl) : QObject() , _typedString(typedUrl.trimmed()) { - if (!_searchEngine ) setSearchEngine(SearchEngine::defaultEngine()); + if (!_searchEngine ) + setSearchEngine(SearchEngine::defaultEngine()); if ( _browseRegexp.isEmpty() ) { @@ -196,8 +197,8 @@ UrlSearchList UrlResolver::orderLists() UrlSearchList common; int commonCount = 0; - //prefer items which are history items als well bookmarks item - //if there are more than 1000 bookmark results, the performance impact is noticeable + // prefer items which are history items as well bookmarks item + // if there are more than 1000 bookmark results, the performance impact is noticeable if(bookmarksCount < 1000) { //add as many items to the common list as there are available entries in the dropdown list @@ -316,7 +317,7 @@ UrlSearchList UrlResolver::orderLists() // PRIVATE ENGINES -//QUrl from User Input (easily the best solution... ) +// QUrl from User Input (easily the best solution... ) void UrlResolver::computeQurlFromUserInput() { QString url = _typedString; @@ -330,7 +331,7 @@ void UrlResolver::computeQurlFromUserInput() } -//webSearches +// webSearches void UrlResolver::computeWebSearches() { QString query = _typedString; @@ -341,11 +342,17 @@ void UrlResolver::computeWebSearches() _searchEngine = engine; } - _webSearches = (UrlSearchList() << UrlSearchItem(UrlSearchItem::Search, SearchEngine::buildQuery(_searchEngine, query), _searchEngine->name())); + if(_searchEngine) + { + UrlSearchItem item = UrlSearchItem(UrlSearchItem::Search, SearchEngine::buildQuery(_searchEngine, query), _searchEngine->name()); + UrlSearchList list; + list << item; + _webSearches = list; + } } -//history +// history void UrlResolver::computeHistory() { QList found = Application::historyManager()->find(_typedString); @@ -375,7 +382,7 @@ void UrlResolver::computeBookmarks() } -//opensearch suggestion +// opensearch suggestion void UrlResolver::computeSuggestions() { // if a string startsWith /, it is probably a local path @@ -405,6 +412,7 @@ void UrlResolver::suggestionsReceived(const QString &text, const ResponseList &s Q_FOREACH(const Response &i, suggestions) { + kDebug() << "RESPONSE URL: " << i.url; UrlSearchItem gItem(UrlSearchItem::Suggestion, i.url, i.title, i.description, i.image, i.image_width, i.image_height); sugList << gItem; } diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index 3e8e4fce..e21e65e8 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -30,6 +30,8 @@ // Rekonq Includes #include "rekonq_defines.h" + +// Locale Includes #include "application.h" #include "opensearchmanager.h" @@ -87,7 +89,7 @@ public: UrlSearchItem(const int &_type, const QString &_url, const QString &_title = QString(), - const QString &_description = QString(), + const QString &_description = QString(), const QString &_image = QString(), const int &_image_width = 0, const int &_image_height = 0 @@ -130,7 +132,8 @@ public: static void setSearchEngine(KService::Ptr engine) { _searchEngine = engine; - Application::opensearchManager()->setSearchProvider(engine->desktopEntryName()); + if(engine) + Application::opensearchManager()->setSearchProvider(engine->desktopEntryName()); }; void computeSuggestions(); -- cgit v1.2.1