Commit cc8433e5 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

update the catalog after removing files or deleting files from disk

parent 9ef096f4
......@@ -46,14 +46,18 @@ gth_browser_activate_remove_from_catalog (GSimpleAction *action,
GthBrowser *browser = GTH_BROWSER (user_data);
GList *items;
GList *file_data_list;
GList *file_list;
items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
file_data_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
file_list = gth_file_data_list_to_file_list (file_data_list);
gth_catalog_manager_remove_files (GTK_WINDOW (browser),
gth_browser_get_location_data (browser),
file_data_list);
file_list,
TRUE);
_g_object_list_unref (file_list);
_g_object_list_unref (file_data_list);
_gtk_tree_path_list_free (items);
}
......
......@@ -1307,9 +1307,10 @@ gth_file_source_catalogs_reorder (GthFileSource *file_source,
typedef struct {
GtkWindow *parent;
GList *file_data_list;
GList *file_list;
GFile *gio_file;
GthCatalog *catalog;
gboolean notify;
} RemoveFromCatalogData;
......@@ -1322,7 +1323,7 @@ remove_from_catalog_end (GError *error,
g_object_unref (data->catalog);
g_object_unref (data->gio_file);
_g_object_list_unref (data->file_data_list);
_g_object_list_unref (data->file_list);
g_free (data);
}
......@@ -1335,22 +1336,15 @@ remove_files__catalog_save_done_cb (void **buffer,
{
RemoveFromCatalogData *data = user_data;
if (error == NULL) {
if ((error == NULL) && data->notify) {
GFile *catalog_file;
GList *files = NULL;
GList *scan;
catalog_file = gth_catalog_file_from_gio_file (data->gio_file, NULL);
for (scan = data->file_data_list; scan; scan = scan->next)
files = g_list_prepend (files, g_object_ref (((GthFileData*) scan->data)->file));
files = g_list_reverse (files);
gth_monitor_folder_changed (gth_main_get_default_monitor (),
catalog_file,
files,
data->file_list,
GTH_MONITOR_EVENT_REMOVED);
_g_object_list_unref (files);
g_object_unref (catalog_file);
}
......@@ -1387,9 +1381,9 @@ catalog_buffer_ready_cb (void **buffer,
return;
}
for (scan = data->file_data_list; scan; scan = scan->next) {
GthFileData *file_data = scan->data;
gth_catalog_remove_file (data->catalog, file_data->file);
for (scan = data->file_list; scan; scan = scan->next) {
GFile *file = scan->data;
gth_catalog_remove_file (data->catalog, file);
}
catalog_buffer = gth_catalog_to_data (data->catalog, &catalog_size);
......@@ -1412,14 +1406,16 @@ catalog_buffer_ready_cb (void **buffer,
void
gth_catalog_manager_remove_files (GtkWindow *parent,
GthFileData *location,
GList *file_list)
GList *file_list,
gboolean notify)
{
RemoveFromCatalogData *data;
data = g_new0 (RemoveFromCatalogData, 1);
data->parent = parent;
data->file_data_list = gth_file_data_list_dup (file_list);
data->file_list = _g_file_list_dup (file_list);
data->gio_file = gth_main_get_gio_file (location->file);
data->notify = notify;
_g_file_load_async (data->gio_file,
G_PRIORITY_DEFAULT,
......@@ -1432,11 +1428,25 @@ gth_catalog_manager_remove_files (GtkWindow *parent,
static void
gth_file_source_catalogs_remove (GthFileSource *file_source,
GthFileData *location,
GList *file_list /* GthFileData list */,
GList *file_data_list /* GthFileData list */,
gboolean permanently,
GtkWindow *parent)
{
gth_catalog_manager_remove_files (parent, location, file_list);
GList *file_list;
file_list = gth_file_data_list_to_file_list (file_data_list);
gth_catalog_manager_remove_files (parent, location, file_list, TRUE);
_g_object_list_unref (file_list);
}
static void
gth_file_source_catalogs_deleted_from_disk (GthFileSource *file_source,
GthFileData *location,
GList *file_list)
{
gth_catalog_manager_remove_files (NULL, location, file_list, FALSE);
}
......@@ -1481,6 +1491,7 @@ gth_file_source_catalogs_class_init (GthFileSourceCatalogsClass *class)
file_source_class->is_reorderable = gth_file_source_catalogs_is_reorderable;
file_source_class->reorder = gth_file_source_catalogs_reorder;
file_source_class->remove = gth_file_source_catalogs_remove;
file_source_class->deleted_from_disk = gth_file_source_catalogs_deleted_from_disk;
}
......
......@@ -49,6 +49,7 @@ struct _GthFileSourceCatalogsClass
GType gth_file_source_catalogs_get_type (void) G_GNUC_CONST;
void gth_catalog_manager_remove_files (GtkWindow *parent,
GthFileData *location,
GList *file_list /* GthFileData list */);
GList *file_list /* GFile list */,
gboolean notify);
#endif /* GTH_FILE_SOURCE_CATALOGS_H */
......@@ -170,7 +170,7 @@ gth_browser_activate_remove_from_selection (GthBrowser *browser,
items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
files = gth_file_data_list_to_file_list (file_list);
gth_selections_manager_remove_files (folder, files);
gth_selections_manager_remove_files (folder, files, TRUE);
_g_object_list_unref (files);
_g_object_list_unref (file_list);
......
......@@ -267,12 +267,21 @@ gth_file_source_selections_remove (GthFileSource *file_source,
GList *files;
files = gth_file_data_list_to_file_list (file_list);
gth_selections_manager_remove_files (location->file, files);
gth_selections_manager_remove_files (location->file, files, TRUE);
_g_object_list_unref (files);
}
static void
gth_file_source_selections_deleted_from_disk (GthFileSource *file_source,
GthFileData *location,
GList *file_list)
{
gth_selections_manager_remove_files (location->file, file_list, FALSE);
}
static gboolean
gth_file_source_selections_shows_extra_widget (GthFileSource *file_source)
{
......@@ -317,6 +326,7 @@ gth_file_source_selections_class_init (GthFileSourceSelectionsClass *class)
file_source_class->is_reorderable = gth_file_source_selections_is_reorderable;
file_source_class->reorder = gth_file_source_selections_reorder;
file_source_class->remove = gth_file_source_selections_remove;
file_source_class->deleted_from_disk = gth_file_source_selections_deleted_from_disk;
file_source_class->shows_extra_widget = gth_file_source_selections_shows_extra_widget;
}
......
......@@ -393,8 +393,9 @@ gth_selections_manager_add_files (GFile *folder,
void
gth_selections_manager_remove_files (GFile *folder,
GList *file_list)
gth_selections_manager_remove_files (GFile *folder,
GList *file_list,
gboolean notify)
{
GthSelectionsManager *self;
int n_selection;
......@@ -433,10 +434,11 @@ gth_selections_manager_remove_files (GFile *folder,
g_mutex_unlock (&self->priv->mutex);
gth_monitor_folder_changed (gth_main_get_default_monitor (),
folder,
file_list,
GTH_MONITOR_EVENT_REMOVED);
if (notify)
gth_monitor_folder_changed (gth_main_get_default_monitor (),
folder,
file_list,
GTH_MONITOR_EVENT_REMOVED);
gth_monitor_emblems_changed (gth_main_get_default_monitor (), file_list);
}
......
......@@ -62,7 +62,8 @@ gboolean gth_selections_manager_add_files (GFile *folder,
GList *file_list, /* GFile list */
int destination_position);
void gth_selections_manager_remove_files (GFile *folder,
GList *file_list);
GList *file_list,
gboolean notify);
void gth_selections_manager_reorder (GFile *folder,
GList *visible_files, /* GFile list */
GList *files_to_move, /* GFile list */
......
......@@ -3242,9 +3242,6 @@ folder_changed_cb (GthMonitor *monitor,
}
}
if ((event == GTH_MONITOR_EVENT_REMOVED) && g_file_equal (parent, browser->priv->location->file))
event = GTH_MONITOR_EVENT_DELETED;
if (update_folder_tree || update_file_list) {
MonitorEventData *monitor_data;
gboolean current_file_deleted = FALSE;
......@@ -3270,7 +3267,11 @@ folder_changed_cb (GthMonitor *monitor,
monitor_data);
break;
case GTH_MONITOR_EVENT_REMOVED:
case GTH_MONITOR_EVENT_DELETED:
if ((event == GTH_MONITOR_EVENT_REMOVED) && ! g_file_equal (parent, browser->priv->location->file))
break;
if (browser->priv->current_file != NULL) {
GList *link;
......@@ -3303,6 +3304,8 @@ folder_changed_cb (GthMonitor *monitor,
g_signal_handlers_block_by_data (gth_browser_get_file_list_view (browser), browser);
gth_file_list_delete_files (GTH_FILE_LIST (browser->priv->file_list), list);
gth_file_list_delete_files (GTH_FILE_LIST (browser->priv->thumbnail_list), list);
if (event == GTH_MONITOR_EVENT_DELETED)
gth_file_source_deleted_from_disk (browser->priv->location_source, browser->priv->location, list);
if (current_file_deleted)
g_signal_handlers_unblock_by_data (gth_browser_get_file_list_view (browser), browser);
}
......
......@@ -55,6 +55,7 @@ typedef enum {
FILE_SOURCE_OP_COPY,
FILE_SOURCE_OP_REORDER,
FILE_SOURCE_OP_REMOVE,
FILE_SOURCE_OP_DELETED_FROM_DISK,
FILE_SOURCE_OP_GET_FREE_SPACE
} FileSourceOp;
......@@ -140,6 +141,12 @@ typedef struct {
} RemoveData;
typedef struct {
GthFileData *location;
GList *file_list;
} DeletedFromDiskData;
typedef struct {
GFile *location;
SpaceReadyCallback callback;
......@@ -151,16 +158,17 @@ typedef struct {
GthFileSource *file_source;
FileSourceOp op;
union {
ListData list;
ForEachChildData fec;
ReadAttributesData read_attributes;
RenameData rename;
CopyData copy;
ReorderData reorder;
WriteMetadataData write_metadata;
ReadMetadataData read_metadata;
RemoveData remove;
GetFreeSpaceData get_free_space;
ListData list;
ForEachChildData fec;
ReadAttributesData read_attributes;
RenameData rename;
CopyData copy;
ReorderData reorder;
WriteMetadataData write_metadata;
ReadMetadataData read_metadata;
RemoveData remove;
DeletedFromDiskData deleted_from_disk;
GetFreeSpaceData get_free_space;
} data;
} FileSourceAsyncOp;
......@@ -202,6 +210,10 @@ file_source_async_op_free (FileSourceAsyncOp *async_op)
_g_object_unref (async_op->data.remove.location);
_g_object_list_unref (async_op->data.remove.file_list);
break;
case FILE_SOURCE_OP_DELETED_FROM_DISK:
_g_object_unref (async_op->data.deleted_from_disk.location);
_g_object_list_unref (async_op->data.deleted_from_disk.file_list);
break;
case FILE_SOURCE_OP_GET_FREE_SPACE:
_g_object_unref (async_op->data.get_free_space.location);
break;
......@@ -418,6 +430,23 @@ gth_file_source_queue_remove (GthFileSource *file_source,
}
static void
gth_file_source_queue_deleted_from_disk (GthFileSource *file_source,
GthFileData *location,
GList *file_list)
{
FileSourceAsyncOp *async_op;
async_op = g_new0 (FileSourceAsyncOp, 1);
async_op->file_source = file_source;
async_op->op = FILE_SOURCE_OP_DELETED_FROM_DISK;
async_op->data.deleted_from_disk.location = gth_file_data_dup (location);
async_op->data.deleted_from_disk.file_list = _g_file_list_dup (file_list);
file_source->priv->queue = g_list_append (file_source->priv->queue, async_op);
}
static void
gth_file_source_queue_get_free_space (GthFileSource *file_source,
GFile *location,
......@@ -526,6 +555,12 @@ gth_file_source_exec_next_in_queue (GthFileSource *file_source)
async_op->data.remove.parent);
break;
case FILE_SOURCE_OP_DELETED_FROM_DISK:
gth_file_source_queue_deleted_from_disk (file_source,
async_op->data.deleted_from_disk.location,
async_op->data.deleted_from_disk.file_list);
break;
case FILE_SOURCE_OP_GET_FREE_SPACE:
gth_file_source_get_free_space (file_source,
async_op->data.get_free_space.location,
......@@ -848,6 +883,14 @@ base_remove (GthFileSource *file_source,
}
static void
base_deleted_from_disk (GthFileSource *file_source,
GList *file_list /* GFile list */)
{
/* void */
}
static gboolean
base_shows_extra_widget (GthFileSource *file_source)
{
......@@ -895,6 +938,7 @@ gth_file_source_class_init (GthFileSourceClass *class)
class->is_reorderable = base_is_reorderable;
class->reorder = base_reorder;
class->remove = base_remove;
class->deleted_from_disk = base_deleted_from_disk;
class->get_free_space = base_get_free_space;
class->shows_extra_widget = base_shows_extra_widget;
}
......@@ -1084,6 +1128,7 @@ list__done_func (GObject *source,
{
ListOpData *data = user_data;
data->files = g_list_reverse (data->files);
data->ready_func (data->file_source, data->files, error, data->user_data);
_g_object_list_unref (data->files);
......@@ -1355,6 +1400,20 @@ gth_file_source_remove (GthFileSource *file_source,
}
void
gth_file_source_deleted_from_disk (GthFileSource *file_source,
GthFileData *location,
GList *file_list /* GFile list */)
{
if (gth_file_source_is_active (file_source)) {
gth_file_source_queue_deleted_from_disk (file_source, location, file_list);
return;
}
g_cancellable_reset (file_source->priv->cancellable);
GTH_FILE_SOURCE_GET_CLASS (G_OBJECT (file_source))->deleted_from_disk (file_source, location, file_list);
}
void
gth_file_source_get_free_space (GthFileSource *file_source,
GFile *location,
......
......@@ -132,6 +132,9 @@ struct _GthFileSourceClass
GList *file_list, /* GthFileData list */
gboolean permanently,
GtkWindow *parent);
void (*deleted_from_disk) (GthFileSource *file_source,
GthFileData *location,
GList *files /* GFile list */);
void (*get_free_space) (GthFileSource *file_source,
GFile *location,
SpaceReadyCallback callback,
......@@ -221,6 +224,9 @@ void gth_file_source_remove (GthFileSource *file
GList *file_list /* GthFileData list */,
gboolean permanently,
GtkWindow *parent);
void gth_file_source_deleted_from_disk (GthFileSource *file_source,
GthFileData *location,
GList *file_list /* GFile list */);
void gth_file_source_get_free_space (GthFileSource *file_source,
GFile *location,
SpaceReadyCallback callback,
......
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