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"
32 #include <Plasma/Applet>
33 #include <Plasma/Package>
34 #include <Plasma/WebView>
36 using namespace Plasma
;
38 class WebApplet::Private
46 void init(WebApplet
*q
)
50 Plasma::Applet
*applet
= q
->applet();
51 applet
->setAcceptsHoverEvents(true);
53 page
= new Plasma::WebView(applet
);
54 page
->setPage(new WebPage(page
));
55 QObject::connect(page
, SIGNAL(loadFinished(bool)),
56 q
, SLOT(loadFinished(bool)));
57 QObject::connect(page
->page(), SIGNAL(frameCreated(QWebFrame
*)),
58 q
, SLOT(connectFrame(QWebFrame
*)));
59 q
->connectFrame(page
->mainFrame());
61 page
->mainFrame()->setScrollBarPolicy(Qt::Horizontal
, Qt::ScrollBarAlwaysOff
);
62 page
->mainFrame()->setScrollBarPolicy(Qt::Vertical
, Qt::ScrollBarAlwaysOff
);
64 QPalette palette
= page
->palette();
65 palette
.setBrush(QPalette::Background
, QBrush(Qt::transparent
));
66 page
->setPalette(palette
);
69 Plasma::WebView
*page
;
73 WebApplet::WebApplet(QObject
*parent
, const QVariantList
&args
)
74 : AppletScript(parent
),
80 WebApplet::~WebApplet()
85 bool WebApplet::init()
90 webpage
= package()->filePath("mainscript");
91 //kDebug() << "webpage is at" << webpage;
92 if (webpage
.isEmpty()) {
95 //kDebug() << package()->path() << package()->filePath("root");
96 d
->page
->mainFrame()->setHtml(dataFor(webpage
), QUrl(package()->filePath("root")));
100 void WebApplet::paintInterface(QPainter
*painter
,
101 const QStyleOptionGraphicsItem
*option
,
102 const QRect
&contentsRect
)
106 Q_UNUSED(contentsRect
)
109 Plasma::WebView
* WebApplet::view() const
114 void WebApplet::loadFinished(bool success
)
119 void WebApplet::connectFrame(QWebFrame
*frame
)
121 connect(frame
, SIGNAL(javaScriptWindowObjectCleared()),
122 this, SLOT(initJsObjects()));
125 void WebApplet::initJsObjects()
129 QByteArray
WebApplet::dataFor(const QString
&str
)
132 f
.open(QIODevice::ReadOnly
);
133 QByteArray data
= f
.readAll();
138 Plasma::WebView
* WebApplet::page()
143 bool WebApplet::loaded()
148 #include "webapplet.moc"