[bijiben] ownCloud: adapt to new auto-rename behaviour



commit afd086ab60adb2ce9aab824bc93bb358e7549e50
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Sat Sep 14 23:11:26 2013 +0200

    ownCloud: adapt to new auto-rename behaviour
    
    ownCloud notes should delete old files and create new ones
    as their title change. TODO : destroy old thumbnails.

 src/libbiji/biji-note-obj.c                    |    2 +-
 src/libbiji/provider/biji-own-cloud-note.c     |   71 +++++++++++++-----------
 src/libbiji/provider/biji-own-cloud-provider.c |   27 ++++++++-
 src/libbiji/provider/biji-own-cloud-provider.h |    3 +
 4 files changed, 66 insertions(+), 37 deletions(-)
---
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index 94dba44..8c53b17 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -577,7 +577,7 @@ biji_note_obj_get_icon_file (BijiNoteObj *note)
   gchar *basename, *filename;
 
   uuid = BIJI_NOTE_OBJ_GET_CLASS (note)->get_basename (note);
-  basename = biji_str_mass_replace (uuid, ".note", ".png", NULL);
+  basename = biji_str_mass_replace (uuid, ".note", ".png", ".txt", ".png", NULL);
 
   filename = g_build_filename (g_get_user_cache_dir (),
                                g_get_application_name (),
diff --git a/src/libbiji/provider/biji-own-cloud-note.c b/src/libbiji/provider/biji-own-cloud-note.c
index 4bab13f..46e64be 100644
--- a/src/libbiji/provider/biji-own-cloud-note.c
+++ b/src/libbiji/provider/biji-own-cloud-note.c
@@ -20,6 +20,7 @@
 #include "biji-item.h"
 #include "biji-own-cloud-note.h"
 #include "biji-own-cloud-provider.h"
+#include "../serializer/biji-lazy-serializer.h"
 
 
 
@@ -68,14 +69,16 @@ ocloud_note_ensure_ressource (BijiNoteObj *note)
   BijiOwnCloudNote *ocnote;
   GFile *file;
   GFileInfo *file_info;
-  const BijiProviderInfo *prov_info;
+  const BijiProviderInfo *provider;
 
   g_return_if_fail (BIJI_IS_OWN_CLOUD_NOTE (note));
+  g_return_if_fail (G_IS_FILE (BIJI_OWN_CLOUD_NOTE (note)->priv->location));
+
   item = BIJI_ITEM (note);
   ocnote = BIJI_OWN_CLOUD_NOTE (note);
   file = ocnote->priv->location;
   file_info = g_file_query_info (file, "time::modified", G_FILE_QUERY_INFO_NONE, NULL, NULL);
-  prov_info = biji_provider_get_info (BIJI_PROVIDER (ocnote->priv->prov));
+  provider = biji_provider_get_info (BIJI_PROVIDER (ocnote->priv->prov));
 
   info = biji_info_set_new ();
   info->url = (gchar*) biji_item_get_uuid (item);
@@ -83,7 +86,7 @@ ocloud_note_ensure_ressource (BijiNoteObj *note)
   info->content = (gchar*) biji_note_obj_get_raw_text (note);
   info->mtime = g_file_info_get_attribute_uint64 (file_info, "time::modified");
   info->created = biji_note_obj_get_create_date (note);
-  info->datasource_urn = g_strdup (prov_info->datasource);
+  info->datasource_urn = g_strdup (provider->datasource);
 
   biji_tracker_ensure_ressource_from_info  (biji_item_get_book (item),
                                             info);
@@ -114,6 +117,7 @@ on_content_replaced  (GObject *source_object,
 
   else
   {
+    biji_note_obj_save_icon (user_data);
     ocloud_note_ensure_ressource (user_data);
   }
 }
@@ -150,66 +154,61 @@ ocloud_note_save (BijiNoteObj *note)
 
 /* Rename the file
  * when note title change
- * Also handle new notes being populated */
+ * Also handle new notes being populated
+ * the noteID still keep some path, which we will remove */
 
 static void
 create_new_file (BijiOwnCloudNote *self, const gchar *basename)
 {
   GFile *folder;
   BijiNoteObj *note;
+  gchar *key;
 
   note = BIJI_NOTE_OBJ (self);
   folder = biji_own_cloud_provider_get_folder (self->priv->prov);
 
+  /* TODO just free old location before, but check for no mistake */
+
   self->priv->location = g_file_get_child (folder, basename);
-  self->priv->basename = g_file_get_basename (self->priv->location);
+  key = g_strdup_printf (
+               "%s/%s",
+               biji_own_cloud_provider_get_readable_path (self->priv->prov),
+               basename);
+  g_object_set (self->priv->id, "path", key, NULL);
 
   ocloud_note_save (note);
   ocloud_note_ensure_ressource (note);
+
+  g_free (key);
 }
 
 
 /* with current design, title might change
  * from user will or because note is edited */
 
+
 static void
-on_title_change                     (gpointer    user_data)
+on_title_change                     (BijiOwnCloudNote *self)
 {
-  BijiOwnCloudNote *self;
-  gchar *old_title;
   const gchar *new_title;
 
+  g_return_if_fail (BIJI_IS_OWN_CLOUD_NOTE (self));
 
-  g_return_if_fail (BIJI_IS_OWN_CLOUD_NOTE (user_data));
-
-  self = BIJI_OWN_CLOUD_NOTE (user_data);
-  old_title = self->priv->basename;
+  g_free (self->priv->basename);
   new_title = biji_note_id_get_title (self->priv->id);
+  self->priv->basename = g_strdup_printf ("%s.txt", new_title);
 
 
-  if (old_title == NULL)
-  {
-    if (new_title != NULL)
-      create_new_file (self, new_title);
-  }
+  g_file_delete_async (self->priv->location,
+                       G_PRIORITY_LOW,
+                       NULL,
+                       NULL,
+                       NULL);
 
-  else if (g_strcmp0 (old_title, new_title) != 0)
-  {
-    g_file_delete_async (self->priv->location,
-                         G_PRIORITY_LOW,
-                         NULL,
-                         NULL,
-                         NULL);
-    // g_object_unref (self->priv->location);
-    // g_free (self->priv->basename);
-    create_new_file (self, new_title);
-  }
-  
+  create_new_file (self, self->priv->basename);
 }
 
 
-/* TODO : check if the title needs change
- * and adjust */
 
 static void
 on_content_change                   (gpointer    user_data)
@@ -220,7 +219,6 @@ on_content_change                   (gpointer    user_data)
   g_return_if_fail (BIJI_IS_OWN_CLOUD_NOTE (user_data));
 
   note = user_data;
-  biji_note_obj_set_title_survives (note, FALSE);
   html = html_from_plain_text ((gchar*) biji_note_obj_get_raw_text (user_data));
   ocloud_note_set_html (note, html);
   g_free (html);
@@ -328,9 +326,18 @@ BijiNoteObj        *biji_own_cloud_note_new_from_info           (BijiOwnCloudPro
                                                                  BijiInfoSet *info)
 {
   BijiNoteID *id;
+  gchar *sane_title;
   BijiNoteObj *retval;
   BijiOwnCloudNote *ocloud;
 
+  /* First, sanitize the title, assuming no other thread
+   * mess up with the InfoSet */
+  sane_title = biji_str_replace (info->title, ".txt", "");
+  g_free (info->title);
+  info->title = sane_title;
+
+  /* Now actually create the stuff */
+
   id = biji_note_id_new_from_info (info);
 
   retval = g_object_new (BIJI_TYPE_OWN_CLOUD_NOTE,
diff --git a/src/libbiji/provider/biji-own-cloud-provider.c b/src/libbiji/provider/biji-own-cloud-provider.c
index b45e019..1300a97 100644
--- a/src/libbiji/provider/biji-own-cloud-provider.c
+++ b/src/libbiji/provider/biji-own-cloud-provider.c
@@ -46,6 +46,13 @@ enum {
 
 static GParamSpec *properties[OCLOUD_PROV_PROP] = { NULL, };
 
+/*
+ * goa : object, account, providerInfo
+ * gio : volume, mount, path, folder. folder get_path would return something we don't want.
+ * data : notes
+ * startup: tracker, queue
+ * todo: monitor, cancel monitor
+ */
 
 struct BijiOwnCloudProviderPrivate_
 {
@@ -53,7 +60,6 @@ struct BijiOwnCloudProviderPrivate_
 
   GoaObject        *object;
   GoaAccount       *account;
-  gchar            *identifier;
 
   GHashTable       *notes;
   GHashTable       *tracker;
@@ -61,6 +67,7 @@ struct BijiOwnCloudProviderPrivate_
 
   GVolume          *volume;
   GMount           *mount;
+  gchar            *path;
   GFile            *folder;
 
   GFileMonitor     *monitor;
@@ -119,7 +126,9 @@ biji_own_cloud_provider_finalize (GObject *object)
   g_return_if_fail (BIJI_IS_OWN_CLOUD_PROVIDER (object));
   self = BIJI_OWN_CLOUD_PROVIDER (object);
 
-  g_free (self->priv->identifier);
+  if (self->priv->path != NULL)
+    g_free (self->priv->path);
+
   g_object_unref (self->priv->account);
   g_object_unref (self->priv->object);
   g_object_unref (self->priv->info.icon);
@@ -152,6 +161,7 @@ create_note_from_item (BijiOCloudItem *item)
   BijiNoteBook *book;
 
   book = biji_provider_get_book (BIJI_PROVIDER (item->self));
+
   note = biji_own_cloud_note_new_from_info (item->self,
                                             book,
                                             &item->set);
@@ -354,7 +364,7 @@ enumerate_next_files_ready_cb (GObject *source,
     g_file_info_get_modification_time (info, &time);
     item->set.mtime = time.tv_sec;
     item->set.created = g_file_info_get_attribute_uint64 (info, "time:created");
-    item->set.datasource_urn = g_strdup (self->priv->identifier);
+    item->set.datasource_urn = g_strdup (self->priv->info.datasource);
     item->file = g_file_new_for_uri (item->set.url);
     g_queue_push_head (self->priv->queue, item);
   }
@@ -511,7 +521,7 @@ handle_mount (BijiOwnCloudProvider *self)
     g_object_unref (root);
     biji_tracker_ensure_datasource (
       biji_provider_get_book (BIJI_PROVIDER (self)),
-      self->priv->identifier,
+      self->priv->info.datasource,
       MINER_ID,
       mine_notes,
       self);
@@ -567,6 +577,7 @@ get_mount (BijiOwnCloudProvider *self)
   if (GOA_IS_FILES (files))
   {
     uri = goa_files_get_uri  (files);
+    self->priv->path = g_strdup_printf ("%sNotes", uri);
     self->priv->volume = g_volume_monitor_get_volume_for_uuid (monitor, uri);
     self->priv->mount = g_volume_get_mount (self->priv->volume);
 
@@ -655,6 +666,7 @@ biji_own_cloud_provider_init (BijiOwnCloudProvider *self)
   self->priv->notes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
   self->priv->tracker = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
   self->priv->queue = g_queue_new ();
+  self->priv->path = NULL;
 }
 
 
@@ -781,3 +793,10 @@ biji_own_cloud_provider_new (BijiNoteBook *book,
                        "goa", object,
                        NULL);
 }
+
+
+gchar *
+biji_own_cloud_provider_get_readable_path (BijiOwnCloudProvider *p)
+{
+  return p->priv->path;
+}
diff --git a/src/libbiji/provider/biji-own-cloud-provider.h b/src/libbiji/provider/biji-own-cloud-provider.h
index 61f234f..5a1d7f6 100644
--- a/src/libbiji/provider/biji-own-cloud-provider.h
+++ b/src/libbiji/provider/biji-own-cloud-provider.h
@@ -59,6 +59,9 @@ BijiProvider     *biji_own_cloud_provider_new           (BijiNoteBook *book,
 GFile            *biji_own_cloud_provider_get_folder    (BijiOwnCloudProvider *provider);
 
 
+gchar            *biji_own_cloud_provider_get_readable_path (BijiOwnCloudProvider *p);
+
+
 G_END_DECLS
 
 #endif /* BIJI_OWN_CLOUD_PROVIDER_H_ */


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