Commit 4e2d3f61 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

libgimpthumb/Makefile.am added new files that define the GIMP_THUMB_ERROR

2003-12-02  Sven Neumann  <sven@gimp.org>

	* libgimpthumb/Makefile.am
	* libgimpthumb/gimpthumb-error.[ch]: added new files that define the
	GIMP_THUMB_ERROR domain.

	* libgimpthumb/gimpthumb-utils.[ch]
	* libgimpthumb/gimpthumb.h
	* libgimpthumb/gimpthumbnail.[ch]: finalizing the API.
parent 56cbe6f6
2003-12-02 Sven Neumann <sven@gimp.org>
* libgimpthumb/Makefile.am
* libgimpthumb/gimpthumb-error.[ch]: added new files that define the
GIMP_THUMB_ERROR domain.
* libgimpthumb/gimpthumb-utils.[ch]
* libgimpthumb/gimpthumb.h
* libgimpthumb/gimpthumbnail.[ch]: finalizing the API.
2003-12-01 Sven Neumann <sven@gimp.org>
* app/core/gimpdrawable-blend.c: some code cleanup I've done while
......@@ -58,6 +58,8 @@ libgimpthumb_1_3_la_SOURCES = \
gimpthumb.h \
gimpthumb-enums.c \
gimpthumb-enums.h \
gimpthumb-error.c \
gimpthumb-error.h \
gimpthumb-types.h \
gimpthumb-utils.c \
gimpthumb-utils.h \
......@@ -67,6 +69,7 @@ libgimpthumb_1_3_la_SOURCES = \
libgimpthumbinclude_HEADERS = \
gimpthumb.h \
gimpthumb-enums.h \
gimpthumb-error.h \
gimpthumb-types.h \
gimpthumb-utils.h \
gimpthumbnail.h
......
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* Thumbnail handling according to the Thumbnail Managing Standard.
* http://triq.net/~pearl/thumbnail-spec/
*
* Copyright (C) 2001-2003 Sven Neumann <sven@gimp.org>
* Michael Natterer <mitch@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <glib.h>
#include "gimpthumb-error.h"
GQuark
gimp_thumb_error_quark (void)
{
static GQuark q = 0;
if (q == 0)
q = g_quark_from_static_string ("gimp-thumb-error-quark");
return q;
}
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* Thumbnail handling according to the Thumbnail Managing Standard.
* http://triq.net/~pearl/thumbnail-spec/
*
* Copyright (C) 2001-2003 Sven Neumann <sven@gimp.org>
* Michael Natterer <mitch@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_THUMB_ERROR_H__
#define __GIMP_THUMB_ERROR_H__
typedef enum
{
GIMP_THUMB_ERROR_OPEN, /* open failed */
GIMP_THUMB_ERROR_OPEN_ENOENT, /* file does not exist */
GIMP_THUMB_ERROR_MKDIR, /* mkdir failed */
} GimpThumbError;
#define GIMP_THUMB_ERROR (gimp_thumb_error_quark ())
GQuark gimp_thumb_error_quark (void) G_GNUC_CONST;
#endif /* __GIMP_THUMB_ERROR_H__ */
......@@ -40,9 +40,12 @@
#include "libgimpmath/gimpmath.h"
#include "gimpthumb-error.h"
#include "gimpthumb-types.h"
#include "gimpthumb-utils.h"
#include "libgimp/libgimp-intl.h"
static const gchar * gimp_thumb_png_name (const gchar *uri);
static void gimp_thumb_exit (void);
......@@ -97,13 +100,48 @@ gimp_thumb_init (const gchar *creator,
return gimp_thumb_initialized;
}
gboolean
gimp_thumb_ensure_thumb_dirs (GError **error)
{
gint i;
g_return_val_if_fail (gimp_thumb_initialized, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
for (i = 0; i < thumb_num_sizes; i++)
{
if (! g_file_test (thumb_subdirs[i], G_FILE_TEST_IS_DIR))
{
if (g_file_test (thumb_dir, G_FILE_TEST_IS_DIR) ||
(mkdir (thumb_dir, S_IRUSR | S_IWUSR | S_IXUSR) == 0))
{
if (i == 0)
mkdir (thumb_fail_subdir, S_IRUSR | S_IWUSR | S_IXUSR);
mkdir (thumb_subdirs[i], S_IRUSR | S_IWUSR | S_IXUSR);
}
if (! g_file_test (thumb_subdirs[i], G_FILE_TEST_IS_DIR))
{
g_set_error (error,
GIMP_THUMB_ERROR, GIMP_THUMB_ERROR_MKDIR,
_("Failed to create thumbnail folder '%s'."),
thumb_subdirs[i]);
return FALSE;
}
}
}
return TRUE;
}
gchar *
gimp_thumb_png_thumb_name (const gchar *uri,
GimpThumbSize *size)
gimp_thumb_name_from_uri (const gchar *uri,
GimpThumbSize *size)
{
const gchar *name;
gchar *thumb_name = NULL;
gint i = 0;
gint i = 0;
g_return_val_if_fail (gimp_thumb_initialized, NULL);
......@@ -125,28 +163,7 @@ gimp_thumb_png_thumb_name (const gchar *uri,
*size = thumb_sizes[i];
if (! g_file_test (thumb_subdirs[i], G_FILE_TEST_IS_DIR))
{
if (g_file_test (thumb_dir, G_FILE_TEST_IS_DIR) ||
(mkdir (thumb_dir, S_IRUSR | S_IWUSR | S_IXUSR) == 0))
{
if (i == 0)
mkdir (thumb_fail_subdir, S_IRUSR | S_IWUSR | S_IXUSR);
mkdir (thumb_subdirs[i], S_IRUSR | S_IWUSR | S_IXUSR);
}
if (! g_file_test (thumb_subdirs[i], G_FILE_TEST_IS_DIR))
{
g_message ("Failed to create thumbnail folder '%s'.",
thumb_subdirs[i]);
return NULL;
}
}
thumb_name = g_build_filename (thumb_subdirs[i], name, NULL);
return thumb_name;
return g_build_filename (thumb_subdirs[i], name, NULL);
}
gchar *
......
......@@ -28,17 +28,21 @@
G_BEGIN_DECLS
gboolean gimp_thumb_init (const gchar *creator,
const gchar *thumb_basedir);
gchar * gimp_thumb_png_thumb_name (const gchar *uri,
GimpThumbSize *size);
gchar * gimp_thumb_find_png_thumb (const gchar *uri,
GimpThumbSize *size);
gboolean gimp_thumb_init (const gchar *creator,
const gchar *thumb_basedir);
gchar * gimp_thumb_name_from_uri (const gchar *uri,
GimpThumbSize *size);
gchar * gimp_thumb_find_thumb (const gchar *uri,
GimpThumbSize *size);
gboolean gimp_thumb_file_test (const gchar *filename,
gint64 *mtime,
gint64 *size);
gboolean gimp_thumb_ensure_thumb_dirs (GError **error);
gboolean gimp_thumb_file_test (const gchar *filename,
gint64 *mtime,
gint64 *size);
G_END_DECLS
......
......@@ -27,6 +27,7 @@
#define __GIMP_THUMB_H__
#include <libgimpthumb/gimpthumb-error.h>
#include <libgimpthumb/gimpthumb-types.h>
#include <libgimpthumb/gimpthumb-utils.h>
#include <libgimpthumb/gimpthumbnail.h>
......
......@@ -37,6 +37,8 @@
#include "gimpthumb-utils.h"
#include "gimpthumbnail.h"
#include "libgimp/libgimp-intl.h"
#define TAG_DESCRIPTION "tEXt::Description"
#define TAG_SOFTWARE "tEXt::Software"
......@@ -81,7 +83,7 @@ static void gimp_thumbnail_reset_info (GimpThumbnail *thumbnail);
static void gimp_thumbnail_update_image (GimpThumbnail *thumbnail);
static void gimp_thumbnail_update_thumb (GimpThumbnail *thumbnail);
static GdkPixbuf * gimp_thumbnail_read_png_thumb (GimpThumbnail *thumbnail,
static GdkPixbuf * gimp_thumbnail_read_thumb (GimpThumbnail *thumbnail,
GimpThumbSize thumb_size,
GError **error);
......@@ -373,15 +375,36 @@ gimp_thumbnail_set_uri (GimpThumbnail *thumbnail,
gimp_thumbnail_invalidate_thumb (thumbnail);
}
void
gimp_thumbnail_update (GimpThumbnail *thumbnail)
GimpThumbState
gimp_thumbnail_peek_image (GimpThumbnail *thumbnail)
{
g_return_val_if_fail (GIMP_IS_THUMBNAIL (thumbnail),
GIMP_THUMB_STATE_UNKNOWN);
g_object_freeze_notify (G_OBJECT (thumbnail));
gimp_thumbnail_update_image (thumbnail);
g_object_thaw_notify (G_OBJECT (thumbnail));
return thumbnail->image_state;
}
GimpThumbState
gimp_thumbnail_peek_thumb (GimpThumbnail *thumbnail,
GimpThumbSize size)
{
g_return_val_if_fail (GIMP_IS_THUMBNAIL (thumbnail),
GIMP_THUMB_STATE_UNKNOWN);
g_object_freeze_notify (G_OBJECT (thumbnail));
gimp_thumbnail_update_image (thumbnail);
gimp_thumbnail_update_thumb (thumbnail);
g_object_thaw_notify (G_OBJECT (thumbnail));
return thumbnail->thumb_state;
}
static void
......@@ -483,7 +506,7 @@ gimp_thumbnail_update_thumb (GimpThumbnail *thumbnail)
g_return_if_fail (thumbnail->thumb_filename == NULL);
thumbnail->thumb_filename =
gimp_thumb_find_png_thumb (thumbnail->image_uri, &size);
gimp_thumb_find_thumb (thumbnail->image_uri, &size);
break;
default:
......@@ -553,16 +576,20 @@ gimp_thumbnail_set_info_from_pixbuf (GimpThumbnail *thumbnail,
}
GdkPixbuf *
gimp_thumbnail_get_pixbuf (GimpThumbnail *thumbnail,
gimp_thumbnail_load_thumb (GimpThumbnail *thumbnail,
GimpThumbSize size,
GError **error)
{
GdkPixbuf *pixbuf;
g_return_val_if_fail (GIMP_IS_THUMBNAIL (thumbnail), NULL);
g_return_val_if_fail (thumbnail->image_uri != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (! thumbnail->image_uri)
return NULL;
pixbuf = gimp_thumbnail_read_png_thumb (thumbnail, size, error);
pixbuf = gimp_thumbnail_read_thumb (thumbnail, size, error);
if (pixbuf)
{
......@@ -587,10 +614,10 @@ gimp_thumbnail_get_pixbuf (GimpThumbnail *thumbnail,
}
gboolean
gimp_thumbnail_save_pixbuf (GimpThumbnail *thumbnail,
GdkPixbuf *pixbuf,
const gchar *software,
GError **error)
gimp_thumbnail_save_thumb (GimpThumbnail *thumbnail,
GdkPixbuf *pixbuf,
const gchar *software,
GError **error)
{
GimpThumbSize size;
gchar *name;
......@@ -608,12 +635,14 @@ gimp_thumbnail_save_pixbuf (GimpThumbnail *thumbnail,
g_return_val_if_fail (software != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
size = MAX (gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf));
if (! gimp_thumb_ensure_thumb_dirs (error))
return FALSE;
size = MAX (gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf));
if (size < 1)
return TRUE;
name = gimp_thumb_png_thumb_name (thumbnail->image_uri, &size);
name = gimp_thumb_name_from_uri (thumbnail->image_uri, &size);
if (! name)
return TRUE;
......@@ -682,7 +711,10 @@ gimp_thumbnail_save_failure (GimpThumbnail *thumbnail,
g_return_val_if_fail (thumbnail->image_uri != NULL, FALSE);
g_return_val_if_fail (software != NULL, FALSE);
name = gimp_thumb_png_thumb_name (thumbnail->image_uri, &size);
if (! gimp_thumb_ensure_thumb_dirs (error))
return FALSE;
name = gimp_thumb_name_from_uri (thumbnail->image_uri, &size);
if (! name)
return TRUE;
......@@ -720,9 +752,9 @@ gimp_thumbnail_save_failure (GimpThumbnail *thumbnail,
}
static GdkPixbuf *
gimp_thumbnail_read_png_thumb (GimpThumbnail *thumbnail,
GimpThumbSize thumb_size,
GError **error)
gimp_thumbnail_read_thumb (GimpThumbnail *thumbnail,
GimpThumbSize thumb_size,
GError **error)
{
GimpThumbState state;
GdkPixbuf *pixbuf = NULL;
......@@ -735,7 +767,7 @@ gimp_thumbnail_read_png_thumb (GimpThumbnail *thumbnail,
state = GIMP_THUMB_STATE_NOT_FOUND;
name = gimp_thumb_find_png_thumb (thumbnail->image_uri, &thumb_size);
name = gimp_thumb_find_thumb (thumbnail->image_uri, &thumb_size);
if (!name)
goto cleanup;
......
......@@ -75,11 +75,14 @@ gboolean gimp_thumbnail_set_filename (GimpThumbnail *thumbnail,
const gchar *filename,
GError **error);
GdkPixbuf * gimp_thumbnail_get_pixbuf (GimpThumbnail *thumbnail,
GimpThumbState gimp_thumbnail_peek_image (GimpThumbnail *thumbnail);
GimpThumbState gimp_thumbnail_peek_thumb (GimpThumbnail *thumbnail,
GimpThumbSize size);
GdkPixbuf * gimp_thumbnail_load_thumb (GimpThumbnail *thumbnail,
GimpThumbSize size,
GError **error);
gboolean gimp_thumbnail_save_pixbuf (GimpThumbnail *thumbnail,
gboolean gimp_thumbnail_save_thumb (GimpThumbnail *thumbnail,
GdkPixbuf *pixbuf,
const gchar *software,
GError **error);
......
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