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
27 #define PURPLE_THEME_GET_PRIVATE(PurpleTheme) \
28 ((PurpleThemePrivate *) ((PurpleTheme)->priv))
30 void purple_theme_set_type_string(PurpleTheme
*theme
, const gchar
*type
);
32 /******************************************************************************
34 *****************************************************************************/
45 /******************************************************************************
47 *****************************************************************************/
49 static GObjectClass
*parent_class
= NULL
;
51 /******************************************************************************
53 *****************************************************************************/
65 /******************************************************************************
67 *****************************************************************************/
70 purple_theme_get_property(GObject
*obj
, guint param_id
, GValue
*value
,
73 PurpleTheme
*theme
= PURPLE_THEME(obj
);
77 g_value_set_string(value
, purple_theme_get_name(theme
));
79 case PROP_DESCRIPTION
:
80 g_value_set_string(value
, purple_theme_get_description(theme
));
83 g_value_set_string(value
, purple_theme_get_author(theme
));
86 g_value_set_string(value
, purple_theme_get_type_string(theme
));
89 g_value_set_string(value
, purple_theme_get_dir(theme
));
92 g_value_set_string(value
, purple_theme_get_image(theme
));
95 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, psec
);
101 purple_theme_set_property(GObject
*obj
, guint param_id
, const GValue
*value
,
104 PurpleTheme
*theme
= PURPLE_THEME(obj
);
108 purple_theme_set_name(theme
, g_value_get_string(value
));
110 case PROP_DESCRIPTION
:
111 purple_theme_set_description(theme
, g_value_get_string(value
));
114 purple_theme_set_author(theme
, g_value_get_string(value
));
117 purple_theme_set_type_string(theme
, g_value_get_string(value
));
120 purple_theme_set_dir(theme
, g_value_get_string(value
));
123 purple_theme_set_image(theme
, g_value_get_string(value
));
126 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, psec
);
132 purple_theme_init(GTypeInstance
*instance
,
135 PurpleTheme
*theme
= PURPLE_THEME(instance
);
136 theme
->priv
= g_new0(PurpleThemePrivate
, 1);
140 purple_theme_finalize(GObject
*obj
)
142 PurpleTheme
*theme
= PURPLE_THEME(obj
);
143 PurpleThemePrivate
*priv
= PURPLE_THEME_GET_PRIVATE(theme
);
146 g_free(priv
->description
);
147 g_free(priv
->author
);
152 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
156 purple_theme_class_init(PurpleThemeClass
*klass
)
158 GObjectClass
*obj_class
= G_OBJECT_CLASS(klass
);
161 parent_class
= g_type_class_peek_parent(klass
);
163 obj_class
->get_property
= purple_theme_get_property
;
164 obj_class
->set_property
= purple_theme_set_property
;
165 obj_class
->finalize
= purple_theme_finalize
;
168 pspec
= g_param_spec_string("name", "Name",
169 "The name of the theme",
171 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
172 g_object_class_install_property(obj_class
, PROP_NAME
, pspec
);
175 pspec
= g_param_spec_string("description", "Description",
176 "The description of the theme",
178 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
179 g_object_class_install_property(obj_class
, PROP_DESCRIPTION
, pspec
);
182 pspec
= g_param_spec_string("author", "Author",
183 "The author of the theme",
185 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
186 g_object_class_install_property(obj_class
, PROP_AUTHOR
, pspec
);
188 /* TYPE STRING (read only) */
189 pspec
= g_param_spec_string("type", "Type",
190 "The string representing the type of the theme",
192 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
);
193 g_object_class_install_property(obj_class
, PROP_TYPE
, pspec
);
196 pspec
= g_param_spec_string("directory", "Directory",
197 "The directory that contains the theme and all its files",
199 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
200 g_object_class_install_property(obj_class
, PROP_DIR
, pspec
);
203 pspec
= g_param_spec_string("image", "Image",
204 "A preview image of the theme",
207 g_object_class_install_property(obj_class
, PROP_IMAGE
, pspec
);
212 purple_theme_get_type(void)
214 static GType type
= 0;
216 static const GTypeInfo info
= {
217 sizeof(PurpleThemeClass
),
218 NULL
, /* base_init */
219 NULL
, /* base_finalize */
220 (GClassInitFunc
)purple_theme_class_init
, /* class_init */
221 NULL
, /* class_finalize */
222 NULL
, /* class_data */
225 purple_theme_init
, /* instance_init */
226 NULL
, /* value table */
228 type
= g_type_register_static (G_TYPE_OBJECT
,
229 "PurpleTheme", &info
, G_TYPE_FLAG_ABSTRACT
);
234 /******************************************************************************
236 *****************************************************************************/
239 theme_clean_text(const gchar
*text
)
241 gchar
*clean_text
= NULL
;
243 clean_text
= g_markup_escape_text(text
, -1);
244 g_strdelimit(clean_text
, "\n", ' ');
245 purple_str_strip_char(clean_text
, '\r');
250 /*****************************************************************************
251 * Public API function
252 *****************************************************************************/
255 purple_theme_get_name(PurpleTheme
*theme
)
257 PurpleThemePrivate
*priv
;
259 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
261 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
266 purple_theme_set_name(PurpleTheme
*theme
, const gchar
*name
)
268 PurpleThemePrivate
*priv
;
270 g_return_if_fail(PURPLE_IS_THEME(theme
));
272 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
275 priv
->name
= theme_clean_text(name
);
279 purple_theme_get_description(PurpleTheme
*theme
)
281 PurpleThemePrivate
*priv
;
283 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
285 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
286 return priv
->description
;
290 purple_theme_set_description(PurpleTheme
*theme
, const gchar
*description
)
292 PurpleThemePrivate
*priv
;
294 g_return_if_fail(PURPLE_IS_THEME(theme
));
296 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
298 g_free(priv
->description
);
299 priv
->description
= theme_clean_text(description
);
303 purple_theme_get_author(PurpleTheme
*theme
)
305 PurpleThemePrivate
*priv
;
307 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
309 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
314 purple_theme_set_author(PurpleTheme
*theme
, const gchar
*author
)
316 PurpleThemePrivate
*priv
;
318 g_return_if_fail(PURPLE_IS_THEME(theme
));
320 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
322 g_free(priv
->author
);
323 priv
->author
= theme_clean_text(author
);
327 purple_theme_get_type_string(PurpleTheme
*theme
)
329 PurpleThemePrivate
*priv
;
331 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
333 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
339 purple_theme_set_type_string(PurpleTheme
*theme
, const gchar
*type
)
341 PurpleThemePrivate
*priv
;
343 g_return_if_fail(PURPLE_IS_THEME(theme
));
345 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
348 priv
->type
= g_strdup(type
);
352 purple_theme_get_dir(PurpleTheme
*theme
)
354 PurpleThemePrivate
*priv
;
356 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
358 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
363 purple_theme_set_dir(PurpleTheme
*theme
, const gchar
*dir
)
365 PurpleThemePrivate
*priv
;
367 g_return_if_fail(PURPLE_IS_THEME(theme
));
369 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
372 priv
->dir
= g_strdup(dir
);
376 purple_theme_get_image(PurpleTheme
*theme
)
378 PurpleThemePrivate
*priv
;
380 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
382 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
388 purple_theme_get_image_full(PurpleTheme
*theme
)
390 const gchar
*filename
= purple_theme_get_image(theme
);
393 return g_build_filename(purple_theme_get_dir(PURPLE_THEME(theme
)), filename
, NULL
);
399 purple_theme_set_image(PurpleTheme
*theme
, const gchar
*img
)
401 PurpleThemePrivate
*priv
;
403 g_return_if_fail(PURPLE_IS_THEME(theme
));
405 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
408 priv
->img
= g_strdup(img
);