add more spacing
[personal-kdebase.git] / workspace / plasma / scriptengines / webkit / dashboardapplet.cpp
blobceb36a73ada6eb988d18f3dc8a1c65d25e3c931c
1 /*
2 Copyright (c) 2007 Zack Rusin <zack@kde.org>
3 Copyright (c) 2008 Beat Wolf <asraniel@fryx.ch>
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
23 #include "dashboardapplet.h"
25 #include <QWebFrame>
26 #include <QFile>
27 #include <QByteArray>
29 #include <KGlobal>
30 #include <KStandardDirs>
32 #include <Plasma/WebView>
33 #include <Plasma/Applet>
34 #include <Plasma/Package>
36 #include "dashboardjs.h"
38 DashboardApplet::DashboardApplet(QObject *parent, const QVariantList &args)
39 : WebApplet(parent, args)
43 DashboardApplet::~DashboardApplet()
47 bool DashboardApplet::init()
49 applet()->setAspectRatioMode(Plasma::FixedSize);
50 return WebApplet::init();
53 void DashboardApplet::loadFinished(bool success)
55 WebApplet::loadFinished(success);
56 if (success) {
57 page()->resize(page()->mainFrame()->contentsSize());
58 applet()->resize(page()->mainFrame()->contentsSize());
62 void DashboardApplet::constraintsEvent(Plasma::Constraints constraints)
64 if (constraints & Plasma::FormFactorConstraint) {
65 applet()->setBackgroundHints(Plasma::Applet::NoBackground);
69 void DashboardApplet::initJsObjects()
71 QWebFrame *frame = qobject_cast<QWebFrame*>(sender());
72 Q_ASSERT(frame);
73 frame->addToJavaScriptWindowObject(QLatin1String("applet"), this);
74 frame->addToJavaScriptWindowObject(QLatin1String("widget"), new DashboardJs(frame, this, applet()));
77 QByteArray DashboardApplet::dataFor(const QString &str)
79 QFile f(str);
80 f.open(QIODevice::ReadOnly);
81 QByteArray data = f.readAll();
82 f.close();
84 //replace the apple javascript imports with the kde ones
85 QString jsBaseDir = KGlobal::dirs()->findResourceDir("data","plasma/dashboard/button/genericButton.js")
86 + "plasma/dashboard";
88 data.replace("file:///System/Library/WidgetResources", jsBaseDir.toUtf8());
89 data.replace("/System/Library/WidgetResources", jsBaseDir.toUtf8());
91 return data;
94 #include "dashboardapplet.moc"