Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[qtcontacts-sqlite] Register an owner name for dbus notifications of …
…contact changes. Contributes to JB#53239

sailjail requires broadcast signals to be sent from a named connection
rather than an anonymous one.
  • Loading branch information
blammit committed Feb 25, 2021
1 parent a0d3937 commit 6c25acf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/engine/contactnotifier.cpp
Expand Up @@ -34,12 +34,15 @@
#include "trace_p.h"

#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusMessage>
#include <QDBusMetaType>
#include <QVector>
#include <QUuid>

#include <QDebug>

#define NOTIFIER_NAME "org.nemomobile.contacts.sqlite.uuid_%1"
#define NOTIFIER_PATH "/org/nemomobile/contacts/sqlite"
#define NOTIFIER_INTERFACE "org.nemomobile.contacts.sqlite"

Expand Down Expand Up @@ -97,6 +100,23 @@ ContactNotifier::ContactNotifier(bool nonprivileged)
: m_nonprivileged(nonprivileged)
{
initialize();

// Register a unique name for this signal source on the session bus.
// Remove surrounding braces and hyphens from the generated uuid.
const QString uuid = QUuid::createUuid().toString();
const QString serviceName = QString(NOTIFIER_NAME)
.arg(uuid.mid(1, uuid.length() - 2).replace('-', QString()));
if (QDBusConnection::sessionBus().registerService(serviceName)) {
m_serviceName = serviceName;
} else {
qWarning() << "Failed to register D-Bus service name for contact change notifications:"
<< serviceName << QDBusConnection::sessionBus().lastError();
}
}

ContactNotifier::~ContactNotifier()
{
QDBusConnection::sessionBus().unregisterService(m_serviceName);
}

void ContactNotifier::collectionsAdded(const QList<QContactCollectionId> &collectionIds)
Expand Down
4 changes: 4 additions & 0 deletions src/engine/contactnotifier.h
Expand Up @@ -47,6 +47,7 @@ class ContactNotifier

public:
ContactNotifier(bool nonprivileged);
~ContactNotifier();

void collectionsAdded(const QList<QContactCollectionId> &collectionIds);
void collectionsChanged(const QList<QContactCollectionId> &collectionIds);
Expand All @@ -62,6 +63,9 @@ class ContactNotifier
void displayLabelGroupsChanged();

bool connect(const char *name, const char *signature, QObject *receiver, const char *slot);

private:
QString m_serviceName;
};

#endif

0 comments on commit 6c25acf

Please sign in to comment.