[gnote] Pass NoteManager to object, that require it



commit c2b5543748aee1e0a5e6851ee057def884bf87e5
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Sun Jan 6 17:04:47 2013 +0200

    Pass NoteManager to object, that require it
    
    Avoid call to Gnote::default_note_manager() where possible.

 src/addinmanager.cpp                               |   10 +++--
 src/addinmanager.hpp                               |    5 +-
 src/addinpreferencefactory.hpp                     |    8 ++-
 src/addins/bugzilla/bugzillapreferences.cpp        |    4 +-
 src/addins/bugzilla/bugzillapreferences.hpp        |    3 +-
 .../inserttimestamp/inserttimestamppreferences.cpp |    4 +-
 .../inserttimestamp/inserttimestamppreferences.hpp |    4 +-
 .../notedirectorywatcherapplicationaddin.cpp       |   21 +++++-----
 .../noteoftheday/noteofthedayapplicationaddin.cpp  |   12 ++----
 .../noteoftheday/noteofthedayapplicationaddin.hpp  |    3 +-
 .../noteoftheday/noteofthedaypreferences.cpp       |   11 ++---
 .../noteoftheday/noteofthedaypreferences.hpp       |    6 ++-
 src/applicationaddin.hpp                           |   12 ++++++
 src/gnote.cpp                                      |   10 ++--
 src/gnote.hpp                                      |    4 +-
 src/notebooks/notebook.cpp                         |   42 +++++++++----------
 src/notebooks/notebook.hpp                         |   20 +++++----
 src/notebooks/notebookapplicationaddin.cpp         |    4 +-
 src/notebooks/notebookmanager.cpp                  |   14 +++---
 src/notebooks/notebookstreeview.cpp                |    7 +--
 src/notebooks/notebookstreeview.hpp                |    3 +-
 src/notemanager.cpp                                |   15 +------
 src/notemanager.hpp                                |    6 +--
 src/preferencesdialog.cpp                          |   12 +++---
 src/preferencesdialog.hpp                          |    5 +-
 src/searchnoteswidget.cpp                          |    3 +-
 src/synchronization/gnotesyncclient.cpp            |    6 +-
 src/synchronization/gnotesyncclient.hpp            |    4 +-
 src/synchronization/syncdialog.cpp                 |   15 ++++---
 src/synchronization/syncdialog.hpp                 |    7 ++-
 src/synchronization/syncmanager.cpp                |   22 +++++++----
 src/synchronization/syncmanager.hpp                |    8 ++-
 32 files changed, 163 insertions(+), 147 deletions(-)
