Changeset View
Changeset View
Standalone View
Standalone View
src/kdbusservice.cpp
Show First 20 Lines • Show All 112 Lines • ▼ Show 20 Line(s) | 81 | public: | |||
---|---|---|---|---|---|
113 | 113 | | |||
114 | void generateServiceName() | 114 | void generateServiceName() | ||
115 | { | 115 | { | ||
116 | d->serviceName = d->generateServiceName(); | 116 | d->serviceName = d->generateServiceName(); | ||
117 | objectPath = QLatin1Char('/') + d->serviceName; | 117 | objectPath = QLatin1Char('/') + d->serviceName; | ||
118 | objectPath.replace(QLatin1Char('.'), QLatin1Char('/')); | 118 | objectPath.replace(QLatin1Char('.'), QLatin1Char('/')); | ||
119 | objectPath.replace(QLatin1Char('-'), QLatin1Char('_')); // see spec change at https://bugs.freedesktop.org/show_bug.cgi?id=95129 | 119 | objectPath.replace(QLatin1Char('-'), QLatin1Char('_')); // see spec change at https://bugs.freedesktop.org/show_bug.cgi?id=95129 | ||
120 | 120 | | |||
121 | | ||||
121 | if (options & KDBusService::Multiple) { | 122 | if (options & KDBusService::Multiple) { | ||
122 | bool inSandbox = false; | 123 | bool inSandbox = false; | ||
123 | if (!qEnvironmentVariableIsEmpty("XDG_RUNTIME_DIR")) { | 124 | if (!qEnvironmentVariableIsEmpty("XDG_RUNTIME_DIR")) { | ||
124 | inSandbox = QFileInfo::exists(QString::fromUtf8(qgetenv("XDG_RUNTIME_DIR")) + QLatin1String("/flatpak-info")); | 125 | inSandbox = QFileInfo::exists(QString::fromUtf8(qgetenv("XDG_RUNTIME_DIR")) + QLatin1String("/flatpak-info")); | ||
125 | } | 126 | } | ||
126 | 127 | | |||
127 | if (inSandbox) { | 128 | if (inSandbox) { | ||
128 | d->serviceName += QStringLiteral(".kdbus-") + QDBusConnection::sessionBus().baseService().replace(QRegularExpression(QStringLiteral("[\\.:]")), QStringLiteral("_")); | 129 | d->serviceName += QStringLiteral(".kdbus-") + QDBusConnection::sessionBus().baseService().replace(QRegularExpression(QStringLiteral("[\\.:]")), QStringLiteral("_")); | ||
129 | } else { | 130 | } else { | ||
130 | d->serviceName += QLatin1Char('-') + QString::number(QCoreApplication::applicationPid()); | 131 | d->serviceName += QLatin1Char('-') + QString::number(QCoreApplication::applicationPid()); | ||
131 | } | 132 | } | ||
133 | } else if (options & KDBusService::Unique) { | ||||
134 | auto reply = bus->registeredServiceNames(); | ||||
135 | if (!reply.isValid()) { | ||||
136 | return; | ||||
137 | } | ||||
138 | | ||||
139 | for (const auto& serviceName : reply.value()) { | ||||
140 | if (serviceName.startsWith(d->serviceName)) { | ||||
141 | d->serviceName = serviceName; | ||||
142 | return; | ||||
143 | } | ||||
144 | } | ||||
132 | } | 145 | } | ||
133 | } | 146 | } | ||
134 | 147 | | |||
135 | void registerOnBus() | 148 | void registerOnBus() | ||
136 | { | 149 | { | ||
137 | auto bus = QDBusConnection::sessionBus(); | 150 | auto bus = QDBusConnection::sessionBus(); | ||
138 | bool objectRegistered = false; | 151 | bool objectRegistered = false; | ||
139 | objectRegistered = bus.registerObject(QStringLiteral("/MainApplication"), | 152 | objectRegistered = bus.registerObject(QStringLiteral("/MainApplication"), | ||
▲ Show 20 Lines • Show All 208 Lines • Show Last 20 Lines |