Commit ec693d7b authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

app/config/gimpcoreconfig.[ch] added new gimprc option

2004-10-08  Sven Neumann  <sven@gimp.org>

	* app/config/gimpcoreconfig.[ch]
	* app/config/gimprc-blurbs.h: added new gimprc option
	"thumbnail-filesize-limit" that allows to control the maximum
	filesize for automatic thumbnail creation.

	* app/dialogs/preferences-dialog.c: added a GUI for it, needs
	review.

	* app/core/gimpimagefile.[ch]: minor cleanups. Moved call to
	gimp_thumbnail_peek_image() from gimp_imagefile_save_thumb() to
	 gimp_imagefile_save_thumbnail() to avoid it being called twice.

	* app/file/file-utils.[ch]: export utility function
	file_utils_find_proc_by_extension() that allows to check for a
	file plug-in by looking at the filename extension only.

	* app/widgets/gimpthumbbox.[ch]: automatically create or update
	thumbnails for image files with a known extension that are smaller
	than "thumbnail-filesize-limit".  Fixes bug #137176.
parent cc87c4c2
2004-10-08 Sven Neumann <sven@gimp.org>
* app/config/gimpcoreconfig.[ch]
* app/config/gimprc-blurbs.h: added new gimprc option
"thumbnail-filesize-limit" that allows to control the maximum
filesize for automatic thumbnail creation.
* app/dialogs/preferences-dialog.c: added a GUI for it, needs
review.
* app/core/gimpimagefile.[ch]: minor cleanups. Moved call to
gimp_thumbnail_peek_image() from gimp_imagefile_save_thumb() to
gimp_imagefile_save_thumbnail() to avoid it being called twice.
* app/file/file-utils.[ch]: export utility function
file_utils_find_proc_by_extension() that allows to check for a
file plug-in by looking at the filename extension only.
* app/widgets/gimpthumbbox.[ch]: automatically create or update
thumbnails for image files with a known extension that are smaller
than "thumbnail-filesize-limit". Fixes bug #137176.
2004-10-08 Sven Neumann <sven@gimp.org>
* plug-ins/common/ripple.c: handle the tile parameter identically
......
......@@ -104,6 +104,7 @@ enum
PROP_LAYER_PREVIEWS,
PROP_LAYER_PREVIEW_SIZE,
PROP_THUMBNAIL_SIZE,
PROP_THUMBNAIL_FILESIZE_LIMIT,
PROP_INSTALL_COLORMAP,
PROP_MIN_COLORS
};
......@@ -309,6 +310,11 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass)
GIMP_TYPE_THUMBNAIL_SIZE,
GIMP_THUMBNAIL_SIZE_NORMAL,
0);
GIMP_CONFIG_INSTALL_PROP_MEMSIZE (object_class, PROP_THUMBNAIL_FILESIZE_LIMIT,
"thumbnail-filesize-limit",
THUMBNAIL_FILESIZE_LIMIT_BLURB,
1, GIMP_MAX_MEMSIZE, 1 << 22,
0);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_INSTALL_COLORMAP,
"install-colormap", INSTALL_COLORMAP_BLURB,
FALSE,
......@@ -501,6 +507,9 @@ gimp_core_config_set_property (GObject *object,
case PROP_THUMBNAIL_SIZE:
core_config->thumbnail_size = g_value_get_enum (value);
break;
case PROP_THUMBNAIL_FILESIZE_LIMIT:
core_config->thumbnail_filesize_limit = g_value_get_uint64 (value);
break;
case PROP_INSTALL_COLORMAP:
core_config->install_cmap = g_value_get_boolean (value);
break;
......@@ -623,6 +632,9 @@ gimp_core_config_get_property (GObject *object,
case PROP_THUMBNAIL_SIZE:
g_value_set_enum (value, core_config->thumbnail_size);
break;
case PROP_THUMBNAIL_FILESIZE_LIMIT:
g_value_set_uint64 (value, core_config->thumbnail_filesize_limit);
break;
case PROP_INSTALL_COLORMAP:
g_value_set_boolean (value, core_config->install_cmap);
break;
......
......@@ -73,6 +73,7 @@ struct _GimpCoreConfig
gboolean layer_previews;
GimpViewSize layer_preview_size;
GimpThumbnailSize thumbnail_size;
guint64 thumbnail_filesize_limit;
gboolean install_cmap;
gint min_colors;
};
......
......@@ -360,6 +360,10 @@ N_("Sets the temporary storage directory. Files will appear here " \
N_("Sets the size of the thumbnail saved with each image. Note that GIMP " \
"can not save thumbnails if layer previews are disabled.")
#define THUMBNAIL_FILESIZE_LIMIT_BLURB \
N_("The preview thumbnail in the Open dialog will be updated on demand " \
"unless the file being previewed is larger than the size set here.")
#define TILE_CACHE_SIZE_BLURB \
N_("The tile cache is used to make sure the GIMP doesn't thrash " \
"tiles between memory and disk. Setting this value higher will " \
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpfileimage.c
* gimpimagefile.c
*
* Copyright (C) 2001-2004 Sven Neumann <sven@gimp.org>
* Michael Natterer <mitch@gimp.org>
......@@ -303,6 +303,9 @@ gimp_imagefile_save_thumbnail (GimpImagefile *imagefile,
g_return_val_if_fail (GIMP_IS_IMAGEFILE (imagefile), FALSE);
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
/* peek the thumbnail to make sure that mtime and filesize are set */
gimp_thumbnail_peek_image (imagefile->thumbnail);
success = gimp_imagefile_save_thumb (imagefile,
gimage,
gimage->gimp->config->thumbnail_size,
......@@ -663,16 +666,12 @@ gimp_imagefile_save_thumb (GimpImagefile *imagefile,
}
}
pixbuf = gimp_viewable_get_new_pixbuf (GIMP_VIEWABLE (gimage),
width, height);
pixbuf = gimp_viewable_get_new_pixbuf (GIMP_VIEWABLE (gimage), width, height);
/* when layer previews are disabled, we won't get a pixbuf */
if (! pixbuf)
return TRUE;
/* peek the thumbnail to make sure that mtime and filesize are set */
gimp_thumbnail_peek_image (thumbnail);
type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (gimp_image_base_type (gimage));
if (gimp_image_has_alpha (gimage))
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpfileimage.h
* gimpimagefile.h
*
* Thumbnail handling according to the Thumbnail Managing Standard.
* http://triq.net/~pearl/thumbnail-spec/
*
......
......@@ -2300,8 +2300,17 @@ prefs_dialog_new (Gimp *gimp,
GTK_TABLE (table), 4, size_group);
#endif /* ENABLE_MP */
/* File Opening */
vbox2 = prefs_frame_new (_("Opening Images"), GTK_CONTAINER (vbox), FALSE);
table = prefs_table_new (1, GTK_CONTAINER (vbox2));
prefs_memsize_entry_add (object, "thumbnail-filesize-limit",
_("Filesize limit for thumbnailing:"),
GTK_TABLE (table), 0, size_group);
/* File Saving */
vbox2 = prefs_frame_new (_("File Saving"), GTK_CONTAINER (vbox), FALSE);
vbox2 = prefs_frame_new (_("Saving Images"), GTK_CONTAINER (vbox), FALSE);
prefs_check_button_add (object, "confirm-on-close",
_("Confirm closing of unsaved images"),
......@@ -2310,13 +2319,12 @@ prefs_dialog_new (Gimp *gimp,
table = prefs_table_new (1, GTK_CONTAINER (vbox2));
prefs_enum_combo_box_add (object, "thumbnail-size", 0, 0,
_("Size of thumbnail files:"),
_("Create thumbnails:"),
GTK_TABLE (table), 0, size_group);
g_object_unref (size_group);
size_group = NULL;
/*************/
/* Folders */
/*************/
......
......@@ -203,18 +203,26 @@ file_utils_find_proc (GSList *procs,
return size_matched_proc;
}
/* As a last ditch, try matching by name */
/* As a last resort, try matching by name */
return file_proc_find_by_name (all_procs, uri, FALSE);
}
PlugInProcDef *
file_utils_find_proc_by_extension (GSList *procs,
const gchar *uri)
{
g_return_val_if_fail (procs != NULL, NULL);
g_return_val_if_fail (uri != NULL, NULL);
return file_proc_find_by_extension (procs, uri, FALSE);
}
gchar *
file_utils_uri_to_utf8_basename (const gchar *uri)
{
gchar *filename;
gchar *basename;
g_assert (uri != NULL);
g_return_val_if_fail (uri != NULL, NULL);
filename = file_utils_uri_to_utf8_filename (uri);
......
......@@ -22,13 +22,17 @@
#define __FILE_UTILS_H__
gchar * file_utils_filename_to_uri (GSList *procs,
const gchar *filename,
GError **error);
PlugInProcDef * file_utils_find_proc (GSList *procs,
const gchar *filename);
gchar * file_utils_uri_to_utf8_basename (const gchar *uri);
gchar * file_utils_uri_to_utf8_filename (const gchar *uri);
gchar * file_utils_filename_to_uri (GSList *procs,
const gchar *filename,
GError **error);
gchar * file_utils_uri_to_utf8_basename (const gchar *uri);
gchar * file_utils_uri_to_utf8_filename (const gchar *uri);
PlugInProcDef * file_utils_find_proc (GSList *procs,
const gchar *filename);
PlugInProcDef * file_utils_find_proc_by_extension (GSList *procs,
const gchar *uri);
#endif /* __FILE_UTILS_H__ */
......@@ -50,6 +50,7 @@ static void gimp_thumb_box_class_init (GimpThumbBoxClass *klass);
static void gimp_thumb_box_init (GimpThumbBox *box);
static void gimp_thumb_box_progress_iface_init (GimpProgressInterface *progress_iface);
static void gimp_thumb_box_dispose (GObject *object);
static void gimp_thumb_box_finalize (GObject *object);
static void gimp_thumb_box_style_set (GtkWidget *widget,
......@@ -73,12 +74,16 @@ static void gimp_thumb_box_thumbnail_clicked (GtkWidget *widget,
GimpThumbBox *box);
static void gimp_thumb_box_imagefile_info_changed (GimpImagefile *imagefile,
GimpThumbBox *box);
static void gimp_thumb_box_thumb_state_notify (GimpThumbnail *thumb,
GParamSpec *pspec,
GimpThumbBox *box);
static void gimp_thumb_box_create_thumbnails (GimpThumbBox *box,
gboolean always_create);
gboolean force);
static void gimp_thumb_box_create_thumbnail (GimpThumbBox *box,
const gchar *uri,
GimpThumbnailSize size,
gboolean always_create);
gboolean force);
static gboolean gimp_thumb_box_auto_thumbnail (GimpThumbBox *box);
/* private variables */
......@@ -132,6 +137,7 @@ gimp_thumb_box_class_init (GimpThumbBoxClass *klass)
parent_class = g_type_class_peek_parent (klass);
object_class->dispose = gimp_thumb_box_dispose;
object_class->finalize = gimp_thumb_box_finalize;
widget_class->style_set = gimp_thumb_box_style_set;
......@@ -141,6 +147,8 @@ static void
gimp_thumb_box_init (GimpThumbBox *box)
{
gtk_frame_set_shadow_type (GTK_FRAME (box), GTK_SHADOW_IN);
box->idle_id = 0;
}
static void
......@@ -153,6 +161,20 @@ gimp_thumb_box_progress_iface_init (GimpProgressInterface *progress_iface)
progress_iface->get_value = gimp_thumb_box_progress_get_value;
}
static void
gimp_thumb_box_dispose (GObject *object)
{
GimpThumbBox *box = GIMP_THUMB_BOX (object);
if (box->idle_id)
{
g_source_remove (box->idle_id);
box->idle_id = 0;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_thumb_box_finalize (GObject *object)
{
......@@ -196,15 +218,15 @@ gimp_thumb_box_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable)
{
GimpThumbBox *thumb_box = GIMP_THUMB_BOX (progress);
GimpThumbBox *box = GIMP_THUMB_BOX (progress);
if (! thumb_box->progress_active)
if (! box->progress_active)
{
GtkProgressBar *bar = GTK_PROGRESS_BAR (thumb_box->progress);
GtkProgressBar *bar = GTK_PROGRESS_BAR (box->progress);
gtk_progress_bar_set_fraction (bar, 0.0);
thumb_box->progress_active = TRUE;
box->progress_active = TRUE;
return progress;
}
......@@ -215,48 +237,58 @@ gimp_thumb_box_progress_start (GimpProgress *progress,
static void
gimp_thumb_box_progress_end (GimpProgress *progress)
{
GimpThumbBox *thumb_box = GIMP_THUMB_BOX (progress);
GimpThumbBox *box = GIMP_THUMB_BOX (progress);
if (thumb_box->progress_active)
if (box->progress_active)
{
GtkProgressBar *bar = GTK_PROGRESS_BAR (thumb_box->progress);
GtkProgressBar *bar = GTK_PROGRESS_BAR (box->progress);
gtk_progress_bar_set_fraction (bar, 0.0);
thumb_box->progress_active = FALSE;
box->progress_active = FALSE;
}
}
static gboolean
gimp_thumb_box_progress_is_active (GimpProgress *progress)
{
GimpThumbBox *thumb_box = GIMP_THUMB_BOX (progress);
GimpThumbBox *box = GIMP_THUMB_BOX (progress);
return thumb_box->progress_active;
return box->progress_active;
}
static void
gimp_thumb_box_progress_set_value (GimpProgress *progress,
gdouble percentage)
{
GimpThumbBox *thumb_box = GIMP_THUMB_BOX (progress);
GimpThumbBox *box = GIMP_THUMB_BOX (progress);
if (thumb_box->progress_active)
if (box->progress_active)
{
GtkProgressBar *bar = GTK_PROGRESS_BAR (thumb_box->progress);
GtkProgressBar *bar = GTK_PROGRESS_BAR (box->progress);
gtk_progress_bar_set_fraction (bar, percentage);
if (box->idle_id)
{
const gchar *desc = gimp_imagefile_get_desc_string (box->imagefile);
gchar *text;
text = g_strdup_printf ("%s\n\n%s", desc, _("Creating Preview ..."));
gtk_label_set_text (GTK_LABEL (box->info), text);
g_free (text);
}
}
}
static gdouble
gimp_thumb_box_progress_get_value (GimpProgress *progress)
{
GimpThumbBox *thumb_box = GIMP_THUMB_BOX (progress);
GimpThumbBox *box = GIMP_THUMB_BOX (progress);
if (thumb_box->progress_active)
if (box->progress_active)
{
GtkProgressBar *bar = GTK_PROGRESS_BAR (thumb_box->progress);
GtkProgressBar *bar = GTK_PROGRESS_BAR (box->progress);
return gtk_progress_bar_get_fraction (bar);
}
......@@ -345,12 +377,17 @@ gimp_thumb_box_new (Gimp *gimp)
G_CALLBACK (gimp_thumb_box_imagefile_info_changed),
box);
g_signal_connect (box->imagefile->thumbnail, "notify::thumb-state",
G_CALLBACK (gimp_thumb_box_thumb_state_notify),
box);
gimp_view_renderer_get_frame_size (&h, &v);
box->preview = gimp_view_new (GIMP_VIEWABLE (box->imagefile),
/* add padding for the shadow frame */
gimp->config->thumbnail_size + MAX (h, v),
0, FALSE);
gtk_box_pack_start (GTK_BOX (hbox), box->preview, TRUE, FALSE, 10);
gtk_widget_show (box->preview);
......@@ -412,6 +449,12 @@ gimp_thumb_box_set_uri (GimpThumbBox *box,
{
g_return_if_fail (GIMP_IS_THUMB_BOX (box));
if (box->idle_id)
{
g_source_remove (box->idle_id);
box->idle_id = 0;
}
gimp_object_set_name (GIMP_OBJECT (box->imagefile), uri);
if (uri)
......@@ -477,13 +520,36 @@ gimp_thumb_box_imagefile_info_changed (GimpImagefile *imagefile,
gimp_imagefile_get_desc_string (imagefile));
}
static void
gimp_thumb_box_thumb_state_notify (GimpThumbnail *thumb,
GParamSpec *pspec,
GimpThumbBox *box)
{
if (box->idle_id)
return;
switch (thumb->thumb_state)
{
case GIMP_THUMB_STATE_NOT_FOUND:
case GIMP_THUMB_STATE_OLD:
box->idle_id =
g_idle_add_full (G_PRIORITY_LOW,
(GSourceFunc) gimp_thumb_box_auto_thumbnail,
box, NULL);
break;
default:
break;
}
}
static void
gimp_thumb_box_create_thumbnails (GimpThumbBox *box,
gboolean always_create)
gboolean force)
{
Gimp *gimp = box->imagefile->gimp;
GtkWidget *toplevel;
GimpFileDialog *dialog = NULL;
GtkWidget *toplevel;
GSList *list;
gint n_uris;
gint i;
......@@ -537,7 +603,7 @@ gimp_thumb_box_create_thumbnails (GimpThumbBox *box,
gimp_thumb_box_create_thumbnail (box,
list->data,
gimp->config->thumbnail_size,
always_create);
force);
if (dialog && dialog->canceled)
goto canceled;
......@@ -563,7 +629,7 @@ gimp_thumb_box_create_thumbnails (GimpThumbBox *box,
gimp_thumb_box_create_thumbnail (box,
box->uris->data,
gimp->config->thumbnail_size,
always_create);
force);
if (n_uris > 1)
{
......@@ -598,7 +664,7 @@ static void
gimp_thumb_box_create_thumbnail (GimpThumbBox *box,
const gchar *uri,
GimpThumbnailSize size,
gboolean always_create)
gboolean force)
{
gchar *filename = g_filename_from_uri (uri, NULL, NULL);
......@@ -611,7 +677,7 @@ gimp_thumb_box_create_thumbnail (GimpThumbBox *box,
gimp_object_set_name (GIMP_OBJECT (box->imagefile), uri);
if (always_create ||
if (force ||
gimp_thumbnail_peek_thumb (box->imagefile->thumbnail, size)
< GIMP_THUMB_STATE_FAILED)
{
......@@ -624,3 +690,59 @@ gimp_thumb_box_create_thumbnail (GimpThumbBox *box,
g_free (filename);
}
static gboolean
gimp_thumb_box_auto_thumbnail (GimpThumbBox *box)
{
Gimp *gimp = box->imagefile->gimp;
GimpThumbnail *thumb = box->imagefile->thumbnail;
const gchar *uri = gimp_object_get_name (GIMP_OBJECT (box->imagefile));
g_object_add_weak_pointer (G_OBJECT (box), (gpointer *) &box);
switch (thumb->thumb_state)
{
case GIMP_THUMB_STATE_NOT_FOUND:
case GIMP_THUMB_STATE_OLD:
if (thumb->image_filesize < gimp->config->thumbnail_filesize_limit &&
file_utils_find_proc_by_extension (gimp->load_procs, uri))
{
/* This is tricky because gimp_imagefile_create_thumbnail()
* may call a plug-in and the progress callback runs the
* mainloop. Thus the dialog may change below our feet. For
* that reason we use a seperate GimpImagefile to create the
* thumbnail.
*/
GimpImagefile *local = gimp_imagefile_new (gimp, uri);
gimp_imagefile_create_thumbnail (local,
gimp_get_user_context (gimp),
GIMP_PROGRESS (box),
gimp->config->thumbnail_size);
if (box)
{
if (strcmp (gimp_object_get_name (GIMP_OBJECT (box->imagefile)),
gimp_object_get_name (GIMP_OBJECT (local))) == 0)
{
gimp_imagefile_update (box->imagefile);
}
}
g_object_unref (local);
}
break;
default:
break;
}
if (box)
{
g_object_remove_weak_pointer (G_OBJECT (box), (gpointer *) &box);
box->idle_id = 0;
}
return FALSE;
}
......@@ -44,6 +44,8 @@ struct _GimpThumbBox
gboolean progress_active;
GtkWidget *progress;
guint idle_id;
};
struct _GimpThumbBoxClass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment