[gnote] Port D-Bus support to Gio::DBus



commit dc5a32d30128540f60fc731aa3b1a99fb866e947
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Fri Aug 26 20:54:17 2011 +0300

    Port D-Bus support to Gio::DBus
    
    Remove dependency on dbus-c++ by replacing it with Gio::DBus alternatives.
    Remove D-Bus support condition from build system.
    In addition fixes bug 618330.

 .gitignore                             |    1 -
 configure.ac                           |   18 --
 data/Makefile.am                       |    2 -
 src/Makefile.am                        |    6 +-
 src/dbus/Makefile.am                   |   16 +-
 src/dbus/remotecontrol-client-glue.cpp |  139 +++++++++++
 src/dbus/remotecontrol-client-glue.hpp |   52 ++++
 src/dbus/remotecontrol-glue.cpp        |  414 ++++++++++++++++++++++++++++++++
 src/dbus/remotecontrol-glue.hpp        |  132 ++++++++++
 src/dbus/remotecontrol.cpp             |    7 +-
 src/dbus/remotecontrol.hpp             |    8 +-
 src/dbus/remotecontrolclient.cpp       |   10 +-
 src/dbus/remotecontrolclient.hpp       |    9 +-
 src/gnote.cpp                          |  196 +++++++--------
 src/gnote.hpp                          |  108 +++++----
 src/remotecontrolproxy.cpp             |  110 +++++++--
 src/remotecontrolproxy.hpp             |   24 ++-
 17 files changed, 1020 insertions(+), 232 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index c6ea3c5..5422ade 100644
--- a/.gitignore
+++ b/.gitignore
@@ -47,7 +47,6 @@ data/gnote.schemas
 data/GNOME_GnoteApplet.server
 data/GNOME_GnoteApplet.server.in
 data/org.gnome.Gnote.service
-src/dbus/remotecontrol*glue.hpp
 src/dttest
 src/filestest
 src/gnote
diff --git a/configure.ac b/configure.ac
index 02732d3..f35f6cd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,7 +29,6 @@ LIBGTKMM_VERSION=3.0
 LIBPANELAPPLET_VERSION=3.0
 GTKSPELL_VERSION=2.0.9
 BOOST_VERSION=1.34
-DBUSCPP_VERSION=0.5.0
 
 AC_PROG_CXX
 AC_GNU_SOURCE
@@ -140,22 +139,6 @@ if test "$GCC" = "yes"; then
 fi
 AC_LANG_POP
 
