From 942c55b945443a2e6dd9a2d3660347fc2176630a Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 29 Mar 2010 11:47:42 +0200 Subject: This commit merge all our work about new UrlBar. DISCLAIMER: this is far from perfect, but we finally have a good starting point to work on.. :) Jonas Gastal started working on it in the 0.3 times, startin from CompletionBase code .. .. I did some work on another idea, proposing (in code) a new "suggest engine" created from scratch... Lionel Chauvin finally merged our ideas and implemented what you are seeing (and improved it, too!).. - New suggestion items (Firefox style) - a mockup on the known urls (rekonq style) - for now, automatic Google and Wikipedia searches (more coming).. - a beautiful animation :) - quite all rough edges smoothed -------------------------------------------------------- Squashed commit of the following: commit d9cf43da421c7f6c71f78444ff1935c414468b98 commit 9dcb6e18f8a3e9ae8ef1cd1299d47d37393aa6e5 commit 6c4bf2b2040ea20c78c5703f20c6bc88b7e40169 commit 8488df67115d186489f34210b638c150c66f62d3 commit 066ab907661282b1ffa4cf640739c20b4c7b6556 commit c23e23cbca7ab3197c570651a95d3f8fea270d78 commit 60655b0a8685a76e2b8b7a457bfded974bc98b4c commit 9a8817db124b55f501c9e5d3415a975ee6f92d68 commit 61312b6b577a535a4d56758b3bd3ea38812d5139 commit b6a3f4ea12423a063eafa641cedd13b890b9d392 commit 5e8e2f851edb42bc2deed296c26c58c3d7570381 commit 2904d828f71ac8ff46a53e58da8f45b5aa16e7ef --------------------------------------------------------- --- src/urlbar/urlresolver.cpp | 177 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 src/urlbar/urlresolver.cpp (limited to 'src/urlbar/urlresolver.cpp') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp new file mode 100644 index 00000000..b2bf50af --- /dev/null +++ b/src/urlbar/urlresolver.cpp @@ -0,0 +1,177 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + + +// Self Includes +#include "urlresolver.h" + +// Local Includes +#include "application.h" +#include "historymanager.h" +#include "bookmarksmanager.h" + +// KDE Includes +#include +#include +#include +#include +#include +#include + +// Qt Includes +#include +#include +#include + + +// NOTE default kurifilter plugin list (at least in my box) +// 1. "kshorturifilter" +// 2. "kurisearchfilter" +// 3. "localdomainurifilter" +// 4 ."kuriikwsfilter" +// 5. "fixhosturifilter" + + +UrlResolver::UrlResolver(const QString &typedUrl) + : _urlString(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 :) + + UrlSearchList list; + + list << qurlFromUserInputResolution(); + list << webSearchesResolution(); + int firstResults = list.count(); + int checkPoint = 9 - firstResults; + + UrlSearchList historyList = historyResolution(); + int historyResults = historyList.count(); + + UrlSearchList bookmarksList = bookmarksResolution(); + int bookmarkResults = bookmarksList.count(); + + if(historyResults + bookmarkResults > checkPoint) + { + historyList = historyList.mid(0,3); + bookmarksList = bookmarksList.mid(0,3); + } + list << historyList; + list << bookmarksList; + + return list; +} + + +////////////////////////////////////////////////////////////////////////// +// PRIVATE ENGINES + + +// STEP 1 = QUrl from User Input (easily the best solution... ) +UrlSearchList UrlResolver::qurlFromUserInputResolution() +{ + UrlSearchList list; + + QString url2 = _urlString; + QUrl urlFromUserInput = QUrl::fromUserInput(url2); + if(urlFromUserInput.isValid()) + { + QByteArray ba = urlFromUserInput.toEncoded(); + if(!ba.isEmpty()) + { + QString str(ba); + UrlSearchItem it(str); + list << it; + } + } + + return list; +} + + +// STEP 2 = Web Searches +UrlSearchList UrlResolver::webSearchesResolution() +{ + UrlSearchList list; + + QString url1 = _urlString; + if(KUrl(url1).isRelative() && !url1.contains('.')) + { + // KUriFilter has the worst performance possible here and let this trick unusable + QString gUrl = QString("http://www.google.com/search?q=%1&ie=UTF-8&oe=UTF-8").arg(url1); + QString gTitle = i18n("Search Google for ") + url1; + UrlSearchItem gItem(gUrl, gTitle, QString("http://www.google.com") ); + list << gItem; + + QString wUrl = QString("http://en.wikipedia.org/wiki/Special:Search?search=%1&go=Go").arg(url1); + QString wTitle = i18n("Search Wikipedia for ") + url1; + UrlSearchItem wItem(wUrl, wTitle, QString("http://wikipedia.org") ); + list << wItem; + } + + return list; +} + + +// STEP 3 = history completion +UrlSearchList UrlResolver::historyResolution() +{ + UrlSearchList list; + + KCompletion *historyCompletion = Application::historyManager()->completionObject(); + QStringList historyResults = historyCompletion->substringCompletion(_urlString); + Q_FOREACH(const QString &s, historyResults) + { + UrlSearchItem it(s, s, QString("view-history")); + list << it; + } + + return list; +} + + +// STEP 4 = bookmarks completion +UrlSearchList UrlResolver::bookmarksResolution() +{ + UrlSearchList list; + + KCompletion *bookmarkCompletion = Application::bookmarkProvider()->completionObject(); + QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString); + Q_FOREACH(const QString &s, bookmarkResults) + { + UrlSearchItem it( s, QString(), QString("rating") ); + list << it; + } + + return list; +} -- cgit v1.2.1 From 0daaf2f04b4e2be4c8a63f6008b4653ea08e1054 Mon Sep 17 00:00:00 2001 From: megabigbug Date: Mon, 29 Mar 2010 21:33:44 +0200 Subject: detect if user type an url and order the results accordingly --- src/urlbar/urlresolver.cpp | 48 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'src/urlbar/urlresolver.cpp') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index b2bf50af..3f87b989 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -70,8 +70,17 @@ UrlSearchList UrlResolver::orderedSearchItems() UrlSearchList list; - list << qurlFromUserInputResolution(); - list << webSearchesResolution(); + if(isHttp()) + { + list << qurlFromUserInputResolution(); + list << webSearchesResolution(); + } + else + { + list << webSearchesResolution(); + list << qurlFromUserInputResolution(); + } + int firstResults = list.count(); int checkPoint = 9 - firstResults; @@ -93,6 +102,21 @@ UrlSearchList UrlResolver::orderedSearchItems() } +bool UrlResolver::isHttp() +{ + QString r = "[\\d\\w-.]+\\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|"\ + "c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|"\ + "h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|"\ + "m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|"\ + "s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|"\ + "y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|"\ + "pro)"; + + return (QRegExp(r, Qt::CaseInsensitive).indexIn(_urlString) != -1) + || _urlString.startsWith("http:") + || _urlString.startsWith("https:"); +} + ////////////////////////////////////////////////////////////////////////// // PRIVATE ENGINES @@ -108,10 +132,12 @@ UrlSearchList UrlResolver::qurlFromUserInputResolution() { QByteArray ba = urlFromUserInput.toEncoded(); if(!ba.isEmpty()) - { - QString str(ba); - UrlSearchItem it(str); - list << it; + { + QString gUrl = QString(ba); + QString gTitle = i18n("Browse"); + UrlSearchItem gItem(gUrl, gTitle, QString("") ); + list << gItem; + } } @@ -125,7 +151,7 @@ UrlSearchList UrlResolver::webSearchesResolution() UrlSearchList list; QString url1 = _urlString; - if(KUrl(url1).isRelative() && !url1.contains('.')) + if(KUrl(url1).isRelative()) { // KUriFilter has the worst performance possible here and let this trick unusable QString gUrl = QString("http://www.google.com/search?q=%1&ie=UTF-8&oe=UTF-8").arg(url1); @@ -133,10 +159,10 @@ UrlSearchList UrlResolver::webSearchesResolution() UrlSearchItem gItem(gUrl, gTitle, QString("http://www.google.com") ); list << gItem; - QString wUrl = QString("http://en.wikipedia.org/wiki/Special:Search?search=%1&go=Go").arg(url1); - QString wTitle = i18n("Search Wikipedia for ") + url1; - UrlSearchItem wItem(wUrl, wTitle, QString("http://wikipedia.org") ); - list << wItem; +// QString wUrl = QString("http://en.wikipedia.org/wiki/Special:Search?search=%1&go=Go").arg(url1); +// QString wTitle = i18n("Search Wikipedia for ") + url1; +// UrlSearchItem wItem(wUrl, wTitle, QString("http://wikipedia.org") ); +// list << wItem; } return list; -- cgit v1.2.1 From b1f39e13b1d2199b2f8a9bef3c213715a36dd146 Mon Sep 17 00:00:00 2001 From: megabigbug Date: Mon, 29 Mar 2010 23:20:37 +0200 Subject: add title for bookmarks in the list --- src/urlbar/urlresolver.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/urlbar/urlresolver.cpp') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 3f87b989..cb61ad95 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -195,9 +195,10 @@ UrlSearchList UrlResolver::bookmarksResolution() QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, bookmarkResults) { - UrlSearchItem it( s, QString(), QString("rating") ); + UrlSearchItem it( s, Application::bookmarkProvider()->titleForBookmarkUrl(s), QString("rating") ); list << it; } + return list; } -- cgit v1.2.1 From 45acb07245d52a51e5b486eaab3c4fdddc2ccbad Mon Sep 17 00:00:00 2001 From: lionelc Date: Tue, 30 Mar 2010 11:01:44 +0200 Subject: display bookmark and history item only if string typed is longer than 3 chars --- src/urlbar/urlresolver.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'src/urlbar/urlresolver.cpp') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index cb61ad95..5593f566 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -81,23 +81,26 @@ UrlSearchList UrlResolver::orderedSearchItems() list << qurlFromUserInputResolution(); } - int firstResults = list.count(); - int checkPoint = 9 - firstResults; - - UrlSearchList historyList = historyResolution(); - int historyResults = historyList.count(); - - UrlSearchList bookmarksList = bookmarksResolution(); - int bookmarkResults = bookmarksList.count(); - - if(historyResults + bookmarkResults > checkPoint) + if (_urlString.length()>2) { - historyList = historyList.mid(0,3); - bookmarksList = bookmarksList.mid(0,3); + int firstResults = list.count(); + int checkPoint = 9 - firstResults; + + UrlSearchList historyList = historyResolution(); + int historyResults = historyList.count(); + + UrlSearchList bookmarksList = bookmarksResolution(); + int bookmarkResults = bookmarksList.count(); + + if(historyResults + bookmarkResults > checkPoint) + { + historyList = historyList.mid(0,3); + bookmarksList = bookmarksList.mid(0,3); + } + list << historyList; + list << bookmarksList; } - list << historyList; - list << bookmarksList; - + return list; } -- cgit v1.2.1 From a2cb9efc54c78c47e41196f0121ca00255a4a7ab Mon Sep 17 00:00:00 2001 From: lionelc Date: Tue, 30 Mar 2010 11:37:25 +0200 Subject: add title for history items --- src/urlbar/urlresolver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/urlbar/urlresolver.cpp') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 5593f566..3877a6c2 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -181,7 +181,7 @@ UrlSearchList UrlResolver::historyResolution() QStringList historyResults = historyCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, historyResults) { - UrlSearchItem it(s, s, QString("view-history")); + UrlSearchItem it(s, Application::historyManager()->titleForHistoryUrl(s), QString("view-history")); list << it; } -- cgit v1.2.1 From a2aa033e21d1746b5479836e8d8363dcb4654d8a Mon Sep 17 00:00:00 2001 From: lionelc Date: Tue, 30 Mar 2010 19:45:27 +0200 Subject: manage common item of bookmarks and history --- src/urlbar/urlresolver.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/urlbar/urlresolver.cpp') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 3877a6c2..ef071c30 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -53,6 +53,10 @@ // 4 ."kuriikwsfilter" // 5. "fixhosturifilter" +bool UrlSearchItem::operator==(UrlSearchItem i) +{ + return url==i.url; +} UrlResolver::UrlResolver(const QString &typedUrl) : _urlString(typedUrl) @@ -97,8 +101,27 @@ UrlSearchList UrlResolver::orderedSearchItems() historyList = historyList.mid(0,3); bookmarksList = bookmarksList.mid(0,3); } - list << historyList; - list << bookmarksList; + + QList common; + + foreach (UrlSearchItem i, historyList) + { + if (!bookmarksList.contains(i)) + list << i; + else + common << i; + } + + foreach (UrlSearchItem i, common) + { + list << i; + } + + foreach (UrlSearchItem i, bookmarksList) + { + if (!common.contains(i)) + list << i; + } } return list; -- cgit v1.2.1 From b18f2e5dfcc17615d73fdbd20cb4e312ea83dfaf Mon Sep 17 00:00:00 2001 From: lionelc Date: Thu, 1 Apr 2010 19:53:18 +0200 Subject: multiple icons for type of items display icon of website --- src/urlbar/urlresolver.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/urlbar/urlresolver.cpp') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index ef071c30..ff90ce14 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -45,6 +45,7 @@ #include #include +#define MAX_ELEMENTS 9 // NOTE default kurifilter plugin list (at least in my box) // 1. "kshorturifilter" @@ -106,10 +107,15 @@ UrlSearchList UrlResolver::orderedSearchItems() foreach (UrlSearchItem i, historyList) { - if (!bookmarksList.contains(i)) + if (!bookmarksList.contains(i)) + { list << i; + } else + { + i.type |= UrlSearchItem::Bookmark; common << i; + } } foreach (UrlSearchItem i, common) @@ -161,7 +167,7 @@ UrlSearchList UrlResolver::qurlFromUserInputResolution() { QString gUrl = QString(ba); QString gTitle = i18n("Browse"); - UrlSearchItem gItem(gUrl, gTitle, QString("") ); + UrlSearchItem gItem(UrlSearchItem::Browse, gUrl, gTitle, QString("") ); list << gItem; } @@ -182,7 +188,7 @@ UrlSearchList UrlResolver::webSearchesResolution() // KUriFilter has the worst performance possible here and let this trick unusable QString gUrl = QString("http://www.google.com/search?q=%1&ie=UTF-8&oe=UTF-8").arg(url1); QString gTitle = i18n("Search Google for ") + url1; - UrlSearchItem gItem(gUrl, gTitle, QString("http://www.google.com") ); + UrlSearchItem gItem(UrlSearchItem::Search, gUrl, gTitle, QString("http://www.google.com") ); list << gItem; // QString wUrl = QString("http://en.wikipedia.org/wiki/Special:Search?search=%1&go=Go").arg(url1); @@ -204,7 +210,7 @@ UrlSearchList UrlResolver::historyResolution() QStringList historyResults = historyCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, historyResults) { - UrlSearchItem it(s, Application::historyManager()->titleForHistoryUrl(s), QString("view-history")); + UrlSearchItem it(UrlSearchItem::History, s, Application::historyManager()->titleForHistoryUrl(s), QString("view-history")); list << it; } @@ -221,7 +227,7 @@ UrlSearchList UrlResolver::bookmarksResolution() QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, bookmarkResults) { - UrlSearchItem it( s, Application::bookmarkProvider()->titleForBookmarkUrl(s), QString("rating") ); + UrlSearchItem it(UrlSearchItem::Bookmark, s, Application::bookmarkProvider()->titleForBookmarkUrl(s), QString("rating") ); list << it; } -- cgit v1.2.1 From 138801dfa40b1bbbbbf0ce6a5bd8e04977b9ccdc Mon Sep 17 00:00:00 2001 From: pano Date: Sun, 11 Apr 2010 12:55:15 +0200 Subject: fix strings --- src/urlbar/urlresolver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/urlbar/urlresolver.cpp') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index ff90ce14..5f025cb5 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -187,12 +187,12 @@ UrlSearchList UrlResolver::webSearchesResolution() { // KUriFilter has the worst performance possible here and let this trick unusable QString gUrl = QString("http://www.google.com/search?q=%1&ie=UTF-8&oe=UTF-8").arg(url1); - QString gTitle = i18n("Search Google for ") + url1; + QString gTitle = i18n("Search Google for %1", url1); UrlSearchItem gItem(UrlSearchItem::Search, gUrl, gTitle, QString("http://www.google.com") ); list << gItem; // QString wUrl = QString("http://en.wikipedia.org/wiki/Special:Search?search=%1&go=Go").arg(url1); -// QString wTitle = i18n("Search Wikipedia for ") + url1; +// QString wTitle = i18n("Search Wikipedia for %1", url1); // UrlSearchItem wItem(wUrl, wTitle, QString("http://wikipedia.org") ); // list << wItem; } -- cgit v1.2.1 From d2b1a62a0ecdd286b9d83275170a3322ffafd32c Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 12 Apr 2010 02:00:13 +0200 Subject: URLBAR ANIMATION: implementation fix This commit follows the logic explained somewhere else, moving rekonq to a better management for urls from user input. 1) users type strings --> we store them in QStrings 2) app load urls --> we should ever work with KUrls, trying to guess users needs Here I also removed the unuseful QString icon from UrlSearchItem definition, as we just have a type (Search, Browse, History, Books..), a (k)url and an Application::icon method :) --- src/urlbar/urlresolver.cpp | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'src/urlbar/urlresolver.cpp') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 5f025cb5..4ff6b461 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -60,7 +60,7 @@ bool UrlSearchItem::operator==(UrlSearchItem i) } UrlResolver::UrlResolver(const QString &typedUrl) - : _urlString(typedUrl) + : _urlString( typedUrl.trimmed() ) { } @@ -162,15 +162,10 @@ UrlSearchList UrlResolver::qurlFromUserInputResolution() QUrl urlFromUserInput = QUrl::fromUserInput(url2); if(urlFromUserInput.isValid()) { - QByteArray ba = urlFromUserInput.toEncoded(); - if(!ba.isEmpty()) - { - QString gUrl = QString(ba); - QString gTitle = i18n("Browse"); - UrlSearchItem gItem(UrlSearchItem::Browse, gUrl, gTitle, QString("") ); - list << gItem; - - } + KUrl gUrl(urlFromUserInput); + QString gTitle = i18n("Browse"); + UrlSearchItem gItem(UrlSearchItem::Browse, gUrl, gTitle); + list << gItem; } return list; @@ -182,19 +177,14 @@ UrlSearchList UrlResolver::webSearchesResolution() { UrlSearchList list; - QString url1 = _urlString; - if(KUrl(url1).isRelative()) + KUrl url1(_urlString); + if(url1.isRelative()) { // KUriFilter has the worst performance possible here and let this trick unusable - QString gUrl = QString("http://www.google.com/search?q=%1&ie=UTF-8&oe=UTF-8").arg(url1); - QString gTitle = i18n("Search Google for %1", url1); - UrlSearchItem gItem(UrlSearchItem::Search, gUrl, gTitle, QString("http://www.google.com") ); + KUrl gUrl( QString("gg:") + _urlString ); + QString gTitle = i18n("Search Google for %1", _urlString); + UrlSearchItem gItem(UrlSearchItem::Search, gUrl, gTitle ); list << gItem; - -// QString wUrl = QString("http://en.wikipedia.org/wiki/Special:Search?search=%1&go=Go").arg(url1); -// QString wTitle = i18n("Search Wikipedia for %1", url1); -// UrlSearchItem wItem(wUrl, wTitle, QString("http://wikipedia.org") ); -// list << wItem; } return list; @@ -210,7 +200,7 @@ UrlSearchList UrlResolver::historyResolution() QStringList historyResults = historyCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, historyResults) { - UrlSearchItem it(UrlSearchItem::History, s, Application::historyManager()->titleForHistoryUrl(s), QString("view-history")); + UrlSearchItem it(UrlSearchItem::History, KUrl(s), Application::historyManager()->titleForHistoryUrl(s) ); //, QString("view-history")); list << it; } @@ -227,7 +217,7 @@ UrlSearchList UrlResolver::bookmarksResolution() QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, bookmarkResults) { - UrlSearchItem it(UrlSearchItem::Bookmark, s, Application::bookmarkProvider()->titleForBookmarkUrl(s), QString("rating") ); + UrlSearchItem it(UrlSearchItem::Bookmark, KUrl(s), Application::bookmarkProvider()->titleForBookmarkUrl(s) ); //, QString("rating") ); list << it; } -- cgit v1.2.1 From ee9fc135d6ee214e999aebebb59459fce9147b38 Mon Sep 17 00:00:00 2001 From: lionelc Date: Thu, 15 Apr 2010 18:36:07 +0200 Subject: introduce search listitem --- src/urlbar/urlresolver.cpp | 58 +++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 34 deletions(-) (limited to 'src/urlbar/urlresolver.cpp') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 4ff6b461..fd4cdfcb 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -60,7 +60,7 @@ bool UrlSearchItem::operator==(UrlSearchItem i) } UrlResolver::UrlResolver(const QString &typedUrl) - : _urlString( typedUrl.trimmed() ) + : _urlString(typedUrl.trimmed()) { } @@ -78,19 +78,15 @@ UrlSearchList UrlResolver::orderedSearchItems() if(isHttp()) { list << qurlFromUserInputResolution(); - list << webSearchesResolution(); - } - else - { - list << webSearchesResolution(); - list << qurlFromUserInputResolution(); } + + list << webSearchesResolution(); if (_urlString.length()>2) { int firstResults = list.count(); int checkPoint = 9 - firstResults; - + UrlSearchList historyList = historyResolution(); int historyResults = historyList.count(); @@ -136,7 +132,12 @@ UrlSearchList UrlResolver::orderedSearchItems() bool UrlResolver::isHttp() { - QString r = "[\\d\\w-.]+\\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|"\ + QString ipv4 = "^0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])"\ + "\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])"; + + QString ipv6 = "^([0-9a-fA-F]{4}|0)(\\:([0-9a-fA-F]{4}|0)){7}"; + + QString address = "[\\d\\w-.]+\\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|"\ "c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|"\ "h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|"\ "m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|"\ @@ -144,9 +145,11 @@ bool UrlResolver::isHttp() "y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|"\ "pro)"; - return (QRegExp(r, Qt::CaseInsensitive).indexIn(_urlString) != -1) - || _urlString.startsWith("http:") - || _urlString.startsWith("https:"); + return _urlString.startsWith("http://") + || _urlString.startsWith("https://") + || (QRegExp(address, Qt::CaseInsensitive).indexIn(_urlString) != -1) + || (QRegExp(ipv4, Qt::CaseInsensitive).indexIn(_urlString) != -1) + || (QRegExp(ipv6, Qt::CaseInsensitive).indexIn(_urlString) != -1); } ////////////////////////////////////////////////////////////////////////// @@ -156,19 +159,8 @@ bool UrlResolver::isHttp() // STEP 1 = QUrl from User Input (easily the best solution... ) UrlSearchList UrlResolver::qurlFromUserInputResolution() { - UrlSearchList list; - - QString url2 = _urlString; - QUrl urlFromUserInput = QUrl::fromUserInput(url2); - if(urlFromUserInput.isValid()) - { - KUrl gUrl(urlFromUserInput); - QString gTitle = i18n("Browse"); - UrlSearchItem gItem(UrlSearchItem::Browse, gUrl, gTitle); - list << gItem; - } - - return list; + UrlSearchItem gItem(UrlSearchItem::Browse, KUrl(_urlString), QString()); + return UrlSearchList() << gItem; } @@ -176,14 +168,12 @@ UrlSearchList UrlResolver::qurlFromUserInputResolution() UrlSearchList UrlResolver::webSearchesResolution() { UrlSearchList list; - - KUrl url1(_urlString); - if(url1.isRelative()) + + if(KUrl(_urlString).isRelative()) { - // KUriFilter has the worst performance possible here and let this trick unusable - KUrl gUrl( QString("gg:") + _urlString ); - QString gTitle = i18n("Search Google for %1", _urlString); - UrlSearchItem gItem(UrlSearchItem::Search, gUrl, gTitle ); + QString gUrl = QString("http://www.google.com/search?q=%1&ie=UTF-8&oe=UTF-8").arg(_urlString); + QString gTitle = i18n("Search Google for ") + _urlString; + UrlSearchItem gItem(UrlSearchItem::Search, KUrl(), gTitle); list << gItem; } @@ -200,7 +190,7 @@ UrlSearchList UrlResolver::historyResolution() QStringList historyResults = historyCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, historyResults) { - UrlSearchItem it(UrlSearchItem::History, KUrl(s), Application::historyManager()->titleForHistoryUrl(s) ); //, QString("view-history")); + UrlSearchItem it(UrlSearchItem::History, KUrl(s), Application::historyManager()->titleForHistoryUrl(s)); list << it; } @@ -217,7 +207,7 @@ UrlSearchList UrlResolver::bookmarksResolution() QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, bookmarkResults) { - UrlSearchItem it(UrlSearchItem::Bookmark, KUrl(s), Application::bookmarkProvider()->titleForBookmarkUrl(s) ); //, QString("rating") ); + UrlSearchItem it(UrlSearchItem::Bookmark, KUrl(s), Application::bookmarkProvider()->titleForBookmarkUrl(s)); list << it; } -- cgit v1.2.1 From 72e0446fbc7017e7703102f733568a4f2e3c5195 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 16 Apr 2010 03:14:48 +0200 Subject: Fixing Lionel's merge request: - clean/fix APIs - removed no more used methods/signals from CompletionWidget - use item->url() (as it has been defined) - Change the "pointing out text" from underline to bold (better, IMO) - QString --> Q/K url, as needed - Restore UrlFromUserInput engine: why it has been deleted? - Comment out the isHttp() check. That way I cannot in any way connect to localhost or to my home server. Apart from typing their IPs.. - Partially fixed the switch search engine implementation. Btw, I have to say I really don't like rekonq switch my default engine just because one time I decided to give a try to another... Not sure about. - Something more coming.. But tomorrow! Now it's 3:20 am here. Good night! --- src/urlbar/urlresolver.cpp | 56 +++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'src/urlbar/urlresolver.cpp') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index fd4cdfcb..5b4b1625 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -45,8 +45,10 @@ #include #include +// defines #define MAX_ELEMENTS 9 + // NOTE default kurifilter plugin list (at least in my box) // 1. "kshorturifilter" // 2. "kurisearchfilter" @@ -54,13 +56,15 @@ // 4 ."kuriikwsfilter" // 5. "fixhosturifilter" + bool UrlSearchItem::operator==(UrlSearchItem i) { return url==i.url; } + UrlResolver::UrlResolver(const QString &typedUrl) - : _urlString(typedUrl.trimmed()) + : _typedString(typedUrl.trimmed()) { } @@ -75,15 +79,17 @@ UrlSearchList UrlResolver::orderedSearchItems() UrlSearchList list; - if(isHttp()) - { - list << qurlFromUserInputResolution(); - } +// if(isHttp()) +// { +// list << qurlFromUserInputResolution(); +// } list << webSearchesResolution(); - if (_urlString.length()>2) + if (_typedString.length() >= 2) { + list << qurlFromUserInputResolution(); + int firstResults = list.count(); int checkPoint = 9 - firstResults; @@ -145,13 +151,14 @@ bool UrlResolver::isHttp() "y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|"\ "pro)"; - return _urlString.startsWith("http://") - || _urlString.startsWith("https://") - || (QRegExp(address, Qt::CaseInsensitive).indexIn(_urlString) != -1) - || (QRegExp(ipv4, Qt::CaseInsensitive).indexIn(_urlString) != -1) - || (QRegExp(ipv6, Qt::CaseInsensitive).indexIn(_urlString) != -1); + return _typedString.startsWith("http://") + || _typedString.startsWith("https://") + || (QRegExp(address, Qt::CaseInsensitive).indexIn(_typedString) != -1) + || (QRegExp(ipv4, Qt::CaseInsensitive).indexIn(_typedString) != -1) + || (QRegExp(ipv6, Qt::CaseInsensitive).indexIn(_typedString) != -1); } + ////////////////////////////////////////////////////////////////////////// // PRIVATE ENGINES @@ -159,8 +166,18 @@ bool UrlResolver::isHttp() // STEP 1 = QUrl from User Input (easily the best solution... ) UrlSearchList UrlResolver::qurlFromUserInputResolution() { - UrlSearchItem gItem(UrlSearchItem::Browse, KUrl(_urlString), QString()); - return UrlSearchList() << gItem; + UrlSearchList list; + QString url2 = _typedString; + QUrl urlFromUserInput = QUrl::fromUserInput(url2); + if(urlFromUserInput.isValid()) + { + KUrl gUrl(urlFromUserInput); + QString gTitle = i18n("Browse"); + UrlSearchItem gItem(UrlSearchItem::Browse, gUrl, gTitle); + list << gItem; + } + + return list; } @@ -169,11 +186,9 @@ UrlSearchList UrlResolver::webSearchesResolution() { UrlSearchList list; - if(KUrl(_urlString).isRelative()) - { - QString gUrl = QString("http://www.google.com/search?q=%1&ie=UTF-8&oe=UTF-8").arg(_urlString); - QString gTitle = i18n("Search Google for ") + _urlString; - UrlSearchItem gItem(UrlSearchItem::Search, KUrl(), gTitle); + if(KUrl(_typedString).isRelative()) + { + UrlSearchItem gItem(UrlSearchItem::Search, KUrl(), QString() ); // others will find this url.. list << gItem; } @@ -187,7 +202,7 @@ UrlSearchList UrlResolver::historyResolution() UrlSearchList list; KCompletion *historyCompletion = Application::historyManager()->completionObject(); - QStringList historyResults = historyCompletion->substringCompletion(_urlString); + QStringList historyResults = historyCompletion->substringCompletion(_typedString); Q_FOREACH(const QString &s, historyResults) { UrlSearchItem it(UrlSearchItem::History, KUrl(s), Application::historyManager()->titleForHistoryUrl(s)); @@ -204,13 +219,12 @@ UrlSearchList UrlResolver::bookmarksResolution() UrlSearchList list; KCompletion *bookmarkCompletion = Application::bookmarkProvider()->completionObject(); - QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString); + QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_typedString); Q_FOREACH(const QString &s, bookmarkResults) { UrlSearchItem it(UrlSearchItem::Bookmark, KUrl(s), Application::bookmarkProvider()->titleForBookmarkUrl(s)); list << it; } - return list; } -- cgit v1.2.1