[gnote] Make singleton classes extendable



commit 1c5011e544a31717c22405b02e9fd8281953a28d
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Tue Jan 15 22:50:37 2013 +0200

    Make singleton classes extendable
    
    Allow to create singleton interface and implement it.
    Create such interfaces for ActionManager, Gnote and TagManager.

 src/Makefile.am                                    |    3 +
 src/actionmanager.cpp                              |    8 +---
 src/actionmanager.hpp                              |   25 ++++-----
 src/addinmanager.cpp                               |    4 +-
 src/addins/backlinks/backlinkmenuitem.cpp          |    6 +-
 src/addins/bugzilla/bugzillanoteaddin.cpp          |   10 ++--
 src/addins/noteoftheday/noteoftheday.cpp           |    7 ++-
 .../noteoftheday/noteofthedaypreferences.cpp       |    4 +-
 src/base/singleton.hpp                             |   46 +++++++++++++---
 src/dbus/remotecontrol.cpp                         |   18 +++---
 src/gnote.cpp                                      |   54 +++++-------------
 src/gnote.hpp                                      |   28 +++-------
 src/iactionmanager.cpp                             |   34 ++++++++++++
 src/iactionmanager.hpp                             |   56 +++++++++++++++++++
 src/iconmanager.cpp                                |    6 ++-
 src/iconmanager.hpp                                |    4 +-
 src/ignote.cpp                                     |   58 ++++++++++++++++++++
 src/ignote.hpp                                     |   49 +++++++++++++++++
 src/itagmanager.cpp                                |   32 +++++++++++
 src/itagmanager.hpp                                |   50 +++++++++++++++++
 src/note.cpp                                       |   10 +++-
 src/note.hpp                                       |    4 +-
 src/notebooks/notebook.cpp                         |   12 ++--
 src/notebooks/notebookapplicationaddin.cpp         |    8 ++--
 src/notebooks/notebookmanager.cpp                  |   23 ++++----
 src/notebooks/notebookmanager.hpp                  |   15 +++---
 src/notebooks/notebooknewnotemenuitem.cpp          |    6 +-
 src/notebooks/notebooknoteaddin.cpp                |    4 +-
 src/notemanager.cpp                                |   20 ++++----
 src/noterenamedialog.cpp                           |    6 +-
 src/notewindow.cpp                                 |   11 ++--
 src/preferencesdialog.cpp                          |    7 ++-
 src/prefskeybinder.cpp                             |    8 ++--
 src/recentchanges.cpp                              |    4 +-
 src/search.cpp                                     |    6 +-
 src/searchnoteswidget.cpp                          |    4 +-
 src/synchronization/gnotesyncclient.cpp            |    4 +-
 src/synchronization/syncdialog.cpp                 |    4 +-
 src/synchronization/syncmanager.cpp                |   15 +++---
 src/synchronization/syncmanager.hpp                |    2 +-
 src/synchronization/syncutils.cpp                  |    6 ++-
 src/synchronization/syncutils.hpp                  |    4 +-
 src/tagmanager.cpp                                 |    7 +--
 src/tagmanager.hpp                                 |   22 +++-----
 src/tray.cpp                                       |   16 +++---
 src/watchers.cpp                                   |   12 ++--
 46 files changed, 511 insertions(+), 231 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 7e80ea1..1ea3309 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -106,8 +106,11 @@ libgnote_la_SOURCES = \
 	applicationaddin.cpp \
 	contrast.hpp contrast.cpp \
 	debug.hpp debug.cpp \
+	iactionmanager.hpp iactionmanager.cpp \
 	iconmanager.hpp iconmanager.cpp \
+	ignote.hpp ignote.cpp \
 	importaddin.hpp importaddin.cpp \
+	itagmanager.hpp itagmanager.cpp \
 	keybinder.hpp \
 	noteaddin.hpp noteaddin.cpp \
 	notebuffer.hpp notebuffer.cpp \
diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp
index d6ea701..c36b543 100644
--- a/src/actionmanager.cpp
+++ b/src/actionmanager.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
@@ -69,12 +69,6 @@
 
 namespace gnote {
 
-  const int ActionManager::APP_ACTION_NEW = 1;
-  const int ActionManager::APP_ACTION_MANAGE = 2;
-  const int ActionManager::APP_ACTION_HELP = 3;
-  const int ActionManager::APP_ACTION_LAST = 4;
-
-
   ActionManager::ActionManager()
     : m_ui(Gtk::UIManager::create())
     , m_main_window_actions(Gtk::ActionGroup::create("MainWindow"))
diff --git a/src/actionmanager.hpp b/src/actionmanager.hpp
index e2be923..4f67437 100644
--- a/src/actionmanager.hpp
+++ b/src/actionmanager.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -32,26 +32,21 @@
 #include <gtkmm/uimanager.h>
 #include <gdkmm/pixbuf.h>
 
-#include "base/singleton.hpp"
+#include "iactionmanager.hpp"
 
 namespace gnote {
 
 class ActionManager
-  : public base::Singleton<ActionManager>
+  : public IActionManager
 {
 public:
-  static const int APP_ACTION_NEW;
-  static const int APP_ACTION_MANAGE;
-  static const int APP_ACTION_HELP;
-  static const int APP_ACTION_LAST;
-
   ActionManager();
 
-  Glib::RefPtr<Gtk::Action> operator[](const std::string & n) const
+  virtual Glib::RefPtr<Gtk::Action> operator[](const std::string & n) const
     {
       return find_action_by_name(n);
     }
-  Gtk::Widget * get_widget(const std::string &n) const
+  virtual Gtk::Widget * get_widget(const std::string &n) const
     {
       return m_ui->get_widget(n);
     }
@@ -59,18 +54,18 @@ public:
   void get_placeholder_children(const std::string & p, std::list<Gtk::Widget*> & placeholders) const;
   void populate_action_groups();
   Glib::RefPtr<Gtk::Action> find_action_by_name(const std::string & n) const;
-  const Glib::RefPtr<Gtk::UIManager> & get_ui()
+  virtual const Glib::RefPtr<Gtk::UIManager> & get_ui()
     {
       return m_ui;
     }
-  Glib::RefPtr<Gio::SimpleAction> get_app_action(const std::string & name) const;
+  virtual Glib::RefPtr<Gio::SimpleAction> get_app_action(const std::string & name) const;
   const std::vector<Glib::RefPtr<Gio::SimpleAction> > & get_app_actions() const
     {
       return m_app_actions;
     }
-  void add_app_action(const std::string & name);
-  void add_app_menu_item(int section, int order, const std::string & label,
-                         const std::string & action_def);
+  virtual void add_app_action(const std::string & name);
+  virtual void add_app_menu_item(int section, int order, const std::string & label,
+                                 const std::string & action_def);
   Glib::RefPtr<Gio::Menu> get_app_menu() const;
 private:
   void make_app_actions();
diff --git a/src/addinmanager.cpp b/src/addinmanager.cpp
index 86d8598..5beee03 100644
--- a/src/addinmanager.cpp
+++ b/src/addinmanager.cpp
@@ -34,7 +34,7 @@
 #include "addinmanager.hpp"
 #include "addinpreferencefactory.hpp"
 #include "debug.hpp"
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "watchers.hpp"
 #include "notebooks/notebookapplicationaddin.hpp"
 #include "notebooks/notebooknoteaddin.hpp"
@@ -65,7 +65,7 @@ namespace gnote {
     const bool is_first_run
                  = !sharp::directory_exists(m_addins_prefs_dir);
     const std::string old_addins_dir
-                        = Glib::build_filename(Gnote::old_note_dir(),
+                        = Glib::build_filename(IGnote::old_note_dir(),
                                                "addins");
     const bool migration_needed
                  = is_first_run
diff --git a/src/addins/backlinks/backlinkmenuitem.cpp b/src/addins/backlinks/backlinkmenuitem.cpp
index e5cb010..3aa08f5 100644
--- a/src/addins/backlinks/backlinkmenuitem.cpp
+++ b/src/addins/backlinks/backlinkmenuitem.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -19,7 +19,7 @@
  */
 
 
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "iconmanager.hpp"
 #include "notewindow.hpp"
 
@@ -58,7 +58,7 @@ void BacklinkMenuItem::on_activate()
   
   gnote::NoteRecentChanges *window = gnote::NoteRecentChanges::get_owning(*this);
   if(!window) {
-    window = gnote::Gnote::obj().new_main_window();
+    window = gnote::IGnote::obj().new_main_window();
   }
 
   window->present_note(m_note);
diff --git a/src/addins/bugzilla/bugzillanoteaddin.cpp b/src/addins/bugzilla/bugzillanoteaddin.cpp
index 77dd718..5bf7b54 100644
--- a/src/addins/bugzilla/bugzillanoteaddin.cpp
+++ b/src/addins/bugzilla/bugzillanoteaddin.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010,2012 Aurimas Cernius
+ * Copyright (C) 2010,2012-2013 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -30,7 +30,7 @@
 #include "sharp/directory.hpp"
 
 #include "debug.hpp"
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "notebuffer.hpp"
 #include "notewindow.hpp"
 
@@ -83,7 +83,7 @@ namespace bugzilla {
     const bool is_first_run
                  = !sharp::directory_exists(images_dir());
     const std::string old_images_dir
-      = Glib::build_filename(gnote::Gnote::old_note_dir(),
+      = Glib::build_filename(gnote::IGnote::old_note_dir(),
                              "BugzillaIcons");
     const bool migration_needed
                  = is_first_run
@@ -98,7 +98,7 @@ namespace bugzilla {
 
   std::string BugzillaNoteAddin::images_dir()
   {
-    return Glib::build_filename(gnote::Gnote::conf_dir(),
+    return Glib::build_filename(gnote::IGnote::conf_dir(),
                                 "BugzillaIcons");
   }
 
@@ -116,7 +116,7 @@ namespace bugzilla {
     const Glib::RefPtr<Gio::File> src
       = Gio::File::create_for_path(old_images_dir);
     const Glib::RefPtr<Gio::File> dest
-      = Gio::File::create_for_path(gnote::Gnote::conf_dir());
+      = Gio::File::create_for_path(gnote::IGnote::conf_dir());
 
     try {
       sharp::directory_copy(src, dest);
diff --git a/src/addins/noteoftheday/noteoftheday.cpp b/src/addins/noteoftheday/noteoftheday.cpp
index 030cc3f..0ddf40d 100644
--- a/src/addins/noteoftheday/noteoftheday.cpp
+++ b/src/addins/noteoftheday/noteoftheday.cpp
@@ -1,7 +1,8 @@
 /*
  * gnote
  *
- * Copyright (C) 2009, 2010 Debarshi Ray
+ * Copyright (C) 2013 Aurimas Cernius
+ * Copyright (C) 2009-2010 Debarshi Ray
  *
  * 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 +24,7 @@
 #include "debug.hpp"
 #include "notemanager.hpp"
 #include "noteoftheday.hpp"
-#include "tagmanager.hpp"
+#include "itagmanager.hpp"
 #include "utils.hpp"
 
 namespace noteoftheday {
@@ -51,7 +52,7 @@ gnote::Note::Ptr NoteOfTheDay::create(gnote::NoteManager & manager,
   }
 
   // Automatically tag all new Note of the Day notes
-  notd->add_tag(gnote::TagManager::obj().get_or_create_system_tag(
+  notd->add_tag(gnote::ITagManager::obj().get_or_create_system_tag(
                                            "NoteOfTheDay"));
 
   return notd;
diff --git a/src/addins/noteoftheday/noteofthedaypreferences.cpp b/src/addins/noteoftheday/noteofthedaypreferences.cpp
index de1315a..ffe8a4b 100644
--- a/src/addins/noteoftheday/noteofthedaypreferences.cpp
+++ b/src/addins/noteoftheday/noteofthedaypreferences.cpp
@@ -21,7 +21,7 @@
 #include <glibmm/i18n.h>
 
 #include "debug.hpp"
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "note.hpp"
 #include "notemanager.hpp"
 #include "noteoftheday.hpp"
@@ -74,7 +74,7 @@ void NoteOfTheDayPreferences::open_template_button_clicked() const
   }
 
   if(0 != template_note) {
-    gnote::Gnote::obj().open_note(template_note);
+    gnote::IGnote::obj().open_note(template_note);
   }
 }
 
diff --git a/src/base/singleton.hpp b/src/base/singleton.hpp
index d38ce0c..3a6788d 100644
--- a/src/base/singleton.hpp
+++ b/src/base/singleton.hpp
@@ -1,3 +1,23 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2013 Aurimas Cernius
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 
 
 
@@ -5,20 +25,32 @@
 #define __BASE_SINGLETON_HPP__
 
 
-namespace base {
+#include <cstddef>
 
+namespace base {
 
-  template <class _Type>
-  class Singleton 
+  template <typename T>
+  class Singleton
   {
   public:
-    static _Type & obj()
+    static T & obj()
+      {
+        return obj(NULL);
+      }
+  protected:
+    Singleton()
+      {
+        obj(static_cast<T*>(this));
+      }
+  private:
+    static T & obj(T * inst)
       {
-        // TODO make this thread safe;
-        static _Type * instance = new _Type();
+        static T *instance = NULL;
+        if(inst) {
+          instance = inst;
+        }
         return *instance;
       }
-
   };
 
 }
diff --git a/src/dbus/remotecontrol.cpp b/src/dbus/remotecontrol.cpp
index 9dcf145..edfa2be 100644
--- a/src/dbus/remotecontrol.cpp
+++ b/src/dbus/remotecontrol.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
@@ -21,14 +21,14 @@
 #include "config.h"
 
 #include "debug.hpp"
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "notemanager.hpp"
 #include "notewindow.hpp"
 #include "recentchanges.hpp"
 #include "remotecontrolproxy.hpp"
 #include "search.hpp"
 #include "tag.hpp"
-#include "tagmanager.hpp"
+#include "itagmanager.hpp"
 #include "dbus/remotecontrol.hpp"
 #include "sharp/map.hpp"
 
@@ -61,7 +61,7 @@ namespace gnote {
     if (!note) {
       return false;
     }
-    Tag::Ptr tag = TagManager::obj().get_or_create_tag (tag_name);
+    Tag::Ptr tag = ITagManager::obj().get_or_create_tag(tag_name);
     note->add_tag (tag);
     return true;
   }
@@ -148,13 +148,13 @@ namespace gnote {
 
   void RemoteControl::DisplaySearch()
   {
-    Gnote::obj().open_search_all();
+    IGnote::obj().open_search_all();
   }
 
 
   void RemoteControl::DisplaySearchWithText(const std::string& search_text)
   {
-    NoteRecentChanges *recent_changes = Gnote::obj().get_main_window();
+    NoteRecentChanges *recent_changes = IGnote::obj().get_main_window();
     recent_changes->set_search_text(search_text);
     recent_changes->present();
   }
@@ -176,7 +176,7 @@ namespace gnote {
 
   std::vector< std::string > RemoteControl::GetAllNotesWithTag(const std::string& tag_name)
   {
-    Tag::Ptr tag = TagManager::obj().get_tag (tag_name);
+    Tag::Ptr tag = ITagManager::obj().get_tag(tag_name);
     if (!tag)
       return std::vector< std::string >();
 
@@ -306,7 +306,7 @@ bool RemoteControl::RemoveTagFromNote(const std::string& uri,
   Note::Ptr note = m_manager.find_by_uri (uri);
   if (!note)
     return false;
-  Tag::Ptr tag = TagManager::obj().get_tag (tag_name);
+  Tag::Ptr tag = ITagManager::obj().get_tag(tag_name);
   if (tag) {
     note->remove_tag (tag);
   }
@@ -409,7 +409,7 @@ void RemoteControl::on_note_saved(const Note::Ptr & note)
 
 void RemoteControl::present_note(const Note::Ptr & note)
 {
-    NoteRecentChanges *window = Gnote::obj().get_window_for_note();
+    NoteRecentChanges *window = IGnote::obj().get_window_for_note();
     window->present_note(note);
     window->present();
 }
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 30a4a1e..167a851 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -47,18 +47,18 @@
 #include "preferencesdialog.hpp"
 #include "remotecontrolproxy.hpp"
 #include "utils.hpp"
+#include "tagmanager.hpp"
 #include "xkeybinder.hpp"
 #include "dbus/remotecontrol.hpp"
 #include "dbus/remotecontrolclient.hpp"
 #include "sharp/streamreader.hpp"
 #include "sharp/files.hpp"
+#include "notebooks/notebookmanager.hpp"
 #include "synchronization/syncmanager.hpp"
 
 
 namespace gnote {
 
-  Gnote *Gnote::s_obj = NULL;
-
   Gnote::Gnote()
     : Gtk::Application("org.gnome.Gnote", Gio::APPLICATION_HANDLES_COMMAND_LINE)
     , m_manager(NULL)
@@ -144,10 +144,16 @@ namespace gnote {
   void Gnote::common_init()
   {
     std::string note_path = get_note_path(cmd_line.note_path());
+
+    //create singleton objects
+    new TagManager;
+    new Preferences;
     m_manager = new NoteManager(note_path, sigc::mem_fun(*this, &Gnote::start_note_created));
+    new notebooks::NotebookManager(default_note_manager());
     m_keybinder = new XKeybinder();
-    ActionManager::obj().load_interface();
+    (new ActionManager)->load_interface();
     sync::SyncManager::init(default_note_manager());
+
     setup_global_actions();
     m_manager->get_addin_manager().initialize_application_addins();
   }
@@ -155,7 +161,7 @@ namespace gnote {
 
   void Gnote::end_main(bool bus_acquired, bool name_acquired)
   {
-    ActionManager & am(ActionManager::obj());
+    IActionManager & am(IActionManager::obj());
     if((m_is_background = cmd_line.background())) {
       am["QuitGNoteAction"]->set_visible(false);
     }
@@ -292,7 +298,7 @@ namespace gnote {
 
   void Gnote::setup_global_actions()
   {
-    ActionManager & am(ActionManager::obj());
+    IActionManager & am(IActionManager::obj());
     am["QuitGNoteAction"]->signal_activate()
       .connect(sigc::mem_fun(*this, &Gnote::quit));
     am["ShowPreferencesAction"]->signal_activate().connect(
@@ -468,7 +474,7 @@ namespace gnote {
 
   void Gnote::make_app_actions()
   {
-    ActionManager & am(ActionManager::obj());
+    IActionManager & am(IActionManager::obj());
     am.get_app_action("new-note")->signal_activate().connect(sigc::mem_fun(*this, &Gnote::on_new_note_app_action));
     am.get_app_action("new-window")->signal_activate().connect(sigc::mem_fun(*this, &Gnote::on_new_window_action));
     am.get_app_action("show-preferences")->signal_activate().connect(
@@ -478,7 +484,7 @@ namespace gnote {
     am.get_app_action("about")->signal_activate().connect(sigc::mem_fun(*this, &Gnote::on_show_about_action));
     am.get_app_action("quit")->signal_activate().connect(sigc::mem_fun(*this, &Gnote::on_quit_gnote_action));
 
-    add_app_actions(am.get_app_actions());
+    add_app_actions(static_cast<ActionManager &>(am).get_app_actions());
   }
 
 
@@ -534,40 +540,10 @@ namespace gnote {
 
   void Gnote::make_app_menu()
   {
-    set_app_menu(ActionManager::obj().get_app_menu());
-  }
-
-
-  std::string Gnote::cache_dir()
-  {
-    return Glib::get_user_cache_dir() + "/gnote";
-  }
-
-
-  std::string Gnote::conf_dir()
-  {
-    return Glib::get_user_config_dir() + "/gnote";
+    set_app_menu(static_cast<ActionManager &>(IActionManager::obj()).get_app_menu());
   }
 
 
-  std::string Gnote::data_dir()
-  {
-    return Glib::get_user_data_dir() + "/gnote";
-  }
-
-
-  std::string Gnote::old_note_dir()
-  {
-    std::string home_dir = Glib::get_home_dir();
-
-    if (home_dir.empty())
-      home_dir = Glib::get_current_dir();
-
-    return home_dir + "/.gnote";
-  }
-
-
-
   GnoteCommandLine::GnoteCommandLine()
     : m_context(g_option_context_new("Foobar"))
     , m_use_panel(false)
@@ -675,7 +651,7 @@ namespace gnote {
       else {
         execute(remote);
       }
-      Gnote::obj().quit();
+      static_cast<Gnote&>(Gnote::obj()).quit();
     }
     return 0;
   }
diff --git a/src/gnote.hpp b/src/gnote.hpp
index 1d770f0..e09cf69 100644
--- a/src/gnote.hpp
+++ b/src/gnote.hpp
@@ -31,8 +31,8 @@
 #include <gtkmm/icontheme.h>
 #include <gtkmm/statusicon.h>
 
-#include "base/singleton.hpp"
 #include "actionmanager.hpp"
+#include "ignote.hpp"
 #include "keybinder.hpp"
 #include "recentchanges.hpp"
 #include "remotecontrolproxy.hpp"
@@ -100,16 +100,12 @@ private:
 
 class Gnote
   : public Gtk::Application
+  , public IGnote
 {
 public:
-  static Gnote& obj()
-    {
-      return *s_obj;
-    }
   static Glib::RefPtr<Gnote> create()
     {
-      s_obj = new Gnote;
-      return Glib::RefPtr<Gnote>(s_obj);
+      return Glib::RefPtr<Gnote>(new Gnote);
     }
 
   ~Gnote();
@@ -131,17 +127,12 @@ public:
   void on_show_preferences_action(const Glib::VariantBase&);
   void on_show_help_action(const Glib::VariantBase&);
   void on_show_about_action(const Glib::VariantBase&);
-  NoteRecentChanges *new_main_window();
-  NoteRecentChanges *get_main_window();
-  NoteRecentChanges *get_window_for_note();
-  void open_search_all();
+  virtual NoteRecentChanges *new_main_window();
+  virtual NoteRecentChanges *get_main_window();
+  virtual NoteRecentChanges *get_window_for_note();
+  virtual void open_search_all();
   void open_note_sync_window(const Glib::VariantBase&);
 
-  static std::string cache_dir();
-  static std::string conf_dir();
-  static std::string data_dir();
-  static std::string old_note_dir();
-
   bool tray_icon_showing()
     {
       return m_tray_icon && m_tray_icon->is_embedded() && m_tray_icon->get_visible();
@@ -158,16 +149,13 @@ public:
     {
       m_tray = tray;
     }
-  sigc::signal<void> signal_quit;
   static void register_remote_control(NoteManager & manager, RemoteControlProxy::slot_name_acquire_finish on_finish);
-  void open_note(const Note::Ptr & note);
+  virtual void open_note(const Note::Ptr & note);
 protected:
   virtual int on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> & command_line);
   virtual void on_startup();
   virtual void on_window_removed(Gtk::Window *window);
 private:
-  static Gnote *s_obj;
-
   Gnote();
   void start_note_created(const Note::Ptr & start_note);
   std::string get_note_path(const std::string & override_path);
diff --git a/src/iactionmanager.cpp b/src/iactionmanager.cpp
new file mode 100644
index 0000000..58ac2cb
--- /dev/null
+++ b/src/iactionmanager.cpp
@@ -0,0 +1,34 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "iactionmanager.hpp"
+
+namespace gnote {
+
+const int IActionManager::APP_ACTION_NEW = 1;
+const int IActionManager::APP_ACTION_MANAGE = 2;
+const int IActionManager::APP_ACTION_HELP = 3;
+const int IActionManager::APP_ACTION_LAST = 4;
+
+IActionManager::~IActionManager()
+{}
+
+}
+
diff --git a/src/iactionmanager.hpp b/src/iactionmanager.hpp
new file mode 100644
index 0000000..024d535
--- /dev/null
+++ b/src/iactionmanager.hpp
@@ -0,0 +1,56 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _IACTIONMANAGER_HPP_
+#define _IACTIONMANAGER_HPP_
+
+#include <giomm/simpleaction.h>
+#include <gtkmm/action.h>
+#include <gtkmm/uimanager.h>
+
+#include "base/singleton.hpp"
+
+namespace gnote {
+
+class IActionManager
+  : public base::Singleton<IActionManager>
+{
+public:
+  static const int APP_ACTION_NEW;
+  static const int APP_ACTION_MANAGE;
+  static const int APP_ACTION_HELP;
+  static const int APP_ACTION_LAST;
+
+  virtual ~IActionManager();
+
+  virtual Glib::RefPtr<Gtk::Action> operator[](const std::string & n) const = 0;
+
+  virtual Glib::RefPtr<Gio::SimpleAction> get_app_action(const std::string & name) const = 0;
+  virtual void add_app_action(const std::string & name) = 0;
+  virtual void add_app_menu_item(int section, int order, const std::string & label,
+                                 const std::string & action_def) = 0;
+  virtual const Glib::RefPtr<Gtk::UIManager> & get_ui() = 0;
+  virtual Gtk::Widget * get_widget(const std::string &n) const = 0;
+};
+
+}
+
+#endif
+
diff --git a/src/iconmanager.cpp b/src/iconmanager.cpp
index d6292e7..ec95864 100644
--- a/src/iconmanager.cpp
+++ b/src/iconmanager.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
@@ -40,6 +40,10 @@ const char *IconManager::PIN_ACTIVE = "pin-active";
 const char *IconManager::PIN_DOWN = "pin-down";
 const char *IconManager::PIN_UP = "pin-up";
 
+//instance
+IconManager IconManager::s_obj;
+
+
 Glib::RefPtr<Gdk::Pixbuf> IconManager::get_icon(const std::string & name, int size)
 {
   try {
diff --git a/src/iconmanager.hpp b/src/iconmanager.hpp
index 3ad9e54..e7a0104 100644
--- a/src/iconmanager.hpp
+++ b/src/iconmanager.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
@@ -51,6 +51,8 @@ private:
   typedef std::map<IconDef, Glib::RefPtr<Gdk::Pixbuf> > IconMap;
 
   IconMap m_icons;
+
+  static IconManager s_obj;
 };
 
 }
diff --git a/src/ignote.cpp b/src/ignote.cpp
new file mode 100644
index 0000000..a655219
--- /dev/null
+++ b/src/ignote.cpp
@@ -0,0 +1,58 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <glibmm/miscutils.h>
+
+#include "ignote.hpp"
+
+
+namespace gnote {
+
+IGnote::~IGnote()
+{}
+
+std::string IGnote::cache_dir()
+{
+  return Glib::get_user_cache_dir() + "/gnote";
+}
+
+std::string IGnote::conf_dir()
+{
+  return Glib::get_user_config_dir() + "/gnote";
+}
+
+std::string IGnote::data_dir()
+{
+  return Glib::get_user_data_dir() + "/gnote";
+}
+
+std::string IGnote::old_note_dir()
+{
+  std::string home_dir = Glib::get_home_dir();
+
+  if(home_dir.empty()) {
+    home_dir = Glib::get_current_dir();
+  }
+
+  return home_dir + "/.gnote";
+}
+
+}
+
diff --git a/src/ignote.hpp b/src/ignote.hpp
new file mode 100644
index 0000000..32f02e3
--- /dev/null
+++ b/src/ignote.hpp
@@ -0,0 +1,49 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _IGNOTE_HPP_
+#define _IGNOTE_HPP_
+
+#include "recentchanges.hpp"
+#include "base/singleton.hpp"
+
+namespace gnote {
+
+class IGnote
+  : public base::Singleton<IGnote>
+{
+public:
+  static std::string cache_dir();
+  static std::string conf_dir();
+  static std::string data_dir();
+  static std::string old_note_dir();
+
+  virtual ~IGnote();
+  virtual NoteRecentChanges *get_main_window() = 0;
+  virtual NoteRecentChanges *get_window_for_note() = 0; //TODO change to return reference
+  virtual NoteRecentChanges *new_main_window() = 0; //TODO change to return reference
+  virtual void open_note(const Note::Ptr & note) = 0;
+  virtual void open_search_all() = 0;
+
+  sigc::signal<void> signal_quit;
+};
+
+}
+
+#endif
diff --git a/src/itagmanager.cpp b/src/itagmanager.cpp
new file mode 100644
index 0000000..3473d49
--- /dev/null
+++ b/src/itagmanager.cpp
@@ -0,0 +1,32 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "itagmanager.hpp"
+
+namespace gnote {
+
+const char *ITagManager::TEMPLATE_NOTE_SYSTEM_TAG = "template";
+const char *ITagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG = "template:save-size";
+const char *ITagManager::TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG = "template:save-selection";
+const char *ITagManager::TEMPLATE_NOTE_SAVE_TITLE_SYSTEM_TAG = "template:save-title";
+
+ITagManager::~ITagManager()
+{}
+
+}
diff --git a/src/itagmanager.hpp b/src/itagmanager.hpp
new file mode 100644
index 0000000..12908a5
--- /dev/null
+++ b/src/itagmanager.hpp
@@ -0,0 +1,50 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _ITAGMANAGER_HPP_
+#define _ITAGMANAGER_HPP_
+
+#include "tag.hpp"
+#include "base/singleton.hpp"
+
+namespace gnote {
+
+class ITagManager
+  : public base::Singleton<ITagManager>
+{
+public:
+  static const char * TEMPLATE_NOTE_SYSTEM_TAG;
+  static const char * TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG;
+  static const char * TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG;
+  static const char * TEMPLATE_NOTE_SAVE_TITLE_SYSTEM_TAG;
+
+  virtual ~ITagManager();
+
+  virtual Tag::Ptr get_tag(const std::string & tag_name) const = 0;
+  virtual Tag::Ptr get_or_create_tag(const std::string &) = 0;
+  virtual Tag::Ptr get_system_tag(const std::string & tag_name) const = 0;
+  virtual Tag::Ptr get_or_create_system_tag(const std::string & name) = 0;
+  virtual void remove_tag(const Tag::Ptr & tag) = 0;
+  virtual void all_tags(std::list<Tag::Ptr> &) const = 0;
+};
+
+}
+
+#endif
+
diff --git a/src/note.cpp b/src/note.cpp
index c75fcff..80cba27 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -42,7 +42,7 @@
 #include "noterenamedialog.hpp"
 #include "notetag.hpp"
 #include "notewindow.hpp"
-#include "tagmanager.hpp"
+#include "itagmanager.hpp"
 #include "utils.hpp"
 #include "debug.hpp"
 #include "notebooks/notebookmanager.hpp"
@@ -872,7 +872,7 @@ namespace gnote {
             parse_tags (doc2->children, tag_strings);
             for(std::list<std::string>::const_iterator iter = tag_strings.begin();
                 iter != tag_strings.end(); ++iter) {
-              Tag::Ptr tag = TagManager::obj().get_or_create_tag(*iter);
+              Tag::Ptr tag = ITagManager::obj().get_or_create_tag(*iter);
               new_tags.push_back(tag);
             }
             xmlFreeDoc(doc2);
@@ -1114,6 +1114,10 @@ namespace gnote {
   const char *NoteArchiver::CURRENT_VERSION = "0.3";
 //  const char *NoteArchiver::DATE_TIME_FORMAT = "%Y-%m-%dT%T  7f@%z"; //"yyyy-MM-ddTHH:mm:ss.fffffffzzz";
 
+  //instance
+  NoteArchiver NoteArchiver::s_obj;
+
+
   NoteData *NoteArchiver::read(const std::string & read_file, const std::string & uri)
   {
     return obj().read_file(read_file, uri);
@@ -1202,7 +1206,7 @@ namespace gnote {
             Note::parse_tags(doc2->children, tag_strings);
             for(std::list<std::string>::const_iterator iter = tag_strings.begin();
                 iter != tag_strings.end(); ++iter) {
-              Tag::Ptr tag = TagManager::obj().get_or_create_tag(*iter);
+              Tag::Ptr tag = ITagManager::obj().get_or_create_tag(*iter);
               note->tags()[tag->normalized_name()] = tag;
             }
             xmlFreeDoc(doc2);
diff --git a/src/note.hpp b/src/note.hpp
index 81f0fe2..b515845 100644
--- a/src/note.hpp
+++ b/src/note.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
@@ -434,6 +434,8 @@ public:
 
 protected:
   NoteData *_read(sharp::XmlReader & xml, const std::string & uri, std::string & version);
+
+  static NoteArchiver s_obj;
 };
 
 namespace noteutils {
diff --git a/src/notebooks/notebook.cpp b/src/notebooks/notebook.cpp
index 11bf491..f536195 100644
--- a/src/notebooks/notebook.cpp
+++ b/src/notebooks/notebook.cpp
@@ -28,7 +28,7 @@
 #include "notemanager.hpp"
 #include "notebooks/notebook.hpp"
 #include "notebooks/notebookmanager.hpp"
-#include "tagmanager.hpp"
+#include "itagmanager.hpp"
 
 namespace gnote {
 namespace notebooks {
@@ -52,7 +52,7 @@ namespace notebooks {
     }
     else {
       set_name(name);
-      m_tag = TagManager::obj().get_or_create_system_tag (
+      m_tag = ITagManager::obj().get_or_create_system_tag(
         std::string(NOTEBOOK_TAG_PREFIX) + name);
     }
   }
@@ -108,8 +108,8 @@ namespace notebooks {
   Note::Ptr Notebook::find_template_note() const
   {
     Note::Ptr note;
-    Tag::Ptr template_tag = TagManager::obj().get_system_tag (TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
-    Tag::Ptr notebook_tag = TagManager::obj().get_system_tag (NOTEBOOK_TAG_PREFIX + get_name());
+    Tag::Ptr template_tag = ITagManager::obj().get_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+    Tag::Ptr notebook_tag = ITagManager::obj().get_system_tag(NOTEBOOK_TAG_PREFIX + get_name());
     if(!template_tag || !notebook_tag) {
       return note;
     }
@@ -143,13 +143,13 @@ namespace notebooks {
       buffer->select_note_body();
 
       // Flag this as a template note
-      Tag::Ptr template_tag = TagManager::obj().get_or_create_system_tag (TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+      Tag::Ptr template_tag = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
       note->add_tag (template_tag);
 
       // Add on the notebook system tag so Tomboy
       // will persist the tag/notebook across sessions
       // if no other notes are added to the notebook.
-      Tag::Ptr notebook_tag = TagManager::obj().get_or_create_system_tag (NOTEBOOK_TAG_PREFIX + get_name());
+      Tag::Ptr notebook_tag = ITagManager::obj().get_or_create_system_tag(NOTEBOOK_TAG_PREFIX + get_name());
       note->add_tag (notebook_tag);
         
       note->queue_save (CONTENT_CHANGED);
diff --git a/src/notebooks/notebookapplicationaddin.cpp b/src/notebooks/notebookapplicationaddin.cpp
index df7cc5a..da96e3b 100644
--- a/src/notebooks/notebookapplicationaddin.cpp
+++ b/src/notebooks/notebookapplicationaddin.cpp
@@ -36,7 +36,7 @@
 #include "notebooks/notebookmanager.hpp"
 #include "notebooks/notebooknewnotemenuitem.hpp"
 #include "notebooks/notebook.hpp"
-#include "actionmanager.hpp"
+#include "iactionmanager.hpp"
 #include "debug.hpp"
 #include "iconmanager.hpp"
 #include "notemanager.hpp"
@@ -75,7 +75,7 @@ namespace gnote {
                              _("Notebooks"),
                              _("Create a new note in a notebook")));
           
-      ActionManager & am(ActionManager::obj());
+      IActionManager & am(IActionManager::obj());
       m_notebookUi = am.get_ui()->add_ui_from_string (uixml);
       
       am.get_ui()->insert_action_group (m_actionGroup, 0);
@@ -125,7 +125,7 @@ namespace gnote {
       am.add_app_action("new-notebook");
       am.get_app_action("new-notebook")->signal_activate().connect(
         sigc::mem_fun(*this, &NotebookApplicationAddin::on_new_notebook_action));
-      am.add_app_menu_item(ActionManager::APP_ACTION_NEW, 300, _("New Note_book"), "app.new-notebook");
+      am.add_app_menu_item(IActionManager::APP_ACTION_NEW, 300, _("New Note_book"), "app.new-notebook");
         
       m_initialized = true;
     }
@@ -133,7 +133,7 @@ namespace gnote {
 
     void NotebookApplicationAddin::shutdown ()
     {
-      ActionManager & am(ActionManager::obj());
+      IActionManager & am(IActionManager::obj());
       try {
         am.get_ui()->remove_action_group(m_actionGroup);
       } 
diff --git a/src/notebooks/notebookmanager.cpp b/src/notebooks/notebookmanager.cpp
index f6ca292..94b6438 100644
--- a/src/notebooks/notebookmanager.cpp
+++ b/src/notebooks/notebookmanager.cpp
@@ -31,17 +31,18 @@
 #include "notebooks/createnotebookdialog.hpp"
 #include "notebooks/notebookmanager.hpp"
 #include "debug.hpp"
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "notemanager.hpp"
-#include "tagmanager.hpp"
+#include "itagmanager.hpp"
 
 
 namespace gnote {
   namespace notebooks {
 
-    NotebookManager::NotebookManager()
+    NotebookManager::NotebookManager(NoteManager & manager)
       : m_adding_notebook(false)
-      , m_active_notes(new ActiveNotesNotebook(Gnote::obj().default_note_manager()))
+      , m_active_notes(new ActiveNotesNotebook(manager))
+      , m_note_manager(manager)
    { 
      m_notebooks = Gtk::ListStore::create(m_column_types);
 
@@ -58,15 +59,15 @@ namespace gnote {
      m_filteredNotebooks->set_visible_func(
        sigc::ptr_fun(&NotebookManager::filter_notebooks));
       
-     Notebook::Ptr allNotesNotebook(new AllNotesNotebook(Gnote::obj().default_note_manager()));
+     Notebook::Ptr allNotesNotebook(new AllNotesNotebook(manager));
      Gtk::TreeIter iter = m_notebooks->append ();
      iter->set_value(0, Notebook::Ptr(allNotesNotebook));
       
-     Notebook::Ptr unfiledNotesNotebook(new UnfiledNotesNotebook(Gnote::obj().default_note_manager()));
+     Notebook::Ptr unfiledNotesNotebook(new UnfiledNotesNotebook(manager));
      iter = m_notebooks->append ();
      iter->set_value(0, Notebook::Ptr(unfiledNotesNotebook));
 
-     Notebook::Ptr pinned_notes_notebook(new PinnedNotesNotebook(Gnote::obj().default_note_manager()));
+     Notebook::Ptr pinned_notes_notebook(new PinnedNotesNotebook(manager));
      iter = m_notebooks->append();
      iter->set_value(0, pinned_notes_notebook);
 
@@ -126,7 +127,7 @@ namespace gnote {
         
         try {
           m_adding_notebook = true;
-          notebook = Notebook::Ptr(new Notebook(Gnote::obj().default_note_manager(), notebookName));
+          notebook = Notebook::Ptr(new Notebook(m_note_manager, notebookName));
         } 
         catch(...)
         {
@@ -365,7 +366,7 @@ namespace gnote {
 
       // Delete the template note
       if (templateNote) {
-        Gnote::obj().default_note_manager().delete_note(templateNote);
+        obj().note_manager().delete_note(templateNote);
       }
     }
 
@@ -449,7 +450,7 @@ namespace gnote {
     {
       Gtk::TreeIter iter;
       std::list<Tag::Ptr> tags;
-      TagManager::obj().all_tags(tags);
+      ITagManager::obj().all_tags(tags);
       for(std::list<Tag::Ptr>::const_iterator tag_iter = tags.begin();
           tag_iter != tags.end(); ++tag_iter) {
         
@@ -461,7 +462,7 @@ namespace gnote {
                                      + Notebook::NOTEBOOK_TAG_PREFIX)) {
           continue;
         }
-        Notebook::Ptr notebook(new Notebook(Gnote::obj().default_note_manager(), tag));
+        Notebook::Ptr notebook(new Notebook(m_note_manager, tag));
         iter = m_notebooks->append ();
         iter->set_value(0, notebook);
         m_notebookMap [notebook->get_normalized_name()] = iter;
diff --git a/src/notebooks/notebookmanager.hpp b/src/notebooks/notebookmanager.hpp
index 6b58c6c..a37e529 100644
--- a/src/notebooks/notebookmanager.hpp
+++ b/src/notebooks/notebookmanager.hpp
@@ -33,22 +33,24 @@
 #include "notebooks/notebook.hpp"
 #include "note.hpp"
 #include "tag.hpp"
+#include "base/singleton.hpp"
 
 namespace gnote {
   namespace notebooks {
 
 
 class NotebookManager
+  : public base::Singleton<NotebookManager>
 {
 public:
+  typedef sigc::signal<void, const Note &, const Notebook::Ptr &> NotebookEventHandler;
+
+  NotebookManager(NoteManager &);
 
-  static NotebookManager & obj()
+  NoteManager & note_manager() const
     {
-      static NotebookManager *s_instance = new NotebookManager();
-      return *s_instance;
+      return m_note_manager;
     }
-
-  typedef sigc::signal<void, const Note &, const Notebook::Ptr &> NotebookEventHandler;
   bool is_adding_notebook() const
     {
       return m_adding_notebook;
@@ -97,8 +99,6 @@ public:
 
   sigc::signal<void, const Note &, bool> signal_note_pin_status_changed;
 private:
-  NotebookManager();
-
   static int compare_notebooks_sort_func(const Gtk::TreeIter &, const Gtk::TreeIter &);
   void load_notebooks();
   bool filter_notebooks_to_display(const Gtk::TreeIter &);
@@ -128,6 +128,7 @@ private:
   NotebookEventHandler                 m_note_added_to_notebook;
   NotebookEventHandler                 m_note_removed_from_notebook;
   Notebook::Ptr                        m_active_notes;
+  NoteManager                        & m_note_manager;
 };
 
   }
diff --git a/src/notebooks/notebooknewnotemenuitem.cpp b/src/notebooks/notebooknewnotemenuitem.cpp
index b33564b..dd2bfcb 100644
--- a/src/notebooks/notebooknewnotemenuitem.cpp
+++ b/src/notebooks/notebooknewnotemenuitem.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010,2012 Aurimas Cernius
+ * Copyright (C) 2010,2012-2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -25,7 +25,7 @@
 #include <gtkmm/image.h>
 
 #include "sharp/string.hpp"
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "iconmanager.hpp"
 #include "note.hpp"
 #include "notemanager.hpp"
@@ -54,7 +54,7 @@ namespace gnote {
       
       // Look for the template note and create a new note
       Note::Ptr note = m_notebook->create_notebook_note ();
-      Gnote::obj().open_note(note);
+      IGnote::obj().open_note(note);
     }
 
 
diff --git a/src/notebooks/notebooknoteaddin.cpp b/src/notebooks/notebooknoteaddin.cpp
index 5cd53d8..56d83ce 100644
--- a/src/notebooks/notebooknoteaddin.cpp
+++ b/src/notebooks/notebooknoteaddin.cpp
@@ -29,7 +29,7 @@
 #include "debug.hpp"
 #include "iconmanager.hpp"
 #include "tag.hpp"
-#include "tagmanager.hpp"
+#include "itagmanager.hpp"
 #include "notewindow.hpp"
 #include "utils.hpp"
 
@@ -41,7 +41,7 @@ namespace notebooks {
   Tag::Ptr NotebookNoteAddin::get_template_tag()
   {
     if(!s_templateTag) {
-      s_templateTag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+      s_templateTag = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
     }
     return s_templateTag;
   }
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index 016cdfd..e4fed6d 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -39,8 +39,8 @@
 #include "notemanager.hpp"
 #include "notewindow.hpp"
 #include "addinmanager.hpp"
-#include "gnote.hpp"
-#include "tagmanager.hpp"
+#include "ignote.hpp"
+#include "itagmanager.hpp"
 #include "trie.hpp"
 #include "sharp/directory.hpp"
 #include "sharp/exception.hpp"
@@ -111,7 +111,7 @@ namespace gnote {
     bool is_first_run = first_run ();
     create_notes_dir ();
 
-    const std::string old_note_dir = Gnote::old_note_dir();
+    const std::string old_note_dir = IGnote::old_note_dir();
     const bool migration_needed
                  = is_first_run
                    && sharp::directory_exists(old_note_dir);
@@ -152,7 +152,7 @@ namespace gnote {
       load_notes ();
     }
 
-    Gnote::obj().signal_quit.connect(sigc::mem_fun(*this, &NoteManager::on_exiting_event));
+    IGnote::obj().signal_quit.connect(sigc::mem_fun(*this, &NoteManager::on_exiting_event));
   }
 
   NoteManager::~NoteManager()
@@ -178,7 +178,7 @@ namespace gnote {
 
   AddinManager *NoteManager::create_addin_manager()
   {
-    return new AddinManager(*this, Gnote::conf_dir());
+    return new AddinManager(*this, IGnote::conf_dir());
   }
 
   // For overriding in test methods.
@@ -579,7 +579,7 @@ namespace gnote {
   Note::Ptr NoteManager::find_template_note() const
   {
     Note::Ptr template_note;
-    Tag::Ptr template_tag = TagManager::obj().get_system_tag (TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+    Tag::Ptr template_tag = ITagManager::obj().get_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
     if(!template_tag) {
       return template_note;
     }
@@ -620,7 +620,7 @@ namespace gnote {
       buffer->select_note_body();
 
       // Flag this as a template note
-      Tag::Ptr template_tag = TagManager::obj().get_or_create_system_tag (TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+      Tag::Ptr template_tag = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
       template_note->add_tag(template_tag);
 
       template_note->queue_save(CONTENT_CHANGED);
@@ -717,7 +717,7 @@ namespace gnote {
   Note::Ptr NoteManager::create_note_from_template(const std::string & title, const Note::Ptr & template_note, const std::string & guid)
   {
     std::string new_title(title);
-    Tag::Ptr template_save_title = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SAVE_TITLE_SYSTEM_TAG);
+    Tag::Ptr template_save_title = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_TITLE_SYSTEM_TAG);
     if(template_note->contains_tag(template_save_title)) {
       new_title = get_unique_name(template_note->get_title(), m_notes.size());
     }
@@ -731,13 +731,13 @@ namespace gnote {
     Note::Ptr new_note = create_new_note(new_title, xml_content, guid);
 
     // Copy template note's properties
-    Tag::Ptr template_save_size = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG);
+    Tag::Ptr template_save_size = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG);
     if(template_note->data().has_extent() && template_note->contains_tag(template_save_size)) {
       new_note->data().height() = template_note->data().height();
       new_note->data().width() = template_note->data().width();
     }
 
-    Tag::Ptr template_save_selection = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG);
+    Tag::Ptr template_save_selection = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG);
     if(template_note->data().cursor_position() > 0 && template_note->contains_tag(template_save_selection)) {
       Glib::RefPtr<Gtk::TextBuffer> buffer = new_note->get_buffer();
       Gtk::TextIter iter;
diff --git a/src/noterenamedialog.cpp b/src/noterenamedialog.cpp
index 7be0589..f050982 100644
--- a/src/noterenamedialog.cpp
+++ b/src/noterenamedialog.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2012 Aurimas Cernius
+ * Copyright (C) 2011-2013 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  *
  * This program is free software: you can redistribute it and/or modify
@@ -28,7 +28,7 @@
 
 #include <glibmm/i18n.h>
 
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "notewindow.hpp"
 #include "noterenamedialog.hpp"
 #include "recentchanges.hpp"
@@ -367,7 +367,7 @@ void NoteRenameDialog::on_notes_view_row_activated(
     window = NoteRecentChanges::get_owning(*parent);
   }
   if(!window) {
-    window = Gnote::obj().new_main_window();
+    window = IGnote::obj().new_main_window();
   }
 
   window->present_note(note);
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index 9d3beb9..4d90cfc 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -44,8 +44,7 @@
 #include "undo.hpp"
 #include "recentchanges.hpp"
 #include "search.hpp"
-#include "actionmanager.hpp"
-#include "tagmanager.hpp"
+#include "itagmanager.hpp"
 #include "notebooks/notebookmanager.hpp"
 #include "sharp/exception.hpp"
 #include "sharp/string.hpp"
@@ -75,10 +74,10 @@ namespace gnote {
     , m_y(-1)
     , m_global_keys(NULL)
   {
-    m_template_tag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
-    m_template_save_size_tag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG);
-    m_template_save_selection_tag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG);
-    m_template_save_title_tag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SAVE_TITLE_SYSTEM_TAG);
+    m_template_tag = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+    m_template_save_size_tag = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG);
+    m_template_save_selection_tag = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG);
+    m_template_save_title_tag = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_TITLE_SYSTEM_TAG);
 
     m_text_menu = Gtk::manage(new NoteTextMenu(note.get_buffer(), note.get_buffer()->undoer()));
 
diff --git a/src/preferencesdialog.cpp b/src/preferencesdialog.cpp
index cdcef4b..a0f7893 100644
--- a/src/preferencesdialog.cpp
+++ b/src/preferencesdialog.cpp
@@ -44,10 +44,11 @@
 #include "sharp/modulemanager.hpp"
 #include "sharp/propertyeditor.hpp"
 #include "synchronization/syncserviceaddin.hpp"
+#include "iactionmanager.hpp"
 #include "addinmanager.hpp"
 #include "addinpreferencefactory.hpp"
 #include "debug.hpp"
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "notemanager.hpp"
 #include "notewindow.hpp"
 #include "preferencesdialog.hpp"
@@ -1036,7 +1037,7 @@ namespace gnote {
     Note::Ptr template_note = m_note_manager.get_or_create_template_note ();
 
     // Open the template note
-    Gnote::obj().open_note(template_note);
+    IGnote::obj().open_note(template_note);
   }
 
 
@@ -1296,7 +1297,7 @@ DBG_OUT("no addin");
 
       if(dialog_response == Gtk::RESPONSE_YES) {
         // TODO: Put this voodoo in a method somewhere
-        ActionManager::obj().get_app_action("sync-notes")->activate(Glib::VariantBase());
+        IActionManager::obj().get_app_action("sync-notes")->activate(Glib::VariantBase());
       }
     }
     else {
diff --git a/src/prefskeybinder.cpp b/src/prefskeybinder.cpp
index c329956..fe85549 100644
--- a/src/prefskeybinder.cpp
+++ b/src/prefskeybinder.cpp
@@ -21,7 +21,7 @@
 
 
 #include "debug.hpp"
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "keybinder.hpp"
 #include "note.hpp"
 #include "notemanager.hpp"
@@ -208,7 +208,7 @@ namespace gnote {
   {
     Note::Ptr note = m_manager.find_by_uri (m_manager.start_note_uri());
     if (note) {
-      Gnote::obj().open_note(note);
+      IGnote::obj().open_note(note);
     }
   }
 
@@ -217,7 +217,7 @@ namespace gnote {
   {
     try {
       Note::Ptr new_note = m_manager.create();
-      Gnote::obj().open_note(new_note);
+      IGnote::obj().open_note(new_note);
     } 
     catch (...) {
       // Fail silently.
@@ -239,7 +239,7 @@ namespace gnote {
 
   void GnotePrefsKeybinder::key_open_recent_changes()
   {
-    Gnote::obj().open_search_all();
+    IGnote::obj().open_search_all();
   }
 
 }
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index 6758278..85fde7d 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -29,7 +29,7 @@
 #include <gtkmm/stock.h>
 
 #include "debug.hpp"
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "iconmanager.hpp"
 #include "note.hpp"
 #include "notemanager.hpp"
@@ -159,7 +159,7 @@ namespace gnote {
 
   void NoteRecentChanges::on_open_note_new_window(const Note::Ptr & note)
   {
-    NoteRecentChanges *window = Gnote::obj().new_main_window();
+    NoteRecentChanges *window = IGnote::obj().new_main_window();
     window->present();
     window->present_note(note);
   }
diff --git a/src/search.cpp b/src/search.cpp
index d5864ad..38d73dd 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011 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
@@ -24,7 +24,7 @@
 #include "sharp/string.hpp"
 #include "notemanager.hpp"
 #include "search.hpp"
-#include "tagmanager.hpp"
+#include "itagmanager.hpp"
 #include "utils.hpp"
 
 namespace gnote {
@@ -53,7 +53,7 @@ namespace gnote {
     ResultsPtr temp_matches(new Results);
       
       // Skip over notes that are template notes
-    Tag::Ptr template_tag = TagManager::obj().get_or_create_system_tag (TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+    Tag::Ptr template_tag = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
 
     for(Note::List::const_iterator iter = m_manager.get_notes().begin();
         iter != m_manager.get_notes().end(); ++iter) {
diff --git a/src/searchnoteswidget.cpp b/src/searchnoteswidget.cpp
index 30e9812..0aa5a32 100644
--- a/src/searchnoteswidget.cpp
+++ b/src/searchnoteswidget.cpp
@@ -35,7 +35,7 @@
 #include "recenttreeview.hpp"
 #include "search.hpp"
 #include "searchnoteswidget.hpp"
-#include "tagmanager.hpp"
+#include "itagmanager.hpp"
 #include "notebooks/notebookmanager.hpp"
 #include "sharp/string.hpp"
 
@@ -745,7 +745,7 @@ bool SearchNotesWidget::filter_notes(const Gtk::TreeIter & iter)
   }
 
   // Don't show the template notes in the list
-  Tag::Ptr template_tag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+  Tag::Ptr template_tag = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
   if(note->contains_tag(template_tag)) {
     return false;
   }
diff --git a/src/synchronization/gnotesyncclient.cpp b/src/synchronization/gnotesyncclient.cpp
index f3f2c1a..e126f91 100644
--- a/src/synchronization/gnotesyncclient.cpp
+++ b/src/synchronization/gnotesyncclient.cpp
@@ -25,7 +25,7 @@
 #include <boost/lexical_cast.hpp>
 
 #include "debug.hpp"
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "gnotesyncclient.hpp"
 #include "notemanager.hpp"
 #include "sharp/files.hpp"
@@ -40,7 +40,7 @@ namespace sync {
 
   GnoteSyncClient::GnoteSyncClient(NoteManager & manager)
   {
-    m_local_manifest_file_path = Glib::build_filename(Gnote::conf_dir(), LOCAL_MANIFEST_FILE_NAME);
+    m_local_manifest_file_path = Glib::build_filename(IGnote::conf_dir(), LOCAL_MANIFEST_FILE_NAME);
     // TODO: Why doesn't OnChanged ever get fired?!
     Glib::RefPtr<Gio::File> manifest = Gio::File::create_for_path(m_local_manifest_file_path);
     if(manifest != 0) {
diff --git a/src/synchronization/syncdialog.cpp b/src/synchronization/syncdialog.cpp
index 9b81235..70578df 100644
--- a/src/synchronization/syncdialog.cpp
+++ b/src/synchronization/syncdialog.cpp
@@ -27,7 +27,7 @@
 #include <gtkmm/stock.h>
 #include <gtkmm/treeview.h>
 
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "iconmanager.hpp"
 #include "notemanager.hpp"
 #include "notewindow.hpp"
@@ -795,7 +795,7 @@ void SyncDialog::rename_note(const Note::Ptr & note, const std::string & newTitl
 
 void SyncDialog::present_note(const Note::Ptr & note)
 {
-  NoteRecentChanges *window = Gnote::obj().get_window_for_note();
+  NoteRecentChanges *window = IGnote::obj().get_window_for_note();
   window->present_note(note);
   window->present();
 }
diff --git a/src/synchronization/syncmanager.cpp b/src/synchronization/syncmanager.cpp
index 1af636a..fe45e2c 100644
--- a/src/synchronization/syncmanager.cpp
+++ b/src/synchronization/syncmanager.cpp
@@ -25,11 +25,11 @@
 #include <gtkmm/actiongroup.h>
 #include <sigc++/sigc++.h>
 
-#include "actionmanager.hpp"
+#include "iactionmanager.hpp"
 #include "addinmanager.hpp"
 #include "debug.hpp"
 #include "filesystemsyncserver.hpp"
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "gnotesyncclient.hpp"
 #include "notemanager.hpp"
 #include "preferences.hpp"
@@ -110,8 +110,8 @@ namespace sync {
   }
 
 
-  SyncManager::SyncManager()
-    : m_note_manager(Gnote::obj().default_note_manager())
+  SyncManager::SyncManager(NoteManager & m)
+    : m_note_manager(m)
   {
   }
 
@@ -124,6 +124,7 @@ namespace sync {
 
   void SyncManager::init(NoteManager & m)
   {
+    new SyncManager(m);
     SyncManager::obj()._init(m);
   }
 
@@ -137,9 +138,9 @@ namespace sync {
     g_signal_connect(m_sync_helper, "delete-note", G_CALLBACK(SyncManager::on_delete_note), NULL);
     m_client = SyncClient::Ptr(new GnoteSyncClient(manager));
     // Add a "Synchronize Notes" to Gnote's Application Menu
-    ActionManager & am(ActionManager::obj());
+    IActionManager & am(IActionManager::obj());
     am.add_app_action("sync-notes");
-    am.add_app_menu_item(ActionManager::APP_ACTION_MANAGE, 200, _("Synchronize Notes"), "app.sync-notes");
+    am.add_app_menu_item(IActionManager::APP_ACTION_MANAGE, 200, _("Synchronize Notes"), "app.sync-notes");
 
     // Initialize all the SyncServiceAddins
     manager.get_addin_manager().initialize_sync_service_addins();
@@ -484,7 +485,7 @@ namespace sync {
   {
     Glib::RefPtr<Gio::Settings> settings = Preferences::obj().get_schema_settings(Preferences::SCHEMA_SYNC);
     std::string sync_addin_id = settings->get_string(Preferences::SYNC_SELECTED_SERVICE_ADDIN);
-    ActionManager::obj().get_app_action("sync-notes")->set_enabled(sync_addin_id != "");
+    IActionManager::obj().get_app_action("sync-notes")->set_enabled(sync_addin_id != "");
 
     int timeoutPref = settings->get_int(Preferences::SYNC_AUTOSYNC_TIMEOUT);
     if(timeoutPref != m_autosync_timeout_pref_minutes) {
diff --git a/src/synchronization/syncmanager.hpp b/src/synchronization/syncmanager.hpp
index 6dcafc2..89d068c 100644
--- a/src/synchronization/syncmanager.hpp
+++ b/src/synchronization/syncmanager.hpp
@@ -63,7 +63,7 @@ namespace sync {
     : public base::Singleton<SyncManager>
   {
   public:
-    SyncManager();
+    SyncManager(NoteManager &);
     ~SyncManager();
     static void init(NoteManager &);
     void reset_client();
diff --git a/src/synchronization/syncutils.cpp b/src/synchronization/syncutils.cpp
index 1cf2c25..b6ee871 100644
--- a/src/synchronization/syncutils.cpp
+++ b/src/synchronization/syncutils.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
@@ -107,6 +107,10 @@ namespace sync {
 
   const char *SyncUtils::common_paths[] = {"/sbin", "/bin", "/usr/bin"};
 
+  //instance
+  SyncUtils SyncUtils::s_obj;
+
+
   bool SyncUtils::is_fuse_enabled()
   {
     try {
diff --git a/src/synchronization/syncutils.hpp b/src/synchronization/syncutils.hpp
index 232df7a..3b1f6bb 100644
--- a/src/synchronization/syncutils.hpp
+++ b/src/synchronization/syncutils.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
@@ -92,6 +92,8 @@ namespace sync {
     std::string find_first_executable_in_path(const std::string & executableName);
   private:
     static const char *common_paths[];
+    static SyncUtils s_obj;
+
     std::string m_guisu_tool;
     std::string m_modprobe_tool;
   };
diff --git a/src/tagmanager.cpp b/src/tagmanager.cpp
index 85b8f81..c8b2c0f 100644
--- a/src/tagmanager.cpp
+++ b/src/tagmanager.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
  *
@@ -33,11 +33,6 @@
 
 namespace gnote {
 
-  const char * TagManager::TEMPLATE_NOTE_SYSTEM_TAG = "template";
-  const char * TagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG = "template:save-size";
-  const char * TagManager::TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG = "template:save-selection";
-  const char * TagManager::TEMPLATE_NOTE_SAVE_TITLE_SYSTEM_TAG = "template:save-title";
-
   namespace {
     int compare_tags_sort_func (const Gtk::TreeIter & a, 
                                 const Gtk::TreeIter & b)
diff --git a/src/tagmanager.hpp b/src/tagmanager.hpp
index c71fcd3..8f1c92c 100644
--- a/src/tagmanager.hpp
+++ b/src/tagmanager.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
@@ -30,34 +31,29 @@
 #include <gtkmm/liststore.h>
 #include <gtkmm/treemodelsort.h>
 
-#include "base/singleton.hpp"
+#include "itagmanager.hpp"
 #include "tag.hpp"
 
 
 namespace gnote {
 
 class TagManager
-  : public  base::Singleton<TagManager>
+  : public ITagManager
 {
 public:
   TagManager();
 
-  static const char * TEMPLATE_NOTE_SYSTEM_TAG;
-  static const char * TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG;
-  static const char * TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG;
-  static const char * TEMPLATE_NOTE_SAVE_TITLE_SYSTEM_TAG;
-  Tag::Ptr get_tag (const std::string & tag_name) const;
-  Tag::Ptr get_or_create_tag(const std::string &);
-  Tag::Ptr get_system_tag (const std::string & tag_name) const;
-  Tag::Ptr get_or_create_system_tag(const std::string & name);
-  void remove_tag (const Tag::Ptr & tag);
+  virtual Tag::Ptr get_tag(const std::string & tag_name) const;
+  virtual Tag::Ptr get_or_create_tag(const std::string &);
+  virtual Tag::Ptr get_system_tag(const std::string & tag_name) const;
+  virtual Tag::Ptr get_or_create_system_tag(const std::string & name);
+  virtual void remove_tag(const Tag::Ptr & tag);
   Glib::RefPtr<Gtk::TreeModel> get_tags() const
     {
       return m_sorted_tags;
     }
-  void all_tags(std::list<Tag::Ptr>  &) const;
+  virtual void all_tags(std::list<Tag::Ptr> &) const;
 private:
-
   class ColumnRecord
     : public Gtk::TreeModelColumnRecord
   {
diff --git a/src/tray.cpp b/src/tray.cpp
index d450fd6..cd0e72d 100644
--- a/src/tray.cpp
+++ b/src/tray.cpp
@@ -37,13 +37,13 @@
 #include "actionmanager.hpp"
 #include "iconmanager.hpp"
 #include "utils.hpp"
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "note.hpp"
 #include "notemanager.hpp"
 #include "notewindow.hpp"
 #include "prefskeybinder.hpp"
 #include "tag.hpp"
-#include "tagmanager.hpp"
+#include "itagmanager.hpp"
 #include "preferences.hpp"
 #include "sharp/datetime.hpp"
 #include "sharp/string.hpp"
@@ -93,7 +93,7 @@ namespace gnote {
   {
     if(!m_inhibit_activate) {
       if(m_note) {
-        NoteRecentChanges *window = Gnote::obj().get_window_for_note();
+        NoteRecentChanges *window = IGnote::obj().get_window_for_note();
         window->present_note(m_note);
         window->present();
       }
@@ -209,7 +209,7 @@ namespace gnote {
   {
     Gtk::Menu *menu;
 
-    ActionManager & am(ActionManager::obj());
+    IActionManager & am(IActionManager::obj());
     
     menu = (Gtk::Menu*)am.get_widget("/TrayIconMenu");
     DBG_ASSERT(menu, "menu not found");
@@ -272,7 +272,7 @@ namespace gnote {
     remove_recently_changed_notes();
 
     // Assume menu opens downward, move common items to top of menu
-    ActionManager & am(ActionManager::obj());
+    ActionManager & am(static_cast<ActionManager &>(IActionManager::obj()));
     Gtk::MenuItem* newNoteItem = (Gtk::MenuItem*)am.get_widget(
       "/TrayIconMenu/TrayNewNotePlaceholder/TrayNewNote");
     Gtk::MenuItem* searchNotesItem = (Gtk::MenuItem*)am.get_widget(
@@ -304,8 +304,8 @@ namespace gnote {
     days_ago.add_days(-3);
 
     // Prevent template notes from appearing in the menu
-    Tag::Ptr template_tag = TagManager::obj()
-      .get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+    Tag::Ptr template_tag = ITagManager::obj()
+      .get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
 
     // List the most recently changed notes, any currently
     // opened notes, and any pinned notes...
@@ -403,7 +403,7 @@ namespace gnote {
     gtk_status_icon_set_tooltip_text(gobj(), 
                                      tray_util_get_tooltip_text().c_str());
 
-    Gnote::obj().signal_quit.connect(sigc::mem_fun(*this, &TrayIcon::on_exit));
+    IGnote::obj().signal_quit.connect(sigc::mem_fun(*this, &TrayIcon::on_exit));
     signal_activate().connect(sigc::mem_fun(*this, &TrayIcon::on_activate));
     signal_popup_menu().connect(sigc::mem_fun(*this, &TrayIcon::on_popup_menu));
   }
diff --git a/src/watchers.cpp b/src/watchers.cpp
index 249401b..5ac4ba9 100644
--- a/src/watchers.cpp
+++ b/src/watchers.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
  *
@@ -33,13 +33,13 @@
 
 #include "sharp/string.hpp"
 #include "debug.hpp"
-#include "gnote.hpp"
+#include "ignote.hpp"
 #include "noteeditor.hpp"
 #include "notemanager.hpp"
 #include "notewindow.hpp"
 #include "preferences.hpp"
 #include "recentchanges.hpp"
-#include "tagmanager.hpp"
+#include "itagmanager.hpp"
 #include "triehit.hpp"
 #include "watchers.hpp"
 
@@ -915,7 +915,7 @@ namespace gnote {
       DBG_OUT ("Opening note '%s' on click...", link_name.c_str());
       NoteRecentChanges *window = NoteRecentChanges::get_owning(const_cast<NoteEditor&>(editor));
       if(!window) {
-        window = Gnote::obj().new_main_window();
+        window = IGnote::obj().new_main_window();
       }
       window->present_note(link);
       window->present();
@@ -1265,10 +1265,10 @@ namespace gnote {
 
   void NoteTagsWatcher::on_tag_removed(const Note::Ptr&, const std::string& tag_name)
   {
-    Tag::Ptr tag = TagManager::obj().get_tag (tag_name);
+    Tag::Ptr tag = ITagManager::obj().get_tag(tag_name);
     DBG_OUT ("Watchers.OnTagRemoved popularity count: %d", tag ? tag->popularity() : 0);
     if (tag && tag->popularity() == 0) {
-      TagManager::obj().remove_tag (tag);
+      ITagManager::obj().remove_tag(tag);
     }
   }
 



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