[gthumb] Add utf8 versions of path/name to file-data to reduce escaping madness
- From: Michael J. Chudobiak <mjc src gnome org>
- To: svn-commits-list gnome org
- Subject: [gthumb] Add utf8 versions of path/name to file-data to reduce escaping madness
- Date: Mon, 4 May 2009 09:52:48 -0400 (EDT)
commit c2790abacad95ff67b6be14bbb7e4583f951e0c7
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date: Mon May 4 09:51:53 2009 -0400
Add utf8 versions of path/name to file-data to reduce escaping madness
---
libgthumb/file-data.c | 17 +++++++++--------
libgthumb/file-data.h | 3 ++-
libgthumb/gth-file-list.c | 4 ++--
libgthumb/gth-filter.c | 4 ++--
libgthumb/print-callbacks.c | 9 +++------
src/catalog-png-exporter.c | 9 +++------
src/dlg-jpegtran.c | 5 +----
src/dlg-rename-series.c | 14 ++++----------
src/dlg-reset-exif.c | 5 +----
src/gth-browser.c | 13 +++----------
src/gth-exif-data-viewer.c | 13 ++++---------
src/gth-viewer.c | 4 +---
src/rotation-utils.c | 5 +----
13 files changed, 36 insertions(+), 69 deletions(-)
diff --git a/libgthumb/file-data.c b/libgthumb/file-data.c
index 3dbc5cb..8cd2dfa 100644
--- a/libgthumb/file-data.c
+++ b/libgthumb/file-data.c
@@ -63,12 +63,8 @@ load_info (FileData *fd)
GError *error = NULL;
GTimeVal tv;
- if (fd->display_name)
- g_free (fd->display_name);
-
gfile = gfile_new (fd->path);
info = g_file_query_info (gfile,
- G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
G_FILE_ATTRIBUTE_STANDARD_SIZE ","
G_FILE_ATTRIBUTE_TIME_CHANGED ","
G_FILE_ATTRIBUTE_TIME_MODIFIED ","
@@ -83,7 +79,6 @@ load_info (FileData *fd)
fd->ctime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CHANGED);
g_file_info_get_modification_time (info, &tv);
fd->mtime = tv.tv_sec;
- fd->display_name = g_strdup (g_file_info_get_display_name (info));
fd->can_read = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ);
fd->mime_type = get_static_string (g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE));
g_object_unref (info);
@@ -94,7 +89,6 @@ load_info (FileData *fd)
fd->size = (goffset) 0;
fd->ctime = (time_t) 0;
fd->mtime = (time_t) 0;
- fd->display_name = get_utf8_display_name_from_uri (fd->name);
fd->can_read = TRUE;
}
@@ -112,6 +106,8 @@ file_data_new (const char *path)
fd->ref = 1;
fd->path = add_scheme_if_absent (path);
fd->name = file_name_from_path (fd->path);
+ fd->utf8_path = get_utf8_display_name_from_uri (fd->path);
+ fd->utf8_name = file_name_from_path (fd->utf8_path);
load_info (fd);
@@ -152,7 +148,9 @@ file_data_dup (FileData *source)
fd->ref = 1;
fd->path = g_strdup (source->path);
fd->name = file_name_from_path (fd->path);
- fd->display_name = g_strdup (source->display_name);
+ fd->utf8_path = g_strdup (source->utf8_path);
+ fd->utf8_name = file_name_from_path (fd->utf8_path);
+
fd->mime_type = get_static_string (source->mime_type);
fd->size = source->size;
fd->ctime = source->ctime;
@@ -180,7 +178,7 @@ file_data_unref (FileData *fd)
if (fd->ref == 0) {
g_free (fd->path);
- g_free (fd->display_name);
+ g_free (fd->utf8_path);
if (fd->comment_data != NULL)
comment_data_free (fd->comment_data);
g_free (fd->comment);
@@ -199,6 +197,7 @@ file_data_update (FileData *fd)
fd->thumb_loaded = FALSE;
fd->thumb_created = FALSE;
fd->name = file_name_from_path (fd->path);
+ fd->utf8_name = file_name_from_path (fd->utf8_path);
load_info (fd);
@@ -232,6 +231,8 @@ file_data_set_path (FileData *fd,
g_free (fd->path);
fd->path = g_strdup (path);
+ g_free (fd->utf8_path);
+ fd->utf8_path = get_utf8_display_name_from_uri (fd->path);
file_data_update (fd);
}
diff --git a/libgthumb/file-data.h b/libgthumb/file-data.h
index b365fc0..5da8f52 100644
--- a/libgthumb/file-data.h
+++ b/libgthumb/file-data.h
@@ -34,7 +34,8 @@ typedef struct {
char *path; /* Full path name. */
const char *name; /* File name only. */
- char *display_name;
+ char *utf8_path;
+ const char *utf8_name;
const char *mime_type;
goffset size;
time_t ctime;
diff --git a/libgthumb/gth-file-list.c b/libgthumb/gth-file-list.c
index 2f177a1..bc1a0b5 100644
--- a/libgthumb/gth-file-list.c
+++ b/libgthumb/gth-file-list.c
@@ -1112,7 +1112,7 @@ add_list_in_chunks (gpointer callback_data)
if (pixbuf != NULL) {
gth_file_view_append_with_data (file_list->view,
pixbuf,
- fd->display_name,
+ fd->utf8_name,
fd->comment,
fd);
g_object_unref (pixbuf);
@@ -1683,7 +1683,7 @@ gfl_rename (GthFileList *file_list,
pos = gth_file_list_pos_from_path (file_list, from_uri);
if (pos != -1) {
- gth_file_view_set_image_text (file_list->view, pos, fd->display_name);
+ gth_file_view_set_image_text (file_list->view, pos, fd->utf8_name);
gth_file_view_sorted (file_list->view,
file_list->priv->sort_method,
file_list->priv->sort_type);
diff --git a/libgthumb/gth-filter.c b/libgthumb/gth-filter.c
index ecfcefd..55ae2de 100644
--- a/libgthumb/gth-filter.c
+++ b/libgthumb/gth-filter.c
@@ -313,7 +313,7 @@ gth_test_match (GthTest *test,
switch (test->scope) {
case GTH_TEST_SCOPE_FILENAME:
- result = test_string (test, fdata->display_name);
+ result = test_string (test, fdata->utf8_name);
break;
case GTH_TEST_SCOPE_COMMENT:
@@ -333,7 +333,7 @@ gth_test_match (GthTest *test,
case GTH_TEST_SCOPE_ALL:
file_data_load_comment_data (fdata);
if (fdata->comment_data != NULL) {
- result = (test_string (test, fdata->display_name)
+ result = (test_string (test, fdata->utf8_name)
|| test_string (test, fdata->comment_data->comment)
|| test_string (test, fdata->comment_data->place));
if (! result && (fdata->comment_data != NULL))
diff --git a/libgthumb/print-callbacks.c b/libgthumb/print-callbacks.c
index bfebbe3..569d9c6 100644
--- a/libgthumb/print-callbacks.c
+++ b/libgthumb/print-callbacks.c
@@ -653,16 +653,13 @@ construct_comment (PrintCatalogInfo *pci,
if (pci->print_filenames) {
const gchar* end = NULL;
- char *unescaped;
- unescaped = get_utf8_display_name_from_uri (image->file->path);
- g_utf8_validate (unescaped, -1, &end);
- if (end > unescaped) {
+ g_utf8_validate (image->file->utf8_path, -1, &end);
+ if (end > image->file->utf8_path) {
if (s->len > 0)
g_string_append (s, "\n");
- g_string_append_len (s, unescaped, end - unescaped);
+ g_string_append_len (s, image->file->utf8_path, end - image->file->utf8_path);
}
- g_free (unescaped);
}
if (s->len > 0) {
diff --git a/src/catalog-png-exporter.c b/src/catalog-png-exporter.c
index c100336..7e46c4d 100644
--- a/src/catalog-png-exporter.c
+++ b/src/catalog-png-exporter.c
@@ -818,8 +818,7 @@ set_item_caption (CatalogPngExporter *ce,
if ((ce->caption_fields & GTH_CAPTION_FILE_PATH)
&& (ce->caption_fields & GTH_CAPTION_FILE_NAME)) {
- char *utf8_name = get_utf8_display_name_from_uri (idata->file->path);
- idata->caption_row[row++] = utf8_name;
+ idata->caption_row[row++] = g_strdup (idata->file->utf8_path);
}
else {
if (ce->caption_fields & GTH_CAPTION_FILE_PATH) {
@@ -829,9 +828,7 @@ set_item_caption (CatalogPngExporter *ce,
g_free (path);
}
else if (ce->caption_fields & GTH_CAPTION_FILE_NAME) {
- const char *name = file_name_from_path (idata->file->path);
- char *utf8_name = get_utf8_display_name_from_uri (name);
- idata->caption_row[row++] = utf8_name;
+ idata->caption_row[row++] = g_strdup (idata->file->utf8_name);;
}
}
@@ -1420,7 +1417,7 @@ load_next_file (CatalogPngExporter *ce)
idata = IMAGE_DATA (ce->file_to_load->data);
g_free (ce->info);
- ce->info = g_strdup_printf (_("Loading image: %s"), idata->file->display_name);
+ ce->info = g_strdup_printf (_("Loading image: %s"), idata->file->utf8_name);
g_signal_emit (G_OBJECT (ce), catalog_png_exporter_signals[PNG_EXPORTER_INFO],
0,
ce->info);
diff --git a/src/dlg-jpegtran.c b/src/dlg-jpegtran.c
index 61141b7..f7ee18e 100644
--- a/src/dlg-jpegtran.c
+++ b/src/dlg-jpegtran.c
@@ -405,12 +405,9 @@ static void
apply_transformation_to_all__apply_to_current (BatchTransformation *bt_data)
{
FileData *file = bt_data->scan->data;
- char *name;
if (bt_data->cancel == FALSE) {
- name = basename_for_display (file->path);
- _gtk_label_set_filename_text (GTK_LABEL (bt_data->label), name);
- g_free (name);
+ _gtk_label_set_filename_text (GTK_LABEL (bt_data->label), file->utf8_name);
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (bt_data->bar),
(gdouble) (bt_data->i + 0.5) / bt_data->n);
diff --git a/src/dlg-rename-series.c b/src/dlg-rename-series.c
index baf1a45..6689f67 100644
--- a/src/dlg-rename-series.c
+++ b/src/dlg-rename-series.c
@@ -443,18 +443,15 @@ update_list (DialogData *data)
FileData *fdata = on_scan->data;
char *new_name = nn_scan->data;
GtkTreeIter iter;
- char *utf8_on;
char *utf8_nn;
gtk_list_store_append (data->rs_list_model, &iter);
- utf8_on = get_utf8_display_name_from_uri (fdata->name);
utf8_nn = get_utf8_display_name_from_uri (new_name);
gtk_list_store_set (data->rs_list_model, &iter,
- RS_OLDNAME_COLUMN, utf8_on,
+ RS_OLDNAME_COLUMN, fdata->utf8_name,
RS_NEWNAME_COLUMN, utf8_nn,
-1);
- g_free (utf8_on);
g_free (utf8_nn);
nn_scan = nn_scan->next;
@@ -634,17 +631,14 @@ dlg_rename_series (GthBrowser *browser)
FileData *fd = data->original_file_list->data;
const char *last_dot;
glong last_dot_pos;
- char *template;
- template = get_utf8_display_name_from_uri (fd->name);
- gtk_entry_set_text (GTK_ENTRY (data->rs_template_entry), template);
- last_dot = g_utf8_strrchr (template, -1, '.');
+ gtk_entry_set_text (GTK_ENTRY (data->rs_template_entry), fd->utf8_name);
+ last_dot = g_utf8_strrchr (fd->utf8_name, -1, '.');
if (last_dot != NULL)
last_dot_pos = g_utf8_strlen (last_dot, -1);
else
last_dot_pos = 0;
- gtk_editable_select_region (GTK_EDITABLE (data->rs_template_entry), 0, g_utf8_strlen (template, -1) - last_dot_pos);
- g_free (template);
+ gtk_editable_select_region (GTK_EDITABLE (data->rs_template_entry), 0, g_utf8_strlen (fd->utf8_name, -1) - last_dot_pos);
}
else {
char *template;
diff --git a/src/dlg-reset-exif.c b/src/dlg-reset-exif.c
index a0663fc..3cac454 100644
--- a/src/dlg-reset-exif.c
+++ b/src/dlg-reset-exif.c
@@ -226,12 +226,9 @@ static void
apply_transformation_to_all__apply_to_current (BatchTransformation *bt_data)
{
FileData *file = bt_data->scan->data;
- char *name;
if (bt_data->cancel == FALSE) {
- name = basename_for_display (file->path);
- _gtk_label_set_filename_text (GTK_LABEL (bt_data->label), name);
- g_free (name);
+ _gtk_label_set_filename_text (GTK_LABEL (bt_data->label), file->utf8_name);
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (bt_data->bar),
(gdouble) (bt_data->i + 0.5) / bt_data->n);
diff --git a/src/gth-browser.c b/src/gth-browser.c
index e6d4f9e..642631f 100644
--- a/src/gth-browser.c
+++ b/src/gth-browser.c
@@ -571,7 +571,6 @@ window_update_infobar (GthBrowser *browser)
GthBrowserPrivateData *priv = browser->priv;
char *text;
char *escaped_name;
- char *display_name;
int images, current;
if (priv->image == NULL) {
@@ -582,8 +581,7 @@ window_update_infobar (GthBrowser *browser)
images = gth_file_view_get_images (priv->file_list->view);
current = gth_file_list_pos_from_path (priv->file_list, priv->image->path) + 1;
- display_name = basename_for_display (priv->image->path);
- escaped_name = g_markup_escape_text (display_name, -1);
+ escaped_name = g_markup_escape_text (priv->image->utf8_name, -1);
text = g_strdup_printf ("%d/%d - <b>%s</b> %s",
current,
@@ -593,7 +591,6 @@ window_update_infobar (GthBrowser *browser)
gthumb_info_bar_set_text (GTHUMB_INFO_BAR (priv->info_bar), text, NULL);
- g_free (display_name);
g_free (escaped_name);
g_free (text);
}
@@ -635,10 +632,8 @@ window_update_title (GthBrowser *browser)
info_txt = g_strdup_printf ("%s", _("gThumb"));
}
else {
- char *image_name;
int images, current;
- image_name = basename_for_display (priv->image->path);
images = gth_file_view_get_images (priv->file_list->view);
current = gth_file_list_pos_from_path (priv->file_list, priv->image->path) + 1;
@@ -649,7 +644,7 @@ window_update_title (GthBrowser *browser)
cat_name[strlen (cat_name) - 4] = 0;
info_txt = g_strdup_printf ("%s %s (%d/%d) - %s",
- image_name,
+ priv->image->utf8_name,
modified,
current,
images,
@@ -658,12 +653,10 @@ window_update_title (GthBrowser *browser)
}
else
info_txt = g_strdup_printf ("%s %s (%d/%d)",
- image_name,
+ priv->image->utf8_name,
modified,
current,
images);
-
- g_free (image_name);
}
gtk_window_set_title (GTK_WINDOW (browser), info_txt);
diff --git a/src/gth-exif-data-viewer.c b/src/gth-exif-data-viewer.c
index aa47435..62960ab 100644
--- a/src/gth-exif-data-viewer.c
+++ b/src/gth-exif-data-viewer.c
@@ -299,8 +299,6 @@ add_to_display (GthMetadata *entry,
static void
update_file_info (GthExifDataViewer *edv)
{
- char *utf8_name;
- char *utf8_fullname;
int width, height;
char *size_txt;
time_t mtime;
@@ -314,9 +312,6 @@ update_file_info (GthExifDataViewer *edv)
if (edv->priv->viewer == NULL)
return;
- utf8_name = basename_for_display (edv->priv->file->path);
- utf8_fullname = get_utf8_display_name_from_uri (edv->priv->file->path);
-
if (!image_viewer_is_void (IMAGE_VIEWER (edv->priv->viewer))) {
width = image_viewer_get_image_width (edv->priv->viewer);
height = image_viewer_get_image_height (edv->priv->viewer);
@@ -340,8 +335,10 @@ update_file_info (GthExifDataViewer *edv)
/**/
- add_to_exif_display_list (edv, GTH_METADATA_CATEGORY_FILE, NULL, _("Name"), utf8_name, NULL, -7, FALSE);
- add_to_exif_display_list (edv, GTH_METADATA_CATEGORY_FILE, NULL, _("Path"), utf8_fullname, NULL, -6, FALSE);
+ add_to_exif_display_list (edv, GTH_METADATA_CATEGORY_FILE, NULL, _("Name"),
+ edv->priv->file->utf8_name, NULL, -7, FALSE);
+ add_to_exif_display_list (edv, GTH_METADATA_CATEGORY_FILE, NULL, _("Path"),
+ edv->priv->file->utf8_path, NULL, -6, FALSE);
if (mime_type_is_image (mime_type))
add_to_exif_display_list (edv, GTH_METADATA_CATEGORY_FILE, NULL, _("Dimensions"), size_txt, NULL, -5, FALSE);
@@ -353,8 +350,6 @@ update_file_info (GthExifDataViewer *edv)
/**/
g_free (utf8_time_txt);
- g_free (utf8_name);
- g_free (utf8_fullname);
g_free (size_txt);
g_free (file_size_txt);
g_free (mime_description);
diff --git a/src/gth-viewer.c b/src/gth-viewer.c
index 265e000..65d0099 100644
--- a/src/gth-viewer.c
+++ b/src/gth-viewer.c
@@ -694,9 +694,7 @@ viewer_update_title (GthViewer *viewer)
if (viewer->priv->image == NULL)
title = g_strdup (_("No image"));
else {
- char *image_name = basename_for_display (viewer->priv->image->path);
- title = g_strdup_printf ("%s %s", image_name, modified);
- g_free (image_name);
+ title = g_strdup_printf ("%s %s", viewer->priv->image->utf8_name, modified);
}
gtk_window_set_title (GTK_WINDOW (viewer), title);
diff --git a/src/rotation-utils.c b/src/rotation-utils.c
index 9533c50..f868cc6 100644
--- a/src/rotation-utils.c
+++ b/src/rotation-utils.c
@@ -79,7 +79,6 @@ ask_whether_to_trim (GtkWindow *parent_window,
gpointer done_data)
{
AskTrimData *data;
- char *display_name;
char *msg;
/* If the user disabled the warning dialog trim the image */
@@ -107,8 +106,7 @@ ask_whether_to_trim (GtkWindow *parent_window,
gtk_window_set_modal (data->parent_window, FALSE);
}
- display_name = basename_for_display (file->path);
- msg = g_strdup_printf (_("Problem transforming the image: %s"), display_name);
+ msg = g_strdup_printf (_("Problem transforming the image: %s"), file->utf8_name);
data->dialog = _gtk_message_dialog_with_checkbutton_new (parent_window,
GTK_DIALOG_MODAL,
GTK_STOCK_DIALOG_WARNING,
@@ -125,7 +123,6 @@ ask_whether_to_trim (GtkWindow *parent_window,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
- g_free (display_name);
g_free (msg);
g_signal_connect (G_OBJECT (data->dialog), "response",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]