[gnote] Add disable support for note and improve reading



commit c7d83e509bf9fd502bd9fb330f0c8ab199bb30bb
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Wed Jan 25 23:54:57 2012 +0200

    Add disable support for note and improve reading
    
    * Add ability to disable note editing
    * Add ability to read note from specified file
    * Add ability to read note from XML

 src/note.cpp        |   51 ++++++++++++++++++++++++++++++++++++++++-----------
 src/note.hpp        |   15 ++++++++++++---
 src/notemanager.hpp |   12 +++++++++++-
 3 files changed, 63 insertions(+), 15 deletions(-)
---
diff --git a/src/note.cpp b/src/note.cpp
index 1e4a086..593d009 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2011 Aurimas Cernius
+ * Copyright (C) 2010-2012 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -277,6 +277,7 @@ namespace gnote {
     , m_filepath(filepath)
     , m_save_needed(false)
     , m_is_deleting(false)
+    , m_focus_widget(NULL)
     , m_manager(_manager)
     , m_window(NULL)
     , m_tag_table(NULL)
@@ -1031,6 +1032,7 @@ namespace gnote {
       m_window->signal_hide().connect(
         sigc::mem_fun(*this, &Note::on_window_hide));
 
+      m_window->editor()->set_sensitive(enabled());
       if (m_data.data().has_extent())
         m_window->set_default_size(m_data.data().width(),
                                    m_data.data().height());
@@ -1127,21 +1129,54 @@ namespace gnote {
     sharp::map_get_values(m_data.data().tags(), l);
   }
 
+  void Note::enabled(bool is_enabled)
+  {
+    m_enabled = is_enabled;
+    if(m_window) {
+      if(!m_enabled) {
+        m_focus_widget = m_window->get_focus();
+      }
+      m_window->set_sensitive(m_enabled);
+      if(m_enabled) {
+        m_window->set_focus(*m_focus_widget);
+      }
+    }
+  }
+
   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";
 
   NoteData *NoteArchiver::read(const std::string & read_file, const std::string & uri)
   {
-    return obj()._read(read_file, uri);
+    return obj().read_file(read_file, uri);
   }
 
 
-  NoteData *NoteArchiver::_read(const std::string & read_file, const std::string & uri)
+  NoteData *NoteArchiver::read_file(const std::string & file, const std::string & uri)
   {
-    NoteData *note = new NoteData(uri);
     std::string version;
+    sharp::XmlReader xml(file);
+    NoteData *data = _read(xml, uri, version);
+    if(version != NoteArchiver::CURRENT_VERSION) {
+      // Note has old format, so rewrite it.  No need
+      // to reread, since we are not adding anything.
+      DBG_OUT("Updating note XML from %s to newest format...", version.c_str());
+      NoteArchiver::write(file, *data);
+    }
+    return data;
+  }
 
-    sharp::XmlReader xml(read_file);
+
+  NoteData *NoteArchiver::read(sharp::XmlReader & xml, const std::string & uri)
+  {
+    std::string version; // discarded
+    return _read(xml, uri, version);
+  }
+
+
+  NoteData *NoteArchiver::_read(sharp::XmlReader & xml, const std::string & uri, std::string & version)
+  {
+    NoteData *note = new NoteData(uri);
 
     std::string name;
 
@@ -1219,12 +1254,6 @@ namespace gnote {
     }
     xml.close ();
 
-    if (version != NoteArchiver::CURRENT_VERSION) {
-      // Note has old format, so rewrite it.  No need
-      // to reread, since we are not adding anything.
-      DBG_OUT("Updating note XML from %s to newest format...", version.c_str());
-      NoteArchiver::write (read_file, *note);
-    }
     return note;
   }
 
diff --git a/src/note.hpp b/src/note.hpp
index 62480f9..e0569a3 100644
--- a/src/note.hpp
+++ b/src/note.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011 Aurimas Cernius
+ * Copyright (C) 2011-2012 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -343,6 +343,11 @@ public:
   bool is_open_on_startup() const;
   void set_is_open_on_startup(bool);
   void get_tags(std::list<Tag::Ptr> &) const;
+  bool enabled() const
+    {
+      return m_enabled;
+    }
+  void enabled(bool is_enabled);
 
   sigc::signal<void,Note&> & signal_opened()
     { return m_signal_opened; }
@@ -402,7 +407,9 @@ private:
   std::string                m_filepath;
   bool                       m_save_needed;
   bool                       m_is_deleting;
-  
+  bool                       m_enabled;
+
+  Gtk::Widget               *m_focus_widget;
   NoteManager               &m_manager;
   NoteWindow                *m_window;
   Glib::RefPtr<NoteBuffer>   m_buffer;
@@ -428,6 +435,8 @@ public:
   static NoteData *read(const std::string & read_file, const std::string & uri);
   static std::string write_string(const NoteData & data);
   static void write(const std::string & write_file, const NoteData & data);
+  NoteData *read_file(const std::string & file, const std::string & uri);
+  NoteData *read(sharp::XmlReader & xml, const std::string & uri);
   void write_file(const std::string & write_file, const NoteData & data);
   void write(sharp::XmlWriter & xml, const NoteData & note);
 
@@ -436,7 +445,7 @@ public:
   std::string get_title_from_note_xml(const std::string & noteXml) const;
 
 protected:
-  NoteData *_read(const std::string & read_file, const std::string & uri);
+  NoteData *_read(sharp::XmlReader & xml, const std::string & uri, std::string & version);
 };
 
 namespace noteutils {
diff --git a/src/notemanager.hpp b/src/notemanager.hpp
index efe6e85..839e718 100644
--- a/src/notemanager.hpp
+++ b/src/notemanager.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2011 Aurimas Cernius
+ * Copyright (C) 2010-2012 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -73,6 +73,14 @@ namespace gnote {
       { 
         return m_start_note_uri; 
       }
+    void read_only(bool ro)
+      {
+        m_read_only = ro;
+      }
+    bool read_only() const
+      {
+        return m_read_only;
+      }
     Note::Ptr find(const std::string &) const;
     Note::Ptr find_by_uri(const std::string &) const;
     static std::string sanitize_xml_content(const std::string & xml_content);
@@ -94,6 +102,7 @@ namespace gnote {
 
     ChangedHandler signal_note_deleted;
     ChangedHandler signal_note_added;
+    ChangedHandler signal_note_buffer_changed;
     /** this signal is emitted when the start note has been created
      *  This is supposed to happen once in a life time *sigh*
      *  This to avoid relying a the Gnote class for that.
@@ -134,6 +143,7 @@ namespace gnote {
     std::string m_default_note_template_title;
     std::string m_start_note_uri;
     NoteChangedSlot m_signal_start_note_created;
+    bool m_read_only;
   };
 
 



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