[gnote] Remove use of singleton IGnote



commit 89f2da05d2b2de5e1081cc5c8def6261eba3278d
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Dec 15 16:23:01 2019 +0200

    Remove use of singleton IGnote

 src/synchronization/filesystemsyncserver.cpp | 16 +++++-----------
 src/synchronization/filesystemsyncserver.hpp |  3 +--
 src/synchronization/fusesyncserviceaddin.cpp |  4 ++--
 src/synchronization/isyncmanager.cpp         |  9 ---------
 src/synchronization/isyncmanager.hpp         |  1 -
 5 files changed, 8 insertions(+), 25 deletions(-)
---
diff --git a/src/synchronization/filesystemsyncserver.cpp b/src/synchronization/filesystemsyncserver.cpp
index 5a725fd5..0aead48c 100644
--- a/src/synchronization/filesystemsyncserver.cpp
+++ b/src/synchronization/filesystemsyncserver.cpp
@@ -26,6 +26,7 @@
 
 #include "debug.hpp"
 #include "filesystemsyncserver.hpp"
+#include "preferences.hpp"
 #include "sharp/directory.hpp"
 #include "sharp/files.hpp"
 #include "sharp/uuid.hpp"
@@ -52,9 +53,10 @@ int str_to_int(const Glib::ustring & s)
 namespace gnote {
 namespace sync {
 
-SyncServer::Ptr FileSystemSyncServer::create(const Glib::RefPtr<Gio::File> & path)
+SyncServer::Ptr FileSystemSyncServer::create(const Glib::RefPtr<Gio::File> & path, Preferences & prefs)
 {
-  return SyncServer::Ptr(new FileSystemSyncServer(path));
+  return SyncServer::Ptr(new FileSystemSyncServer(path,
+    prefs.get_schema_settings(Preferences::SCHEMA_SYNC)->get_string(Preferences::SYNC_CLIENT_ID)));
 }
 
 
@@ -64,14 +66,6 @@ SyncServer::Ptr FileSystemSyncServer::create(const Glib::RefPtr<Gio::File> & pat
 }
 
 
-FileSystemSyncServer::FileSystemSyncServer(const Glib::RefPtr<Gio::File> & localSyncPath)
-  : m_server_path(localSyncPath)
-  , m_cache_path(Glib::build_filename(Glib::get_tmp_dir(), Glib::get_user_name(), "gnote"))
-{
-  common_ctor();
-}
-
-
 FileSystemSyncServer::FileSystemSyncServer(const Glib::RefPtr<Gio::File> & localSyncPath, const 
Glib::ustring & client_id)
   : m_server_path(localSyncPath)
   , m_cache_path(Glib::build_filename(Glib::get_tmp_dir(), Glib::get_user_name(), "gnote"))
@@ -472,7 +466,7 @@ int FileSystemSyncServer::latest_revision()
 
 SyncLockInfo FileSystemSyncServer::current_sync_lock()
 {
-  SyncLockInfo syncLockInfo;
+  SyncLockInfo syncLockInfo(m_sync_lock.client_id);
 
   xmlDocPtr xml_doc = NULL;
   if(is_valid_xml_file(m_lock_path, &xml_doc)) {
diff --git a/src/synchronization/filesystemsyncserver.hpp b/src/synchronization/filesystemsyncserver.hpp
index 5d0c1205..a4239bf9 100644
--- a/src/synchronization/filesystemsyncserver.hpp
+++ b/src/synchronization/filesystemsyncserver.hpp
@@ -34,7 +34,7 @@ class FileSystemSyncServer
   : public SyncServer
 {
 public:
-  static SyncServer::Ptr create(const Glib::RefPtr<Gio::File> & path);
+  static SyncServer::Ptr create(const Glib::RefPtr<Gio::File> & path, Preferences & prefs);
   static SyncServer::Ptr create(const Glib::RefPtr<Gio::File> & path, const Glib::ustring & client_id);
   virtual bool begin_sync_transaction() override;
   virtual bool commit_sync_transaction() override;
@@ -48,7 +48,6 @@ public:
   virtual Glib::ustring id() override;
   virtual bool updates_available_since(int revision) override;
 private:
-  explicit FileSystemSyncServer(const Glib::RefPtr<Gio::File> & path);
   FileSystemSyncServer(const Glib::RefPtr<Gio::File> & path, const Glib::ustring & client_id);
   void common_ctor();
 
diff --git a/src/synchronization/fusesyncserviceaddin.cpp b/src/synchronization/fusesyncserviceaddin.cpp
index 5c0358e6..57d07a22 100644
--- a/src/synchronization/fusesyncserviceaddin.cpp
+++ b/src/synchronization/fusesyncserviceaddin.cpp
@@ -80,7 +80,7 @@ SyncServer::Ptr FuseSyncServiceAddin::create_sync_server()
   if(is_configured()) {
     if(!is_mounted() && !mount_fuse(true)) // mount_fuse may throw GnoteSyncException!
       throw std::runtime_error(("Could not mount " + m_mount_path).c_str());
-    server = FileSystemSyncServer::create(Gio::File::create_for_path(m_mount_path));
+    server = FileSystemSyncServer::create(Gio::File::create_for_path(m_mount_path), ignote().preferences());
   }
   else {
     throw new std::logic_error("create_sync_server called without being configured");
@@ -256,7 +256,7 @@ bool FuseSyncServiceAddin::mount_fuse(bool useStoredValues)
 
 int FuseSyncServiceAddin::get_timeout_ms()
 {
-  Glib::RefPtr<Gio::Settings> settings = 
IGnote::obj().preferences().get_schema_settings(Preferences::SCHEMA_GNOTE);
+  Glib::RefPtr<Gio::Settings> settings = 
ignote().preferences().get_schema_settings(Preferences::SCHEMA_GNOTE);
   try {
     return settings->get_int(Preferences::SYNC_FUSE_MOUNT_TIMEOUT);
   }
diff --git a/src/synchronization/isyncmanager.cpp b/src/synchronization/isyncmanager.cpp
index ed72d2ad..2e88fcf8 100644
--- a/src/synchronization/isyncmanager.cpp
+++ b/src/synchronization/isyncmanager.cpp
@@ -28,15 +28,6 @@ namespace gnote {
 namespace sync {
 
 
-SyncLockInfo::SyncLockInfo()
-  : 
client_id(IGnote::obj().preferences().get_schema_settings(Preferences::SCHEMA_SYNC)->get_string(Preferences::SYNC_CLIENT_ID))
-  , transaction_id(sharp::uuid().string())
-  , renew_count(0)
-  , duration(0, 2, 0) // default of 2 minutes
-  , revision(0)
-{
-}
-
 SyncLockInfo::SyncLockInfo(const Glib::ustring & client)
   : client_id(client)
   , transaction_id(sharp::uuid().string())
diff --git a/src/synchronization/isyncmanager.hpp b/src/synchronization/isyncmanager.hpp
index db9dd0b7..1dc3e99b 100644
--- a/src/synchronization/isyncmanager.hpp
+++ b/src/synchronization/isyncmanager.hpp
@@ -37,7 +37,6 @@ public:
   sharp::TimeSpan duration;
   int revision;
 
-  SyncLockInfo();
   explicit SyncLockInfo(const Glib::ustring & client);
   Glib::ustring hash_string();
 };


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