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
This commit is contained in:
Alexia Death
2011-12-02 22:09:06 +02:00
parent b6767ba0a6
commit aa9806c687
4 changed files with 136 additions and 57 deletions

View File

@ -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);
}
}
/**

View File

@ -46,6 +46,7 @@ gimp_tag_init (GimpTag *tag)
{
tag->tag = 0;
tag->collate_key = 0;
tag->internal = FALSE;
}
/**
@ -135,6 +136,40 @@ gimp_tag_try_new (const char *tag_string)
return tag;
}
/**
* 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.

View File

@ -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,

View File

@ -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);
if (rec->identifier == identifier_quark)
{
GimpTagCacheRecord *rec = &g_array_index (cache->priv->records,
GimpTagCacheRecord, i);
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));
}
}
}
checksum = gimp_tagged_get_checksum (tagged);
if (checksum)
{
checksum_quark = g_quark_try_string (checksum);
g_free (checksum);
}
if (checksum_quark)
{
for (i = 0; i < cache->priv->records->len; i++)
{
GimpTagCacheRecord *rec = &g_array_index (cache->priv->records,
GimpTagCacheRecord, i);
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)");
#endif
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;
}
rec->referenced = TRUE;
return;
}
}
}
checksum = gimp_tagged_get_checksum (tagged);
if (checksum)
{
checksum_quark = g_quark_try_string (checksum);
g_free (checksum);
}
if (checksum_quark)
{
for (i = 0; i < cache->priv->records->len; i++)
{
GimpTagCacheRecord *rec = &g_array_index (cache->priv->records,
GimpTagCacheRecord, i);
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)");
#endif
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;
}
}
}
}
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");