[bijiben] NoteIconFile : rm cache icon file when note deleted



commit a2a1f621c93fb3df59f9943fc4538f5896ccb946
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Thu Dec 6 22:06:03 2012 +0100

    NoteIconFile : rm cache icon file when note deleted
    
    The notebook creates the cache dir. When note is deleted, icon file is deleted (not trashed).

 src/libbiji/biji-note-book.c                      |   10 +++++++
 src/libbiji/biji-note-obj.c                       |   30 ++++++++++++++++++---
 src/libbiji/biji-note-obj.h                       |    2 +-
 src/libbiji/deserializer/biji-lazy-deserializer.c |   15 ++--------
 src/libbiji/serializer/biji-lazy-serializer.c     |   24 ++--------------
 5 files changed, 43 insertions(+), 38 deletions(-)
---
diff --git a/src/libbiji/biji-note-book.c b/src/libbiji/biji-note-book.c
index 6ee2886..57fd061 100644
--- a/src/libbiji/biji-note-book.c
+++ b/src/libbiji/biji-note-book.c
@@ -360,9 +360,19 @@ static void
 biji_note_book_constructed (GObject *object)
 {
   BijiNoteBook *self = BIJI_NOTE_BOOK (object);
+  gchar *filename;
+  GFile *cache;
 
   G_OBJECT_CLASS (biji_note_book_parent_class)->constructed (object);
 
+  /* Ensure cache directory for icons */
+  filename = g_build_filename (g_get_user_cache_dir (),
+                               g_get_application_name (),
+                               NULL);
+  cache = g_file_new_for_path (filename);
+  g_file_make_directory (cache, NULL, NULL);
+  g_object_unref (cache);
+
   note_book_load_from_location (self);
 }
 
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index 62ba15e..4f42fe1 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -326,8 +326,8 @@ note_obj_are_same(BijiNoteObj *a, BijiNoteObj* b)
 gboolean
 biji_note_obj_trash (BijiNoteObj *note_to_kill)
 {
-  GFile *to_trash, *parent, *trash, *backup_file;
-  gchar *note_name, *parent_path, *trash_path, *backup_path;
+  GFile *to_trash, *parent, *trash, *backup_file, *icon;
+  gchar *note_name, *parent_path, *trash_path, *backup_path, *icon_path;
   GError *error = NULL;
   gboolean result = FALSE;
 
@@ -375,6 +375,14 @@ biji_note_obj_trash (BijiNoteObj *note_to_kill)
     g_object_unref (backup_file);
   }
 
+  /* Delete icon file */
+  icon_path = biji_note_obj_get_icon_file (note_to_kill);
+  icon = g_file_new_for_path (icon_path);
+  g_free (icon_path);
+  g_file_delete (icon, NULL, NULL);
+  g_object_unref (icon);
+
+  /* Tracker, NoteBook, Memory. TODO : zeitgeist */
   biji_note_delete_from_tracker (note_to_kill);
   g_signal_emit (G_OBJECT (note_to_kill), biji_obj_signals[NOTE_DELETED], 0);
   g_clear_object (&note_to_kill);
@@ -663,10 +671,24 @@ biji_note_obj_save_note (BijiNoteObj *self)
 }
 
 gchar *
-biji_note_obj_get_uuid (BijiNoteObj *note)
+biji_note_obj_get_icon_file (BijiNoteObj *note)
 {
   g_return_val_if_fail (BIJI_IS_NOTE_OBJ (note), NULL);
-  return biji_note_id_get_uuid (note->priv->id);
+
+  gchar *uuid, *basename, *filename;
+
+  uuid = biji_note_id_get_uuid (note->priv->id);
+  basename = biji_str_mass_replace (uuid, ".note", ".png", NULL);
+
+  filename = g_build_filename (g_get_user_cache_dir (),
+                               g_get_application_name (),
+                               basename,
+                               NULL);
+
+  g_free (uuid);
+  g_free (basename);
+
+  return filename;
 }
 
 void
diff --git a/src/libbiji/biji-note-obj.h b/src/libbiji/biji-note-obj.h
index e4932e2..e0d7d71 100644
--- a/src/libbiji/biji-note-obj.h
+++ b/src/libbiji/biji-note-obj.h
@@ -137,7 +137,7 @@ GdkPixbuf * biji_note_obj_get_icon (BijiNoteObj *note);
 
 void biji_note_obj_set_icon (BijiNoteObj *note, GdkPixbuf *pix);
 
-gchar *biji_note_obj_get_uuid (BijiNoteObj *note);
+gchar *biji_note_obj_get_icon_file (BijiNoteObj *note);
 
 gchar *biji_note_get_raw_text(BijiNoteObj *note);
 
diff --git a/src/libbiji/deserializer/biji-lazy-deserializer.c b/src/libbiji/deserializer/biji-lazy-deserializer.c
index d2228c3..6e687a9 100644
--- a/src/libbiji/deserializer/biji-lazy-deserializer.c
+++ b/src/libbiji/deserializer/biji-lazy-deserializer.c
@@ -704,22 +704,13 @@ biji_lazy_deserializer_new (BijiNoteObj *note)
 static void
 biji_note_obj_load_icon (BijiNoteObj *note)
 {
-  gchar *uuid, *basename, *filename;
+  gchar *filename;
   GdkPixbuf *retval;
   GError *error = NULL;
 
-  uuid = biji_note_obj_get_uuid (note);
-  basename = biji_str_mass_replace (uuid, ".note", ".png", NULL);
-
-  filename = g_build_filename (g_get_user_cache_dir (),
-                               g_get_application_name (),
-                               basename,
-                               NULL);
-
-  g_free (uuid);
-  g_free (basename);
-
+  filename = biji_note_obj_get_icon_file (note);
   retval = gdk_pixbuf_new_from_file (filename, &error);
+
   if (error)
   {
      g_warning ("%s", error->message);
diff --git a/src/libbiji/serializer/biji-lazy-serializer.c b/src/libbiji/serializer/biji-lazy-serializer.c
index ed6dd0a..80b0d71 100644
--- a/src/libbiji/serializer/biji-lazy-serializer.c
+++ b/src/libbiji/serializer/biji-lazy-serializer.c
@@ -416,30 +416,12 @@ biji_lazy_serialize_internal (BijiLazySerializer *self)
 static void
 biji_note_obj_save_icon (BijiNoteObj *note)
 {
-  gchar *uuid, *basename, *filename;
-  GFile *directory;
+  gchar *filename;
   GError *error = NULL;
-  GdkPixbuf *icon;
-
-  /* First ensure the dir exists */
-  filename = g_build_filename (g_get_user_cache_dir (),
-                               g_get_application_name (),
-                               NULL);
-  directory = g_file_new_for_path (filename);
-  g_file_make_directory (directory, NULL, NULL);
 
   /* Png */
-  uuid = biji_note_obj_get_uuid (note);
-  basename = biji_str_mass_replace (uuid, ".note", ".png", NULL);
-  icon = biji_note_obj_get_icon (note);
-  filename = g_build_filename (g_get_user_cache_dir (),
-                               g_get_application_name (),
-                               basename,
-                               NULL);
-  g_free (uuid);
-  g_free (basename);
-
-  gdk_pixbuf_save (icon, filename, "png", &error, NULL);
+  filename = biji_note_obj_get_icon_file (note);
+  gdk_pixbuf_save (biji_note_obj_get_icon (note), filename, "png", &error, NULL);
 
   if (error)
   {



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