'hidden' contacts
[dyskinesia.git] / src / k8webview.cpp
blob412e3ebce0a7a045e91dac2228f570a809ec5c77
1 /* coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://sam.zoy.org/wtfpl/COPYING for more details.
9 */
10 #include <QDebug>
12 #include <QByteArray>
13 #include <QNetworkRequest>
14 #include <QTextCodec>
15 #include <QString>
16 #include <QUiLoader>
17 #include <QWebFrame>
18 #include <QWebHitTestResult>
19 #include <QWebPage>
20 #include <QWebView>
22 #include "k8webview.h"
25 extern bool debugOutput;
28 ///////////////////////////////////////////////////////////////////////////////
29 static void printQStr (const QString &str) {
30 //QTextCodec *codec = QTextCodec::codecForName("koi8-r");
31 QTextCodec *codec = QTextCodec::codecForLocale();
32 QByteArray ba;
33 if (codec) ba = codec->fromUnicode(str); else ba = str.toLatin1();
34 const char *s = ba.constData();
35 int sz = ba.size();
36 while (sz > 0) {
37 int len = strlen(s);
38 if (debugOutput) fprintf(stdout, "%s", s);
39 sz -= len;
40 if (sz > 0) {
41 if (debugOutput) fprintf(stdout, "\n ");
42 sz--;
43 s += len+1;
46 if (debugOutput) fprintf(stdout, "\n");
50 K8WebPage::K8WebPage (QObject *parent) : QWebPage(parent)
55 void K8WebPage::javaScriptConsoleMessage (const QString &message, int lineNumber, const QString &sourceID) {
56 QString us = mainFrame()->url().toString();
57 if (debugOutput) fprintf(stderr, "----------------------------\n");
58 printQStr(QString("line: %1; sid: %2").arg(QString::number(lineNumber)).arg(sourceID));
59 printQStr("msg: "+message);
60 if (debugOutput) fflush(stderr);
64 QObject *K8WebPage::createPlugin (const QString &classId, const QUrl &url, const QStringList &paramNames, const QStringList &paramValues) {
65 Q_UNUSED(url);
66 Q_UNUSED(paramNames);
67 Q_UNUSED(paramValues);
68 //qDebug() << "plugin class:" << classId;
69 QUiLoader loader;
70 return loader.createWidget(classId, view());
74 ///////////////////////////////////////////////////////////////////////////////
75 K8WebView::K8WebView (QWidget *parent) : QWebView(parent), mPage(new K8WebPage(this)), mAllowContextMenu(false) {
76 setPage(mPage);
78 QWebSettings *ws = page()->settings();
79 //ws->setFontFamily(QWebSettings::SerifFont, "Arial");
80 //ws->setFontSize(QWebSettings::SerifFont, 12);
81 page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
83 ws->setAttribute(QWebSettings::AutoLoadImages, true);
84 ws->setAttribute(QWebSettings::JavascriptEnabled, true);
85 ws->setAttribute(QWebSettings::JavaEnabled, false);
86 ws->setAttribute(QWebSettings::PluginsEnabled, false);
87 ws->setAttribute(QWebSettings::PrivateBrowsingEnabled, true);
88 ws->setAttribute(QWebSettings::JavascriptCanOpenWindows, false);
89 ws->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true);
90 ws->setAttribute(QWebSettings::DeveloperExtrasEnabled, false);
91 ws->setAttribute(QWebSettings::LinksIncludedInFocusChain, false);
92 #if QT_VERSION >= 0x040500
93 ws->setAttribute(QWebSettings::ZoomTextOnly, false);
94 ws->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, false);
95 ws->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, false);
96 ws->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, false);
97 ws->setAttribute(QWebSettings::SiteSpecificQuirksEnabled, false);
98 #endif
99 connect(mPage, SIGNAL(downloadRequested(const QNetworkRequest &)), this, SLOT(onDownloadRequested(const QNetworkRequest &)));
103 K8WebView::~K8WebView () {
107 void K8WebView::contextMenuEvent (QContextMenuEvent *event) {
108 if (mAllowContextMenu) {
109 QWebView::contextMenuEvent(event);
110 } else {
111 QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());
112 emit webContextMenu(r, event->pos());
117 void K8WebView::onDownloadRequested (const QNetworkRequest &request) {
118 qDebug() << "dlrq:" << request.url();