[bijiben] ownCloud: do not create a file each time the note is renamed



commit 4ba220ff4523c4d491ca9351f24e16c1804a75ea
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Sun Sep 15 01:32:52 2013 +0200

    ownCloud: do not create a file each time the note is renamed
    
    We end up with a big mess. Rather wait some secs before
    creating a new file.

 src/libbiji/provider/biji-own-cloud-note.c |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/src/libbiji/provider/biji-own-cloud-note.c b/src/libbiji/provider/biji-own-cloud-note.c
index 39bdf18..438c78c 100644
--- a/src/libbiji/provider/biji-own-cloud-note.c
+++ b/src/libbiji/provider/biji-own-cloud-note.c
@@ -21,6 +21,7 @@
 #include "biji-item.h"
 #include "biji-own-cloud-note.h"
 #include "biji-own-cloud-provider.h"
+#include "../biji-timeout.h"
 #include "../serializer/biji-lazy-serializer.h"
 
 
@@ -30,6 +31,8 @@ struct BijiOwnCloudNotePrivate_
   BijiOwnCloudProvider *prov;
   BijiNoteID *id;
 
+  BijiTimeout           *timeout;
+
   gchar *html;
   GFile *location;
   gchar *basename;
@@ -125,6 +128,8 @@ on_content_replaced  (GObject *source_object,
 
 
 
+
+
 static void
 ocloud_note_save (BijiNoteObj *note)
 {
@@ -135,6 +140,7 @@ ocloud_note_save (BijiNoteObj *note)
   self = BIJI_OWN_CLOUD_NOTE (note);
   str = g_string_new (biji_note_obj_get_raw_text (note));
 
+
   /* backup would fail for some reason. 
    * gfilemove for workaround? */
   g_file_replace_contents_async  (
@@ -153,6 +159,12 @@ ocloud_note_save (BijiNoteObj *note)
 }
 
 
+
+
+
+
+
+
 /* Rename the file
  * when note title change
  * Also handle new notes being populated
@@ -184,8 +196,12 @@ create_new_file (BijiOwnCloudNote *self, const gchar *basename)
 }
 
 
-/* with current design, title might change
- * from user will or because note is edited */
+/* When the title is stable, handle io */
+static void
+on_timeout (BijiOwnCloudNote *self)
+{
+  create_new_file (self, self->priv->basename);
+}
 
 
 static void
@@ -206,7 +222,7 @@ on_title_change                     (BijiOwnCloudNote *self)
                        NULL,
                        NULL);
 
-  create_new_file (self, self->priv->basename);
+  biji_timeout_reset (self->priv->timeout, 3000);
 }
 
 
@@ -240,6 +256,7 @@ biji_own_cloud_note_finalize (GObject *object)
   self = BIJI_OWN_CLOUD_NOTE (object);
   g_free (self->priv->html);
   g_object_unref (self->priv->cancellable);
+  g_object_unref (self->priv->timeout);
   G_OBJECT_CLASS (biji_own_cloud_note_parent_class)->finalize (object);
 }
 
@@ -261,6 +278,10 @@ biji_own_cloud_note_init (BijiOwnCloudNote *self)
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, BIJI_TYPE_OWN_CLOUD_NOTE, BijiOwnCloudNotePrivate);
   self->priv->cancellable = g_cancellable_new ();
   self->priv->id = NULL;
+
+  self->priv->timeout = biji_timeout_new ();
+  g_signal_connect_swapped (self->priv->timeout, "timeout",
+                            G_CALLBACK (on_timeout), self);
 }
 
 


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