gimp r26152 - in branches/soc-2008-tagging: . app/core
- From: aurisj svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r26152 - in branches/soc-2008-tagging: . app/core
- Date: Sat, 12 Jul 2008 10:08:38 +0000 (UTC)
Author: aurisj
Date: Sat Jul 12 10:08:38 2008
New Revision: 26152
URL: http://svn.gnome.org/viewvc/gimp?rev=26152&view=rev
Log:
2008-07-12 Aurimas JuÅka <aurisj svn gnome org>
* app/core/gimptagcache.[ch]: detect resource file renames/moves and
update tag cache accordingly. If identifier (filename) changes,
objects are identified using checksum.
* app/core/gimpbrush.c (gimp_brush_tagged_init),
(gimp_brush_get_checksum)
* app/core/gimpdata.c (gimp_data_tagged_iface_init),
(gimp_data_get_checksum)
* app/core/gimptagged.c (gimp_tagged_get_checksum)
* app/core/gimptagged.h: checksum support for tagged objects.
Modified:
branches/soc-2008-tagging/ChangeLog
branches/soc-2008-tagging/app/core/gimpbrush.c
branches/soc-2008-tagging/app/core/gimpdata.c
branches/soc-2008-tagging/app/core/gimptagcache.c
branches/soc-2008-tagging/app/core/gimptagcache.h
branches/soc-2008-tagging/app/core/gimptagged.c
branches/soc-2008-tagging/app/core/gimptagged.h
Modified: branches/soc-2008-tagging/app/core/gimpbrush.c
==============================================================================
--- branches/soc-2008-tagging/app/core/gimpbrush.c (original)
+++ branches/soc-2008-tagging/app/core/gimpbrush.c Sat Jul 12 10:08:38 2008
@@ -21,6 +21,7 @@
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
+#include "libgimpmath/gimpmd5.h"
#include "core-types.h"
@@ -31,6 +32,7 @@
#include "gimpbrush-scale.h"
#include "gimpbrushgenerated.h"
#include "gimpmarshal.h"
+#include "gimptagged.h"
#include "gimp-intl.h"
@@ -47,6 +49,7 @@
PROP_SPACING
};
+static void gimp_brush_tagged_init (GimpTaggedInterface *iface);
static void gimp_brush_set_property (GObject *object,
guint property_id,
@@ -79,8 +82,12 @@
GimpCoords *last_coords,
GimpCoords *cur_coords);
+static gchar * gimp_brush_get_checksum (GimpTagged *tagged);
-G_DEFINE_TYPE (GimpBrush, gimp_brush, GIMP_TYPE_DATA)
+
+G_DEFINE_TYPE_WITH_CODE (GimpBrush, gimp_brush, GIMP_TYPE_DATA,
+ G_IMPLEMENT_INTERFACE (GIMP_TYPE_TAGGED,
+ gimp_brush_tagged_init))
#define parent_class gimp_brush_parent_class
@@ -145,6 +152,12 @@
}
static void
+gimp_brush_tagged_init (GimpTaggedInterface *iface)
+{
+ iface->get_checksum = gimp_brush_get_checksum;
+}
+
+static void
gimp_brush_set_property (GObject *object,
guint property_id,
const GValue *value,
@@ -515,3 +528,34 @@
g_signal_emit (brush, brush_signals[SPACING_CHANGED], 0);
}
+
+static gchar *
+gimp_brush_get_checksum(GimpTagged *tagged)
+{
+ GimpBrush *brush = GIMP_BRUSH (tagged);
+ TempBuf *buffer;
+ GChecksum *checksum;
+ gchar *checksum_string;
+
+ checksum = g_checksum_new (G_CHECKSUM_MD5);
+
+ buffer = brush->pixmap;
+ if (buffer)
+ {
+ g_checksum_update (checksum, temp_buf_data (buffer),
+ buffer->width * buffer->height * buffer->bytes);
+ }
+ buffer = brush->mask;
+ if (buffer)
+ {
+ g_checksum_update (checksum, temp_buf_data (buffer),
+ buffer->width * buffer->height * buffer->bytes);
+ }
+
+ checksum_string = g_strdup (g_checksum_get_string (checksum));
+
+ g_checksum_free (checksum);
+
+ return checksum_string;
+}
+
Modified: branches/soc-2008-tagging/app/core/gimpdata.c
==============================================================================
--- branches/soc-2008-tagging/app/core/gimpdata.c (original)
+++ branches/soc-2008-tagging/app/core/gimpdata.c Sat Jul 12 10:08:38 2008
@@ -94,8 +94,7 @@
GimpTag tag);
static GList * gimp_data_get_tags (GimpTagged *tagged);
static gchar * gimp_data_get_identifier (GimpTagged *tagged);
-static gboolean gimp_data_get_digest (GimpTagged *tagged,
- guchar digest[16]);
+static gchar * gimp_data_get_checksum (GimpTagged *tagged);
static guint data_signals[LAST_SIGNAL] = { 0 };
@@ -198,7 +197,7 @@
iface->remove_tag = gimp_data_remove_tag;
iface->get_tags = gimp_data_get_tags;
iface->get_identifier = gimp_data_get_identifier;
- iface->get_digest = gimp_data_get_digest;
+ iface->get_checksum = gimp_data_get_checksum;
}
static void
@@ -421,11 +420,10 @@
}
}
-static gboolean
-gimp_data_get_digest (GimpTagged *tagged,
- guchar digest[16])
+static gchar *
+gimp_data_get_checksum (GimpTagged *tagged)
{
- return FALSE;
+ return NULL;
}
/**
Modified: branches/soc-2008-tagging/app/core/gimptagcache.c
==============================================================================
--- branches/soc-2008-tagging/app/core/gimptagcache.c (original)
+++ branches/soc-2008-tagging/app/core/gimptagcache.c Sat Jul 12 10:08:38 2008
@@ -178,6 +178,8 @@
{
const char *identifier;
GQuark identifier_quark = 0;
+ gchar *checksum_string;
+ GQuark checksum_quark;
GList *tag_iterator;
gint i;
@@ -186,25 +188,60 @@
if (identifier
&& !gimp_tagged_get_tags (tagged))
{
- identifier_quark = g_quark_from_string (identifier);
-
- for (i = 0; i < cache->records->len; i++)
+ identifier_quark = g_quark_try_string (identifier);
+ if (identifier_quark)
{
- GimpTagCacheRecord *rec = &g_array_index (cache->records, GimpTagCacheRecord, i);
+ for (i = 0; i < cache->records->len; i++)
+ {
+ GimpTagCacheRecord *rec = &g_array_index (cache->records,
+ GimpTagCacheRecord, i);
- if (rec->identifier == identifier_quark)
+ if (rec->identifier == identifier_quark)
+ {
+ tag_iterator = rec->tags;
+ while (tag_iterator)
+ {
+ printf ("assigning cached tag: %s to %s\n",
+ g_quark_to_string (GPOINTER_TO_UINT (tag_iterator->data)),
+ identifier);
+ gimp_tagged_add_tag (tagged, GPOINTER_TO_UINT (tag_iterator->data));
+ tag_iterator = g_list_next (tag_iterator);
+ }
+ rec->referenced = TRUE;
+ return;
+ }
+ }
+ }
+
+ checksum_string = gimp_tagged_get_checksum (tagged);
+ checksum_quark = g_quark_try_string (checksum_string);
+ g_free (checksum_string);
+
+ if (checksum_quark)
+ {
+ for (i = 0; i < cache->records->len; i++)
{
- tag_iterator = rec->tags;
- while (tag_iterator)
+ GimpTagCacheRecord *rec = &g_array_index (cache->records,
+ GimpTagCacheRecord, i);
+
+ if (rec->checksum == checksum_quark)
{
- printf ("assigning cached tag: %s to %s\n",
- g_quark_to_string (GPOINTER_TO_UINT (tag_iterator->data)),
- identifier);
- gimp_tagged_add_tag (tagged, GPOINTER_TO_UINT (tag_iterator->data));
- tag_iterator = g_list_next (tag_iterator);
+ printf ("remapping identifier: %s ==> %s\n",
+ g_quark_to_string (rec->identifier), identifier);
+ rec->identifier = g_quark_from_string (identifier);
+
+ tag_iterator = rec->tags;
+ while (tag_iterator)
+ {
+ printf ("assigning cached tag: %s to %s\n",
+ g_quark_to_string (GPOINTER_TO_UINT (tag_iterator->data)),
+ identifier);
+ gimp_tagged_add_tag (tagged, GPOINTER_TO_UINT (tag_iterator->data));
+ tag_iterator = g_list_next (tag_iterator);
+ }
+ rec->referenced = TRUE;
+ return;
}
- rec->referenced = TRUE;
- break;
}
}
}
@@ -222,6 +259,7 @@
GList **cache_records)
{
const char *identifier;
+ gchar *checksum;
GimpTagCacheRecord *cache_rec;
identifier = gimp_tagged_get_identifier (tagged);
@@ -229,6 +267,9 @@
{
cache_rec = (GimpTagCacheRecord*) g_malloc (sizeof (GimpTagCacheRecord));
cache_rec->identifier = g_quark_from_string (identifier);
+ checksum = gimp_tagged_get_checksum (tagged);
+ cache_rec->checksum = g_quark_from_string (checksum);
+ g_free (checksum);
cache_rec->tags = g_list_copy (gimp_tagged_get_tags (tagged));
*cache_records = g_list_append (*cache_records, cache_rec);
}
@@ -257,6 +298,7 @@
* but were not loaded. */
GimpTagCacheRecord *record_copy = (GimpTagCacheRecord*) g_malloc (sizeof (GimpTagCacheRecord));
record_copy->identifier = current_record->identifier;
+ record_copy->checksum = current_record->checksum;
record_copy->tags = g_list_copy (current_record->tags);
saved_records = g_list_append (saved_records, record_copy);
}
@@ -279,8 +321,9 @@
GimpTagCacheRecord *cache_rec = (GimpTagCacheRecord*) iterator->data;
GList *tag_iterator;
- g_string_append_printf (buf, "\t<resource identifier=\"%s\">\n",
- g_quark_to_string (cache_rec->identifier));
+ g_string_append_printf (buf, "\t<resource identifier=\"%s\" checksum=\"%s\">\n",
+ g_quark_to_string (cache_rec->identifier),
+ g_quark_to_string (cache_rec->checksum));
tag_iterator = cache_rec->tags;
while (tag_iterator)
{
@@ -381,9 +424,12 @@
if (! strcmp (element_name, "resource"))
{
const gchar *identifier;
+ const gchar *checksum;
identifier = attribute_name_to_value (attribute_names, attribute_values,
"identifier");
+ checksum = attribute_name_to_value (attribute_names, attribute_values,
+ "checksum");
if (! identifier)
{
@@ -392,11 +438,10 @@
return;
}
- printf ("loading element %s\n", identifier);
-
memset (&parse_data->current_record, 0, sizeof (GimpTagCacheRecord));
parse_data->current_record.identifier = g_quark_from_string (identifier);
+ parse_data->current_record.checksum = g_quark_from_string (checksum);
}
}
Modified: branches/soc-2008-tagging/app/core/gimptagcache.h
==============================================================================
--- branches/soc-2008-tagging/app/core/gimptagcache.h (original)
+++ branches/soc-2008-tagging/app/core/gimptagcache.h Sat Jul 12 10:08:38 2008
@@ -40,6 +40,7 @@
struct _GimpTagCacheRecord
{
GQuark identifier;
+ GQuark checksum;
GList *tags;
guint referenced : 1;
};
Modified: branches/soc-2008-tagging/app/core/gimptagged.c
==============================================================================
--- branches/soc-2008-tagging/app/core/gimptagged.c (original)
+++ branches/soc-2008-tagging/app/core/gimptagged.c Sat Jul 12 10:08:38 2008
@@ -172,26 +172,25 @@
}
/**
- * gimp_tagged_get_digest:
+ * gimp_tagged_get_checksum:
* @tagged: an object that implements the %GimpTagged interface
*
- * Returns an digest value of @tagged object. It is used to remap
+ * Returns an checksum value of @tagged object. It is used to remap
* object identifier if it changed from the previous session.
* For example, when filename changes tags can be remapped to the
- * proper objects by finding it using digest value.
+ * proper objects by finding it using checksum value.
*
* If the object does not want to support such remapping
- * (object not stored in file, for example) it can return #FALSE
+ * (object not stored in file, for example) it can return #NULL.
*
- * Return value: TRUE if object needs identifier remapping and provides
- * digest value, FALSE otherwise.
+ * Return value: checksum string if object needs identifier remapping,
+ * NULL otherwise. Returned string should be freed with #g_free().
**/
-gboolean
-gimp_tagged_get_digest (GimpTagged *tagged,
- guchar digest[16])
+gchar *
+gimp_tagged_get_checksum (GimpTagged *tagged)
{
g_return_val_if_fail (GIMP_IS_TAGGED (tagged), FALSE);
- return GIMP_TAGGED_GET_INTERFACE (tagged)->get_digest (tagged, digest);
+ return GIMP_TAGGED_GET_INTERFACE (tagged)->get_checksum (tagged);
}
Modified: branches/soc-2008-tagging/app/core/gimptagged.h
==============================================================================
--- branches/soc-2008-tagging/app/core/gimptagged.h (original)
+++ branches/soc-2008-tagging/app/core/gimptagged.h Sat Jul 12 10:08:38 2008
@@ -49,8 +49,7 @@
GList * (* get_tags) (GimpTagged *tagged);
gchar * (* get_identifier) (GimpTagged *tagged);
- gboolean (* get_digest) (GimpTagged *tagged,
- guchar digest[16]);
+ gchar * (* get_checksum) (GimpTagged *tagged);
};
@@ -63,7 +62,6 @@
GList * gimp_tagged_get_tags (GimpTagged *tagged);
gchar * gimp_tagged_get_identifier (GimpTagged *tagged);
-gboolean gimp_tagged_get_digest (GimpTagged *tagged,
- guchar digest[16]);
+gchar * gimp_tagged_get_checksum (GimpTagged *tagged);
#endif /* __GIMP_TAGGED_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]