[gnote] Implement local manifest monitoring



commit 9fe81d635b8f72cadc7dd5973f14faaf43294218
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Sat Feb 25 19:54:41 2012 +0200

    Implement local manifest monitoring

 src/synchronization/gnotesyncclient.cpp |   21 ++++++++++++++-------
 src/synchronization/gnotesyncclient.hpp |    5 +++++
 2 files changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/src/synchronization/gnotesyncclient.cpp b/src/synchronization/gnotesyncclient.cpp
index a0f29ef..a846ec3 100644
--- a/src/synchronization/gnotesyncclient.cpp
+++ b/src/synchronization/gnotesyncclient.cpp
@@ -40,15 +40,15 @@ namespace sync {
 
   GnoteSyncClient::GnoteSyncClient()
   {
+    m_local_manifest_file_path = Glib::build_filename(Gnote::conf_dir(), LOCAL_MANIFEST_FILE_NAME);
     // TODO: Why doesn't OnChanged ever get fired?!
-#if 0
-    FileSystemWatcher w = new FileSystemWatcher ();
-    w.Path = Services.NativeApplication.ConfigurationDirectory;
-    w.Filter = localManifestFileName;
-    w.Changed += OnChanged;
-#endif
+    Glib::RefPtr<Gio::File> manifest = Gio::File::create_for_path(m_local_manifest_file_path);
+    if(manifest != 0) {
+      m_file_watcher = manifest->monitor_file();
+      m_file_watcher->signal_changed()
+        .connect(sigc::mem_fun(*this, &GnoteSyncClient::on_changed));
+    }
 
-    m_local_manifest_file_path = Glib::build_filename(Gnote::conf_dir(), LOCAL_MANIFEST_FILE_NAME);
     parse(m_local_manifest_file_path);
 
     Gnote::obj().default_note_manager().signal_note_deleted
@@ -65,6 +65,13 @@ namespace sync {
   }
 
 
+  void GnoteSyncClient::on_changed(const Glib::RefPtr<Gio::File>&, const Glib::RefPtr<Gio::File>&,
+                                   Gio::FileMonitorEvent)
+  {
+    parse(m_local_manifest_file_path);
+  }
+
+
   void GnoteSyncClient::parse(const std::string & manifest_path)
   {
     // Set defaults before parsing
diff --git a/src/synchronization/gnotesyncclient.hpp b/src/synchronization/gnotesyncclient.hpp
index 8db1775..878e5b1 100644
--- a/src/synchronization/gnotesyncclient.hpp
+++ b/src/synchronization/gnotesyncclient.hpp
@@ -18,6 +18,8 @@
  */
 
 
+#include <giomm/file.h>
+
 #include "syncmanager.hpp"
 
 
@@ -57,9 +59,12 @@ namespace sync {
     static const char *LOCAL_MANIFEST_FILE_NAME;
 
     void note_deleted_handler(const Note::Ptr &);
+    void on_changed(const Glib::RefPtr<Gio::File>&, const Glib::RefPtr<Gio::File>&,
+                    Gio::FileMonitorEvent);
     void parse(const std::string & manifest_path);
     void write(const std::string & manifest_path);
 
+    Glib::RefPtr<Gio::FileMonitor> m_file_watcher;
     sharp::DateTime m_last_sync_date;
     int m_last_sync_rev;
     std::string m_server_id;



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