first draft of the platform status kded module

This commit is contained in:
Aaron Seigo 2013-04-21 18:04:29 +02:00
parent 4c21d54980
commit dad03a43ce
6 changed files with 153 additions and 0 deletions

View File

@ -2,5 +2,6 @@ add_subdirectory(plasma)
add_subdirectory(declarativeimports)
#add_subdirectory(kpart)
add_subdirectory(plasmapkg)
add_subdirectory(platformstatus)
add_subdirectory(scriptengines)
add_subdirectory(shell)

View File

@ -0,0 +1,10 @@
set(kded_platformstatus_SRCS platformstatus.cpp )
kde4_add_plugin(kded_platformstatus ${kded_platformstatus_SRCS})
target_link_libraries(kded_platformstatus ${KDE4_KDECORE_LIBS} ${KCoreAddons_LIBRARIES} Qt5::DBus)
install(TARGETS kded_platformstatus DESTINATION ${PLUGIN_INSTALL_DIR} )
install( FILES kded-platformstatus.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kded )
install( FILES org.kde.platformstatus.xml DESTINATION ${DBUS_INTERFACES_INSTALL_DIR} )

View File

@ -0,0 +1,9 @@
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KDEDModule
X-KDE-Library=kded_platformstatus
X-KDE-DBus-ModuleName=plaformstatus
X-KDE-Kded-autoload=true
X-KDE-Kded-load-on-demand=false
Name=Platform Status
Comment=Tracks the current shell package and the platform definition strings.

View File

@ -0,0 +1,19 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.PlatformStatus">
<property name="shellPackage" type="s" access="read"/>
<property name="runtimePlatform" type="as" access="read"/>
<signal name="shellPackageChanged">
<arg name="package" type="s" direction="out"/>
</signal>
<signal name="runtimePlatformChanged">
<arg name="runtimePlatform" type="as" direction="out"/>
</signal>
<method name="shellPackage">
<arg type="s" direction="out"/>
</method>
<method name="runtimePlatform">
<arg type="as" direction="out"/>
</method>
</interface>
</node>

View File

@ -0,0 +1,76 @@
#include <platformstatus.h>
#include <QDBusConnection>
#include <QStandardPaths>
#include <KConfigGroup>
#include <KDirWatch>
#include <KPluginFactory>
const char *defaultPackage = "org.kde.desktop";
K_PLUGIN_FACTORY(PlatformStatusFactory, registerPlugin<PlatformStatus>();)
K_EXPORT_PLUGIN(PlatformStatusFactory("platformstatus"))
PlatformStatus::PlatformStatus(QObject *parent, const QVariantList &)
: KDEDModule(parent)
{
QDBusConnection::sessionBus().registerObject("/PlatformStatus", this,
QDBusConnection::ExportAllProperties |
QDBusConnection::ExportAllSignals);
findShellPackage(false);
const QString globalrcPath = QStandardPaths::locate(QStandardPaths::ConfigLocation, "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);
const QString path = QStandardPaths::locate(QStandardPaths::DataLocation, "plasma/shells/" + package + "/");
if (path.isEmpty()) {
if (package != defaultPackage) {
group.deleteEntry("ShellPackage");
findShellPackage(sendSignal);
}
return;
}
m_shellPackage = package;
QString runtimePlatform = group.readEntry("runtimePlatform", QString());
KConfig packageDefaults(path + "contents/defaults", KConfig::SimpleConfig);
group = KConfigGroup(&packageDefaults, "DesktopShell");
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"

View File

@ -0,0 +1,38 @@
#ifndef PLATFORMSTATUS_H
#define PLATFORMSTATUS_H
#include <KDEDModule>
#include <QStringList>
class PlatformStatus : public KDEDModule
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.PlatformStatus")
Q_PROPERTY(QString shellPackage READ shellPackage NOTIFY shellPackageChanged)
Q_PROPERTY(QStringList runtimePlatform READ runtimePlatform NOTIFY runtimePlatformChanged)
public:
PlatformStatus(QObject *parent, const QVariantList &);
public Q_SLOTS:
QString shellPackage() const;
QStringList runtimePlatform() const;
Q_SIGNALS:
void shellPackageChanged(const QString &package);
void runtimePlatformChanged(const QStringList &runtimePlatform);
private:
void findShellPackage(bool sendSignal);
private Q_SLOTS:
void fileDirtied(const QString &path);
private:
QString m_shellPackage;
QStringList m_runtimePlatform;
};
#endif