---
diff --git a/src/addinmanager.cpp b/src/addinmanager.cpp
index f8bcc64..86d8598 100644
--- a/src/addinmanager.cpp
+++ b/src/addinmanager.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2012 Aurimas Cernius
+ * Copyright (C) 2010-2013 Aurimas Cernius
  * Copyright (C) 2009, 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -54,8 +54,9 @@ namespace gnote {
   m_app_addins.insert(std::make_pair(typeid(klass).name(),        \
                                      klass::create()))
 
-  AddinManager::AddinManager(const std::string & conf_dir)
-    : m_gnote_conf_dir(conf_dir)
+  AddinManager::AddinManager(NoteManager & note_manager, const std::string & conf_dir)
+    : m_note_manager(note_manager)
+    , m_gnote_conf_dir(conf_dir)
   {
     m_addins_prefs_dir = Glib::build_filename(conf_dir, "addins");
     m_addins_prefs_file = Glib::build_filename(m_addins_prefs_dir,
@@ -324,6 +325,7 @@ namespace gnote {
     for(AppAddinMap::const_iterator iter = m_app_addins.begin();
         iter != m_app_addins.end(); ++iter) {
       ApplicationAddin * addin = iter->second;
+      addin->note_manager(m_note_manager);
       const sharp::DynamicModule * dmod
         = m_module_manager.get_module(iter->first);
       if (!dmod || dmod->is_enabled()) {
@@ -400,7 +402,7 @@ namespace gnote {
   {
     IdAddinPrefsMap::const_iterator iter = m_addin_prefs.find(id);
     if(iter != m_addin_prefs.end()) {
-      return iter->second->create_preference_widget();
+      return iter->second->create_preference_widget(m_note_manager);
     }
     return NULL;
   }
diff --git a/src/addinmanager.hpp b/src/addinmanager.hpp
index 9be4d65..1b69b6e 100644
--- a/src/addinmanager.hpp
+++ b/src/addinmanager.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010,2012 Aurimas Cernius
+ * Copyright (C) 2010,2012-2013 Aurimas Cernius
  * Copyright (C) 2009 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -49,7 +49,7 @@ class SyncServiceAddin;
 class AddinManager
 {
 public:
-  AddinManager(const std::string & conf_dir);
+  AddinManager(NoteManager & note_manager, const std::string & conf_dir);
   ~AddinManager();
 
   void add_note_addin_info(const sharp::DynamicModule * dmod);
@@ -82,6 +82,7 @@ private:
   void initialize_sharp_addins();
   void migrate_addins(const std::string & old_addins_dir);
     
+  NoteManager & m_note_manager;
   const std::string m_gnote_conf_dir;
   std::string m_addins_prefs_dir;
   std::string m_addins_prefs_file;
diff --git a/src/addinpreferencefactory.hpp b/src/addinpreferencefactory.hpp
index e1c1a3a..c8d43a7 100644
--- a/src/addinpreferencefactory.hpp
+++ b/src/addinpreferencefactory.hpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -25,6 +26,7 @@
 
 #include <gtkmm/widget.h>
 
+#include "notemanager.hpp"
 #include "sharp/modulefactory.hpp"
 
 
@@ -37,7 +39,7 @@ class AddinPreferenceFactoryBase
 {
 public:
   static const char * IFACE_NAME;
-  virtual Gtk::Widget * create_preference_widget() = 0;
+  virtual Gtk::Widget * create_preference_widget(NoteManager & m) = 0;
 };
 
 
@@ -51,9 +53,9 @@ public:
     {
       return new AddinPreferenceFactory<_AddinType>();
     }
-  virtual Gtk::Widget * create_preference_widget()
+  virtual Gtk::Widget * create_preference_widget(NoteManager & m)
     {
-      return Gtk::manage(new _AddinType);
+      return Gtk::manage(new _AddinType(m));
     }
 };
 
diff --git a/src/addins/bugzilla/bugzillapreferences.cpp b/src/addins/bugzilla/bugzillapreferences.cpp
index 2afa881..dc22855 100644
--- a/src/addins/bugzilla/bugzillapreferences.cpp
+++ b/src/addins/bugzilla/bugzillapreferences.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011 Aurimas Cernius
+ * Copyright (C) 2011,2013 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -53,7 +53,7 @@ namespace bugzilla {
     }
   }
 
-  BugzillaPreferences::BugzillaPreferences()
+  BugzillaPreferences::BugzillaPreferences(gnote::NoteManager &)
     : Gtk::VBox(false, 12)
   {
     _init_static();
diff --git a/src/addins/bugzilla/bugzillapreferences.hpp b/src/addins/bugzilla/bugzillapreferences.hpp
index 4e9865d..74680ed 100644
--- a/src/addins/bugzilla/bugzillapreferences.hpp
+++ b/src/addins/bugzilla/bugzillapreferences.hpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -42,7 +43,7 @@ class BugzillaPreferences
   : public Gtk::VBox
 {
 public:
-  BugzillaPreferences();
+  BugzillaPreferences(gnote::NoteManager &);
 
 protected:
   virtual void on_realize();
diff --git a/src/addins/inserttimestamp/inserttimestamppreferences.cpp b/src/addins/inserttimestamp/inserttimestamppreferences.cpp
index 5067793..84e1e00 100644
--- a/src/addins/inserttimestamp/inserttimestamppreferences.cpp
+++ b/src/addins/inserttimestamp/inserttimestamppreferences.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2012 Aurimas Cernius
+ * Copyright (C) 2011-2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -53,7 +53,7 @@ namespace inserttimestamp {
   }
 
 
-  InsertTimestampPreferences::InsertTimestampPreferences()
+  InsertTimestampPreferences::InsertTimestampPreferences(gnote::NoteManager &)
     : Gtk::VBox(false, 12)
   {
     _init_static();
diff --git a/src/addins/inserttimestamp/inserttimestamppreferences.hpp b/src/addins/inserttimestamp/inserttimestamppreferences.hpp
index c80f68d..10d6fbb 100644
--- a/src/addins/inserttimestamp/inserttimestamppreferences.hpp
+++ b/src/addins/inserttimestamp/inserttimestamppreferences.hpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -29,6 +30,7 @@
 #include <gtkmm/scrolledwindow.h>
 #include <gtkmm/treeview.h>
 
+#include "notemanager.hpp"
 
 namespace inserttimestamp {
 
@@ -39,7 +41,7 @@ class InsertTimestampPreferences
   : public Gtk::VBox
 {
 public:
-  InsertTimestampPreferences();
+  InsertTimestampPreferences(gnote::NoteManager &);
 private:
   static void _init_static();
   class FormatColumns
diff --git a/src/addins/notedirectorywatcher/notedirectorywatcherapplicationaddin.cpp b/src/addins/notedirectorywatcher/notedirectorywatcherapplicationaddin.cpp
index b39fd4b..a47dae5 100644
--- a/src/addins/notedirectorywatcher/notedirectorywatcherapplicationaddin.cpp
+++ b/src/addins/notedirectorywatcher/notedirectorywatcherapplicationaddin.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 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
@@ -23,7 +23,6 @@
 #include <glibmm/i18n.h>
 
 #include "debug.hpp"
-#include "gnote.hpp"
 #include "notedirectorywatcherapplicationaddin.hpp"
 #include "notemanager.hpp"
 #include "sharp/files.hpp"
@@ -77,9 +76,9 @@ NoteDirectoryWatcherApplicationAddin::NoteDirectoryWatcherApplicationAddin()
 
 void NoteDirectoryWatcherApplicationAddin::initialize()
 {
-  gnote::NoteManager & note_manager = gnote::Gnote::obj().default_note_manager();
-  std::string note_path = note_manager.get_notes_dir();
-  note_manager.signal_note_saved
+  gnote::NoteManager & manager(note_manager());
+  std::string note_path = manager.get_notes_dir();
+  manager.signal_note_saved
     .connect(sigc::mem_fun(*this, &NoteDirectoryWatcherApplicationAddin::handle_note_saved));
 
   Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(note_path);
@@ -222,9 +221,9 @@ void NoteDirectoryWatcherApplicationAddin::delete_note(const std::string & note_
 
   std::string note_uri = make_uri(note_id);
 
-  gnote::Note::Ptr note_to_delete = gnote::Gnote::obj().default_note_manager().find_by_uri(note_uri);
+  gnote::Note::Ptr note_to_delete = note_manager().find_by_uri(note_uri);
   if(note_to_delete != 0) {
-    gnote::Gnote::obj().default_note_manager().delete_note(note_to_delete);
+    note_manager().delete_note(note_to_delete);
   }
   else {
     DBG_OUT("notedirectorywatcher: did not delete %s because note not found.", note_id.c_str());
@@ -234,7 +233,7 @@ void NoteDirectoryWatcherApplicationAddin::delete_note(const std::string & note_
 void NoteDirectoryWatcherApplicationAddin::add_or_update_note(const std::string & note_id)
 {
   std::string note_path = Glib::build_filename(
-    gnote::Gnote::obj().default_note_manager().get_notes_dir(), note_id + ".note");
+    note_manager().get_notes_dir(), note_id + ".note");
   if (!sharp::file_exists(note_path)) {
     DBG_OUT("NoteDirectoryWatcher: Not processing update of %s because file does not exist.", note_path.c_str());
     return;
@@ -263,7 +262,7 @@ void NoteDirectoryWatcherApplicationAddin::add_or_update_note(const std::string
 
   std::string note_uri = make_uri(note_id);
 
-  gnote::Note::Ptr note = gnote::Gnote::obj().default_note_manager().find_by_uri(note_uri);
+  gnote::Note::Ptr note = note_manager().find_by_uri(note_uri);
 
   bool is_new_note = false;
 
@@ -283,7 +282,7 @@ void NoteDirectoryWatcherApplicationAddin::add_or_update_note(const std::string
     }
 
     try {
-      note = gnote::Gnote::obj().default_note_manager().create_with_guid(title, note_id);
+      note = note_manager().create_with_guid(title, note_id);
       if(note == 0) {
         ERR_OUT("NoteDirectoryWatcher: Unknown error creating note from %s", note_path.c_str());
         return;
@@ -304,7 +303,7 @@ void NoteDirectoryWatcherApplicationAddin::add_or_update_note(const std::string
   catch(std::exception & e) {
     ERR_OUT("NoteDirectoryWatcher: Update aborted, error parsing %s: %s", note_path.c_str(), e.what());
     if(is_new_note) {
-      gnote::Gnote::obj().default_note_manager().delete_note(note);
+      note_manager().delete_note(note);
     }
   }
 }
diff --git a/src/addins/noteoftheday/noteofthedayapplicationaddin.cpp b/src/addins/noteoftheday/noteofthedayapplicationaddin.cpp
index 005b0e4..248b2c2 100644
--- a/src/addins/noteoftheday/noteofthedayapplicationaddin.cpp
+++ b/src/addins/noteoftheday/noteofthedayapplicationaddin.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010 Aurimas Cernius
+ * Copyright (C) 2010,2013 Aurimas Cernius
  * Copyright (C) 2009 Debarshi Ray
  *
  * This program is free software: you can redistribute it and/or modify
@@ -21,7 +21,6 @@
 #include <glibmm.h>
 #include <glibmm/i18n.h>
 
-#include "gnote.hpp"
 #include "noteoftheday.hpp"
 #include "noteofthedayapplicationaddin.hpp"
 #include "noteofthedaypreferencesfactory.hpp"
@@ -68,7 +67,6 @@ const char * NoteOfTheDayApplicationAddin::IFACE_NAME
 NoteOfTheDayApplicationAddin::NoteOfTheDayApplicationAddin()
   : ApplicationAddin()
   , m_initialized(false)
-  , m_manager(0)
   , m_timeout()
 {
 }
@@ -82,11 +80,11 @@ void NoteOfTheDayApplicationAddin::check_new_day() const
   Glib::Date date;
   date.set_time_current();
 
-  if (0 == NoteOfTheDay::get_note_by_date(*m_manager, date)) {
-    NoteOfTheDay::cleanup_old(*m_manager);
+  if (0 == NoteOfTheDay::get_note_by_date(note_manager(), date)) {
+    NoteOfTheDay::cleanup_old(note_manager());
 
     // Create a new NotD if the day has changed
-    NoteOfTheDay::create(*m_manager, date);
+    NoteOfTheDay::create(note_manager(), date);
   }
 }
 
@@ -110,7 +108,6 @@ void NoteOfTheDayApplicationAddin::initialize()
     Glib::PRIORITY_DEFAULT);
 
   m_initialized = true;
-  m_manager = &gnote::Gnote::obj().default_note_manager();
 }
 
 void NoteOfTheDayApplicationAddin::shutdown()
@@ -119,7 +116,6 @@ void NoteOfTheDayApplicationAddin::shutdown()
     m_timeout.disconnect();
 
   m_initialized = false;
-  m_manager = 0;
 }
 
 bool NoteOfTheDayApplicationAddin::initialized()
diff --git a/src/addins/noteoftheday/noteofthedayapplicationaddin.hpp b/src/addins/noteoftheday/noteofthedayapplicationaddin.hpp
index fe29686..5308364 100644
--- a/src/addins/noteoftheday/noteofthedayapplicationaddin.hpp
+++ b/src/addins/noteoftheday/noteofthedayapplicationaddin.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010 Aurimas Cernius
+ * Copyright (C) 2010,2013 Aurimas Cernius
  * Copyright (C) 2009 Debarshi Ray
  *
  * This program is free software: you can redistribute it and/or modify
@@ -69,7 +69,6 @@ private:
   void check_new_day() const;
 
   bool m_initialized;
-  gnote::NoteManager * m_manager;
   sigc::connection m_timeout;
 };
 
diff --git a/src/addins/noteoftheday/noteofthedaypreferences.cpp b/src/addins/noteoftheday/noteofthedaypreferences.cpp
index 916c430..de1315a 100644
--- a/src/addins/noteoftheday/noteofthedaypreferences.cpp
+++ b/src/addins/noteoftheday/noteofthedaypreferences.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2012 Aurimas Cernius
+ * Copyright (C) 2011-2013 Aurimas Cernius
  * Copyright (C) 2009 Debarshi Ray
  *
  * This program is free software: you can redistribute it and/or modify
@@ -30,11 +30,12 @@
 
 namespace noteoftheday {
 
-NoteOfTheDayPreferences::NoteOfTheDayPreferences()
+NoteOfTheDayPreferences::NoteOfTheDayPreferences(gnote::NoteManager & manager)
   : Gtk::VBox(false, 12)
   , m_open_template_button(_("_Open Today: Template"), true)
   , m_label(_("Change the <span weight=\"bold\">Today: Template</span> "
               "note to customize the text that new Today notes have."))
+  , m_note_manager(manager)
 {
   m_label.set_line_wrap(true);
   m_label.set_use_markup(true);
@@ -55,13 +56,11 @@ NoteOfTheDayPreferences::~NoteOfTheDayPreferences()
 
 void NoteOfTheDayPreferences::open_template_button_clicked() const
 {
-  gnote::NoteManager & manager = gnote::Gnote::obj().default_note_manager();
-  gnote::Note::Ptr template_note = manager.find(
-                                       NoteOfTheDay::s_template_title);
+  gnote::Note::Ptr template_note = m_note_manager.find(NoteOfTheDay::s_template_title);
 
   if (0 == template_note) {
     try {
-      template_note = manager.create(
+      template_note = m_note_manager.create(
                                 NoteOfTheDay::s_template_title,
                                 NoteOfTheDay::get_template_content(
                                   NoteOfTheDay::s_template_title));
diff --git a/src/addins/noteoftheday/noteofthedaypreferences.hpp b/src/addins/noteoftheday/noteofthedaypreferences.hpp
index 1db9728..fdfdad8 100644
--- a/src/addins/noteoftheday/noteofthedaypreferences.hpp
+++ b/src/addins/noteoftheday/noteofthedaypreferences.hpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2013 Aurimas Cernius
  * Copyright (C) 2009 Debarshi Ray
  *
  * This program is free software: you can redistribute it and/or modify
@@ -20,7 +21,7 @@
 #ifndef __NOTE_OF_THE_DAY_PREFERENCES_HPP_
 #define __NOTE_OF_THE_DAY_PREFERENCES_HPP_
 
-#include <gtkmm.h>
+#include "notemanager.hpp"
 
 namespace noteoftheday {
 
@@ -29,7 +30,7 @@ class NoteOfTheDayPreferences
 {
 public:
 
-  NoteOfTheDayPreferences();
+  NoteOfTheDayPreferences(gnote::NoteManager &);
   ~NoteOfTheDayPreferences();
 
 private:
@@ -38,6 +39,7 @@ private:
 
   Gtk::Button m_open_template_button;
   Gtk::Label m_label;
+  gnote::NoteManager & m_note_manager;
 };
 
 }
diff --git a/src/applicationaddin.hpp b/src/applicationaddin.hpp
index da772dd..6750ef8 100644
--- a/src/applicationaddin.hpp
+++ b/src/applicationaddin.hpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -24,6 +25,7 @@
 
 
 #include "abstractaddin.hpp"
+#include "notemanager.hpp"
 
 
 namespace gnote {
@@ -49,6 +51,16 @@ public:
   /// </summary>
   virtual bool initialized () = 0;
 
+  NoteManager & note_manager() const
+    {
+      return *m_note_manager;
+    }
+  void note_manager(NoteManager & manager)
+    {
+      m_note_manager = &manager;
+    }
+private:
+  NoteManager *m_note_manager;
 };
 
 
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 6725518..39c2a77 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -147,7 +147,7 @@ namespace gnote {
     m_manager = new NoteManager(note_path, sigc::mem_fun(*this, &Gnote::start_note_created));
     m_keybinder = new XKeybinder();
     ActionManager::obj().load_interface();
-    sync::SyncManager::init();
+    sync::SyncManager::init(default_note_manager());
     setup_global_actions();
     m_manager->get_addin_manager().initialize_application_addins();
   }
@@ -265,8 +265,8 @@ namespace gnote {
   void Gnote::register_object()
   {
     RemoteControlProxy::register_object(Gio::DBus::Connection::get_sync(Gio::DBus::BUS_TYPE_SESSION),
-                                        Gnote::obj().default_note_manager(),
-                                        sigc::mem_fun(Gnote::obj(), &Gnote::end_main));
+                                        default_note_manager(),
+                                        sigc::mem_fun(*this, &Gnote::end_main));
   }
 
 
@@ -322,7 +322,7 @@ namespace gnote {
   void Gnote::on_show_preferences_action(const Glib::VariantBase&)
   {
     if(!m_prefsdlg) {
-      m_prefsdlg = new PreferencesDialog(m_manager->get_addin_manager());
+      m_prefsdlg = new PreferencesDialog(default_note_manager());
       m_prefsdlg->signal_response().connect(
         sigc::mem_fun(*this, &Gnote::on_preferences_response));
     }
@@ -451,7 +451,7 @@ namespace gnote {
   void Gnote::open_note_sync_window(const Glib::VariantBase&)
   {
     if(m_sync_dlg == 0) {
-      m_sync_dlg = sync::SyncDialog::create();
+      m_sync_dlg = sync::SyncDialog::create(default_note_manager());
       m_sync_dlg->signal_response().connect(sigc::mem_fun(*this, &Gnote::on_sync_dialog_response));
     }
 
diff --git a/src/gnote.hpp b/src/gnote.hpp
index 192a47a..1df243a 100644
--- a/src/gnote.hpp
+++ b/src/gnote.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2012 Aurimas Cernius
+ * Copyright (C) 2010-2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -160,7 +160,6 @@ public:
     }
   sigc::signal<void> signal_quit;
   static void register_remote_control(NoteManager & manager, RemoteControlProxy::slot_name_acquire_finish on_finish);
-  static void register_object();
   sync::SyncDialog::Ptr sync_dialog()
     {
       return m_sync_dlg;
@@ -188,6 +187,7 @@ private:
   void on_new_note_app_action(const Glib::VariantBase&);
   NoteRecentChanges *get_active_window();
   bool show_tray_icon_timeout();
+  void register_object();
 
   NoteManager *m_manager;
   IKeybinder  *m_keybinder;
diff --git a/src/notebooks/notebook.cpp b/src/notebooks/notebook.cpp
index 9e64272..6922a6b 100644
--- a/src/notebooks/notebook.cpp
+++ b/src/notebooks/notebook.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2012 Aurimas Cernius
+ * Copyright (C) 2010-2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -44,7 +44,8 @@ namespace notebooks {
   /// A <see cref="System.String"/>.  This is the name that will be used
   /// to identify the notebook.
   /// </param>
-  Notebook::Notebook(const std::string & name, bool is_special)
+  Notebook::Notebook(NoteManager & manager, const std::string & name, bool is_special)
+    : m_note_manager(manager)
   {
     // is special assume the name as is, and we don't want a tag.
     if(is_special) {
@@ -63,7 +64,8 @@ namespace notebooks {
   /// <param name="notebookTag">
   /// A <see cref="Tag"/>.  This must be a system notebook tag.
   /// </param>
-  Notebook::Notebook(const Tag::Ptr & notebookTag)
+  Notebook::Notebook(NoteManager & manager, const Tag::Ptr & notebookTag)
+    : m_note_manager(manager)
   {
   // Parse the notebook name from the tag name
     std::string systemNotebookPrefix = std::string(Tag::SYSTEM_TAG_PREFIX)
@@ -126,19 +128,16 @@ namespace notebooks {
 
   Note::Ptr Notebook::get_template_note() const
   {
-    NoteManager & noteManager = Gnote::obj().default_note_manager();
     Note::Ptr note = find_template_note();
 
     if (!note) {
       std::string title = m_default_template_note_title;
-      if (noteManager.find(title)) {
+      if(m_note_manager.find(title)) {
         std::list<Note*> tag_notes;
         m_tag->get_notes(tag_notes);
-        title = noteManager.get_unique_name (title, tag_notes.size());
+        title = m_note_manager.get_unique_name (title, tag_notes.size());
       }
-      note =
-        noteManager.create (title,
-                            NoteManager::get_note_template_content (title));
+      note = m_note_manager.create(title, NoteManager::get_note_template_content (title));
           
       // Select the initial text
       NoteBuffer::Ptr buffer = note->get_buffer();
@@ -164,10 +163,9 @@ namespace notebooks {
   {
     std::string temp_title;
     Note::Ptr note_template = get_template_note();
-    NoteManager & note_manager = Gnote::obj().default_note_manager();
 
-    temp_title = note_manager.get_unique_name(_("New Note"), note_manager.get_notes().size());
-    Note::Ptr note = note_manager.create_note_from_template(temp_title, note_template);
+    temp_title = m_note_manager.get_unique_name(_("New Note"), m_note_manager.get_notes().size());
+    Note::Ptr note = m_note_manager.create_note_from_template(temp_title, note_template);
 
     // Add the notebook tag
     note->add_tag(m_tag);
@@ -212,12 +210,12 @@ namespace notebooks {
 
   Note::Ptr SpecialNotebook::get_template_note() const
   {
-    return Gnote::obj().default_note_manager().get_or_create_template_note();
+    return m_note_manager.get_or_create_template_note();
   }
 
 
-  AllNotesNotebook::AllNotesNotebook()
-    : SpecialNotebook(_("All Notes"))
+  AllNotesNotebook::AllNotesNotebook(NoteManager & manager)
+    : SpecialNotebook(manager, _("All Notes"))
   {
   }
 
@@ -245,8 +243,8 @@ namespace notebooks {
   }
 
 
-  UnfiledNotesNotebook::UnfiledNotesNotebook()
-    : SpecialNotebook(_("Unfiled Notes"))
+  UnfiledNotesNotebook::UnfiledNotesNotebook(NoteManager & manager)
+    : SpecialNotebook(manager, _("Unfiled Notes"))
   {
   }
 
@@ -274,8 +272,8 @@ namespace notebooks {
   }
 
 
-  PinnedNotesNotebook::PinnedNotesNotebook()
-    : SpecialNotebook(_("Pinned Notes"))
+  PinnedNotesNotebook::PinnedNotesNotebook(NoteManager & manager)
+    : SpecialNotebook(manager, _("Pinned Notes"))
   {
   }
 
@@ -302,10 +300,10 @@ namespace notebooks {
   }
 
 
-  ActiveNotesNotebook::ActiveNotesNotebook()
-    : SpecialNotebook(_("Active Notes"))
+  ActiveNotesNotebook::ActiveNotesNotebook(NoteManager & manager)
+    : SpecialNotebook(manager, _("Active Notes"))
   {
-    Gnote::obj().default_note_manager().signal_note_deleted
+    manager.signal_note_deleted
       .connect(sigc::mem_fun(*this, &ActiveNotesNotebook::on_note_deleted));
   }
 
diff --git a/src/notebooks/notebook.hpp b/src/notebooks/notebook.hpp
index 6837efb..aa6832d 100644
--- a/src/notebooks/notebook.hpp
+++ b/src/notebooks/notebook.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2012 Aurimas Cernius
+ * Copyright (C) 2010-2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -43,8 +43,8 @@ class Notebook
 public:
   typedef std::tr1::shared_ptr<Notebook> Ptr;
   static const char * NOTEBOOK_TAG_PREFIX;
-  Notebook(const std::string &, bool is_special = false);
-  Notebook(const Tag::Ptr &);
+  Notebook(NoteManager &, const std::string &, bool is_special = false);
+  Notebook(NoteManager &, const Tag::Ptr &);
   std::string get_name() const
     { return m_name; }
   void set_name(const std::string &);
@@ -60,6 +60,8 @@ public:
 ////
   virtual ~Notebook()
     {}
+protected:
+  NoteManager & m_note_manager;
 private:
   Notebook(const Notebook &);
   Notebook & operator=(const Notebook &);
@@ -82,8 +84,8 @@ class SpecialNotebook
 public:
   typedef std::tr1::shared_ptr<SpecialNotebook> Ptr;
 protected:
-  SpecialNotebook(const std::string &s)
-    : Notebook(s, true)
+  SpecialNotebook(NoteManager & m, const std::string &s)
+    : Notebook(m, s, true)
     {
     }
   virtual Tag::Ptr    get_tag() const;
@@ -102,7 +104,7 @@ class AllNotesNotebook
 {
 public:
   typedef std::tr1::shared_ptr<AllNotesNotebook> Ptr;
-  AllNotesNotebook();
+  AllNotesNotebook(NoteManager &);
   virtual std::string get_normalized_name() const;
   virtual bool        contains_note(const Note::Ptr &);
   virtual bool        add_note(const Note::Ptr &);
@@ -120,7 +122,7 @@ class UnfiledNotesNotebook
 {
 public:
   typedef std::tr1::shared_ptr<UnfiledNotesNotebook> Ptr;
-  UnfiledNotesNotebook();
+  UnfiledNotesNotebook(NoteManager &);
   virtual std::string get_normalized_name() const;
   virtual bool        contains_note(const Note::Ptr &);
   virtual bool        add_note(const Note::Ptr &);
@@ -133,7 +135,7 @@ class PinnedNotesNotebook
 {
 public:
   typedef std::tr1::shared_ptr<PinnedNotesNotebook> Ptr;
-  PinnedNotesNotebook();
+  PinnedNotesNotebook(NoteManager &);
   virtual std::string get_normalized_name() const;
   virtual bool        contains_note(const Note::Ptr &);
   virtual bool        add_note(const Note::Ptr &);
@@ -146,7 +148,7 @@ class ActiveNotesNotebook
 {
 public:
   typedef std::tr1::shared_ptr<ActiveNotesNotebook> Ptr;
-  ActiveNotesNotebook();
+  ActiveNotesNotebook(NoteManager &);
   virtual std::string get_normalized_name() const;
   virtual bool        contains_note(const Note::Ptr &);
   virtual bool        add_note(const Note::Ptr &);
diff --git a/src/notebooks/notebookapplicationaddin.cpp b/src/notebooks/notebookapplicationaddin.cpp
index 226e02c..232d74a 100644
--- a/src/notebooks/notebookapplicationaddin.cpp
+++ b/src/notebooks/notebookapplicationaddin.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2012 Aurimas Cernius
+ * Copyright (C) 2011-2013 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -107,7 +107,7 @@ namespace gnote {
             IconManager::obj().get_icon(IconManager::NOTE_NEW, 16))));
       }
 
-      NoteManager & nm(Gnote::obj().default_note_manager());
+      NoteManager & nm(note_manager());
       
       for(Note::List::const_iterator iter = nm.get_notes().begin();
           iter != nm.get_notes().end(); ++iter) {
diff --git a/src/notebooks/notebookmanager.cpp b/src/notebooks/notebookmanager.cpp
index c07eb9c..92c78e4 100644
--- a/src/notebooks/notebookmanager.cpp
+++ b/src/notebooks/notebookmanager.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2012 Aurimas Cernius
+ * Copyright (C) 2010-2013 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -41,7 +41,7 @@ namespace gnote {
 
     NotebookManager::NotebookManager()
       : m_adding_notebook(false)
-      , m_active_notes(new ActiveNotesNotebook)
+      , m_active_notes(new ActiveNotesNotebook(Gnote::obj().default_note_manager()))
    { 
      m_notebooks = Gtk::ListStore::create(m_column_types);
 
@@ -58,15 +58,15 @@ namespace gnote {
      m_filteredNotebooks->set_visible_func(
        sigc::ptr_fun(&NotebookManager::filter_notebooks));
       
-     Notebook::Ptr allNotesNotebook(new AllNotesNotebook ());
+     Notebook::Ptr allNotesNotebook(new AllNotesNotebook(Gnote::obj().default_note_manager()));
      Gtk::TreeIter iter = m_notebooks->append ();
      iter->set_value(0, Notebook::Ptr(allNotesNotebook));
       
-     Notebook::Ptr unfiledNotesNotebook(new UnfiledNotesNotebook ());
+     Notebook::Ptr unfiledNotesNotebook(new UnfiledNotesNotebook(Gnote::obj().default_note_manager()));
      iter = m_notebooks->append ();
      iter->set_value(0, Notebook::Ptr(unfiledNotesNotebook));
 
-     Notebook::Ptr pinned_notes_notebook(new PinnedNotesNotebook);
+     Notebook::Ptr pinned_notes_notebook(new PinnedNotesNotebook(Gnote::obj().default_note_manager()));
      iter = m_notebooks->append();
      iter->set_value(0, pinned_notes_notebook);
 
@@ -126,7 +126,7 @@ namespace gnote {
         
         try {
           m_adding_notebook = true;
-          notebook = Notebook::Ptr(new Notebook (notebookName));
+          notebook = Notebook::Ptr(new Notebook(Gnote::obj().default_note_manager(), notebookName));
         } 
         catch(...)
         {
@@ -462,7 +462,7 @@ namespace gnote {
                                      + Notebook::NOTEBOOK_TAG_PREFIX)) {
           continue;
         }
-        Notebook::Ptr notebook(new Notebook (tag));
+        Notebook::Ptr notebook(new Notebook(Gnote::obj().default_note_manager(), tag));
         iter = m_notebooks->append ();
         iter->set_value(0, notebook);
         m_notebookMap [notebook->get_normalized_name()] = iter;
diff --git a/src/notebooks/notebookstreeview.cpp b/src/notebooks/notebookstreeview.cpp
index a065411..a6a32af 100644
--- a/src/notebooks/notebookstreeview.cpp
+++ b/src/notebooks/notebookstreeview.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2012 Aurimas Cernius
+ * Copyright (C) 2011-2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -25,7 +25,6 @@
 #include <gtkmm/targetentry.h>
 
 #include "debug.hpp"
-#include "gnote.hpp"
 #include "notebooks/notebook.hpp"
 #include "notebooks/notebookmanager.hpp"
 #include "notebooks/notebookstreeview.hpp"
@@ -34,9 +33,9 @@
 namespace gnote {
   namespace notebooks {
 
-    NotebooksTreeView::NotebooksTreeView(const Glib::RefPtr<Gtk::TreeModel> & model)
+    NotebooksTreeView::NotebooksTreeView(NoteManager & manager, const Glib::RefPtr<Gtk::TreeModel> & model)
       : Gtk::TreeView(model)
-      , m_note_manager(Gnote::obj().default_note_manager())
+      , m_note_manager(manager)
     {
       // Set up the notebooksTree as a drag target so that notes
       // can be dragged into the notebook.
diff --git a/src/notebooks/notebookstreeview.hpp b/src/notebooks/notebookstreeview.hpp
index 683d3ab..49dbde6 100644
--- a/src/notebooks/notebookstreeview.hpp
+++ b/src/notebooks/notebookstreeview.hpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -34,7 +35,7 @@ namespace gnote {
     : public Gtk::TreeView
   {
   public:
-    NotebooksTreeView(const Glib::RefPtr<Gtk::TreeModel> & model);
+    NotebooksTreeView(NoteManager & manager, const Glib::RefPtr<Gtk::TreeModel> & model);
 
   protected:
     virtual void on_drag_data_received( const Glib::RefPtr<Gdk::DragContext> & context,
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index afaf681..8a7fcfc 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2012 Aurimas Cernius
+ * Copyright (C) 2010-2013 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -88,15 +88,6 @@ namespace gnote {
   }
 
 
-  NoteManager::NoteManager(const std::string & directory, 
-                           const std::string & backup,
-                           const NoteChangedSlot & start_created)
-    : m_signal_start_note_created(start_created)
-  {
-    _common_init(directory, backup);
-  }
-
-
   void NoteManager::_common_init(const std::string & directory, const std::string & backup_directory)
   {
     m_addin_mgr = NULL;
@@ -185,9 +176,9 @@ namespace gnote {
     return new TrieController(*this);
   }
 
-  AddinManager *NoteManager::create_addin_manager() const
+  AddinManager *NoteManager::create_addin_manager()
   {
-    return new AddinManager(Gnote::conf_dir());
+    return new AddinManager(*this, Gnote::conf_dir());
   }
 
   // For overriding in test methods.
diff --git a/src/notemanager.hpp b/src/notemanager.hpp
index 840ec4e..bf590ce 100644
--- a/src/notemanager.hpp
+++ b/src/notemanager.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2012 Aurimas Cernius
+ * Copyright (C) 2010-2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -47,8 +47,6 @@ namespace gnote {
     
     NoteManager(const std::string & ,
                 const NoteChangedSlot & start_created = NoteChangedSlot() );
-    NoteManager(const std::string & directory, const std::string & backup,
-                const NoteChangedSlot & start_created = NoteChangedSlot());
     ~NoteManager();
 
     void on_setting_changed(const Glib::ustring & key);
@@ -113,7 +111,7 @@ namespace gnote {
 
   private:
     TrieController *create_trie_controller();
-    AddinManager *create_addin_manager() const;
+    AddinManager *create_addin_manager();
     bool directory_exists(const std::string & directory) const;
     bool create_directory(const std::string & directory) const;
     void on_note_rename(const Note::Ptr & note, const std::string & old_title);
diff --git a/src/preferencesdialog.cpp b/src/preferencesdialog.cpp
index 413aa4b..cdcef4b 100644
--- a/src/preferencesdialog.cpp
+++ b/src/preferencesdialog.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2012 Aurimas Cernius
+ * Copyright (C) 2010-2013 Aurimas Cernius
  * Copyright (C) 2009 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -85,7 +85,7 @@ namespace gnote {
   };
 
 
-  PreferencesDialog::PreferencesDialog(AddinManager & addinmanager)
+  PreferencesDialog::PreferencesDialog(NoteManager & note_manager)
     : Gtk::Dialog()
     , m_sync_addin_combo(NULL)
     , m_selected_sync_addin(NULL)
@@ -94,7 +94,8 @@ namespace gnote {
     , m_reset_sync_addin_button(NULL)
     , m_save_sync_addin_button(NULL)
     , m_rename_behavior_combo(NULL)
-    , m_addin_manager(addinmanager)
+    , m_addin_manager(note_manager.get_addin_manager())
+    , m_note_manager(note_manager)
   {
 //    set_icon(utils::get_icon("gnote"));
     set_border_width(5);
@@ -525,7 +526,7 @@ namespace gnote {
     // Populate the store with all the available SyncServiceAddins
     m_sync_addin_store = Gtk::ListStore::create(m_sync_addin_store_record);
     std::list<sync::SyncServiceAddin*> addins;
-    Gnote::obj().default_note_manager().get_addin_manager().get_sync_service_addins(addins);
+    m_addin_manager.get_sync_service_addins(addins);
     addins.sort(CompareSyncAddinsByName());
     for(std::list<sync::SyncServiceAddin*>::iterator addin = addins.begin(); addin != addins.end(); ++addin) {
       if((*addin)->initialized()) {
@@ -1032,8 +1033,7 @@ namespace gnote {
 
   void  PreferencesDialog::open_template_button_clicked()
   {
-    NoteManager &manager = Gnote::obj().default_note_manager();
-    Note::Ptr template_note = manager.get_or_create_template_note ();
+    Note::Ptr template_note = m_note_manager.get_or_create_template_note ();
 
     // Open the template note
     Gnote::obj().open_note(template_note);
diff --git a/src/preferencesdialog.hpp b/src/preferencesdialog.hpp
index b7f849f..cb8908c 100644
--- a/src/preferencesdialog.hpp
+++ b/src/preferencesdialog.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2012 Aurimas Cernius
+ * Copyright (C) 2011-2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -45,7 +45,7 @@ class PreferencesDialog
   : public Gtk::Dialog
 {
 public:
-  PreferencesDialog(AddinManager & addinmanager);
+  explicit PreferencesDialog(NoteManager & note_manager);
   
 
   Gtk::Widget *make_editing_pane();
@@ -119,6 +119,7 @@ private:
   Gtk::SpinButton *m_autosync_spinner;
   Gtk::ComboBoxText *m_rename_behavior_combo;
   AddinManager &m_addin_manager;
+  NoteManager & m_note_manager;
     
   Gtk::Button *font_button;
   Gtk::Label  *font_face;
diff --git a/src/searchnoteswidget.cpp b/src/searchnoteswidget.cpp
index ad246ca..0e8da72 100644
--- a/src/searchnoteswidget.cpp
+++ b/src/searchnoteswidget.cpp
@@ -351,7 +351,8 @@ void SearchNotesWidget::add_to_previous_searches(const std::string & text)
 Gtk::Widget *SearchNotesWidget::make_notebooks_pane()
 {
   m_notebooksTree = Gtk::manage(
-    new notebooks::NotebooksTreeView(notebooks::NotebookManager::instance()
+    new notebooks::NotebooksTreeView(m_manager,
+                                     notebooks::NotebookManager::instance()
                                        .get_notebooks_with_special_items()));
 
   m_notebooksTree->get_selection()->set_mode(Gtk::SELECTION_SINGLE);
diff --git a/src/synchronization/gnotesyncclient.cpp b/src/synchronization/gnotesyncclient.cpp
index 77db68a..f3f2c1a 100644
--- a/src/synchronization/gnotesyncclient.cpp
+++ b/src/synchronization/gnotesyncclient.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 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
@@ -38,7 +38,7 @@ namespace sync {
 
   const char * GnoteSyncClient::LOCAL_MANIFEST_FILE_NAME = "manifest.xml";
 
-  GnoteSyncClient::GnoteSyncClient()
+  GnoteSyncClient::GnoteSyncClient(NoteManager & manager)
   {
     m_local_manifest_file_path = Glib::build_filename(Gnote::conf_dir(), LOCAL_MANIFEST_FILE_NAME);
     // TODO: Why doesn't OnChanged ever get fired?!
@@ -51,7 +51,7 @@ namespace sync {
 
     parse(m_local_manifest_file_path);
 
-    Gnote::obj().default_note_manager().signal_note_deleted
+    manager.signal_note_deleted
       .connect(sigc::mem_fun(*this, &GnoteSyncClient::note_deleted_handler));
   }
 
diff --git a/src/synchronization/gnotesyncclient.hpp b/src/synchronization/gnotesyncclient.hpp
index f605785..5a9c6ba 100644
--- a/src/synchronization/gnotesyncclient.hpp
+++ b/src/synchronization/gnotesyncclient.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 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
@@ -31,7 +31,7 @@ namespace sync {
     : public SyncClient
   {
   public:
-    GnoteSyncClient();
+    GnoteSyncClient(NoteManager &);
 
     virtual sharp::DateTime last_sync_date()
       {
diff --git a/src/synchronization/syncdialog.cpp b/src/synchronization/syncdialog.cpp
index dd7b8c1..76b5ef8 100644
--- a/src/synchronization/syncdialog.cpp
+++ b/src/synchronization/syncdialog.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 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
@@ -263,13 +263,14 @@ private:
 
 
 
-SyncDialog::Ptr SyncDialog::create()
+SyncDialog::Ptr SyncDialog::create(NoteManager & m)
 {
-  return SyncDialog::Ptr(new SyncDialog);
+  return SyncDialog::Ptr(new SyncDialog(m));
 }
 
 
-SyncDialog::SyncDialog()
+SyncDialog::SyncDialog(NoteManager & manager)
+  : m_manager(manager)
 {
   m_obj = gnote_sync_dialog_new();
   g_signal_connect(m_obj, "sync-state-changed", G_CALLBACK(on_sync_state_changed), this);
@@ -466,7 +467,7 @@ void SyncDialog::on_row_activated(const Gtk::TreeModel::Path & path, Gtk::TreeVi
   std::string noteTitle;
   iter->get_value(0, noteTitle);
 
-  Note::Ptr note = Gnote::obj().default_note_manager().find(noteTitle);
+  Note::Ptr note = m_manager.find(noteTitle);
   if(note != 0) {
     present_note(note);
   }
@@ -770,11 +771,11 @@ void SyncDialog::rename_note(const Note::Ptr & note, const std::string & newTitl
   //Logger.Debug ("RenameNote: newCompleteContent: " + newCompleteContent);
 
   // We delete and recreate the note to simplify content conflict handling
-  Gnote::obj().default_note_manager().delete_note(note);
+  m_manager.delete_note(note);
 
   // Create note with old XmlContent just in case GetCompleteNoteXml failed
   DBG_OUT("RenameNote: about to create %s", newTitle.c_str());
-  Note::Ptr renamedNote = Gnote::obj().default_note_manager().create(newTitle, newContent);
+  Note::Ptr renamedNote = m_manager.create(newTitle, newContent);
   if(newCompleteContent != "") {// TODO: Anything to do if it is null?
     try {
       renamedNote->load_foreign_note_xml(newCompleteContent, OTHER_DATA_CHANGED);
diff --git a/src/synchronization/syncdialog.hpp b/src/synchronization/syncdialog.hpp
index 99290a2..c679d5a 100644
--- a/src/synchronization/syncdialog.hpp
+++ b/src/synchronization/syncdialog.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 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
@@ -41,7 +41,7 @@ namespace sync {
   public:
     typedef std::tr1::shared_ptr<SyncDialog> Ptr;
 
-    static Ptr create();
+    static Ptr create(NoteManager &);
 
     virtual ~SyncDialog();
 
@@ -63,7 +63,7 @@ namespace sync {
     static void on_sync_state_changed(GObject*, int, gpointer);
     static void on_note_conflict_detected(GObject*, gpointer, gpointer);
 
-    SyncDialog();
+    SyncDialog(NoteManager &);
     bool on_pulse_progress_bar();
     void on_row_activated(const Gtk::TreeModel::Path & path, Gtk::TreeViewColumn *column);
     void treeview_col1_data_func(Gtk::CellRenderer *renderer, const Gtk::TreeIter & iter);
@@ -72,6 +72,7 @@ namespace sync {
     void rename_note(const Note::Ptr & note, const std::string & newTitle, bool updateReferencingNotes);
     void present_note(const Note::Ptr &);
 
+    NoteManager & m_manager;
     Gtk::Image *m_image;
     Gtk::Label *m_header_label;
     Gtk::Label *m_message_label;
diff --git a/src/synchronization/syncmanager.cpp b/src/synchronization/syncmanager.cpp
index 5132045..234816c 100644
--- a/src/synchronization/syncmanager.cpp
+++ b/src/synchronization/syncmanager.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 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
@@ -110,33 +110,39 @@ namespace sync {
   }
 
 
+  SyncManager::SyncManager()
+    : m_note_manager(Gnote::obj().default_note_manager())
+  {
+  }
+
+
   SyncManager::~SyncManager()
   {
     g_object_unref(m_sync_helper);
   }
 
 
-  void SyncManager::init()
+  void SyncManager::init(NoteManager & m)
   {
-    SyncManager::obj()._init();
+    SyncManager::obj()._init(m);
   }
 
 
-  void SyncManager::_init()
+  void SyncManager::_init(NoteManager & manager)
   {
     m_sync_helper = sync_helper_new();
     g_signal_connect(m_sync_helper, "delete-notes", G_CALLBACK(SyncManager::on_delete_notes), NULL);
     g_signal_connect(m_sync_helper, "create-note", G_CALLBACK(SyncManager::on_create_note), NULL);
     g_signal_connect(m_sync_helper, "update-note", G_CALLBACK(SyncManager::on_update_note), NULL);
     g_signal_connect(m_sync_helper, "delete-note", G_CALLBACK(SyncManager::on_delete_note), NULL);
-    m_client = SyncClient::Ptr(new GnoteSyncClient);
+    m_client = SyncClient::Ptr(new GnoteSyncClient(manager));
     // Add a "Synchronize Notes" to Gnote's Application Menu
     ActionManager & am(ActionManager::obj());
     am.add_app_action("sync-notes");
     am.add_app_menu_item(ActionManager::APP_ACTION_MANAGE, 200, _("Synchronize Notes"), "app.sync-notes");
 
     // Initialize all the SyncServiceAddins
-    Gnote::obj().default_note_manager().get_addin_manager().initialize_sync_service_addins();
+    manager.get_addin_manager().initialize_sync_service_addins();
 
     Preferences::obj().get_schema_settings(Preferences::SCHEMA_SYNC)->signal_changed()
       .connect(sigc::mem_fun(*this, &SyncManager::preferences_setting_changed));
@@ -615,7 +621,7 @@ namespace sync {
     SyncServiceAddin *addin = NULL;
 
     std::list<SyncServiceAddin*> addins;
-    Gnote::obj().default_note_manager().get_addin_manager().get_sync_service_addins(addins);
+    m_note_manager.get_addin_manager().get_sync_service_addins(addins);
     for(std::list<SyncServiceAddin*>::iterator iter = addins.begin(); iter != addins.end(); ++iter) {
       if((*iter)->id() == sync_service_id) {
         addin = *iter;
@@ -682,7 +688,7 @@ namespace sync {
 
   NoteManager & SyncManager::note_mgr()
   {
-    return Gnote::obj().default_note_manager();
+    return m_note_manager;
   }
 
 
diff --git a/src/synchronization/syncmanager.hpp b/src/synchronization/syncmanager.hpp
index 2c60b4f..6dcafc2 100644
--- a/src/synchronization/syncmanager.hpp
+++ b/src/synchronization/syncmanager.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 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
@@ -63,8 +63,9 @@ namespace sync {
     : public base::Singleton<SyncManager>
   {
   public:
+    SyncManager();
     ~SyncManager();
-    static void init();
+    static void init(NoteManager &);
     void reset_client();
     void perform_synchronization(const std::tr1::shared_ptr<SyncUI> & sync_ui);
     void synchronization_thread();
@@ -75,7 +76,7 @@ namespace sync {
         return m_state;
       }
   private:
-    void _init();
+    void _init(NoteManager &);
     void handle_note_saved_or_deleted(const Note::Ptr & note);
     void handle_note_buffer_changed(const Note::Ptr & note);
     void preferences_setting_changed(const Glib::ustring & key);
@@ -97,6 +98,7 @@ namespace sync {
     static void on_delete_note(GObject*, gpointer, gpointer);
     static void note_save(const Note::Ptr & note);
 
+    NoteManager & m_note_manager;
     SyncUI::Ptr m_sync_ui;
     SyncClient::Ptr m_client;
     SyncState m_state;



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