[Xfce4-commits] r29899 - in thunar/branches/migration-to-gio: . thunar
Jannis Pohlmann
jannis at xfce.org
Fri Apr 24 01:04:59 CEST 2009
Author: jannis
Date: 2009-04-23 23:04:58 +0000 (Thu, 23 Apr 2009)
New Revision: 29899
Modified:
thunar/branches/migration-to-gio/ChangeLog
thunar/branches/migration-to-gio/thunar/thunar-application.c
thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c
thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h
thunar/branches/migration-to-gio/thunar/thunar-job.c
thunar/branches/migration-to-gio/thunar/thunar-job.h
thunar/branches/migration-to-gio/thunar/thunar-transfer-job.c
Log:
* thunar/thunar-application, thunar/thunar-io-jobs.{c,h},
thunar/thunar-job.{c,h}, thunar/thunar-transfer-job.c: Re-implement
thunar_application_restore_files() based on a new job called
thunar_io_jobs_restore_files(). Modify ThunarTransferJob so that it
checks whether the parent directory of the original path exists and
otherwise tries to create it (with user interaction). Add new
function thunar_job_ask_create() to ThunarJob. ThunarApplication is
now almost ThunarVFS free.
Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog 2009-04-23 20:39:59 UTC (rev 29898)
+++ thunar/branches/migration-to-gio/ChangeLog 2009-04-23 23:04:58 UTC (rev 29899)
@@ -1,3 +1,14 @@
+2009-04-24 Jannis Pohlmann <jannis at xfce.org>
+
+ * thunar/thunar-application, thunar/thunar-io-jobs.{c,h},
+ thunar/thunar-job.{c,h}, thunar/thunar-transfer-job.c: Re-implement
+ thunar_application_restore_files() based on a new job called
+ thunar_io_jobs_restore_files(). Modify ThunarTransferJob so that it
+ checks whether the parent directory of the original path exists and
+ otherwise tries to create it (with user interaction). Add new
+ function thunar_job_ask_create() to ThunarJob. ThunarApplication is
+ now almost ThunarVFS free.
+
2009-04-23 Jannis Pohlmann <jannis at xfce.org>
* thunar/thunar-dialogs.c: Use more fine-grained labels for files,
Modified: thunar/branches/migration-to-gio/thunar/thunar-application.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-application.c 2009-04-23 20:39:59 UTC (rev 29898)
+++ thunar/branches/migration-to-gio/thunar/thunar-application.c 2009-04-23 23:04:58 UTC (rev 29899)
@@ -1550,29 +1550,20 @@
GList *trash_file_list,
GClosure *new_files_closure)
{
-#if 0
- ThunarVfsPath *target_path;
- const gchar *original_path;
- GtkWidget *dialog;
- GtkWindow *window;
- GdkScreen *screen;
- GError *err = NULL;
- GList *source_path_list = NULL;
- GList *target_path_list = NULL;
- GList *lp;
- gchar *original_dir;
- gchar *display_name;
- gint response = GTK_RESPONSE_YES;
+ const gchar *original_uri;
+ GError *err = NULL;
+ GFile *target_path;
+ GList *source_path_list = NULL;
+ GList *target_path_list = NULL;
+ GList *lp;
_thunar_return_if_fail (parent == NULL || GDK_IS_SCREEN (parent) || GTK_IS_WIDGET (parent));
_thunar_return_if_fail (THUNAR_IS_APPLICATION (application));
- /* determine the target paths for all files */
- for (lp = trash_file_list; err == NULL && lp != NULL && response == GTK_RESPONSE_YES; lp = lp->next)
+ for (lp = trash_file_list; lp != NULL; lp = lp->next)
{
- /* determine the original path for the file */
- original_path = thunar_file_get_original_path (lp->data);
- if (G_UNLIKELY (original_path == NULL))
+ original_uri = thunar_file_get_original_path (lp->data);
+ if (G_UNLIKELY (original_uri == NULL))
{
/* no OriginalPath, impossible to continue */
g_set_error (&err, G_FILE_ERROR, G_FILE_ERROR_INVAL,
@@ -1581,89 +1572,33 @@
break;
}
- /* determine the target path for the OriginalPath */
- target_path = thunar_vfs_path_new (original_path, &err);
- if (G_UNLIKELY (target_path == NULL))
- {
- /* invalid OriginalPath, cannot continue */
- break;
- }
+ /* TODO we need to distinguish between URIs and paths here */
+ target_path = g_file_new_for_commandline_arg (original_uri);
- /* determine the directory of the original path */
- original_dir = g_path_get_dirname (original_path);
- if (!g_file_test (original_dir, G_FILE_TEST_IS_DIR))
- {
- /* parse the parent pointer */
- screen = thunar_util_parse_parent (parent, &window);
+ source_path_list = g_file_list_append (source_path_list, thunar_file_get_file (lp->data));
+ target_path_list = g_file_list_append (target_path_list, target_path);
- /* ask the user whether to recreate the original dir */
- display_name = g_filename_display_name (original_dir);
- dialog = gtk_message_dialog_new (window,
- GTK_DIALOG_MODAL
- | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_NONE,
- _("Create the folder \"%s\"?"),
- display_name);
- gtk_dialog_add_buttons (GTK_DIALOG (dialog),
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- _("C_reate Folder"), GTK_RESPONSE_YES,
- NULL);
- if (G_UNLIKELY (window == NULL && screen != NULL))
- gtk_window_set_screen (GTK_WINDOW (dialog), screen);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- _("The folder \"%s\" does not exist anymore, but it is required to restore "
- "the file \"%s\" from the trash. Do you want to create the folder again?"),
- display_name, thunar_file_get_display_name (lp->data));
- response = gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
- g_free (display_name);
-
- /* check if the user wants to recreate the folder */
- if (G_LIKELY (response == GTK_RESPONSE_YES))
- {
- /* try to recreate the folder */
- xfce_mkdirhier (original_dir, 0755, &err);
- }
- }
-
- /* check if we succeed and aren't cancelled */
- if (G_LIKELY (err == NULL && response == GTK_RESPONSE_YES))
- {
- /* add the source/target pair to our lists */
- source_path_list = thunar_vfs_path_list_append (source_path_list, thunar_file_get_path (lp->data));
- target_path_list = g_list_append (target_path_list, target_path);
- }
- else
- {
- /* release the target path */
- thunar_vfs_path_unref (target_path);
- }
-
- /* cleanup */
- g_free (original_dir);
+ g_object_unref (target_path);
}
- /* check if an error occurred or the user cancelled */
if (G_UNLIKELY (err != NULL))
{
/* display an error dialog */
- thunar_dialogs_show_error (parent, err, _("Failed to restore \"%s\""), thunar_file_get_display_name (lp->data));
+ thunar_dialogs_show_error (parent, err, _("Could not restore \"%s\""),
+ thunar_file_get_display_name (lp->data));
g_error_free (err);
}
- else if (G_LIKELY (response == GTK_RESPONSE_YES))
+ else
{
/* launch the operation */
thunar_application_launch (application, parent, "stock_folder-move",
- _("Restoring files..."), thunar_vfs_move_files,
+ _("Restoring files..."), thunar_io_jobs_restore_files,
source_path_list, target_path_list, new_files_closure);
}
- /* cleanup */
- thunar_vfs_path_list_free (target_path_list);
- thunar_vfs_path_list_free (source_path_list);
-#endif
+ /* free path lists */
+ g_file_list_free (source_path_list);
+ g_file_list_free (target_path_list);
}
Modified: thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c 2009-04-23 20:39:59 UTC (rev 29898)
+++ thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c 2009-04-23 23:04:58 UTC (rev 29899)
@@ -662,3 +662,18 @@
return thunar_simple_job_launch (_thunar_io_jobs_trash, 1,
G_TYPE_FILE_LIST, file_list);
}
+
+
+
+ThunarJob *
+thunar_io_jobs_restore_files (GList *source_file_list,
+ GList *target_file_list)
+{
+ _thunar_return_val_if_fail (source_file_list != NULL, NULL);
+ _thunar_return_val_if_fail (target_file_list != NULL, NULL);
+ _thunar_return_val_if_fail (g_list_length (source_file_list) == g_list_length (target_file_list), NULL);
+
+ return thunar_job_launch (thunar_transfer_job_new (source_file_list,
+ target_file_list,
+ THUNAR_TRANSFER_JOB_MOVE));
+}
Modified: thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h 2009-04-23 20:39:59 UTC (rev 29898)
+++ thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h 2009-04-23 23:04:58 UTC (rev 29899)
@@ -35,6 +35,8 @@
ThunarJob *thunar_io_jobs_link_files (GList *source_file_list,
GList *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
ThunarJob *thunar_io_jobs_trash_files (GList *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+ThunarJob *thunar_io_jobs_restore_files (GList *source_file_list,
+ GList *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
G_END_DECLS
Modified: thunar/branches/migration-to-gio/thunar/thunar-job.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-job.c 2009-04-23 20:39:59 UTC (rev 29898)
+++ thunar/branches/migration-to-gio/thunar/thunar-job.c 2009-04-23 23:04:58 UTC (rev 29899)
@@ -63,6 +63,9 @@
static void thunar_job_class_init (ThunarJobClass *klass);
static void thunar_job_init (ThunarJob *job);
static void thunar_job_finalize (GObject *object);
+static ThunarJobResponse thunar_job_real_ask (ThunarJob *job,
+ const gchar *message,
+ ThunarJobResponse choices);
static ThunarJobResponse thunar_job_real_ask_replace (ThunarJob *job,
ThunarFile *source_file,
ThunarFile *target_file);
@@ -82,6 +85,7 @@
struct _ThunarJobPrivate
{
+ ThunarJobResponse earlier_ask_create_response;
ThunarJobResponse earlier_ask_overwrite_response;
ThunarJobResponse earlier_ask_skip_response;
GIOSchedulerJob *scheduler_job;
@@ -153,6 +157,7 @@
gobject_class->finalize = thunar_job_finalize;
klass->execute = NULL;
+ klass->ask = thunar_job_real_ask;
klass->ask_replace = thunar_job_real_ask_replace;
/**
@@ -291,6 +296,7 @@
{
job->priv = THUNAR_JOB_GET_PRIVATE (job);
job->priv->cancellable = g_cancellable_new ();
+ job->priv->earlier_ask_create_response = 0;
job->priv->earlier_ask_overwrite_response = 0;
job->priv->earlier_ask_skip_response = 0;
job->priv->running = FALSE;
@@ -312,6 +318,20 @@
static ThunarJobResponse
+thunar_job_real_ask (ThunarJob *job,
+ const gchar *message,
+ ThunarJobResponse choices)
+{
+ ThunarJobResponse response;
+
+ _thunar_return_val_if_fail (THUNAR_IS_JOB (job), THUNAR_JOB_RESPONSE_CANCEL);
+ g_signal_emit (job, job_signals[ASK], 0, message, choices, &response);
+ return response;
+}
+
+
+
+static ThunarJobResponse
thunar_job_real_ask_replace (ThunarJob *job,
ThunarFile *source_file,
ThunarFile *target_file)
@@ -663,6 +683,49 @@
+ThunarJobResponse
+thunar_job_ask_create (ThunarJob *job,
+ const gchar *format,
+ ...)
+{
+ ThunarJobResponse response;
+ va_list var_args;
+
+ _thunar_return_val_if_fail (THUNAR_IS_JOB (job), THUNAR_JOB_RESPONSE_CANCEL);
+
+ if (G_UNLIKELY (thunar_job_is_cancelled (job)))
+ return THUNAR_JOB_RESPONSE_CANCEL;
+
+ /* check if the user said "Create All" earlier */
+ if (G_UNLIKELY (job->priv->earlier_ask_create_response == THUNAR_JOB_RESPONSE_YES_ALL))
+ return THUNAR_JOB_RESPONSE_YES;
+
+ /* check if the user said "Create None" earlier */
+ if (G_UNLIKELY (job->priv->earlier_ask_create_response == THUNAR_JOB_RESPONSE_NO_ALL))
+ return THUNAR_JOB_RESPONSE_NO;
+
+ va_start (var_args, format);
+ response = _thunar_job_ask_valist (job, format, var_args,
+ _("Do you want to create it?"),
+ THUNAR_JOB_RESPONSE_YES
+ | THUNAR_JOB_RESPONSE_CANCEL);
+ va_end (var_args);
+
+ job->priv->earlier_ask_create_response = response;
+
+ /* translate the response */
+ if (response == THUNAR_JOB_RESPONSE_YES_ALL)
+ response = THUNAR_JOB_RESPONSE_YES;
+ else if (response == THUNAR_JOB_RESPONSE_NO_ALL)
+ response = THUNAR_JOB_RESPONSE_NO;
+ else if (response == THUNAR_JOB_RESPONSE_CANCEL)
+ thunar_job_cancel (job);
+
+ return response;
+}
+
+
+
ThunarJobResponse
thunar_job_ask_replace (ThunarJob *job,
GFile *source_path,
Modified: thunar/branches/migration-to-gio/thunar/thunar-job.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-job.h 2009-04-23 20:39:59 UTC (rev 29898)
+++ thunar/branches/migration-to-gio/thunar/thunar-job.h 2009-04-23 23:04:58 UTC (rev 29899)
@@ -85,6 +85,9 @@
guint signal_id,
GQuark signal_detail,
...);
+ThunarJobResponse thunar_job_ask_create (ThunarJob *job,
+ const gchar *format,
+ ...);
ThunarJobResponse thunar_job_ask_overwrite (ThunarJob *job,
const gchar *format,
...);
Modified: thunar/branches/migration-to-gio/thunar/thunar-transfer-job.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-transfer-job.c 2009-04-23 20:39:59 UTC (rev 29898)
+++ thunar/branches/migration-to-gio/thunar/thunar-transfer-job.c 2009-04-23 23:04:58 UTC (rev 29899)
@@ -622,15 +622,20 @@
GError **error)
{
ThunarTransferNode *node;
+ ThunarJobResponse response;
ThunarTransferJob *transfer_job = THUNAR_TRANSFER_JOB (job);
GFileInfo *info;
+ gboolean parent_exists;
GError *err = NULL;
GList *new_files_list = NULL;
GList *snext;
GList *sp;
GList *tnext;
GList *tp;
+ GFile *target_parent;
+ gchar *basename;
gchar *message;
+ gchar *parent_display_name;
_thunar_return_val_if_fail (THUNAR_IS_TRANSFER_JOB (job), FALSE);
_thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -660,6 +665,76 @@
if (G_UNLIKELY (info == NULL))
break;
+ /* check if we are moving a file out of the trash */
+ if (transfer_job->type == THUNAR_TRANSFER_JOB_MOVE && g_file_is_trashed (node->source_file))
+ {
+ /* update progress information */
+ message = g_strdup_printf (_("Trying to restore \"%s\""),
+ g_file_info_get_display_name (info));
+ thunar_job_info_message (job, message);
+ g_free (message);
+
+ /* determine the parent file */
+ target_parent = g_file_get_parent (tp->data);
+
+ /* check if the parent exists */
+ parent_exists = g_file_query_exists (target_parent, thunar_job_get_cancellable (job));
+
+ /* abort on cancellation */
+ if (thunar_job_set_error_if_cancelled (job, &err))
+ {
+ g_object_unref (target_parent);
+ break;
+ }
+
+ if (G_LIKELY (!parent_exists))
+ {
+ /* determine the display name of the parent */
+ basename = g_file_get_basename (target_parent);
+ parent_display_name = g_filename_display_name (basename);
+ g_free (basename);
+
+ /* ask the user whether he wants to create the parent folder because its gone */
+ response = thunar_job_ask_create (job,
+ _("The folder \"%s\" does not exist anymore but is "
+ "required to restore the file \"%s\" from the "
+ "trash"),
+ parent_display_name,
+ g_file_info_get_display_name (info));
+
+ /* abort if cancelled */
+ if (G_UNLIKELY (response == THUNAR_JOB_RESPONSE_CANCEL))
+ {
+ g_object_unref (target_parent);
+ g_free (parent_display_name);
+ break;
+ }
+
+ /* try to create the parent directory */
+ if (!g_file_make_directory_with_parents (target_parent,
+ thunar_job_get_cancellable (job),
+ &err))
+ {
+ if (!thunar_job_is_cancelled (job))
+ {
+ g_clear_error (&err);
+
+ /* overwrite the internal GIO error with something more user-friendly */
+ g_set_error (&err, G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("Failed to restore the folder \"%s\""),
+ parent_display_name);
+ }
+
+ g_object_unref (target_parent);
+ g_free (parent_display_name);
+ break;
+ }
+
+ /* clean up */
+ g_free (parent_display_name);
+ }
+ }
+
if (transfer_job->type == THUNAR_TRANSFER_JOB_MOVE)
{
message = g_strdup_printf (_("Trying to move \"%s\""),
More information about the Xfce4-commits
mailing list