-#
-# Use DBus to export our remote control if available.
-#
-AC_ARG_ENABLE(dbus,
-	AS_HELP_STRING([--enable-dbus],[compile with dbus support @<:@default: yes@:>@]),
-	[],[enable_dbus=yes])
-
-if test "$enable_dbus" != "no"; then
-	PKG_CHECK_MODULES(DBUS, dbus-c++-1 >= $DBUSCPP_VERSION, [
-		have_dbus="yes"
-		AC_DEFINE([ENABLE_DBUS], [1], [Define to 1 if DBus is enabled])
-	], have_dbus="no")
-fi
-AM_CONDITIONAL(HAVE_DBUS, test "$have_dbus" = "yes")
-
-
 
 AC_ARG_WITH(dbus_service_dir, [  --with-dbus-service-dir=DIR            Where to install Gnote's DBus service file.])
 AM_CONDITIONAL(WITH_DBUS_SERVICE_DIR, test "x$with_dbus_service_dir" != "x")
@@ -221,6 +204,5 @@ Options:
 
   Spellchecking support:       ${FIXED_GTKSPELL}
   GNOME Panel Applet support:  ${have_panelapplet}
-  DBus support:                ${have_dbus}
 
 "
diff --git a/data/Makefile.am b/data/Makefile.am
index 16371b3..2c65123 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -20,7 +20,6 @@ gsettings_SCHEMAS = org.gnome.gnote.gschema.xml
 @GSETTINGS_RULES@
 
 
-if HAVE_DBUS
 dbusservicedir       = $(DBUS_SERVICE_DIR)
 dbusservice_in_files = org.gnome.Gnote.service.in
 dbusservice_DATA     = $(dbusservice_in_files:.service.in=.service)
@@ -29,7 +28,6 @@ $(dbusservice_DATA): $(dbusservice_in_files) Makefile
 	sed -e "s|\ bindir\@|$(bindir)|g"	\
 	    -e "s|\ wrapper\@|gnote|g"		\
 	    < $< > $@
-endif
 
 if HAVE_PANELAPPLET
 appletdir       = $(datadir)/gnome-panel/4.0/applets
diff --git a/src/Makefile.am b/src/Makefile.am
index 6a6e1d6..b375c7a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,7 +10,6 @@ AM_CPPFLAGS= LIBGTKMM_CFLAGS@ @LIBGLIBMM_CFLAGS@ \
 	@GTKSPELL_CFLAGS@ @LIBXML_CFLAGS@ \
 	@LIBXSLT_CFLAGS@ \
 	@PCRE_CFLAGS@ \
-	@DBUS_CFLAGS@ \
 	@UUID_CFLAGS@ \
 	-DGNOTE_LOCALEDIR=\"@GNOTE_LOCALEDIR \" \
 	-DDATADIR=\"$(datadir)\" -DLIBDIR=\"$(libdir)\"
@@ -21,7 +20,6 @@ GNOTE_LIBS = libgnote.a $(top_builddir)/libtomboy/libtomboy.la \
 	@LIBGLIBMM_LIBS@ @LIBGTKMM_LIBS@ \
 	@LIBXSLT_LIBS@ \
 	@PCRE_LIBS@ \
-	@DBUS_LIBS@ \
 	@GTKSPELL_LIBS@ @GTK_LIBS@ \
 	@UUID_LIBS@
 
@@ -82,14 +80,14 @@ CLEANFILES = gnote-applet
 endif
 
 
-if HAVE_DBUS
 SUBDIRS += dbus
 DBUS_SOURCES=remotecontrolproxy.hpp remotecontrolproxy.cpp \
 	dbus/remotecontrol.hpp dbus/remotecontrol.cpp \
 	dbus/remotecontrolclient.hpp dbus/remotecontrolclient.cpp \
 	dbus/iremotecontrol.hpp \
+	dbus/remotecontrol-client-glue.cpp \
+	dbus/remotecontrol-glue.cpp \
 	$(NULL)
-endif
 
 libgnote_a_SOURCES = \
 	base/singleton.hpp \
diff --git a/src/dbus/Makefile.am b/src/dbus/Makefile.am
index bc04507..9a3f29d 100644
--- a/src/dbus/Makefile.am
+++ b/src/dbus/Makefile.am
@@ -1,15 +1,3 @@
+introspectdir = $(datadir)/gnote
 
-
-remotecontrol-glue.hpp: gnote-introspect.xml
-	dbusxx-xml2cpp $^ --adaptor=$@
-
-remotecontrol-client-glue.hpp: gnote-introspect.xml
-	dbusxx-xml2cpp $^ --proxy=$@
-
-BUILT_SOURCES = remotecontrol-glue.hpp remotecontrol-client-glue.hpp
-CLEANFILES = $(BUILT_SOURCES)
-
-dist-hook:
-	cd $(distdir); rm -f $(BUILT_SOURCES)
-
-EXTRA_DIST = gnote-introspect.xml
\ No newline at end of file
+introspect_DATA = gnote-introspect.xml
diff --git a/src/dbus/remotecontrol-client-glue.cpp b/src/dbus/remotecontrol-client-glue.cpp
new file mode 100644
index 0000000..2102730
--- /dev/null
+++ b/src/dbus/remotecontrol-client-glue.cpp
@@ -0,0 +1,139 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2011 Aurimas Cernius
+ *
+ * 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 "debug.hpp"
+#include "remotecontrol-client-glue.hpp"
+
+using namespace org::gnome::Gnote;
+
+RemoteControl_proxy::RemoteControl_proxy(const Glib::RefPtr<Gio::DBus::Connection> & connection,
+                                         const char * name, const char * p, const char * interface_name,
+                                         const Glib::RefPtr<Gio::DBus::InterfaceInfo> & gnote_interface)
+  : Gio::DBus::Proxy(connection, name, p, interface_name, gnote_interface)
+{
+}
+
+std::string RemoteControl_proxy::CreateNamedNote(const std::string & linked_title)
+{
+  Glib::VariantContainerBase result = call_remote("CreateNamedNote",
+    Glib::VariantContainerBase::create_tuple(Glib::Variant<Glib::ustring>::create(linked_title)));
+  if(result.get_n_children() == 0) {
+    return "";
+  }
+  Glib::Variant<Glib::ustring> res;
+  result.get_child(res);
+  return res.get();
+}
+
+std::string RemoteControl_proxy::CreateNote()
+{
+  Glib::VariantContainerBase result = call_remote("CreateNote", Glib::VariantContainerBase());
+  if(result.get_n_children() == 0) {
+    return "";
+  }
+  Glib::Variant<Glib::ustring> res;
+  result.get_child(res);
+  return res.get();
+}
+
+bool RemoteControl_proxy::DisplayNote(const std::string & uri)
+{
+  Glib::VariantContainerBase result = call_remote("DisplayNote",
+    Glib::VariantContainerBase::create_tuple(Glib::Variant<Glib::ustring>::create(uri)));
+  if(result.get_n_children() == 0) {
+    return false;
+  }
+  Glib::Variant<bool> res;
+  result.get_child(res);
+  return res.get();
+}
+
+bool RemoteControl_proxy::DisplayNoteWithSearch(const std::string & uri, const std::string & search)
+{
+  std::vector<Glib::VariantBase> parameters;
+  parameters.push_back(Glib::Variant<Glib::ustring>::create(uri));
+  parameters.push_back(Glib::Variant<Glib::ustring>::create(search));
+  Glib::VariantContainerBase result = call_remote("DisplayNoteWithSearch",
+    Glib::VariantContainerBase::create_tuple(parameters));
+  if(result.get_n_children() == 0) {
+    return false;
+  }
+  Glib::Variant<bool> res;
+  result.get_child(res);
+  return res.get();
+}
+
+void RemoteControl_proxy::DisplaySearch()
+{
+  call_remote("DisplaySearch", Glib::VariantContainerBase());
+}
+
+std::string RemoteControl_proxy::FindNote(const std::string & linked_title)
+{
+  Glib::VariantContainerBase result = call_remote("FindNote",
+    Glib::VariantContainerBase::create_tuple(Glib::Variant<Glib::ustring>::create(linked_title)));
+  if(result.get_n_children() == 0) {
+    return "";
+  }
+  Glib::Variant<Glib::ustring> res;
+  result.get_child(res);
+  return res.get();
+}
+
+std::string RemoteControl_proxy::FindStartHereNote()
+{
+  Glib::VariantContainerBase result = call_remote("FindStartHereNote", Glib::VariantContainerBase());
+  if(result.get_n_children() == 0) {
+    return "";
+  }
+  Glib::Variant<Glib::ustring> res;
+  result.get_child(res);
+  return res.get();
+}
+
+void RemoteControl_proxy::DisplaySearchWithText(const std::string & search_text)
+{
+  call_remote("DisplaySearchWithText", Glib::VariantContainerBase::create_tuple(Glib::Variant<Glib::ustring>::create(search_text)));
+}
+
+bool RemoteControl_proxy::SetNoteCompleteXml(const std::string & uri, const std::string & xml_contents)
+{
+  std::vector<Glib::VariantBase> parameters;
+  parameters.push_back(Glib::Variant<Glib::ustring>::create(uri));
+  parameters.push_back(Glib::Variant<Glib::ustring>::create(xml_contents));
+  Glib::VariantContainerBase result = call_remote("SetNoteCompleteXml", Glib::VariantContainerBase::create_tuple(parameters));
+  if(result.get_n_children() == 0) {
+    return false;
+  }
+  Glib::Variant<bool> res;
+  result.get_child(res);
+  return res.get();
+}
+
+Glib::VariantContainerBase RemoteControl_proxy::call_remote(const Glib::ustring & method_name, const Glib::VariantContainerBase & parameters)
+{
+  try {
+    return call_sync(method_name, parameters);
+  }
+  catch(...) {
+    ERR_OUT(("Remote call failed: " + method_name).c_str());
+    return Glib::VariantContainerBase();
+  }
+}
diff --git a/src/dbus/remotecontrol-client-glue.hpp b/src/dbus/remotecontrol-client-glue.hpp
new file mode 100644
index 0000000..7381077
--- /dev/null
+++ b/src/dbus/remotecontrol-client-glue.hpp
@@ -0,0 +1,52 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2011 Aurimas Cernius
+ *
+ * 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 <string>
+
+#include <giomm/dbusproxy.h>
+
+namespace org {
+namespace gnome {
+namespace Gnote {
+
+class RemoteControl_proxy
+  : public Gio::DBus::Proxy
+{
+public:
+  RemoteControl_proxy(const Glib::RefPtr<Gio::DBus::Connection> & connection,
+                      const char * name, const char * p, const char * interface_name,
+                      const Glib::RefPtr<Gio::DBus::InterfaceInfo> & gnote_interface);
+
+  std::string CreateNamedNote(const std::string & linked_title);
+  std::string CreateNote();
+  bool DisplayNote(const std::string & uri);
+  bool DisplayNoteWithSearch(const std::string & uri, const std::string & search);
+  void DisplaySearch();
+  std::string FindNote(const std::string & linked_title);
+  std::string FindStartHereNote();
+  void DisplaySearchWithText(const std::string & search_text);
+  bool SetNoteCompleteXml(const std::string & uri, const std::string & xml_contents);
+private:
+  Glib::VariantContainerBase call_remote(const Glib::ustring & method_name, const Glib::VariantContainerBase & parameters);
+};
+
+}
+}
+}
diff --git a/src/dbus/remotecontrol-glue.cpp b/src/dbus/remotecontrol-glue.cpp
new file mode 100644
index 0000000..867e60b
--- /dev/null
+++ b/src/dbus/remotecontrol-glue.cpp
@@ -0,0 +1,414 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2011 Aurimas Cernius
+ *
+ * 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 <gio/gio.h>
+#include <giomm/dbuserror.h>
+
+#include "debug.hpp"
+#include "remotecontrol-glue.hpp"
+
+using namespace org::gnome::Gnote;
+
+RemoteControl_adaptor::RemoteControl_adaptor(const Glib::RefPtr<Gio::DBus::Connection> & conn,
+                                             const char *object_path,
+                                             const char *interface_name,
+                                             const Glib::RefPtr<Gio::DBus::InterfaceInfo> & gnote_interface)
+  : Gio::DBus::InterfaceVTable(sigc::mem_fun(*this, &RemoteControl_adaptor::on_method_call))
+  , m_connection(conn)
+  , m_path(object_path)
+  , m_interface_name(interface_name)
+{
+  conn->register_object(object_path, gnote_interface, *this);
+
+  m_stubs["AddTagToNote"] = &RemoteControl_adaptor::AddTagToNote_stub;
+  m_stubs["CreateNamedNote"] = &RemoteControl_adaptor::CreateNamedNote_stub;
+  m_stubs["CreateNote"] = &RemoteControl_adaptor::CreateNote_stub;
+  m_stubs["DeleteNote"] = &RemoteControl_adaptor::DeleteNote_stub;
+  m_stubs["DisplayNote"] = &RemoteControl_adaptor::DisplayNote_stub;
+  m_stubs["DisplayNoteWithSearch"] = &RemoteControl_adaptor::DisplayNoteWithSearch_stub;
+  m_stubs["DisplaySearch"] = &RemoteControl_adaptor::DisplaySearch_stub;
+  m_stubs["DisplaySearchWithText"] = &RemoteControl_adaptor::DisplaySearchWithText_stub;
+  m_stubs["FindNote"] = &RemoteControl_adaptor::FindNote_stub;
+  m_stubs["FindStartHereNote"] = &RemoteControl_adaptor::FindStartHereNote_stub;
+  m_stubs["GetAllNotesWithTag"] = &RemoteControl_adaptor::GetAllNotesWithTag_stub;
+  m_stubs["GetNoteChangeDate"] = &RemoteControl_adaptor::GetNoteChangeDate_stub;
+  m_stubs["GetNoteCompleteXml"] = &RemoteControl_adaptor::GetNoteCompleteXml_stub;
+  m_stubs["GetNoteContents"] = &RemoteControl_adaptor::GetNoteContents_stub;
+  m_stubs["GetNoteContentsXml"] = &RemoteControl_adaptor::GetNoteContentsXml_stub;
+  m_stubs["GetNoteCreateDate"] = &RemoteControl_adaptor::GetNoteCreateDate_stub;
+  m_stubs["GetNoteTitle"] = &RemoteControl_adaptor::GetNoteTitle_stub;
+  m_stubs["GetTagsForNote"] = &RemoteControl_adaptor::GetTagsForNote_stub;
+  m_stubs["HideNote"] = &RemoteControl_adaptor::HideNote_stub;
+  m_stubs["ListAllNotes"] = &RemoteControl_adaptor::ListAllNotes_stub;
+  m_stubs["NoteExists"] = &RemoteControl_adaptor::NoteExists_stub;
+  m_stubs["RemoveTagFromNote"] = &RemoteControl_adaptor::RemoveTagFromNote_stub;
+  m_stubs["SearchNotes"] = &RemoteControl_adaptor::SearchNotes_stub;
+  m_stubs["SetNoteCompleteXml"] = &RemoteControl_adaptor::SetNoteCompleteXml_stub;
+  m_stubs["SetNoteContents"] = &RemoteControl_adaptor::SetNoteContents_stub;
+  m_stubs["SetNoteContentsXml"] = &RemoteControl_adaptor::SetNoteContentsXml_stub;
+  m_stubs["Version"] = &RemoteControl_adaptor::Version_stub;
+}
+
+void RemoteControl_adaptor::NoteAdded(const std::string & uri)
+{
+  emit_signal("NoteAdded", Glib::VariantContainerBase::create_tuple(Glib::Variant<Glib::ustring>::create(uri)));
+}
+
+void RemoteControl_adaptor::NoteDeleted(const std::string & uri, const std::string & title)
+{
+  std::vector<Glib::VariantBase> parameters;
+  parameters.push_back(Glib::Variant<Glib::ustring>::create(uri));
+  parameters.push_back(Glib::Variant<Glib::ustring>::create(title));
+  emit_signal("NoteDeleted", Glib::VariantContainerBase::create_tuple(parameters));
+}
+
+void RemoteControl_adaptor::NoteSaved(const std::string & uri)
+{
+  emit_signal("NoteSaved", Glib::VariantContainerBase::create_tuple(Glib::Variant<Glib::ustring>::create(uri)));
+}
+
+void RemoteControl_adaptor::on_method_call(const Glib::RefPtr<Gio::DBus::Connection> &,
+                                           const Glib::ustring &,
+                                           const Glib::ustring &,
+                                           const Glib::ustring &,
+                                           const Glib::ustring & method_name,
+                                           const Glib::VariantContainerBase & parameters,
+                                           const Glib::RefPtr<Gio::DBus::MethodInvocation> & invocation)
+{
+  std::map<Glib::ustring, stub_func>::iterator iter = m_stubs.find(method_name);
+  if(iter == m_stubs.end()) {
+    invocation->return_error(Gio::DBus::Error(Gio::DBus::Error::UNKNOWN_METHOD,
+                             "Unknown method: " + method_name));
+  }
+  else {
+    try {
+      stub_func func = iter->second;
+      invocation->return_value((this->*func)(parameters));
+    }
+    catch(Glib::Exception & e) {
+      invocation->return_error(Gio::DBus::Error(Gio::DBus::Error::UNKNOWN_METHOD,
+                               "Exception in method " + method_name + ": " + e.what()));
+    }
+    catch(std::exception & e) {
+      invocation->return_error(Gio::DBus::Error(Gio::DBus::Error::UNKNOWN_METHOD,
+                               "Exception in method " + method_name + ": " + e.what()));
+    }
+    catch(...) {
+      invocation->return_error(Gio::DBus::Error(Gio::DBus::Error::UNKNOWN_METHOD,
+                               "Exception in method " + method_name));
+    }
+  }
+}
+
+
+void RemoteControl_adaptor::emit_signal(const Glib::ustring & name, const Glib::VariantContainerBase & parameters)
+{
+  //work-around glibmm bug 645072
+  g_dbus_connection_emit_signal(m_connection->gobj(), NULL, m_path, m_interface_name, name.c_str(),
+                                  const_cast<GVariant*>(parameters.gobj()), NULL);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::AddTagToNote_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_bool_string_string(parameters, &RemoteControl_adaptor::AddTagToNote);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::CreateNamedNote_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_string_string(parameters, &RemoteControl_adaptor::CreateNamedNote);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::CreateNote_stub(const Glib::VariantContainerBase &)
+{
+  return Glib::VariantContainerBase::create_tuple(Glib::Variant<Glib::ustring>::create(CreateNote()));
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::DeleteNote_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_bool_string(parameters, &RemoteControl_adaptor::DeleteNote);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::DisplayNote_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_bool_string(parameters, &RemoteControl_adaptor::DisplayNote);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::DisplayNoteWithSearch_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_bool_string_string(parameters, &RemoteControl_adaptor::DisplayNoteWithSearch);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::DisplaySearch_stub(const Glib::VariantContainerBase &)
+{
+  DisplaySearch();
+  return Glib::VariantContainerBase();
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::DisplaySearchWithText_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_void_string(parameters, &RemoteControl_adaptor::DisplaySearchWithText);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::FindNote_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_string_string(parameters, &RemoteControl_adaptor::FindNote);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::FindStartHereNote_stub(const Glib::VariantContainerBase &)
+{
+  return Glib::VariantContainerBase::create_tuple(Glib::Variant<Glib::ustring>::create(FindStartHereNote()));
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::GetAllNotesWithTag_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_vectorstring_string(parameters, &RemoteControl_adaptor::GetAllNotesWithTag);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::GetNoteChangeDate_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_int_string(parameters, &RemoteControl_adaptor::GetNoteChangeDate);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::GetNoteCompleteXml_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_string_string(parameters, &RemoteControl_adaptor::GetNoteCompleteXml);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::GetNoteContents_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_string_string(parameters, &RemoteControl_adaptor::GetNoteContents);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::GetNoteContentsXml_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_string_string(parameters, &RemoteControl_adaptor::GetNoteContentsXml);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::GetNoteCreateDate_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_int_string(parameters, &RemoteControl_adaptor::GetNoteCreateDate);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::GetNoteTitle_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_string_string(parameters, &RemoteControl_adaptor::GetNoteTitle);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::GetTagsForNote_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_vectorstring_string(parameters, &RemoteControl_adaptor::GetTagsForNote);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::HideNote_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_bool_string(parameters, &RemoteControl_adaptor::HideNote);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::ListAllNotes_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_vectorstring_void(parameters, &RemoteControl_adaptor::ListAllNotes);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::NoteExists_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_bool_string(parameters, &RemoteControl_adaptor::NoteExists);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::RemoveTagFromNote_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_bool_string_string(parameters, &RemoteControl_adaptor::RemoveTagFromNote);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::SearchNotes_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_vectorstring_string_bool(parameters, &RemoteControl_adaptor::SearchNotes);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::SetNoteCompleteXml_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_bool_string_string(parameters, &RemoteControl_adaptor::SetNoteCompleteXml);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::SetNoteContents_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_bool_string_string(parameters, &RemoteControl_adaptor::SetNoteContents);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::SetNoteContentsXml_stub(const Glib::VariantContainerBase & parameters)
+{
+  return stub_bool_string_string(parameters, &RemoteControl_adaptor::SetNoteContentsXml);
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::Version_stub(const Glib::VariantContainerBase &)
+{
+  return Glib::VariantContainerBase::create_tuple(Glib::Variant<Glib::ustring>::create(Version()));
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::stub_void_string(const Glib::VariantContainerBase & parameters,
+                                                                   void_string_func func)
+{
+  if(parameters.get_n_children() == 1) {
+    Glib::Variant<Glib::ustring> param;
+    parameters.get_child(param);
+    (this->*func)(param.get());
+  }
+
+  return Glib::VariantContainerBase();
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::stub_bool_string(const Glib::VariantContainerBase & parameters,
+                                                                   bool_string_func func)
+{
+  bool result = false;
+  if(parameters.get_n_children() == 1) {
+    Glib::Variant<Glib::ustring> param;
+    parameters.get_child(param);
+    result = (this->*func)(param.get());
+  }
+
+  return Glib::VariantContainerBase::create_tuple(Glib::Variant<bool>::create(result));
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::stub_bool_string_string(const Glib::VariantContainerBase & parameters,
+                                                                          bool_string_string_func func)
+{
+  bool result = false;
+  if(parameters.get_n_children() == 2) {
+    Glib::Variant<Glib::ustring> param1;
+    parameters.get_child(param1, 0);
+    Glib::Variant<Glib::ustring> param2;
+    parameters.get_child(param2, 1);
+    result = (this->*func)(param1.get(), param2.get());
+  }
+
+  return Glib::VariantContainerBase::create_tuple(Glib::Variant<bool>::create(result));
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::stub_int_string(const Glib::VariantContainerBase & parameters, int_string_func func)
+{
+  gint32 result = 0;
+  if(parameters.get_n_children() == 1) {
+    Glib::Variant<Glib::ustring> param;
+    parameters.get_child(param);
+    result = (this->*func)(param.get());
+  }
+
+  return Glib::VariantContainerBase::create_tuple(Glib::Variant<gint32>::create(result));
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::stub_string_string(const Glib::VariantContainerBase & parameters,
+                                                                     string_string_func func)
+{
+  Glib::ustring result;
+  if(parameters.get_n_children() == 1) {
+    Glib::Variant<Glib::ustring> param;
+    parameters.get_child(param);
+    result = (this->*func)(param.get());
+  }
+
+  return Glib::VariantContainerBase::create_tuple(Glib::Variant<Glib::ustring>::create(result));
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::stub_vectorstring_void(const Glib::VariantContainerBase &,
+                                                                         vectorstring_void_func func)
+{
+  std::vector<std::string> result = (this->*func)();
+
+  //work-around glibmm bug 657030
+  std::vector<Glib::ustring> res;
+  for(unsigned i = 0; i < result.size(); ++i) {
+    res.push_back(result[i]);
+  }
+
+  return Glib::VariantContainerBase::create_tuple(Glib::Variant<std::vector<Glib::ustring> >::create(res));
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::stub_vectorstring_string(const Glib::VariantContainerBase & parameters,
+                                                                           vectorstring_string_func func)
+{
+  std::vector<Glib::ustring> res;
+  if(parameters.get_n_children() == 1) {
+    Glib::Variant<Glib::ustring> param;
+    parameters.get_child(param);
+    std::vector<std::string> result = (this->*func)(param.get());
+
+    //work-around glibmm bug 657030
+    for(unsigned i = 0; i < result.size(); ++i) {
+      res.push_back(result[i]);
+    }
+  }
+
+  return Glib::VariantContainerBase::create_tuple(Glib::Variant<std::vector<Glib::ustring> >::create(res));
+}
+
+
+Glib::VariantContainerBase RemoteControl_adaptor::stub_vectorstring_string_bool(const Glib::VariantContainerBase & parameters,
+                                                                                vectorstring_string_bool_func func)
+{
+  std::vector<Glib::ustring> res;
+  if(parameters.get_n_children() == 2) {
+    Glib::Variant<Glib::ustring> param1;
+    parameters.get_child(param1, 0);
+    Glib::Variant<bool> param2;
+    parameters.get_child(param2, 1);
+    std::vector<std::string> result = (this->*func)(param1.get(), param2.get());
+
+    //work-around glibmm bug 657030
+    for(unsigned i = 0; i < result.size(); ++i) {
+      res.push_back(result[i]);
+    }
+  }
+
+  return Glib::VariantContainerBase::create_tuple(Glib::Variant<std::vector<Glib::ustring> >::create(res));
+}
+
diff --git a/src/dbus/remotecontrol-glue.hpp b/src/dbus/remotecontrol-glue.hpp
new file mode 100644
index 0000000..5fbac10
--- /dev/null
+++ b/src/dbus/remotecontrol-glue.hpp
@@ -0,0 +1,132 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2011 Aurimas Cernius
+ *
+ * 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 <string>
+
+#include <giomm/dbusconnection.h>
+#include <giomm/dbusinterfacevtable.h>
+
+namespace org {
+namespace gnome {
+namespace Gnote {
+
+class RemoteControl_adaptor
+  : Gio::DBus::InterfaceVTable
+{
+public:
+  RemoteControl_adaptor(const Glib::RefPtr<Gio::DBus::Connection> & conn,
+                        const char *object_path, const char *interface_name,
+                        const Glib::RefPtr<Gio::DBus::InterfaceInfo> & gnote_interface);
+
+  virtual bool AddTagToNote(const std::string& uri, const std::string& tag_name) = 0;
+  virtual std::string CreateNamedNote(const std::string& linked_title) = 0;
+  virtual std::string CreateNote() = 0;
+  virtual bool DeleteNote(const std::string& uri) = 0;
+  virtual bool DisplayNote(const std::string& uri) = 0;
+  virtual bool DisplayNoteWithSearch(const std::string& uri, const std::string& search) = 0;
+  virtual void DisplaySearch() = 0;
+  virtual void DisplaySearchWithText(const std::string& search_text) = 0;
+  virtual std::string FindNote(const std::string& linked_title) = 0;
+  virtual std::string FindStartHereNote() = 0;
+  virtual std::vector<std::string> GetAllNotesWithTag(const std::string& tag_name) = 0;
+  virtual int32_t GetNoteChangeDate(const std::string& uri) = 0;
+  virtual std::string GetNoteCompleteXml(const std::string& uri) = 0;
+  virtual std::string GetNoteContents(const std::string& uri) = 0;
+  virtual std::string GetNoteContentsXml(const std::string& uri) = 0;
+  virtual int32_t GetNoteCreateDate(const std::string& uri) = 0;
+  virtual std::string GetNoteTitle(const std::string& uri) = 0;
+  virtual std::vector<std::string> GetTagsForNote(const std::string& uri) = 0;
+  virtual bool HideNote(const std::string& uri) = 0;
+  virtual std::vector<std::string> ListAllNotes() = 0;
+  virtual bool NoteExists(const std::string& uri) = 0;
+  virtual bool RemoveTagFromNote(const std::string& uri, const std::string& tag_name) = 0;
+  virtual std::vector<std::string> SearchNotes(const std::string& query, const bool& case_sensitive) = 0;
+  virtual bool SetNoteCompleteXml(const std::string& uri, const std::string& xml_contents) = 0;
+  virtual bool SetNoteContents(const std::string& uri, const std::string& text_contents) = 0;
+  virtual bool SetNoteContentsXml(const std::string& uri, const std::string& xml_contents) = 0;
+  virtual std::string Version() = 0;
+  void NoteAdded(const std::string & );
+  void NoteDeleted(const std::string &, const std::string &);
+  void NoteSaved(const std::string &);
+private:
+  void on_method_call(const Glib::RefPtr<Gio::DBus::Connection> & connection,
+                      const Glib::ustring & sender,
+                      const Glib::ustring & object_path,
+                      const Glib::ustring & interface_name,
+                      const Glib::ustring & method_name,
+                      const Glib::VariantContainerBase & parameters,
+                      const Glib::RefPtr<Gio::DBus::MethodInvocation> & invocation);
+  void emit_signal(const Glib::ustring & name, const Glib::VariantContainerBase & parameters);
+
+  Glib::VariantContainerBase AddTagToNote_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase CreateNamedNote_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase CreateNote_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase DeleteNote_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase DisplayNote_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase DisplayNoteWithSearch_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase DisplaySearch_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase DisplaySearchWithText_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase FindNote_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase FindStartHereNote_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase GetAllNotesWithTag_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase GetNoteChangeDate_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase GetNoteCompleteXml_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase GetNoteContents_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase GetNoteContentsXml_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase GetNoteCreateDate_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase GetNoteTitle_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase GetTagsForNote_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase HideNote_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase ListAllNotes_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase NoteExists_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase RemoveTagFromNote_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase SearchNotes_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase SetNoteCompleteXml_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase SetNoteContents_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase SetNoteContentsXml_stub(const Glib::VariantContainerBase &);
+  Glib::VariantContainerBase Version_stub(const Glib::VariantContainerBase &);
+
+  typedef void (RemoteControl_adaptor::*void_string_func)(const std::string &);
+  Glib::VariantContainerBase stub_void_string(const Glib::VariantContainerBase &, void_string_func);
+  typedef bool (RemoteControl_adaptor::*bool_string_func)(const std::string &);
+  Glib::VariantContainerBase stub_bool_string(const Glib::VariantContainerBase &, bool_string_func);
+  typedef bool (RemoteControl_adaptor::*bool_string_string_func)(const std::string &, const std::string &);
+  Glib::VariantContainerBase stub_bool_string_string(const Glib::VariantContainerBase &, bool_string_string_func);
+  typedef int32_t (RemoteControl_adaptor::*int_string_func)(const std::string &);
+  Glib::VariantContainerBase stub_int_string(const Glib::VariantContainerBase &, int_string_func);
+  typedef std::string (RemoteControl_adaptor::*string_string_func)(const std::string &);
+  Glib::VariantContainerBase stub_string_string(const Glib::VariantContainerBase &, string_string_func);
+  typedef std::vector<std::string> (RemoteControl_adaptor::*vectorstring_void_func)();
+  Glib::VariantContainerBase stub_vectorstring_void(const Glib::VariantContainerBase &, vectorstring_void_func);
+  typedef std::vector<std::string> (RemoteControl_adaptor::*vectorstring_string_func)(const std::string &);
+  Glib::VariantContainerBase stub_vectorstring_string(const Glib::VariantContainerBase &, vectorstring_string_func);
+  typedef std::vector<std::string> (RemoteControl_adaptor::*vectorstring_string_bool_func)(const std::string &, const bool &);
+  Glib::VariantContainerBase stub_vectorstring_string_bool(const Glib::VariantContainerBase &, vectorstring_string_bool_func);
+
+  typedef Glib::VariantContainerBase (RemoteControl_adaptor::*stub_func)(const Glib::VariantContainerBase &);
+  std::map<Glib::ustring, stub_func> m_stubs;
+  Glib::RefPtr<Gio::DBus::Connection> m_connection;
+  const char *m_path;
+  const char *m_interface_name;
+};
+
+}
+}
+}
diff --git a/src/dbus/remotecontrol.cpp b/src/dbus/remotecontrol.cpp
index 80f0daa..b81031c 100644
--- a/src/dbus/remotecontrol.cpp
+++ b/src/dbus/remotecontrol.cpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2011 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -33,8 +34,10 @@
 namespace gnote {
 
 
-  RemoteControl::RemoteControl(DBus::Connection& cnx, NoteManager& manager)
-    : DBus::ObjectAdaptor(cnx, RemoteControlProxy::GNOTE_SERVER_PATH)
+  RemoteControl::RemoteControl(const Glib::RefPtr<Gio::DBus::Connection> & cnx, NoteManager& manager,
+                               const char * path, const char * interface_name,
+                               const Glib::RefPtr<Gio::DBus::InterfaceInfo> & gnote_interface)
+    : IRemoteControl(cnx, path, interface_name, gnote_interface)
     , m_manager(manager)
   {
     DBG_OUT("initialized remote control");
diff --git a/src/dbus/remotecontrol.hpp b/src/dbus/remotecontrol.hpp
index ee2cb80..b0b323d 100644
--- a/src/dbus/remotecontrol.hpp
+++ b/src/dbus/remotecontrol.hpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2011 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -23,7 +24,7 @@
 #include <string>
 #include <vector>
 
-#include <dbus-c++/dbus.h>
+#include <giomm/dbusconnection.h>
 
 #include "dbus/iremotecontrol.hpp"
 #include "note.hpp"
@@ -35,11 +36,10 @@ class NoteManager;
 
 class RemoteControl
   : public IRemoteControl
-  , public DBus::IntrospectableAdaptor
-  , public DBus::ObjectAdaptor
 {
 public:
-  RemoteControl(DBus::Connection&, gnote::NoteManager&);
+  RemoteControl(const Glib::RefPtr<Gio::DBus::Connection> &, gnote::NoteManager&, const char *, const char *,
+                const Glib::RefPtr<Gio::DBus::InterfaceInfo> &);
   virtual ~RemoteControl();
 
   virtual bool AddTagToNote(const std::string& uri, const std::string& tag_name);
diff --git a/src/dbus/remotecontrolclient.cpp b/src/dbus/remotecontrolclient.cpp
index 36df663..a443bf5 100644
--- a/src/dbus/remotecontrolclient.cpp
+++ b/src/dbus/remotecontrolclient.cpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2011 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -24,14 +25,13 @@ namespace gnote {
 
 
 
-  RemoteControlClient::RemoteControlClient(DBus::Connection &connection, 
-                                           const char *p, const char *name)
-    : DBus::ObjectProxy(connection, p, name)
+  RemoteControlClient::RemoteControlClient(const Glib::RefPtr<Gio::DBus::Connection> & connection,
+                                           const char *path, const char *name, const char *interface_name,
+                                           const Glib::RefPtr<Gio::DBus::InterfaceInfo> & gnote_interface)
+    : RemoteControl_proxy(connection, name, path, interface_name, gnote_interface)
   {
   }
 
-
-
 }
 
 
diff --git a/src/dbus/remotecontrolclient.hpp b/src/dbus/remotecontrolclient.hpp
index 7b37a14..c31871a 100644
--- a/src/dbus/remotecontrolclient.hpp
+++ b/src/dbus/remotecontrolclient.hpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2011 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -21,6 +22,8 @@
 #ifndef __GNOTE_REMOTECONTROLCLIENT_HPP_
 #define __GNOTE_REMOTECONTROLCLIENT_HPP_
 
+#include <giomm/dbusconnection.h>
+
 #include "dbus/remotecontrol-client-glue.hpp"
 
 namespace gnote {
@@ -28,11 +31,11 @@ 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);
+  RemoteControlClient(const Glib::RefPtr<Gio::DBus::Connection> & connection, const char *path,
+                      const char *name, const char *interface_name,
+                      const Glib::RefPtr<Gio::DBus::InterfaceInfo> & gnote_interface);
 
   virtual void NoteAdded(const std::string&) {}
   virtual void NoteDeleted(const std::string&, const std::string&) {}
diff --git a/src/gnote.cpp b/src/gnote.cpp
index ded2ce0..0ebe721 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -48,8 +48,11 @@
 #include "notewindow.hpp"
 #include "preferencesdialog.hpp"
 #include "recentchanges.hpp"
+#include "remotecontrolproxy.hpp"
 #include "utils.hpp"
 #include "xkeybinder.hpp"
+#include "dbus/remotecontrol.hpp"
+#include "dbus/remotecontrolclient.hpp"
 #include "sharp/streamreader.hpp"
 #include "sharp/files.hpp"
 
@@ -57,10 +60,6 @@
 #include "applet.hpp"
 #endif
 
-#if ENABLE_DBUS
-#include "remotecontrolproxy.hpp"
-#include "dbus/remotecontrolclient.hpp"
-#endif
 
 namespace gnote {
 
@@ -82,19 +81,13 @@ namespace gnote {
 
   int Gnote::main(int argc, char **argv)
   {
-    GnoteCommandLine cmd_line;
-
     cmd_line.parse(argc, argv);
-
-    m_is_panel_applet = cmd_line.use_panel_applet();
-
-#ifdef ENABLE_DBUS
-    if(cmd_line.needs_execute()) {
-      cmd_line.execute();
+    if(cmd_line.needs_immediate_execute()) {
+      cmd_line.immediate_execute();
       return 0;
     }
-#endif
 
+    m_is_panel_applet = cmd_line.use_panel_applet();
     m_icon_theme = Gtk::IconTheme::get_default();
     m_icon_theme->append_search_path(DATADIR"/icons");
     m_icon_theme->append_search_path(DATADIR"/gnote/icons");
@@ -108,47 +101,77 @@ namespace gnote {
 
     ActionManager & am(ActionManager::obj());
     am.load_interface();
-    register_remote_control(*m_manager);
+    register_remote_control(*m_manager, sigc::mem_fun(*this, &Gnote::end_main));
     setup_global_actions();
-
     m_manager->get_addin_manager().initialize_application_addins();
 
-#ifndef ENABLE_DBUS
-    if(cmd_line.needs_execute()) {
-      cmd_line.execute();
-    }
-#endif
-
     if(m_is_panel_applet) {
-      DBG_OUT("starting applet");
-
       am["CloseWindowAction"]->set_visible(true);
       am["QuitGNoteAction"]->set_visible(false);
-      
-      // register panel applet factory
-#if HAVE_PANELAPPLET
-      return panel::register_applet();
-#else
-      return 0;
-#endif
     }
     else {
       Glib::RefPtr<Gio::Settings> settings = Preferences::obj()
         .get_schema_settings(Preferences::SCHEMA_GNOTE);
       settings->signal_changed()
         .connect(sigc::mem_fun(*this, &Gnote::on_setting_changed));
+    }
+
+    if(m_is_panel_applet) {
+#if HAVE_PANELAPPLET
+      panel::register_applet();
+#endif
+    }
+    else {
+      Gtk::Main::run();
+    }
+    signal_quit();
+    return 0;
+  }
+
+
+  void Gnote::end_main(bool bus_acquired, bool name_acquired)
+  {
+    if(cmd_line.needs_execute()) {
+      cmd_line.execute();
+    }
+
+    if(bus_acquired) {
+      if(name_acquired) {
+        DBG_OUT("Gnote remote control active.");
+      } 
+      else {
+        // If Gnote is already running, open the search window
+        // so the user gets some sort of feedback when they
+        // attempt to run Gnote again.
+        Glib::RefPtr<RemoteControlClient> remote;
+        try {
+          remote = RemoteControlProxy::get_instance();
+          DBG_ASSERT(remote, "remote is NULL, something is wrong");
+          if(remote) {
+            remote->DisplaySearch();
+          }
+        } 
+        catch (...)
+        {
+        }
+
+        ERR_OUT ("Gnote is already running.  Exiting...");
+        ::exit(-1);
+      }
+    }
+
+    if(!m_is_panel_applet) {
+      Glib::RefPtr<Gio::Settings> settings = Preferences::obj()
+        .get_schema_settings(Preferences::SCHEMA_GNOTE);
       if(settings->get_boolean(Preferences::USE_STATUS_ICON)) {
         DBG_OUT("starting tray icon");
         start_tray_icon();
       }
       else {
+        ActionManager & am(ActionManager::obj());
         am["ShowSearchAllNotesAction"]->activate();
-        Gtk::Main::run();
       }
     }
-
-    signal_quit();
-    return 0;
   }
 
 
@@ -194,8 +217,6 @@ namespace gnote {
       timeout->connect(sigc::mem_fun(*this, &Gnote::check_tray_icon_showing));
       timeout->attach();
     }
-    
-    Gtk::Main::run();
   }
 
 
@@ -211,39 +232,9 @@ namespace gnote {
   }
 
 
-  void Gnote::register_remote_control(NoteManager & manager)
+  void Gnote::register_remote_control(NoteManager & manager, RemoteControlProxy::slot_name_acquire_finish on_finish)
   {
-#if ENABLE_DBUS
-    try {
-      m_remote_control = RemoteControlProxy::register_remote(manager);
-      if (m_remote_control) {
-        DBG_OUT("Gnote remote control active.");
-      } 
-      else {
-        // If Gnote is already running, open the search window
-        // so the user gets some sort of feedback when they
-        // attempt to run Gnote again.
-        RemoteControlClient *remote;
-        try {
-          remote = RemoteControlProxy::get_instance();
-          DBG_ASSERT(remote, "remote is NULL, something is wrong");
-          if(remote) {
-            remote->DisplaySearch();
-          }
-        } 
-        catch (...)
-        {
-        }
-
-        ERR_OUT ("Gnote is already running.  Exiting...");
-        ::exit(-1);
-      }
-    } 
-    catch (const std::exception & e) {
-      ERR_OUT("Gnote remote control disabled (DBus exception): %s",
-              e.what());
-    }
-#endif
+    RemoteControlProxy::register_remote(manager, on_finish);
   }
 
 
@@ -537,23 +528,42 @@ namespace gnote {
 
 
   int GnoteCommandLine::execute()
-
   {
-    bool quit = false;
     DBG_OUT("running args");
 
+    RemoteControl *remote_control = RemoteControlProxy::get_remote_control();
+    if(remote_control) {
+      execute(remote_control);
+    }
+    else {
+      //gnote already running, execute via D-Bus and exit this instance
+      Glib::RefPtr<RemoteControlClient> remote = RemoteControlProxy::get_instance();
+      if(!remote) {
+        ERR_OUT("Could not connect to remote instance.");
+      }
+      else {
+        execute(remote);
+      }
+      Gtk::Main::quit();
+    }
+    return 0;
+  }
+
+
+  int GnoteCommandLine::immediate_execute()
+  {
     if(m_show_version) {
       print_version();
-      quit = true;
       exit(0);
     }
 
-#ifdef ENABLE_DBUS
-    RemoteControlClient * remote = RemoteControlProxy::get_instance();
-    if(!remote) {
-      ERR_OUT("couldn't get remote client");
-      return 1;
-    }
+    return 0;
+  }
+
+
+  template <typename T>
+  void GnoteCommandLine::execute(T & remote)
+  {
     if (m_do_new_note) {
       std::string new_uri;
 
@@ -640,23 +650,6 @@ namespace gnote {
         remote->DisplaySearch();
       }
     }
-#else
-      // as long as we don't have the DBus support.
-    if(m_do_search) {
-      NoteRecentChanges * recent_changes
-        = NoteRecentChanges::get_instance(
-          Gnote::obj().default_note_manager());
-
-      recent_changes->set_search_text(m_search);
-
-      recent_changes->present ();
-    }
-#endif
-
-    if(quit) {
-      exit(0);
-    }
-    return 0;
   }
 
 
@@ -668,19 +661,15 @@ namespace gnote {
   }
 
 
-  bool GnoteCommandLine::display_note(RemoteControlClient * remote,
-                                      std::string uri)
+  template <typename T>
+  bool GnoteCommandLine::display_note(T & remote, std::string uri)
   {
-#ifdef ENABLE_DBUS
     if (m_highlight_search) {
       return remote->DisplayNoteWithSearch(uri, m_highlight_search);
     }
     else {
       return remote->DisplayNote (uri);
     }
-#else
-    return false;
-#endif
   }
 
 
@@ -691,9 +680,12 @@ namespace gnote {
       m_open_note ||
       m_do_search ||
       m_open_start_here ||
-      m_highlight_search ||
-      m_show_version;
+      m_highlight_search;
   }
 
+  bool GnoteCommandLine::needs_immediate_execute() const
+  {
+    return m_show_version;
+  }
 
 }
diff --git a/src/gnote.hpp b/src/gnote.hpp
index 4dc1ee2..d02802a 100644
--- a/src/gnote.hpp
+++ b/src/gnote.hpp
@@ -34,13 +34,66 @@
 #include "base/singleton.hpp"
 #include "actionmanager.hpp"
 #include "keybinder.hpp"
+#include "remotecontrolproxy.hpp"
 #include "tray.hpp"
 
 namespace gnote {
 
 class PreferencesDialog;
 class NoteManager;
-class RemoteControl;
+class RemoteControlClient;
+
+class GnoteCommandLine
+{
+public:
+  GnoteCommandLine();
+  ~GnoteCommandLine();
+  int execute();
+  int immediate_execute();
+
+  const gchar * note_path() const
+    {
+      return m_note_path ? m_note_path : "";
+    }
+  bool        needs_execute() const;
+  bool        needs_immediate_execute() const;
+  bool        use_panel_applet() const
+    {
+      return m_use_panel;
+    }
+  void parse(int &argc, gchar ** & argv);
+
+  static gboolean parse_func(const gchar *option_name,
+                             const gchar *value,
+                             gpointer data,
+                             GError **error);
+private:
+  void        print_version();
+  template <typename T>
+  bool        display_note(T & remote, std::string uri);
+  template <typename T>
+  void execute(T & remote);
+
+  GOptionContext *m_context;
+
+  bool        m_use_panel;
+  gchar *     m_note_path;
+  bool        m_do_search;
+  std::string m_search;
+  bool        m_show_version;
+  bool        m_do_new_note;
+  std::string m_new_note_name;
+  gchar*      m_open_note;
+  bool        m_open_start_here;
+  gchar*      m_highlight_search;
+
+
+  // depend on m_open_note, set in on_post_parse
+  std::string m_open_note_name;
+  std::string m_open_note_uri;
+  std::string m_open_external_note_path;
+};
+
 
 class Gnote
   : public base::Singleton<Gnote>
@@ -90,11 +143,12 @@ public:
       m_tray = tray;
     }
   sigc::signal<void> signal_quit;
+  static void register_remote_control(NoteManager & manager, RemoteControlProxy::slot_name_acquire_finish on_finish);
 private:
   void start_note_created(const Note::Ptr & start_note);
   std::string get_note_path(const std::string & override_path);
-  void register_remote_control(NoteManager & manager);
   void on_setting_changed(const Glib::ustring & key);
+  void end_main(bool bus_aquired, bool name_acquired);
 
   NoteManager *m_manager;
   IKeybinder  *m_keybinder;
@@ -103,57 +157,9 @@ private:
   Tray::Ptr m_tray;
   bool m_is_panel_applet;
   PreferencesDialog *m_prefsdlg;
-  RemoteControl     *m_remote_control;
+  GnoteCommandLine cmd_line;
 };
 
-class RemoteControlClient;
-
-class GnoteCommandLine
-{
-public:
-  GnoteCommandLine();
-  ~GnoteCommandLine();
-  int execute();
-
-  const gchar * note_path() const
-    {
-      return m_note_path ? m_note_path : "";
-    }
-  bool        needs_execute() const;
-  bool        use_panel_applet() const
-    {
-      return m_use_panel;
-    }
-  void parse(int &argc, gchar ** & argv);
-
-  static gboolean parse_func(const gchar *option_name,
-                             const gchar *value,
-                             gpointer data,
-                             GError **error);
-private:
-  void        print_version();
-  bool        display_note(RemoteControlClient * remote,
-                           std::string uri);
-
-  GOptionContext *m_context;
-
-  bool        m_use_panel;
-  gchar *     m_note_path;
-  bool        m_do_search;
-  std::string m_search;
-  bool        m_show_version;
-  bool        m_do_new_note;
-  std::string m_new_note_name;
-  gchar*      m_open_note;
-  bool        m_open_start_here;
-  gchar*      m_highlight_search;
-
-
-  // depend on m_open_note, set in on_post_parse
-  std::string m_open_note_name;
-  std::string m_open_note_uri;
-  std::string m_open_external_note_path;
-};
 
 }
 
diff --git a/src/remotecontrolproxy.cpp b/src/remotecontrolproxy.cpp
index 840de21..b2c8219 100644
--- a/src/remotecontrolproxy.cpp
+++ b/src/remotecontrolproxy.cpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2011 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -17,7 +18,10 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <dbus-c++/glib-integration.h>
+#include <fstream>
+
+#include <giomm/dbusownname.h>
+
 
 #include "debug.hpp"
 #include "dbus/remotecontrol.hpp"
@@ -28,45 +32,103 @@
 namespace gnote {
 
 const char *RemoteControlProxy::GNOTE_SERVER_NAME = "org.gnome.Gnote";
+const char *RemoteControlProxy::GNOTE_INTERFACE_NAME = "org.gnome.Gnote.RemoteControl";
 const char *RemoteControlProxy::GNOTE_SERVER_PATH = "/org/gnome/Gnote/RemoteControl";
 
-DBus::BusDispatcher dispatcher;
+NoteManager *RemoteControlProxy::s_manager;
+RemoteControl *RemoteControlProxy::s_remote_control;
+bool RemoteControlProxy::s_bus_acquired;
+Glib::RefPtr<Gio::DBus::Connection> RemoteControlProxy::s_connection;
+Glib::RefPtr<RemoteControlClient> RemoteControlProxy::s_remote_control_proxy;
+Glib::RefPtr<Gio::DBus::InterfaceInfo> RemoteControlProxy::s_gnote_interface;
+RemoteControlProxy::slot_name_acquire_finish RemoteControlProxy::s_on_name_acquire_finish;
 
-DBus::Glib::BusDispatcher glib_dispatcher;
 
-RemoteControlClient *RemoteControlProxy::get_instance()
+Glib::RefPtr<RemoteControlClient> RemoteControlProxy::get_instance()
 {
-  // we likely won't have a Glib main loop at the point.
-  if(!DBus::default_dispatcher) {
-    DBus::default_dispatcher = &dispatcher;
+  if(s_remote_control_proxy) {
+    return s_remote_control_proxy;
   }
-  DBus::Connection conn = DBus::Connection::SessionBus();
-  return new RemoteControlClient(conn, GNOTE_SERVER_PATH, GNOTE_SERVER_NAME);
+  if(!s_connection) {
+    return Glib::RefPtr<RemoteControlClient>();
+  }
+
+  load_introspection_xml();
+  return s_remote_control_proxy = Glib::RefPtr<RemoteControlClient>(
+    new RemoteControlClient(s_connection, GNOTE_SERVER_PATH, GNOTE_SERVER_NAME, GNOTE_INTERFACE_NAME, s_gnote_interface));
 }
 
+RemoteControl *RemoteControlProxy::get_remote_control()
+{
+  return s_remote_control;
+}
 
-RemoteControl *RemoteControlProxy::register_remote(NoteManager & manager)
+void RemoteControlProxy::register_remote(NoteManager & manager, const slot_name_acquire_finish & on_finish)
 {
-  RemoteControl *remote_control = NULL;
-  if(!DBus::default_dispatcher) {
-    DBus::default_dispatcher = &glib_dispatcher;
-    glib_dispatcher.attach(NULL);
-  }
+  s_on_name_acquire_finish = on_finish;
+  s_manager = &manager;
+  Gio::DBus::own_name(Gio::DBus::BUS_TYPE_SESSION, GNOTE_SERVER_NAME,
+                      sigc::ptr_fun(RemoteControlProxy::on_bus_acquired),
+                      sigc::ptr_fun(RemoteControlProxy::on_name_acquired),
+                      sigc::ptr_fun(RemoteControlProxy::on_name_lost));
+}
+
+
+void RemoteControlProxy::on_bus_acquired(const Glib::RefPtr<Gio::DBus::Connection> & conn, const Glib::ustring &)
+{
+  s_bus_acquired = true;
+  s_connection = conn;
+}
 
-	DBus::Connection conn = DBus::Connection::SessionBus();
-  // 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");
 
-    remote_control = new RemoteControl (conn, manager);
+void RemoteControlProxy::on_name_acquired(const Glib::RefPtr<Gio::DBus::Connection> & conn, const Glib::ustring &)
+{
+  try {
+    if(s_bus_acquired) {
+      load_introspection_xml();
+      s_remote_control = new RemoteControl(conn, *s_manager, GNOTE_SERVER_PATH, GNOTE_INTERFACE_NAME, s_gnote_interface);
+      s_on_name_acquire_finish(true, true);
+      return;
+    }
+  }
+  catch(Glib::Exception & e) {
+    DBG_OUT("Failed to acquire name: " + e.what());
   }
 
-  return remote_control;
+  s_on_name_acquire_finish(false, false);
 }
 
 
+void RemoteControlProxy::on_name_lost(const Glib::RefPtr<Gio::DBus::Connection> &, const Glib::ustring &)
+{
+  s_on_name_acquire_finish(s_bus_acquired, false);
+}
+
+
+void RemoteControlProxy::load_introspection_xml()
+{
+  if(s_gnote_interface != 0) {
+    return;
+  }
+  std::ifstream fin(DATADIR"/gnote/gnote-introspect.xml");
+  if(!fin) {
+    return;
+  }
+  Glib::ustring introspect_xml;
+  while(!fin.eof()) {
+    std::string line;
+    std::getline(fin, line);
+    introspect_xml += line;
+  }
+  fin.close();
+  try {
+    Glib::RefPtr<Gio::DBus::NodeInfo> node = Gio::DBus::NodeInfo::create_for_xml(introspect_xml);
+    s_gnote_interface = node->lookup_interface(GNOTE_INTERFACE_NAME);
+  }
+  catch(Glib::Error & e) {
+    ERR_OUT(("Failed to load interface: " + e.what()).c_str());
+  }
+}
+
 }
 
diff --git a/src/remotecontrolproxy.hpp b/src/remotecontrolproxy.hpp
index 71d97cc..0a352a9 100644
--- a/src/remotecontrolproxy.hpp
+++ b/src/remotecontrolproxy.hpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2011 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -21,6 +22,8 @@
 #ifndef _REMOTECONTROL_PROXY_HPP_
 #define _REMOTECONTROL_PROXY_HPP_
 
+#include <giomm/dbusconnection.h>
+#include <giomm/dbusintrospection.h>
 
 namespace gnote {
 
@@ -32,12 +35,29 @@ class RemoteControlProxy
 {
 public:
   static const char *GNOTE_SERVER_PATH;
+  static const char *GNOTE_INTERFACE_NAME;
   static const char *GNOTE_SERVER_NAME;
 
+  typedef sigc::slot<void, bool, bool> slot_name_acquire_finish;
+  typedef sigc::slot<void> slot_connected;
+
   /** Get a dbus client */
-  static RemoteControlClient *get_instance();
+  static Glib::RefPtr<RemoteControlClient> get_instance();
+  static RemoteControl *get_remote_control();
+  static void register_remote(NoteManager & manager, const slot_name_acquire_finish & on_finish);
+private:
+  static void on_bus_acquired(const Glib::RefPtr<Gio::DBus::Connection> & conn, const Glib::ustring & name);
+  static void on_name_acquired(const Glib::RefPtr<Gio::DBus::Connection> & conn, const Glib::ustring & name);
+  static void on_name_lost(const Glib::RefPtr<Gio::DBus::Connection> & conn, const Glib::ustring & name);
+  static void load_introspection_xml();
 
-  static RemoteControl *register_remote(NoteManager & manager);
+  static NoteManager * s_manager;
+  static RemoteControl * s_remote_control;
+  static bool s_bus_acquired;
+  static Glib::RefPtr<Gio::DBus::Connection> s_connection;
+  static Glib::RefPtr<Gio::DBus::InterfaceInfo> s_gnote_interface;
+  static Glib::RefPtr<RemoteControlClient> s_remote_control_proxy;
+  static slot_name_acquire_finish s_on_name_acquire_finish;
 };
 
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]