[gimp] app: Make resource subfolders elements in the tag cloud
- From: Alexia Death <alexiade src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: Make resource subfolders elements in the tag cloud
- Date: Sun, 4 Dec 2011 18:36:15 +0000 (UTC)
commit aa9806c6871d2a5de1b5a670e7d074e6be38d6be
Author: Alexia Death <alexiadeath gmail com>
Date: Fri Dec 2 22:09:06 2011 +0200
app: Make resource subfolders elements in the tag cloud
This patch does following things for this purpose:
* Adds intrernal flag to GimpTag api
* Modifies GimpData gimp_data_set_filename to use the last element
of the path, unless blacklisted, as internal tag for the resource.
* Modify tag cache to not save internal tags
* Removes a check for existing tags when objects are added to tag cache
app/core/gimpdata.c | 35 +++++++++++++++++
app/core/gimptag.c | 35 +++++++++++++++++
app/core/gimptag.h | 7 +++
app/core/gimptagcache.c | 94 ++++++++++++++++++++++++-----------------------
4 files changed, 125 insertions(+), 46 deletions(-)
---
diff --git a/app/core/gimpdata.c b/app/core/gimpdata.c
index b396810..9247fcb 100644
--- a/app/core/gimpdata.c
+++ b/app/core/gimpdata.c
@@ -746,6 +746,41 @@ gimp_data_set_filename (GimpData *data,
if (! GIMP_DATA_GET_CLASS (data)->save)
private->writable = FALSE;
}
+
+ if (private->filename)
+ {
+ const gchar *tag_blacklist[] = { "brushes",
+ "dynamics",
+ "patterns",
+ "palettes",
+ "gradients",
+ "tool-presets" };
+
+ gchar *file_path = g_path_get_dirname (private->filename);
+ gchar *tag_text = g_path_get_basename (file_path);
+ gint i = 0;
+ gboolean blacklisted = FALSE;
+
+ for (i = 0; i < G_N_ELEMENTS (tag_blacklist); i++)
+ {
+ if (! g_strcmp0 (tag_text, tag_blacklist[i]))
+ {
+ blacklisted = TRUE;
+ }
+ }
+
+ if (! blacklisted)
+ {
+ GimpTag *tag = gimp_tag_new (tag_text);
+
+ gimp_tag_set_internal (tag, TRUE);
+ gimp_tagged_add_tag (GIMP_TAGGED (data), tag);
+ g_object_unref (tag);
+ }
+
+ g_free (file_path);
+ g_free (tag_text);
+ }
}
/**
diff --git a/app/core/gimptag.c b/app/core/gimptag.c
index 13e8b7c..8d0639a 100644
--- a/app/core/gimptag.c
+++ b/app/core/gimptag.c
@@ -46,6 +46,7 @@ gimp_tag_init (GimpTag *tag)
{
tag->tag = 0;
tag->collate_key = 0;
+ tag->internal = FALSE;
}
/**
@@ -136,6 +137,40 @@ gimp_tag_try_new (const char *tag_string)
}
/**
+ * gimp_tag_get_internal:
+ * @tag: a gimp tag.
+ *
+ * Retrieve internal status of the tag.
+ *
+ * Return value: internal status of tag. Internal tags are not saved.
+ **/
+gboolean
+gimp_tag_get_internal (GimpTag *tag)
+{
+ g_return_val_if_fail (GIMP_IS_TAG (tag), FALSE);
+
+ return tag->internal;
+}
+
+/**
+ * gimp_tag_set_internal:
+ * @tag: a gimp tag.
+ * @inernal: desired tag internal status
+ *
+ * Set internal status of the tag. Internal tags are usually automaticaly
+ * generated and will not be saved into users tag cache.
+ *
+ **/
+void
+gimp_tag_set_internal (GimpTag *tag, gboolean internal)
+{
+ g_return_if_fail (GIMP_IS_TAG (tag));
+
+ tag->internal = internal;
+}
+
+
+/**
* gimp_tag_get_name:
* @tag: a gimp tag.
*
diff --git a/app/core/gimptag.h b/app/core/gimptag.h
index dcdbaff..fc168f1 100644
--- a/app/core/gimptag.h
+++ b/app/core/gimptag.h
@@ -41,6 +41,8 @@ struct _GimpTag
GQuark tag;
GQuark collate_key;
+
+ gboolean internal; /* Tags that are not serialized to disk */
};
struct _GimpTagClass
@@ -55,6 +57,11 @@ GimpTag * gimp_tag_try_new (const gchar *tag_string);
const gchar * gimp_tag_get_name (GimpTag *tag);
guint gimp_tag_get_hash (GimpTag *tag);
+
+gboolean gimp_tag_get_internal (GimpTag *tag);
+void gimp_tag_set_internal (GimpTag *tag,
+ gboolean internal);
+
gboolean gimp_tag_equals (const GimpTag *tag,
const GimpTag *other);
gint gimp_tag_compare_func (const void *p1,
diff --git a/app/core/gimptagcache.c b/app/core/gimptagcache.c
index b6019c6..bc470ed 100644
--- a/app/core/gimptagcache.c
+++ b/app/core/gimptagcache.c
@@ -238,6 +238,10 @@ gimp_tag_cache_add_object (GimpTagCache *cache,
{
gchar *identifier;
GQuark identifier_quark = 0;
+ gchar *checksum;
+ GQuark checksum_quark = 0;
+ GList *list;
+ gint i;
identifier = gimp_tagged_get_identifier (tagged);
@@ -247,69 +251,62 @@ gimp_tag_cache_add_object (GimpTagCache *cache,
g_free (identifier);
}
- if (! gimp_tagged_get_tags (tagged))
+ if (identifier_quark)
{
- gchar *checksum;
- GQuark checksum_quark = 0;
- GList *list;
- gint i;
-
- if (identifier_quark)
+ for (i = 0; i < cache->priv->records->len; i++)
{
- for (i = 0; i < cache->priv->records->len; i++)
- {
- GimpTagCacheRecord *rec = &g_array_index (cache->priv->records,
- GimpTagCacheRecord, i);
+ GimpTagCacheRecord *rec = &g_array_index (cache->priv->records,
+ GimpTagCacheRecord, i);
- if (rec->identifier == identifier_quark)
+ if (rec->identifier == identifier_quark)
+ {
+ for (list = rec->tags; list; list = g_list_next (list))
{
- for (list = rec->tags; list; list = g_list_next (list))
- {
- gimp_tagged_add_tag (tagged, GIMP_TAG (list->data));
- }
-
- rec->referenced = TRUE;
- return;
+ gimp_tagged_add_tag (tagged, GIMP_TAG (list->data));
}
+
+ rec->referenced = TRUE;
+ return;
}
}
+ }
- checksum = gimp_tagged_get_checksum (tagged);
+ checksum = gimp_tagged_get_checksum (tagged);
- if (checksum)
- {
- checksum_quark = g_quark_try_string (checksum);
- g_free (checksum);
- }
+ if (checksum)
+ {
+ checksum_quark = g_quark_try_string (checksum);
+ g_free (checksum);
+ }
- if (checksum_quark)
+ if (checksum_quark)
+ {
+ for (i = 0; i < cache->priv->records->len; i++)
{
- for (i = 0; i < cache->priv->records->len; i++)
- {
- GimpTagCacheRecord *rec = &g_array_index (cache->priv->records,
- GimpTagCacheRecord, i);
+ GimpTagCacheRecord *rec = &g_array_index (cache->priv->records,
+ GimpTagCacheRecord, i);
- if (rec->checksum == checksum_quark)
- {
+ if (rec->checksum == checksum_quark)
+ {
#if DEBUG_GIMP_TAG_CACHE
- g_printerr ("remapping identifier: %s ==> %s\n",
- rec->identifier ? g_quark_to_string (rec->identifier) : "(NULL)",
- identifier_quark ? g_quark_to_string (identifier_quark) : "(NULL)");
+ g_printerr ("remapping identifier: %s ==> %s\n",
+ rec->identifier ? g_quark_to_string (rec->identifier) : "(NULL)",
+ identifier_quark ? g_quark_to_string (identifier_quark) : "(NULL)");
#endif
- rec->identifier = identifier_quark;
+ rec->identifier = identifier_quark;
- for (list = rec->tags; list; list = g_list_next (list))
- {
- gimp_tagged_add_tag (tagged, GIMP_TAG (list->data));
- }
-
- rec->referenced = TRUE;
- return;
+ for (list = rec->tags; list; list = g_list_next (list))
+ {
+ gimp_tagged_add_tag (tagged, GIMP_TAG (list->data));
}
+
+ rec->referenced = TRUE;
+ return;
}
}
}
+
}
static void
@@ -415,9 +412,14 @@ gimp_tag_cache_save (GimpTagCache *cache)
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);
+ GimpTag *tag = GIMP_TAG (tag_iterator->data);
+
+ if (! gimp_tag_get_internal (tag))
+ {
+ tag_string = g_markup_escape_text (gimp_tag_get_name (tag), -1);
+ g_string_append_printf (buf, " <tag>%s</tag>\n", tag_string);
+ g_free (tag_string);
+ }
}
g_string_append (buf, " </resource>\n");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]