2010-09-05 01:23:35 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2006-2008 Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2009 Marco Martin <notmart@gmail.com>
|
|
|
|
* 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 "plasmakpart.h"
|
|
|
|
|
2011-08-11 00:16:24 +02:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QGraphicsProxyWidget>
|
|
|
|
#include <QGraphicsLinearLayout>
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
#include <KDebug>
|
|
|
|
#include <KStandardDirs>
|
2010-09-05 01:23:35 +02:00
|
|
|
|
|
|
|
#include <Plasma/Containment>
|
|
|
|
#include <Plasma/Theme>
|
|
|
|
#include <Plasma/Applet>
|
2011-01-25 00:00:42 +01:00
|
|
|
#include <Plasma/Wallpaper>
|
2010-09-05 01:23:35 +02:00
|
|
|
#include <plasma/pluginloader.h>
|
|
|
|
|
2011-08-11 00:16:24 +02:00
|
|
|
#include "plasmakpartcorona.h"
|
|
|
|
#include "plasmakpartview.h"
|
2010-09-05 01:23:35 +02:00
|
|
|
|
|
|
|
K_PLUGIN_FACTORY(plasmaKPartFactory, registerPlugin<PlasmaKPart>();)
|
|
|
|
K_EXPORT_PLUGIN(plasmaKPartFactory("plasma-kpart","plasma-kpart") )
|
|
|
|
|
2011-01-16 20:12:25 +01:00
|
|
|
PlasmaKPart::PlasmaKPart(QWidget *parentWidget, QObject *parent, const QVariantList &args)
|
|
|
|
: KParts::ReadOnlyPart(parent),
|
|
|
|
m_corona(0),
|
2011-08-11 01:29:10 +02:00
|
|
|
m_view(new PlasmaKPartView(0, 1))
|
2010-09-05 01:23:35 +02:00
|
|
|
{
|
2011-01-16 20:12:25 +01:00
|
|
|
setComponentData(plasmaKPartFactory::componentData());
|
2010-09-05 01:23:35 +02:00
|
|
|
|
|
|
|
KGlobal::locale()->insertCatalog("libplasma");
|
|
|
|
KGlobal::locale()->insertCatalog("plasmagenericshell");
|
|
|
|
KGlobal::locale()->insertCatalog("plasma-kpart");
|
|
|
|
|
|
|
|
setThemeDefaults();
|
|
|
|
|
|
|
|
setWidget(m_view);
|
|
|
|
|
|
|
|
// initialize the plugin loader
|
2011-01-16 20:12:25 +01:00
|
|
|
if (args.length() > 0) {
|
|
|
|
Plasma::PluginLoader *loader = qVariantValue<Plasma::PluginLoader *>(args.first());
|
|
|
|
if (loader) {
|
|
|
|
Plasma::PluginLoader::setPluginLoader(loader);
|
2010-09-05 01:23:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-11 01:29:10 +02:00
|
|
|
setAutoDeletePart(false);
|
2011-08-11 00:16:24 +02:00
|
|
|
QTimer::singleShot(0, this, SLOT(initCorona()));
|
2010-09-05 01:23:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PlasmaKPart::~PlasmaKPart()
|
|
|
|
{
|
2011-08-11 00:16:24 +02:00
|
|
|
delete m_view;
|
|
|
|
m_view = 0;
|
|
|
|
|
|
|
|
if (!m_configFile.isEmpty()) {
|
|
|
|
m_corona->saveLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete m_corona;
|
|
|
|
m_corona = 0;
|
|
|
|
|
|
|
|
//TODO: This manual sync() should not be necessary?
|
|
|
|
syncConfig();
|
2010-09-05 01:23:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaKPart::setThemeDefaults()
|
|
|
|
{
|
2010-09-12 23:15:13 +02:00
|
|
|
KConfigGroup cg(KSharedConfig::openConfig("plasmarc"), "Theme-plasma-kpart" );
|
2011-01-25 00:00:42 +01:00
|
|
|
const QString themeName = cg.readEntry("name", "appdashboard");
|
2010-09-05 01:23:35 +02:00
|
|
|
Plasma::Theme::defaultTheme()->setUseGlobalSettings(false);
|
|
|
|
Plasma::Theme::defaultTheme()->setThemeName(themeName);
|
|
|
|
|
|
|
|
cg = KConfigGroup(KGlobal::config(), "General");
|
|
|
|
|
|
|
|
Plasma::Theme::defaultTheme()->setFont(cg.readEntry("desktopFont", QFont("Sans") ));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaKPart::syncConfig()
|
|
|
|
{
|
|
|
|
KGlobal::config()->sync();
|
|
|
|
}
|
|
|
|
|
2011-07-13 12:41:25 +02:00
|
|
|
void PlasmaKPart::initCorona()
|
2010-09-05 01:23:35 +02:00
|
|
|
{
|
2011-07-13 12:41:25 +02:00
|
|
|
if (m_corona) {
|
|
|
|
return;
|
|
|
|
}
|
2010-09-05 01:23:35 +02:00
|
|
|
|
2011-07-13 12:41:25 +02:00
|
|
|
m_corona = new PlasmaKPartCorona(this);
|
|
|
|
connect(m_corona, SIGNAL(containmentAdded(Plasma::Containment*)), this, SLOT(createView(Plasma::Containment*)));
|
|
|
|
connect(m_corona, SIGNAL(configSynced()), this, SLOT(syncConfig()));
|
2010-09-05 01:23:35 +02:00
|
|
|
|
2011-07-13 12:41:25 +02:00
|
|
|
m_corona->setItemIndexMethod(QGraphicsScene::NoIndex);
|
2011-08-11 00:16:24 +02:00
|
|
|
m_corona->initializeLayout(m_configFile);
|
2011-07-13 12:41:25 +02:00
|
|
|
|
|
|
|
m_view->show();
|
|
|
|
}
|
2010-09-05 01:23:35 +02:00
|
|
|
|
2011-07-13 12:41:25 +02:00
|
|
|
PlasmaKPartCorona* PlasmaKPart::corona() const
|
|
|
|
{
|
2010-09-05 01:23:35 +02:00
|
|
|
return m_corona;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaKPart::createView(Plasma::Containment *containment)
|
|
|
|
{
|
|
|
|
m_view->setContainment(containment);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaKPart::addApplet(const QString& name, const QVariantList& args, const QRectF& geometry )
|
|
|
|
{
|
|
|
|
containment()->addApplet(name, args, geometry);
|
|
|
|
}
|
|
|
|
|
2011-07-13 12:41:25 +02:00
|
|
|
Plasma::Applet::List PlasmaKPart::listActiveApplets() const
|
2010-09-05 01:23:35 +02:00
|
|
|
{
|
|
|
|
return containment()->applets();
|
|
|
|
}
|
|
|
|
|
2011-08-11 00:16:24 +02:00
|
|
|
QString PlasmaKPart::configFile() const
|
|
|
|
{
|
|
|
|
return m_configFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaKPart::setConfigFile(const QString &file)
|
|
|
|
{
|
|
|
|
m_configFile = file;
|
|
|
|
if (m_corona && QFile::exists(m_configFile)) {
|
|
|
|
m_corona->initializeLayout(m_configFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-13 12:41:25 +02:00
|
|
|
Plasma::Containment* PlasmaKPart::containment() const
|
2010-09-05 01:23:35 +02:00
|
|
|
{
|
|
|
|
return corona()->containments().first();
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "plasmakpart.moc"
|