comparison libpurple/theme-loader.c @ 25918:bc8d1607f9b8

propagate from branch 'im.pidgin.pidgin' (head 566d2e86bfd45c806aba1b32d6f85a9a409ff9ea) to branch 'im.pidgin.pidgin.next.minor' (head ffd76856f93610f7cd6178e943d0b61e4220b549)
author Richard Laager <rlaager@wiktel.com>
date Mon, 26 Jan 2009 02:39:55 +0000
parents 0c7b74fc558e
children a444fe876e52
comparison
equal deleted inserted replaced
25372:a8db457c421a 25918:bc8d1607f9b8
1 /*
2 * ThemeLoaders for libpurple
3 *
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.
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #include "internal.h"
24 #include "theme-loader.h"
25
26 #define PURPLE_THEME_LOADER_GET_PRIVATE(PurpleThemeLoader) \
27 ((PurpleThemeLoaderPrivate *) ((PurpleThemeLoader)->priv))
28
29 void purple_theme_loader_set_type_string(PurpleThemeLoader *loader, const gchar *type);
30
31 /******************************************************************************
32 * Structs
33 *****************************************************************************/
34 typedef struct {
35 gchar *type;
36 } PurpleThemeLoaderPrivate;
37
38 /******************************************************************************
39 * Globals
40 *****************************************************************************/
41
42 static GObjectClass *parent_class = NULL;
43
44 /******************************************************************************
45 * Enums
46 *****************************************************************************/
47
48 enum {
49 PROP_ZERO = 0,
50 PROP_TYPE,
51 };
52
53 /******************************************************************************
54 * GObject Stuff *
55 *****************************************************************************/
56
57 static void
58 purple_theme_loader_get_property(GObject *obj, guint param_id, GValue *value,
59 GParamSpec *psec)
60 {
61 PurpleThemeLoader *theme_loader = PURPLE_THEME_LOADER(obj);
62
63 switch (param_id) {
64 case PROP_TYPE:
65 g_value_set_string(value, purple_theme_loader_get_type_string(theme_loader));
66 default:
67 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
68 break;
69 }
70 }
71
72 static void
73 purple_theme_loader_set_property(GObject *obj, guint param_id, const GValue *value,
74 GParamSpec *psec)
75 {
76 PurpleThemeLoader *loader = PURPLE_THEME_LOADER(obj);
77
78 switch (param_id) {
79 case PROP_TYPE:
80 purple_theme_loader_set_type_string(loader, g_value_get_string(value));
81 break;
82 default:
83 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
84 break;
85 }
86 }
87
88 static void
89 purple_theme_loader_init(GTypeInstance *instance,
90 gpointer klass)
91 {
92 PurpleThemeLoader *loader = PURPLE_THEME_LOADER(instance);
93 loader->priv = g_new0(PurpleThemeLoaderPrivate, 1);
94 }
95
96 static void
97 purple_theme_loader_finalize(GObject *obj)
98 {
99 PurpleThemeLoader *loader = PURPLE_THEME_LOADER(obj);
100 PurpleThemeLoaderPrivate *priv = PURPLE_THEME_LOADER_GET_PRIVATE(loader);
101
102 g_free(priv->type);
103
104 parent_class->finalize(obj);
105 }
106
107 static void
108 purple_theme_loader_class_init(PurpleThemeLoaderClass *klass)
109 {
110 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
111 GParamSpec *pspec;
112
113 parent_class = g_type_class_peek_parent(klass);
114
115 obj_class->get_property = purple_theme_loader_get_property;
116 obj_class->set_property = purple_theme_loader_set_property;
117 obj_class->finalize = purple_theme_loader_finalize;
118
119 /* TYPE STRING (read only) */
120 pspec = g_param_spec_string("type", "Type",
121 "The string represtenting the type of the theme",
122 NULL,
123 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
124 g_object_class_install_property(obj_class, PROP_TYPE, pspec);
125 }
126
127 GType
128 purple_theme_loader_get_type(void)
129 {
130 static GType type = 0;
131 if (type == 0) {
132 static const GTypeInfo info = {
133 sizeof(PurpleThemeLoaderClass),
134 NULL, /* base_init */
135 NULL, /* base_finalize */
136 (GClassInitFunc)purple_theme_loader_class_init, /* class_init */
137 NULL, /* class_finalize */
138 NULL, /* class_data */
139 sizeof(PurpleThemeLoader),
140 0, /* n_preallocs */
141 purple_theme_loader_init, /* instance_init */
142 NULL, /* value table */
143 };
144 type = g_type_register_static(G_TYPE_OBJECT,
145 "PurpleThemeLoader", &info, G_TYPE_FLAG_ABSTRACT);
146 }
147 return type;
148 }
149
150 /*****************************************************************************
151 * Public API functions
152 *****************************************************************************/
153
154 const gchar *
155 purple_theme_loader_get_type_string(PurpleThemeLoader *theme_loader)
156 {
157 PurpleThemeLoaderPrivate *priv = NULL;
158
159 g_return_val_if_fail(PURPLE_IS_THEME_LOADER(theme_loader), NULL);
160
161 priv = PURPLE_THEME_LOADER_GET_PRIVATE(theme_loader);
162 return priv->type;
163 }
164
165 /* < private > */
166 void
167 purple_theme_loader_set_type_string(PurpleThemeLoader *loader, const gchar *type)
168 {
169 PurpleThemeLoaderPrivate *priv;
170
171 g_return_if_fail(PURPLE_IS_THEME_LOADER(loader));
172
173 priv = PURPLE_THEME_LOADER_GET_PRIVATE(loader);
174
175 g_free(priv->type);
176 priv->type = g_strdup(type);
177 }
178
179 PurpleTheme *
180 purple_theme_loader_build(PurpleThemeLoader *loader, const gchar *dir)
181 {
182 return PURPLE_THEME_LOADER_GET_CLASS(loader)->purple_theme_loader_build(dir);
183 }