[gnote] Prevent starting a second Gnote using DBus. (Closes #585773)
- From: Hubert Figuière <hub src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnote] Prevent starting a second Gnote using DBus. (Closes #585773)
- Date: Sun, 19 Jul 2009 03:29:15 +0000 (UTC)
commit 8736827dd8248af920b5efae76f438c9fb640655
Author: Hubert Figuiere <hub figuiere net>
Date: Sat Jul 18 15:22:02 2009 -0400
Prevent starting a second Gnote using DBus. (Closes #585773)
src/Makefile.am | 1 +
src/dbus/Makefile.am | 5 +++-
src/dbus/remotecontrolclient.cpp | 37 +++++++++++++++++++++++++++++
src/dbus/remotecontrolclient.hpp | 47 ++++++++++++++++++++++++++++++++++++++
src/gnote.cpp | 14 +++++++----
src/remotecontrolproxy.cpp | 20 +++++++++++++--
src/remotecontrolproxy.hpp | 5 ++-
7 files changed, 118 insertions(+), 11 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0455b84..97d7023 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -81,6 +81,7 @@ if HAVE_DBUS
SUBDIRS += dbus
DBUS_SOURCES=remotecontrolproxy.hpp remotecontrolproxy.cpp \
dbus/remotecontrol.hpp dbus/remotecontrol.cpp \
+ dbus/remotecontrolclient.hpp dbus/remotecontrolclient.cpp \
$(NULL)
endif
diff --git a/src/dbus/Makefile.am b/src/dbus/Makefile.am
index 28dbb6a..6ae69eb 100644
--- a/src/dbus/Makefile.am
+++ b/src/dbus/Makefile.am
@@ -3,7 +3,10 @@
remotecontrol-glue.hpp: gnote-introspect.xml
dbusxx-xml2cpp $^ --adaptor=$@
-BUILT_SOURCES = remotecontrol-glue.hpp
+remotecontrol-client-glue.hpp: gnote-introspect.xml
+ dbusxx-xml2cpp $^ --proxy=$@
+
+BUILT_SOURCES = remotecontrol-glue.hpp remotecontrol-client-glue.hpp
CLEANFILES = $(BUILT_SOURCES)
dist-hook:
diff --git a/src/dbus/remotecontrolclient.cpp b/src/dbus/remotecontrolclient.cpp
new file mode 100644
index 0000000..36df663
--- /dev/null
+++ b/src/dbus/remotecontrolclient.cpp
@@ -0,0 +1,37 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "dbus/remotecontrolclient.hpp"
+
+namespace gnote {
+
+
+
+ RemoteControlClient::RemoteControlClient(DBus::Connection &connection,
+ const char *p, const char *name)
+ : DBus::ObjectProxy(connection, p, name)
+ {
+ }
+
+
+
+}
+
+
diff --git a/src/dbus/remotecontrolclient.hpp b/src/dbus/remotecontrolclient.hpp
new file mode 100644
index 0000000..7b37a14
--- /dev/null
+++ b/src/dbus/remotecontrolclient.hpp
@@ -0,0 +1,47 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __GNOTE_REMOTECONTROLCLIENT_HPP_
+#define __GNOTE_REMOTECONTROLCLIENT_HPP_
+
+#include "dbus/remotecontrol-client-glue.hpp"
+
+namespace gnote {
+
+
+class RemoteControlClient
+ : public org::gnome::Gnote::RemoteControl_proxy
+ , public DBus::IntrospectableProxy
+ , public DBus::ObjectProxy
+{
+public:
+ RemoteControlClient(DBus::Connection &connection, const char *path, const char *name);
+
+ virtual void NoteAdded(const std::string&) {}
+ virtual void NoteDeleted(const std::string&, const std::string&) {}
+ virtual void NoteSaved(const std::string&) {}
+
+
+};
+
+}
+
+
+#endif
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 509e6e6..363cf25 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -56,6 +56,7 @@
#if ENABLE_DBUS
#include "remotecontrolproxy.hpp"
+#include "dbus/remotecontrolclient.hpp"
#endif
namespace gnote {
@@ -221,13 +222,16 @@ namespace gnote {
DBG_OUT("Gnote remote control active.");
}
else {
- // If Tomboy is already running, open the search window
+ // If Gnote is already running, open the search window
// so the user gets some sort of feedback when they
- // attempt to run Tomboy again.
- IRemoteControl *m_remote;
+ // attempt to run Gnote again.
+ RemoteControlClient *remote;
try {
- m_remote = RemoteControlProxy::get_instance();
- m_remote->DisplaySearch();
+ remote = RemoteControlProxy::get_instance();
+ DBG_ASSERT(remote, "remote is NULL, something is wrong");
+ if(remote) {
+ remote->DisplaySearch();
+ }
}
catch (...)
{
diff --git a/src/remotecontrolproxy.cpp b/src/remotecontrolproxy.cpp
index 89f058a..e1fd0d9 100644
--- a/src/remotecontrolproxy.cpp
+++ b/src/remotecontrolproxy.cpp
@@ -19,7 +19,9 @@
#include <dbus-c++/glib-integration.h>
+#include "debug.hpp"
#include "dbus/remotecontrol.hpp"
+#include "dbus/remotecontrolclient.hpp"
#include "remotecontrolproxy.hpp"
@@ -28,8 +30,13 @@ namespace gnote {
const char *RemoteControlProxy::GNOTE_SERVER_NAME = "org.gnome.Gnote";
const char *RemoteControlProxy::GNOTE_SERVER_PATH = "/org/gnome/Gnote/RemoteControl";
-IRemoteControl *RemoteControlProxy::get_instance()
+RemoteControlClient *RemoteControlProxy::get_instance()
{
+ DBus::Connection conn = DBus::Connection::SessionBus();
+ if(conn.has_name(GNOTE_SERVER_NAME)) {
+ return new RemoteControlClient(conn, GNOTE_SERVER_PATH, GNOTE_SERVER_NAME);
+ }
+
return NULL;
}
@@ -38,13 +45,20 @@ DBus::Glib::BusDispatcher dispatcher;
RemoteControl *RemoteControlProxy::register_remote(NoteManager & manager)
{
+ RemoteControl *remote_control = NULL;
DBus::default_dispatcher = &dispatcher;
dispatcher.attach(NULL);
DBus::Connection conn = DBus::Connection::SessionBus();
- conn.request_name(GNOTE_SERVER_NAME);
+ // NOTE: I find no way to check whether we connected or not
+ // using DBus-C++
+ if(!conn.has_name(GNOTE_SERVER_NAME)) {
+
+ conn.request_name(GNOTE_SERVER_NAME);
+ DBG_ASSERT(conn.connected(), "must be connected");
- RemoteControl *remote_control = new RemoteControl (conn, manager);
+ remote_control = new RemoteControl (conn, manager);
+ }
return remote_control;
}
diff --git a/src/remotecontrolproxy.hpp b/src/remotecontrolproxy.hpp
index 49a8ba5..71d97cc 100644
--- a/src/remotecontrolproxy.hpp
+++ b/src/remotecontrolproxy.hpp
@@ -21,11 +21,11 @@
#ifndef _REMOTECONTROL_PROXY_HPP_
#define _REMOTECONTROL_PROXY_HPP_
-#include "dbus/iremotecontrol.hpp"
namespace gnote {
class RemoteControl;
+class RemoteControlClient;
class NoteManager;
class RemoteControlProxy
@@ -34,7 +34,8 @@ public:
static const char *GNOTE_SERVER_PATH;
static const char *GNOTE_SERVER_NAME;
- static IRemoteControl *get_instance();
+ /** Get a dbus client */
+ static RemoteControlClient *get_instance();
static RemoteControl *register_remote(NoteManager & manager);
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]