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

Started work on copying folders recursively.

parent adc3bd26
......@@ -417,6 +417,7 @@ static void
gth_file_source_catalogs_copy (GthFileSource *file_source,
GthFileData *destination,
GList *file_list, /* GFile * list */
gboolean move,
ProgressCallback progress_callback,
ReadyCallback ready_callback,
gpointer data)
......
......@@ -67,15 +67,10 @@ get_place_for_test (GthTest *test,
void
comments__add_sidecars_cb (GList *sources,
comments__add_sidecars_cb (GFile *file,
GList **sidecars)
{
GList *scan;
for (scan = sources; scan; scan = scan->next) {
GFile *file = (GFile *) scan->data;
*sidecars = g_list_prepend (*sidecars, gth_comment_get_comment_file (file));
}
*sidecars = g_list_prepend (*sidecars, gth_comment_get_comment_file (file));
}
......
......@@ -85,6 +85,7 @@ gth_copy_task_exec (GthTask *task)
gth_file_source_copy (self->priv->file_source,
self->priv->destination,
self->priv->files,
self->priv->move,
copy_progress_cb,
copy_done_cb,
self);
......
......@@ -77,21 +77,15 @@ get_destination (GthFileData *file_data,
static void
copy_progress_cb (goffset current_file,
goffset total_files,
GFile *source,
GFile *destination,
goffset current_num_bytes,
goffset total_num_bytes,
gpointer user_data)
copy_progress_cb (GObject *object,
const char *description,
const char *details,
gboolean pulse,
double fraction,
gpointer user_data)
{
GthDuplicateTask *self = user_data;
char *name;
name = _g_file_get_display_name (source);
gth_task_progress (GTH_TASK (self), _("Duplicating files"), name, FALSE, (double) current_num_bytes / total_num_bytes);
g_free (name);
gth_task_progress (GTH_TASK (self), _("Duplicating files"), details, pulse, fraction);
}
......@@ -139,6 +133,7 @@ duplicate_current_file (GthDuplicateTask *self)
_g_copy_file_async (file_data->file,
destination,
FALSE,
G_FILE_COPY_ALL_METADATA,
G_PRIORITY_DEFAULT,
self->priv->cancellable,
......
......@@ -264,6 +264,7 @@ copy_remote_file_to_cache (GthFileData *file_data,
copy_data->dummy = FALSE;
_g_copy_file_async (file_data->file,
cache_file,
FALSE,
G_FILE_COPY_OVERWRITE,
G_PRIORITY_DEFAULT,
cancellable,
......@@ -325,6 +326,7 @@ update_file_from_cache (GthFileData *file_data,
{
_g_copy_file_async (cache_file,
file_data->file,
FALSE,
G_FILE_COPY_OVERWRITE,
G_PRIORITY_DEFAULT,
cancellable,
......
This diff is collapsed.
......@@ -25,6 +25,7 @@
#include <glib.h>
#include <gio/gio.h>
#include "typedefs.h"
G_BEGIN_DECLS
......@@ -49,13 +50,6 @@ typedef void (*ListReadyCallback) (GList *files,
GList *dirs,
GError *error,
gpointer user_data);
typedef void (*CopyProgressCallback) (goffset current_file,
goffset total_files,
GFile *source,
GFile *destination,
goffset current_num_bytes,
goffset total_num_bytes,
gpointer user_data);
typedef void (*CopyDoneCallback) (GError *error,
gpointer user_data);
typedef void (*BufferReadyCallback) (void *buffer,
......@@ -98,38 +92,28 @@ void g_query_info_async (GList *files, /* GF
/* asynchronous copy functions */
void _g_dummy_file_op_async (CopyDoneCallback callback,
void _g_dummy_file_op_async (CopyDoneCallback callback,
gpointer user_data);
void g_copy_files_async (GList *sources,
GList *destinations,
GFileCopyFlags flags,
int io_priority,
GCancellable *cancellable,
CopyProgressCallback progress_callback,
gpointer progress_callback_data,
CopyDoneCallback callback,
gpointer user_data);
void _g_copy_file_async (GFile *source,
void _g_copy_files_async (GList *sources,
GFile *destination,
gboolean move,
GFileCopyFlags flags,
int io_priority,
GCancellable *cancellable,
CopyProgressCallback progress_callback,
ProgressCallback progress_callback,
gpointer progress_callback_data,
CopyDoneCallback callback,
gpointer user_data);
void g_directory_copy_async (GFile *source,
void _g_copy_file_async (GFile *source,
GFile *destination,
gboolean move,
GFileCopyFlags flags,
int io_priority,
GCancellable *cancellable,
CopyProgressCallback progress_callback,
ProgressCallback progress_callback,
gpointer progress_callback_data,
CopyDoneCallback callback,
gpointer user_data);
gboolean _g_delete_files (GList *file_list,
gboolean include_metadata,
GError **error);
gboolean _g_move_file (GFile *source,
GFile *destination,
GFileCopyFlags flags,
......@@ -137,6 +121,12 @@ gboolean _g_move_file (GFile *source,
GFileProgressCallback progress_callback,
gpointer progress_callback_data,
GError **error);
gboolean _g_delete_files (GList *file_list,
gboolean include_metadata,
GError **error);
/* -- read/write/create file -- */
gboolean g_load_file_in_buffer (GFile *file,
void **buffer,
gsize *size,
......@@ -168,8 +158,6 @@ GFile * _g_directory_create_unique (GFile *parent,
const char *display_name,
const char *suffix,
GError **error);
GFileType
_g_file_get_standard_type (GFile *file);
/* convenience macros */
......
......@@ -1522,6 +1522,28 @@ _g_file_get_display_name (GFile *file)
}
GFileType
_g_file_get_standard_type (GFile *file)
{
GFileType result;
GFileInfo *info;
GError *error = NULL;
info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, 0, NULL, &error);
if (error == NULL) {
result = g_file_info_get_file_type (info);
}
else {
result = G_FILE_ATTRIBUTE_TYPE_INVALID;
g_error_free (error);
}
g_object_unref (info);
return result;
}
GFile *
_g_file_get_child (GFile *file,
...)
......
......@@ -206,6 +206,7 @@ char * _g_build_uri (const char *base,
/* GIO utils */
char * _g_file_get_display_name (GFile *file);
GFileType _g_file_get_standard_type (GFile *file);
GFile * _g_file_get_child (GFile *file,
...);
GIcon * _g_file_get_icon (GFile *file);
......
......@@ -239,177 +239,22 @@ gth_file_source_vfs_list (GthFileSource *file_source,
typedef struct {
GthFileSourceVfs *file_source;
GthFileData *destination;
GList *file_list;
ProgressCallback progress_callback;
ReadyCallback ready_callback;
gpointer user_data;
GList *files;
GList *dirs;
GList *current_dir;
char *message;
GthFileSource *file_source;
ReadyCallback ready_callback;
gpointer user_data;
} CopyOpData;
static void
copy_op_data_free (CopyOpData *cod)
{
g_object_unref (cod->file_source);
g_object_unref (cod->destination);
_g_object_list_unref (cod->file_list);
_g_object_list_unref (cod->files);
_g_object_list_unref (cod->dirs);
g_free (cod->message);
g_free (cod);
}
static void
copy__copy_files_done (GError *error,
gpointer user_data)
copy_done_cb (GError *error,
gpointer user_data)
{
CopyOpData *cod = user_data;
cod->ready_callback (G_OBJECT (cod->file_source), error, cod->user_data);
copy_op_data_free (cod);
}
static void
copy__copy_files (CopyOpData *cod)
{
GList *destinations;
GList *scan;
destinations = NULL;
for (scan = cod->files; scan; scan = scan->next) {
GFile *source = scan->data;
char *source_basename;
source_basename = g_file_get_basename (source);
destinations = g_list_prepend (destinations, g_file_get_child (cod->destination->file, source_basename));
g_free (source_basename);
}
g_copy_files_async (cod->files,
destinations,
G_FILE_COPY_NONE,
G_PRIORITY_DEFAULT,
gth_file_source_get_cancellable (GTH_FILE_SOURCE (cod->file_source)),
NULL,
NULL,
copy__copy_files_done,
cod);
_g_object_list_unref (destinations);
}
static void copy__copy_current_dir (CopyOpData *cod);
static void
copy__copy_current_dir_done (GError *error,
gpointer user_data)
{
CopyOpData *cod = user_data;
if (error != NULL) {
cod->ready_callback (G_OBJECT (cod->file_source), error, cod->user_data);
copy_op_data_free (cod);
return;
}
cod->current_dir = cod->current_dir->next;
copy__copy_current_dir (cod);
}
static void
copy__copy_current_dir_progress (goffset current_file,
goffset total_files,
GFile *source,
GFile *destination,
goffset current_num_bytes,
goffset total_num_bytes,
gpointer user_data)
{
CopyOpData *cod = user_data;
GthFileData *source_file_data;
char *details;
if (cod->progress_callback == NULL)
return;
source_file_data = (GthFileData *) cod->current_dir->data;
details = g_strdup_printf (_("Copying files from '%s'"), g_file_info_get_display_name (source_file_data->info));
(cod->progress_callback) (G_OBJECT (cod->file_source), cod->message, details, FALSE, ((double) current_num_bytes) / total_num_bytes, cod->user_data);
g_free (details);
}
static void
copy__copy_current_dir (CopyOpData *cod)
{
GthFileData *source;
char *source_basename;
GFile *destination;
if (cod->current_dir == NULL) {
copy__copy_files (cod);
return;
}
source = (GthFileData *) cod->current_dir->data;
source_basename = g_file_get_basename (source->file);
destination = g_file_get_child (cod->destination->file, source_basename);
g_directory_copy_async (source->file,
destination,
G_FILE_COPY_NONE,
G_PRIORITY_DEFAULT,
gth_file_source_get_cancellable (GTH_FILE_SOURCE (cod->file_source)),
copy__copy_current_dir_progress,
cod,
copy__copy_current_dir_done,
cod);
g_object_unref (destination);
g_free (source_basename);
}
static void
copy__file_list_info_ready_cb (GList *files,
GError *error,
gpointer user_data)
{
CopyOpData *cod = user_data;
GList *scan;
for (scan = files; scan; scan = scan->next) {
GthFileData *file_data = scan->data;
switch (g_file_info_get_file_type (file_data->info)) {
case G_FILE_TYPE_DIRECTORY:
cod->dirs = g_list_prepend (cod->dirs, g_object_ref (file_data));
break;
case G_FILE_TYPE_REGULAR:
case G_FILE_TYPE_SYMBOLIC_LINK:
cod->files = g_list_prepend (cod->files, g_object_ref (file_data->file));
break;
default:
break;
}
}
cod->files = g_list_reverse (cod->files);
cod->dirs = g_list_reverse (cod->dirs);
cod->current_dir = cod->dirs;
copy__copy_current_dir (cod);
g_object_unref (cod->file_source);
g_free (cod);
}
......@@ -417,6 +262,7 @@ static void
gth_file_source_vfs_copy (GthFileSource *file_source,
GthFileData *destination,
GList *file_list, /* GFile * list */
gboolean move,
ProgressCallback progress_callback,
ReadyCallback ready_callback,
gpointer data)
......@@ -425,21 +271,19 @@ gth_file_source_vfs_copy (GthFileSource *file_source,
cod = g_new0 (CopyOpData, 1);
cod->file_source = g_object_ref (file_source);
cod->destination = g_object_ref (destination);
cod->file_list = _g_object_list_ref (file_list);
cod->progress_callback = progress_callback;
cod->ready_callback = ready_callback;
cod->user_data = data;
cod->message = g_strdup_printf (_("Copying files to '%s'"), g_file_info_get_display_name (destination->info));
if (cod->progress_callback != NULL)
(cod->progress_callback) (G_OBJECT (file_source), cod->message, _("Getting files information"), TRUE, 0.0, cod->user_data);
g_query_info_async (cod->file_list,
G_FILE_ATTRIBUTE_STANDARD_TYPE,
gth_file_source_get_cancellable (GTH_FILE_SOURCE (cod->file_source)),
copy__file_list_info_ready_cb,
cod);
_g_copy_files_async (file_list,
destination->file,
move,
G_FILE_COPY_ALL_METADATA,
G_PRIORITY_DEFAULT,
gth_file_source_get_cancellable (file_source),
progress_callback,
data,
copy_done_cb,
cod);
}
......
......@@ -81,6 +81,7 @@ typedef struct {
typedef struct {
GthFileData *destination;
GList *file_list;
gboolean move;
ProgressCallback progress_callback;
ReadyCallback ready_callback;
gpointer data;
......@@ -190,6 +191,7 @@ static void
gth_file_source_queue_copy (GthFileSource *file_source,
GthFileData *destination,
GList *file_list,
gboolean move,
ProgressCallback progress_callback,
ReadyCallback ready_callback,
gpointer data)
......@@ -201,6 +203,7 @@ gth_file_source_queue_copy (GthFileSource *file_source,
async_op->op = FILE_SOURCE_OP_COPY;
async_op->data.copy.destination = gth_file_data_dup (destination);
async_op->data.copy.file_list = _g_file_list_dup (file_list);
async_op->data.copy.move = move;
async_op->data.copy.progress_callback = progress_callback;
async_op->data.copy.ready_callback = ready_callback;
async_op->data.copy.data = data;
......@@ -248,6 +251,7 @@ gth_file_source_exec_next_in_queue (GthFileSource *file_source)
gth_file_source_copy (file_source,
async_op->data.copy.destination,
async_op->data.copy.file_list,
async_op->data.copy.move,
async_op->data.copy.progress_callback,
async_op->data.copy.ready_callback,
async_op->data.copy.data);
......@@ -692,15 +696,16 @@ void
gth_file_source_copy (GthFileSource *file_source,
GthFileData *destination,
GList *file_list, /* GFile * list */
gboolean move,
ProgressCallback progress_callback,
ReadyCallback ready_callback,
gpointer data)
{
if (gth_file_source_is_active (file_source)) {
gth_file_source_queue_copy (file_source, destination, file_list, progress_callback, ready_callback, data);
gth_file_source_queue_copy (file_source, destination, file_list, move, progress_callback, ready_callback, data);
return;
}
GTH_FILE_SOURCE_GET_CLASS (G_OBJECT (file_source))->copy (file_source, destination, file_list, progress_callback, ready_callback, data);
GTH_FILE_SOURCE_GET_CLASS (G_OBJECT (file_source))->copy (file_source, destination, file_list, move, progress_callback, ready_callback, data);
}
......
......@@ -89,6 +89,7 @@ struct _GthFileSourceClass
void (*copy) (GthFileSource *file_source,
GthFileData *destination,
GList *file_list, /* GFile * list */
gboolean move,
ProgressCallback progress_callback,
ReadyCallback callback,
gpointer data);
......@@ -136,6 +137,7 @@ void gth_file_source_rename (GthFileSource *file_sou
void gth_file_source_copy (GthFileSource *file_source,
GthFileData *destination,
GList *file_list, /* GFile list */
gboolean move,
ProgressCallback progress_callback,
ReadyCallback ready_callback,
gpointer data);
......
......@@ -134,12 +134,12 @@ gth_main_register_default_hooks (void)
gth_hook_register ("save-pixbuf", 1);
/**
* Called when copying files in g_copy_files_async with the
* Called when copying files in _g_copy_files_async with the
* G_FILE_COPY_ALL_METADATA flag activated and when deleting file
* with _g_delete_files. Used to add sidecar files that contain
* file metadata.
*
* @sources (GList *): the original file list, a GFile * list.
* @file (GFile *): the original file.
* @sidecar_sources (GList **): the sidecars list.
*/
gth_hook_register ("add-sidecars", 2);
......
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