summaryrefslogtreecommitdiff
path: root/kwebapp/webview.cpp
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2011-11-08 10:17:36 +0100
committerAndrea Diamantini <adjam7@gmail.com>2011-11-08 10:17:36 +0100
commit7187da9812bbe6ffb5bf272f18f8e74c8d23d3c7 (patch)
tree210924711005452a622383dcfadb20c5c4cfb364 /kwebapp/webview.cpp
parentLet rekonq save file remotely (diff)
downloadrekonq-7187da9812bbe6ffb5bf272f18f8e74c8d23d3c7.tar.xz
Application Shortcut
Added an action to manage it in the tools menu, added initial code to manage icons, added kwebapp application
Diffstat (limited to 'kwebapp/webview.cpp')
-rw-r--r--kwebapp/webview.cpp121
1 files changed, 121 insertions, 0 deletions
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 <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 . *
+ ***************************************************************************/
+
+
+// Self Includes
+#include "webview.h"
+#include "webview.moc"
+
+// 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>
+
+// Qt Includes
+#include <QUrl>
+#include <QDebug>
+#include <QWebHitTestResult>
+#include <QWebHistory>
+#include <QNetworkRequest>
+#include <QPointer>
+
+
+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<KAction*>(sender());
+ KUrl u(a->data().toUrl());
+
+ (void)new KRun(u, this, 0);
+}