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
24 #include "glibcompat.h"
28 #define PURPLE_THEME_GET_PRIVATE(PurpleTheme) \
29 (G_TYPE_INSTANCE_GET_PRIVATE((PurpleTheme), PURPLE_TYPE_THEME, PurpleThemePrivate))
31 void purple_theme_set_type_string(PurpleTheme
*theme
, const gchar
*type
);
33 /******************************************************************************
35 *****************************************************************************/
46 /******************************************************************************
48 *****************************************************************************/
61 /******************************************************************************
63 *****************************************************************************/
65 static GObjectClass
*parent_class
= NULL
;
66 static GParamSpec
*properties
[PROP_LAST
];
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_finalize(GObject
*obj
)
137 PurpleTheme
*theme
= PURPLE_THEME(obj
);
138 PurpleThemePrivate
*priv
= PURPLE_THEME_GET_PRIVATE(theme
);
141 g_free(priv
->description
);
142 g_free(priv
->author
);
147 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
151 purple_theme_class_init(PurpleThemeClass
*klass
)
153 GObjectClass
*obj_class
= G_OBJECT_CLASS(klass
);
155 parent_class
= g_type_class_peek_parent(klass
);
157 g_type_class_add_private(klass
, sizeof(PurpleThemePrivate
));
159 obj_class
->get_property
= purple_theme_get_property
;
160 obj_class
->set_property
= purple_theme_set_property
;
161 obj_class
->finalize
= purple_theme_finalize
;
164 properties
[PROP_NAME
] = g_param_spec_string("name", "Name",
165 "The name of the theme",
167 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
| G_PARAM_STATIC_STRINGS
);
170 properties
[PROP_DESCRIPTION
] = g_param_spec_string("description",
172 "The description of the theme",
174 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
| G_PARAM_STATIC_STRINGS
);
177 properties
[PROP_AUTHOR
] = g_param_spec_string("author", "Author",
178 "The author of the theme",
180 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
| G_PARAM_STATIC_STRINGS
);
182 /* TYPE STRING (read only) */
183 properties
[PROP_TYPE
] = g_param_spec_string("type", "Type",
184 "The string representing the type of the theme",
186 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
|
187 G_PARAM_STATIC_STRINGS
);
190 properties
[PROP_DIR
] = g_param_spec_string("directory", "Directory",
191 "The directory that contains the theme and all its files",
193 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
| G_PARAM_STATIC_STRINGS
);
196 properties
[PROP_IMAGE
] = g_param_spec_string("image", "Image",
197 "A preview image of the theme",
199 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
);
201 g_object_class_install_properties(obj_class
, PROP_LAST
, properties
);
206 purple_theme_get_type(void)
208 static GType type
= 0;
210 static const GTypeInfo info
= {
211 sizeof(PurpleThemeClass
),
212 NULL
, /* base_init */
213 NULL
, /* base_finalize */
214 (GClassInitFunc
)purple_theme_class_init
, /* class_init */
215 NULL
, /* class_finalize */
216 NULL
, /* class_data */
219 NULL
, /* instance_init */
220 NULL
, /* value table */
222 type
= g_type_register_static (G_TYPE_OBJECT
,
223 "PurpleTheme", &info
, G_TYPE_FLAG_ABSTRACT
);
228 /******************************************************************************
230 *****************************************************************************/
233 theme_clean_text(const gchar
*text
)
235 gchar
*clean_text
= NULL
;
237 clean_text
= g_markup_escape_text(text
, -1);
238 g_strdelimit(clean_text
, "\n", ' ');
239 purple_str_strip_char(clean_text
, '\r');
244 /*****************************************************************************
245 * Public API function
246 *****************************************************************************/
249 purple_theme_get_name(PurpleTheme
*theme
)
251 PurpleThemePrivate
*priv
;
253 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
255 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
260 purple_theme_set_name(PurpleTheme
*theme
, const gchar
*name
)
262 PurpleThemePrivate
*priv
;
264 g_return_if_fail(PURPLE_IS_THEME(theme
));
266 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
269 priv
->name
= theme_clean_text(name
);
271 g_object_notify_by_pspec(G_OBJECT(theme
), properties
[PROP_NAME
]);
275 purple_theme_get_description(PurpleTheme
*theme
)
277 PurpleThemePrivate
*priv
;
279 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
281 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
282 return priv
->description
;
286 purple_theme_set_description(PurpleTheme
*theme
, const gchar
*description
)
288 PurpleThemePrivate
*priv
;
290 g_return_if_fail(PURPLE_IS_THEME(theme
));
292 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
294 g_free(priv
->description
);
295 priv
->description
= theme_clean_text(description
);
297 g_object_notify_by_pspec(G_OBJECT(theme
), properties
[PROP_DESCRIPTION
]);
301 purple_theme_get_author(PurpleTheme
*theme
)
303 PurpleThemePrivate
*priv
;
305 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
307 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
312 purple_theme_set_author(PurpleTheme
*theme
, const gchar
*author
)
314 PurpleThemePrivate
*priv
;
316 g_return_if_fail(PURPLE_IS_THEME(theme
));
318 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
320 g_free(priv
->author
);
321 priv
->author
= theme_clean_text(author
);
323 g_object_notify_by_pspec(G_OBJECT(theme
), properties
[PROP_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
);
350 g_object_notify_by_pspec(G_OBJECT(theme
), properties
[PROP_TYPE
]);
354 purple_theme_get_dir(PurpleTheme
*theme
)
356 PurpleThemePrivate
*priv
;
358 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
360 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
365 purple_theme_set_dir(PurpleTheme
*theme
, const gchar
*dir
)
367 PurpleThemePrivate
*priv
;
369 g_return_if_fail(PURPLE_IS_THEME(theme
));
371 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
374 priv
->dir
= g_strdup(dir
);
376 g_object_notify_by_pspec(G_OBJECT(theme
), properties
[PROP_DIR
]);
380 purple_theme_get_image(PurpleTheme
*theme
)
382 PurpleThemePrivate
*priv
;
384 g_return_val_if_fail(PURPLE_IS_THEME(theme
), NULL
);
386 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
392 purple_theme_get_image_full(PurpleTheme
*theme
)
394 const gchar
*filename
= purple_theme_get_image(theme
);
397 return g_build_filename(purple_theme_get_dir(PURPLE_THEME(theme
)), filename
, NULL
);
403 purple_theme_set_image(PurpleTheme
*theme
, const gchar
*img
)
405 PurpleThemePrivate
*priv
;
407 g_return_if_fail(PURPLE_IS_THEME(theme
));
409 priv
= PURPLE_THEME_GET_PRIVATE(theme
);
412 priv
->img
= g_strdup(img
);
414 g_object_notify_by_pspec(G_OBJECT(theme
), properties
[PROP_IMAGE
]);