Mercurial > pidgin
changeset 25085:fecc8e2612c4
Fixed some things needed for proper gobfication (init/finalize/etc)
author | Justin Rodriguez <ffdragon@soc.pidgin.im> |
---|---|
date | Mon, 16 Jun 2008 19:48:56 +0000 |
parents | 623f0b40f6f6 |
children | 774ef2a2e7f8 |
files | libpurple/sound-loader.c libpurple/sound-theme.c libpurple/sound-theme.h libpurple/theme-loader.c libpurple/theme-loader.h libpurple/theme-manager.c libpurple/theme-manager.h libpurple/theme.c |
diffstat | 8 files changed, 160 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/sound-loader.c Fri Jun 13 21:33:17 2008 +0000 +++ b/libpurple/sound-loader.c Mon Jun 16 19:48:56 2008 +0000 @@ -25,6 +25,12 @@ #include "util.h" #include "xmlnode.h" +/****************************************************************************** + * Globals + *****************************************************************************/ + +static PurpleThemeLoaderClass *parent_class = NULL; + /***************************************************************************** * Sound Theme Builder *****************************************************************************/ @@ -68,7 +74,7 @@ g_return_val_if_fail(root_node != NULL, NULL); /* Parse the tree */ - theme = purple_sound_theme_new(); + theme = g_object_new(PURPLE_TYPE_SOUND_THEME, "type", "sound", NULL); purple_theme_set_name(theme->parent, xmlnode_get_attrib(root_node, THEME_NAME)); purple_theme_set_author(theme->parent, xmlnode_get_attrib(root_node, THEME_AUTHOR)); @@ -103,9 +109,10 @@ static void purple_sound_theme_loader_class_init (PurpleSoundThemeLoaderClass *klass) { - PurpleSoundThemeLoaderClass *loader_class = PURPLE_SOUND_THEME_LOADER_CLASS(klass); + parent_class = g_type_class_peek_parent (klass); - loader_class->parent_class._purple_theme_loader_build = purple_sound_loader_build; + /* TODO: fix warning */ + parent_class->purple_theme_loader_build = purple_sound_loader_build; }
--- a/libpurple/sound-theme.c Fri Jun 13 21:33:17 2008 +0000 +++ b/libpurple/sound-theme.c Mon Jun 16 19:48:56 2008 +0000 @@ -39,6 +39,8 @@ * Globals *****************************************************************************/ +static GObjectClass *parent_class = NULL; + /****************************************************************************** * Enums *****************************************************************************/ @@ -47,6 +49,21 @@ * GObject Stuff *****************************************************************************/ +static void +purple_sound_theme_init(GTypeInstance *instance, + gpointer klass) +{ + PurpleSoundThemePrivate *priv; + GObject *obj = (GObject *)instance; + + priv = PURPLE_SOUND_THEME_GET_PRIVATE(obj); + + priv->sound_files = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + g_free); +} + static void purple_sound_theme_finalize (GObject *obj) { @@ -55,6 +72,8 @@ priv = PURPLE_SOUND_THEME_GET_PRIVATE(obj); g_hash_table_destroy(priv->sound_files); + + parent_class->finalize (obj); } static void @@ -62,6 +81,8 @@ { GObjectClass *obj_class = G_OBJECT_CLASS(klass); + parent_class = g_type_class_peek_parent (klass); + obj_class->finalize = purple_sound_theme_finalize; } @@ -79,7 +100,7 @@ NULL, /* class_data */ sizeof (PurpleSoundTheme), 0, /* n_preallocs */ - NULL, /* instance_init */ + purple_sound_theme_init, /* instance_init */ NULL, /* value table */ }; type = g_type_register_static (G_TYPE_OBJECT, @@ -94,23 +115,6 @@ * Public API functions *****************************************************************************/ -PurpleSoundTheme * -purple_sound_theme_new() -{ - PurpleSoundTheme *theme; - PurpleSoundThemePrivate *priv; - - theme = g_object_new(PURPLE_TYPE_SOUND_THEME, NULL); - priv = PURPLE_SOUND_THEME_GET_PRIVATE(theme); - - priv->sound_files = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - g_free); - - return theme; -} - gchar * purple_sound_theme_get_file(PurpleSoundTheme *theme, const gchar *event)
--- a/libpurple/sound-theme.h Fri Jun 13 21:33:17 2008 +0000 +++ b/libpurple/sound-theme.h Mon Jun 16 19:48:56 2008 +0000 @@ -71,13 +71,6 @@ GType purple_sound_theme_get_type(void); /** - * Creates a new purple sound theme - * - * @returns a new purple sound theme object - */ -PurpleSoundTheme *purple_sound_theme_new(void); - -/** * Returns a copy of the filename for the sound event * * @param event the purple sound event to look up
--- a/libpurple/theme-loader.c Fri Jun 13 21:33:17 2008 +0000 +++ b/libpurple/theme-loader.c Mon Jun 16 19:48:56 2008 +0000 @@ -26,7 +26,7 @@ #define PURPLE_THEME_LOADER_GET_PRIVATE(PurpleThemeLoader) \ ((PurpleThemeLoaderPrivate *) ((PurpleThemeLoader)->priv)) - +void purple_theme_loader_set_type_string(PurpleThemeLoader *loader, const gchar *type); /****************************************************************************** * Structs *****************************************************************************/ @@ -38,6 +38,8 @@ * Globals *****************************************************************************/ +static GObjectClass *parent_class = NULL; + /****************************************************************************** * Enums *****************************************************************************/ @@ -68,16 +70,43 @@ } static void +purple_theme_loader_set_property(GObject *obj, guint param_id, const GValue *value, + GParamSpec *psec) +{ + PurpleThemeLoader *loader = PURPLE_THEME_LOADER(obj); + + switch(param_id) { + case PROP_TYPE: + purple_theme_loader_set_type_string(loader, g_value_get_string(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec); + break; + } +} + +static void +purple_theme_loader_finalize(GObject *obj) +{ + PurpleThemeLoader *loader = PURPLE_THEME_LOADER(obj); + PurpleThemeLoaderPrivate *priv = PURPLE_THEME_LOADER_GET_PRIVATE(loader); + + g_free(priv->type); + + parent_class->finalize (obj); +} + +static void purple_theme_loader_class_init (PurpleThemeLoaderClass *klass) { GObjectClass *obj_class = G_OBJECT_CLASS(klass); GParamSpec *pspec; - /* 2.4 - * g_type_class_add_private(klass, sizeof(PurpleThemePrivate)); */ - + parent_class = g_type_class_peek_parent (klass); obj_class->get_property = purple_theme_loader_get_property; + obj_class->set_property = purple_theme_loader_set_property; + obj_class->finalize = purple_theme_loader_finalize; /* TYPE STRING (read only) */ pspec = g_param_spec_string(PROP_TYPE_S, "Type", @@ -129,8 +158,23 @@ return priv->type; } +/* < private > */ +void +purple_theme_loader_set_type_string(PurpleThemeLoader *loader, const gchar *type) +{ + PurpleThemeLoaderPrivate *priv; + + g_return_if_fail(PURPLE_IS_THEME_LOADER(loader)); + + priv = PURPLE_THEME_LOADER_GET_PRIVATE(loader); + + g_free(priv->type); + priv->type = g_strdup (type); +} + PurpleTheme * purple_theme_loader_build (PurpleThemeLoader *loader, const gchar *dir) { - return PURPLE_THEME_LOADER_GET_CLASS(loader)->_purple_theme_loader_build(dir); + /* TODO: fix warning */ + return PURPLE_THEME_LOADER_GET_CLASS(loader)->purple_theme_loader_build(dir); }
--- a/libpurple/theme-loader.h Fri Jun 13 21:33:17 2008 +0000 +++ b/libpurple/theme-loader.h Mon Jun 16 19:48:56 2008 +0000 @@ -56,7 +56,7 @@ struct _PurpleThemeLoaderClass { GObjectClass parent_class; - PurpleTheme *(*_purple_theme_loader_build)(const gchar); + PurpleTheme *(*purple_theme_loader_build)(const gchar); }; /**************************************************************************/
--- a/libpurple/theme-manager.c Fri Jun 13 21:33:17 2008 +0000 +++ b/libpurple/theme-manager.c Mon Jun 16 19:48:56 2008 +0000 @@ -30,29 +30,10 @@ static GHashTable *theme_table; - /***************************************************************************** * GObject Stuff ****************************************************************************/ -static void -purple_theme_manager_finalize (GObject *obj) -{ - g_hash_table_destroy(theme_table); -} - -static void -purple_theme_manager_class_init (PurpleThemeManagerClass *klass) -{ - /*PurpleThemeManagerClass *theme_manager_class = PURPLE_THEME_MANAGER_CLASS(klass);*/ - GObjectClass *obj_class = G_OBJECT_CLASS(klass); - - /* 2.4 g_type_class_add_private(klass, sizeof(PurpleThemeManagerPrivate));*/ - - obj_class->finalize = purple_theme_manager_finalize; - -} - GType purple_theme_manager_get_type (void) { @@ -62,7 +43,7 @@ sizeof (PurpleThemeManagerClass), NULL, /* base_init */ NULL, /* base_finalize */ - (GClassInitFunc)purple_theme_manager_class_init, /* class_init */ + NULL, /* class_init */ NULL, /* class_finalize */ NULL, /* class_data */ sizeof (PurpleThemeManager), @@ -116,7 +97,7 @@ } static void -purple_theme_manager_build(const gchar *root) +purple_theme_manager_build_dir(const gchar *root) { GDir *rdir; @@ -166,10 +147,12 @@ va_list args; PurpleThemeLoader *loader; + g_return_if_fail(theme_table != NULL); + theme_table = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - g_object_unref); + g_str_equal, + g_free, + g_object_unref); va_start(args, loader1); for (loader = loader1; loader != NULL; loader = va_arg(args, PurpleThemeLoader *)) @@ -177,7 +160,25 @@ va_end(args); /* TODO: add themes properly */ - purple_theme_manager_build(NULL); + purple_theme_manager_build_dir(NULL); +} + +void +purple_theme_manager_refresh() +{ + g_hash_table_foreach_remove (theme_table, + (GHRFunc) purple_theme_manager_is_theme, + NULL); + + /* TODO: this also needs to be fixed the same as new */ + purple_theme_manager_build_dir(NULL); + +} + +void +purple_theme_manager_uninit () +{ + g_hash_table_destroy(theme_table); } @@ -269,18 +270,6 @@ } void -purple_theme_manager_refresh() -{ - g_hash_table_foreach_remove (theme_table, - (GHRFunc) purple_theme_manager_is_theme, - NULL); - - /* TODO: this also needs to be fixed the same as new */ - purple_theme_manager_build(NULL); - -} - -void purple_theme_manager_for_each_theme(PTFunc func) { g_return_if_fail(func);
--- a/libpurple/theme-manager.h Fri Jun 13 21:33:17 2008 +0000 +++ b/libpurple/theme-manager.h Mon Jun 16 19:48:56 2008 +0000 @@ -63,14 +63,24 @@ GType purple_theme_manager_get_type (void); /** - * Creates a new ThemeManager object - * @param the loaders to initalize the manager with and use for first build - * - * @returns a new ThemeManager object + * Initalizes the manager then add the loaders to the theme manager + * and builds with the given loaders + * @param the loaders to build with */ void purple_theme_manager_init (PurpleThemeLoader *loader1, ...); /** + * Rebuilds all the themes in the theme manager + * (removes all current themes but keeps the added loaders) + */ +void purple_theme_manager_refresh(void); + +/** + * Uninitalizes the manager then frees all the themes an loaders it is responsible for + */ +void purple_theme_manager_uninit (void); + +/** * Finds the PurpleTheme object stored by the theme manager * * @param name the name of the PurpleTheme @@ -106,11 +116,6 @@ void purple_theme_manager_unregister_type(PurpleThemeLoader *loader); /** - * Rebuilds all the themes in the theme manaer - */ -void purple_theme_manager_refresh(void); - -/** * Calles the given function on each purple theme * * @param func the PTFunc to be applied to each theme
--- a/libpurple/theme.c Fri Jun 13 21:33:17 2008 +0000 +++ b/libpurple/theme.c Mon Jun 16 19:48:56 2008 +0000 @@ -26,6 +26,7 @@ #define PURPLE_THEME_GET_PRIVATE(PurpleTheme) \ ((PurpleThemePrivate *) ((PurpleTheme)->priv)) +void purple_theme_set_type_string(PurpleTheme *theme, const gchar *type); /****************************************************************************** * Structs @@ -43,6 +44,8 @@ * Globals *****************************************************************************/ +static GObjectClass *parent_class = NULL; + /****************************************************************************** * Enums *****************************************************************************/ @@ -115,6 +118,9 @@ case PROP_AUTHOR: purple_theme_set_author(theme, g_value_get_string(value)); break; + case PROP_TYPE: + purple_theme_set_type_string(theme, g_value_get_string(value)); + break; case PROP_DIR: purple_theme_set_dir(theme, g_value_get_string(value)); break; @@ -128,16 +134,32 @@ } static void +purple_theme_finalize(GObject *obj) +{ + PurpleTheme *theme = PURPLE_THEME(obj); + PurpleThemePrivate *priv = PURPLE_THEME_GET_PRIVATE(theme); + + g_free(priv->name); + g_free(priv->description); + g_free(priv->author); + g_free(priv->type); + g_free(priv->dir); + purple_imgstore_unref(priv->img); + + G_OBJECT_CLASS (parent_class)->finalize (obj); +} + +static void purple_theme_class_init (PurpleThemeClass *klass) { GObjectClass *obj_class = G_OBJECT_CLASS(klass); GParamSpec *pspec; - /* 2.4 - * g_type_class_add_private(klass, sizeof(PurpleThemePrivate)); */ + parent_class = g_type_class_peek_parent(klass); obj_class->get_property = purple_theme_get_property; obj_class->set_property = purple_theme_set_property; + obj_class->finalize = purple_theme_finalize; /* NAME */ pspec = g_param_spec_string(PROP_NAME_S, "Name", @@ -289,6 +311,20 @@ return priv->type; } +/* < private > */ +void +purple_theme_set_type_string(PurpleTheme *theme, const gchar *type) +{ + PurpleThemePrivate *priv; + + g_return_if_fail(PURPLE_IS_THEME(theme)); + + priv = PURPLE_THEME_GET_PRIVATE(theme); + + g_free(priv->type); + priv->type = g_strdup (type); +} + gchar * purple_theme_get_dir(PurpleTheme *theme) {