Remove useless comparison
[pidgin-git.git] / libpurple / theme-loader.c
bloba77533b1e064a3a37651c1894586c7598ea92c88
1 /*
2 * ThemeLoaders for libpurple
4 * Pidgin is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #include "internal.h"
24 #include "theme-loader.h"
26 #define PURPLE_THEME_LOADER_GET_PRIVATE(PurpleThemeLoader) \
27 ((PurpleThemeLoaderPrivate *) ((PurpleThemeLoader)->priv))
29 void purple_theme_loader_set_type_string(PurpleThemeLoader *loader, const gchar *type);
31 /******************************************************************************
32 * Structs
33 *****************************************************************************/
34 typedef struct {
35 gchar *type;
36 } PurpleThemeLoaderPrivate;
38 /******************************************************************************
39 * Globals
40 *****************************************************************************/
42 static GObjectClass *parent_class = NULL;
44 /******************************************************************************
45 * Enums
46 *****************************************************************************/
48 enum {
49 PROP_ZERO = 0,
50 PROP_TYPE,
53 /******************************************************************************
54 * GObject Stuff *
55 *****************************************************************************/
57 static void
58 purple_theme_loader_get_property(GObject *obj, guint param_id, GValue *value,
59 GParamSpec *psec)
61 PurpleThemeLoader *theme_loader = PURPLE_THEME_LOADER(obj);
63 switch (param_id) {
64 case PROP_TYPE:
65 g_value_set_string(value, purple_theme_loader_get_type_string(theme_loader));
66 break;
67 default:
68 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
69 break;
73 static void
74 purple_theme_loader_set_property(GObject *obj, guint param_id, const GValue *value,
75 GParamSpec *psec)
77 PurpleThemeLoader *loader = PURPLE_THEME_LOADER(obj);
79 switch (param_id) {
80 case PROP_TYPE:
81 purple_theme_loader_set_type_string(loader, g_value_get_string(value));
82 break;
83 default:
84 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
85 break;
89 static void
90 purple_theme_loader_init(GTypeInstance *instance,
91 gpointer klass)
93 PurpleThemeLoader *loader = PURPLE_THEME_LOADER(instance);
94 loader->priv = g_new0(PurpleThemeLoaderPrivate, 1);
97 static void
98 purple_theme_loader_finalize(GObject *obj)
100 PurpleThemeLoader *loader = PURPLE_THEME_LOADER(obj);
101 PurpleThemeLoaderPrivate *priv = PURPLE_THEME_LOADER_GET_PRIVATE(loader);
103 g_free(priv->type);
104 g_free(priv);
106 parent_class->finalize(obj);
109 static void
110 purple_theme_loader_class_init(PurpleThemeLoaderClass *klass)
112 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
113 GParamSpec *pspec;
115 parent_class = g_type_class_peek_parent(klass);
117 obj_class->get_property = purple_theme_loader_get_property;
118 obj_class->set_property = purple_theme_loader_set_property;
119 obj_class->finalize = purple_theme_loader_finalize;
121 /* TYPE STRING (read only) */
122 pspec = g_param_spec_string("type", "Type",
123 "The string representing the type of the theme",
124 NULL,
125 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
126 g_object_class_install_property(obj_class, PROP_TYPE, pspec);
129 GType
130 purple_theme_loader_get_type(void)
132 static GType type = 0;
133 if (type == 0) {
134 static const GTypeInfo info = {
135 sizeof(PurpleThemeLoaderClass),
136 NULL, /* base_init */
137 NULL, /* base_finalize */
138 (GClassInitFunc)purple_theme_loader_class_init, /* class_init */
139 NULL, /* class_finalize */
140 NULL, /* class_data */
141 sizeof(PurpleThemeLoader),
142 0, /* n_preallocs */
143 purple_theme_loader_init, /* instance_init */
144 NULL, /* value table */
146 type = g_type_register_static(G_TYPE_OBJECT,
147 "PurpleThemeLoader", &info, G_TYPE_FLAG_ABSTRACT);
149 return type;
152 /*****************************************************************************
153 * Public API functions
154 *****************************************************************************/
156 const gchar *
157 purple_theme_loader_get_type_string(PurpleThemeLoader *theme_loader)
159 PurpleThemeLoaderPrivate *priv = NULL;
161 g_return_val_if_fail(PURPLE_IS_THEME_LOADER(theme_loader), NULL);
163 priv = PURPLE_THEME_LOADER_GET_PRIVATE(theme_loader);
164 return priv->type;
167 /* < private > */
168 void
169 purple_theme_loader_set_type_string(PurpleThemeLoader *loader, const gchar *type)
171 PurpleThemeLoaderPrivate *priv;
173 g_return_if_fail(PURPLE_IS_THEME_LOADER(loader));
175 priv = PURPLE_THEME_LOADER_GET_PRIVATE(loader);
177 g_free(priv->type);
178 priv->type = g_strdup(type);
181 PurpleTheme *
182 purple_theme_loader_build(PurpleThemeLoader *loader, const gchar *dir)
184 return PURPLE_THEME_LOADER_GET_CLASS(loader)->purple_theme_loader_build(dir);