summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kwebapp/CMakeLists.txt1
-rw-r--r--kwebapp/kwebmain.cpp2
-rw-r--r--kwebapp/searchengine.cpp139
-rw-r--r--kwebapp/searchengine.h56
-rw-r--r--kwebapp/webview.cpp124
-rw-r--r--kwebapp/webview.h5
-rw-r--r--scripts/codingstyle.sh1
-rw-r--r--src/settings/passexceptionswidget.cpp4
8 files changed, 294 insertions, 38 deletions
diff --git a/kwebapp/CMakeLists.txt b/kwebapp/CMakeLists.txt
index 990897eb..fab9106a 100644
--- a/kwebapp/CMakeLists.txt
+++ b/kwebapp/CMakeLists.txt
@@ -1,5 +1,6 @@
set( kwebapp_SRCS
rekonqview.cpp
+ searchengine.cpp
walletbar.cpp
webview.cpp
webpage.cpp
diff --git a/kwebapp/kwebmain.cpp b/kwebapp/kwebmain.cpp
index a0848946..9e6c7452 100644
--- a/kwebapp/kwebmain.cpp
+++ b/kwebapp/kwebmain.cpp
@@ -59,7 +59,7 @@ int main(int argc, char **argv)
KApplication app;
QWebSettings::setIconDatabasePath(KStandardDirs::locateLocal("cache", "kwebapp.favicons/"));
- qDebug() << "ICON PATH: " << KStandardDirs::locateLocal("cache", "kwebapp.favicons/");
+
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
if (args->count() != 1)
{
diff --git a/kwebapp/searchengine.cpp b/kwebapp/searchengine.cpp
new file mode 100644
index 00000000..6f7f6edc
--- /dev/null
+++ b/kwebapp/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/kwebapp/searchengine.h b/kwebapp/searchengine.h
new file mode 100644
index 00000000..bcb364fa
--- /dev/null
+++ b/kwebapp/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/kwebapp/webview.cpp b/kwebapp/webview.cpp
index 782c98d9..a79fa41f 100644
--- a/kwebapp/webview.cpp
+++ b/kwebapp/webview.cpp
@@ -28,6 +28,9 @@
#include "webview.h"
#include "webview.moc"
+// Local Includes
+#include "searchengine.h"
+
// KDE Includes
#include <KIO/Job>
#include <KIO/RenameDialog>
@@ -52,6 +55,10 @@
#include <QWebHistory>
#include <QNetworkRequest>
#include <QPointer>
+#include <QWebSettings>
+#include <QApplication>
+#include <QMimeData>
+#include <QClipboard>
// Defines
#define QL1S(x) QLatin1String(x)
@@ -235,32 +242,32 @@ void WebView::menuRequested(const QPoint &pos)
}
}
-// // Default SearchEngine
-// KService::Ptr defaultEngine = SearchEngine::defaultEngine();
-// if (defaultEngine) // check if a default engine is set
-// {
-// a = new KAction(i18nc("Search selected text with the default search engine", "Search with %1", defaultEngine->name()), this);
-// a->setIcon(rApp->iconManager()->iconForUrl(SearchEngine::buildQuery(defaultEngine, "")));
-// a->setData(defaultEngine->entryPath());
-// connect(a, SIGNAL(triggered(bool)), this, SLOT(search()));
-// menu.addAction(a);
-// }
+ // Default SearchEngine
+ KService::Ptr defaultEngine = SearchEngine::defaultEngine();
+ if (defaultEngine) // check if a default engine is set
+ {
+ a = new KAction(i18nc("Search selected text with the default search engine", "Search with %1", defaultEngine->name()), this);
+ a->setIcon(QWebSettings::iconForUrl(SearchEngine::buildQuery(defaultEngine, "")));
+ a->setData(defaultEngine->entryPath());
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(search()));
+ menu.addAction(a);
+ }
// All favourite ones
KActionMenu *searchMenu = new KActionMenu(KIcon("edit-find"), i18nc("@title:menu", "Search"), this);
-// Q_FOREACH(const KService::Ptr & engine, SearchEngine::favorites())
-// {
-// a = new KAction(i18nc("@item:inmenu Search, %1 = search engine", "With %1", engine->name()), this);
-// a->setIcon(rApp->iconManager()->iconForUrl(SearchEngine::buildQuery(engine, "")));
-// a->setData(engine->entryPath());
-// connect(a, SIGNAL(triggered(bool)), this, SLOT(search()));
-// searchMenu->addAction(a);
-// }
+ Q_FOREACH(const KService::Ptr & engine, SearchEngine::favorites())
+ {
+ a = new KAction(i18nc("@item:inmenu Search, %1 = search engine", "With %1", engine->name()), this);
+ a->setIcon(QWebSettings::iconForUrl(SearchEngine::buildQuery(engine, "")));
+ a->setData(engine->entryPath());
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(search()));
+ searchMenu->addAction(a);
+ }
-// a = new KAction(KIcon("edit-find"), i18n("On Current Page"), this);
-// connect(a, SIGNAL(triggered()), rApp->mainWindow(), SLOT(findSelectedText()));
-// searchMenu->addAction(a);
+ a = new KAction(KIcon("edit-find"), i18n("On Current Page"), this);
+ connect(a, SIGNAL(triggered()), this, SLOT(findSelectedText()));
+ searchMenu->addAction(a);
if (!searchMenu->menu()->isEmpty())
{
@@ -270,19 +277,21 @@ void WebView::menuRequested(const QPoint &pos)
// DEFAULT ACTIONs (on the bottom) -----------------------
menu.addSeparator();
- if (resultHit & WebView::LinkSelection)
- {
- a = new KAction(KIcon("bookmark-new"), i18n("&Bookmark link"), this);
- a->setData(result.linkUrl());
- connect(a, SIGNAL(triggered(bool)), this, SLOT(bookmarkLink()));
- menu.addAction(a);
- }
- else
- {
- a = new KAction(KIcon("bookmark-new"), i18n("&Add Bookmark"), this);
- connect(a, SIGNAL(triggered(bool)), this, SLOT(bookmarkCurrentPage()));
- menu.addAction(a);
- }
+
+ // FIXME: bookmarks management
+// if (resultHit & WebView::LinkSelection)
+// {
+// a = new KAction(KIcon("bookmark-new"), i18n("&Bookmark link"), this);
+// a->setData(result.linkUrl());
+// connect(a, SIGNAL(triggered(bool)), this, SLOT(bookmarkLink()));
+// menu.addAction(a);
+// }
+// else
+// {
+// a = new KAction(KIcon("bookmark-new"), i18n("&Add Bookmark"), this);
+// connect(a, SIGNAL(triggered(bool)), this, SLOT(bookmarkCurrentPage()));
+// menu.addAction(a);
+// }
menu.addAction(sendByMailAction);
@@ -307,3 +316,50 @@ void WebView::sendByMail()
KToolInvocation::invokeMailer("", "", "", "", url);
}
+
+void WebView::findSelectedText()
+{
+ QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument;
+
+ findText(selectedText(), options);
+}
+
+
+void WebView::search()
+{
+ KAction *a = qobject_cast<KAction*>(sender());
+ KService::Ptr engine = KService::serviceByDesktopPath(a->data().toString());
+ KUrl urlSearch = KUrl(SearchEngine::buildQuery(engine, selectedText()));
+
+ load(urlSearch);
+}
+
+
+void WebView::viewImage(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
+{
+ Q_UNUSED(buttons);
+ Q_UNUSED(modifiers);
+
+ KAction *a = qobject_cast<KAction*>(sender());
+ KUrl url(a->data().toUrl());
+
+ load(url);
+}
+
+
+void WebView::slotCopyImageLocation()
+{
+ KAction *a = qobject_cast<KAction*>(sender());
+ KUrl imageUrl(a->data().toUrl());
+#ifndef QT_NO_MIMECLIPBOARD
+ // Set it in both the mouse selection and in the clipboard
+ QMimeData* mimeData = new QMimeData;
+ imageUrl.populateMimeData(mimeData);
+ QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
+ mimeData = new QMimeData;
+ imageUrl.populateMimeData(mimeData);
+ QApplication::clipboard()->setMimeData(mimeData, QClipboard::Selection);
+#else
+ QApplication::clipboard()->setText(imageUrl.url());
+#endif
+}
diff --git a/kwebapp/webview.h b/kwebapp/webview.h
index 5cf6fcfe..7c636367 100644
--- a/kwebapp/webview.h
+++ b/kwebapp/webview.h
@@ -61,6 +61,11 @@ private Q_SLOTS:
void openLinkInDefaultBrowser();
void sendByMail();
+ void findSelectedText();
+ void search();
+
+ void viewImage(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
+ void slotCopyImageLocation();
private:
WebPage *m_page;
diff --git a/scripts/codingstyle.sh b/scripts/codingstyle.sh
index 5285c22c..b35d9433 100644
--- a/scripts/codingstyle.sh
+++ b/scripts/codingstyle.sh
@@ -27,7 +27,6 @@ PWD=$(pwd)
cd $PWD
cd ..
-cd src
echo "Applying astyle rules..."
astyle \
diff --git a/src/settings/passexceptionswidget.cpp b/src/settings/passexceptionswidget.cpp
index bf705723..fe20e711 100644
--- a/src/settings/passexceptionswidget.cpp
+++ b/src/settings/passexceptionswidget.cpp
@@ -54,8 +54,8 @@ PassExWidget::PassExWidget(QWidget *parent)
void PassExWidget::removeOne()
{
const int currentRow(listWidget->currentRow());
- if(currentRow==-1)
- return;
+ if (currentRow == -1)
+ return;
QString item = listWidget->takeItem(currentRow)->text();
QStringList exList = ReKonfig::walletBlackList();