2010-09-20 18:18:30 +02:00
|
|
|
/*
|
|
|
|
* ld-symbol-category.c
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:ld-symbol-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
|
|
|
*
|
|
|
|
* #LdSymbolCategory represents a category of #LdSymbol objects.
|
|
|
|
*/
|
|
|
|
|
2010-09-30 05:19:31 +02:00
|
|
|
/*
|
|
|
|
* LdSymbolCategoryPrivate:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @name: the name of this category.
|
|
|
|
* @image_path: path to the image for this category.
|
|
|
|
* @children: children of this category.
|
2010-09-30 05:19:31 +02:00
|
|
|
*/
|
|
|
|
struct _LdSymbolCategoryPrivate
|
|
|
|
{
|
|
|
|
gchar *name;
|
2010-12-11 01:40:05 +01:00
|
|
|
gchar *human_name;
|
2010-09-30 05:19:31 +02:00
|
|
|
gchar *image_path;
|
|
|
|
GSList *children;
|
|
|
|
};
|
|
|
|
|
2010-10-24 12:43:16 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_NAME,
|
2010-12-11 01:40:05 +01:00
|
|
|
PROP_HUMAN_NAME,
|
2010-10-24 12:43:16 +02:00
|
|
|
PROP_IMAGE_PATH
|
|
|
|
};
|
|
|
|
|
2010-12-16 05:18:41 +01:00
|
|
|
static void ld_symbol_category_get_property (GObject *object, guint property_id,
|
2010-10-24 12:43:16 +02:00
|
|
|
GValue *value, GParamSpec *pspec);
|
2010-12-16 05:18:41 +01:00
|
|
|
static void ld_symbol_category_set_property (GObject *object, guint property_id,
|
2010-10-24 12:43:16 +02:00
|
|
|
const GValue *value, GParamSpec *pspec);
|
2010-12-16 05:18:41 +01:00
|
|
|
static void ld_symbol_category_finalize (GObject *gobject);
|
2010-09-20 18:18:30 +02:00
|
|
|
|
|
|
|
|
2011-01-04 14:52:57 +01:00
|
|
|
G_DEFINE_TYPE (LdSymbolCategory, ld_symbol_category, G_TYPE_OBJECT);
|
|
|
|
|
2010-09-20 18:18:30 +02:00
|
|
|
static void
|
|
|
|
ld_symbol_category_class_init (LdSymbolCategoryClass *klass)
|
|
|
|
{
|
|
|
|
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);
|
2010-10-24 12:43:16 +02:00
|
|
|
object_class->get_property = ld_symbol_category_get_property;
|
|
|
|
object_class->set_property = ld_symbol_category_set_property;
|
2010-09-20 18:18:30 +02:00
|
|
|
object_class->finalize = ld_symbol_category_finalize;
|
2010-09-30 05:19:31 +02:00
|
|
|
|
2010-10-24 12:43:16 +02:00
|
|
|
/**
|
|
|
|
* LdSymbolCategory:name:
|
|
|
|
*
|
|
|
|
* 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
|
|
|
/**
|
|
|
|
* LdSymbolCategory:human-name:
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2010-10-24 12:43:16 +02:00
|
|
|
/**
|
|
|
|
* LdSymbolCategory:image-path:
|
|
|
|
*
|
|
|
|
* Path to an image file representing this category.
|
|
|
|
*/
|
|
|
|
pspec = g_param_spec_string ("image-path", "Image path",
|
|
|
|
"Path to an image file representing this category.",
|
|
|
|
"", G_PARAM_READWRITE);
|
|
|
|
g_object_class_install_property (object_class, PROP_IMAGE_PATH, pspec);
|
|
|
|
|
2010-09-30 05:19:31 +02:00
|
|
|
g_type_class_add_private (klass, sizeof (LdSymbolCategoryPrivate));
|
2010-09-20 18:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ld_symbol_category_init (LdSymbolCategory *self)
|
|
|
|
{
|
2010-09-30 05:19:31 +02:00
|
|
|
self->priv = G_TYPE_INSTANCE_GET_PRIVATE
|
|
|
|
(self, LD_TYPE_SYMBOL_CATEGORY, LdSymbolCategoryPrivate);
|
2010-09-20 18:18:30 +02:00
|
|
|
}
|
|
|
|
|
2010-10-24 12:43:16 +02:00
|
|
|
static void
|
|
|
|
ld_symbol_category_get_property (GObject *object, guint property_id,
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
LdSymbolCategory *self;
|
|
|
|
|
|
|
|
self = LD_SYMBOL_CATEGORY (object);
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
|
|
|
g_value_set_string (value, ld_symbol_category_get_name (self));
|
|
|
|
break;
|
2010-12-11 01:40:05 +01:00
|
|
|
case PROP_HUMAN_NAME:
|
|
|
|
g_value_set_string (value, ld_symbol_category_get_human_name (self));
|
|
|
|
break;
|
2010-10-24 12:43:16 +02:00
|
|
|
case PROP_IMAGE_PATH:
|
|
|
|
g_value_set_string (value, ld_symbol_category_get_image_path (self));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ld_symbol_category_set_property (GObject *object, guint property_id,
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
LdSymbolCategory *self;
|
|
|
|
|
|
|
|
self = LD_SYMBOL_CATEGORY (object);
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
|
|
|
ld_symbol_category_set_name (self, g_value_get_string (value));
|
|
|
|
break;
|
2010-12-11 01:40:05 +01:00
|
|
|
case PROP_HUMAN_NAME:
|
|
|
|
ld_symbol_category_set_human_name (self, g_value_get_string (value));
|
|
|
|
break;
|
2010-10-24 12:43:16 +02:00
|
|
|
case PROP_IMAGE_PATH:
|
|
|
|
ld_symbol_category_set_image_path (self, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-20 18:18:30 +02:00
|
|
|
static void
|
|
|
|
ld_symbol_category_finalize (GObject *gobject)
|
|
|
|
{
|
|
|
|
LdSymbolCategory *self;
|
|
|
|
|
|
|
|
self = LD_SYMBOL_CATEGORY (gobject);
|
|
|
|
|
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-30 05:19:31 +02:00
|
|
|
if (self->priv->image_path)
|
|
|
|
g_free (self->priv->image_path);
|
2010-09-20 18:18:30 +02:00
|
|
|
|
2010-10-24 12:43:16 +02:00
|
|
|
g_slist_foreach (self->priv->children, (GFunc) g_object_unref, NULL);
|
|
|
|
g_slist_free (self->priv->children);
|
|
|
|
|
2010-09-20 18:18:30 +02:00
|
|
|
/* Chain up to the parent class. */
|
|
|
|
G_OBJECT_CLASS (ld_symbol_category_parent_class)->finalize (gobject);
|
|
|
|
}
|
|
|
|
|
2010-12-16 05:18:41 +01:00
|
|
|
|
2010-09-20 18:18:30 +02:00
|
|
|
/**
|
|
|
|
* ld_symbol_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.
|
|
|
|
*/
|
|
|
|
LdSymbolCategory *
|
2010-12-11 01:40:05 +01:00
|
|
|
ld_symbol_category_new (const gchar *name, const gchar *human_name)
|
2010-09-20 18:18:30 +02:00
|
|
|
{
|
|
|
|
LdSymbolCategory *cat;
|
|
|
|
|
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);
|
|
|
|
|
2010-09-20 18:18:30 +02:00
|
|
|
cat = g_object_new (LD_TYPE_SYMBOL_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
|
|
|
/**
|
|
|
|
* ld_symbol_category_set_name:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @self: an #LdSymbolCategory object.
|
|
|
|
* @name: the new name for this category.
|
2010-09-30 05:19:31 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
ld_symbol_category_set_name (LdSymbolCategory *self, const gchar *name)
|
|
|
|
{
|
|
|
|
g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ld_symbol_category_get_name:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @self: an #LdSymbolCategory object.
|
2010-09-30 05:19:31 +02:00
|
|
|
*
|
|
|
|
* Return the name of this category.
|
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
ld_symbol_category_get_name (LdSymbolCategory *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (self), NULL);
|
|
|
|
return self->priv->name;
|
|
|
|
}
|
|
|
|
|
2010-12-11 01:40:05 +01:00
|
|
|
/**
|
|
|
|
* ld_symbol_category_set_human_name:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @self: an #LdSymbolCategory object.
|
|
|
|
* @human_name: the new localized human name for this category.
|
2010-12-11 01:40:05 +01:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
ld_symbol_category_set_human_name (LdSymbolCategory *self,
|
|
|
|
const gchar *human_name)
|
|
|
|
{
|
|
|
|
g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ld_symbol_category_get_human_name:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @self: an #LdSymbolCategory object.
|
2010-12-11 01:40:05 +01:00
|
|
|
*
|
|
|
|
* Return the localized human name of this category.
|
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
ld_symbol_category_get_human_name (LdSymbolCategory *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (self), NULL);
|
|
|
|
return self->priv->human_name;
|
|
|
|
}
|
|
|
|
|
2010-09-30 05:19:31 +02:00
|
|
|
/**
|
|
|
|
* ld_symbol_category_set_image_path:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @self: an #LdSymbolCategory object.
|
|
|
|
* @image_path: (allow-none): The new path to the image for this category.
|
2010-09-30 05:19:31 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
ld_symbol_category_set_image_path (LdSymbolCategory *self,
|
|
|
|
const gchar *image_path)
|
|
|
|
{
|
|
|
|
g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self));
|
|
|
|
|
|
|
|
if (self->priv->image_path)
|
|
|
|
g_free (self->priv->image_path);
|
|
|
|
self->priv->image_path = g_strdup (image_path);
|
2010-12-12 19:03:36 +01:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "image-path");
|
2010-09-30 05:19:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ld_symbol_category_get_image_path:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @self: an #LdSymbolCategory object.
|
2010-09-30 05:19:31 +02:00
|
|
|
*
|
2011-01-28 17:39:40 +01:00
|
|
|
* Return value: (allow-none): filesystem path to the image for this category.
|
2010-09-30 05:19:31 +02:00
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
ld_symbol_category_get_image_path (LdSymbolCategory *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (self), NULL);
|
|
|
|
return self->priv->image_path;
|
|
|
|
}
|
|
|
|
|
2010-10-24 12:43:16 +02:00
|
|
|
/**
|
|
|
|
* ld_symbol_category_insert_child:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @self: an #LdSymbolCategory object.
|
|
|
|
* @child: the child to be inserted.
|
|
|
|
* @pos: the position at which the child will be inserted.
|
2010-10-24 12:43:16 +02:00
|
|
|
* Negative values will append to the end of list.
|
|
|
|
*
|
|
|
|
* Insert a child into the category.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ld_symbol_category_insert_child (LdSymbolCategory *self,
|
|
|
|
GObject *child, gint pos)
|
|
|
|
{
|
|
|
|
g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self));
|
|
|
|
g_return_if_fail (G_IS_OBJECT (child));
|
|
|
|
|
|
|
|
g_object_ref (child);
|
|
|
|
self->priv->children = g_slist_insert (self->priv->children, child, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ld_symbol_category_remove_child:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @self: an #LdSymbolCategory object.
|
|
|
|
* @child: the child to be removed.
|
2010-10-24 12:43:16 +02:00
|
|
|
*
|
|
|
|
* Removes a child from the category.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ld_symbol_category_remove_child (LdSymbolCategory *self,
|
|
|
|
GObject *child)
|
|
|
|
{
|
|
|
|
g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self));
|
|
|
|
g_return_if_fail (G_IS_OBJECT (child));
|
|
|
|
|
|
|
|
g_object_unref (child);
|
|
|
|
self->priv->children = g_slist_remove (self->priv->children, child);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ld_symbol_category_get_children:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @self: an #LdSymbolCategory object.
|
2010-10-24 12:43:16 +02:00
|
|
|
*
|
2011-01-28 17:39:40 +01:00
|
|
|
* Return value: the internal list of children. Do not modify.
|
2010-10-24 12:43:16 +02:00
|
|
|
*/
|
|
|
|
const GSList *
|
|
|
|
ld_symbol_category_get_children (LdSymbolCategory *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (self), NULL);
|
|
|
|
return self->priv->children;
|
|
|
|
}
|
|
|
|
|