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.
13 #include <QNetworkRequest>
18 #include <QWebHitTestResult>
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();
33 if (codec
) ba
= codec
->fromUnicode(str
); else ba
= str
.toLatin1();
34 const char *s
= ba
.constData();
38 if (debugOutput
) fprintf(stdout
, "%s", s
);
41 if (debugOutput
) fprintf(stdout
, "\n ");
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
¶mNames
, const QStringList
¶mValues
) {
67 Q_UNUSED(paramValues
);
68 //qDebug() << "plugin class:" << classId;
70 return loader
.createWidget(classId
, view());
74 ///////////////////////////////////////////////////////////////////////////////
75 K8WebView::K8WebView (QWidget
*parent
) : QWebView(parent
), mPage(new K8WebPage(this)), mAllowContextMenu(false) {
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);
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
);
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();