[gnote] Make RemoteControlProxy a member of Gnote



commit 44c9e75bf6050bf606848c94231bdf5c0870f707
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat Nov 16 18:47:05 2019 +0200

    Make RemoteControlProxy a member of Gnote

 src/gnote.cpp              | 13 +++++----
 src/gnote.hpp              |  8 ++++--
 src/remotecontrolproxy.cpp | 67 +++++++++++++++++++++++-----------------------
 src/remotecontrolproxy.hpp | 44 ++++++++++++++++--------------
 4 files changed, 69 insertions(+), 63 deletions(-)
---
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 175e006a..e9072400 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -62,6 +62,7 @@ namespace gnote {
     , m_sync_manager(NULL)
     , m_is_background(false)
     , m_is_shell_search(false)
+    , m_remote_control(*this)
     , m_prefsdlg(NULL)
     , m_cmd_line(*this)
   {
@@ -173,7 +174,7 @@ namespace gnote {
         if(!m_is_background) {
           Glib::RefPtr<RemoteControlClient> remote;
           try {
-            remote = RemoteControlProxy::get_instance();
+            remote = m_remote_control.get_instance();
             DBG_ASSERT(remote, "remote is NULL, something is wrong");
             if(remote) {
               remote->DisplaySearch();
@@ -223,15 +224,13 @@ namespace gnote {
 
   void Gnote::register_remote_control(NoteManager & manager, RemoteControlProxy::slot_name_acquire_finish 
on_finish)
   {
-    RemoteControlProxy::register_remote(manager, on_finish);
+    m_remote_control.register_remote(manager, on_finish);
   }
 
 
   void Gnote::register_object()
   {
-    RemoteControlProxy::register_object(Gio::DBus::Connection::get_sync(Gio::DBus::BUS_TYPE_SESSION),
-                                        default_note_manager(),
-                                        sigc::mem_fun(*this, &Gnote::end_main));
+    m_remote_control.register_object(Gio::DBus::Connection::get_sync(Gio::DBus::BUS_TYPE_SESSION), 
default_note_manager(), sigc::mem_fun(*this, &Gnote::end_main));
   }
 
 
@@ -597,13 +596,13 @@ namespace gnote {
   {
     DBG_OUT("running args");
 
-    RemoteControl *remote_control = RemoteControlProxy::get_remote_control();
+    RemoteControl *remote_control = static_cast<Gnote&>(m_gnote).remote_control().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();
+      Glib::RefPtr<RemoteControlClient> remote = 
static_cast<Gnote&>(m_gnote).remote_control().get_instance();
       if(!remote) {
         ERR_OUT(_("Could not connect to remote instance."));
       }
diff --git a/src/gnote.hpp b/src/gnote.hpp
index 60f17fcf..7c8bef15 100644
--- a/src/gnote.hpp
+++ b/src/gnote.hpp
@@ -41,7 +41,6 @@ namespace gnote {
 
 class PreferencesDialog;
 class NoteManager;
-class RemoteControlClient;
 
 class GnoteCommandLine
 {
@@ -140,6 +139,10 @@ public:
     {
       return m_preferences;
     }
+  RemoteControlProxy & remote_control()
+    {
+      return m_remote_control;
+    }
 
   void on_preferences_response(int res);
   void on_show_preferences_action(const Glib::VariantBase&);
@@ -159,7 +162,7 @@ public:
     {
       return !is_background();
     }
-  static void register_remote_control(NoteManager & manager, RemoteControlProxy::slot_name_acquire_finish 
on_finish);
+  void register_remote_control(NoteManager & manager, RemoteControlProxy::slot_name_acquire_finish 
on_finish);
   virtual void open_note(const Note::Ptr & note) override;
 protected:
   virtual int on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> & command_line) override;
@@ -187,6 +190,7 @@ private:
   Glib::RefPtr<Gtk::IconTheme> m_icon_theme;
   bool m_is_background;
   bool m_is_shell_search;
+  RemoteControlProxy m_remote_control;
   PreferencesDialog *m_prefsdlg;
   GnoteCommandLine m_cmd_line;
   sync::SyncDialog::Ptr m_sync_dlg;
diff --git a/src/remotecontrolproxy.cpp b/src/remotecontrolproxy.cpp
index c4438c7c..ccc85058 100644
--- a/src/remotecontrolproxy.cpp
+++ b/src/remotecontrolproxy.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011,2013,2017 Aurimas Cernius
+ * Copyright (C) 2011,2013,2017,2019 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -59,59 +59,58 @@ const char *RemoteControlProxy::GNOTE_SERVER_PATH = "/org/gnome/Gnote/RemoteCont
 const char *RemoteControlProxy::GNOTE_SEARCH_PROVIDER_PATH = "/org/gnome/Gnote/SearchProvider";
 const char *RemoteControlProxy::GNOTE_SEARCH_PROVIDER_INTERFACE_NAME = "org.gnome.Shell.SearchProvider2";
 
-NoteManager *RemoteControlProxy::s_manager;
-RemoteControl *RemoteControlProxy::s_remote_control;
-org::gnome::Gnote::SearchProvider *RemoteControlProxy::s_search_provider;
-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;
-Glib::RefPtr<Gio::DBus::InterfaceInfo> RemoteControlProxy::s_search_provider_interface;
-RemoteControlProxy::slot_name_acquire_finish RemoteControlProxy::s_on_name_acquire_finish;
 
+RemoteControlProxy::RemoteControlProxy(IGnote & g)
+  : m_gnote(g)
+  , m_manager(NULL)
+  , m_remote_control(NULL)
+  , m_search_provider(NULL)
+  , m_bus_acquired(false)
+{
+}
 
 Glib::RefPtr<RemoteControlClient> RemoteControlProxy::get_instance()
 {
-  if(s_remote_control_proxy) {
-    return s_remote_control_proxy;
+  if(m_remote_control_proxy) {
+    return m_remote_control_proxy;
   }
-  if(!s_connection) {
+  if(!m_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));
+  return m_remote_control_proxy = Glib::RefPtr<RemoteControlClient>(
+    new RemoteControlClient(m_connection, GNOTE_SERVER_PATH, GNOTE_SERVER_NAME, GNOTE_INTERFACE_NAME, 
m_gnote_interface));
 }
 
 RemoteControl *RemoteControlProxy::get_remote_control()
 {
-  return s_remote_control;
+  return m_remote_control;
 }
 
-void RemoteControlProxy::register_remote(NoteManager & manager, const slot_name_acquire_finish & on_finish)
+void RemoteControlProxy::register_remote(NoteManagerBase & manager, const slot_name_acquire_finish & 
on_finish)
 {
-  s_on_name_acquire_finish = on_finish;
-  s_manager = &manager;
+  m_on_name_acquire_finish = on_finish;
+  m_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));
+                      sigc::mem_fun(*this, &RemoteControlProxy::on_bus_acquired),
+                      sigc::mem_fun(*this, &RemoteControlProxy::on_name_acquired),
+                      sigc::mem_fun(*this, &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;
+  m_bus_acquired = true;
+  m_connection = conn;
 }
 
 
 void RemoteControlProxy::on_name_acquired(const Glib::RefPtr<Gio::DBus::Connection> & conn, const 
Glib::ustring &)
 {
   try {
-    if(s_bus_acquired) {
-      register_object(conn, *s_manager, s_on_name_acquire_finish);
+    if(m_bus_acquired) {
+      register_object(conn, *m_manager, m_on_name_acquire_finish);
       return;
     }
   }
@@ -119,32 +118,32 @@ void RemoteControlProxy::on_name_acquired(const Glib::RefPtr<Gio::DBus::Connecti
     DBG_OUT("Failed to acquire name: %s", e.what().c_str());
   }
 
-  s_on_name_acquire_finish(false, false);
+  m_on_name_acquire_finish(false, false);
 }
 
 
-void RemoteControlProxy::register_object(const Glib::RefPtr<Gio::DBus::Connection> & conn, NoteManager & 
manager,
+void RemoteControlProxy::register_object(const Glib::RefPtr<Gio::DBus::Connection> & conn, NoteManagerBase & 
manager,
                                          const slot_name_acquire_finish & on_finish)
 {
   load_introspection_xml();
-  s_remote_control = new RemoteControl(conn, manager, GNOTE_SERVER_PATH, GNOTE_INTERFACE_NAME, 
s_gnote_interface);
-  s_search_provider = new org::gnome::Gnote::SearchProvider(conn, GNOTE_SEARCH_PROVIDER_PATH,
-                                                            s_search_provider_interface, manager);
+  m_remote_control = new RemoteControl(conn, manager, GNOTE_SERVER_PATH, GNOTE_INTERFACE_NAME, 
m_gnote_interface);
+  m_search_provider = new org::gnome::Gnote::SearchProvider(conn, GNOTE_SEARCH_PROVIDER_PATH,
+                                                            m_search_provider_interface, manager);
   on_finish(true, true);
 }
 
 
 void RemoteControlProxy::on_name_lost(const Glib::RefPtr<Gio::DBus::Connection> &, const Glib::ustring &)
 {
-  s_on_name_acquire_finish(s_bus_acquired, false);
+  m_on_name_acquire_finish(m_bus_acquired, false);
 }
 
 
 void RemoteControlProxy::load_introspection_xml()
 {
-  load_interface_from_file(DATADIR"/gnote/gnote-introspect.xml", GNOTE_INTERFACE_NAME, s_gnote_interface);
+  load_interface_from_file(DATADIR"/gnote/gnote-introspect.xml", GNOTE_INTERFACE_NAME, m_gnote_interface);
   load_interface_from_file(DATADIR"/gnote/shell-search-provider-dbus-interfaces.xml",
-                           GNOTE_SEARCH_PROVIDER_INTERFACE_NAME, s_search_provider_interface);
+                           GNOTE_SEARCH_PROVIDER_INTERFACE_NAME, m_search_provider_interface);
 }
 
 }
diff --git a/src/remotecontrolproxy.hpp b/src/remotecontrolproxy.hpp
index f48fb632..2756d2fa 100644
--- a/src/remotecontrolproxy.hpp
+++ b/src/remotecontrolproxy.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011,2013 Aurimas Cernius
+ * Copyright (C) 2011,2013,2019 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -35,9 +35,10 @@ namespace Gnote {
 
 namespace gnote {
 
+class IGnote;
 class RemoteControl;
 class RemoteControlClient;
-class NoteManager;
+class NoteManagerBase;
 
 class RemoteControlProxy 
 {
@@ -51,27 +52,30 @@ public:
   typedef sigc::slot<void, bool, bool> slot_name_acquire_finish;
   typedef sigc::slot<void> slot_connected;
 
+  explicit RemoteControlProxy(IGnote & g);
+
   /** Get a dbus client */
-  static Glib::RefPtr<RemoteControlClient> get_instance();
-  static RemoteControl *get_remote_control();
-  static void register_remote(NoteManager & manager, const slot_name_acquire_finish & on_finish);
-  static void register_object(const Glib::RefPtr<Gio::DBus::Connection> & conn, NoteManager & manager,
-                              const slot_name_acquire_finish & on_finish);
+  Glib::RefPtr<RemoteControlClient> get_instance();
+  RemoteControl *get_remote_control();
+  void register_remote(NoteManagerBase & manager, const slot_name_acquire_finish & on_finish);
+  void register_object(const Glib::RefPtr<Gio::DBus::Connection> & conn, NoteManagerBase & 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();
+  void on_bus_acquired(const Glib::RefPtr<Gio::DBus::Connection> & conn, const Glib::ustring & name);
+  void on_name_acquired(const Glib::RefPtr<Gio::DBus::Connection> & conn, const Glib::ustring & name);
+  void on_name_lost(const Glib::RefPtr<Gio::DBus::Connection> & conn, const Glib::ustring & name);
+  void load_introspection_xml();
 
-  static NoteManager * s_manager;
-  static RemoteControl * s_remote_control;
-  static org::gnome::Gnote::SearchProvider * s_search_provider;
-  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<Gio::DBus::InterfaceInfo> s_search_provider_interface;
-  static Glib::RefPtr<RemoteControlClient> s_remote_control_proxy;
-  static slot_name_acquire_finish s_on_name_acquire_finish;
+  IGnote & m_gnote;
+  NoteManagerBase *m_manager;
+  RemoteControl *m_remote_control;
+  org::gnome::Gnote::SearchProvider *m_search_provider;
+  bool m_bus_acquired;
+  Glib::RefPtr<Gio::DBus::Connection> m_connection;
+  Glib::RefPtr<Gio::DBus::InterfaceInfo> m_gnote_interface;
+  Glib::RefPtr<Gio::DBus::InterfaceInfo> m_search_provider_interface;
+  Glib::RefPtr<RemoteControlClient> m_remote_control_proxy;
+  slot_name_acquire_finish m_on_name_acquire_finish;
 };
 
 }


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