[gnote] Do not use singleton IGnote in note manager



commit 93a4ea5320ab42d58305cc0d7d7bf852586a09af
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat Dec 7 22:54:42 2019 +0200

    Do not use singleton IGnote in note manager

 src/gnote.cpp           | 2 +-
 src/notemanager.cpp     | 9 +++++----
 src/notemanager.hpp     | 2 +-
 src/notemanagerbase.cpp | 7 ++++---
 src/notemanagerbase.hpp | 4 +++-
 5 files changed, 14 insertions(+), 10 deletions(-)
---
diff --git a/src/gnote.cpp b/src/gnote.cpp
index e9072400..e828705e 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -146,7 +146,7 @@ namespace gnote {
 
     //create singleton objects
     m_preferences.init();
-    m_manager = new NoteManager(m_preferences);
+    m_manager = new NoteManager(*this);
     m_manager->init(note_path);
     m_action_manager.init();
     m_sync_manager = new sync::SyncManager(*this, default_note_manager());
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index 40309b00..cd8071ba 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -37,8 +37,9 @@
 
 namespace gnote {
 
-  NoteManager::NoteManager(Preferences & preferences)
-    : m_preferences(preferences)
+  NoteManager::NoteManager(IGnote & g)
+    : NoteManagerBase(g)
+    , m_preferences(g.preferences())
     , m_notebook_manager(*this)
     , m_addin_mgr(NULL)
     , m_note_archiver(*this)
@@ -93,7 +94,7 @@ namespace gnote {
     }
 
     m_notebook_manager.init();
-    IGnote::obj().signal_quit.connect(sigc::mem_fun(*this, &NoteManager::on_exiting_event));
+    m_gnote.signal_quit.connect(sigc::mem_fun(*this, &NoteManager::on_exiting_event));
   }
 
   NoteManager::~NoteManager()
@@ -111,7 +112,7 @@ namespace gnote {
 
   AddinManager *NoteManager::create_addin_manager()
   {
-    return new AddinManager(IGnote::obj(), *this, m_preferences, IGnote::conf_dir());
+    return new AddinManager(m_gnote, *this, m_preferences, IGnote::conf_dir());
   }
 
   void NoteManager::create_start_notes ()
diff --git a/src/notemanager.hpp b/src/notemanager.hpp
index 51944126..324df326 100644
--- a/src/notemanager.hpp
+++ b/src/notemanager.hpp
@@ -40,7 +40,7 @@ namespace gnote {
     typedef std::shared_ptr<NoteManager> Ptr;
     typedef sigc::slot<void, const Note::Ptr &> NoteChangedSlot;
     
-    NoteManager(Preferences & preferences);
+    NoteManager(IGnote & g);
     ~NoteManager();
 
     void init(const Glib::ustring &);
diff --git a/src/notemanagerbase.cpp b/src/notemanagerbase.cpp
index be76fa92..6ea9e642 100644
--- a/src/notemanagerbase.cpp
+++ b/src/notemanagerbase.cpp
@@ -88,8 +88,9 @@ Glib::ustring NoteManagerBase::sanitize_xml_content(const Glib::ustring & xml_co
 }
 
 
-NoteManagerBase::NoteManagerBase()
-  : m_trie_controller(NULL)
+NoteManagerBase::NoteManagerBase(IGnote & g)
+  : m_gnote(g)
+  , m_trie_controller(NULL)
 {
 }
 
@@ -434,7 +435,7 @@ NoteBase::Ptr NoteManagerBase::find_template_note() const
   auto notes = template_tag->get_notes();
   for(NoteBase *iter : notes) {
     NoteBase::Ptr note = iter->shared_from_this();
-    if(!IGnote::obj().notebook_manager().get_notebook_from_note(note)) {
+    if(!m_gnote.notebook_manager().get_notebook_from_note(note)) {
       template_note = note;
       break;
     }
diff --git a/src/notemanagerbase.hpp b/src/notemanagerbase.hpp
index 075b146d..238ef186 100644
--- a/src/notemanagerbase.hpp
+++ b/src/notemanagerbase.hpp
@@ -29,6 +29,7 @@
 
 namespace gnote {
 
+class IGnote;
 class TrieController;
 
 class NoteManagerBase
@@ -40,7 +41,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();
+  NoteManagerBase(IGnote & g);
   virtual ~NoteManagerBase();
 
   size_t trie_max_length();
@@ -112,6 +113,7 @@ protected:
   Glib::ustring make_new_file_name(const Glib::ustring & guid) const;
   virtual NoteBase::Ptr note_load(const Glib::ustring & file_name) = 0;
 
+  IGnote & m_gnote;
   NoteBase::List m_notes;
   Glib::ustring m_start_note_uri;
   Glib::ustring m_backup_dir;


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