Remove unused Meson option for enchant.
[pidgin-git.git] / libpurple / theme.c
bloba5ca50082a14bfc99e4618069c8e597e2043e052
1 /*
2 * Themes 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 "glibcompat.h"
25 #include "theme.h"
26 #include "util.h"
28 void purple_theme_set_type_string(PurpleTheme *theme, const gchar *type);
30 /******************************************************************************
31 * Structs
32 *****************************************************************************/
34 typedef struct {
35 gchar *name;
36 gchar *description;
37 gchar *author;
38 gchar *type;
39 gchar *dir;
40 gchar *img;
41 } PurpleThemePrivate;
43 /******************************************************************************
44 * Enums
45 *****************************************************************************/
47 enum {
48 PROP_ZERO = 0,
49 PROP_NAME,
50 PROP_DESCRIPTION,
51 PROP_AUTHOR,
52 PROP_TYPE,
53 PROP_DIR,
54 PROP_IMAGE,
55 PROP_LAST
58 /******************************************************************************
59 * Globals
60 *****************************************************************************/
62 static GParamSpec *properties[PROP_LAST];
64 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(PurpleTheme, purple_theme, G_TYPE_OBJECT);
66 /******************************************************************************
67 * GObject Stuff
68 *****************************************************************************/
70 static void
71 purple_theme_get_property(GObject *obj, guint param_id, GValue *value,
72 GParamSpec *psec)
74 PurpleTheme *theme = PURPLE_THEME(obj);
76 switch (param_id) {
77 case PROP_NAME:
78 g_value_set_string(value, purple_theme_get_name(theme));
79 break;
80 case PROP_DESCRIPTION:
81 g_value_set_string(value, purple_theme_get_description(theme));
82 break;
83 case PROP_AUTHOR:
84 g_value_set_string(value, purple_theme_get_author(theme));
85 break;
86 case PROP_TYPE:
87 g_value_set_string(value, purple_theme_get_type_string(theme));
88 break;
89 case PROP_DIR:
90 g_value_set_string(value, purple_theme_get_dir(theme));
91 break;
92 case PROP_IMAGE:
93 g_value_set_string(value, purple_theme_get_image(theme));
94 break;
95 default:
96 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
97 break;
101 static void
102 purple_theme_set_property(GObject *obj, guint param_id, const GValue *value,
103 GParamSpec *psec)
105 PurpleTheme *theme = PURPLE_THEME(obj);
107 switch (param_id) {
108 case PROP_NAME:
109 purple_theme_set_name(theme, g_value_get_string(value));
110 break;
111 case PROP_DESCRIPTION:
112 purple_theme_set_description(theme, g_value_get_string(value));
113 break;
114 case PROP_AUTHOR:
115 purple_theme_set_author(theme, g_value_get_string(value));
116 break;
117 case PROP_TYPE:
118 purple_theme_set_type_string(theme, g_value_get_string(value));
119 break;
120 case PROP_DIR:
121 purple_theme_set_dir(theme, g_value_get_string(value));
122 break;
123 case PROP_IMAGE:
124 purple_theme_set_image(theme, g_value_get_string(value));
125 break;
126 default:
127 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
128 break;
132 static void
133 purple_theme_init(PurpleTheme *theme)
137 static void
138 purple_theme_finalize(GObject *obj)
140 PurpleTheme *theme = PURPLE_THEME(obj);
141 PurpleThemePrivate *priv = purple_theme_get_instance_private(theme);
143 g_free(priv->name);
144 g_free(priv->description);
145 g_free(priv->author);
146 g_free(priv->type);
147 g_free(priv->dir);
148 g_free(priv->img);
150 G_OBJECT_CLASS(purple_theme_parent_class)->finalize(obj);
153 static void
154 purple_theme_class_init(PurpleThemeClass *klass)
156 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
158 obj_class->get_property = purple_theme_get_property;
159 obj_class->set_property = purple_theme_set_property;
160 obj_class->finalize = purple_theme_finalize;
162 /* NAME */
163 properties[PROP_NAME] = g_param_spec_string("name", "Name",
164 "The name of the theme",
165 NULL,
166 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
168 /* DESCRIPTION */
169 properties[PROP_DESCRIPTION] = g_param_spec_string("description",
170 "Description",
171 "The description of the theme",
172 NULL,
173 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
175 /* AUTHOR */
176 properties[PROP_AUTHOR] = g_param_spec_string("author", "Author",
177 "The author of the theme",
178 NULL,
179 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
181 /* TYPE STRING (read only) */
182 properties[PROP_TYPE] = g_param_spec_string("type", "Type",
183 "The string representing the type of the theme",
184 NULL,
185 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
186 G_PARAM_STATIC_STRINGS);
188 /* DIRECTORY */
189 properties[PROP_DIR] = g_param_spec_string("directory", "Directory",
190 "The directory that contains the theme and all its files",
191 NULL,
192 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
194 /* PREVIEW IMAGE */
195 properties[PROP_IMAGE] = g_param_spec_string("image", "Image",
196 "A preview image of the theme",
197 NULL,
198 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
200 g_object_class_install_properties(obj_class, PROP_LAST, properties);
203 /******************************************************************************
204 * Helper Functions
205 *****************************************************************************/
207 static gchar *
208 theme_clean_text(const gchar *text)
210 gchar *clean_text = NULL;
211 if (text != NULL) {
212 clean_text = g_markup_escape_text(text, -1);
213 g_strdelimit(clean_text, "\n", ' ');
214 purple_str_strip_char(clean_text, '\r');
216 return clean_text;
219 /*****************************************************************************
220 * Public API function
221 *****************************************************************************/
223 const gchar *
224 purple_theme_get_name(PurpleTheme *theme)
226 PurpleThemePrivate *priv;
228 g_return_val_if_fail(PURPLE_IS_THEME(theme), NULL);
230 priv = purple_theme_get_instance_private(theme);
231 return priv->name;
234 void
235 purple_theme_set_name(PurpleTheme *theme, const gchar *name)
237 PurpleThemePrivate *priv;
239 g_return_if_fail(PURPLE_IS_THEME(theme));
241 priv = purple_theme_get_instance_private(theme);
243 g_free(priv->name);
244 priv->name = theme_clean_text(name);
246 g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_NAME]);
249 const gchar *
250 purple_theme_get_description(PurpleTheme *theme)
252 PurpleThemePrivate *priv;
254 g_return_val_if_fail(PURPLE_IS_THEME(theme), NULL);
256 priv = purple_theme_get_instance_private(theme);
257 return priv->description;
260 void
261 purple_theme_set_description(PurpleTheme *theme, const gchar *description)
263 PurpleThemePrivate *priv;
265 g_return_if_fail(PURPLE_IS_THEME(theme));
267 priv = purple_theme_get_instance_private(theme);
269 g_free(priv->description);
270 priv->description = theme_clean_text(description);
272 g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_DESCRIPTION]);
275 const gchar *
276 purple_theme_get_author(PurpleTheme *theme)
278 PurpleThemePrivate *priv;
280 g_return_val_if_fail(PURPLE_IS_THEME(theme), NULL);
282 priv = purple_theme_get_instance_private(theme);
283 return priv->author;
286 void
287 purple_theme_set_author(PurpleTheme *theme, const gchar *author)
289 PurpleThemePrivate *priv;
291 g_return_if_fail(PURPLE_IS_THEME(theme));
293 priv = purple_theme_get_instance_private(theme);
295 g_free(priv->author);
296 priv->author = theme_clean_text(author);
298 g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_AUTHOR]);
301 const gchar *
302 purple_theme_get_type_string(PurpleTheme *theme)
304 PurpleThemePrivate *priv;
306 g_return_val_if_fail(PURPLE_IS_THEME(theme), NULL);
308 priv = purple_theme_get_instance_private(theme);
309 return priv->type;
312 /* < private > */
313 void
314 purple_theme_set_type_string(PurpleTheme *theme, const gchar *type)
316 PurpleThemePrivate *priv;
318 g_return_if_fail(PURPLE_IS_THEME(theme));
320 priv = purple_theme_get_instance_private(theme);
322 g_free(priv->type);
323 priv->type = g_strdup(type);
325 g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_TYPE]);
328 const gchar *
329 purple_theme_get_dir(PurpleTheme *theme)
331 PurpleThemePrivate *priv;
333 g_return_val_if_fail(PURPLE_IS_THEME(theme), NULL);
335 priv = purple_theme_get_instance_private(theme);
336 return priv->dir;
339 void
340 purple_theme_set_dir(PurpleTheme *theme, const gchar *dir)
342 PurpleThemePrivate *priv;
344 g_return_if_fail(PURPLE_IS_THEME(theme));
346 priv = purple_theme_get_instance_private(theme);
348 g_free(priv->dir);
349 priv->dir = g_strdup(dir);
351 g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_DIR]);
354 const gchar *
355 purple_theme_get_image(PurpleTheme *theme)
357 PurpleThemePrivate *priv;
359 g_return_val_if_fail(PURPLE_IS_THEME(theme), NULL);
361 priv = purple_theme_get_instance_private(theme);
363 return priv->img;
366 gchar *
367 purple_theme_get_image_full(PurpleTheme *theme)
369 const gchar *filename = purple_theme_get_image(theme);
371 if (filename)
372 return g_build_filename(purple_theme_get_dir(PURPLE_THEME(theme)), filename, NULL);
373 else
374 return NULL;
377 void
378 purple_theme_set_image(PurpleTheme *theme, const gchar *img)
380 PurpleThemePrivate *priv;
382 g_return_if_fail(PURPLE_IS_THEME(theme));
384 priv = purple_theme_get_instance_private(theme);
386 g_free(priv->img);
387 priv->img = g_strdup(img);
389 g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_IMAGE]);