~ubuntu-branches/ubuntu/natty/kdebase-runtime/natty-proposed

« back to all changes in this revision

Viewing changes to plasma/kpart/plasmakpartcorona.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-24 11:07:10 UTC
  • mto: (0.8.7 upstream)
  • mto: This revision was merged to the branch mainline in revision 129.
  • Revision ID: james.westby@ubuntu.com-20101124110710-6dbsyw0yh21qvn82
Tags: upstream-4.5.80
ImportĀ upstreamĀ versionĀ 4.5.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2008 Aaron Seigo <aseigo@kde.org>
 
3
 *   Copyright 2010 Ryan Rix <ry@n.rix.si>
 
4
 *   Copyright 2010 Siddharth Sharma <siddharth.kde@gmail.com>
 
5
 * 
 
6
 *   This program is free software; you can redistribute it and/or modify
 
7
 *   it under the terms of the GNU Library General Public License as
 
8
 *   published by the Free Software Foundation; either version 2, or
 
9
 *   (at your option) any later version.
 
10
 *
 
11
 *   This program is distributed in the hope that it will be useful,
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *   GNU General Public License for more details
 
15
 *
 
16
 *   You should have received a copy of the GNU Library General Public
 
17
 *   License along with this program; if not, write to the
 
18
 *   Free Software Foundation, Inc.,
 
19
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
20
 */
 
21
 
 
22
#include "plasmakpartcorona.h"
 
23
 
 
24
#include "plasmakpart.h"
 
25
 
 
26
#include <KDebug>
 
27
 
 
28
#include <Plasma/Containment>
 
29
 
 
30
#include <qaction.h>
 
31
#include <qfile.h>
 
32
#include "scripting/scriptengine.h"
 
33
 
 
34
PlasmaKPartCorona::PlasmaKPartCorona(QObject* parent)
 
35
    : Plasma::Corona(parent)
 
36
{
 
37
    init();
 
38
}
 
39
 
 
40
void PlasmaKPartCorona::init()
 
41
{
 
42
    enableAction("Lock Widgets", false);
 
43
    enableAction("Shortcut Settings", false);
 
44
}
 
45
 
 
46
void PlasmaKPartCorona::loadDefaultLayout()
 
47
{
 
48
    // used to force a save into the config file
 
49
    KConfigGroup invalidConfig;
 
50
    Plasma::Containment* c = addContainment("newspaper");
 
51
 
 
52
    if (!c) {
 
53
        // do some error reporting?
 
54
        return;
 
55
    }
 
56
 
 
57
    evaluateScripts(PlasmaKPartScripting::ScriptEngine::defaultLayoutScripts());
 
58
    requestConfigSync();
 
59
}
 
60
 
 
61
void PlasmaKPartCorona::evaluateScripts(const QStringList &scripts)
 
62
{
 
63
    foreach (const QString &script, scripts) {
 
64
        PlasmaKPartScripting::ScriptEngine scriptEngine(this);
 
65
        connect(&scriptEngine, SIGNAL(printError(QString)), this, SLOT(printScriptError(QString)));
 
66
        connect(&scriptEngine, SIGNAL(print(QString)), this, SLOT(printScriptMessage(QString)));
 
67
 
 
68
        QFile file(script);
 
69
        if (file.open(QIODevice::ReadOnly | QIODevice::Text) ) {
 
70
            QString code = file.readAll();
 
71
            kDebug() << "evaluating startup script:" << script;
 
72
            scriptEngine.evaluateScript(code);
 
73
        }
 
74
    }
 
75
}
 
76
 
 
77
void PlasmaKPartCorona::printScriptError(const QString &error)
 
78
{
 
79
    kWarning() << "Startup script errror:" << error;
 
80
}
 
81
 
 
82
void PlasmaKPartCorona::printScriptMessage(const QString &error)
 
83
{
 
84
    kDebug() << "Startup script: " << error;
 
85
}
 
86
 
 
87
Plasma::Containment* PlasmaKPartCorona::containment()
 
88
{
 
89
    QList<Plasma::Containment*> list = containments();
 
90
 
 
91
    return list.first(); // We only have one containment
 
92
}
 
93
 
 
94
#include "plasmakpartcorona.moc"