~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/scriptengines/webkit/dashboardapplet.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 2007 Zack Rusin <zack@kde.org>
 
3
Copyright (c) 2008 Beat Wolf <asraniel@fryx.ch>
 
4
 
 
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:
 
11
 
 
12
The above copyright notice and this permission notice shall be included in
 
13
all copies or substantial portions of the Software.
 
14
 
 
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.
 
22
 */
 
23
#include "dashboardapplet.h"
 
24
 
 
25
#include <QWebFrame>
 
26
#include <QFile>
 
27
#include <QByteArray>
 
28
 
 
29
#include <KGlobal>
 
30
#include <KStandardDirs>
 
31
 
 
32
#include <Plasma/WebView>
 
33
#include <Plasma/Applet>
 
34
#include <Plasma/Package>
 
35
 
 
36
#include "dashboardjs.h"
 
37
 
 
38
DashboardApplet::DashboardApplet(QObject *parent, const QVariantList &args)
 
39
    : WebApplet(parent, args)
 
40
{
 
41
}
 
42
 
 
43
DashboardApplet::~DashboardApplet()
 
44
{
 
45
}
 
46
 
 
47
bool DashboardApplet::init()
 
48
{
 
49
    applet()->setAspectRatioMode(Plasma::FixedSize);
 
50
    return WebApplet::init();
 
51
}
 
52
 
 
53
void DashboardApplet::loadFinished(bool success)
 
54
{
 
55
    WebApplet::loadFinished(success);
 
56
    if (success) {
 
57
        view()->resize(view()->mainFrame()->contentsSize());
 
58
        applet()->resize(view()->mainFrame()->contentsSize());
 
59
    }
 
60
}
 
61
 
 
62
void DashboardApplet::constraintsEvent(Plasma::Constraints constraints)
 
63
{
 
64
    if (constraints & Plasma::FormFactorConstraint) {
 
65
        applet()->setBackgroundHints(Plasma::Applet::NoBackground);
 
66
    }
 
67
}
 
68
 
 
69
void DashboardApplet::initJsObjects()
 
70
{
 
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()));
 
75
}
 
76
 
 
77
QByteArray DashboardApplet::dataFor(const QString &str)
 
78
{
 
79
    QFile f(str);
 
80
    f.open(QIODevice::ReadOnly);
 
81
    QByteArray data = f.readAll();
 
82
    f.close();
 
83
 
 
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";
 
87
 
 
88
    data.replace("file:///System/Library/WidgetResources", jsBaseDir.toUtf8());
 
89
    data.replace("/System/Library/WidgetResources", jsBaseDir.toUtf8());
 
90
 
 
91
    return data;
 
92
}
 
93
 
 
94
#include "dashboardapplet.moc"