From 7187da9812bbe6ffb5bf272f18f8e74c8d23d3c7 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 8 Nov 2011 10:17:36 +0100 Subject: Application Shortcut Added an action to manage it in the tools menu, added initial code to manage icons, added kwebapp application --- kwebapp/webview.cpp | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 kwebapp/webview.cpp (limited to 'kwebapp/webview.cpp') diff --git a/kwebapp/webview.cpp b/kwebapp/webview.cpp new file mode 100644 index 00000000..7a5ba4c1 --- /dev/null +++ b/kwebapp/webview.cpp @@ -0,0 +1,121 @@ +/*************************************************************************** + * Copyright (C) 2011 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) 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 . * + ***************************************************************************/ + + +// Self Includes +#include "webview.h" +#include "webview.moc" + +// KDE Includes +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Qt Includes +#include +#include +#include +#include +#include +#include + + +WebView::WebView(QWidget *parent) + : KWebView(parent) +{ + page()->setForwardUnsupportedContent(true); + connect(page(), SIGNAL(unsupportedContent(QNetworkReply *)), page(), SLOT(downloadResponse(QNetworkReply *))); + connect(page(), SIGNAL(downloadRequested(const QNetworkRequest &)), page(), SLOT(downloadRequest(const QNetworkRequest &))); + connect(this, SIGNAL(linkShiftClicked(const KUrl &)), page(), SLOT(downloadUrl(const KUrl &))); + + QWebSettings::setIconDatabasePath( KStandardDirs::locateLocal("cache","kwebapp.favicons") ); + + setContextMenuPolicy(Qt::CustomContextMenu); + + connect(this, SIGNAL(titleChanged(const QString &)), this, SLOT(setTitle(const QString &))); + connect(this, SIGNAL(iconChanged()), this, SLOT(setIcon())); + connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(menuRequested(const QPoint &))); +} + + +void WebView::setTitle(const QString &t) +{ + setWindowTitle(t); +} + + +void WebView::setIcon() +{ + setWindowIcon(icon()); +} + + +void WebView::menuRequested(const QPoint &pos) +{ + QWebHitTestResult result = page()->mainFrame()->hitTestContent(pos); + + KMenu menu(this); + QAction *a; + + // is a link? + if (!result.linkUrl().isEmpty()) + { + a = new KAction(KIcon("window-new"), i18n("Open in default browser"), this); + a->setData(result.linkUrl()); + connect(a, SIGNAL(triggered(bool)), this, SLOT(openLinkInDefaultBrowser())); + menu.addAction(a); + + menu.addAction(pageAction(KWebPage::DownloadLinkToDisk)); + menu.addAction(pageAction(KWebPage::CopyLinkToClipboard)); + menu.addSeparator(); + } + + if(history()->canGoBack()) + { + menu.addAction(pageAction(KWebPage::Back)); + } + + if(history()->canGoBack()) + { + menu.addAction(pageAction(KWebPage::Forward)); + } + + menu.addAction(pageAction(KWebPage::Reload)); + + menu.exec(mapToGlobal(pos)); +} + + +void WebView::openLinkInDefaultBrowser() +{ + KAction *a = qobject_cast(sender()); + KUrl u(a->data().toUrl()); + + (void)new KRun(u, this, 0); +} -- cgit v1.2.1