Commit bb1d00e1 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Add list of timer ids to DBus interface

That's a bit more straight-forward than introspecting the interface
parent 34b2ae87
Pipeline #73256 passed with stage
in 17 seconds
......@@ -28,26 +28,11 @@ TimerModel::TimerModel(QObject *parent)
}
setConnectedToDaemon(m_interface->isValid());
QDBusInterface *interface = new QDBusInterface(QStringLiteral("org.kde.kclockd"),
QStringLiteral("/Timers"),
QStringLiteral("org.freedesktop.DBus.Introspectable"),
QDBusConnection::sessionBus(),
this);
QDBusReply<QString> reply = interface->call(QStringLiteral("Introspect"));
if (reply.isValid()) {
auto xmlMsg = reply.value();
QXmlStreamReader xml(xmlMsg);
while (!xml.atEnd()) {
xml.readNext();
if (xml.name() == QStringLiteral("node") && xml.attributes().hasAttribute(QStringLiteral("name"))) {
if (xml.attributes().value(QStringLiteral("name")).toString().indexOf(QStringLiteral("org")) == -1) {
// already existed on kclock launch, not justCreated
this->addTimer(xml.attributes().value(QStringLiteral("name")).toString(), false);
}
}
}
const QStringList timers = m_interface->timers();
for (const QString &timerId : timers) {
addTimer(timerId, false);
}
interface->deleteLater();
// watch for kclockd
m_watcher = new QDBusServiceWatcher(QStringLiteral("org.kde.kclockd"), QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this);
......
......@@ -93,3 +93,17 @@ void TimerModel::remove(int index)
save();
}
QStringList TimerModel::timers() const
{
QStringList ret;
ret.reserve(m_timerList.size());
// Filter out { } and - which are not allowed in DBus paths
static QRegularExpression dbusfilter("[{}-]");
for (const Timer *timer : qAsConst(m_timerList)) {
ret << timer->uuid().toString().replace(dbusfilter, QString());
}
return ret;
}
......@@ -26,6 +26,7 @@ public:
void load();
void save();
Q_SCRIPTABLE QStringList timers() const;
Q_SCRIPTABLE void addTimer(int length, QString label, QString commandTimeout, bool running);
Q_SCRIPTABLE void removeTimer(QString uuid);
Q_SIGNALS:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment