2013-04-21 18:04:29 +02:00
|
|
|
#include <platformstatus.h>
|
|
|
|
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
2013-10-05 02:32:44 +02:00
|
|
|
#include <kconfiggroup.h>
|
2014-03-29 08:22:28 +01:00
|
|
|
#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>
|
2013-10-05 12:49:18 +02:00
|
|
|
#include <qstandardpaths.h>
|
2013-04-21 18:04:29 +02:00
|
|
|
|
2013-06-24 08:59:13 +02:00
|
|
|
#include "platformstatusadaptor.h"
|
2014-04-27 17:14:22 +02:00
|
|
|
#include "../plasma/config-plasma.h"
|
2013-06-24 08:59:13 +02:00
|
|
|
|
2014-09-28 12:40:40 +02:00
|
|
|
const char defaultPackage[] = "org.kde.plasma.desktop";
|
|
|
|
const char defaultLnFPackage[] = "org.kde.breeze.desktop";
|
2013-04-21 18:04:29 +02:00
|
|
|
|
|
|
|
K_PLUGIN_FACTORY(PlatformStatusFactory, registerPlugin<PlatformStatus>();)
|
|
|
|
|
|
|
|
PlatformStatus::PlatformStatus(QObject *parent, const QVariantList &)
|
|
|
|
: KDEDModule(parent)
|
|
|
|
{
|
2013-06-24 08:59:13 +02:00
|
|
|
new PlatformStatusAdaptor(this);
|
|
|
|
QDBusConnection::sessionBus().registerObject("/PlatformStatus", this);
|
|
|
|
|
2013-04-21 18:04:29 +02:00
|
|
|
findShellPackage(false);
|
2014-09-03 14:38:36 +02:00
|
|
|
findLookAndFeelPackage(false);
|
2013-06-24 08:59:13 +02:00
|
|
|
|
2013-12-08 13:30:40 +01:00
|
|
|
const QString globalrcPath = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, "kdeglobals");
|
2013-04-21 18:04:29 +02:00
|
|
|
connect(KDirWatch::self(), SIGNAL(dirty(QString)), this, SLOT(fileDirtied(QString)));
|
2014-09-03 14:38:36 +02:00
|
|
|
connect(KDirWatch::self(), SIGNAL(created(QString)), this, SLOT(fileDirtied(QString)));
|
2013-04-21 18:04:29 +02:00
|
|
|
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,
|
2014-04-27 17:14:22 +02:00
|
|
|
PLASMA_RELATIVE_DATA_INSTALL_DIR "/shells/" + package + '/',
|
2014-04-26 01:45:47 +02:00
|
|
|
QStandardPaths::LocateDirectory);
|
2013-04-21 18:04:29 +02:00
|
|
|
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());
|
2013-04-21 18:04:29 +02:00
|
|
|
KConfig packageDefaults(path + "contents/defaults", KConfig::SimpleConfig);
|
2013-04-21 18:36:00 +02:00
|
|
|
group = KConfigGroup(&packageDefaults, "Desktop");
|
|
|
|
runtimePlatform = group.readEntry("RuntimePlatform", runtimePlatform);
|
2013-04-21 18:04:29 +02:00
|
|
|
const bool runtimeChanged = runtimePlatform != m_runtimePlatform.join(',');
|
|
|
|
if (runtimeChanged) {
|
|
|
|
m_runtimePlatform = runtimePlatform.split(',');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sendSignal) {
|
|
|
|
emit shellPackageChanged(m_shellPackage);
|
|
|
|
emit runtimePlatformChanged(m_runtimePlatform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-03 14:38:36 +02:00
|
|
|
void PlatformStatus::findLookAndFeelPackage(bool sendSignal)
|
|
|
|
{
|
|
|
|
|
|
|
|
KConfigGroup group(KSharedConfig::openConfig("kdeglobals"), "KDE");
|
|
|
|
QString package = group.readEntry("LookAndFeelPackage", QString());
|
|
|
|
|
|
|
|
if (package.isEmpty()) {
|
|
|
|
const QString shellPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
|
|
|
|
PLASMA_RELATIVE_DATA_INSTALL_DIR "/shells/" + m_shellPackage + '/',
|
|
|
|
QStandardPaths::LocateDirectory);
|
|
|
|
KConfig packageDefaults(shellPath + "contents/defaults", KConfig::SimpleConfig);
|
|
|
|
group = KConfigGroup(&packageDefaults, "Desktop");
|
|
|
|
package = group.readEntry("LookAndFeel", defaultLnFPackage);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
|
|
|
|
PLASMA_RELATIVE_DATA_INSTALL_DIR "/look-and-feel/" + package + '/',
|
|
|
|
QStandardPaths::LocateDirectory);
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
if (package != defaultPackage) {
|
2015-01-29 13:35:31 +01:00
|
|
|
group.deleteEntry("LookAndFeel");
|
2014-09-03 14:38:36 +02:00
|
|
|
findLookAndFeelPackage(sendSignal);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool lnfChanged = (m_lookAndFeelPackage != package);
|
|
|
|
m_lookAndFeelPackage = package;
|
|
|
|
|
|
|
|
if (sendSignal && lnfChanged) {
|
|
|
|
emit lookAndFeelPackageChanged(m_lookAndFeelPackage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-21 18:04:29 +02:00
|
|
|
QString PlatformStatus::shellPackage() const
|
|
|
|
{
|
|
|
|
return m_shellPackage;
|
|
|
|
}
|
|
|
|
|
2014-09-03 14:38:36 +02:00
|
|
|
QString PlatformStatus::lookAndFeelPackage() const
|
|
|
|
{
|
|
|
|
return m_lookAndFeelPackage;
|
|
|
|
}
|
|
|
|
|
2013-04-21 18:04:29 +02:00
|
|
|
QStringList PlatformStatus::runtimePlatform() const
|
|
|
|
{
|
|
|
|
return m_runtimePlatform;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlatformStatus::fileDirtied(const QString &path)
|
|
|
|
{
|
|
|
|
if (path.endsWith("kdeglobals")) {
|
|
|
|
findShellPackage(true);
|
2014-09-03 14:38:36 +02:00
|
|
|
findLookAndFeelPackage(true);
|
2013-04-21 18:04:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "platformstatus.moc"
|