Commit 500026ac authored by Cyrille Pontvieux's avatar Cyrille Pontvieux Committed by Alexander Schwinn
Browse files

Option to rename a file when existing copy conflicts (Bug #16686)

parent 544dad41
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -474,6 +474,14 @@ thunar_dialogs_show_job_ask (GtkWindow *parent,
          mnemonic = _("S_kip All");
          break;

        case THUNAR_JOB_RESPONSE_RENAME:
          mnemonic = _("Re_name");
          break;

        case THUNAR_JOB_RESPONSE_RENAME_ALL:
          mnemonic = _("Rena_me All");
          break;

        case THUNAR_JOB_RESPONSE_NO:
          mnemonic = _("_No");
          break;
@@ -579,6 +587,8 @@ thunar_dialogs_show_job_ask_replace (GtkWindow *parent,
  GtkWidget         *skip_button;
  GtkWidget         *replaceall_button;
  GtkWidget         *replace_button;
  GtkWidget         *renameall_button;
  GtkWidget         *rename_button;
  GdkPixbuf         *icon;
  gchar             *date_custom_style;
  gchar             *date_string;
@@ -626,24 +636,32 @@ thunar_dialogs_show_job_ask_replace (GtkWindow *parent,
  skip_button       = gtk_button_new_with_mnemonic (_("_Skip"));
  replaceall_button = gtk_button_new_with_mnemonic (_("Replace _All"));
  replace_button    = gtk_button_new_with_mnemonic (_("_Replace"));
  renameall_button  = gtk_button_new_with_mnemonic (_("Rena_me All"));
  rename_button     = gtk_button_new_with_mnemonic (_("Re_name"));

  g_signal_connect (cancel_button,      "clicked", G_CALLBACK (thunar_dialogs_show_job_ask_replace_callback), dialog);
  g_signal_connect (skipall_button,     "clicked", G_CALLBACK (thunar_dialogs_show_job_ask_replace_callback), dialog);
  g_signal_connect (skip_button,        "clicked", G_CALLBACK (thunar_dialogs_show_job_ask_replace_callback), dialog);
  g_signal_connect (replaceall_button,  "clicked", G_CALLBACK (thunar_dialogs_show_job_ask_replace_callback), dialog);
  g_signal_connect (replace_button,     "clicked", G_CALLBACK (thunar_dialogs_show_job_ask_replace_callback), dialog);
  g_signal_connect (renameall_button,   "clicked", G_CALLBACK (thunar_dialogs_show_job_ask_replace_callback), dialog);
  g_signal_connect (rename_button,      "clicked", G_CALLBACK (thunar_dialogs_show_job_ask_replace_callback), dialog);

  g_object_set_data (G_OBJECT (cancel_button),     "response-id", GINT_TO_POINTER (GTK_RESPONSE_CANCEL));
  g_object_set_data (G_OBJECT (skipall_button),    "response-id", GINT_TO_POINTER (THUNAR_JOB_RESPONSE_SKIP_ALL));
  g_object_set_data (G_OBJECT (skip_button),       "response-id", GINT_TO_POINTER (THUNAR_JOB_RESPONSE_SKIP));
  g_object_set_data (G_OBJECT (replaceall_button), "response-id", GINT_TO_POINTER (THUNAR_JOB_RESPONSE_REPLACE_ALL));
  g_object_set_data (G_OBJECT (replace_button),    "response-id", GINT_TO_POINTER (THUNAR_JOB_RESPONSE_REPLACE));
  g_object_set_data (G_OBJECT (renameall_button),  "response-id", GINT_TO_POINTER (THUNAR_JOB_RESPONSE_RENAME_ALL));
  g_object_set_data (G_OBJECT (rename_button),     "response-id", GINT_TO_POINTER (THUNAR_JOB_RESPONSE_RENAME));

  gtk_container_add (GTK_CONTAINER (button_box), cancel_button);
  gtk_container_add (GTK_CONTAINER (button_box), skipall_button);
  gtk_container_add (GTK_CONTAINER (button_box), skip_button);
  gtk_container_add (GTK_CONTAINER (button_box), replaceall_button);
  gtk_container_add (GTK_CONTAINER (button_box), replace_button);
  gtk_container_add (GTK_CONTAINER (button_box), renameall_button);
  gtk_container_add (GTK_CONTAINER (button_box), rename_button);
  gtk_container_add (GTK_CONTAINER (content_area), button_box);
  gtk_widget_set_halign (button_box, GTK_ALIGN_CENTER);
  gtk_box_set_spacing (GTK_BOX (button_box), 5);
+2 −0
Original line number Diff line number Diff line
@@ -372,6 +372,8 @@ thunar_job_response_get_type (void)
	      { THUNAR_JOB_RESPONSE_REPLACE_ALL, "THUNAR_JOB_RESPONSE_REPLACE_ALL", "replace-all" },
	      { THUNAR_JOB_RESPONSE_SKIP,        "THUNAR_JOB_RESPONSE_SKIP",        "skip"        },
	      { THUNAR_JOB_RESPONSE_SKIP_ALL,    "THUNAR_JOB_RESPONSE_SKIP_ALL",    "skip-all"    },
	      { THUNAR_JOB_RESPONSE_RENAME,      "THUNAR_JOB_RESPONSE_RENAME",      "rename"      },
	      { THUNAR_JOB_RESPONSE_RENAME_ALL,  "THUNAR_JOB_RESPONSE_RENAME_ALL",  "rename-all " },
	      { 0,                               NULL,                              NULL          }
	    };

+5 −1
Original line number Diff line number Diff line
@@ -240,6 +240,8 @@ ThunarThumbnailSize thunar_zoom_level_to_thumbnail_size (ThunarZoomLevel zoom_
 * @THUNAR_JOB_RESPONSE_REPLACE_ALL :
 * @THUNAR_JOB_RESPONSE_SKIP        :
 * @THUNAR_JOB_RESPONSE_SKIP_ALL    :
 * @THUNAR_JOB_RESPONSE_RENAME      :
 * @THUNAR_JOB_RESPONSE_RENAME_ALL  :
 *
 * Possible responses for the ThunarJob::ask signal.
 **/
@@ -256,8 +258,10 @@ typedef enum /*< flags >*/
  THUNAR_JOB_RESPONSE_REPLACE_ALL = 1 << 8,
  THUNAR_JOB_RESPONSE_SKIP        = 1 << 9,
  THUNAR_JOB_RESPONSE_SKIP_ALL    = 1 << 10,
  THUNAR_JOB_RESPONSE_RENAME      = 1 << 11,
  THUNAR_JOB_RESPONSE_RENAME_ALL  = 1 << 12,
} ThunarJobResponse;
#define THUNAR_JOB_RESPONSE_MAX_INT 10
#define THUNAR_JOB_RESPONSE_MAX_INT 12

GType thunar_job_response_get_type (void) G_GNUC_CONST;

+88 −0
Original line number Diff line number Diff line
@@ -141,3 +141,91 @@ thunar_io_jobs_util_next_duplicate_file (ThunarJob *job,



/**
 * thunar_io_jobs_util_next_renamed_file:
 * @job       : a #ThunarJob.
 * @src_file  : the source #GFile.
 * @tgt_file  : the target #GFile.
 * @n         : the @n<!---->th copy/move to create the #GFile for.
 * @error     : return location for errors or %NULL.
 *
 * Determines the #GFile for the next copy/move to @tgt_file.
 *
 * File named X will be renamed to "X (copy 1)".
 *
 * If there are errors or the job was cancelled, the return value
 * will be %NULL and @error will be set.
 *
 * Return value: the #GFile referencing the @n<!---->th copy/move
 *               of @tgt_file or %NULL on error/cancellation.
 **/
GFile *
thunar_io_jobs_util_next_renamed_file (ThunarJob *job,
                                       GFile     *src_file,
                                       GFile     *tgt_file,
                                       guint      n,
                                       GError   **error)
{
  GFileInfo   *info;
  GError      *err = NULL;
  GFile       *renamed_file = NULL;
  GFile       *parent_file = NULL;
  const gchar *old_display_name;
  gchar       *display_name;
  gchar       *file_basename;
  gchar       *dot = NULL;

  _thunar_return_val_if_fail (THUNAR_IS_JOB (job), NULL);
  _thunar_return_val_if_fail (G_IS_FILE (src_file), NULL);
  _thunar_return_val_if_fail (G_IS_FILE (tgt_file), NULL);
  _thunar_return_val_if_fail (0 < n, NULL);
  _thunar_return_val_if_fail (error == NULL || *error == NULL, NULL);
  _thunar_return_val_if_fail (!thunar_g_file_is_root (src_file), NULL);
  _thunar_return_val_if_fail (!thunar_g_file_is_root (tgt_file), NULL);

  /* abort on cancellation */
  if (exo_job_set_error_if_cancelled (EXO_JOB (job), error))
    return NULL;

  /* query the source file info / display name */
  info = g_file_query_info (src_file, G_FILE_ATTRIBUTE_STANDARD_TYPE ","
                            G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
                            G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
                            exo_job_get_cancellable (EXO_JOB (job)), &err);

  /* abort on error */
  if (info == NULL)
    {
      g_propagate_error (error, err);
      return NULL;
    }

  old_display_name = g_file_info_get_display_name (info);
  /* get file extension if file is not a directory */
  if (g_file_info_get_file_type (info) != G_FILE_TYPE_DIRECTORY)
    dot = thunar_util_str_get_extension (old_display_name);

  if (dot != NULL)
    {
      file_basename = g_strndup (old_display_name, dot - old_display_name);
      /* I18N: put " (copy #)" between basename and extension */
      display_name = g_strdup_printf (_("%s (copy %u)%s"), file_basename, n, dot);
      g_free(file_basename);
    }
  else
    {
      /* I18N: put " (copy #)" after filename (for files without extension) */
      display_name = g_strdup_printf (_("%s (copy %u)"), old_display_name, n);
    }

  /* create the GFile for the copy/move */
  parent_file = g_file_get_parent (tgt_file);
  renamed_file = g_file_get_child (parent_file, display_name);
  g_object_unref (parent_file);

  /* free resources */
  g_object_unref (info);
  g_free (display_name);

  return renamed_file;
}
+6 −0
Original line number Diff line number Diff line
@@ -31,6 +31,12 @@ GFile *thunar_io_jobs_util_next_duplicate_file (ThunarJob *job,
                                                guint      n,
                                                GError   **error) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;

GFile *thunar_io_jobs_util_next_renamed_file (ThunarJob *job,
                                              GFile     *src_file,
                                              GFile     *tgt_file,
                                              guint      n,
                                              GError   **error) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;

G_END_DECLS

#endif /* !__THUNAR_IO_JOBS_UITL_H__ */
Loading