summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2012-03-21 14:11:49 (GMT)
committerChristian Franke <nobody@nowhere.ws>2012-03-21 14:20:18 (GMT)
commit91cf04d9257908169e59fb052c2a77b65252004f (patch)
treeaf26aa2d5112488e4f5c35c54baba34501956ea1
parent966c8701a7c90342d220f4a0374e1e1290c0c393 (diff)
use requestSearchResults also in loadString
-rw-r--r--autotests/opensearchmanager/tst_opensearchmanager.cpp11
-rw-r--r--src/opensearchmanager.cpp14
-rw-r--r--src/opensearchmanager.h2
-rw-r--r--src/tabwidget.cpp35
-rw-r--r--src/tabwidget.h1
5 files changed, 30 insertions, 33 deletions
diff --git a/autotests/opensearchmanager/tst_opensearchmanager.cpp b/autotests/opensearchmanager/tst_opensearchmanager.cpp
index bf56cc6..a955af1 100644
--- a/autotests/opensearchmanager/tst_opensearchmanager.cpp
+++ b/autotests/opensearchmanager/tst_opensearchmanager.cpp
@@ -43,8 +43,8 @@ private slots:
void generateEngineFileName();
void restoreDefaults();
void keywords();
- void convertKeywordSearchToUrl();
- void convertKeywordSearchToUrl_data();
+ void convertKeywordSearch();
+ void convertKeywordSearch_data();
};
class SubOpenSearchManager : public OpenSearchManager
@@ -307,7 +307,7 @@ void tst_OpenSearchManager::keywords()
}
}
-void tst_OpenSearchManager::convertKeywordSearchToUrl_data()
+void tst_OpenSearchManager::convertKeywordSearch_data()
{
QTest::addColumn<QString>("string");
QTest::addColumn<bool>("valid");
@@ -321,7 +321,7 @@ void tst_OpenSearchManager::convertKeywordSearchToUrl_data()
QTest::newRow("valid-0") << "foo searchstring" << true;
}
-void tst_OpenSearchManager::convertKeywordSearchToUrl()
+void tst_OpenSearchManager::convertKeywordSearch()
{
QFETCH(QString, string);
QFETCH(bool, valid);
@@ -334,7 +334,8 @@ void tst_OpenSearchManager::convertKeywordSearchToUrl()
OpenSearchEngine *engine2 = manager.engine(manager.allEnginesNames().at(1));
manager.setEngineForKeyword("baz", engine2);
- QCOMPARE(manager.convertKeywordSearchToUrl(string).isValid(), valid);
+ QString terms;
+ QCOMPARE(!!manager.convertKeywordSearch(string, terms), valid);
}
QTEST_MAIN(tst_OpenSearchManager)
diff --git a/src/opensearchmanager.cpp b/src/opensearchmanager.cpp
index d9bb0a2..c672528 100644
--- a/src/opensearchmanager.cpp
+++ b/src/opensearchmanager.cpp
@@ -355,21 +355,19 @@ void OpenSearchManager::engineFromUrlAvailable()
}
}
-QUrl OpenSearchManager::convertKeywordSearchToUrl(const QString &string)
+OpenSearchEngine *OpenSearchManager::convertKeywordSearch(const QString &string,
+ QString &terms)
{
int i = string.indexOf(QLatin1Char(' '));
if (i <= 0)
- return QUrl();
+ return 0;
const QString keyword = string.left(i);
- const QString terms = string.mid(i + 1);
+ terms = QString(string.mid(i + 1));
if (terms.isEmpty())
- return QUrl();
-
- if (OpenSearchEngine *engine = engineForKeyword(keyword))
- return engine->searchUrl(terms);
+ return 0;
- return QUrl();
+ return engineForKeyword(keyword);
}
OpenSearchEngine *OpenSearchManager::engineForKeyword(const QString &keyword) const
diff --git a/src/opensearchmanager.h b/src/opensearchmanager.h
index 1d3f33c..6852c94 100644
--- a/src/opensearchmanager.h
+++ b/src/opensearchmanager.h
@@ -60,7 +60,7 @@ public:
bool engineExists(const QString &name);
- QUrl convertKeywordSearchToUrl(const QString &string);
+ OpenSearchEngine *convertKeywordSearch(const QString &string, QString &terms);
OpenSearchEngine *engineForKeyword(const QString &keyword) const;
void setEngineForKeyword(const QString &keyword, OpenSearchEngine *engine);
diff --git a/src/tabwidget.cpp b/src/tabwidget.cpp
index 015c770..be73558 100644
--- a/src/tabwidget.cpp
+++ b/src/tabwidget.cpp
@@ -810,21 +810,18 @@ void TabWidget::loadString(const QString &string, OpenUrlIn tab)
if (string.isEmpty())
return;
- QUrl url = guessUrlFromString(string);
- loadUrl(url, tab);
-}
-
-QUrl TabWidget::guessUrlFromString(const QString &string)
-{
OpenSearchManager *manager = ToolbarSearch::openSearchManager();
- QUrl url = manager->convertKeywordSearchToUrl(string);
- if (url.isValid())
- return url;
+ QString terms;
+ OpenSearchEngine *engine = manager->convertKeywordSearch(string, terms);
+ if (engine) {
+ performSearch(terms, tab, engine);
+ return;
+ }
#if QT_VERSION >= 0x040600
- url = QUrl::fromUserInput(string);
+ QUrl url = QUrl::fromUserInput(string);
#else
- url = WebView::guessUrlFromString(string);
+ QUrl url = WebView::guessUrlFromString(string);
#endif
if (url.scheme() == QLatin1String("about")
@@ -833,21 +830,23 @@ QUrl TabWidget::guessUrlFromString(const QString &string)
// QUrl::isValid() is too much tolerant.
// We actually want to check if the url conforms to the RFC, which QUrl::isValid() doesn't state.
- if (!url.scheme().isEmpty() && (!url.host().isEmpty() || !url.path().isEmpty()))
- return url;
+ if (!url.scheme().isEmpty() && (!url.host().isEmpty() || !url.path().isEmpty())) {
+ loadUrl(url, tab);
+ return;
+ }
QSettings settings;
settings.beginGroup(QLatin1String("urlloading"));
bool search = settings.value(QLatin1String("searchEngineFallback"), false).toBool();
if (search) {
- url = ToolbarSearch::openSearchManager()->currentEngine()->searchUrl(string.trimmed());
- } else {
- QString urlString = QLatin1String("http://") + string.trimmed();
- url = QUrl::fromEncoded(urlString.toUtf8(), QUrl::TolerantMode);
+ performSearch(string.trimmed(), tab);
+ return;
}
- return url;
+ QString urlString = QLatin1String("http://") + string.trimmed();
+ url = QUrl::fromEncoded(urlString.toUtf8(), QUrl::TolerantMode);
+ loadUrl(url,tab);
}
/*
diff --git a/src/tabwidget.h b/src/tabwidget.h
index ee1a3b3..75dce42 100644
--- a/src/tabwidget.h
+++ b/src/tabwidget.h
@@ -189,7 +189,6 @@ private slots:
void historyCleared();
private:
- static QUrl guessUrlFromString(const QString &url);
QLabel *animationLabel(int index, bool addMovie);
void retranslate();