From 974f6ddd2e4bcb52986af4aaf89b7ad86fd5c182 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 26 Jul 2012 17:36:31 +0200 Subject: Added NEW UrlResolver class (from kwebapp) and SearchEngine old one... --- src/urlresolver.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/urlresolver.cpp (limited to 'src/urlresolver.cpp') diff --git a/src/urlresolver.cpp b/src/urlresolver.cpp new file mode 100644 index 00000000..c56e5a94 --- /dev/null +++ b/src/urlresolver.cpp @@ -0,0 +1,98 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2012 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 "searchengine.h" + +// KDE Includes +#include +#include +#include + +// Qt Includes +#include + +#define QL1S(x) QLatin1String(x) + + +// NOTE +// default kurifilter plugin list (at least in my box): +// 1. "kshorturifilter" +// 2. "kurisearchfilter" +// 3. "localdomainurifilter" +// 4 ."kuriikwsfilter" +// 5. "fixhosturifilter" + + +KUrl UrlResolver::urlFromTextTyped(const QString &typedText) +{ + QString typedString = typedText.trimmed(); + + // Url from KService + KService::Ptr engine = SearchEngine::fromString(typedString); + if (engine) + { + QString query = typedString; + query = query.remove(0, typedString.indexOf(SearchEngine::delimiter()) + 1); + + QString url = SearchEngine::buildQuery(engine, query); + + kDebug() << "Url from service: " << url; + return KUrl(url); + } + + // Url from User Input + QUrl urlFromUserInput = QUrl::fromUserInput(typedString); + if (urlFromUserInput.isValid()) + { + // ensure http(s) hosts are lower cases + if (urlFromUserInput.scheme().startsWith(QL1S("http"))) + { + QString hst = urlFromUserInput.host(); + urlFromUserInput.setHost(hst.toLower()); + } + + kDebug() << "(Q)Url from user input: " << urlFromUserInput; + return urlFromUserInput; + } + + // failed... + kDebug() << "KUrl fallback: " << typedText; + return KUrl(typedText); +} + + +bool UrlResolver::isKDEUrl(const QString &urlString) +{ + KService::Ptr engine = SearchEngine::fromString(urlString); + if (engine) + return true; + + return false; +} -- cgit v1.2.1