2
Copyright (c) 2007 Zack Rusin <zack@kde.org>
4
Permission is hereby granted, free of charge, to any person obtaining a copy
5
of this software and associated documentation files (the "Software"), to deal
6
in the Software without restriction, including without limitation the rights
7
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
copies of the Software, and to permit persons to whom the Software is
9
furnished to do so, subject to the following conditions:
11
The above copyright notice and this permission notice shall be included in
12
all copies or substantial portions of the Software.
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
#include "webapplet.h"
34
#include <Plasma/Applet>
35
#include <Plasma/Package>
36
#include <Plasma/WebView>
38
using namespace Plasma;
40
class WebApplet::Private
48
void init(WebApplet *q)
52
Plasma::Applet *applet = q->applet();
53
applet->setAcceptsHoverEvents(true);
55
view = new Plasma::WebView(applet);
56
QObject::connect(view, SIGNAL(loadFinished(bool)),
57
q, SLOT(loadFinished(bool)));
58
QObject::connect(view->page(), SIGNAL(frameCreated(QWebFrame *)),
59
q, SLOT(connectFrame(QWebFrame *)));
60
q->connectFrame(view->mainFrame());
62
view->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
63
view->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
65
QPalette palette = view->palette();
66
palette.setColor(QPalette::Base, Qt::transparent);
67
view->page()->setPalette(palette);
70
Plasma::WebView *view;
74
WebApplet::WebApplet(QObject *parent, const QVariantList &args)
75
: AppletScript(parent),
81
WebApplet::~WebApplet()
86
bool WebApplet::init()
91
webpage = package()->filePath("mainscript");
93
if (webpage.isEmpty()) {
94
kDebug() << "fail! no page";
100
KUrl url(package()->filePath("html"));
101
kDebug() << webpage << package()->path() << url;
102
d->view->mainFrame()->setHtml(dataFor(webpage), url);
106
void WebApplet::paintInterface(QPainter *painter,
107
const QStyleOptionGraphicsItem *option,
108
const QRect &contentsRect)
112
Q_UNUSED(contentsRect)
115
Plasma::WebView* WebApplet::view() const
120
void WebApplet::loadFinished(bool success)
125
void WebApplet::connectFrame(QWebFrame *frame)
127
connect(frame, SIGNAL(javaScriptWindowObjectCleared()),
128
this, SLOT(initJsObjects()));
131
void WebApplet::initJsObjects()
135
QByteArray WebApplet::dataFor(const QString &str)
138
f.open(QIODevice::ReadOnly);
139
QByteArray data = f.readAll();
144
QWebPage *WebApplet::page()
146
return d->view ? d->view->page() : 0;
149
bool WebApplet::loaded()
154
#include "webapplet.moc"