2010-09-20 18:18:30 +02:00
|
|
|
/*
|
2012-08-29 18:44:47 +02:00
|
|
|
* ld-category.c
|
2010-09-20 18:18:30 +02:00
|
|
|
*
|
|
|
|
* This file is a part of logdiag.
|
2011-01-08 06:44:40 +01:00
|
|
|
* Copyright Přemysl Janouch 2010 - 2011. All rights reserved.
|
2010-09-20 18:18:30 +02:00
|
|
|
*
|
|
|
|
* See the file LICENSE for licensing information.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-01-10 11:20:14 +01:00
|
|
|
#include "liblogdiag.h"
|
2010-09-20 18:18:30 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-08-29 18:44:47 +02:00
|
|
|
* SECTION:ld-category
|
2011-01-28 17:39:40 +01:00
|
|
|
* @short_description: A category of symbols
|
2010-09-25 16:14:09 +02:00
|
|
|
* @see_also: #LdSymbol, #LdLibrary
|
2010-09-20 18:18:30 +02:00
|
|
|
*
|
2012-08-29 18:44:47 +02:00
|
|
|
* #LdCategory represents a category of #LdSymbol objects.
|
2010-09-20 18:18:30 +02:00
|
|
|
*/
|
|
|
|
|
2010-09-30 05:19:31 +02:00
|
|
|
/*
|
2012-08-29 18:44:47 +02:00
|
|
|
* LdCategoryPrivate:
|
2012-08-30 07:39:40 +02:00
|
|
|
* @parent: the parent of this category.
|
2011-01-28 17:39:40 +01:00
|
|
|
* @name: the name of this category.
|
2012-08-29 15:46:20 +02:00
|
|
|
* @human_name: the localized human-readable name of this category.
|
2012-08-11 07:37:40 +02:00
|
|
|
* @symbols: (element-type LdSymbol *): symbols in this category.
|
2012-08-29 18:44:47 +02:00
|
|
|
* @subcategories: (element-type LdCategory *) children of this category.
|
2010-09-30 05:19:31 +02:00
|
|
|
*/
|
2012-08-29 18:44:47 +02:00
|
|
|
struct _LdCategoryPrivate
|
2010-09-30 05:19:31 +02:00
|
|
|
{
|
2012-08-30 07:39:40 +02:00
|
|
|
LdCategory *parent;
|
2010-09-30 05:19:31 +02:00
|
|
|
gchar *name;
|
2010-12-11 01:40:05 +01:00
|
|
|
gchar *human_name;
|
2012-08-11 07:37:40 +02:00
|
|
|
GSList *symbols;
|
|
|
|
GSList *subcategories;
|
2010-09-30 05:19:31 +02:00
|
|
|
};
|
|
|
|
|
2010-10-24 12:43:16 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2012-08-30 07:39:40 +02:00
|
|
|
PROP_PARENT,
|
2010-10-24 12:43:16 +02:00
|
|
|
PROP_NAME,
|
2012-08-29 15:46:20 +02:00
|
|
|
PROP_HUMAN_NAME
|
2010-10-24 12:43:16 +02:00
|
|
|
};
|
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
static void ld_category_get_property (GObject *object, guint property_id,
|
2010-10-24 12:43:16 +02:00
|
|
|
GValue *value, GParamSpec *pspec);
|
2012-08-29 18:44:47 +02:00
|
|
|
static void ld_category_set_property (GObject *object, guint property_id,
|
2010-10-24 12:43:16 +02:00
|
|
|
const GValue *value, GParamSpec *pspec);
|
2012-08-29 18:44:47 +02:00
|
|
|
static void ld_category_finalize (GObject *gobject);
|
2010-09-20 18:18:30 +02:00
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
static void on_category_notify_name (LdCategory *category,
|
2012-08-12 01:27:21 +02:00
|
|
|
GParamSpec *pspec, gpointer user_data);
|
|
|
|
|
2010-09-20 18:18:30 +02:00
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
G_DEFINE_TYPE (LdCategory, ld_category, G_TYPE_OBJECT);
|
2011-01-04 14:52:57 +01:00
|
|
|
|
2010-09-20 18:18:30 +02:00
|
|
|
static void
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_class_init (LdCategoryClass *klass)
|
2010-09-20 18:18:30 +02:00
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
2010-10-24 12:43:16 +02:00
|
|
|
GParamSpec *pspec;
|
2010-09-20 18:18:30 +02:00
|
|
|
|
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
2012-08-29 18:44:47 +02:00
|
|
|
object_class->get_property = ld_category_get_property;
|
|
|
|
object_class->set_property = ld_category_set_property;
|
|
|
|
object_class->finalize = ld_category_finalize;
|
2010-09-30 05:19:31 +02:00
|
|
|
|
2012-08-30 07:39:40 +02:00
|
|
|
/**
|
|
|
|
* LdCategory:parent:
|
|
|
|
*
|
|
|
|
* The parent of this symbol category.
|
|
|
|
*/
|
|
|
|
pspec = g_param_spec_string ("parent", "Parent",
|
|
|
|
"The parent of this symbol category.",
|
|
|
|
"", G_PARAM_READWRITE);
|
|
|
|
g_object_class_install_property (object_class, PROP_PARENT, pspec);
|
|
|
|
|
2010-10-24 12:43:16 +02:00
|
|
|
/**
|
2012-08-29 18:44:47 +02:00
|
|
|
* LdCategory:name:
|
2010-10-24 12:43:16 +02:00
|
|
|
*
|
|
|
|
* The name of this symbol category.
|
|
|
|
*/
|
|
|
|
pspec = g_param_spec_string ("name", "Name",
|
|
|
|
"The name of this symbol category.",
|
|
|
|
"", G_PARAM_READWRITE);
|
|
|
|
g_object_class_install_property (object_class, PROP_NAME, pspec);
|
|
|
|
|
2010-12-11 01:40:05 +01:00
|
|
|
/**
|
2012-08-29 18:44:47 +02:00
|
|
|
* LdCategory:human-name:
|
2010-12-11 01:40:05 +01:00
|
|
|
*
|
|
|
|
* The localized human name of this symbol category.
|
|
|
|
*/
|
|
|
|
pspec = g_param_spec_string ("human-name", "Human name",
|
|
|
|
"The localized human name of this symbol category.",
|
|
|
|
"", G_PARAM_READWRITE);
|
2010-12-12 19:03:36 +01:00
|
|
|
g_object_class_install_property (object_class, PROP_HUMAN_NAME, pspec);
|
2010-12-11 01:40:05 +01:00
|
|
|
|
2012-08-29 21:56:59 +02:00
|
|
|
/**
|
|
|
|
* LdCategory::symbols-changed:
|
|
|
|
*
|
|
|
|
* The list of symbols has changed.
|
|
|
|
*/
|
|
|
|
klass->symbols_changed_signal = g_signal_new
|
|
|
|
("symbols-changed", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* LdCategory::children-changed:
|
|
|
|
*
|
|
|
|
* The list of subcategory children has changed.
|
|
|
|
*/
|
|
|
|
klass->children_changed_signal = g_signal_new
|
|
|
|
("children-changed", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
g_type_class_add_private (klass, sizeof (LdCategoryPrivate));
|
2010-09-20 18:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_init (LdCategory *self)
|
2010-09-20 18:18:30 +02:00
|
|
|
{
|
2010-09-30 05:19:31 +02:00
|
|
|
self->priv = G_TYPE_INSTANCE_GET_PRIVATE
|
2012-08-29 18:44:47 +02:00
|
|
|
(self, LD_TYPE_CATEGORY, LdCategoryPrivate);
|
2010-09-20 18:18:30 +02:00
|
|
|
}
|
|
|
|
|
2010-10-24 12:43:16 +02:00
|
|
|
static void
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_get_property (GObject *object, guint property_id,
|
2010-10-24 12:43:16 +02:00
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
2012-08-29 18:44:47 +02:00
|
|
|
LdCategory *self;
|
2010-10-24 12:43:16 +02:00
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
self = LD_CATEGORY (object);
|
2010-10-24 12:43:16 +02:00
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
2012-08-29 18:44:47 +02:00
|
|
|
g_value_set_string (value, ld_category_get_name (self));
|
2010-10-24 12:43:16 +02:00
|
|
|
break;
|
2010-12-11 01:40:05 +01:00
|
|
|
case PROP_HUMAN_NAME:
|
2012-08-29 18:44:47 +02:00
|
|
|
g_value_set_string (value, ld_category_get_human_name (self));
|
2010-12-11 01:40:05 +01:00
|
|
|
break;
|
2012-08-30 07:39:40 +02:00
|
|
|
case PROP_PARENT:
|
|
|
|
g_value_set_object (value, ld_category_get_parent (self));
|
|
|
|
break;
|
2010-10-24 12:43:16 +02:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_set_property (GObject *object, guint property_id,
|
2010-10-24 12:43:16 +02:00
|
|
|
const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
2012-08-29 18:44:47 +02:00
|
|
|
LdCategory *self;
|
2010-10-24 12:43:16 +02:00
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
self = LD_CATEGORY (object);
|
2010-10-24 12:43:16 +02:00
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_set_name (self, g_value_get_string (value));
|
2010-10-24 12:43:16 +02:00
|
|
|
break;
|
2010-12-11 01:40:05 +01:00
|
|
|
case PROP_HUMAN_NAME:
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_set_human_name (self, g_value_get_string (value));
|
2010-12-11 01:40:05 +01:00
|
|
|
break;
|
2012-08-30 07:39:40 +02:00
|
|
|
case PROP_PARENT:
|
|
|
|
ld_category_set_parent (self, g_value_get_object (value));
|
|
|
|
break;
|
2010-10-24 12:43:16 +02:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-12 01:27:21 +02:00
|
|
|
static void
|
2012-08-29 18:44:47 +02:00
|
|
|
uninstall_category_cb (LdCategory *category, LdCategory *self)
|
2012-08-12 01:27:21 +02:00
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (category,
|
|
|
|
on_category_notify_name, self);
|
2012-08-30 07:39:40 +02:00
|
|
|
if (ld_category_get_parent (category) == self)
|
|
|
|
ld_category_set_parent (category, NULL);
|
2012-08-12 01:27:21 +02:00
|
|
|
g_object_unref (category);
|
|
|
|
}
|
|
|
|
|
2012-08-30 07:39:40 +02:00
|
|
|
static void
|
|
|
|
parent_weak_notify (gpointer data, GObject *object)
|
|
|
|
{
|
|
|
|
LdCategory *self;
|
|
|
|
|
|
|
|
/* In practice this should never happen, for it would mean that
|
|
|
|
* we have a parent that have us as its child.
|
|
|
|
*/
|
|
|
|
self = (LdCategory *) data;
|
|
|
|
if (self->priv->parent)
|
|
|
|
{
|
|
|
|
self->priv->parent = NULL;
|
|
|
|
g_object_notify (G_OBJECT (self), "parent");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-20 18:18:30 +02:00
|
|
|
static void
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_finalize (GObject *gobject)
|
2010-09-20 18:18:30 +02:00
|
|
|
{
|
2012-08-29 18:44:47 +02:00
|
|
|
LdCategory *self;
|
2010-09-20 18:18:30 +02:00
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
self = LD_CATEGORY (gobject);
|
2010-09-20 18:18:30 +02:00
|
|
|
|
2012-08-30 07:39:40 +02:00
|
|
|
if (self->priv->parent)
|
|
|
|
g_object_weak_unref
|
|
|
|
(G_OBJECT (self->priv->parent), parent_weak_notify, self);
|
|
|
|
|
2010-09-30 05:19:31 +02:00
|
|
|
if (self->priv->name)
|
|
|
|
g_free (self->priv->name);
|
2010-12-11 01:40:05 +01:00
|
|
|
if (self->priv->human_name)
|
|
|
|
g_free (self->priv->human_name);
|
2010-09-20 18:18:30 +02:00
|
|
|
|
2012-08-11 07:37:40 +02:00
|
|
|
g_slist_foreach (self->priv->symbols, (GFunc) g_object_unref, NULL);
|
|
|
|
g_slist_free (self->priv->symbols);
|
|
|
|
|
2012-08-12 01:27:21 +02:00
|
|
|
g_slist_foreach (self->priv->subcategories,
|
|
|
|
(GFunc) uninstall_category_cb, self);
|
2012-08-11 07:37:40 +02:00
|
|
|
g_slist_free (self->priv->subcategories);
|
2010-10-24 12:43:16 +02:00
|
|
|
|
2010-09-20 18:18:30 +02:00
|
|
|
/* Chain up to the parent class. */
|
2012-08-29 18:44:47 +02:00
|
|
|
G_OBJECT_CLASS (ld_category_parent_class)->finalize (gobject);
|
2010-09-20 18:18:30 +02:00
|
|
|
}
|
|
|
|
|
2010-12-16 05:18:41 +01:00
|
|
|
|
2010-09-20 18:18:30 +02:00
|
|
|
/**
|
2012-08-29 18:44:47 +02:00
|
|
|
* ld_category_new:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @name: the name of the new category.
|
|
|
|
* @human_name: the localized human name of the new category.
|
2010-09-20 18:18:30 +02:00
|
|
|
*
|
|
|
|
* Create an instance.
|
|
|
|
*/
|
2012-08-29 18:44:47 +02:00
|
|
|
LdCategory *
|
|
|
|
ld_category_new (const gchar *name, const gchar *human_name)
|
2010-09-20 18:18:30 +02:00
|
|
|
{
|
2012-08-29 18:44:47 +02:00
|
|
|
LdCategory *cat;
|
2010-09-20 18:18:30 +02:00
|
|
|
|
2010-12-11 01:40:05 +01:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
g_return_val_if_fail (human_name != NULL, NULL);
|
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
cat = g_object_new (LD_TYPE_CATEGORY, NULL);
|
2010-09-30 05:19:31 +02:00
|
|
|
cat->priv->name = g_strdup (name);
|
2010-12-11 01:40:05 +01:00
|
|
|
cat->priv->human_name = g_strdup (human_name);
|
2010-09-20 18:18:30 +02:00
|
|
|
|
|
|
|
return cat;
|
|
|
|
}
|
|
|
|
|
2010-09-30 05:19:31 +02:00
|
|
|
/**
|
2012-08-29 18:44:47 +02:00
|
|
|
* ld_category_set_name:
|
|
|
|
* @self: an #LdCategory object.
|
2011-01-28 17:39:40 +01:00
|
|
|
* @name: the new name for this category.
|
2010-09-30 05:19:31 +02:00
|
|
|
*/
|
|
|
|
void
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_set_name (LdCategory *self, const gchar *name)
|
2010-09-30 05:19:31 +02:00
|
|
|
{
|
2012-08-29 18:44:47 +02:00
|
|
|
g_return_if_fail (LD_IS_CATEGORY (self));
|
2010-09-30 05:19:31 +02:00
|
|
|
g_return_if_fail (name != NULL);
|
|
|
|
|
|
|
|
if (self->priv->name)
|
|
|
|
g_free (self->priv->name);
|
|
|
|
self->priv->name = g_strdup (name);
|
2010-12-12 19:03:36 +01:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "name");
|
2010-09-30 05:19:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-08-29 18:44:47 +02:00
|
|
|
* ld_category_get_name:
|
|
|
|
* @self: an #LdCategory object.
|
2010-09-30 05:19:31 +02:00
|
|
|
*
|
|
|
|
* Return the name of this category.
|
|
|
|
*/
|
|
|
|
const gchar *
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_get_name (LdCategory *self)
|
2010-09-30 05:19:31 +02:00
|
|
|
{
|
2012-08-29 18:44:47 +02:00
|
|
|
g_return_val_if_fail (LD_IS_CATEGORY (self), NULL);
|
2010-09-30 05:19:31 +02:00
|
|
|
return self->priv->name;
|
|
|
|
}
|
|
|
|
|
2010-12-11 01:40:05 +01:00
|
|
|
/**
|
2012-08-29 18:44:47 +02:00
|
|
|
* ld_category_set_human_name:
|
|
|
|
* @self: an #LdCategory object.
|
2011-01-28 17:39:40 +01:00
|
|
|
* @human_name: the new localized human name for this category.
|
2010-12-11 01:40:05 +01:00
|
|
|
*/
|
|
|
|
void
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_set_human_name (LdCategory *self, const gchar *human_name)
|
2010-12-11 01:40:05 +01:00
|
|
|
{
|
2012-08-29 18:44:47 +02:00
|
|
|
g_return_if_fail (LD_IS_CATEGORY (self));
|
2010-12-11 01:40:05 +01:00
|
|
|
g_return_if_fail (human_name != NULL);
|
|
|
|
|
|
|
|
if (self->priv->human_name)
|
|
|
|
g_free (self->priv->human_name);
|
|
|
|
self->priv->human_name = g_strdup (human_name);
|
2010-12-12 19:03:36 +01:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "human-name");
|
2010-12-11 01:40:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-08-29 18:44:47 +02:00
|
|
|
* ld_category_get_human_name:
|
|
|
|
* @self: an #LdCategory object.
|
2010-12-11 01:40:05 +01:00
|
|
|
*
|
|
|
|
* Return the localized human name of this category.
|
|
|
|
*/
|
|
|
|
const gchar *
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_get_human_name (LdCategory *self)
|
2010-12-11 01:40:05 +01:00
|
|
|
{
|
2012-08-29 18:44:47 +02:00
|
|
|
g_return_val_if_fail (LD_IS_CATEGORY (self), NULL);
|
2010-12-11 01:40:05 +01:00
|
|
|
return self->priv->human_name;
|
|
|
|
}
|
|
|
|
|
2010-10-24 12:43:16 +02:00
|
|
|
/**
|
2012-08-29 18:44:47 +02:00
|
|
|
* ld_category_insert_symbol:
|
|
|
|
* @self: an #LdCategory object.
|
2012-08-11 07:37:40 +02:00
|
|
|
* @symbol: the symbol to be inserted.
|
|
|
|
* @pos: the position at which the symbol will be inserted.
|
|
|
|
* Negative values will append to the end of list.
|
|
|
|
*
|
2012-08-12 01:27:21 +02:00
|
|
|
* Insert a symbol into the category.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if successful (no name collisions).
|
2012-08-11 07:37:40 +02:00
|
|
|
*/
|
2012-08-12 01:27:21 +02:00
|
|
|
gboolean
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_insert_symbol (LdCategory *self, LdSymbol *symbol, gint pos)
|
2012-08-11 07:37:40 +02:00
|
|
|
{
|
2012-08-12 01:27:21 +02:00
|
|
|
const gchar *name;
|
|
|
|
const GSList *iter;
|
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
g_return_val_if_fail (LD_IS_CATEGORY (self), FALSE);
|
2012-08-12 01:27:21 +02:00
|
|
|
g_return_val_if_fail (LD_IS_SYMBOL (symbol), FALSE);
|
|
|
|
|
|
|
|
/* Check for name collisions. */
|
|
|
|
name = ld_symbol_get_name (symbol);
|
|
|
|
for (iter = self->priv->symbols; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
if (!strcmp (name, ld_symbol_get_name (iter->data)))
|
|
|
|
{
|
|
|
|
g_warning ("attempted to insert multiple `%s' symbols into"
|
2012-08-29 18:44:47 +02:00
|
|
|
" category `%s'", name, ld_category_get_name (self));
|
2012-08-12 01:27:21 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2012-08-11 07:37:40 +02:00
|
|
|
|
|
|
|
self->priv->symbols = g_slist_insert (self->priv->symbols, symbol, pos);
|
2012-08-12 01:27:21 +02:00
|
|
|
g_object_ref (symbol);
|
2012-08-29 21:56:59 +02:00
|
|
|
|
|
|
|
g_signal_emit (self,
|
|
|
|
LD_CATEGORY_GET_CLASS (self)->symbols_changed_signal, 0);
|
2012-08-12 01:27:21 +02:00
|
|
|
return TRUE;
|
2012-08-11 07:37:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-08-29 18:44:47 +02:00
|
|
|
* ld_category_remove_symbol:
|
|
|
|
* @self: an #LdCategory object.
|
2012-08-11 07:37:40 +02:00
|
|
|
* @symbol: the symbol to be removed.
|
|
|
|
*
|
|
|
|
* Removes a symbol from the category.
|
|
|
|
*/
|
|
|
|
void
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_remove_symbol (LdCategory *self, LdSymbol *symbol)
|
2012-08-11 07:37:40 +02:00
|
|
|
{
|
2012-08-29 20:57:31 +02:00
|
|
|
GSList *link;
|
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
g_return_if_fail (LD_IS_CATEGORY (self));
|
2012-08-11 07:37:40 +02:00
|
|
|
g_return_if_fail (LD_IS_SYMBOL (symbol));
|
|
|
|
|
2012-08-29 20:57:31 +02:00
|
|
|
if ((link = g_slist_find (self->priv->symbols, symbol)))
|
2012-08-11 21:00:38 +02:00
|
|
|
{
|
2012-08-29 20:57:31 +02:00
|
|
|
self->priv->symbols = g_slist_delete_link (self->priv->symbols, link);
|
2012-08-11 21:00:38 +02:00
|
|
|
g_object_unref (symbol);
|
2012-08-29 21:56:59 +02:00
|
|
|
|
|
|
|
g_signal_emit (self,
|
|
|
|
LD_CATEGORY_GET_CLASS (self)->symbols_changed_signal, 0);
|
2012-08-11 21:00:38 +02:00
|
|
|
}
|
2012-08-11 07:37:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-08-29 18:44:47 +02:00
|
|
|
* ld_category_get_symbols:
|
|
|
|
* @self: an #LdCategory object.
|
2012-08-11 07:37:40 +02:00
|
|
|
*
|
|
|
|
* Return value: (element-type LdSymbol *): a list of symbols. Do not modify.
|
|
|
|
*/
|
|
|
|
const GSList *
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_get_symbols (LdCategory *self)
|
2012-08-11 07:37:40 +02:00
|
|
|
{
|
2012-08-29 18:44:47 +02:00
|
|
|
g_return_val_if_fail (LD_IS_CATEGORY (self), NULL);
|
2012-08-11 07:37:40 +02:00
|
|
|
return self->priv->symbols;
|
|
|
|
}
|
|
|
|
|
2012-08-30 07:39:40 +02:00
|
|
|
/**
|
|
|
|
* ld_category_set_parent:
|
|
|
|
* @self: an #LdCategory object.
|
|
|
|
* @parent: the new parent category.
|
|
|
|
*
|
|
|
|
* Set the parent of this category.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ld_category_set_parent (LdCategory *self, LdCategory *parent)
|
|
|
|
{
|
|
|
|
g_return_if_fail (LD_IS_CATEGORY (self));
|
|
|
|
g_return_if_fail (parent == NULL || LD_IS_CATEGORY (parent));
|
|
|
|
|
|
|
|
if (self->priv->parent)
|
|
|
|
g_object_weak_unref
|
|
|
|
(G_OBJECT (self->priv->parent), parent_weak_notify, self);
|
|
|
|
|
|
|
|
self->priv->parent = parent;
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
g_object_weak_ref (G_OBJECT (parent), parent_weak_notify, self);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "parent");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ld_category_get_parent:
|
|
|
|
* @self: an #LdCategory object.
|
|
|
|
*
|
|
|
|
* Return value: the parent of this category.
|
|
|
|
*/
|
|
|
|
LdCategory *
|
|
|
|
ld_category_get_parent (LdCategory *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (LD_IS_CATEGORY (self), NULL);
|
|
|
|
return self->priv->parent;
|
|
|
|
}
|
2012-08-11 07:37:40 +02:00
|
|
|
|
2012-09-09 16:39:36 +02:00
|
|
|
/**
|
|
|
|
* ld_category_get_path:
|
|
|
|
* @self: an #LdCategory object.
|
|
|
|
*
|
|
|
|
* Return value: the path to this category within the library.
|
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
ld_category_get_path (LdCategory *self)
|
|
|
|
{
|
|
|
|
LdCategory *iter;
|
|
|
|
gchar *path = NULL, *new_path;
|
|
|
|
|
|
|
|
g_return_val_if_fail (LD_IS_CATEGORY (self), NULL);
|
|
|
|
|
|
|
|
for (iter = self; iter; iter = ld_category_get_parent (iter))
|
|
|
|
{
|
|
|
|
const gchar *name;
|
|
|
|
|
|
|
|
/* Stop at the root category. */
|
|
|
|
name = ld_category_get_name (iter);
|
|
|
|
if (!strcmp (name, LD_LIBRARY_IDENTIFIER_SEPARATOR))
|
|
|
|
break;
|
|
|
|
|
|
|
|
new_path = g_build_path
|
|
|
|
(LD_LIBRARY_IDENTIFIER_SEPARATOR, name, path, NULL);
|
|
|
|
g_free (path);
|
|
|
|
path = new_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2012-08-12 01:27:21 +02:00
|
|
|
static void
|
2012-08-29 18:44:47 +02:00
|
|
|
on_category_notify_name (LdCategory *category,
|
2012-08-12 01:27:21 +02:00
|
|
|
GParamSpec *pspec, gpointer user_data)
|
|
|
|
{
|
2012-08-29 18:44:47 +02:00
|
|
|
LdCategory *self;
|
2012-08-29 18:27:41 +02:00
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
self = (LdCategory *) user_data;
|
2012-08-12 01:27:21 +02:00
|
|
|
g_warning ("name of a library subcategory has changed");
|
2012-08-29 18:27:41 +02:00
|
|
|
|
|
|
|
/* The easy way of handling it. */
|
|
|
|
g_object_ref (category);
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_remove_child (self, category);
|
|
|
|
ld_category_add_child (self, category);
|
2012-08-29 18:27:41 +02:00
|
|
|
g_object_unref (category);
|
2012-08-12 01:27:21 +02:00
|
|
|
}
|
|
|
|
|
2012-08-11 07:37:40 +02:00
|
|
|
/**
|
2012-08-29 18:44:47 +02:00
|
|
|
* ld_category_add_child:
|
|
|
|
* @self: an #LdCategory object.
|
2012-08-11 07:37:40 +02:00
|
|
|
* @category: the category to be inserted.
|
2010-10-24 12:43:16 +02:00
|
|
|
*
|
2012-08-12 01:27:21 +02:00
|
|
|
* Insert a subcategory into the category.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if successful (no name collisions).
|
2010-10-24 12:43:16 +02:00
|
|
|
*/
|
2012-08-12 01:27:21 +02:00
|
|
|
gboolean
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_add_child (LdCategory *self, LdCategory *category)
|
2010-10-24 12:43:16 +02:00
|
|
|
{
|
2012-08-12 01:27:21 +02:00
|
|
|
const gchar *name;
|
2012-08-29 18:27:41 +02:00
|
|
|
GSList *iter;
|
2010-10-24 12:43:16 +02:00
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
g_return_val_if_fail (LD_IS_CATEGORY (self), FALSE);
|
|
|
|
g_return_val_if_fail (LD_IS_CATEGORY (category), FALSE);
|
2012-08-12 01:27:21 +02:00
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
name = ld_category_get_name (category);
|
2012-08-12 01:27:21 +02:00
|
|
|
for (iter = self->priv->subcategories; iter; iter = iter->next)
|
|
|
|
{
|
2012-08-29 18:27:41 +02:00
|
|
|
gint comp;
|
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
comp = g_utf8_collate (name, ld_category_get_name (iter->data));
|
2012-08-29 18:27:41 +02:00
|
|
|
if (!comp)
|
2012-08-12 01:27:21 +02:00
|
|
|
{
|
|
|
|
g_warning ("attempted to insert multiple `%s' subcategories into"
|
2012-08-29 18:44:47 +02:00
|
|
|
" category `%s'", name, ld_category_get_name (self));
|
2012-08-12 01:27:21 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-08-29 18:27:41 +02:00
|
|
|
if (comp < 0)
|
|
|
|
break;
|
2012-08-12 01:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect (category, "notify::name",
|
|
|
|
G_CALLBACK (on_category_notify_name), self);
|
2012-08-29 18:27:41 +02:00
|
|
|
self->priv->subcategories = g_slist_insert_before
|
|
|
|
(self->priv->subcategories, iter, category);
|
2012-08-30 07:39:40 +02:00
|
|
|
ld_category_set_parent (category, self);
|
2012-08-12 01:27:21 +02:00
|
|
|
g_object_ref (category);
|
2012-08-29 21:56:59 +02:00
|
|
|
|
|
|
|
g_signal_emit (self,
|
|
|
|
LD_CATEGORY_GET_CLASS (self)->children_changed_signal, 0);
|
2012-08-12 01:27:21 +02:00
|
|
|
return TRUE;
|
2010-10-24 12:43:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-08-29 18:44:47 +02:00
|
|
|
* ld_category_remove_child:
|
|
|
|
* @self: an #LdCategory object.
|
2012-08-11 07:37:40 +02:00
|
|
|
* @category: the category to be removed.
|
2010-10-24 12:43:16 +02:00
|
|
|
*
|
2012-08-11 07:37:40 +02:00
|
|
|
* Removes a subcategory from the category.
|
2010-10-24 12:43:16 +02:00
|
|
|
*/
|
|
|
|
void
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_remove_child (LdCategory *self, LdCategory *category)
|
2010-10-24 12:43:16 +02:00
|
|
|
{
|
2012-08-29 20:57:31 +02:00
|
|
|
GSList *link;
|
|
|
|
|
2012-08-29 18:44:47 +02:00
|
|
|
g_return_if_fail (LD_IS_CATEGORY (self));
|
|
|
|
g_return_if_fail (LD_IS_CATEGORY (category));
|
2010-10-24 12:43:16 +02:00
|
|
|
|
2012-08-29 20:57:31 +02:00
|
|
|
if ((link = g_slist_find (self->priv->subcategories, category)))
|
2012-08-11 21:00:38 +02:00
|
|
|
{
|
|
|
|
self->priv->subcategories
|
2012-08-29 20:57:31 +02:00
|
|
|
= g_slist_delete_link (self->priv->subcategories, link);
|
2012-08-30 07:39:40 +02:00
|
|
|
uninstall_category_cb (category, self);
|
2012-08-29 21:56:59 +02:00
|
|
|
|
|
|
|
g_signal_emit (self,
|
|
|
|
LD_CATEGORY_GET_CLASS (self)->children_changed_signal, 0);
|
2012-08-11 21:00:38 +02:00
|
|
|
}
|
2010-10-24 12:43:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-08-29 18:44:47 +02:00
|
|
|
* ld_category_get_children:
|
|
|
|
* @self: an #LdCategory object.
|
2010-10-24 12:43:16 +02:00
|
|
|
*
|
2012-08-29 18:44:47 +02:00
|
|
|
* Return value: (element-type LdCategory *):
|
2012-08-11 07:37:40 +02:00
|
|
|
* a list of subcategories. Do not modify.
|
2010-10-24 12:43:16 +02:00
|
|
|
*/
|
|
|
|
const GSList *
|
2012-08-29 18:44:47 +02:00
|
|
|
ld_category_get_children (LdCategory *self)
|
2010-10-24 12:43:16 +02:00
|
|
|
{
|
2012-08-29 18:44:47 +02:00
|
|
|
g_return_val_if_fail (LD_IS_CATEGORY (self), NULL);
|
2012-08-11 07:37:40 +02:00
|
|
|
return self->priv->subcategories;
|
2010-10-24 12:43:16 +02:00
|
|
|
}
|
|
|
|
|