From 9e12ec978211369530186fc72aa862b1f40243ef Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Tue, 16 Jun 2009 13:09:16 +0200 Subject: Allow only one instance of applet --- src/Applet/Applet.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/Applet/Applet.cpp') diff --git a/src/Applet/Applet.cpp b/src/Applet/Applet.cpp index 0f957ce..b3ea05b 100644 --- a/src/Applet/Applet.cpp +++ b/src/Applet/Applet.cpp @@ -19,9 +19,11 @@ #include "CCApplet.h" #include +#include //@@global applet object CApplet *applet; + static void crash_notify_cb(const char* progname) { @@ -45,12 +47,26 @@ int main(int argc, char **argv) /* this should bind the dispatcher with mainloop */ dispatcher.attach(NULL); DBus::default_dispatcher = &dispatcher; - + DBus::Connection session = DBus::Connection::SessionBus(); + //FIXME: possible race, but the dbus-c++ API won't let us check return value of request_name :( + if(session.has_name("com.redhat.abrt.applet")) + { + //applet is already running + std::cerr << "Applet is already running." << std::endl; + return -1; + } + else + { + //applet is not running, so claim the name on the session bus + session.request_name("com.redhat.abrt.applet"); + } + DBus::Connection conn = DBus::Connection::SystemBus(); //CDBusClient client(conn, CC_DBUS_PATH, CC_DBUS_NAME); applet = new CApplet(conn, CC_DBUS_PATH, CC_DBUS_NAME); applet->ConnectCrashHandler(crash_notify_cb); gtk_main(); + gtk_main(); gdk_threads_leave(); return 0; } -- cgit