plasma-framework/src/platformstatus/platformstatus.cpp

85 lines
2.5 KiB
C++
Raw Normal View History

#include <platformstatus.h>
#include <QDBusConnection>
#include <QStandardPaths>
2013-10-05 02:32:44 +02:00
#include <kconfiggroup.h>
#include <ksharedconfig.h>
2013-08-09 04:14:26 +02:00
#include <QDebug>
2013-10-05 02:32:44 +02:00
#include <kdirwatch.h>
#include <kpluginfactory.h>
#include <qstandardpaths.h>
#include "platformstatusadaptor.h"
#include "../plasma/config-plasma.h"
2014-09-03 12:40:37 +02:00
const char *defaultPackage = "org.kde.plasma.desktop";
K_PLUGIN_FACTORY(PlatformStatusFactory, registerPlugin<PlatformStatus>();)
PlatformStatus::PlatformStatus(QObject *parent, const QVariantList &)
: KDEDModule(parent)
{
new PlatformStatusAdaptor(this);
QDBusConnection::sessionBus().registerObject("/PlatformStatus", this);
findShellPackage(false);
const QString globalrcPath = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, "kdeglobals");
connect(KDirWatch::self(), SIGNAL(dirty(QString)), this, SLOT(fileDirtied(QString)));
KDirWatch::self()->addFile(globalrcPath);
}
void PlatformStatus::findShellPackage(bool sendSignal)
{
KConfigGroup group(KSharedConfig::openConfig("kdeglobals"), "DesktopShell");
const QString package = group.readEntry("shellPackage", defaultPackage);
2013-04-21 18:36:00 +02:00
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
PLASMA_RELATIVE_DATA_INSTALL_DIR "/shells/" + package + '/',
2014-04-26 01:45:47 +02:00
QStandardPaths::LocateDirectory);
if (path.isEmpty()) {
if (package != defaultPackage) {
group.deleteEntry("ShellPackage");
findShellPackage(sendSignal);
}
return;
}
m_shellPackage = package;
2013-04-21 18:36:00 +02:00
QString runtimePlatform = group.readEntry("RuntimePlatform", QString());
KConfig packageDefaults(path + "contents/defaults", KConfig::SimpleConfig);
2013-04-21 18:36:00 +02:00
group = KConfigGroup(&packageDefaults, "Desktop");
runtimePlatform = group.readEntry("RuntimePlatform", runtimePlatform);
const bool runtimeChanged = runtimePlatform != m_runtimePlatform.join(',');
if (runtimeChanged) {
m_runtimePlatform = runtimePlatform.split(',');
}
if (sendSignal) {
emit shellPackageChanged(m_shellPackage);
emit runtimePlatformChanged(m_runtimePlatform);
}
}
QString PlatformStatus::shellPackage() const
{
return m_shellPackage;
}
QStringList PlatformStatus::runtimePlatform() const
{
return m_runtimePlatform;
}
void PlatformStatus::fileDirtied(const QString &path)
{
if (path.endsWith("kdeglobals")) {
findShellPackage(true);
}
}
#include "platformstatus.moc"