summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-07-26 17:36:31 +0200
committerAndrea Diamantini <adjam7@gmail.com>2012-12-10 02:48:04 +0100
commit974f6ddd2e4bcb52986af4aaf89b7ad86fd5c182 (patch)
tree9717473f76dd957859d2afb8cbf20aa89dd1b5d1 /src
parentRe-add && Re-view tab preview popup (diff)
downloadrekonq-974f6ddd2e4bcb52986af4aaf89b7ad86fd5c182.tar.xz
Added NEW UrlResolver class (from kwebapp) and SearchEngine old one...
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt9
-rw-r--r--src/main.cpp111
-rw-r--r--src/searchengine.cpp139
-rw-r--r--src/searchengine.h56
-rw-r--r--src/urlresolver.cpp98
-rw-r--r--src/urlresolver.h46
6 files changed, 457 insertions, 2 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0143874f..eeaf4ef3 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,6 +7,10 @@ ADD_SUBDIRECTORY( data )
set(rekonq_KDEINIT_SRCS
#----------------------------------------
+ searchengine.cpp
+ urlresolver.cpp
+ websnap.cpp
+ #----------------------------------------
tabwindow/tabbar.cpp
tabwindow/tabhighlighteffect.cpp
tabwindow/tabpreviewpopup.cpp
@@ -15,7 +19,6 @@ set(rekonq_KDEINIT_SRCS
webwindow/webpage.cpp
webwindow/webwindow.cpp
#----------------------------------------
- websnap.cpp
)
@@ -42,7 +45,9 @@ KDE4_ADD_APP_ICON( rekonq_KDEINIT_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../icons/hi*-
### --------------- ADDING EXECUTABLE...
# NOTE: This is the simple main used to test the tabwindow :)
-KDE4_ADD_KDEINIT_EXECUTABLE( rekonq ${rekonq_KDEINIT_SRCS} tabmain.cpp )
+# KDE4_ADD_KDEINIT_EXECUTABLE( rekonq ${rekonq_KDEINIT_SRCS} tabmain.cpp )
+
+KDE4_ADD_KDEINIT_EXECUTABLE( rekonq ${rekonq_KDEINIT_SRCS} main.cpp )
### --------------- TARGETTING LINK LIBRARIES...
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 00000000..5c55aa81
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,111 @@
+/***************************************************************************
+ * Copyright (C) 2012 by Andrea Diamantini <adjam7@gmail.com> *
+ * *
+ * 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) any later version. *
+ * *
+ * 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, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
+ ***************************************************************************/
+
+
+// version include
+#include "config-version.h"
+
+#include "tabwindow.h"
+#include "urlresolver.h"
+
+#include <KDE/KAboutData>
+#include <KDE/KApplication>
+#include <KDE/KCmdLineArgs>
+
+#include <QDir>
+#include <QUrl>
+#include <QWebSettings>
+
+
+static const char description[] =
+ I18N_NOOP("A lightweight Web Browser for KDE based on WebKit");
+
+
+extern "C" KDE_EXPORT int kdemain(int argc, char **argv)
+{
+ KAboutData about("rekonq",
+ 0,
+ ki18n("rekonq"),
+ REKONQ_VERSION,
+ ki18n(description),
+ KAboutData::License_GPL_V3,
+ ki18n("(C) 2008-2012 Andrea Diamantini"),
+ KLocalizedString(),
+ "http://rekonq.kde.org"
+ );
+
+ // Initialize command line args
+ KCmdLineArgs::init(argc, argv, &about);
+
+ // Define the command line options using KCmdLineOptions
+ KCmdLineOptions options;
+
+ // adding URL option
+ options.add("+[URL]" , ki18n("Location to open"));
+
+ // Register the supported options
+ KCmdLineArgs::addCmdLineOptions(options);
+
+// if (!Application::start())
+// {
+// kWarning() << "rekonq is already running!";
+// return 0;
+// }
+
+#if defined(Q_WS_X11)
+ // On X11, the raster engine gives better performance than native.
+ QApplication::setGraphicsSystem(QLatin1String("raster"));
+#endif
+
+ KApplication app;
+
+ QWebSettings::setIconDatabasePath("/tmp/iconcache");
+
+ // set application data
+ QCoreApplication::setApplicationName(QLatin1String("rekonq"));
+ QCoreApplication::setApplicationVersion(REKONQ_VERSION);
+
+ KCmdLineArgs::setCwd(QDir::currentPath().toUtf8());
+
+ TabWindow *w = new TabWindow;
+
+ // no session.. just start up normally
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ if (args->count() == 0)
+ {
+ w->newCleanTab();
+ w->show();
+ }
+ else
+ {
+ int i = 0;
+ for (; i < args->count(); i++)
+ {
+ w->loadUrlInNewTab( UrlResolver::urlFromTextTyped(args->arg(i)) );
+ }
+ w->show();
+ }
+ args->clear();
+
+// if (app.isSessionRestored())
+// for (int i = 1; MainWindow::canBeRestored(i); i++)
+// app.newMainWindow(false)->restore(i);
+
+ return app.exec();
+}
diff --git a/src/searchengine.cpp b/src/searchengine.cpp
new file mode 100644
index 00000000..6f7f6edc
--- /dev/null
+++ b/src/searchengine.cpp
@@ -0,0 +1,139 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr>
+*
+*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+// local includes
+#include "searchengine.h"
+
+//KDE includes
+#include <KConfigGroup>
+#include <KServiceTypeTrader>
+
+
+struct SearchEnginePrivate
+{
+ SearchEnginePrivate() : isLoaded(false) {}
+ bool isLoaded;
+ QString delimiter;
+ KService::List favorites;
+ KService::Ptr defaultEngine;
+};
+
+
+K_GLOBAL_STATIC(SearchEnginePrivate, d)
+
+
+void SearchEngine::reload()
+{
+ KConfig config("kuriikwsfilterrc"); //Shared with konqueror
+ KConfigGroup cg = config.group("General");
+
+ //load delimiter
+ d->delimiter = cg.readEntry("KeywordDelimiter", ":");
+
+ //load favorite engines
+ QStringList favoriteEngines;
+ favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines);
+ KService::List favorites;
+ KService::Ptr service;
+ Q_FOREACH(const QString & engine, favoriteEngines)
+ {
+ service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine));
+ if (service)
+ {
+ favorites << service;
+ }
+ }
+ d->favorites = favorites;
+
+ //load default engine
+ QString dse = cg.readEntry("DefaultSearchEngine");
+ d->defaultEngine = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(dse));
+
+ d->isLoaded = true;
+}
+
+
+QString SearchEngine::delimiter()
+{
+ if (!d->isLoaded)
+ reload();
+
+ return d->delimiter;
+}
+
+
+KService::List SearchEngine::favorites()
+{
+ if (!d->isLoaded)
+ reload();
+
+ return d->favorites;
+}
+
+
+KService::Ptr SearchEngine::defaultEngine()
+{
+ if (!d->isLoaded)
+ reload();
+
+ return d->defaultEngine;
+}
+
+
+KService::Ptr SearchEngine::fromString(const QString &text)
+{
+ KService::List providers = KServiceTypeTrader::self()->query("SearchProvider");
+ int i = 0;
+ bool found = false;
+ KService::Ptr service;
+ while (!found && i < providers.size())
+ {
+ QStringList list = providers.at(i)->property("Keys").toStringList();
+ Q_FOREACH(const QString & key, list)
+ {
+ const QString searchPrefix = key + delimiter();
+ if (text.startsWith(searchPrefix))
+ {
+ service = providers.at(i);
+ found = true;
+ }
+ }
+ i++;
+ }
+
+ return service;
+}
+
+
+QString SearchEngine::buildQuery(KService::Ptr engine, const QString &text)
+{
+ if (!engine)
+ return QString();
+ QString query = engine->property("Query").toString();
+ query = query.replace("\\{@}", KUrl::toPercentEncoding(text));
+ return query;
+}
diff --git a/src/searchengine.h b/src/searchengine.h
new file mode 100644
index 00000000..bcb364fa
--- /dev/null
+++ b/src/searchengine.h
@@ -0,0 +1,56 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr>
+*
+*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+#ifndef SEARCHENGINE_H
+#define SEARCHENGINE_H
+
+
+// KDE Includes
+#include <KService>
+
+//Qt Includes
+#include <QString>
+
+
+namespace SearchEngine
+{
+void reload();
+
+QString delimiter();
+
+KService::Ptr defaultEngine();
+
+KService::List favorites();
+
+KService::Ptr fromString(const QString &text);
+
+QString buildQuery(KService::Ptr engine, const QString &text);
+
+QString extractQuery(const QString &text);
+}
+
+#endif
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 <adjam7 at gmail dot com>
+*
+*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+// Self Includes
+#include "urlresolver.h"
+
+// Local Includes
+#include "searchengine.h"
+
+// KDE Includes
+#include <KService>
+#include <KProtocolInfo>
+#include <KDebug>
+
+// Qt Includes
+#include <QLatin1String>
+
+#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;
+}
diff --git a/src/urlresolver.h b/src/urlresolver.h
new file mode 100644
index 00000000..47105f01
--- /dev/null
+++ b/src/urlresolver.h
@@ -0,0 +1,46 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2012 by Andrea Diamantini <adjam7 at gmail dot com>
+*
+*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+#ifndef URL_RESOLVER_H
+#define URL_RESOLVER_H
+
+
+// KDE Includes
+#include <KUrl>
+
+// Qt Includes
+#include <QString>
+
+
+namespace UrlResolver
+{
+KUrl urlFromTextTyped(const QString &);
+
+bool isKDEUrl(const QString &);
+}
+
+
+#endif // URL_RESOLVER_H