diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2012-12-10 02:09:41 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2012-12-10 02:09:41 +0100 |
commit | 288ace1df39dbea40cae66d0b04bfdefcd6cec70 (patch) | |
tree | 87c03b9dbfb330b7e743a45276d73de0cea0e950 /kwebapp | |
parent | Lindsay's credits (diff) | |
download | rekonq-288ace1df39dbea40cae66d0b04bfdefcd6cec70.tar.xz |
WARNING COMMIT --> FIRST REKONQ 2 IMPORT
Preparing repo to merge rekonq2 code...
Diffstat (limited to 'kwebapp')
-rw-r--r-- | kwebapp/CMakeLists.txt | 29 | ||||
-rw-r--r-- | kwebapp/Messages.sh | 3 | ||||
-rw-r--r-- | kwebapp/kwebmain.cpp | 82 | ||||
-rw-r--r-- | kwebapp/rekonqview.cpp | 270 | ||||
-rw-r--r-- | kwebapp/rekonqview.h | 83 | ||||
-rw-r--r-- | kwebapp/searchengine.cpp | 149 | ||||
-rw-r--r-- | kwebapp/searchengine.h | 56 | ||||
-rw-r--r-- | kwebapp/urlresolver.cpp | 98 | ||||
-rw-r--r-- | kwebapp/urlresolver.h | 46 | ||||
-rw-r--r-- | kwebapp/walletbar.cpp | 105 | ||||
-rw-r--r-- | kwebapp/walletbar.h | 63 | ||||
-rw-r--r-- | kwebapp/webpage.cpp | 129 | ||||
-rw-r--r-- | kwebapp/webpage.h | 49 | ||||
-rw-r--r-- | kwebapp/websnap.cpp | 166 | ||||
-rw-r--r-- | kwebapp/websnap.h | 121 | ||||
-rw-r--r-- | kwebapp/webview.cpp | 365 | ||||
-rw-r--r-- | kwebapp/webview.h | 74 |
17 files changed, 0 insertions, 1888 deletions
diff --git a/kwebapp/CMakeLists.txt b/kwebapp/CMakeLists.txt deleted file mode 100644 index 459c5a45..00000000 --- a/kwebapp/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -set( kwebapp_SRCS - rekonqview.cpp - searchengine.cpp - urlresolver.cpp - walletbar.cpp - webview.cpp - webpage.cpp - websnap.cpp - kwebmain.cpp - ) - -include_directories ( - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} - ${QT4_INCLUDES} - ${KDE4_INCLUDES} -) - - -kde4_add_executable(kwebapp ${kwebapp_SRCS}) - -target_link_libraries(kwebapp - ${KDE4_KDEUI_LIBS} - ${KDE4_KDEWEBKIT_LIBS} -) - - -install(TARGETS kwebapp ${INSTALL_TARGETS_DEFAULT_ARGS} ) - diff --git a/kwebapp/Messages.sh b/kwebapp/Messages.sh deleted file mode 100644 index 37199e06..00000000 --- a/kwebapp/Messages.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /usr/bin/env bash -$EXTRACTRC `find . -name \*.rc` >> rc.cpp -$XGETTEXT *.cpp -o $podir/kwebapp.pot diff --git a/kwebapp/kwebmain.cpp b/kwebapp/kwebmain.cpp deleted file mode 100644 index 8c324fa9..00000000 --- a/kwebapp/kwebmain.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2011-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/>. -* -* ============================================================ */ - - -// Local Includes -#include "rekonqview.h" -#include "urlresolver.h" - -// KDE Includes -#include <KApplication> -#include <KAboutData> -#include <KCmdLineArgs> -#include <KUrl> -#include <KStandardDirs> - -// Qt Includes -#include <QWebSettings> -#include <QDebug> - - -static const char description[] = - I18N_NOOP("Web Application Viewer"); - -static const char version[] = "0.2"; - - -int main(int argc, char **argv) -{ - KAboutData about("kwebapp", 0, ki18n("kwebapp"), version, ki18n(description), - KAboutData::License_GPL, ki18n("(C) 2011-2012 Andrea Diamantini"), KLocalizedString(), 0, "adjam7@gmail.com"); - about.addAuthor(ki18n("Andrea Diamantini"), KLocalizedString(), "adjam7@gmail.com"); - KCmdLineArgs::init(argc, argv, &about); - - KCmdLineOptions options; - options.add("+[URL]", ki18n("Document to open")); - KCmdLineArgs::addCmdLineOptions(options); - - KApplication app; - - QWebSettings::setIconDatabasePath(KStandardDirs::locateLocal("cache", "kwebapp.favicons/")); - - QWebSettings::globalSettings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true); - QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true); - QWebSettings::globalSettings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true); - - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - if (args->count() != 1) - { - qDebug() << "ERROR: Impossible to launch kwebapp WITHOUT just ONE url to load!!!"; - return 0; - } - - RekonqView *widg = new RekonqView(); - widg->loadUrl(UrlResolver::urlFromTextTyped(args->arg(0))); - widg->show(); - args->clear(); - - return app.exec(); -} - diff --git a/kwebapp/rekonqview.cpp b/kwebapp/rekonqview.cpp deleted file mode 100644 index ec8ca01d..00000000 --- a/kwebapp/rekonqview.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/* ============================================================ -* -* 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 "rekonqview.h" -#include "rekonqview.moc" - -// Local Includes -#include "walletbar.h" -#include "webpage.h" - -// KDE Includes -#include <KWebWallet> -#include <KStandardShortcut> -#include <KMenu> -#include <KActionMenu> -#include <KWebView> -#include <KDebug> -#include <KMessageBox> -#include <KRun> -#include <klocalizedstring.h> -#include <KSharedConfig> -#include <KConfigGroup> - -// Qt Includes -#include <QVBoxLayout> -#include <QWebElement> -#include <QWebFrame> -#include <QByteArray> -#include <QDataStream> -#include <QLabel> -#include <QTimer> -#include <QTextDocument> -#include <QStyle> - - -RekonqView::RekonqView(QWidget *parent) - : QWidget(parent) - , m_webView(0) - , m_popup(new QLabel(this)) - , m_hidePopupTimer(new QTimer(this)) - -{ - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - QVBoxLayout *l = new QVBoxLayout(this); - l->setMargin(0); - l->setSpacing(0); - - l->addWidget(view()); - view()->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - // fix focus handling - setFocusProxy(view()); - - KWebWallet *wallet = page()->wallet(); - - if (wallet) - { - connect(wallet, SIGNAL(saveFormDataRequested(QString, QUrl)), - this, SLOT(createWalletBar(QString, QUrl))); - } - - connect(page(), SIGNAL(linkHovered(QString, QString, QString)), this, SLOT(notifyMessage(QString))); - - // setting popup notification - m_popup->setAutoFillBackground(true); - m_popup->setMargin(4); - m_popup->raise(); - m_popup->hide(); - - connect(m_hidePopupTimer, SIGNAL(timeout()), m_popup, SLOT(hide())); - - // signal && slots - connect(view(), SIGNAL(iconChanged()), this, SLOT(setIcon())); - connect(view(), SIGNAL(titleChanged(QString)), this, SLOT(setTitle(QString))); - -} - - -RekonqView::~RekonqView() -{ - m_walletBar.clear(); - - delete m_webView; -} - - -WebView *RekonqView::view() -{ - if (!m_webView) - { - m_webView = new WebView(this); - } - return m_webView; -} - - -WebPage *RekonqView::page() -{ - return view()->page(); -} - - -KUrl RekonqView::url() -{ -// if (page() && page()->isOnRekonqPage()) -// { -// return page()->loadingUrl(); -// } - - return view()->url(); -} - - -void RekonqView::setTitle(const QString &t) -{ - setWindowTitle(t); -} - - -void RekonqView::setIcon() -{ - setWindowIcon(view()->icon()); -} - - -void RekonqView::createWalletBar(const QString &key, const QUrl &url) -{ - // check if the url is in the wallet blacklist - QString urlString = url.toString(); - - KSharedConfig::Ptr config = KSharedConfig::openConfig("rekonqrc", KConfig::SimpleConfig, "config"); - KConfigGroup group1(config, "misc"); - QStringList blackList = group1.readEntry("walletBlackList", QStringList()); - if (blackList.contains(urlString)) - return; - - KWebWallet *wallet = page()->wallet(); - - KConfigGroup group2(config, "Privacy"); - bool passwordSavingEnabled = group2.readEntry("passwordSavingEnabled", false); - - if (!passwordSavingEnabled) - { - wallet->rejectSaveFormDataRequest(key); - return; - } - - if (m_walletBar.isNull()) - { - m_walletBar = new WalletBar(this); - m_walletBar.data()->onSaveFormData(key, url); - qobject_cast<QVBoxLayout *>(layout())->insertWidget(0, m_walletBar.data()); - m_walletBar.data()->animatedShow(); - } - else - { - disconnect(wallet); - qobject_cast<QVBoxLayout *>(layout())->insertWidget(0, m_walletBar.data()); - m_walletBar.data()->animatedShow(); - } - - connect(m_walletBar.data(), SIGNAL(saveFormDataAccepted(QString)), - wallet, SLOT(acceptSaveFormDataRequest(QString)), Qt::UniqueConnection); - connect(m_walletBar.data(), SIGNAL(saveFormDataRejected(QString)), - wallet, SLOT(rejectSaveFormDataRequest(QString)), Qt::UniqueConnection); -} - - -bool RekonqView::hasRSSInfo() -{ - QWebElementCollection col = page()->mainFrame()->findAllElements("link[type=\"application/rss+xml\"]"); - col.append(page()->mainFrame()->findAllElements("link[type=\"application/atom+xml\"]")); - if (col.count() != 0) - return true; - - return false; -} - - -void RekonqView::loadUrl(const KUrl& url) -{ - if (url.isEmpty()) - return; - - if (!url.isValid()) - { - KMessageBox::error(0, i18n("Malformed URL:\n%1", url.url(KUrl::RemoveTrailingSlash))); - return; - } - - view()->load(url); -} - - -void RekonqView::notifyMessage(const QString &msg) -{ - // deleting popus if empty msgs - if (msg.isEmpty()) - { - m_hidePopupTimer->start(250); - return; - } - - m_hidePopupTimer->stop(); - m_hidePopupTimer->start(3000); - - QString msgToShow = Qt::escape(msg); - - const int margin = 4; - const int halfWidth = width() / 2; - - // Set Popup size - QFontMetrics fm = m_popup->fontMetrics(); - QSize labelSize(fm.width(msgToShow) + 2 * margin, fm.height() + 2 * margin); - - if (labelSize.width() > halfWidth) - labelSize.setWidth(halfWidth); - - m_popup->setFixedSize(labelSize); - m_popup->setText(fm.elidedText(msgToShow, Qt::ElideMiddle, labelSize.width() - 2 * margin)); - - // NOTE: while currentFrame should NEVER be null - // we are checking here its existence cause of bug:264187 - if (!page() || !page()->currentFrame()) - return; - - const bool horizontalScrollbarIsVisible = page()->currentFrame()->scrollBarMaximum(Qt::Horizontal); - const bool verticalScrollbarIsVisible = page()->currentFrame()->scrollBarMaximum(Qt::Vertical); - const bool actionBarsVisible = false; //FIXME m_findBar->isVisible() || m_zoomBar->isVisible(); - - const int scrollbarExtent = style()->pixelMetric(QStyle::PM_ScrollBarExtent); - const int hScrollbarSize = horizontalScrollbarIsVisible ? scrollbarExtent : 0; - const int vScrollbarSize = verticalScrollbarIsVisible ? scrollbarExtent : 0; - - const QPoint mousePos = mapFromGlobal(QCursor::pos()); - const QPoint bottomPoint = geometry().bottomLeft(); - - int y = bottomPoint.y() + 1 - 2 * m_popup->height() - hScrollbarSize; // +1 because bottom() returns top() + height() - 1, see QRect doku - int x = QRect(QPoint(0, y), labelSize).contains(mousePos) || actionBarsVisible - ? width() - labelSize.width() - vScrollbarSize - : 0; - - m_popup->move(x, y); - m_popup->show(); -} diff --git a/kwebapp/rekonqview.h b/kwebapp/rekonqview.h deleted file mode 100644 index 770c468a..00000000 --- a/kwebapp/rekonqview.h +++ /dev/null @@ -1,83 +0,0 @@ -/* ============================================================ -* -* 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 REKONQ_VIEW_H -#define REKONQ_VIEW_H - - -// Local Includes -#include "webview.h" - -// Qt Includes -#include <QWidget> - -// Forward Declarations -class WalletBar; - -class WebPage; - -class QLabel; -class QTimer; - - -class RekonqView : public QWidget -{ - Q_OBJECT - -public: - explicit RekonqView(QWidget *parent = 0); - ~RekonqView(); - - WebView *view(); - WebPage *page(); - - KUrl url(); - - bool hasRSSInfo(); - -public Q_SLOTS: - void loadUrl(const KUrl& url); - -private Q_SLOTS: - void setTitle(const QString &); - void setIcon(); - - void createWalletBar(const QString &, const QUrl &); - void notifyMessage(const QString &msg); - -Q_SIGNALS: - void loadProgressing(); - -private: - WebView *m_webView; - - QWeakPointer<WalletBar> m_walletBar; - - QLabel *m_popup; - QTimer *m_hidePopupTimer; -}; - -#endif diff --git a/kwebapp/searchengine.cpp b/kwebapp/searchengine.cpp deleted file mode 100644 index 212f0ee8..00000000 --- a/kwebapp/searchengine.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* ============================================================ -* -* 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"); - KConfigGroup cg = config.group("General"); - - // load delimiter - d->delimiter = cg.readEntry("KeywordDelimiter", ":"); - - // load favorite engines - QStringList favoriteEngines; -#if KDE_IS_VERSION(4,9,0) - favoriteEngines = cg.readEntry("PreferredWebShortcuts", favoriteEngines); -#else - favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines); -#endif - - 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; -#if KDE_IS_VERSION(4,9,0) - dse = cg.readEntry("DefaultWebShortcut"); -#else - dse = cg.readEntry("DefaultSearchEngine"); -#endif - 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 deleted file mode 100644 index bcb364fa..00000000 --- a/kwebapp/searchengine.h +++ /dev/null @@ -1,56 +0,0 @@ -/* ============================================================ -* -* 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/urlresolver.cpp b/kwebapp/urlresolver.cpp deleted file mode 100644 index c56e5a94..00000000 --- a/kwebapp/urlresolver.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* ============================================================ -* -* 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/kwebapp/urlresolver.h b/kwebapp/urlresolver.h deleted file mode 100644 index 47105f01..00000000 --- a/kwebapp/urlresolver.h +++ /dev/null @@ -1,46 +0,0 @@ -/* ============================================================ -* -* 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 diff --git a/kwebapp/walletbar.cpp b/kwebapp/walletbar.cpp deleted file mode 100644 index 36a97578..00000000 --- a/kwebapp/walletbar.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009-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 "walletbar.h" -#include "walletbar.moc" - -// KDE Includes -#include <KIcon> -#include <KLocalizedString> -#include <KSharedConfig> -#include <KConfigGroup> - -// Qt Includes -#include <QAction> - - -WalletBar::WalletBar(QWidget *parent) - : KMessageWidget(parent) -{ - setMessageType(KMessageWidget::Warning); - - QSize sz = size(); - sz.setWidth(qobject_cast<QWidget *>(parent)->size().width()); - resize(sz); - - setCloseButtonVisible(false); - - QAction *rememberAction = new QAction(KIcon("document-save"), i18n("Remember"), this); - connect(rememberAction, SIGNAL(triggered(bool)), this, SLOT(rememberData())); - addAction(rememberAction); - - QAction *neverHereAction = new QAction(KIcon("process-stop"), i18n("Never for This Site"), this); - connect(neverHereAction, SIGNAL(triggered(bool)), this, SLOT(neverRememberData())); - addAction(neverHereAction); - - QAction *notNowAction = new QAction(KIcon("dialog-cancel"), i18n("Not Now"), this); - connect(notNowAction, SIGNAL(triggered(bool)), this, SLOT(notNowRememberData())); - addAction(notNowAction); -} - - -void WalletBar::rememberData() -{ - emit saveFormDataAccepted(m_key); - - animatedHide(); - deleteLater(); -} - - -void WalletBar::neverRememberData() -{ - // add url to the blacklist - KSharedConfig::Ptr config = KSharedConfig::openConfig("rekonqrc", KConfig::SimpleConfig, "config"); - KConfigGroup group(config, "misc"); - QStringList list = group.readEntry("walletBlackList", QStringList()); - list << m_url.toString(); - group.writeEntry("walletBlackList", list); - config->sync(); - - notNowRememberData(); -} - - -void WalletBar::notNowRememberData() -{ - emit saveFormDataRejected(m_key); - - animatedHide(); - deleteLater(); -} - - - -void WalletBar::onSaveFormData(const QString &key, const QUrl &url) -{ - setText(i18n("Do you want rekonq to remember the password on %1?", url.host())); - - m_key = key; - m_url = url; -} diff --git a/kwebapp/walletbar.h b/kwebapp/walletbar.h deleted file mode 100644 index 094dec0e..00000000 --- a/kwebapp/walletbar.h +++ /dev/null @@ -1,63 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009-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 WALLET_BAR_H -#define WALLET_BAR_H - - -// KDE Includes -#include <KMessageWidget> - -// Qt Includes -#include <QUrl> -#include <QString> - - -class WalletBar : public KMessageWidget -{ - Q_OBJECT - -public: - WalletBar(QWidget *parent); - -private Q_SLOTS: - void rememberData(); - void neverRememberData(); - void notNowRememberData(); - -public Q_SLOTS: - void onSaveFormData(const QString &, const QUrl &); - -Q_SIGNALS: - void saveFormDataAccepted(const QString &); - void saveFormDataRejected(const QString &); - -private: - QString m_key; - QUrl m_url; -}; - -#endif // WALLET_BAR_H diff --git a/kwebapp/webpage.cpp b/kwebapp/webpage.cpp deleted file mode 100644 index 827bbce1..00000000 --- a/kwebapp/webpage.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2011-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 "webpage.h" -#include "webpage.moc" - -// Local Includes -#include "urlresolver.h" - -// KDE Includes -#include <KRun> -#include <KToolInvocation> -#include <KProtocolInfo> -#include <KDebug> - -// Qt Includes -#include <QNetworkRequest> -#include <QNetworkReply> -#include <QWebFrame> - -// Defines -#define QL1S(x) QLatin1String(x) - - -WebPage::WebPage(QObject *parent) - : KWebPage(parent) -{ - // ----- handling unsupported content... - setForwardUnsupportedContent(true); - connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(handleUnsupportedContent(QNetworkReply*))); - - // downloads - connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(downloadResponse(QNetworkReply*))); - connect(this, SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequest(QNetworkRequest))); -} - - -bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type) -{ - QUrl reqUrl = request.url(); - QString protocol = reqUrl.scheme(); - - // javascript handling - if (protocol == QL1S("javascript")) - { - QString scriptSource = QUrl::fromPercentEncoding(reqUrl.toString().mid(11).toUtf8()); - mainFrame()->evaluateJavaScript(scriptSource); - return false; - } - - // "mailto" handling: It needs to be handled both here (mail url launched) - // and in handleUnsupportedContent (mail links clicked) - if (protocol == QL1S("mailto")) - { - KToolInvocation::invokeMailer(reqUrl); - return false; - } - - if (frame && UrlResolver::isKDEUrl(reqUrl.toString())) - { - QUrl newReqUrl = UrlResolver::urlFromTextTyped(reqUrl.toString()); - frame->load(newReqUrl); - return false; - } - - // don't let webkit try to load an unknown (or missing) protocol... - if (!KProtocolInfo::isKnownProtocol(protocol)) - { - kDebug() << "UNKNOWN PROTOCOL: " << protocol; - return false; - } - - return KWebPage::acceptNavigationRequest(frame, request, type); -} - - -void WebPage::handleUnsupportedContent(QNetworkReply *reply) -{ - Q_ASSERT(reply); - - if (!reply) - { - kDebug() << "NO REPLY. Why????"; - return; - } - - QUrl replyUrl = reply->url(); - QString protocol = replyUrl.scheme(); - - // "http(s)" (fast) handling - if (protocol == QL1S("http") || protocol == QL1S("https")) - { - kDebug() << "Error: " << protocol; - return; - } - - // "mailto" handling. - if (protocol == QL1S("mailto")) - { - KToolInvocation::invokeMailer(replyUrl); - return; - } - - return; -} diff --git a/kwebapp/webpage.h b/kwebapp/webpage.h deleted file mode 100644 index 97d7102a..00000000 --- a/kwebapp/webpage.h +++ /dev/null @@ -1,49 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2011-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 _WEB_PAGE_H -#define _WEB_PAGE_H - - -// KDE Includes -#include <KWebPage> - - -class WebPage : public KWebPage -{ - Q_OBJECT - -public: - WebPage(QObject *parent = 0); - -protected: - virtual bool acceptNavigationRequest(QWebFrame *, const QNetworkRequest &, NavigationType); - -private Q_SLOTS: - void handleUnsupportedContent(QNetworkReply *); -}; - -#endif // _WEB_PAGE_H diff --git a/kwebapp/websnap.cpp b/kwebapp/websnap.cpp deleted file mode 100644 index 830d37e1..00000000 --- a/kwebapp/websnap.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 Nokia Corporation <qt-info@nokia.com> -* Copyright (C) 2009-2012 by Andrea Diamantini <adjam7 at gmail dot com> -* Copyright (C) 2010 by Matthieu Gicquel <matgic78 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 "websnap.h" -#include "websnap.moc" - -// KDE Includes -#include <KStandardDirs> - -// Qt Includes -#include <QSize> -#include <QFile> - -#include <QCryptographicHash> - -#include <QPainter> -#include <QAction> - -#include <QWebFrame> -#include <QWebSettings> - - -WebSnap::WebSnap(const KUrl& url, QObject *parent) - : QObject(parent) - , m_url(url) -{ - // this to not register websnap history - m_page.settings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, true); - - // this to not let this page open other windows - m_page.settings()->setAttribute(QWebSettings::PluginsEnabled, false); - m_page.settings()->setAttribute(QWebSettings::JavascriptEnabled, false); - - connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(saveResult(bool))); - - QMetaObject::invokeMethod(this, "load", Qt::QueuedConnection); -} - - -WebSnap::~WebSnap() -{ - m_page.action(QWebPage::Stop)->trigger(); - m_page.deleteLater(); -} - - -void WebSnap::load() -{ - m_page.mainFrame()->load(m_url); -} - - - -QPixmap WebSnap::render(const QWebPage &page, int w, int h) -{ - // create the page image - QPixmap pageImage = QPixmap(w, h); - pageImage.fill(Qt::transparent); - - // render it - QPainter p(&pageImage); - page.mainFrame()->render(&p, QWebFrame::ContentsLayer); - p.end(); - - return pageImage; -} - - -// NOTE -// to render page preview in a safe way, you CANNOT work with scrollbars! -// In fact, disabling temporarily them DOES NOT work without reloading a page -// that is something we CANNOT do. -QPixmap WebSnap::renderPagePreview(const QWebPage &page, int w, int h) -{ - // store actual viewportsize - QSize oldSize = page.viewportSize(); - - // prepare page - // NOTE: I saw some sites with strange CMS and with absurd content size width (eg: 8584553) - // This usually leads setViewportSize to crash :( - // So, ensure renderWidth is no more than 2000. - int renderWidth = page.mainFrame()->contentsSize().width(); - if (renderWidth > 2000) - renderWidth = 2000; - int renderHeight = renderWidth * ((0.0 + h) / w); - - page.setViewportSize(QSize(renderWidth, renderHeight)); - - // consider scrollbars and render the page - bool verticalScrollBarActive = !page.mainFrame()->scrollBarGeometry(Qt::Vertical).isEmpty(); - if (verticalScrollBarActive) - renderWidth -= 15; - - bool horizontalScrollBarActive = !page.mainFrame()->scrollBarGeometry(Qt::Horizontal).isEmpty(); - if (horizontalScrollBarActive) - renderHeight -= 15; - - QPixmap pageImage = WebSnap::render(page, renderWidth, renderHeight); - - // resize image - pageImage = pageImage.scaled(w, h, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); - - // restore page state - page.setViewportSize(oldSize); - - return pageImage; -} - - -QString WebSnap::imagePathFromUrl(const KUrl &url) -{ - QUrl temp = QUrl(url.url()); - QByteArray name = temp.toEncoded(QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash); - - QByteArray hashedName = QCryptographicHash::hash(name, QCryptographicHash::Md5).toHex(); - - return KStandardDirs::locateLocal("cache", QString("thumbs/") + hashedName + ".png", true); -} - - -void WebSnap::saveResult(bool ok) -{ - if (ok) - { - QPixmap image = renderPagePreview(m_page, defaultWidth, defaultHeight); - QString path = imagePathFromUrl(m_url); - QFile::remove(path); - image.save(path); - } - - emit snapDone(ok); - - this->deleteLater(); -} - - -bool WebSnap::existsImage(const KUrl &u) -{ - return QFile::exists(imagePathFromUrl(u)); -} diff --git a/kwebapp/websnap.h b/kwebapp/websnap.h deleted file mode 100644 index 0584ce00..00000000 --- a/kwebapp/websnap.h +++ /dev/null @@ -1,121 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 Nokia Corporation <qt-info@nokia.com> -* Copyright (C) 2009-2012 by Andrea Diamantini <adjam7 at gmail dot com> -* Copyright (C) 2010 by Matthieu Gicquel <matgic78 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 WEB_SNAP_H -#define WEB_SNAP_H - - -// KDE Includes -#include <KUrl> - -// Qt Includes -#include <QObject> -#include <QWebPage> - -// Forward Declarations -class QPixmap; - -/** - * This class is used in many classes of rekonq to produce an image - * based on the site corresponding to the url passed as argument. - * It also cached the images to not retrieve them every time :) - * - * Heavily based on Graphics-Dojo WebSnap example (thanks!) - * - * We use this in the following rekonq classes: - * - * - TabBar class: to show a tab preview (given a page, you show AND save an image) - * - PreviewSelector class: to save new favorite selection (given a page, you show AND save an image) - * - * - NewTabPage class: to show the favorites page "preview" (given an url, you show AND save an image) - * - */ - -class WebSnap : public QObject -{ - Q_OBJECT - -public: - /** - * Creates a WebSnap object. It will load the url in one WebPage - * and snap an image from it. - * - * @param url the url to load - * @param parent the object parent - */ - explicit WebSnap(const KUrl &url, QObject *parent = 0); - - ~WebSnap(); - - /** - * Snaps a pixmap of size w * h from a page - * - * @param page the page to snap - * @param w the image width - * @param h the image height - * - * @return the pixmap snapped from the page - */ - static QPixmap renderPagePreview(const QWebPage &page, int w = defaultWidth, int h = defaultHeight); - - /** - * Guess the local path where the image for the url provided - * should be - * - * @param url the url to guess snap path - * - * @return the local path of the url snap - */ - static QString imagePathFromUrl(const KUrl &url); - - /** - * Determines if a snap exists for that url - * - */ - static bool existsImage(const KUrl &url); - - -private Q_SLOTS: - void saveResult(bool ok = true); - void load(); - -Q_SIGNALS: - void snapDone(bool ok); - -private: - // Constants - static const int defaultWidth = 200; - static const int defaultHeight = 150; - QWebPage m_page; - KUrl m_url; - - //render a preview: common part of renderPagePreview() and renderTabPreview() - static QPixmap render(const QWebPage &page, int w, int h); -}; - -#endif // WEB_SNAP_H diff --git a/kwebapp/webview.cpp b/kwebapp/webview.cpp deleted file mode 100644 index a79fa41f..00000000 --- a/kwebapp/webview.cpp +++ /dev/null @@ -1,365 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2011-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 "webview.h" -#include "webview.moc" - -// Local Includes -#include "searchengine.h" - -// KDE Includes -#include <KIO/Job> -#include <KIO/RenameDialog> -#include <KIO/JobUiDelegate> - -#include <KGlobalSettings> -#include <KStandardDirs> -#include <KFileDialog> -#include <KJobUiDelegate> -#include <KLocalizedString> -#include <KMenu> -#include <KAction> -#include <KUrl> -#include <KRun> -#include <KToolInvocation> -#include <KActionMenu> - -// Qt Includes -#include <QUrl> -#include <QDebug> -#include <QWebHitTestResult> -#include <QWebHistory> -#include <QNetworkRequest> -#include <QPointer> -#include <QWebSettings> -#include <QApplication> -#include <QMimeData> -#include <QClipboard> - -// Defines -#define QL1S(x) QLatin1String(x) - - -WebView::WebView(QWidget *parent) - : KWebView(parent) - , m_page(0) -{ - page()->setForwardUnsupportedContent(true); - connect(this, SIGNAL(linkShiftClicked(KUrl)), page(), SLOT(downloadUrl(KUrl))); - - setContextMenuPolicy(Qt::CustomContextMenu); - - connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(menuRequested(QPoint))); -} - - -WebPage *WebView::page() -{ - if (!m_page) - { - m_page = new WebPage(this); - setPage(m_page); - } - return m_page; -} - - -void WebView::menuRequested(const QPoint &pos) -{ - QWebHitTestResult result = page()->mainFrame()->hitTestContent(pos); - - KMenu menu(this); - QAction *a; - - KAction *sendByMailAction = new KAction(this); - sendByMailAction->setIcon(KIcon("mail-send")); - connect(sendByMailAction, SIGNAL(triggered(bool)), this, SLOT(sendByMail())); - - KAction *openInDefaultBrowserAction = new KAction(KIcon("window-new"), i18n("Open in default browser"), this); - connect(openInDefaultBrowserAction, SIGNAL(triggered(bool)), this, SLOT(openLinkInDefaultBrowser())); - - // Choose right context - int resultHit = 0; - if (result.linkUrl().isEmpty()) - resultHit = WebView::EmptySelection; - else - resultHit = WebView::LinkSelection; - - if (!result.pixmap().isNull()) - resultHit |= WebView::ImageSelection; - - if (result.isContentSelected()) - resultHit = WebView::TextSelection; - - // ----------------------------------------------------------- - // Ok, let's start filling up the menu... - - // is content editable? Add PASTE - if (result.isContentEditable()) - { - menu.addAction(pageAction(KWebPage::Paste)); - menu.addSeparator(); - } - - - // EMPTY PAGE ACTIONS ---------------------------------------- - if (resultHit == WebView::EmptySelection) - { - // send by mail: page url - sendByMailAction->setData(page()->currentFrame()->url()); - sendByMailAction->setText(i18n("Share page url")); - - // navigation - QWebHistory *history = page()->history(); - if (history->canGoBack()) - { - menu.addAction(pageAction(KWebPage::Back)); - } - - if (history->canGoForward()) - { - menu.addAction(pageAction(KWebPage::Forward)); - } - - menu.addAction(pageAction(KWebPage::Reload)); - - menu.addSeparator(); - - // Page Actions - menu.addAction(pageAction(KWebPage::SelectAll)); - - menu.addAction(pageAction(KWebPage::DownloadLinkToDisk)); - - } - - // LINK ACTIONS ------------------------------------------ - if (resultHit & WebView::LinkSelection) - { - // send by mail: link url - sendByMailAction->setData(result.linkUrl()); - sendByMailAction->setText(i18n("Share link")); - - openInDefaultBrowserAction->setData(result.linkUrl()); - menu.addAction(openInDefaultBrowserAction); - - menu.addSeparator(); - - a = pageAction(KWebPage::DownloadLinkToDisk); - menu.addAction(a); - menu.addAction(pageAction(KWebPage::CopyLinkToClipboard)); - } - - // IMAGE ACTION ----------------------------------------- - if (resultHit & WebView::ImageSelection) - { - // send by mail: image url - sendByMailAction->setData(result.imageUrl()); - sendByMailAction->setText(i18n("Share image link")); - - menu.addSeparator(); - - a = new KAction(KIcon("view-preview"), i18n("&View Image"), this); - a->setData(result.imageUrl()); - connect(a, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), - this, SLOT(viewImage(Qt::MouseButtons, Qt::KeyboardModifiers))); - menu.addAction(a); - - menu.addAction(pageAction(KWebPage::DownloadImageToDisk)); - - a = new KAction(KIcon("view-media-visualization"), i18n("&Copy Image Location"), this); - a->setData(result.imageUrl()); - connect(a, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(slotCopyImageLocation())); - menu.addAction(a); - - } - - // ACTIONS FOR TEXT SELECTION ---------------------------- - if (resultHit & WebView::TextSelection) - { - // send by mail: text - sendByMailAction->setData(selectedText()); - sendByMailAction->setText(i18n("Share selected text")); - - if (result.isContentEditable()) - { - // actions for text selected in field - menu.addAction(pageAction(KWebPage::Cut)); - } - - a = pageAction(KWebPage::Copy); - if (!result.linkUrl().isEmpty()) - a->setText(i18n("Copy Text")); //for link - else - a->setText(i18n("Copy")); - menu.addAction(a); - - if (selectedText().contains('.') && selectedText().indexOf('.') < selectedText().length() - && !selectedText().trimmed().contains(" ") - ) - { - QString text = selectedText(); - text = text.trimmed(); - KUrl urlLikeText(text); - if (urlLikeText.isValid()) - { - QString truncatedUrl = text; - const int maxTextSize = 18; - if (truncatedUrl.length() > maxTextSize) - { - const int truncateSize = 15; - truncatedUrl.truncate(truncateSize); - truncatedUrl += QL1S("..."); - } - - openInDefaultBrowserAction->setData(QUrl(urlLikeText)); - menu.addAction(openInDefaultBrowserAction); - - menu.addSeparator(); - } - } - - // 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(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()), this, SLOT(findSelectedText())); - searchMenu->addAction(a); - - if (!searchMenu->menu()->isEmpty()) - { - menu.addAction(searchMenu); - } - } - - // DEFAULT ACTIONs (on the bottom) ----------------------- - menu.addSeparator(); - - // 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); - - - menu.exec(mapToGlobal(pos)); -} - - -void WebView::openLinkInDefaultBrowser() -{ - KAction *a = qobject_cast<KAction*>(sender()); - KUrl u(a->data().toUrl()); - - (void)new KRun(u, this, 0); -} - - -void WebView::sendByMail() -{ - KAction *a = qobject_cast<KAction*>(sender()); - QString url = a->data().toString(); - - 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 deleted file mode 100644 index 7c636367..00000000 --- a/kwebapp/webview.h +++ /dev/null @@ -1,74 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2011-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 WEB_VIEW_H -#define WEB_VIEW_H - - -// Local Includes -#include "webpage.h" - -// KDE Includes -#include <KWebView> - -// Qt Includes -#include <QUrl> - - -class WebView : public KWebView -{ - Q_OBJECT - -public: - - enum ContextType - { - EmptySelection = 0x00000000, - LinkSelection = 0x00000001, - ImageSelection = 0x00000010, - TextSelection = 0x00000100 - }; - - explicit WebView(QWidget *parent = 0); - - WebPage *page(); - -private Q_SLOTS: - void menuRequested(const QPoint &); - void openLinkInDefaultBrowser(); - - void sendByMail(); - void findSelectedText(); - void search(); - - void viewImage(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); - void slotCopyImageLocation(); - -private: - WebPage *m_page; -}; - -#endif // WEB_VIEW_H |