[nautilus/wip/alexpandelea/batchRename] Add review changes
- From: Alexandru-Ionut Pandelea <alexpandelea src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/alexpandelea/batchRename] Add review changes
- Date: Fri, 15 Jul 2016 11:19:34 +0000 (UTC)
commit 5a618a938fdf03f24502ea16541d8537e46e89af
Author: Alexandru Pandelea <alexandru pandelea gmail com>
Date: Fri Jul 15 13:59:33 2016 +0300
Add review changes
Handle conflicts for files with same parent and make changes according to
the review.
https://bugzilla.gnome.org/show_bug.cgi?id=768311
src/nautilus-batch-rename-utilities.c | 404 +++++++++++++---------
src/nautilus-batch-rename-utilities.h | 60 ++--
src/nautilus-batch-rename.c | 288 +++++++++++-----
src/nautilus-batch-rename.h | 7 +-
src/nautilus-file-utilities.c | 16 +
src/nautilus-file-utilities.h | 2 +
src/nautilus-files-view.c | 4 +-
src/resources/ui/nautilus-batch-rename-dialog.ui | 68 +++-
8 files changed, 548 insertions(+), 301 deletions(-)
---
diff --git a/src/nautilus-batch-rename-utilities.c b/src/nautilus-batch-rename-utilities.c
index 1c80671..8bc4dd9 100644
--- a/src/nautilus-batch-rename-utilities.c
+++ b/src/nautilus-batch-rename-utilities.c
@@ -16,6 +16,15 @@ typedef struct {
gint *position;
} CreateDateElem;
+typedef struct {
+ NautilusBatchRename *dialog;
+ GHashTable *hash_table;
+} QueryData;
+
+static void cursor_callback (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data);
+
static gchar*
batch_rename_append (gchar *file_name,
gchar *entry_text)
@@ -23,7 +32,7 @@ batch_rename_append (gchar *file_name,
gchar *result;
gint len;
- len = strlen (entry_text) + strlen (file_name) + 1;
+ len = strlen (entry_text) + strlen (file_name);
result = g_malloc (len);
if (result == NULL) {
@@ -41,7 +50,7 @@ batch_rename_prepend (gchar *file_name,
gchar *result;
gint len;
- len = strlen (entry_text) + strlen (file_name) + 1;
+ len = strlen (entry_text) + strlen (file_name);
result = g_malloc (len);
if (result == NULL) {
@@ -78,50 +87,18 @@ batch_rename_replace (gchar *string,
new_string = g_string_new ("");
- i = 0;
-
- while (i < n_splits) {
+ for (i = 0; i < n_splits; i++) {
g_string_append (new_string, splitted_string[i]);
if (i != n_splits - 1)
g_string_append (new_string, replacement);
- i++;
}
return new_string->str;
}
-gchar*
-get_new_name (NautilusBatchRenameMode mode,
- gchar *file_name,
- gchar *entry_text,
- ...)
-{
- va_list args;
- gchar *result;
-
- result = NULL;
-
- if (mode == NAUTILUS_BATCH_RENAME_REPLACE) {
-
- va_start (args, entry_text);
-
- result = batch_rename_replace (file_name, entry_text, va_arg(args, gchar*));
-
- va_end (args);
- }
-
- if (mode == NAUTILUS_BATCH_RENAME_APPEND)
- result = batch_rename_append (file_name, entry_text);
-
- if (mode == NAUTILUS_BATCH_RENAME_PREPEND)
- result = batch_rename_prepend (file_name, entry_text);
-
- return result;
-}
-
GList*
-get_new_names_list (NautilusBatchRenameMode mode,
+get_new_names_list (NautilusBatchRenameMode mode,
GList *selection,
gchar *entry_text,
gchar *replace_text)
@@ -157,56 +134,68 @@ get_new_names_list (NautilusBatchRenameMode mode,
return result;
}
-gchar*
-get_new_display_name (NautilusBatchRenameMode mode,
- gchar *file_name,
- gchar *entry_text,
- gchar *replace_text)
+GList*
+list_has_duplicates (NautilusDirectory *model,
+ GList *new_names,
+ GList *selection,
+ gboolean same_parent)
{
- gchar *result;
+ /* handling conflicts for files in different directories is missing */
+ if (!same_parent)
+ return NULL;
- result = get_new_name (mode, file_name, entry_text, replace_text);
+ GList *directory_files, *l1, *l2, *result;
+ NautilusFile *file1, *file2;
+ GString *file_name1, *file_name2;
- return result;
-}
+ directory_files = nautilus_directory_get_file_list (model);
-GList*
-list_has_duplicates (NautilusFilesView *view,
- GList *new_names,
- GList *old_names)
-{
- GList *l1, *l2;
- GList *result;
- NautilusFile *file;
- gchar *file_name;
+ file_name1 = g_string_new ("");
+ file_name2 = g_string_new ("");
result = NULL;
- for (l1 = new_names, l2 = old_names; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) {
- file = NAUTILUS_FILE (l2->data);
- file_name = strdup (nautilus_file_get_name (file));
+ for (l1 = new_names; l1 != NULL; l1 = l1->next) {
+ file1 = NAUTILUS_FILE (selection->data);
- if (strcmp (l1->data, file_name) != 0 && file_with_name_exists (view, l1->data) == TRUE) {
- result = g_list_prepend (result,
- l1->data);
+ g_string_erase (file_name1, 0, -1);
+ g_string_append (file_name1, nautilus_file_get_name (file1));
+
+ /* check for duplicate only if the name has changed */
+ if (g_strcmp0 (l1->data, file_name1->str) != 0) {
+ for (l2 = directory_files; l2 != NULL; l2 = l2->next) {
+ file2 = NAUTILUS_FILE (l2->data);
+
+ g_string_erase (file_name2, 0, -1);
+ g_string_append (file_name2, nautilus_file_get_name (file2));
+
+ if (g_strcmp0 (l1->data, file_name2->str) == 0) {
+ result = g_list_prepend (result, strdup (l1->data));
+ break;
+ }
+ }
}
- g_free (file_name);
+ selection = selection->next;
}
- return result;
+
+ g_string_free (file_name1, TRUE);
+ g_string_free (file_name2, TRUE);
+
+ return g_list_reverse (result);
}
gint
compare_files_by_name_ascending (gconstpointer a,
gconstpointer b)
{
- NautilusFile *f1;
- NautilusFile *f2;
+ NautilusFile *file1;
+ NautilusFile *file2;
- f1 = NAUTILUS_FILE (a);
- f2 = NAUTILUS_FILE (b);
+ file1 = NAUTILUS_FILE (a);
+ file2 = NAUTILUS_FILE (b);
- return nautilus_file_compare_for_sort (f1,f2,
+ return nautilus_file_compare_for_sort (file1,file2,
NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
FALSE, FALSE);
}
@@ -215,13 +204,13 @@ gint
compare_files_by_name_descending (gconstpointer a,
gconstpointer b)
{
- NautilusFile *f1;
- NautilusFile *f2;
+ NautilusFile *file1;
+ NautilusFile *file2;
- f1 = NAUTILUS_FILE (a);
- f2 = NAUTILUS_FILE (b);
+ file1 = NAUTILUS_FILE (a);
+ file2 = NAUTILUS_FILE (b);
- return nautilus_file_compare_for_sort (f1,f2,
+ return nautilus_file_compare_for_sort (file1,file2,
NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
FALSE, TRUE);
}
@@ -230,13 +219,13 @@ gint
compare_files_by_first_modified (gconstpointer a,
gconstpointer b)
{
- NautilusFile *f1;
- NautilusFile *f2;
+ NautilusFile *file1;
+ NautilusFile *file2;
- f1 = NAUTILUS_FILE (a);
- f2 = NAUTILUS_FILE (b);
+ file1 = NAUTILUS_FILE (a);
+ file2 = NAUTILUS_FILE (b);
- return nautilus_file_compare_for_sort (f1,f2,
+ return nautilus_file_compare_for_sort (file1,file2,
NAUTILUS_FILE_SORT_BY_MTIME,
FALSE, FALSE);
}
@@ -245,13 +234,13 @@ gint
compare_files_by_last_modified (gconstpointer a,
gconstpointer b)
{
- NautilusFile *f1;
- NautilusFile *f2;
+ NautilusFile *file1;
+ NautilusFile *file2;
- f1 = NAUTILUS_FILE (a);
- f2 = NAUTILUS_FILE (b);
+ file1 = NAUTILUS_FILE (a);
+ file2 = NAUTILUS_FILE (b);
- return nautilus_file_compare_for_sort (f1,f2,
+ return nautilus_file_compare_for_sort (file1,file2,
NAUTILUS_FILE_SORT_BY_MTIME,
FALSE, TRUE);
}
@@ -260,24 +249,34 @@ gint
compare_files_by_first_created (gconstpointer a,
gconstpointer b)
{
- return *(((CreateDateElem*) a)->position) - *(((CreateDateElem*) b)->position);
+ CreateDateElem *elem1;
+ CreateDateElem *elem2;
+
+ elem1 = (CreateDateElem*) a;
+ elem2 = (CreateDateElem*) b;
+
+ return *(elem1->position) - *(elem2->position);
}
gint
compare_files_by_last_created (gconstpointer a,
gconstpointer b)
{
- return *(((CreateDateElem*) b)->position) - *(((CreateDateElem*) a)->position);
+ CreateDateElem *elem1;
+ CreateDateElem *elem2;
+
+ elem1 = (CreateDateElem*) a;
+ elem2 = (CreateDateElem*) b;
+
+ return *(elem2->position) - *(elem1->position);
}
GList*
-nautilus_batch_rename_sort (GList *selection,
- SortingMode mode,
- ...)
+nautilus_batch_rename_sort (GList *selection,
+ SortingMode mode,
+ GHashTable *hash_table)
{
GList *l,*l2;
- va_list args;
- GHashTable *hash_table;
NautilusFile *file;
GList *createDate_list, *createDate_list_sorted;
@@ -297,10 +296,6 @@ nautilus_batch_rename_sort (GList *selection,
}
if (mode == FIRST_CREATED || mode == LAST_CREATED) {
- va_start (args, mode);
-
- hash_table = va_arg(args, GHashTable*);
-
createDate_list = NULL;
for (l = selection; l != NULL; l = l->next) {
@@ -327,115 +322,188 @@ nautilus_batch_rename_sort (GList *selection,
l->data = elem->file;
}
- va_end (args);
g_list_free (createDate_list);
}
return selection;
}
-GHashTable*
-check_creation_date_for_selection (GList *selection)
+static void
+cursor_next (QueryData *data,
+ TrackerSparqlCursor *cursor)
+{
+ tracker_sparql_cursor_next_async (cursor,
+ NULL,
+ cursor_callback,
+ data);
+}
+
+static void
+cursor_callback (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GHashTable *hash_table;
+ TrackerSparqlCursor *cursor;
+ gboolean success;
+ gint *value;
+ QueryData *data;
+ GError *error;
+
+ error = NULL;
+
+ cursor = TRACKER_SPARQL_CURSOR (object);
+ data = user_data;
+ hash_table = data->hash_table;
+
+ success = tracker_sparql_cursor_next_finish (cursor, result, &error);
+
+ if (!success) {
+ g_clear_error (&error);
+ g_clear_object (&cursor);
+
+ query_finished (data->dialog, data->hash_table);
+
+ return;
+ }
+
+ value = g_malloc (sizeof(int));
+ *value = g_hash_table_size (hash_table);
+
+ g_hash_table_insert (hash_table,
+ strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL)),
+ value);
+
+ if (tracker_sparql_cursor_get_string (cursor, 1, NULL) == NULL) {
+ g_object_unref (cursor);
+ g_hash_table_destroy (hash_table);
+
+ query_finished (data->dialog, NULL);
+
+ /* if one file doesn't have the metadata, there's no point in
+ * continuing the query */
+ return ;
+ }
+
+ /* Get next */
+ cursor_next (data, cursor);
+}
+
+static void
+query_callback (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
{
- GError *error = NULL;
TrackerSparqlConnection *connection;
TrackerSparqlCursor *cursor;
- gchar *filter1, *filter2, *sparql, *tmp;
+ QueryData *data;
+ GError *error;
+
+ error = NULL;
+
+ connection = TRACKER_SPARQL_CONNECTION (object);
+ data = user_data;
+
+ cursor = tracker_sparql_connection_query_finish (connection,
+ result,
+ &error);
+
+ if (error != NULL) {
+ g_error_free (error);
+
+ query_finished (data->dialog, data->hash_table);
+ } else {
+ cursor_next (data, cursor);
+ }
+}
+
+void
+check_creation_date_for_selection (NautilusBatchRename *dialog,
+ GList *selection)
+{
+ TrackerSparqlConnection *connection;
+ GString *query;
GHashTable *hash_table;
GList *l;
- gint i, *value;
NautilusFile *file;
- gchar *query = "SELECT nfo:fileName(?file) nie:contentCreated(?file) WHERE { ?file a
nfo:FileDataObject. ";
+ GError *error;
+ QueryData *data;
- filter1 = g_malloc (MAX_FILTER_LEN);
- g_snprintf (filter1, MAX_FILTER_LEN, "FILTER(tracker:uri-is-parent('%s', nie:url(?file)))",
- nautilus_file_get_parent_uri (NAUTILUS_FILE (selection->data)));
+ error = NULL;
- sparql = g_strconcat (query, filter1, NULL);
+ query = g_string_new ("SELECT nfo:fileName(?file) nie:contentCreated(?file) WHERE { ?file a
nfo:FileDataObject. ");
- for (l = selection; l != NULL; l = l->next) {
- filter2 = g_malloc (MAX_FILTER_LEN);
+ g_string_append_printf (query,
+ "FILTER(tracker:uri-is-parent('%s', nie:url(?file))) ",
+ nautilus_file_get_parent_uri (NAUTILUS_FILE (selection->data)));
+ for (l = selection; l != NULL; l = l->next) {
file = NAUTILUS_FILE (l->data);
if (l == selection)
- g_snprintf (filter2, MAX_FILTER_LEN, "FILTER (nfo:fileName(?file) = '%s' ",
nautilus_file_get_name (file));
+ g_string_append_printf (query,
+ "FILTER (nfo:fileName(?file) = '%s' ",
+ nautilus_file_get_name (file));
else
- g_snprintf (filter2, MAX_FILTER_LEN, "|| nfo:fileName(?file) = '%s'",
nautilus_file_get_name (file));
-
- tmp = sparql;
- sparql = g_strconcat (sparql, filter2, NULL);
-
- g_free (tmp);
- g_free (filter2);
+ g_string_append_printf (query,
+ "|| nfo:fileName(?file) = '%s' ",
+ nautilus_file_get_name (file));
}
- tmp = sparql;
- sparql = g_strconcat (sparql, ")} ORDER BY ASC(nie:contentCreated(?file))", NULL);
+ g_string_append (query, ")} ORDER BY ASC(nie:contentCreated(?file))");
connection = tracker_sparql_connection_get (NULL, &error);
- if (!connection)
- return NULL;
+ if (!connection) {
+ g_error_free (error);
- /* Make a synchronous query to the store */
- cursor = tracker_sparql_connection_query (connection,
- sparql,
- NULL,
- &error);
+ return;
+ }
- if (error)
- return NULL;
+ hash_table = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
- /* Check results */
- if (!cursor) {
- return NULL;
- } else {
- hash_table = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_free);
- i = 0;
-
- /* Iterate, synchronously, the results */
- while (tracker_sparql_cursor_next (cursor, NULL, &error)) {
- value = g_malloc (sizeof(int));
- *value = i++;
-
- g_hash_table_insert (hash_table,
- strdup(tracker_sparql_cursor_get_string (cursor, 0, NULL)),
- value);
-
- if (tracker_sparql_cursor_get_string (cursor, 1, NULL) == NULL) {
- g_object_unref (connection);
- g_hash_table_destroy (hash_table);
- g_free (filter1);
-
- return NULL;
- }
- }
+ data = g_malloc (sizeof (QueryData*));
+ data->hash_table = hash_table;
+ data->dialog = dialog;
- g_object_unref (cursor);
- }
+ /* Make an asynchronous query to the store */
+ tracker_sparql_connection_query_async (connection,
+ query->str,
+ NULL,
+ query_callback,
+ data);
g_object_unref (connection);
- g_free (filter1);
- g_free (sparql);
-
- return hash_table;
+ g_string_free (query, TRUE);
}
gboolean
-nautilus_file_can_rename_files (GList *selection)
+selection_has_single_parent (GList *selection)
{
- GList *l;
- NautilusFile *file;
+ GList *l;
+ NautilusFile *file;
+ GString *parent_name1, *parent_name2;
- for (l = selection; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
+ file = NAUTILUS_FILE (selection->data);
- if (!nautilus_file_can_rename (file))
- return FALSE;
- }
+ parent_name2 = g_string_new ("");
+ parent_name1 = g_string_new ("");
+ g_string_append (parent_name1, nautilus_file_get_parent_uri (file));
- return TRUE;
-}
+ for (l = selection->next; l != NULL; l = l->next) {
+ file = NAUTILUS_FILE (l->data);
+
+ g_string_erase (parent_name2, 0, -1);
+ g_string_append (parent_name2, nautilus_file_get_parent_uri (file));
+
+ if (!g_string_equal (parent_name1, parent_name2))
+ return FALSE;
+ }
+
+ g_string_free (parent_name1, TRUE);
+ g_string_free (parent_name2, TRUE);
+
+ return TRUE;
+}
\ No newline at end of file
diff --git a/src/nautilus-batch-rename-utilities.h b/src/nautilus-batch-rename-utilities.h
index 875cde6..ced8797 100644
--- a/src/nautilus-batch-rename-utilities.h
+++ b/src/nautilus-batch-rename-utilities.h
@@ -5,48 +5,40 @@
#include <gtk/gtk.h>
#include <tracker-sparql.h>
-gchar* get_new_name (NautilusBatchRenameMode mode,
- gchar *file_name,
- gchar *entry_text,
- ...);
+GList* get_new_names_list (NautilusBatchRenameMode mode,
+ GList *selection,
+ gchar *entry_text,
+ gchar *replace_text);
-GList* get_new_names_list (NautilusBatchRenameMode mode,
- GList *selection,
- gchar *entry_text,
- gchar *replace_text);
+GList* list_has_duplicates (NautilusDirectory *model,
+ GList *names,
+ GList *selection,
+ gboolean same_parent);
-gchar* get_new_display_name (NautilusBatchRenameMode mode,
- gchar *file_name,
- gchar *entry_text,
- gchar *replace_text);
+GList* nautilus_batch_rename_sort (GList *selection,
+ SortingMode mode,
+ GHashTable *create_date);
-GList* list_has_duplicates (NautilusFilesView *view,
- GList *names,
- GList *old_names);
+gint compare_files_by_last_modified (gconstpointer a,
+ gconstpointer b);
-GList* nautilus_batch_rename_sort (GList *selection,
- SortingMode mode,
- ...);
+gint compare_files_by_first_modified (gconstpointer a,
+ gconstpointer b);
-gint compare_files_by_last_modified (gconstpointer a,
- gconstpointer b);
+gint compare_files_by_name_descending (gconstpointer a,
+ gconstpointer b);
-gint compare_files_by_first_modified (gconstpointer a,
- gconstpointer b);
+gint compare_files_by_name_ascending (gconstpointer a,
+ gconstpointer b);
-gint compare_files_by_name_descending (gconstpointer a,
- gconstpointer b);
+gint compare_files_by_first_created (gconstpointer a,
+ gconstpointer b);
-gint compare_files_by_name_ascending (gconstpointer a,
- gconstpointer b);
+gint compare_files_by_last_created (gconstpointer a,
+ gconstpointer b);
-gint compare_files_by_first_created (gconstpointer a,
- gconstpointer b);
-
-gint compare_files_by_last_created (gconstpointer a,
- gconstpointer b);
-
-GHashTable* check_creation_date_for_selection (GList *selection);
-gboolean nautilus_file_can_rename_files (GList *selection);
+void check_creation_date_for_selection (NautilusBatchRename *dialog,
+ GList *selection);
+gboolean selection_has_single_parent (GList *selection);
#endif /* NAUTILUS_BATCH_RENAME_UTILITIES_H */
\ No newline at end of file
diff --git a/src/nautilus-batch-rename.c b/src/nautilus-batch-rename.c
index be192ec..bb0a517 100644
--- a/src/nautilus-batch-rename.c
+++ b/src/nautilus-batch-rename.c
@@ -18,7 +18,6 @@
#include "nautilus-batch-rename.h"
#include "nautilus-file.h"
-#include "nautilus-files-view.h"
#include "nautilus-error-reporting.h"
#include "nautilus-batch-rename-utilities.h"
@@ -27,7 +26,6 @@
#define ADD_TEXT_ENTRY_SIZE 550
#define REPLACE_ENTRY_SIZE 275
-#define MAX_DISPLAY_LEN 65
#define DIALOG_TITLE_LEN 25
struct _NautilusBatchRename
@@ -38,7 +36,6 @@ struct _NautilusBatchRename
GtkWidget *cancel_button;
GtkWidget *conflict_listbox;
- GtkWidget *error_label;
GtkWidget *name_entry;
GtkWidget *rename_button;
GtkWidget *find_entry;
@@ -53,30 +50,40 @@ struct _NautilusBatchRename
GtkWidget *scrolled_window;
GtkWidget *numbering_order_popover;
GtkWidget *numbering_order_button;
+ GtkWidget *conflict_box;
+ GtkWidget *conflict_label;
+ GtkWidget *conflict_down;
+ GtkWidget *conflict_up;
GList *listbox_rows;
GList *selection;
- NautilusBatchRenameMode mode;
- NautilusFilesView *view;
+ NautilusBatchRenameMode mode;
+ NautilusDirectory *model;
GActionGroup *action_group;
GMenu *numbering_order_menu;
GHashTable *create_date;
+
+ /* check if all files in selection have the same parent */
+ gboolean same_parent;
+ /* the number of the currently selected conflict */
+ gint selected_conflict;
+ /* total conflicts number */
+ gint conflcts_number;
+ GList *duplicates;
};
-static void batch_rename_dialog_on_closed (GtkDialog *dialog);
static void file_names_widget_entry_on_changed (NautilusBatchRename *dialog);
-
G_DEFINE_TYPE (NautilusBatchRename, nautilus_batch_rename, GTK_TYPE_DIALOG);
static void
numbering_order_changed (GSimpleAction *action,
GVariant *value,
- gpointer user_data)
+ gpointer user_data)
{
NautilusBatchRename *dialog;
const gchar *target_name;
@@ -89,28 +96,32 @@ numbering_order_changed (GSimpleAction *action,
gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
"Original name (Ascending)");
dialog->selection = nautilus_batch_rename_sort (dialog->selection,
- ORIGINAL_ASCENDING);
+ ORIGINAL_ASCENDING,
+ NULL);
}
if (g_strcmp0 (target_name, "name-descending") == 0) {
gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
"Original name (Descending)");
dialog->selection = nautilus_batch_rename_sort (dialog->selection,
- ORIGINAL_DESCENDING);
+ ORIGINAL_DESCENDING,
+ NULL);
}
if (g_strcmp0 (target_name, "first-modified") == 0) {
gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
"First Modified");
dialog->selection = nautilus_batch_rename_sort (dialog->selection,
- FIRST_MODIFIED);
+ FIRST_MODIFIED,
+ NULL);
}
if (g_strcmp0 (target_name, "last-modified") == 0) {
gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
"Last Modified");
dialog->selection = nautilus_batch_rename_sort (dialog->selection,
- LAST_MODIFIED);
+ LAST_MODIFIED,
+ NULL);
}
if (g_strcmp0 (target_name, "first-created") == 0) {
@@ -131,7 +142,7 @@ numbering_order_changed (GSimpleAction *action,
g_simple_action_set_state (action, value);
- g_signal_emit_by_name (dialog->numbering_order_popover, "closed");
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->numbering_order_button), FALSE);
/* update display text */
file_names_widget_entry_on_changed (dialog);
@@ -243,9 +254,6 @@ create_row_for_label (const gchar *new_text,
NULL);
gtk_label_set_ellipsize (GTK_LABEL (label_new), PANGO_ELLIPSIZE_END);
- gtk_label_set_max_width_chars (GTK_LABEL (label_new), MAX_DISPLAY_LEN);
-
- gtk_label_set_max_width_chars (GTK_LABEL (label_old), MAX_DISPLAY_LEN);
gtk_box_pack_end (GTK_BOX (box), label_new, TRUE, FALSE, 0);
gtk_box_pack_end (GTK_BOX (box), icon, TRUE, FALSE, 0);
@@ -260,7 +268,7 @@ create_row_for_label (const gchar *new_text,
static void
fill_display_listbox (NautilusBatchRename *dialog,
- GList *new_names)
+ GList *new_names)
{
GtkWidget *row;
GList *l1;
@@ -268,7 +276,7 @@ fill_display_listbox (NautilusBatchRename *dialog,
GList *l;
NautilusFile *file;
- /* clear rows from listbox (if there are any) */
+ /* clear rows from listbox (if any) */
if (dialog->listbox_rows != NULL)
for (l = dialog->listbox_rows; l != NULL; l = l->next) {
gtk_container_remove (GTK_CONTAINER (dialog->conflict_listbox),
@@ -287,59 +295,126 @@ fill_display_listbox (NautilusBatchRename *dialog,
gtk_container_add (GTK_CONTAINER (dialog->conflict_listbox), row);
- dialog->listbox_rows = g_list_prepend (dialog->listbox_rows,
- row);
+ dialog->listbox_rows = g_list_append (dialog->listbox_rows,
+ row);
}
}
static void
+select_nth_conflict (NautilusBatchRename *dialog)
+{
+ GList *l, *new_names, *l2;
+ GString *file_name, *display_text;
+ gint n;
+ NautilusFile *file;
+
+ n = dialog->selected_conflict;
+ l = g_list_nth (dialog->duplicates, n);
+
+ file_name = g_string_new (l->data);
+ display_text = g_string_new ("");
+
+ n = 0;
+
+ new_names = batch_rename_get_new_names (dialog);
+ l2 = dialog->selection;
+
+ for (l = new_names; l != NULL; l = l->next) {
+ file = NAUTILUS_FILE (l2->data);
+
+ /* first g_strcmp0 is for not selecting a file that doesn't change
+ * it's name */
+ if (g_strcmp0 ((gchar*) l->data, nautilus_file_get_name (file)) &&
+ g_strcmp0 (file_name->str, (gchar*) l->data) == 0)
+ break;
+ n++;
+ l2 = l2->next;
+ }
+
+ l = g_list_nth (dialog->listbox_rows, n);
+
+ gtk_list_box_select_row (GTK_LIST_BOX (dialog->conflict_listbox),
+ l->data);
+
+ g_string_append_printf (display_text,
+ "\"%s\" would conflict with an existing file.",
+ file_name->str);
+ gtk_label_set_label (GTK_LABEL (dialog->conflict_label),
+ display_text->str);
+
+ g_list_free_full (new_names, g_free);
+}
+
+static void
+move_next_conflict_down (NautilusBatchRename *dialog)
+{
+ dialog->selected_conflict++;
+
+ if (dialog->selected_conflict == 1)
+ gtk_widget_set_sensitive (dialog->conflict_up, TRUE);
+
+ if (dialog->selected_conflict == dialog->conflcts_number - 1)
+ gtk_widget_set_sensitive (dialog->conflict_down, FALSE);
+
+ select_nth_conflict (dialog);
+}
+
+static void
+move_next_conflict_up (NautilusBatchRename *dialog)
+{
+ dialog->selected_conflict--;
+
+ if (dialog->selected_conflict == 0)
+ gtk_widget_set_sensitive (dialog->conflict_up, FALSE);
+
+ if (dialog->selected_conflict == dialog->conflcts_number - 2)
+ gtk_widget_set_sensitive (dialog->conflict_down, TRUE);
+
+ select_nth_conflict (dialog);
+}
+
+static void
file_names_widget_entry_on_changed (NautilusBatchRename *dialog)
{
- gchar *entry_text;
- gchar *file_name;
GList *new_names;
- GList *duplicates;
- gchar *display_text = NULL;
- gboolean single_conflict;
if(dialog->selection == NULL)
return;
- new_names = batch_rename_get_new_names(dialog);
- duplicates = list_has_duplicates (dialog->view, new_names, dialog->selection);
+ if (dialog->duplicates != NULL)
+ g_list_free_full (dialog->duplicates, g_free);
- if (duplicates != NULL)
- single_conflict = (duplicates->next == NULL) ? TRUE:FALSE;
+ new_names = batch_rename_get_new_names(dialog);
+ dialog->duplicates = list_has_duplicates (dialog->model,
+ new_names,
+ dialog->selection,
+ dialog->same_parent);
- file_name = NULL;
- entry_text = NULL;
+ /* Update listbox that shows the result of the renaming for each file */
+ fill_display_listbox (dialog, new_names);
/* check if there are name conflicts and display them if they exist */
- if (duplicates != NULL) {
+ if (dialog->duplicates != NULL) {
gtk_widget_set_sensitive (dialog->rename_button, FALSE);
- return;
+ gtk_widget_show (dialog->conflict_box);
+
+ dialog->selected_conflict = 0;
+ dialog->conflcts_number = g_list_length (dialog->duplicates);
+
+ select_nth_conflict (dialog);
+
+ gtk_widget_set_sensitive (dialog->conflict_up, FALSE);
+ gtk_widget_set_sensitive (dialog->conflict_down, TRUE);
} else {
+ gtk_widget_hide (dialog->conflict_box);
+
/* re-enable the rename button if there are no more name conflicts */
- if (duplicates == NULL && !gtk_widget_is_sensitive (dialog->rename_button))
+ if (dialog->duplicates == NULL && !gtk_widget_is_sensitive (dialog->rename_button))
gtk_widget_set_sensitive (dialog->rename_button, TRUE);
}
- /* Update listbox that shows the result of the renaming for each file */
- fill_display_listbox (dialog, new_names);
-
- g_list_free (new_names);
- g_list_free (duplicates);
-
- g_free (entry_text);
- g_free (file_name);
- g_free (display_text);
-}
-
-static void
-batch_rename_dialog_on_closed (GtkDialog *dialog)
-{
- gtk_window_close (GTK_WINDOW (dialog));
+ g_list_free_full (new_names, g_free);
}
static void
@@ -368,6 +443,8 @@ batch_rename_mode_changed (NautilusBatchRename *dialog)
gtk_entry_set_text (GTK_ENTRY (dialog->name_entry),
gtk_entry_get_text (GTK_ENTRY (dialog->find_entry)));
+ gtk_widget_grab_focus (dialog->name_entry);
+
} else {
gtk_stack_set_visible_child_name (GTK_STACK (dialog->mode_stack), "replace");
@@ -375,6 +452,8 @@ batch_rename_mode_changed (NautilusBatchRename *dialog)
gtk_entry_set_text (GTK_ENTRY (dialog->find_entry),
gtk_entry_get_text ( GTK_ENTRY (dialog->name_entry)));
+
+ gtk_widget_grab_focus (dialog->find_entry);
}
/* update display text */
@@ -412,23 +491,21 @@ numbering_order_popover_closed (NautilusBatchRename *dialog)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->numbering_order_button), FALSE);
}
-static void
-nautilus_batch_rename_initialize_actions (NautilusBatchRename *dialog)
+void
+query_finished (NautilusBatchRename *dialog,
+ GHashTable *hash_table)
{
GMenuItem *first_created;
GMenuItem *last_created;
- dialog->action_group = G_ACTION_GROUP (g_simple_action_group_new ());
-
- g_action_map_add_action_entries (G_ACTION_MAP (dialog->action_group),
- dialog_entries,
- G_N_ELEMENTS (dialog_entries),
- dialog);
- gtk_widget_insert_action_group (GTK_WIDGET (dialog),
- "dialog",
- G_ACTION_GROUP (dialog->action_group));
+ /* for files with no metadata */
+ if (hash_table != NULL && g_hash_table_size (hash_table) == 0)
+ g_hash_table_destroy (hash_table);
- dialog->create_date = check_creation_date_for_selection (dialog->selection);
+ if (hash_table == NULL || g_hash_table_size (hash_table) == 0)
+ dialog->create_date = NULL;
+ else
+ dialog->create_date = hash_table;
if (dialog->create_date != NULL) {
first_created = g_menu_item_new ("First Created",
@@ -449,17 +526,50 @@ nautilus_batch_rename_initialize_actions (NautilusBatchRename *dialog)
}
static void
+nautilus_batch_rename_initialize_actions (NautilusBatchRename *dialog)
+{
+ dialog->action_group = G_ACTION_GROUP (g_simple_action_group_new ());
+
+ g_action_map_add_action_entries (G_ACTION_MAP (dialog->action_group),
+ dialog_entries,
+ G_N_ELEMENTS (dialog_entries),
+ dialog);
+ gtk_widget_insert_action_group (GTK_WIDGET (dialog),
+ "dialog",
+ G_ACTION_GROUP (dialog->action_group));
+
+ check_creation_date_for_selection (dialog, dialog->selection);
+}
+
+static void
+nautilus_batch_rename_finalize (GObject *object)
+{
+ NautilusBatchRename *dialog;
+
+ dialog = NAUTILUS_BATCH_RENAME (object);
+
+ if (dialog->create_date != NULL)
+ g_hash_table_destroy (dialog->create_date);
+
+ G_OBJECT_CLASS (nautilus_batch_rename_parent_class)->finalize (object);
+}
+
+static void
nautilus_batch_rename_class_init (NautilusBatchRenameClass *klass)
{
- GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GtkWidgetClass *widget_class;
+ GObjectClass *oclass;
+
+ widget_class = GTK_WIDGET_CLASS (klass);
+ oclass = G_OBJECT_CLASS (klass);
+
+ oclass->finalize = nautilus_batch_rename_finalize;
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/nautilus/ui/nautilus-batch-rename-dialog.ui");
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, grid);
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, cancel_button);
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, conflict_listbox);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, error_label);
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, name_entry);
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, rename_button);
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, find_entry);
@@ -475,42 +585,37 @@ nautilus_batch_rename_class_init (NautilusBatchRenameClass *klass)
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, numbering_order_popover);
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, numbering_order_button);
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, numbering_order_menu);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, conflict_box);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, conflict_label);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, conflict_up);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, conflict_down);
gtk_widget_class_bind_template_callback (widget_class, file_names_widget_entry_on_changed);
- gtk_widget_class_bind_template_callback (widget_class, batch_rename_dialog_on_closed);
gtk_widget_class_bind_template_callback (widget_class, file_names_widget_on_activate);
gtk_widget_class_bind_template_callback (widget_class, batch_rename_mode_changed);
gtk_widget_class_bind_template_callback (widget_class, add_button_clicked);
gtk_widget_class_bind_template_callback (widget_class, add_popover_closed);
gtk_widget_class_bind_template_callback (widget_class, numbering_order_button_clicked);
gtk_widget_class_bind_template_callback (widget_class, numbering_order_popover_closed);
+ gtk_widget_class_bind_template_callback (widget_class, move_next_conflict_up);
+ gtk_widget_class_bind_template_callback (widget_class, move_next_conflict_down);
}
GtkWidget*
-nautilus_batch_rename_new (NautilusFilesView *view)
+nautilus_batch_rename_new (GList *selection, NautilusDirectory *model, NautilusWindow *window)
{
NautilusBatchRename *dialog;
gint files_nr;
GList *l;
gchar *dialog_title;
- dialog = g_object_new (NAUTILUS_TYPE_BATCH_RENAME,"use-header-bar",1, NULL);
+ dialog = g_object_new (NAUTILUS_TYPE_BATCH_RENAME, "use-header-bar", TRUE, NULL);
- dialog->selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- dialog->view = view;
+ dialog->selection = selection;
+ dialog->model = model;
gtk_window_set_transient_for (GTK_WINDOW (dialog),
- GTK_WINDOW (nautilus_files_view_get_window (view)));
-
- gtk_widget_grab_focus (dialog->name_entry);
-
- gtk_label_set_ellipsize (GTK_LABEL (dialog->error_label), PANGO_ELLIPSIZE_END);
- gtk_label_set_max_width_chars (GTK_LABEL (dialog->error_label), MAX_DISPLAY_LEN);
-
- gtk_label_set_markup_with_mnemonic (GTK_LABEL (dialog->add_button_label),
- "<b>+</b> _Add");
-
- gtk_widget_set_vexpand (dialog->rename_button, FALSE);
+ GTK_WINDOW (window));
files_nr = 0;
@@ -521,12 +626,10 @@ nautilus_batch_rename_new (NautilusFilesView *view)
g_snprintf (dialog_title, DIALOG_TITLE_LEN, "Renaming %d files", files_nr);
gtk_window_set_title (GTK_WINDOW (dialog), dialog_title);
- gtk_popover_bind_model (GTK_POPOVER (dialog->numbering_order_popover),
- G_MENU_MODEL (dialog->numbering_order_menu),
- NULL);
-
nautilus_batch_rename_initialize_actions (dialog);
+ dialog->same_parent = selection_has_single_parent (dialog->selection);
+
/* update display text */
file_names_widget_entry_on_changed (dialog);
@@ -541,9 +644,20 @@ nautilus_batch_rename_init (NautilusBatchRename *self)
gtk_widget_init_template (GTK_WIDGET (self));
gtk_list_box_set_header_func (GTK_LIST_BOX (self->conflict_listbox),
- (GtkListBoxUpdateHeaderFunc) listbox_header_func,
- self,
- NULL);
+ (GtkListBoxUpdateHeaderFunc) listbox_header_func,
+ self,
+ NULL);
self->mode = NAUTILUS_BATCH_RENAME_PREPEND;
+
+ gtk_label_set_markup_with_mnemonic (GTK_LABEL (self->add_button_label),
+ "<b>+</b> _Add");
+
+ gtk_popover_bind_model (GTK_POPOVER (self->numbering_order_popover),
+ G_MENU_MODEL (self->numbering_order_menu),
+ NULL);
+
+ gtk_label_set_ellipsize (GTK_LABEL (self->conflict_label), PANGO_ELLIPSIZE_END);
+
+ self->duplicates = NULL;
}
\ No newline at end of file
diff --git a/src/nautilus-batch-rename.h b/src/nautilus-batch-rename.h
index 95d042a..4aa36f3 100644
--- a/src/nautilus-batch-rename.h
+++ b/src/nautilus-batch-rename.h
@@ -29,7 +29,12 @@ typedef enum {
G_DECLARE_FINAL_TYPE (NautilusBatchRename, nautilus_batch_rename, NAUTILUS, BATCH_RENAME, GtkDialog);
-GtkWidget* nautilus_batch_rename_new (NautilusFilesView *view);
+GtkWidget* nautilus_batch_rename_new (GList *selection,
+ NautilusDirectory *model,
+ NautilusWindow *window);
+
+void query_finished (NautilusBatchRename *dialog,
+ GHashTable *hash_table);
G_END_DECLS
diff --git a/src/nautilus-file-utilities.c b/src/nautilus-file-utilities.c
index 40b37df..cc7fac5 100644
--- a/src/nautilus-file-utilities.c
+++ b/src/nautilus-file-utilities.c
@@ -1149,6 +1149,22 @@ nautilus_file_selection_equal (GList *selection_a,
return selection_matches;
}
+gboolean
+nautilus_file_can_rename_files (GList *selection)
+{
+ GList *l;
+ NautilusFile *file;
+
+ for (l = selection; l != NULL; l = l->next) {
+ file = NAUTILUS_FILE (l->data);
+
+ if (!nautilus_file_can_rename (file))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
void
diff --git a/src/nautilus-file-utilities.h b/src/nautilus-file-utilities.h
index ee5f624..b974462 100644
--- a/src/nautilus-file-utilities.h
+++ b/src/nautilus-file-utilities.h
@@ -98,4 +98,6 @@ gboolean nautilus_file_selection_equal (GList *selection_a, GList *selection_b);
void nautilus_ensure_extension_points (void);
void nautilus_ensure_extension_builtins (void);
+gboolean nautilus_file_can_rename_files (GList *selection);
+
#endif /* NAUTILUS_FILE_UTILITIES_H */
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index e1118e1..3f5ef6b 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -5528,7 +5528,9 @@ real_action_rename (NautilusFilesView *view,
if (have_bulk_rename_tool ()) {
invoke_external_bulk_rename_utility (view, selection);
} else {
- dialog = nautilus_batch_rename_new (view);
+ dialog = nautilus_batch_rename_new (nautilus_files_view_get_selection (view),
+ nautilus_files_view_get_model (view),
+ nautilus_files_view_get_window (view));
gtk_widget_show (GTK_WIDGET (dialog));
}
diff --git a/src/resources/ui/nautilus-batch-rename-dialog.ui
b/src/resources/ui/nautilus-batch-rename-dialog.ui
index 69fd9d5..b715b48 100644
--- a/src/resources/ui/nautilus-batch-rename-dialog.ui
+++ b/src/resources/ui/nautilus-batch-rename-dialog.ui
@@ -5,14 +5,12 @@
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="destroy_with_parent">True</property>
-
<child type="action">
<object class="GtkButton" id="cancel_button">
<property name="label" translatable="yes">_Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="use_underline">True</property>
- <signal name="clicked" handler="batch_rename_dialog_on_closed" swapped="yes" />
</object>
</child>
<child type="action">
@@ -27,12 +25,10 @@
</style>
</object>
</child>
-
<action-widgets>
<action-widget response="ok" default="true">rename_button</action-widget>
<action-widget response="cancel">cancel_button</action-widget>
</action-widgets>
-
<child internal-child="vbox">
<object class="GtkBox" id="vbox">
<child>
@@ -108,6 +104,7 @@
<object class="GtkEntry" id="name_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="has_focus">True</property>
<property name="width_request">400</property>
<property name="hexpand">False</property>
<property name="activates-default">True</property>
@@ -293,18 +290,70 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="error_label">
- <property name="visible">False</property>
- <property name="halign">start</property>
- <property name="can_focus">False</property>
+ <object class="GtkBox" id="conflict_box">
+ <property name="orientation">horizontal</property>
+ <property name="spacing">6</property>
+ <property name="visible">True</property>
+ <property name="margin-left">6</property>
+ <child>
+ <object class="GtkLabel" id="conflict_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">False</property>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">horizontal</property>
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkButton" id="conflict_down">
+ <property name="visible">True</property>
+ <property name="relief">none</property>
+ <signal name="clicked" handler="move_next_conflict_down" swapped="yes" />
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="icon-name">go-down-symbolic</property>
+ <property name="icon-size">1</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="conflict_up">
+ <property name="visible">True</property>
+ <property name="relief">GTK_RELIEF_NONE</property>
+ <signal name="clicked" handler="move_next_conflict_up" swapped="yes" />
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="icon-name">go-up-symbolic</property>
+ <property name="icon-size">1</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
</object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">3</property>
+ <property name="width">8</property>
+ </packing>
</child>
</object>
</child>
</object>
</child>
</template>
-
<object class="GtkPopover" id="add_popover">
<property name="position">bottom</property>
<property name="relative-to">add_button</property>
@@ -318,7 +367,6 @@
</object>
</child>
</object>
-
<object class="GtkImage" id="done_image">
<property name="visible">True</property>
<property name="icon_name">object-select-symbolic</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]