From 38621bba327b6889c98a00fdd1cc97c9cdaa4f0b Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 24 May 2022 11:33:42 +0300 Subject: [PATCH] knotify: use KApplication instead of KUniqueApplication Signed-off-by: Ivailo Monev --- knotify/knotify.cpp | 3 +-- knotify/main.cpp | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/knotify/knotify.cpp b/knotify/knotify.cpp index 183aaa53..d6fc9324 100644 --- a/knotify/knotify.cpp +++ b/knotify/knotify.cpp @@ -39,8 +39,6 @@ #include "notifybytaskbar.h" #include "notifybyktts.h" - - KNotify::KNotify( QObject *parent ) : QObject( parent ), m_counter(0) @@ -48,6 +46,7 @@ KNotify::KNotify( QObject *parent ) loadConfig(); (void)new KNotifyAdaptor(this); (void)new KSolidNotify(this); + QDBusConnection::sessionBus().registerService("org.kde.knotify"); QDBusConnection::sessionBus().registerObject("/Notify", this, QDBusConnection::ExportAdaptors /*| QDBusConnection::ExportScriptableSlots | QDBusConnection::ExportScriptableSignals*/ ); } diff --git a/knotify/main.cpp b/knotify/main.cpp index c24351ac..9e0d589b 100644 --- a/knotify/main.cpp +++ b/knotify/main.cpp @@ -19,7 +19,7 @@ */ -#include +#include #include #include #include @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include "knotify.h" @@ -45,21 +47,25 @@ int main(int argc, char **argv) aboutdata.addAuthor(ki18n("Allan Sandfeld Jensen"),ki18n("Porting to KDE 4"),"kde@carewolf.com"); KCmdLineArgs::init( argc, argv, &aboutdata ); - KUniqueApplication::addCmdLineOptions(); - - // initialize application - if ( !KUniqueApplication::start() ) { - kDebug() << "Running knotify found"; - return 0; - } + KApplication app; // do not connect to ksmserver at all, knotify is launched on demand and doesn't need // to know about logout, and moreover it may be ksmserver who tries to launch knotify, // in which case there is a deadlock with ksmserver waiting for knotify to finish // startup and knotify waiting to register with ksmserver - unsetenv( "SESSION_MANAGER" ); - KUniqueApplication app; - + app.disableSessionManagement(); + + QDBusConnection session = QDBusConnection::sessionBus(); + if (!session.isConnected()) { + kWarning() << "No DBUS session-bus found. Check if you have started the DBUS server."; + return 1; + } + QDBusReply sessionReply = session.interface()->isServiceRegistered("org.kde.knotify"); + if (sessionReply.isValid() && sessionReply.value() == true) { + kWarning() << "Another instance of knotify is already running!"; + return 2; + } + /* * the default KMessageBoxMessageHandler will do messagesbox that notify * so we have a deadlock if one debug message is shown as messagebox.