19#include "LocationWatcher.h"
21#include "ProcessControl.h"
23#include <QDBusConnection>
29const QString locationServiceName = QStringLiteral(
"com.lomiri.location.Service");
30const QString locationObjectPath = QStringLiteral(
"/com/lomiri/location/Service");
31const QString propertiesInterface = QStringLiteral(
"org.freedesktop.DBus.Properties");
32const QString methodPropertiesChanged = QStringLiteral(
"PropertiesChanged");
35class LocationWatcherPrivate:
public QObject
40 LocationWatcherPrivate(ProcessControl *processControl);
43 void onPropertiesChanged(
const QString &interface,
44 const QVariantMap &changedProps,
45 const QStringList &invalidatedProps);
48 friend class LocationWatcher;
49 ProcessControl *m_processControl;
50 QDBusConnection m_connection;
51 QStringList m_clientApplications;
54LocationWatcherPrivate::LocationWatcherPrivate(ProcessControl *processControl):
56 m_processControl(processControl),
57 m_connection(QDBusConnection::systemBus())
59 m_connection.connect(locationServiceName,
62 methodPropertiesChanged,
64 SLOT(onPropertiesChanged(QString,QVariantMap,QStringList)));
67void LocationWatcherPrivate::onPropertiesChanged(
const QString &interface,
68 const QVariantMap &changedProps,
69 const QStringList &invalidatedProps)
72 Q_UNUSED(invalidatedProps);
74 qDebug() << Q_FUNC_INFO << changedProps;
75 const auto i = changedProps.find(QStringLiteral(
"ClientApplications"));
76 if (i != changedProps.end()) {
77 const QStringList appIds = i.value().toStringList();
78 qDebug() <<
"Location clients changed:" << appIds;
81 m_clientApplications.clear();
82 for (
const QString &appId: appIds) {
83 QStringList parts = appId.split(
'_');
84 QString versionLessAppId = parts.mid(0, 2).join(
'_');
85 m_clientApplications.append(versionLessAppId);
87 m_processControl->setAwakenProcesses(m_clientApplications);
91LocationWatcher::LocationWatcher(ProcessControl *processControl):
92 QObject(processControl),
93 d_ptr(new LocationWatcherPrivate(processControl))
97LocationWatcher::~LocationWatcher() =
default;
99#include "LocationWatcher.moc"