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
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
30 #define PURPLE_THEME_GET_PRIVATE(PurpleTheme) \
31 ((PurpleThemePrivate *) ((PurpleTheme)->priv))
33 void purple_theme_set_type_string(PurpleTheme
*theme
, const gchar
*type
);
35 /******************************************************************************
37 *****************************************************************************/
48 /******************************************************************************
50 *****************************************************************************/
52 static GObjectClass
*parent_class
= NULL
;
54 /******************************************************************************
56 *****************************************************************************/
68 /******************************************************************************
70 *****************************************************************************/
73 purple_theme_get_property(GObject
*obj
, guint param_id
, GValue
*value
,
76 PurpleTheme
*theme
= PURPLE_THEME(obj
);
80 g_value_set_string(value
, purple_theme_get_name(theme
));
82 case PROP_DESCRIPTION
:
83 g_value_set_string(value
, purple_theme_get_description(theme
));
86 g_value_set_string(value
, purple_theme_get_author(theme
));
89 g_value_set_string(value
, purple_theme_get_type_string(theme
));
92 g_value_set_string(value
, purple_theme_get_dir(theme
));
95 g_value_set_string(value
, purple_theme_get_image(theme
));
98 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, psec
);
104 purple_theme_set_property(GObject
*obj
, guint param_id
, const GValue
*value
,
107 PurpleTheme
*theme
= PURPLE_THEME(obj
);
111 purple_theme_set_name(theme
, g_value_get_string(value
));
113 case PROP_DESCRIPTION
:
114 purple_theme_set_description(theme
, g_value_get_string(value
));
117 purple_theme_set_author(theme
, g_value_get_string(value
));
120 purple_theme_set_type_string(theme
, g_value_get_string(value
));
123 purple_theme_set_dir(theme
, g_value_get_string(value
));
126 purple_theme_set_image(theme
, g_value_get_string(value
));
129 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, psec
);
135 purple_theme_init(GTypeInstance
*instance
,
138 PurpleTheme
*theme
= PURPLE_THEME(instance
);
139 theme
->priv
= g_new0(PurpleThemePrivate
, 1);
143 purple_theme_finalize(GObject
*obj
)
145 PurpleTheme
*theme
= PURPLE_THEME(obj
);
146 PurpleThemePrivate
*priv
= PURPLE_THEME_GET_PRIVATE(theme
);
149 g_free(priv
->description
);
150 g_free(priv
->author
);
155 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
159 purple_theme_class_init(PurpleThemeClass
*klass
)
161 GObjectClass
*obj_class
= G_OBJECT_CLASS(klass
);
164 parent_class
= g_type_class_peek_parent(klass
);
166 obj_class
->get_property
= purple_theme_get_property
;
167 obj_class
->set_property
= purple_theme_set_property
;
168 obj_class
->finalize
= purple_theme_finalize
;
171 pspec
= g_param_spec_string("name", "Name",
172 "The name of the theme",
174 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
175 g_object_class_install_property(obj_class
, PROP_NAME
, pspec
);
178 pspec
= g_param_spec_string("description", "Description",
179 "The description of the theme",
181 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
182 g_object_class_install_property(obj_class
, PROP_DESCRIPTION
, pspec
);
185 pspec
= g_param_spec_string("author", "Author",
186 "The author of the theme",
188 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
189 g_object_class_install_property(obj_class
, PROP_AUTHOR
, pspec
);
191 /* TYPE STRING (read only) */
192 pspec
= g_param_spec_string("type", "Type",
193 "The string representing the type of the theme",
195 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
);
196 g_object_class_install_property(obj_class
, PROP_TYPE
, pspec
);
199 pspec
= g_param_spec_string("directory", "Directory",
200 "The directory that contains the theme and all its files",
202 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
203 g_object_class_install_property(obj_class
, PROP_DIR
, pspec
);
206 pspec
= g_param_spec_string("image", "Image",
207 "A preview image of the theme",
210 g_object_class_install_property(obj_class
, PROP_IMAGE
, pspec
);
215 purple_theme_get_type(void)
217 static GType type
= 0;
219 static const GTypeInfo info
= {
220 sizeof(PurpleThemeClass
),
221 NULL
, /* base_init */
222 NULL
, /* base_finalize */
223 (GClassInitFunc
)purple_theme_class_init
, /* class_init */
224 NULL
, /* class_finalize */
225 NULL
, /* class_data */
228 purple_theme_init
, /* instance_init */
229 NULL
, /* value table */
231 type
= g_type_register_static (G_TYPE_OBJECT
,
232 "PurpleTheme", &info
, G_TYPE_FLAG_ABSTRACT
);
237 /******************************************************************************
239 *****************************************************************************/
242 theme_clean_text(const gchar
*text
)
244 gchar
*clean_text
= NULL
;
246 clean_text
= g_markup_escape_text(text
, -1);
247 g_strdelimit(clean_text
, "\n", ' ');
248 purple_str_strip_char(clean_text
, '\r');
253 /*****************************************************************************
254 * Public API function
255 *****************************************************************************/
258 purple_theme_get_name(PurpleTheme
*theme
)
260 PurpleThemePrivate
*priv
;
262 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
264 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
269 purple_theme_set_name(PurpleTheme
*theme
, const gchar
*name
)
271 PurpleThemePrivate
*priv
;
273 g_return_if_fail(PURPLE_IS_THEME(theme
));
275 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
278 priv
->name
= theme_clean_text(name
);
282 purple_theme_get_description(PurpleTheme
*theme
)
284 PurpleThemePrivate
*priv
;
286 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
288 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
289 return priv
->description
;
293 purple_theme_set_description(PurpleTheme
*theme
, const gchar
*description
)
295 PurpleThemePrivate
*priv
;
297 g_return_if_fail(PURPLE_IS_THEME(theme
));
299 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
301 g_free(priv
->description
);
302 priv
->description
= theme_clean_text(description
);
306 purple_theme_get_author(PurpleTheme
*theme
)
308 PurpleThemePrivate
*priv
;
310 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
312 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
317 purple_theme_set_author(PurpleTheme
*theme
, const gchar
*author
)
319 PurpleThemePrivate
*priv
;
321 g_return_if_fail(PURPLE_IS_THEME(theme
));
323 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
325 g_free(priv
->author
);
326 priv
->author
= theme_clean_text(author
);
330 purple_theme_get_type_string(PurpleTheme
*theme
)
332 PurpleThemePrivate
*priv
;
334 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
336 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
342 purple_theme_set_type_string(PurpleTheme
*theme
, const gchar
*type
)
344 PurpleThemePrivate
*priv
;
346 g_return_if_fail(PURPLE_IS_THEME(theme
));
348 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
351 priv
->type
= g_strdup(type
);
355 purple_theme_get_dir(PurpleTheme
*theme
)
357 PurpleThemePrivate
*priv
;
359 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
361 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
366 purple_theme_set_dir(PurpleTheme
*theme
, const gchar
*dir
)
368 PurpleThemePrivate
*priv
;
370 g_return_if_fail(PURPLE_IS_THEME(theme
));
372 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
375 priv
->dir
= g_strdup(dir
);
379 purple_theme_get_image(PurpleTheme
*theme
)
381 PurpleThemePrivate
*priv
;
383 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
385 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
391 purple_theme_get_image_full(PurpleTheme
*theme
)
393 const gchar
*filename
= purple_theme_get_image(theme
);
396 return g_build_filename(purple_theme_get_dir(PURPLE_THEME(theme
)), filename
, NULL
);
402 purple_theme_set_image(PurpleTheme
*theme
, const gchar
*img
)
404 PurpleThemePrivate
*priv
;
406 g_return_if_fail(PURPLE_IS_THEME(theme
));
408 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
411 priv
->img
= g_strdup(img
);