Commit f3e9f67c authored by Pierre-Yves LUYTEN's avatar Pierre-Yves LUYTEN

Trash note rather than hard delete

parent 83b8e741
......@@ -431,7 +431,7 @@ _note_book_remove_one_note(BijiNoteBook *book,BijiNoteObj *note)
/* Ref note first, hash_table won't finalize it & we can delete it*/
g_object_ref (to_delete);
g_hash_table_remove (book->priv->notes, biji_note_obj_get_path (note));
biji_note_obj_delete (note);
biji_note_obj_trash (note);
g_signal_emit ( G_OBJECT (book), biji_book_signals[BOOK_AMENDED],0);
return TRUE;
}
......
......@@ -15,8 +15,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtk/gtk.h>
#include "biji-note-id.h"
/* Properties */
......@@ -149,6 +147,12 @@ biji_note_id_get_uuid (BijiNoteID *n)
return g_file_get_basename (n->priv->location);
}
GFile *
biji_note_id_get_file (BijiNoteID *note)
{
return note->priv->location;
}
void
biji_note_id_set_title (BijiNoteID *n, gchar* title)
{
......
......@@ -20,6 +20,7 @@
#define _BIJI_NOTE_ID_H_
#include <glib-object.h>
#include <gtk/gtk.h>
G_BEGIN_DECLS
......@@ -54,6 +55,8 @@ gchar * biji_note_id_get_path (BijiNoteID *note);
gchar * biji_note_id_get_uuid (BijiNoteID *note);
GFile * biji_note_id_get_file (BijiNoteID *note);
void biji_note_id_set_title (BijiNoteID* n,gchar* title);
gchar* biji_note_id_get_title (BijiNoteID* n);
......
......@@ -315,30 +315,60 @@ note_obj_are_same(BijiNoteObj *a, BijiNoteObj* b)
return FALSE ;
}
/* First cancel timeout */
void
biji_note_obj_delete(BijiNoteObj *dead)
{
GFile *file ;
// GError *error = NULL ;
biji_timeout_cancel (dead->priv->timeout);
file = g_file_new_for_path(biji_note_id_get_path(dead->priv->id));
// TODO get the note book GCancellable and set it,
// or create one and append it to BijiNoteBook
if ( g_file_trash(file,NULL,NULL) == FALSE )
{
if ( g_file_delete(file,NULL,NULL) == FALSE )
/* First cancel timeout
* this func is most probably stupid it might exists (move file) */
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;
GError *error = NULL;
gboolean result;
biji_timeout_cancel (note_to_kill->priv->timeout);
to_trash = biji_note_id_get_file (note_to_kill->priv->id);
note_name = g_file_get_basename (to_trash);
parent = g_file_get_parent (to_trash);
/* Create the trash directory
* No matter if already exists */
parent_path = g_file_get_path (parent);
trash_path = g_build_filename (parent_path, ".Trash", NULL);
g_free (parent_path);
g_object_unref (parent);
trash = g_file_new_for_path (trash_path);
g_file_make_directory (trash, NULL, NULL);
/* Move the note to trash */
backup_path = g_build_filename (trash_path, note_name, NULL);
g_free (trash_path);
backup_file = g_file_new_for_path (backup_path);
g_free (note_name);
g_free (backup_path);
result = g_file_move (to_trash,
backup_file,
G_FILE_COPY_NONE,
NULL, // cancellable
NULL, // progress callback
NULL, // progress_callback_data,
&error);
if (error)
{
g_message("Critical, file not deleted:%s",
biji_note_id_get_path(dead->priv->id));
}
g_message (error->message);
g_error_free (error);
error = NULL;
}
biji_note_delete_from_tracker (dead);
g_signal_emit ( G_OBJECT (dead), biji_obj_signals[NOTE_DELETED],0);
biji_note_obj_finalize(G_OBJECT(dead));
/* Say goodbye however */
g_object_unref (trash);
g_object_unref (backup_file);
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);
return result;
}
gchar* biji_note_obj_get_path (BijiNoteObj* n)
......
......@@ -75,8 +75,11 @@ BijiNoteObj * biji_note_obj_new_from_path (const gchar *path);
/////////////////////////////////////////////////// Relationships other notes
gpointer biji_note_obj_get_note_book(BijiNoteObj *note);
void _biji_note_obj_set_book(BijiNoteObj *note, gpointer biji_note_book);
void biji_note_obj_delete(BijiNoteObj *dead);
gboolean biji_note_obj_trash (BijiNoteObj *dead);
gboolean note_obj_are_same(BijiNoteObj *a, BijiNoteObj* b);
///////////////////////////////////////////////////////////////////// Metadata
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment