[gnote] Add options to disable url and note autolinking



commit a0d8564da246568d79cb271b8c46a770d4603e7d
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat Oct 26 19:56:34 2013 +0300

    Add options to disable url and note autolinking
    
    Fixes Bug 633855.

 data/org.gnome.gnote.gschema.xml.in |   10 +++++
 src/addinmanager.cpp                |   69 +++++++++++++++++++++++++----------
 src/addinmanager.hpp                |    2 +
 src/preferences.cpp                 |    2 +
 src/preferences.hpp                 |    2 +
 5 files changed, 66 insertions(+), 19 deletions(-)
---
diff --git a/data/org.gnome.gnote.gschema.xml.in b/data/org.gnome.gnote.gschema.xml.in
index 0217e70..149c70b 100644
--- a/data/org.gnome.gnote.gschema.xml.in
+++ b/data/org.gnome.gnote.gschema.xml.in
@@ -5,6 +5,16 @@
       <_summary>Enable spellchecking</_summary>
       <_description>If true, misspellings will be underlined in red, and correct spelling suggestions shown 
in the right-click menu.</_description>
     </key>
+    <key name="enable-auto-links" type="b">
+      <default>true</default>
+      <_summary>Automatically create links when typing</_summary>
+      <_description>Enable this option to automatically create a link, when text matches note 
title.</_description>
+    </key>
+    <key name="enable-url-links" type="b">
+      <default>true</default>
+      <_summary>Create links for URLs in notes</_summary>
+      <_description>Enable this option to create links for URLs in notes.</_description>
+    </key>
     <key name="enable-wikiwords" type="b">
       <default>false</default>
       <_summary>Enable WikiWord highlighting</_summary>
diff --git a/src/addinmanager.cpp b/src/addinmanager.cpp
index 3ad0602..10c922b 100644
--- a/src/addinmanager.cpp
+++ b/src/addinmanager.cpp
@@ -56,6 +56,22 @@ namespace gnote {
   m_app_addins.insert(std::make_pair(typeid(klass).name(),        \
                                      klass::create()))
 
+#define SETUP_NOTE_ADDIN(key, KEY, klass) \
+{ \
+  if(key == KEY) { \
+    Glib::RefPtr<Gio::Settings> settings = Preferences::obj() \
+      .get_schema_settings(Preferences::SCHEMA_GNOTE); \
+    if(settings->get_boolean(key)) { \
+      sharp::IfaceFactoryBase *iface = new sharp::IfaceFactory<klass>; \
+      m_builtin_ifaces.push_back(iface); \
+      load_note_addin(typeid(klass).name(), iface); \
+    } \
+    else { \
+      erase_note_addin_info(typeid(klass).name()); \
+    } \
+  } \
+}
+
   AddinManager::AddinManager(NoteManager & note_manager, const std::string & conf_dir)
     : m_note_manager(note_manager)
     , m_gnote_conf_dir(conf_dir)
@@ -107,24 +123,26 @@ namespace gnote {
       return;
     }
 
-    m_note_addin_infos.insert(std::make_pair(id, f));
+    load_note_addin(id, f);
+  }
 
