gimp r28097 - in trunk: . app/core
- From: mitch svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r28097 - in trunk: . app/core
- Date: Mon, 2 Mar 2009 23:33:25 +0000 (UTC)
Author: mitch
Date: Mon Mar 2 23:33:24 2009
New Revision: 28097
URL: http://svn.gnome.org/viewvc/gimp?rev=28097&view=rev
Log:
2009-03-03 Michael Natterer <mitch gimp org>
* app/core/gimpfilteredcontainer.[ch]
* app/core/gimptag.c
* app/core/gimptagcache.[ch]: codingstylize. Call iterator GList*
variables simply "list" just as we call integers simply "i".
Modified:
trunk/ChangeLog
trunk/app/core/gimpfilteredcontainer.c
trunk/app/core/gimpfilteredcontainer.h
trunk/app/core/gimptag.c
trunk/app/core/gimptagcache.c
trunk/app/core/gimptagcache.h
Modified: trunk/app/core/gimpfilteredcontainer.c
==============================================================================
--- trunk/app/core/gimpfilteredcontainer.c (original)
+++ trunk/app/core/gimpfilteredcontainer.c Mon Mar 2 23:33:24 2009
@@ -43,10 +43,11 @@
enum
{
PROP_0,
- PROP_SRC_CONTAINER,
+ PROP_SRC_CONTAINER
};
-typedef struct MatchParams_
+
+typedef struct _MatchParams
{
GimpFilteredContainer *filtered_container;
GList *items_to_add;
@@ -54,50 +55,50 @@
} MatchParams;
-static GObject* gimp_filtered_container_constructor (GType type,
- guint n_construct_params,
- GObjectConstructParam *construct_params);
-
-static void gimp_filtered_container_dispose (GObject *object);
-static void gimp_filtered_container_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gimp_filtered_container_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec);
-
-static gint64 gimp_filtered_container_get_memsize (GimpObject *object,
- gint64 *gui_size);
-
-static gboolean gimp_filtered_container_object_matches (GimpFilteredContainer *filtered_container,
- GimpObject *object);
-
-static void gimp_filtered_container_filter (GimpFilteredContainer *filtered_container);
-
-static void gimp_filtered_container_src_add (GimpContainer *src_container,
- GimpObject *obj,
- GimpFilteredContainer *filtered_container);
-static void gimp_filtered_container_src_remove (GimpContainer *src_container,
- GimpObject *obj,
- GimpFilteredContainer *filtered_container);
-static void gimp_filtered_container_src_freeze (GimpContainer *src_container,
- GimpFilteredContainer *filtered_container);
-static void gimp_filtered_container_src_thaw (GimpContainer *src_container,
- GimpFilteredContainer *filtered_container);
-static void gimp_filtered_container_tag_added (GimpTagged *tagged,
- GimpTag *tag,
- GimpFilteredContainer *filtered_container);
-static void gimp_filtered_container_tag_removed (GimpTagged *tagged,
- GimpTag *tag,
- GimpFilteredContainer *filtered_container);
-static void gimp_filtered_container_tagged_item_added (GimpTagged *tagged,
- GimpFilteredContainer *filtered_container);
-static void gimp_filtered_container_tagged_item_removed(GimpTagged *tagged,
- GimpFilteredContainer *filtered_container);
-static void gimp_filtered_container_tag_count_changed (GimpFilteredContainer *filtered_container,
- gint tag_count);
+static GObject * gimp_filtered_container_constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params);
+
+static void gimp_filtered_container_dispose (GObject *object);
+static void gimp_filtered_container_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gimp_filtered_container_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+static gint64 gimp_filtered_container_get_memsize (GimpObject *object,
+ gint64 *gui_size);
+
+static gboolean gimp_filtered_container_object_matches (GimpFilteredContainer *filtered_container,
+ GimpObject *object);
+
+static void gimp_filtered_container_filter (GimpFilteredContainer *filtered_container);
+
+static void gimp_filtered_container_src_add (GimpContainer *src_container,
+ GimpObject *obj,
+ GimpFilteredContainer *filtered_container);
+static void gimp_filtered_container_src_remove (GimpContainer *src_container,
+ GimpObject *obj,
+ GimpFilteredContainer *filtered_container);
+static void gimp_filtered_container_src_freeze (GimpContainer *src_container,
+ GimpFilteredContainer *filtered_container);
+static void gimp_filtered_container_src_thaw (GimpContainer *src_container,
+ GimpFilteredContainer *filtered_container);
+static void gimp_filtered_container_tag_added (GimpTagged *tagged,
+ GimpTag *tag,
+ GimpFilteredContainer *filtered_container);
+static void gimp_filtered_container_tag_removed (GimpTagged *tagged,
+ GimpTag *tag,
+ GimpFilteredContainer *filtered_container);
+static void gimp_filtered_container_tagged_item_added (GimpTagged *tagged,
+ GimpFilteredContainer *filtered_container);
+static void gimp_filtered_container_tagged_item_removed(GimpTagged *tagged,
+ GimpFilteredContainer *filtered_container);
+static void gimp_filtered_container_tag_count_changed (GimpFilteredContainer *filtered_container,
+ gint tag_count);
G_DEFINE_TYPE (GimpFilteredContainer, gimp_filtered_container, GIMP_TYPE_LIST)
@@ -123,14 +124,14 @@
klass->tag_count_changed = gimp_filtered_container_tag_count_changed;
gimp_filtered_container_signals[TAG_COUNT_CHANGED] =
- g_signal_new ("tag-count-changed",
- GIMP_TYPE_FILTERED_CONTAINER,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GimpFilteredContainerClass, tag_count_changed),
- NULL, NULL,
- gimp_marshal_VOID__INT,
- G_TYPE_NONE, 1,
- G_TYPE_INT);
+ g_signal_new ("tag-count-changed",
+ GIMP_TYPE_FILTERED_CONTAINER,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GimpFilteredContainerClass, tag_count_changed),
+ NULL, NULL,
+ gimp_marshal_VOID__INT,
+ G_TYPE_NONE, 1,
+ G_TYPE_INT);
g_object_class_install_property (g_object_class, PROP_SRC_CONTAINER,
g_param_spec_object ("src-container", NULL, NULL,
@@ -142,10 +143,10 @@
static void
gimp_filtered_container_init (GimpFilteredContainer *filtered_container)
{
- filtered_container->src_container = NULL;
- filtered_container->filter = NULL;
- filtered_container->tag_ref_counts = NULL;
- filtered_container->tag_count = 0;
+ filtered_container->src_container = NULL;
+ filtered_container->filter = NULL;
+ filtered_container->tag_ref_counts = NULL;
+ filtered_container->tag_count = 0;
}
static GObject*
@@ -161,9 +162,10 @@
construct_params);
filtered_container = GIMP_FILTERED_CONTAINER (object);
+
filtered_container->tag_ref_counts =
- g_hash_table_new ((GHashFunc)gimp_tag_get_hash,
- (GEqualFunc)gimp_tag_equals);
+ g_hash_table_new ((GHashFunc) gimp_tag_get_hash,
+ (GEqualFunc) gimp_tag_equals);
gimp_container_foreach (filtered_container->src_container,
(GFunc) gimp_filtered_container_tagged_item_added,
@@ -174,9 +176,9 @@
}
static void
-gimp_filtered_container_dispose (GObject *object)
+gimp_filtered_container_dispose (GObject *object)
{
- GimpFilteredContainer *filtered_container = GIMP_FILTERED_CONTAINER (object);
+ GimpFilteredContainer *filtered_container = GIMP_FILTERED_CONTAINER (object);
if (filtered_container->src_container)
{
@@ -192,6 +194,7 @@
g_signal_handlers_disconnect_by_func (filtered_container->src_container,
gimp_filtered_container_src_thaw,
filtered_container);
+
g_object_unref (filtered_container->src_container);
filtered_container->src_container = NULL;
}
@@ -209,49 +212,47 @@
switch (property_id)
{
- case PROP_SRC_CONTAINER:
- {
- filtered_container->src_container = g_value_get_object (value);
- g_object_ref (filtered_container->src_container);
-
- g_signal_connect (filtered_container->src_container, "add",
- G_CALLBACK (gimp_filtered_container_src_add),
- filtered_container);
- g_signal_connect (filtered_container->src_container, "remove",
- G_CALLBACK (gimp_filtered_container_src_remove),
- filtered_container);
- g_signal_connect (filtered_container->src_container, "freeze",
- G_CALLBACK (gimp_filtered_container_src_freeze),
- filtered_container);
- g_signal_connect (filtered_container->src_container, "thaw",
- G_CALLBACK (gimp_filtered_container_src_thaw),
- filtered_container);
- }
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
+ case PROP_SRC_CONTAINER:
+ filtered_container->src_container = g_value_get_object (value);
+ g_object_ref (filtered_container->src_container);
+
+ g_signal_connect (filtered_container->src_container, "add",
+ G_CALLBACK (gimp_filtered_container_src_add),
+ filtered_container);
+ g_signal_connect (filtered_container->src_container, "remove",
+ G_CALLBACK (gimp_filtered_container_src_remove),
+ filtered_container);
+ g_signal_connect (filtered_container->src_container, "freeze",
+ G_CALLBACK (gimp_filtered_container_src_freeze),
+ filtered_container);
+ g_signal_connect (filtered_container->src_container, "thaw",
+ G_CALLBACK (gimp_filtered_container_src_thaw),
+ filtered_container);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
static void
-gimp_filtered_container_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+gimp_filtered_container_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GimpFilteredContainer *filtered_container = GIMP_FILTERED_CONTAINER (object);
switch (property_id)
{
- case PROP_SRC_CONTAINER:
- g_value_set_object (value, filtered_container->src_container);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
+ case PROP_SRC_CONTAINER:
+ g_value_set_object (value, filtered_container->src_container);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
@@ -259,8 +260,8 @@
gimp_filtered_container_get_memsize (GimpObject *object,
gint64 *gui_size)
{
- GimpFilteredContainer *filtered_container = GIMP_FILTERED_CONTAINER (object);
- gint64 memsize = 0;
+ GimpFilteredContainer *filtered_container = GIMP_FILTERED_CONTAINER (object);
+ gint64 memsize = 0;
memsize += (gimp_container_get_n_children (GIMP_CONTAINER (filtered_container)) *
sizeof (GList));
@@ -281,11 +282,11 @@
* Return value: a new #GimpFilteredContainer object.
**/
GimpContainer *
-gimp_filtered_container_new (GimpContainer *src_container,
- GCompareFunc sort_func)
+gimp_filtered_container_new (GimpContainer *src_container,
+ GCompareFunc sort_func)
{
- GimpFilteredContainer *filtered_container;
- GType children_type;
+ GimpFilteredContainer *filtered_container;
+ GType children_type;
g_return_val_if_fail (GIMP_IS_CONTAINER (src_container), NULL);
@@ -311,8 +312,8 @@
* the tags assigned match filtering criteria.
**/
void
-gimp_filtered_container_set_filter (GimpFilteredContainer *filtered_container,
- GList *tags)
+gimp_filtered_container_set_filter (GimpFilteredContainer *filtered_container,
+ GList *tags)
{
g_return_if_fail (GIMP_IS_FILTERED_CONTAINER (filtered_container));
@@ -334,18 +335,19 @@
* not be modified or freed.
**/
const GList *
-gimp_filtered_container_get_filter (GimpFilteredContainer *filtered_container)
+gimp_filtered_container_get_filter (GimpFilteredContainer *filtered_container)
{
g_return_val_if_fail (GIMP_IS_FILTERED_CONTAINER (filtered_container), NULL);
+
return filtered_container->filter;
}
static gboolean
-gimp_filtered_container_object_matches (GimpFilteredContainer *filtered_container,
- GimpObject *object)
+gimp_filtered_container_object_matches (GimpFilteredContainer *filtered_container,
+ GimpObject *object)
{
- GList *filter_tag;
- GList *object_tag;
+ GList *filter_tag;
+ GList *object_tag;
filter_tag = filtered_container->filter;
while (filter_tag)
@@ -382,8 +384,8 @@
}
static void
-gimp_filtered_container_check_needs_remove (GimpObject *object,
- MatchParams *match_params)
+gimp_filtered_container_check_needs_remove (GimpObject *object,
+ MatchParams *match_params)
{
if (! gimp_filtered_container_object_matches (match_params->filtered_container,
object))
@@ -394,10 +396,11 @@
}
static void
-gimp_filtered_container_check_needs_add (GimpObject *object,
- MatchParams *match_params)
+gimp_filtered_container_check_needs_add (GimpObject *object,
+ MatchParams *match_params)
{
- if (gimp_filtered_container_object_matches (match_params->filtered_container, object)
+ if (gimp_filtered_container_object_matches (match_params->filtered_container,
+ object)
&& !gimp_container_have (GIMP_CONTAINER (match_params->filtered_container),
object))
{
@@ -407,10 +410,10 @@
}
static void
-gimp_filtered_container_filter (GimpFilteredContainer *filtered_container)
+gimp_filtered_container_filter (GimpFilteredContainer *filtered_container)
{
- MatchParams match_params;
- GList *iterator;
+ MatchParams match_params;
+ GList *list;
match_params.filtered_container = filtered_container;
match_params.items_to_add = NULL;
@@ -423,18 +426,16 @@
(GFunc) gimp_filtered_container_check_needs_add,
&match_params);
- for (iterator = match_params.items_to_remove; iterator;
- iterator = g_list_next (iterator))
+ for (list = match_params.items_to_remove; list; list = g_list_next (list))
{
gimp_container_remove (GIMP_CONTAINER (filtered_container),
- GIMP_OBJECT (iterator->data));
+ GIMP_OBJECT (list->data));
}
- for (iterator = match_params.items_to_add; iterator;
- iterator = g_list_next (iterator))
+ for (list = match_params.items_to_add; list; list = g_list_next (list))
{
gimp_container_add (GIMP_CONTAINER (filtered_container),
- GIMP_OBJECT (iterator->data));
+ GIMP_OBJECT (list->data));
}
g_list_free (match_params.items_to_add);
@@ -471,32 +472,31 @@
}
static void
-gimp_filtered_container_src_freeze (GimpContainer *src_container,
- GimpFilteredContainer *filtered_container)
+gimp_filtered_container_src_freeze (GimpContainer *src_container,
+ GimpFilteredContainer *filtered_container)
{
gimp_container_freeze (GIMP_CONTAINER (filtered_container));
gimp_container_clear (GIMP_CONTAINER (filtered_container));
}
static void
-gimp_filtered_container_src_thaw (GimpContainer *src_container,
- GimpFilteredContainer *filtered_container)
+gimp_filtered_container_src_thaw (GimpContainer *src_container,
+ GimpFilteredContainer *filtered_container)
{
gimp_filtered_container_filter (filtered_container);
gimp_container_thaw (GIMP_CONTAINER (filtered_container));
}
static void
-gimp_filtered_container_tagged_item_added (GimpTagged *tagged,
- GimpFilteredContainer *filtered_container)
+gimp_filtered_container_tagged_item_added (GimpTagged *tagged,
+ GimpFilteredContainer *filtered_container)
{
- GList *tag_iterator;
+ GList *list;
- for (tag_iterator = gimp_tagged_get_tags (tagged); tag_iterator;
- tag_iterator = g_list_next (tag_iterator))
+ for (list = gimp_tagged_get_tags (tagged); list; list = g_list_next (list))
{
gimp_filtered_container_tag_added (tagged,
- GIMP_TAG (tag_iterator->data),
+ list->data,
filtered_container);
}
@@ -509,10 +509,10 @@
}
static void
-gimp_filtered_container_tagged_item_removed (GimpTagged *tagged,
- GimpFilteredContainer *filtered_container)
+gimp_filtered_container_tagged_item_removed (GimpTagged *tagged,
+ GimpFilteredContainer *filtered_container)
{
- GList *tag_iterator;
+ GList *list;
g_signal_handlers_disconnect_by_func (tagged,
G_CALLBACK (gimp_filtered_container_tag_added),
@@ -521,11 +521,10 @@
G_CALLBACK (gimp_filtered_container_tag_removed),
filtered_container);
- for (tag_iterator = gimp_tagged_get_tags (tagged); tag_iterator;
- tag_iterator = g_list_next (tag_iterator))
+ for (list = gimp_tagged_get_tags (tagged); list; list = g_list_next (list))
{
gimp_filtered_container_tag_removed (tagged,
- GIMP_TAG (tag_iterator->data),
+ GIMP_TAG (list->data),
filtered_container);
}
@@ -536,7 +535,7 @@
GimpTag *tag,
GimpFilteredContainer *filtered_container)
{
- gint ref_count;
+ gint ref_count;
ref_count = GPOINTER_TO_INT (g_hash_table_lookup (filtered_container->tag_ref_counts,
tag));
@@ -547,17 +546,17 @@
{
filtered_container->tag_count++;
g_signal_emit (filtered_container,
- gimp_filtered_container_signals[TAG_COUNT_CHANGED],
- 0, filtered_container->tag_count);
+ gimp_filtered_container_signals[TAG_COUNT_CHANGED], 0,
+ filtered_container->tag_count);
}
}
static void
-gimp_filtered_container_tag_removed (GimpTagged *tagged,
- GimpTag *tag,
- GimpFilteredContainer *filtered_container)
+gimp_filtered_container_tag_removed (GimpTagged *tagged,
+ GimpTag *tag,
+ GimpFilteredContainer *filtered_container)
{
- gint ref_count;
+ gint ref_count;
ref_count = GPOINTER_TO_INT (g_hash_table_lookup (filtered_container->tag_ref_counts,
tag));
@@ -573,15 +572,15 @@
{
filtered_container->tag_count--;
g_signal_emit (filtered_container,
- gimp_filtered_container_signals[TAG_COUNT_CHANGED],
- 0, filtered_container->tag_count);
+ gimp_filtered_container_signals[TAG_COUNT_CHANGED], 0,
+ filtered_container->tag_count);
}
}
}
static void
-gimp_filtered_container_tag_count_changed (GimpFilteredContainer *container,
- gint tag_count)
+gimp_filtered_container_tag_count_changed (GimpFilteredContainer *container,
+ gint tag_count)
{
}
@@ -603,4 +602,3 @@
return container->tag_count;
}
-
Modified: trunk/app/core/gimpfilteredcontainer.h
==============================================================================
--- trunk/app/core/gimpfilteredcontainer.h (original)
+++ trunk/app/core/gimpfilteredcontainer.h Mon Mar 2 23:33:24 2009
@@ -36,33 +36,33 @@
struct _GimpFilteredContainer
{
- GimpList parent_instance;
+ GimpList parent_instance;
- GimpContainer *src_container;
- GList *filter;
- GHashTable *tag_ref_counts;
- gint tag_count;
+ GimpContainer *src_container;
+ GList *filter;
+ GHashTable *tag_ref_counts;
+ gint tag_count;
};
struct _GimpFilteredContainerClass
{
GimpContainerClass parent_class;
- void (* tag_count_changed) (GimpFilteredContainer *container,
- gint count);
+ void (* tag_count_changed) (GimpFilteredContainer *container,
+ gint count);
};
GType gimp_filtered_container_get_type (void) G_GNUC_CONST;
-GimpContainer * gimp_filtered_container_new (GimpContainer *src_container,
- GCompareFunc sort_func);
+GimpContainer * gimp_filtered_container_new (GimpContainer *src_container,
+ GCompareFunc sort_func);
-void gimp_filtered_container_set_filter (GimpFilteredContainer *filtered_container,
- GList *tags);
+void gimp_filtered_container_set_filter (GimpFilteredContainer *filtered_container,
+ GList *tags);
+const GList * gimp_filtered_container_get_filter (GimpFilteredContainer *filtered_container);
-const GList * gimp_filtered_container_get_filter (GimpFilteredContainer *filtered_container);
+gint gimp_filtered_container_get_tag_count (GimpFilteredContainer *container);
-gint gimp_filtered_container_get_tag_count (GimpFilteredContainer *container);
#endif /* __GIMP_FILTERED_CONTAINER_H__ */
Modified: trunk/app/core/gimptag.c
==============================================================================
--- trunk/app/core/gimptag.c (original)
+++ trunk/app/core/gimptag.c Mon Mar 2 23:33:24 2009
@@ -60,18 +60,16 @@
GimpTag *
gimp_tag_new (const char *tag_string)
{
- GimpTag *tag;
- gchar *tag_name;
- gchar *case_folded;
- gchar *collate_key;
+ GimpTag *tag;
+ gchar *tag_name;
+ gchar *case_folded;
+ gchar *collate_key;
g_return_val_if_fail (tag_string != NULL, NULL);
tag_name = gimp_tag_string_make_valid (tag_string);
if (! tag_name)
- {
- return NULL;
- }
+ return NULL;
tag = g_object_new (GIMP_TYPE_TAG, NULL);
@@ -102,18 +100,16 @@
GimpTag *
gimp_tag_try_new (const char *tag_string)
{
- GimpTag *tag;
- gchar *tag_name;
- gchar *case_folded;
- gchar *collate_key;
- GQuark tag_quark;
- GQuark collate_key_quark;
+ GimpTag *tag;
+ gchar *tag_name;
+ gchar *case_folded;
+ gchar *collate_key;
+ GQuark tag_quark;
+ GQuark collate_key_quark;
tag_name = gimp_tag_string_make_valid (tag_string);
if (! tag_name)
- {
- return NULL;
- }
+ return NULL;
case_folded = g_utf8_casefold (tag_name, -1);
collate_key = g_utf8_collate_key (case_folded, -1);
@@ -130,13 +126,12 @@
tag_quark = g_quark_from_string (tag_name);
g_free (tag_name);
if (! tag_quark)
- {
- return NULL;
- }
+ return NULL;
tag = g_object_new (GIMP_TYPE_TAG, NULL);
tag->tag = tag_quark;
tag->collate_key = collate_key_quark;
+
return tag;
}
@@ -149,7 +144,7 @@
* Return value: name of tag.
**/
const gchar *
-gimp_tag_get_name (GimpTag *tag)
+gimp_tag_get_name (GimpTag *tag)
{
g_return_val_if_fail (GIMP_IS_TAG (tag), NULL);
@@ -166,7 +161,7 @@
* Return value: hash value for tag.
**/
guint
-gimp_tag_get_hash (GimpTag *tag)
+gimp_tag_get_hash (GimpTag *tag)
{
g_return_val_if_fail (GIMP_IS_TAG (tag), -1);
@@ -203,8 +198,8 @@
* Return value: meaning of return value is the same as in strcmp().
**/
int
-gimp_tag_compare_func (const void *p1,
- const void *p2)
+gimp_tag_compare_func (const void *p1,
+ const void *p2)
{
GimpTag *t1 = GIMP_TAG (p1);
GimpTag *t2 = GIMP_TAG (p2);
@@ -225,8 +220,8 @@
* Return value: meaning of return value is the same as in strcmp().
**/
gint
-gimp_tag_compare_with_string (GimpTag *tag,
- const char *tag_string)
+gimp_tag_compare_with_string (GimpTag *tag,
+ const gchar *tag_string)
{
gchar *case_folded;
const gchar *collate_key;
@@ -257,20 +252,18 @@
* using g_free().
**/
gchar *
-gimp_tag_string_make_valid (const gchar *tag_string)
+gimp_tag_string_make_valid (const gchar *tag_string)
{
- gchar *tag;
- GString *buffer;
- gchar *tag_cursor;
- gunichar c;
+ gchar *tag;
+ GString *buffer;
+ gchar *tag_cursor;
+ gunichar c;
g_return_val_if_fail (tag_string, NULL);
tag = g_utf8_normalize (tag_string, -1, G_NORMALIZE_ALL);
if (! tag)
- {
- return NULL;
- }
+ return NULL;
tag = g_strstrip (tag);
if (! *tag)
Modified: trunk/app/core/gimptagcache.c
==============================================================================
--- trunk/app/core/gimptagcache.c (original)
+++ trunk/app/core/gimptagcache.c Mon Mar 2 23:33:24 2009
@@ -50,22 +50,22 @@
enum
{
PROP_0,
- PROP_GIMP,
+ PROP_GIMP
};
typedef struct
{
- GQuark identifier;
- GQuark checksum;
- GList *tags;
- guint referenced : 1;
+ GQuark identifier;
+ GQuark checksum;
+ GList *tags;
+ guint referenced : 1;
} GimpTagCacheRecord;
typedef struct
{
- GArray *records;
- GimpTagCacheRecord current_record;
+ GArray *records;
+ GimpTagCacheRecord current_record;
} GimpTagCacheParseData;
struct _GimpTagCachePriv
@@ -175,8 +175,8 @@
gimp_tag_cache_get_memsize (GimpObject *object,
gint64 *gui_size)
{
- GimpTagCache *cache = GIMP_TAG_CACHE (object);
- gint64 memsize = 0;
+ GimpTagCache *cache = GIMP_TAG_CACHE (object);
+ gint64 memsize = 0;
memsize += gimp_g_list_get_memsize (cache->priv->containers, 0);
memsize += cache->priv->records->len * sizeof (GimpTagCacheRecord);
@@ -214,14 +214,15 @@
* cache is saved to file, tags are collected from objects in priv->containers.
**/
void
-gimp_tag_cache_add_container (GimpTagCache *cache,
- GimpContainer *container)
+gimp_tag_cache_add_container (GimpTagCache *cache,
+ GimpContainer *container)
{
g_return_if_fail (GIMP_IS_TAG_CACHE (cache));
g_return_if_fail (GIMP_IS_CONTAINER (container));
cache->priv->containers = g_list_append (cache->priv->containers, container);
- gimp_container_foreach (container, (GFunc) gimp_tag_cache_object_initialize, cache);
+ gimp_container_foreach (container, (GFunc) gimp_tag_cache_object_initialize,
+ cache);
g_signal_connect_swapped (container, "add",
G_CALLBACK (gimp_tag_cache_container_add_callback),
@@ -229,15 +230,15 @@
}
static void
-gimp_tag_cache_add_object (GimpTagCache *cache,
- GimpTagged *tagged)
+gimp_tag_cache_add_object (GimpTagCache *cache,
+ GimpTagged *tagged)
{
- gchar *identifier;
- GQuark identifier_quark = 0;
- gchar *checksum_string;
- GQuark checksum_quark;
- GList *tag_iterator;
- gint i;
+ gchar *identifier;
+ GQuark identifier_quark = 0;
+ gchar *checksum_string;
+ GQuark checksum_quark;
+ GList *list;
+ gint i;
identifier = gimp_tagged_get_identifier (tagged);
identifier_quark = g_quark_try_string (identifier);
@@ -254,11 +255,11 @@
if (rec->identifier == identifier_quark)
{
- for (tag_iterator = rec->tags; tag_iterator;
- tag_iterator = g_list_next (tag_iterator))
+ for (list = rec->tags; list; list = g_list_next (list))
{
- gimp_tagged_add_tag (tagged, GIMP_TAG (tag_iterator->data));
+ gimp_tagged_add_tag (tagged, GIMP_TAG (list->data));
}
+
rec->referenced = TRUE;
return;
}
@@ -278,16 +279,16 @@
if (rec->checksum == checksum_quark)
{
- printf ("remapping identifier: %s ==> %s\n",
- g_quark_to_string (rec->identifier),
- g_quark_to_string (identifier_quark));
+ g_printerr ("remapping identifier: %s ==> %s\n",
+ g_quark_to_string (rec->identifier),
+ g_quark_to_string (identifier_quark));
rec->identifier = identifier_quark;
- for (tag_iterator = rec->tags; tag_iterator;
- tag_iterator = g_list_next (tag_iterator))
+ for (list = rec->tags; list; list = g_list_next (list))
{
- gimp_tagged_add_tag (tagged, GIMP_TAG (tag_iterator->data));
+ gimp_tagged_add_tag (tagged, GIMP_TAG (list->data));
}
+
rec->referenced = TRUE;
return;
}
@@ -297,31 +298,36 @@
}
static void
-gimp_tag_cache_object_initialize (GimpTagged *tagged,
- GimpTagCache *cache)
+gimp_tag_cache_object_initialize (GimpTagged *tagged,
+ GimpTagCache *cache)
{
gimp_tag_cache_add_object (cache, tagged);
}
static void
-gimp_tag_cache_tagged_to_cache_record_foreach (GimpTagged *tagged,
- GList **cache_records)
+gimp_tag_cache_tagged_to_cache_record_foreach (GimpTagged *tagged,
+ GList **cache_records)
{
- gchar *identifier;
- gchar *checksum;
- GimpTagCacheRecord *cache_rec;
+ gchar *identifier;
identifier = gimp_tagged_get_identifier (tagged);
+
if (identifier)
{
- cache_rec = (GimpTagCacheRecord*) g_malloc (sizeof (GimpTagCacheRecord));
- cache_rec->identifier = g_quark_from_string (identifier);
+ GimpTagCacheRecord *cache_rec = g_new (GimpTagCacheRecord, 1);
+ gchar *checksum;
+
checksum = gimp_tagged_get_checksum (tagged);
- cache_rec->checksum = g_quark_from_string (checksum);
- g_free (checksum);
+
+ cache_rec->identifier = g_quark_from_string (identifier);
+ cache_rec->checksum = g_quark_from_string (checksum);
cache_rec->tags = g_list_copy (gimp_tagged_get_tags (tagged));
+
+ g_free (checksum);
+
*cache_records = g_list_append (*cache_records, cache_rec);
}
+
g_free (identifier);
}
@@ -332,30 +338,33 @@
* Saves tag cache to cache file.
**/
void
-gimp_tag_cache_save (GimpTagCache *cache)
+gimp_tag_cache_save (GimpTagCache *cache)
{
- GString *buf;
- GList *saved_records;
- GList *iterator;
- gchar *filename;
- GError *error;
- gint i;
+ GString *buf;
+ GList *saved_records;
+ GList *iterator;
+ gchar *filename;
+ GError *error = NULL;
+ gint i;
g_return_if_fail (GIMP_IS_TAG_CACHE (cache));
saved_records = NULL;
for (i = 0; i < cache->priv->records->len; i++)
{
- GimpTagCacheRecord *current_record = &g_array_index(cache->priv->records, GimpTagCacheRecord, i);
- if (! current_record->referenced
- && current_record->tags)
+ GimpTagCacheRecord *current_record = &g_array_index (cache->priv->records, GimpTagCacheRecord, i);
+
+ if (! current_record->referenced && current_record->tags)
{
/* keep tagged objects which have tags assigned
- * but were not loaded. */
- GimpTagCacheRecord *record_copy = (GimpTagCacheRecord*) g_malloc (sizeof (GimpTagCacheRecord));
+ * but were not loaded.
+ */
+ GimpTagCacheRecord *record_copy = g_new (GimpTagCacheRecord, 1);
+
record_copy->identifier = current_record->identifier;
- record_copy->checksum = current_record->checksum;
- record_copy->tags = g_list_copy (current_record->tags);
+ record_copy->checksum = current_record->checksum;
+ record_copy->tags = g_list_copy (current_record->tags);
+
saved_records = g_list_append (saved_records, record_copy);
}
}
@@ -371,10 +380,9 @@
buf = g_string_new ("");
g_string_append (buf, "<?xml version='1.0' encoding='UTF-8'?>\n");
g_string_append (buf, "<tags>\n");
- for (iterator = saved_records; iterator;
- iterator = g_list_next (iterator))
+ for (iterator = saved_records; iterator; iterator = g_list_next (iterator))
{
- GimpTagCacheRecord *cache_rec = (GimpTagCacheRecord*) iterator->data;
+ GimpTagCacheRecord *cache_rec = iterator->data;
GList *tag_iterator;
gchar *identifier_string;
gchar *tag_string;
@@ -386,21 +394,22 @@
g_free (identifier_string);
for (tag_iterator = cache_rec->tags; tag_iterator;
- tag_iterator = g_list_next (tag_iterator))
+ tag_iterator = g_list_next (tag_iterator))
{
tag_string = g_markup_escape_text (gimp_tag_get_name (GIMP_TAG (tag_iterator->data)), -1);
g_string_append_printf (buf, " <tag>%s</tag>\n", tag_string);
g_free (tag_string);
}
+
g_string_append (buf, " </resource>\n");
}
+
g_string_append (buf, "</tags>\n");
filename = g_build_filename (gimp_directory (), GIMP_TAG_CACHE_FILE, NULL);
- error = NULL;
- if (!g_file_set_contents (filename, buf->str, buf->len, &error))
+ if (! g_file_set_contents (filename, buf->str, buf->len, &error))
{
- printf ("Error while saving tag cache: %s\n", error->message);
+ g_printerr ("Error while saving tag cache: %s\n", error->message);
g_error_free (error);
}
@@ -410,10 +419,12 @@
for (iterator = saved_records; iterator;
iterator = g_list_next (iterator))
{
- GimpTagCacheRecord *cache_rec = (GimpTagCacheRecord*) iterator->data;
+ GimpTagCacheRecord *cache_rec = iterator->data;
+
g_list_free (cache_rec->tags);
g_free (cache_rec);
}
+
g_list_free (saved_records);
}
@@ -424,13 +435,13 @@
* Loads tag cache from file.
**/
void
-gimp_tag_cache_load (GimpTagCache *cache)
+gimp_tag_cache_load (GimpTagCache *cache)
{
- gchar *filename;
- GError *error;
- GMarkupParser markup_parser;
- GimpXmlParser *xml_parser;
- GimpTagCacheParseData parse_data;
+ gchar *filename;
+ GError *error = NULL;
+ GMarkupParser markup_parser;
+ GimpXmlParser *xml_parser;
+ GimpTagCacheParseData parse_data;
g_return_if_fail (GIMP_IS_TAG_CACHE (cache));
@@ -438,20 +449,20 @@
cache->priv->records = g_array_set_size (cache->priv->records, 0);
filename = g_build_filename (gimp_directory (), GIMP_TAG_CACHE_FILE, NULL);
- error = NULL;
parse_data.records = g_array_new (FALSE, FALSE, sizeof (GimpTagCacheRecord));
memset (&parse_data.current_record, 0, sizeof (GimpTagCacheRecord));
markup_parser.start_element = gimp_tag_cache_load_start_element;
- markup_parser.end_element = gimp_tag_cache_load_end_element;
- markup_parser.text = gimp_tag_cache_load_text;
- markup_parser.passthrough = NULL;
- markup_parser.error = gimp_tag_cache_load_error;
+ markup_parser.end_element = gimp_tag_cache_load_end_element;
+ markup_parser.text = gimp_tag_cache_load_text;
+ markup_parser.passthrough = NULL;
+ markup_parser.error = gimp_tag_cache_load_error;
+
xml_parser = gimp_xml_parser_new (&markup_parser, &parse_data);
if (! gimp_xml_parser_parse_file (xml_parser, filename, &error))
{
- printf ("Failed to parse tag cache.\n");
+ g_printerr ("Failed to parse tag cache.\n");
}
else
{
@@ -466,24 +477,26 @@
}
static void
-gimp_tag_cache_load_start_element (GMarkupParseContext *context,
- const gchar *element_name,
- const gchar **attribute_names,
- const gchar **attribute_values,
- gpointer user_data,
- GError **error)
+gimp_tag_cache_load_start_element (GMarkupParseContext *context,
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer user_data,
+ GError **error)
{
- GimpTagCacheParseData *parse_data = (GimpTagCacheParseData*) user_data;
+ GimpTagCacheParseData *parse_data = user_data;
if (! strcmp (element_name, "resource"))
{
- const gchar *identifier;
- const gchar *checksum;
+ const gchar *identifier;
+ const gchar *checksum;
- identifier = gimp_tag_cache_attribute_name_to_value (attribute_names, attribute_values,
- "identifier");
- checksum = gimp_tag_cache_attribute_name_to_value (attribute_names, attribute_values,
- "checksum");
+ identifier = gimp_tag_cache_attribute_name_to_value (attribute_names,
+ attribute_values,
+ "identifier");
+ checksum = gimp_tag_cache_attribute_name_to_value (attribute_names,
+ attribute_values,
+ "checksum");
if (! identifier)
{
@@ -507,7 +520,7 @@
gpointer user_data,
GError **error)
{
- GimpTagCacheParseData *parse_data = (GimpTagCacheParseData*) user_data;
+ GimpTagCacheParseData *parse_data = user_data;
if (strcmp (element_name, "resource") == 0)
{
@@ -518,21 +531,20 @@
}
static void
-gimp_tag_cache_load_text (GMarkupParseContext *context,
- const gchar *text,
- gsize text_len,
- gpointer user_data,
- GError **error)
+gimp_tag_cache_load_text (GMarkupParseContext *context,
+ const gchar *text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error)
{
- GimpTagCacheParseData *parse_data = (GimpTagCacheParseData*) user_data;
+ GimpTagCacheParseData *parse_data = user_data;
const gchar *current_element;
gchar buffer[2048];
GimpTag *tag;
current_element = g_markup_parse_context_get_element (context);
- if (current_element &&
- strcmp (current_element, "tag") == 0)
+ if (current_element && strcmp (current_element, "tag") == 0)
{
if (text_len >= sizeof (buffer))
{
@@ -553,7 +565,7 @@
else
{
g_warning ("dropping invalid tag '%s' from '%s'\n", buffer,
- g_quark_to_string (parse_data->current_record.identifier));
+ g_quark_to_string (parse_data->current_record.identifier));
}
}
}
@@ -567,9 +579,9 @@
}
static const gchar*
-gimp_tag_cache_attribute_name_to_value (const gchar **attribute_names,
- const gchar **attribute_values,
- const gchar *name)
+gimp_tag_cache_attribute_name_to_value (const gchar **attribute_names,
+ const gchar **attribute_values,
+ const gchar *name)
{
while (*attribute_names)
{
Modified: trunk/app/core/gimptagcache.h
==============================================================================
--- trunk/app/core/gimptagcache.h (original)
+++ trunk/app/core/gimptagcache.h Mon Mar 2 23:33:24 2009
@@ -24,6 +24,7 @@
#include "gimpobject.h"
+
#define GIMP_TYPE_TAG_CACHE (gimp_tag_cache_get_type ())
#define GIMP_TAG_CACHE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TAG_CACHE, GimpTagCache))
#define GIMP_TAG_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TAG_CACHE, GimpTagCacheClass))
@@ -37,14 +38,14 @@
struct _GimpTagCache
{
- GimpObject parent_instance;
+ GimpObject parent_instance;
- GimpTagCachePriv *priv;
+ GimpTagCachePriv *priv;
};
struct _GimpTagCacheClass
{
- GimpObjectClass parent_class;
+ GimpObjectClass parent_class;
};
@@ -52,10 +53,11 @@
GimpTagCache * gimp_tag_cache_new (void);
-void gimp_tag_cache_save (GimpTagCache *cache);
-void gimp_tag_cache_load (GimpTagCache *cache);
+void gimp_tag_cache_save (GimpTagCache *cache);
+void gimp_tag_cache_load (GimpTagCache *cache);
+
+void gimp_tag_cache_add_container (GimpTagCache *cache,
+ GimpContainer *container);
-void gimp_tag_cache_add_container (GimpTagCache *cache,
- GimpContainer *container);
#endif /* __GIMP_TAG_CACHE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]