[bijiben] trash: initial restore feature



commit 198c533205e8a7f952ee3181816f8c961f9e3fb6
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Mon Dec 9 22:43:00 2013 +0100

    trash: initial restore feature
    
    The file is moved. Signal, model and view update is to be done.

 src/bjb-trash-bar.c           |    5 ++++-
 src/libbiji/biji-local-note.c |   38 +++++++++++++++++++++++++++++++++++---
 2 files changed, 39 insertions(+), 4 deletions(-)
---
diff --git a/src/bjb-trash-bar.c b/src/bjb-trash-bar.c
index 3b54606..7a6300e 100644
--- a/src/bjb-trash-bar.c
+++ b/src/bjb-trash-bar.c
@@ -77,9 +77,12 @@ on_empty_clicked_callback        (BjbTrashBar *self)
 static void
 on_restore_clicked_callback      (BjbTrashBar *self)
 {
-  GList *selection;
+  GList *selection, *l;
 
   selection = bjb_main_view_get_selected_items (self->priv->view);
+  for (l=selection; l!=NULL; l=l->next)
+    biji_item_restore (BIJI_ITEM (l->data));
+
   g_list_free (selection);
 }
 
diff --git a/src/libbiji/biji-local-note.c b/src/libbiji/biji-local-note.c
index e9e90aa..2393930 100644
--- a/src/libbiji/biji-local-note.c
+++ b/src/libbiji/biji-local-note.c
@@ -191,7 +191,7 @@ local_note_archive (BijiNoteObj *note)
   g_object_unref (parent);
   g_free (trash_path);
   g_object_unref (trash);
-  g_free (backup_path);  
+  g_free (backup_path);
   g_object_unref (archive);
 
   return result;
@@ -202,13 +202,45 @@ static gboolean
 local_note_restore (BijiItem *item)
 {
   BijiLocalNote *self;
+  gchar *root_path, *path;
+  GFile *trash, *root, *target;
+  gboolean retval;
+  GError *error;
+
 
   g_return_val_if_fail (BIJI_IS_LOCAL_NOTE (item), FALSE);
   self = BIJI_LOCAL_NOTE (item);
+  error = NULL;
 
-  g_warning ("local note restore");
+  trash = g_file_get_parent (self->priv->location);
+  root = g_file_get_parent (trash);
 
-  return FALSE;
+  root_path = g_file_get_path (root);
+  path = g_build_filename (root_path, self->priv->basename, NULL);
+  target = g_file_new_for_path (path);
+
+  retval = g_file_move (self->priv->location,
+                        target,
+                        G_FILE_COPY_NONE,
+                        NULL, // cancellable
+                        NULL, // progress callback
+                        NULL, // progress_callback_data,
+                        &error);
+
+  if (error != NULL)
+  {
+    g_warning ("Could not restore file : %s", error->message);
+    g_error_free (error);
+  }
+
+  g_object_unref (self->priv->location);
+  g_object_unref (trash);
+  g_object_unref (root);
+  g_free (path);
+  g_free (root_path);
+
+  self->priv->location = target;
+  return retval;
 }
 
 


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