[gthumb] Simplified the file list code adding a custom caption cell renderer
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] Simplified the file list code adding a custom caption cell renderer
- Date: Sat, 5 Nov 2011 18:44:11 +0000 (UTC)
commit b23b574ea18250e5881ed4087e3550ac508a7ac1
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sat Nov 5 14:44:44 2011 +0100
Simplified the file list code adding a custom caption cell renderer
gthumb/Makefile.am | 2 +
gthumb/gth-cell-renderer-caption.c | 374 ++++++++++++++++++++++++++++++++++++
gthumb/gth-cell-renderer-caption.h | 55 ++++++
gthumb/gth-file-list.c | 114 ++----------
gthumb/gth-file-store.c | 41 +----
gthumb/gth-file-store.h | 4 -
gthumb/gth-icon-view.c | 5 -
7 files changed, 446 insertions(+), 149 deletions(-)
---
diff --git a/gthumb/Makefile.am b/gthumb/Makefile.am
index 2b6f48a..6344504 100644
--- a/gthumb/Makefile.am
+++ b/gthumb/Makefile.am
@@ -37,6 +37,7 @@ PUBLIC_HEADER_FILES = \
gth-async-task.h \
gth-buffer-data.h \
gth-browser.h \
+ gth-cell-renderer-caption.h \
gth-cell-renderer-thumbnail.h \
gth-dumb-notebook.h \
gth-duplicable.h \
@@ -161,6 +162,7 @@ gthumb_SOURCES = \
gth-browser.c \
gth-browser-actions-callbacks.c \
gth-buffer-data.c \
+ gth-cell-renderer-caption.c \
gth-cell-renderer-thumbnail.c \
gth-dumb-notebook.c \
gth-duplicable.c \
diff --git a/gthumb/gth-cell-renderer-caption.c b/gthumb/gth-cell-renderer-caption.c
new file mode 100644
index 0000000..3c992d5
--- /dev/null
+++ b/gthumb/gth-cell-renderer-caption.c
@@ -0,0 +1,374 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include "gth-cell-renderer-caption.h"
+#include "gth-file-data.h"
+#include "glib-utils.h"
+
+
+#define LINE_SPACING 4
+
+
+enum {
+ PROP_0,
+ PROP_FILE,
+ PROP_FILE_ATTRIBUTES
+};
+
+
+struct _GthCellRendererCaptionPrivate
+{
+ GthFileData *file;
+ char *attributes;
+ char **attributes_v;
+ char *text;
+ GHashTable *heights_cache;
+ int last_width;
+};
+
+
+G_DEFINE_TYPE (GthCellRendererCaption, gth_cell_renderer_caption, GTK_TYPE_CELL_RENDERER)
+
+
+static void
+gth_cell_renderer_caption_finalize (GObject *object)
+{
+ GthCellRendererCaption *self = GTH_CELL_RENDERER_CAPTION (object);
+
+ g_strfreev (self->priv->attributes_v);
+ g_free (self->priv->attributes);
+ _g_object_unref (self->priv->file);
+ g_free (self->priv->text);
+ g_hash_table_destroy (self->priv->heights_cache);
+
+ G_OBJECT_CLASS (gth_cell_renderer_caption_parent_class)->finalize (object);
+}
+
+
+static void
+gth_cell_renderer_caption_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GthCellRendererCaption *self = (GthCellRendererCaption *) object;
+
+ switch (param_id) {
+ case PROP_FILE:
+ g_value_set_object (value, self->priv->file);
+ break;
+
+ case PROP_FILE_ATTRIBUTES:
+ g_value_set_string (value, self->priv->attributes);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+}
+
+
+static void
+_gth_cell_renderer_caption_set_attributes (GthCellRendererCaption *self,
+ const char *attributes)
+{
+ g_free (self->priv->attributes);
+ self->priv->attributes = g_strdup (attributes);
+
+ if (self->priv->attributes_v != NULL) {
+ g_strfreev (self->priv->attributes_v);
+ self->priv->attributes_v = NULL;
+ }
+ if (self->priv->attributes != NULL)
+ self->priv->attributes_v = g_strsplit (self->priv->attributes, ",", -1);
+}
+
+
+#define MAX_TEXT_LENGTH 70
+#define ODD_ROW_ATTR_STYLE ""
+#define EVEN_ROW_ATTR_STYLE " style='italic'"
+
+
+static void
+_gth_cell_renderer_caption_update_text (GthCellRendererCaption *self)
+{
+ GString *metadata;
+ gboolean odd;
+ int i;
+
+ g_free (self->priv->text);
+ self->priv->text = NULL;
+
+ if ((self->priv->file == NULL)
+ || (self->priv->attributes_v == NULL)
+ || g_str_equal (self->priv->attributes_v[0], "none"))
+ {
+ return;
+ }
+
+ metadata = g_string_new (NULL);
+
+ odd = TRUE;
+ for (i = 0; self->priv->attributes_v[i] != NULL; i++) {
+ char *value;
+
+ value = gth_file_data_get_attribute_as_string (self->priv->file, self->priv->attributes_v[i]);
+ if ((value != NULL) && ! g_str_equal (value, "")) {
+ char *escaped;
+
+ if (metadata->len > 0)
+ g_string_append (metadata, "\n");
+ if (g_utf8_strlen (value, -1) > MAX_TEXT_LENGTH) {
+ char *tmp;
+
+ tmp = g_strdup (value);
+ g_utf8_strncpy (tmp, value, MAX_TEXT_LENGTH);
+ g_free (value);
+ value = g_strdup_printf ("%sâ", tmp);
+
+ g_free (tmp);
+ }
+
+ escaped = g_markup_escape_text (value, -1);
+ g_string_append_printf (metadata, "<span%s>%s</span>", (odd ? ODD_ROW_ATTR_STYLE : EVEN_ROW_ATTR_STYLE), value);
+
+ g_free (escaped);
+ }
+ odd = ! odd;
+
+ g_free (value);
+ }
+
+ self->priv->text = g_string_free (metadata, FALSE);
+}
+
+
+static void
+gth_cell_renderer_caption_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GthCellRendererCaption *self = (GthCellRendererCaption *) object;
+
+ switch (param_id) {
+ case PROP_FILE:
+ if (self->priv->file != NULL)
+ g_object_unref (self->priv->file);
+ self->priv->file = g_value_dup_object (value);
+ _gth_cell_renderer_caption_update_text (self);
+ break;
+
+ case PROP_FILE_ATTRIBUTES:
+ _gth_cell_renderer_caption_set_attributes (self, g_value_get_string (value));
+ _gth_cell_renderer_caption_update_text (self);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+}
+
+
+static GtkSizeRequestMode
+gth_cell_renderer_caption_get_request_mode (GtkCellRenderer *cell)
+{
+ return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
+}
+
+
+static void
+gth_cell_renderer_caption_get_preferred_width (GtkCellRenderer *cell,
+ GtkWidget *widget,
+ int *minimum_size,
+ int *natural_size)
+{
+ GthCellRendererCaption *self = (GthCellRendererCaption *) cell;
+ int width;
+
+ width = 0;
+ g_object_get (cell, "width", &width, NULL);
+
+ if (self->priv->last_width != width) {
+ self->priv->last_width = width;
+ g_hash_table_remove_all (self->priv->heights_cache);
+ }
+
+ if (minimum_size) *minimum_size = width;
+ if (natural_size) *natural_size = width;
+}
+
+
+static PangoLayout *
+_gth_cell_renderer_caption_create_pango_layout (GthCellRendererCaption *self,
+ GtkWidget *widget,
+ const char *text)
+{
+ PangoLayout *pango_layout;
+
+ pango_layout = gtk_widget_create_pango_layout (widget, NULL);
+ pango_layout_set_markup (pango_layout, text, -1);
+ pango_layout_set_wrap (pango_layout, PANGO_WRAP_WORD_CHAR);
+ pango_layout_set_alignment (pango_layout, PANGO_ALIGN_CENTER);
+ pango_layout_set_spacing (pango_layout, LINE_SPACING);
+
+ return pango_layout;
+}
+
+
+static void
+gth_cell_renderer_caption_get_preferred_height_for_width (GtkCellRenderer *cell,
+ GtkWidget *widget,
+ int width,
+ int *minimum_height,
+ int *natural_height)
+{
+ GthCellRendererCaption *self = (GthCellRendererCaption *) cell;
+ int height;
+
+ height = 0;
+
+ if ((self->priv->text != NULL) && ! g_str_equal (self->priv->text, "")) {
+ int *height_p;
+
+ height_p = g_hash_table_lookup (self->priv->heights_cache, self->priv->text);
+ if (height_p != NULL) {
+ height = GPOINTER_TO_INT (height_p);
+ }
+ else {
+ PangoLayout *pango_layout;
+
+ pango_layout = _gth_cell_renderer_caption_create_pango_layout (self, widget, self->priv->text);
+ pango_layout_set_width (pango_layout, width * PANGO_SCALE);
+ pango_layout_get_pixel_size (pango_layout, &width, &height);
+
+ g_hash_table_insert (self->priv->heights_cache,
+ g_strdup (self->priv->text),
+ GINT_TO_POINTER (height));
+
+ g_object_unref (pango_layout);
+ }
+ }
+
+ if (minimum_height) *minimum_height = height;
+ if (natural_height) *natural_height = height;
+}
+
+
+static void
+gth_cell_renderer_caption_render (GtkCellRenderer *cell,
+ cairo_t *cr,
+ GtkWidget *widget,
+ const GdkRectangle *background_area,
+ const GdkRectangle *cell_area,
+ GtkCellRendererState cell_state)
+{
+ GthCellRendererCaption *self = (GthCellRendererCaption *) cell;
+ PangoLayout *pango_layout;
+ GtkStyleContext *style_context;
+ GdkRGBA foreground_color;
+
+ if (self->priv->text == NULL)
+ return;
+
+ pango_layout = _gth_cell_renderer_caption_create_pango_layout (self, widget, self->priv->text);
+ pango_layout_set_width (pango_layout, cell_area->width * PANGO_SCALE);
+
+ style_context = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_color (style_context, gtk_widget_get_state_flags (widget), &foreground_color);
+ gdk_cairo_set_source_rgba (cr, &foreground_color);
+ cairo_move_to (cr, cell_area->x, cell_area->y);
+ pango_cairo_show_layout (cr, pango_layout);
+
+ g_object_unref (pango_layout);
+}
+
+
+static void
+gth_cell_renderer_caption_class_init (GthCellRendererCaptionClass *klass)
+{
+ GObjectClass *object_class;
+ GtkCellRendererClass *cell_renderer;
+
+ g_type_class_add_private (klass, sizeof (GthCellRendererCaptionPrivate));
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = gth_cell_renderer_caption_finalize;
+ object_class->get_property = gth_cell_renderer_caption_get_property;
+ object_class->set_property = gth_cell_renderer_caption_set_property;
+
+ cell_renderer = GTK_CELL_RENDERER_CLASS (klass);
+ cell_renderer->get_request_mode = gth_cell_renderer_caption_get_request_mode;
+ cell_renderer->get_preferred_width = gth_cell_renderer_caption_get_preferred_width;
+ cell_renderer->get_preferred_height_for_width = gth_cell_renderer_caption_get_preferred_height_for_width;
+ cell_renderer->render = gth_cell_renderer_caption_render;
+
+ /* properties */
+
+ g_object_class_install_property (object_class,
+ PROP_FILE,
+ g_param_spec_object ("file",
+ "File",
+ "The file data",
+ GTH_TYPE_FILE_DATA,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_FILE_ATTRIBUTES,
+ g_param_spec_string ("file-attributes",
+ "File attributes",
+ "The attributes to display, separated by a comma",
+ NULL,
+ G_PARAM_READWRITE));
+}
+
+
+static void
+gth_cell_renderer_caption_init (GthCellRendererCaption *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_CELL_RENDERER_CAPTION, GthCellRendererCaptionPrivate);
+ self->priv->file = NULL;
+ self->priv->attributes = NULL;
+ self->priv->attributes_v = NULL;
+ self->priv->text = NULL;
+ self->priv->heights_cache = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ NULL);
+ self->priv->last_width = 0;
+}
+
+
+GtkCellRenderer *
+gth_cell_renderer_caption_new (void)
+{
+ return g_object_new (GTH_TYPE_CELL_RENDERER_CAPTION, NULL);
+}
+
+
+void
+gth_cell_renderer_caption_clear_cache (GthCellRendererCaption *self)
+{
+ self->priv->last_width = 0;
+ g_hash_table_remove_all (self->priv->heights_cache);
+}
diff --git a/gthumb/gth-cell-renderer-caption.h b/gthumb/gth-cell-renderer-caption.h
new file mode 100644
index 0000000..7c0e4b2
--- /dev/null
+++ b/gthumb/gth-cell-renderer-caption.h
@@ -0,0 +1,55 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTH_CELL_RENDERER_CAPTION_H
+#define GTH_CELL_RENDERER_CAPTION_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTH_TYPE_CELL_RENDERER_CAPTION (gth_cell_renderer_caption_get_type ())
+#define GTH_CELL_RENDERER_CAPTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_CELL_RENDERER_CAPTION, GthCellRendererCaption))
+#define GTH_CELL_RENDERER_CAPTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTH_TYPE_CELL_RENDERER_CAPTION, GthCellRendererCaptionClass))
+#define GTH_IS_CELL_RENDERER_CAPTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTH_TYPE_CELL_RENDERER_CAPTION))
+#define GTH_IS_CELL_RENDERER_CAPTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTH_TYPE_CELL_RENDERER_CAPTION))
+#define GTH_CELL_RENDERER_CAPTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTH_TYPE_CELL_RENDERER_CAPTION, GthCellRendererCaptionClass))
+
+typedef struct _GthCellRendererCaption GthCellRendererCaption;
+typedef struct _GthCellRendererCaptionClass GthCellRendererCaptionClass;
+typedef struct _GthCellRendererCaptionPrivate GthCellRendererCaptionPrivate;
+
+struct _GthCellRendererCaption {
+ GtkCellRenderer parent_instance;
+ GthCellRendererCaptionPrivate * priv;
+};
+
+struct _GthCellRendererCaptionClass {
+ GtkCellRendererClass parent_class;
+};
+
+GType gth_cell_renderer_caption_get_type (void);
+GtkCellRenderer * gth_cell_renderer_caption_new (void);
+void gth_cell_renderer_caption_clear_cache (GthCellRendererCaption *self);
+
+G_END_DECLS
+
+#endif /* GTH_CELL_RENDERER_CAPTION_H */
diff --git a/gthumb/gth-file-list.c b/gthumb/gth-file-list.c
index 8396223..99305d7 100644
--- a/gthumb/gth-file-list.c
+++ b/gthumb/gth-file-list.c
@@ -25,6 +25,7 @@
#include <gtk/gtk.h>
#include "gconf-utils.h"
#include "glib-utils.h"
+#include "gth-cell-renderer-caption.h"
#include "gth-cell-renderer-thumbnail.h"
#include "gth-dumb-notebook.h"
#include "gth-empty-list.h"
@@ -127,9 +128,8 @@ struct _GthFileListPrivateData
GList *queue; /* list of GthFileListOp */
GList *jobs; /* list of ThumbnailJob */
GtkCellRenderer *thumbnail_renderer;
- GtkCellRenderer *text_renderer;
+ GtkCellRenderer *caption_renderer;
GtkCellRenderer *checkbox_renderer;
- char **caption_attributes_v;
gboolean cancelling;
guint update_event;
gboolean visibility_changed;
@@ -269,7 +269,6 @@ gth_file_list_finalize (GObject *object)
g_hash_table_unref (file_list->priv->thumb_data);
if (file_list->priv->icon_cache != NULL)
gth_icon_cache_free (file_list->priv->icon_cache);
- g_strfreev (file_list->priv->caption_attributes_v);
g_free (file_list->priv);
file_list->priv = NULL;
@@ -387,7 +386,6 @@ gth_file_list_init (GthFileList *file_list)
file_list->priv->thumb_size = DEFAULT_THUMBNAIL_SIZE;
file_list->priv->ignore_hidden_thumbs = FALSE;
file_list->priv->load_thumbs = TRUE;
- file_list->priv->caption_attributes_v = g_strsplit ("none", ",", -1);
file_list->priv->cancelling = FALSE;
file_list->priv->update_event = 0;
file_list->priv->visibles = NULL;
@@ -747,23 +745,22 @@ gth_file_list_construct (GthFileList *file_list,
"checked",
GTH_FILE_STORE_CHECKED_COLUMN);
- /* text */
+ /* caption */
- file_list->priv->text_renderer = renderer = gtk_cell_renderer_text_new ();
+ file_list->priv->caption_renderer = renderer = gth_cell_renderer_caption_new ();
cell_layout = gth_file_view_add_renderer (GTH_FILE_VIEW (file_list->priv->view),
GTH_FILE_VIEW_RENDERER_TEXT,
- file_list->priv->text_renderer);
+ file_list->priv->caption_renderer);
gtk_cell_layout_set_attributes (cell_layout,
renderer,
- "text", GTH_FILE_STORE_METADATA_COLUMN,
- "visible", GTH_FILE_STORE_METADATA_VISIBLE_COLUMN,
+ "file", GTH_FILE_STORE_FILE_DATA_COLUMN,
NULL);
gth_file_view_update_attributes (GTH_FILE_VIEW (file_list->priv->view),
file_list->priv->checkbox_renderer,
file_list->priv->thumbnail_renderer,
- file_list->priv->text_renderer,
+ file_list->priv->caption_renderer,
file_list->priv->thumb_size);
_gth_file_list_set_type (file_list, list_type);
@@ -909,6 +906,7 @@ gfl_clear_list (GthFileList *file_list,
gth_file_selection_unselect_all (GTH_FILE_SELECTION (file_list->priv->view));
file_store = (GthFileStore*) gth_file_view_get_model (GTH_FILE_VIEW (file_list->priv->view));
+ gth_cell_renderer_caption_clear_cache (GTH_CELL_RENDERER_CAPTION (file_list->priv->caption_renderer));
gth_file_store_clear (file_store);
g_hash_table_remove_all (file_list->priv->thumb_data);
@@ -946,46 +944,6 @@ _gth_file_list_update_pane (GthFileList *file_list)
}
-#define MAX_TEXT_LENGTH 70
-
-
-static GString *
-_gth_file_list_get_metadata (GthFileList *file_list,
- GthFileData *file_data)
-{
- GString *metadata;
- int i;
-
- metadata = g_string_new (NULL);
- for (i = 0; file_list->priv->caption_attributes_v[i] != NULL; i++) {
- char *value;
-
- value = gth_file_data_get_attribute_as_string (file_data, file_list->priv->caption_attributes_v[i]);
- if (value != NULL) {
- if (metadata->len > 0)
- g_string_append (metadata, "\n");
- if (gth_file_view_truncate_metadata (GTH_FILE_VIEW (file_list->priv->view))
- && g_utf8_strlen (value, -1) > MAX_TEXT_LENGTH)
- {
- char *tmp;
-
- tmp = g_strdup (value);
- g_utf8_strncpy (tmp, value, MAX_TEXT_LENGTH);
- g_free (value);
- value = g_strdup_printf ("%s [â]", tmp);
-
- g_free (tmp);
- }
- g_string_append (metadata, value);
- }
-
- g_free (value);
- }
-
- return metadata;
-}
-
-
static void
gfl_add_files (GthFileList *file_list,
GList *files,
@@ -1004,7 +962,6 @@ gfl_add_files (GthFileList *file_list,
ThumbData *thumb_data;
GIcon *icon;
GdkPixbuf *pixbuf = NULL;
- GString *metadata;
if (g_file_info_get_file_type (file_data->info) != G_FILE_TYPE_REGULAR)
continue;
@@ -1025,18 +982,14 @@ gfl_add_files (GthFileList *file_list,
icon = g_file_info_get_icon (file_data->info);
pixbuf = gth_icon_cache_get_pixbuf (file_list->priv->icon_cache, icon);
- metadata = _gth_file_list_get_metadata (file_list, file_data);
gth_file_store_queue_add (file_store,
file_data,
pixbuf,
TRUE,
- metadata->str,
TRUE);
- g_string_free (metadata, TRUE);
if (pixbuf != NULL)
g_object_unref (pixbuf);
-
g_free (uri);
}
g_free (cache_base_uri);
@@ -1119,18 +1072,11 @@ gfl_update_files (GthFileList *file_list,
thumb_data->thumb_loaded = FALSE;
thumb_data->thumb_created = FALSE;
- if (gth_file_store_find (file_store, file_data->file, &iter)) {
- GString *metadata;
-
- metadata = _gth_file_list_get_metadata (file_list, file_data);
+ if (gth_file_store_find (file_store, file_data->file, &iter))
gth_file_store_queue_set (file_store,
&iter,
GTH_FILE_STORE_FILE_DATA_COLUMN, file_data,
- GTH_FILE_STORE_METADATA_COLUMN, metadata->str,
-1);
-
- g_string_free (metadata, TRUE);
- }
}
gth_file_store_exec_set (file_store);
_gth_file_list_update_pane (file_list);
@@ -1160,7 +1106,6 @@ gfl_rename_file (GthFileList *file_list,
file_store = (GthFileStore*) gth_file_view_get_model (GTH_FILE_VIEW (file_list->priv->view));
if (gth_file_store_find (file_store, file, &iter)) {
ThumbData *thumb_data;
- GString *metadata;
thumb_data = g_hash_table_lookup (file_list->priv->thumb_data, file);
g_assert (thumb_data != NULL);
@@ -1170,14 +1115,10 @@ gfl_rename_file (GthFileList *file_list,
thumb_data_ref (thumb_data));
g_hash_table_remove (file_list->priv->thumb_data, file);
- metadata = _gth_file_list_get_metadata (file_list, file_data);
gth_file_store_set (file_store,
&iter,
GTH_FILE_STORE_FILE_DATA_COLUMN, file_data,
- GTH_FILE_STORE_METADATA_COLUMN, metadata->str,
-1);
-
- g_string_free (metadata, TRUE);
}
_gth_file_list_update_pane (file_list);
}
@@ -1205,6 +1146,7 @@ gfl_set_files (GthFileList *file_list,
gth_thumb_loader_set_max_file_size (file_list->priv->thumb_loader, eel_gconf_get_integer (PREF_THUMBNAIL_LIMIT, 0));
gth_file_selection_unselect_all (GTH_FILE_SELECTION (file_list->priv->view));
+ gth_cell_renderer_caption_clear_cache (GTH_CELL_RENDERER_CAPTION (file_list->priv->caption_renderer));
gth_file_store_clear ((GthFileStore*) gth_file_view_get_model (GTH_FILE_VIEW (file_list->priv->view)));
g_hash_table_remove_all (file_list->priv->thumb_data);
gfl_add_files (file_list, files, -1);
@@ -1391,7 +1333,7 @@ gth_file_list_set_thumb_size (GthFileList *file_list,
gth_file_view_update_attributes (GTH_FILE_VIEW (file_list->priv->view),
file_list->priv->checkbox_renderer,
file_list->priv->thumbnail_renderer,
- file_list->priv->text_renderer,
+ file_list->priv->caption_renderer,
file_list->priv->thumb_size);
_gth_file_list_update_orientation (file_list);
@@ -1402,38 +1344,10 @@ void
gth_file_list_set_caption (GthFileList *file_list,
const char *attributes)
{
- GthFileStore *file_store;
- GtkTreeIter iter;
- gboolean metadata_visible;
-
- g_strfreev (file_list->priv->caption_attributes_v);
- file_list->priv->caption_attributes_v = g_strsplit (attributes, ",", -1);
-
- metadata_visible = (strcmp (file_list->priv->caption_attributes_v[0], "none") != 0);
- g_object_set (file_list->priv->text_renderer,
- "visible", metadata_visible,
- "height", metadata_visible ? -1 : 0,
+ g_object_set (file_list->priv->caption_renderer,
+ "file-attributes", attributes,
NULL);
-
- file_store = (GthFileStore *) gth_file_view_get_model (GTH_FILE_VIEW (file_list->priv->view));
- if (gth_file_store_get_first (file_store, &iter)) {
- do {
- GthFileData *file_data;
- GString *metadata;
-
- file_data = gth_file_store_get_file (file_store, &iter);
- metadata = _gth_file_list_get_metadata (file_list, file_data);
- gth_file_store_queue_set (file_store,
- &iter,
- GTH_FILE_STORE_METADATA_COLUMN, metadata->str,
- -1);
-
- g_string_free (metadata, TRUE);
- }
- while (gth_file_store_get_next (file_store, &iter));
-
- gth_file_store_exec_set (file_store);
- }
+ gtk_widget_queue_resize (file_list->priv->view);
}
diff --git a/gthumb/gth-file-store.c b/gthumb/gth-file-store.c
index 9b370de..948da3d 100644
--- a/gthumb/gth-file-store.c
+++ b/gthumb/gth-file-store.c
@@ -48,7 +48,6 @@ typedef struct {
GthFileData *file_data;
GdkPixbuf *thumbnail;
gboolean is_icon;
- char *metadata;
gboolean checked;
/*< private >*/
@@ -129,21 +128,6 @@ _gth_file_row_set_thumbnail (GthFileRow *row,
}
-static void
-_gth_file_row_set_metadata (GthFileRow *row,
- const char *metadata)
-{
- if (metadata == NULL)
- return;
-
- if (metadata == row->metadata)
- return;
-
- g_free (row->metadata);
- row->metadata = g_strdup (metadata);
-}
-
-
GthFileRow *
_gth_file_row_copy (GthFileRow *row)
{
@@ -152,7 +136,6 @@ _gth_file_row_copy (GthFileRow *row)
row2 = _gth_file_row_new ();
_gth_file_row_set_file (row2, row->file_data);
_gth_file_row_set_thumbnail (row2, row->thumbnail);
- _gth_file_row_set_metadata (row2, row->metadata);
row2->is_icon = row->is_icon;
row2->checked = row->checked;
row2->pos = row->pos;
@@ -182,7 +165,6 @@ _gth_file_row_unref (GthFileRow *row)
g_object_unref (row->file_data);
if (row->thumbnail != NULL)
g_object_unref (row->thumbnail);
- g_free (row->metadata);
g_free (row);
}
@@ -293,8 +275,6 @@ gth_file_store_init (GthFileStore *file_store)
column_type[GTH_FILE_STORE_THUMBNAIL_COLUMN] = GDK_TYPE_PIXBUF;
column_type[GTH_FILE_STORE_IS_ICON_COLUMN] = G_TYPE_BOOLEAN;
column_type[GTH_FILE_STORE_FILENAME_COLUMN] = G_TYPE_STRING;
- column_type[GTH_FILE_STORE_METADATA_COLUMN] = G_TYPE_STRING;
- column_type[GTH_FILE_STORE_METADATA_VISIBLE_COLUMN] = G_TYPE_BOOLEAN;
column_type[GTH_FILE_STORE_CHECKED_COLUMN] = G_TYPE_BOOLEAN;
}
}
@@ -411,14 +391,6 @@ gth_file_store_get_value (GtkTreeModel *tree_model,
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, g_file_info_get_display_name (row->file_data->info));
break;
- case GTH_FILE_STORE_METADATA_COLUMN:
- g_value_init (value, G_TYPE_STRING);
- g_value_set_string (value, row->metadata);
- break;
- case GTH_FILE_STORE_METADATA_VISIBLE_COLUMN:
- g_value_init (value, G_TYPE_BOOLEAN);
- g_value_set_boolean (value, (row->metadata != NULL) && ! g_str_equal (row->metadata, ""));
- break;
case GTH_FILE_STORE_CHECKED_COLUMN:
g_value_init (value, G_TYPE_BOOLEAN);
g_value_set_boolean (value, row->checked);
@@ -1416,11 +1388,10 @@ gth_file_store_add (GthFileStore *file_store,
GthFileData *file,
GdkPixbuf *thumbnail,
gboolean is_icon,
- const char *metadata,
gboolean checked,
int position)
{
- gth_file_store_queue_add (file_store, file, thumbnail, is_icon, metadata, checked);
+ gth_file_store_queue_add (file_store, file, thumbnail, is_icon, checked);
gth_file_store_exec_add (file_store, position);
}
@@ -1430,7 +1401,6 @@ gth_file_store_queue_add (GthFileStore *file_store,
GthFileData *file,
GdkPixbuf *thumbnail,
gboolean is_icon,
- const char *metadata,
gboolean checked)
{
GthFileRow *row;
@@ -1440,7 +1410,6 @@ gth_file_store_queue_add (GthFileStore *file_store,
row = _gth_file_row_new ();
_gth_file_row_set_file (row, file);
_gth_file_row_set_thumbnail (row, thumbnail);
- _gth_file_row_set_metadata (row, metadata);
row->is_icon = is_icon;
row->checked = checked;
@@ -1473,7 +1442,6 @@ gth_file_store_queue_set_valist (GthFileStore *file_store,
while (column != -1) {
GthFileData *file_data;
GdkPixbuf *thumbnail;
- const char *metadata;
switch (column) {
case GTH_FILE_STORE_FILE_DATA_COLUMN:
@@ -1493,13 +1461,6 @@ gth_file_store_queue_set_valist (GthFileStore *file_store,
row->is_icon = va_arg (var_args, gboolean);
row->changed = TRUE;
break;
- case GTH_FILE_STORE_METADATA_COLUMN:
- metadata = va_arg (var_args, const char *);
- _gth_file_row_set_metadata (row, metadata);
- row->changed = TRUE;
- break;
- case GTH_FILE_STORE_METADATA_VISIBLE_COLUMN:
- break;
case GTH_FILE_STORE_CHECKED_COLUMN:
row->checked = va_arg (var_args, gboolean);
row->changed = TRUE;
diff --git a/gthumb/gth-file-store.h b/gthumb/gth-file-store.h
index 6500923..7c1d707 100644
--- a/gthumb/gth-file-store.h
+++ b/gthumb/gth-file-store.h
@@ -44,8 +44,6 @@ enum {
GTH_FILE_STORE_THUMBNAIL_COLUMN,
GTH_FILE_STORE_IS_ICON_COLUMN,
GTH_FILE_STORE_FILENAME_COLUMN,
- GTH_FILE_STORE_METADATA_COLUMN,
- GTH_FILE_STORE_METADATA_VISIBLE_COLUMN,
GTH_FILE_STORE_CHECKED_COLUMN,
GTH_FILE_STORE_N_COLUMNS
};
@@ -106,14 +104,12 @@ void gth_file_store_add (GthFileStore *file_sto
GthFileData *file,
GdkPixbuf *thumbnail,
gboolean is_icon,
- const char *metadata,
gboolean checked,
int position);
void gth_file_store_queue_add (GthFileStore *file_store,
GthFileData *file,
GdkPixbuf *thumbnail,
gboolean is_icon,
- const char *metadata,
gboolean checked);
void gth_file_store_exec_add (GthFileStore *file_store,
int position);
diff --git a/gthumb/gth-icon-view.c b/gthumb/gth-icon-view.c
index 5e216d3..3b0d455 100644
--- a/gthumb/gth-icon-view.c
+++ b/gthumb/gth-icon-view.c
@@ -348,12 +348,7 @@ gth_icon_view_update_attributes (GthFileView *self,
"yalign", 0.0,
NULL);
g_object_set (text_renderer,
- "xalign", 0.5,
- "yalign", 0.0,
- "alignment", PANGO_ALIGN_CENTER,
"width", thumb_size + THUMBNAIL_BORDER,
- "wrap-mode", PANGO_WRAP_WORD_CHAR,
- "wrap-width", thumb_size + THUMBNAIL_BORDER,
NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]