-    {
-      for(NoteAddinMap::iterator iter = m_note_addins.begin();
-          iter != m_note_addins.end(); ++iter) {
-        IdAddinMap & id_addin_map = iter->second;
-        IdAddinMap::const_iterator it = id_addin_map.find(id);
-        if (id_addin_map.end() != it) {
-          ERR_OUT(_("Note plugin %s already present"), id.c_str());
-          continue;
-        }
+  void AddinManager::load_note_addin(const std::string & id, sharp::IfaceFactoryBase *const f)
+  {
+    m_note_addin_infos.insert(std::make_pair(id, f));
+    for(NoteAddinMap::iterator iter = m_note_addins.begin();
+        iter != m_note_addins.end(); ++iter) {
+      IdAddinMap & id_addin_map = iter->second;
+      IdAddinMap::const_iterator it = id_addin_map.find(id);
+      if(id_addin_map.end() != it) {
+        ERR_OUT(_("Note plugin %s already present"), id.c_str());
+        continue;
+      }
 
-        const Note::Ptr & note = iter->first;
-        NoteAddin * const addin = dynamic_cast<NoteAddin *>((*f)());
-        if (addin) {
-         addin->initialize(note);
-         id_addin_map.insert(std::make_pair(id, addin));
-        }
+      const Note::Ptr & note = iter->first;
+      NoteAddin *const addin = dynamic_cast<NoteAddin *>((*f)());
+      if(addin) {
+       addin->initialize(note);
+       id_addin_map.insert(std::make_pair(id, addin));
       }
     }
   }
@@ -218,12 +236,19 @@ namespace gnote {
     if (!sharp::directory_exists (m_addins_prefs_dir))
       g_mkdir_with_parents(m_addins_prefs_dir.c_str(), S_IRWXU);
 
-    // get the factory
+    Glib::RefPtr<Gio::Settings> settings = Preferences::obj()
+      .get_schema_settings(Preferences::SCHEMA_GNOTE);
+    settings->signal_changed()
+      .connect(sigc::mem_fun(*this, &AddinManager::on_setting_changed));
 
     REGISTER_BUILTIN_NOTE_ADDIN(NoteRenameWatcher);
     REGISTER_BUILTIN_NOTE_ADDIN(NoteSpellChecker);
-    REGISTER_BUILTIN_NOTE_ADDIN(NoteUrlWatcher);
-    REGISTER_BUILTIN_NOTE_ADDIN(NoteLinkWatcher);
+    if(settings->get_boolean(Preferences::ENABLE_URL_LINKS)) {
+      REGISTER_BUILTIN_NOTE_ADDIN(NoteUrlWatcher);
+    }
+    if(settings->get_boolean(Preferences::ENABLE_AUTO_LINKS)) {
+      REGISTER_BUILTIN_NOTE_ADDIN(NoteLinkWatcher);
+    }
     REGISTER_BUILTIN_NOTE_ADDIN(NoteWikiWatcher);
     REGISTER_BUILTIN_NOTE_ADDIN(MouseHandWatcher);
     REGISTER_BUILTIN_NOTE_ADDIN(NoteTagsWatcher);
@@ -484,4 +509,10 @@ namespace gnote {
     }
     return NULL;
   }
+
+  void AddinManager::on_setting_changed(const Glib::ustring & key)
+  {
+    SETUP_NOTE_ADDIN(key, Preferences::ENABLE_URL_LINKS, NoteUrlWatcher);
+    SETUP_NOTE_ADDIN(key, Preferences::ENABLE_AUTO_LINKS, NoteLinkWatcher);
+  }
 }
diff --git a/src/addinmanager.hpp b/src/addinmanager.hpp
index fce604a..f15f49b 100644
--- a/src/addinmanager.hpp
+++ b/src/addinmanager.hpp
@@ -86,10 +86,12 @@ public:
 private:
   void load_addin_infos(const std::string & global_path, const std::string & local_path);
   void load_addin_infos(const std::string & path);
+  void load_note_addin(const std::string & id, sharp::IfaceFactoryBase *const f);
   void get_enabled_addins(std::list<std::string> & addins) const;
   void initialize_sharp_addins();
   void add_module_addins(const std::string & mod_id, sharp::DynamicModule * dmod);
   AddinInfo get_info_for_module(const std::string & module) const;
+  void on_setting_changed(const Glib::ustring & key);
     
   NoteManager & m_note_manager;
   const std::string m_gnote_conf_dir;
diff --git a/src/preferences.cpp b/src/preferences.cpp
index 67c97b3..2b02682 100644
--- a/src/preferences.cpp
+++ b/src/preferences.cpp
@@ -34,6 +34,8 @@ namespace gnote {
   const char * Preferences::SCHEMA_DESKTOP_GNOME_INTERFACE = "org.gnome.desktop.interface";
 
   const char * Preferences::ENABLE_SPELLCHECKING = "enable-spellchecking";
+  const char * Preferences::ENABLE_AUTO_LINKS = "enable-auto-links";
+  const char * Preferences::ENABLE_URL_LINKS = "enable-url-links";
   const char * Preferences::ENABLE_WIKIWORDS = "enable-wikiwords";
   const char * Preferences::ENABLE_CUSTOM_FONT = "enable-custom-font";
   const char * Preferences::ENABLE_KEYBINDINGS = "enable-keybindings";
diff --git a/src/preferences.hpp b/src/preferences.hpp
index a1abb2b..eca9843 100644
--- a/src/preferences.hpp
+++ b/src/preferences.hpp
@@ -44,6 +44,8 @@ namespace gnote {
     static const char *SCHEMA_DESKTOP_GNOME_INTERFACE;
 
     static const char *ENABLE_SPELLCHECKING;
+    static const char *ENABLE_AUTO_LINKS;
+    static const char *ENABLE_URL_LINKS;
     static const char *ENABLE_WIKIWORDS;
     static const char *ENABLE_CUSTOM_FONT;
     static const char *ENABLE_KEYBINDINGS;


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