2010-09-05 01:23:35 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2010 Ryan Rix <ry@n.rix.si>
|
|
|
|
* Copyright 2010 Siddharth Sharma <siddharth.kde@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "plasmakpartcorona.h"
|
|
|
|
|
|
|
|
#include "plasmakpart.h"
|
|
|
|
|
|
|
|
#include <KDebug>
|
|
|
|
|
|
|
|
#include <Plasma/Containment>
|
|
|
|
|
|
|
|
#include <qaction.h>
|
|
|
|
#include <qfile.h>
|
|
|
|
#include "scripting/scriptengine.h"
|
|
|
|
|
2011-01-16 20:17:00 +01:00
|
|
|
PlasmaKPartCorona::PlasmaKPartCorona(QObject *parent)
|
2010-09-05 01:23:35 +02:00
|
|
|
: Plasma::Corona(parent)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaKPartCorona::init()
|
|
|
|
{
|
|
|
|
enableAction("Lock Widgets", false);
|
|
|
|
enableAction("Shortcut Settings", false);
|
2011-01-12 01:09:23 +01:00
|
|
|
setDefaultContainmentPlugin("newspaper");
|
2010-09-05 01:23:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaKPartCorona::loadDefaultLayout()
|
|
|
|
{
|
|
|
|
// used to force a save into the config file
|
|
|
|
KConfigGroup invalidConfig;
|
2011-01-16 20:17:00 +01:00
|
|
|
Plasma::Containment *c = addContainment(QString());
|
2010-09-05 01:23:35 +02:00
|
|
|
|
|
|
|
if (!c) {
|
|
|
|
// do some error reporting?
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
evaluateScripts(PlasmaKPartScripting::ScriptEngine::defaultLayoutScripts());
|
|
|
|
requestConfigSync();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaKPartCorona::evaluateScripts(const QStringList &scripts)
|
|
|
|
{
|
|
|
|
foreach (const QString &script, scripts) {
|
|
|
|
PlasmaKPartScripting::ScriptEngine scriptEngine(this);
|
|
|
|
connect(&scriptEngine, SIGNAL(printError(QString)), this, SLOT(printScriptError(QString)));
|
|
|
|
connect(&scriptEngine, SIGNAL(print(QString)), this, SLOT(printScriptMessage(QString)));
|
|
|
|
|
|
|
|
QFile file(script);
|
|
|
|
if (file.open(QIODevice::ReadOnly | QIODevice::Text) ) {
|
|
|
|
QString code = file.readAll();
|
|
|
|
kDebug() << "evaluating startup script:" << script;
|
|
|
|
scriptEngine.evaluateScript(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaKPartCorona::printScriptError(const QString &error)
|
|
|
|
{
|
2011-02-07 21:29:08 +01:00
|
|
|
kWarning() << "Startup script error:" << error;
|
2010-09-05 01:23:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaKPartCorona::printScriptMessage(const QString &error)
|
|
|
|
{
|
|
|
|
kDebug() << "Startup script: " << error;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::Containment* PlasmaKPartCorona::containment()
|
|
|
|
{
|
2011-01-16 20:17:00 +01:00
|
|
|
// We only have one containment, so just try and return the first one
|
2010-09-05 01:23:35 +02:00
|
|
|
QList<Plasma::Containment*> list = containments();
|
2011-01-16 20:17:00 +01:00
|
|
|
if (!list.isEmpty()) {
|
|
|
|
return list.first();
|
|
|
|
}
|
2010-09-05 01:23:35 +02:00
|
|
|
|
2011-01-16 20:17:00 +01:00
|
|
|
return 0;
|
2010-09-05 01:23:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "plasmakpartcorona.moc"
|