[gnote] Refactor NoteManager removing stuff out of ctor



commit 8332e291143787df6df48ddc4c915d9fdcecc267
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Oct 13 17:13:05 2019 +0300

    Refactor NoteManager removing stuff out of ctor

 src/gnote.cpp           |  3 ++-
 src/notemanager.cpp     | 16 ++++++----------
 src/notemanager.hpp     |  5 +++--
 src/notemanagerbase.cpp |  6 +++---
 src/notemanagerbase.hpp |  4 ++--
 5 files changed, 16 insertions(+), 18 deletions(-)
---
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 19c5c52d..910024ea 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -142,7 +142,8 @@ namespace gnote {
 
     //create singleton objects
     m_preferences.init();;
-    m_manager = new NoteManager(m_preferences, note_path);
+    m_manager = new NoteManager(m_preferences);
+    m_manager->init(note_path);
     new notebooks::NotebookManager(default_note_manager());
     new ActionManager;
     sync::SyncManager::init(default_note_manager());
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index 45e3d1ad..bce21a39 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -37,24 +37,20 @@
 
 namespace gnote {
 
-  NoteManager::NoteManager(Preferences & preferences, const Glib::ustring & directory)
-    : NoteManagerBase(directory)
-    , m_preferences(preferences)
+  NoteManager::NoteManager(Preferences & preferences)
+    : m_preferences(preferences)
+    , m_addin_mgr(NULL)
     , m_note_archiver(*this)
   {
-    Glib::ustring backup = directory + "/Backup";
-    
-    _common_init(directory, backup);
   }
 
 
-  void NoteManager::_common_init(const Glib::ustring & directory, const Glib::ustring & backup_directory)
+  void NoteManager::init(const Glib::ustring & directory)
   {
-    m_addin_mgr = NULL;
+    Glib::ustring backup = directory + "/Backup";
+    NoteManagerBase::init(directory, backup);
     bool is_first_run = first_run();
 
-    NoteManagerBase::_common_init(directory, backup_directory);
-
     Glib::RefPtr<Gio::Settings> settings = m_preferences.get_schema_settings(Preferences::SCHEMA_GNOTE);
     // Watch the START_NOTE_URI setting and update it so that the
     // StartNoteUri property doesn't generate a call to
diff --git a/src/notemanager.hpp b/src/notemanager.hpp
index e09cea54..7210271b 100644
--- a/src/notemanager.hpp
+++ b/src/notemanager.hpp
@@ -39,9 +39,11 @@ namespace gnote {
     typedef std::shared_ptr<NoteManager> Ptr;
     typedef sigc::slot<void, const Note::Ptr &> NoteChangedSlot;
     
-    NoteManager(Preferences & preferences, const Glib::ustring &);
+    NoteManager(Preferences & preferences);
     ~NoteManager();
 
+    void init(const Glib::ustring &);
+
     virtual NoteArchiver & note_archiver() override
       {
         return m_note_archiver;
@@ -68,7 +70,6 @@ namespace gnote {
 
     using NoteManagerBase::create_note_from_template;
   protected:
-    virtual void _common_init(const Glib::ustring & directory, const Glib::ustring & backup) override;
     virtual void post_load() override;
     virtual void migrate_notes(const Glib::ustring & old_note_dir) override;
     virtual NoteBase::Ptr create_note_from_template(const Glib::ustring & title,
diff --git a/src/notemanagerbase.cpp b/src/notemanagerbase.cpp
index 2c613d50..d6f40282 100644
--- a/src/notemanagerbase.cpp
+++ b/src/notemanagerbase.cpp
@@ -88,9 +88,8 @@ Glib::ustring NoteManagerBase::sanitize_xml_content(const Glib::ustring & xml_co
 }
 
 
-NoteManagerBase::NoteManagerBase(const Glib::ustring & directory)
+NoteManagerBase::NoteManagerBase()
   : m_trie_controller(NULL)
-  , m_notes_dir(directory)
 {
 }
 
@@ -101,8 +100,9 @@ NoteManagerBase::~NoteManagerBase()
   }
 }
 
-void NoteManagerBase::_common_init(const Glib::ustring & /*directory*/, const Glib::ustring & 
backup_directory)
+void NoteManagerBase::init(const Glib::ustring & directory, const Glib::ustring & backup_directory)
 {
+  m_notes_dir = directory;
   m_default_note_template_title = _("New Note Template");
   m_backup_dir = backup_directory;
   bool is_first_run = first_run();
diff --git a/src/notemanagerbase.hpp b/src/notemanagerbase.hpp
index e783f35a..075b146d 100644
--- a/src/notemanagerbase.hpp
+++ b/src/notemanagerbase.hpp
@@ -40,7 +40,7 @@ public:
   static Glib::ustring get_note_template_content(const Glib::ustring & title);
   static Glib::ustring split_title_from_content(Glib::ustring title, Glib::ustring & body);
 
-  NoteManagerBase(const Glib::ustring & directory);
+  NoteManagerBase();
   virtual ~NoteManagerBase();
 
   size_t trie_max_length();
@@ -93,7 +93,7 @@ public:
   NoteBase::RenamedHandler signal_note_renamed;
   NoteBase::SavedHandler signal_note_saved;
 protected:
-  virtual void _common_init(const Glib::ustring & directory, const Glib::ustring & backup);
+  void init(const Glib::ustring & directory, const Glib::ustring & backup);
   bool first_run() const;
   virtual void post_load();
   virtual void migrate_notes(const Glib::ustring & old_note_dir);


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