Mercurial > pidgin
comparison libpurple/theme.c @ 25889:e2b193decaa5
explicit merge of '814d53152c168c9c4732b3d084260711d536fba6'
and 'af375020001eed33302b471e7ee9dec6a478e824'
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Fri, 02 Jan 2009 22:23:58 +0000 |
| parents | 1eacf60a73dd |
| children | 0c7b74fc558e |
comparison
equal
deleted
inserted
replaced
| 24844:94a47062819c | 25889:e2b193decaa5 |
|---|---|
| 1 /* | |
| 2 * Themes 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 <glib.h> | |
| 24 #include <string.h> | |
| 25 | |
| 26 #include "internal.h" | |
| 27 #include "theme.h" | |
| 28 #include "util.h" | |
| 29 | |
| 30 #define PURPLE_THEME_GET_PRIVATE(PurpleTheme) \ | |
| 31 ((PurpleThemePrivate *) ((PurpleTheme)->priv)) | |
| 32 | |
| 33 void purple_theme_set_type_string(PurpleTheme *theme, const gchar *type); | |
| 34 | |
| 35 /****************************************************************************** | |
| 36 * Structs | |
| 37 *****************************************************************************/ | |
| 38 typedef struct { | |
| 39 gchar *name; | |
| 40 gchar *description; | |
| 41 gchar *author; | |
| 42 gchar *type; | |
| 43 gchar *dir; | |
| 44 gchar *img; | |
| 45 } PurpleThemePrivate; | |
| 46 | |
| 47 /****************************************************************************** | |
| 48 * Globals | |
| 49 *****************************************************************************/ | |
| 50 | |
| 51 static GObjectClass *parent_class = NULL; | |
| 52 | |
| 53 /****************************************************************************** | |
| 54 * Enums | |
| 55 *****************************************************************************/ | |
| 56 | |
| 57 enum { | |
| 58 PROP_ZERO = 0, | |
| 59 PROP_NAME, | |
| 60 PROP_DESCRIPTION, | |
| 61 PROP_AUTHOR, | |
| 62 PROP_TYPE, | |
| 63 PROP_DIR, | |
| 64 PROP_IMAGE | |
| 65 }; | |
| 66 | |
| 67 /****************************************************************************** | |
| 68 * GObject Stuff * | |
| 69 *****************************************************************************/ | |
| 70 | |
| 71 static void | |
| 72 purple_theme_get_property(GObject *obj, guint param_id, GValue *value, | |
| 73 GParamSpec *psec) | |
| 74 { | |
| 75 PurpleTheme *theme = PURPLE_THEME(obj); | |
| 76 | |
| 77 switch(param_id) { | |
| 78 case PROP_NAME: | |
| 79 g_value_set_string(value, purple_theme_get_name(theme)); | |
| 80 break; | |
| 81 case PROP_DESCRIPTION: | |
| 82 g_value_set_string(value, purple_theme_get_description(theme)); | |
| 83 break; | |
| 84 case PROP_AUTHOR: | |
| 85 g_value_set_string(value, purple_theme_get_author(theme)); | |
| 86 break; | |
| 87 case PROP_TYPE: | |
| 88 g_value_set_string(value, purple_theme_get_type_string(theme)); | |
| 89 break; | |
| 90 case PROP_DIR: | |
| 91 g_value_set_string(value, purple_theme_get_dir(theme)); | |
| 92 break; | |
| 93 case PROP_IMAGE: | |
| 94 g_value_set_string(value, purple_theme_get_image(theme)); | |
| 95 break; | |
| 96 default: | |
| 97 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec); | |
| 98 break; | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 static void | |
| 103 purple_theme_set_property(GObject *obj, guint param_id, const GValue *value, | |
| 104 GParamSpec *psec) | |
| 105 { | |
| 106 PurpleTheme *theme = PURPLE_THEME(obj); | |
| 107 | |
| 108 switch(param_id) { | |
| 109 case PROP_NAME: | |
| 110 purple_theme_set_name(theme, g_value_get_string(value)); | |
| 111 break; | |
| 112 case PROP_DESCRIPTION: | |
| 113 purple_theme_set_description(theme, g_value_get_string(value)); | |
| 114 break; | |
| 115 case PROP_AUTHOR: | |
| 116 purple_theme_set_author(theme, g_value_get_string(value)); | |
| 117 break; | |
| 118 case PROP_TYPE: | |
| 119 purple_theme_set_type_string(theme, g_value_get_string(value)); | |
| 120 break; | |
| 121 case PROP_DIR: | |
| 122 purple_theme_set_dir(theme, g_value_get_string(value)); | |
| 123 break; | |
| 124 case PROP_IMAGE: | |
| 125 purple_theme_set_image(theme, g_value_get_string(value)); | |
| 126 break; | |
| 127 default: | |
| 128 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec); | |
| 129 break; | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 static void | |
| 134 purple_theme_init(GTypeInstance *instance, | |
| 135 gpointer klass) | |
| 136 { | |
| 137 PurpleTheme *theme = PURPLE_THEME(instance); | |
| 138 theme->priv = g_new0(PurpleThemePrivate, 1); | |
| 139 } | |
| 140 | |
| 141 static void | |
| 142 purple_theme_finalize(GObject *obj) | |
| 143 { | |
| 144 PurpleTheme *theme = PURPLE_THEME(obj); | |
| 145 PurpleThemePrivate *priv = PURPLE_THEME_GET_PRIVATE(theme); | |
| 146 | |
| 147 g_free(priv->name); | |
| 148 g_free(priv->description); | |
| 149 g_free(priv->author); | |
| 150 g_free(priv->type); | |
| 151 g_free(priv->dir); | |
| 152 g_free(priv->img); | |
| 153 | |
| 154 G_OBJECT_CLASS (parent_class)->finalize (obj); | |
| 155 } | |
| 156 | |
| 157 static void | |
| 158 purple_theme_class_init (PurpleThemeClass *klass) | |
| 159 { | |
| 160 GObjectClass *obj_class = G_OBJECT_CLASS(klass); | |
| 161 GParamSpec *pspec; | |
| 162 | |
| 163 parent_class = g_type_class_peek_parent(klass); | |
| 164 | |
| 165 obj_class->get_property = purple_theme_get_property; | |
| 166 obj_class->set_property = purple_theme_set_property; | |
| 167 obj_class->finalize = purple_theme_finalize; | |
| 168 | |
| 169 /* NAME */ | |
| 170 pspec = g_param_spec_string("name", "Name", | |
| 171 "The name of the theme", | |
| 172 NULL, | |
| 173 G_PARAM_READWRITE | G_PARAM_CONSTRUCT); | |
| 174 g_object_class_install_property(obj_class, PROP_NAME, pspec); | |
| 175 | |
| 176 /* DESCRIPTION */ | |
| 177 pspec = g_param_spec_string("description", "Description", | |
| 178 "The description of the theme", | |
| 179 NULL, | |
| 180 G_PARAM_READWRITE | G_PARAM_CONSTRUCT); | |
| 181 g_object_class_install_property(obj_class, PROP_DESCRIPTION, pspec); | |
| 182 | |
| 183 /* AUTHOR */ | |
| 184 pspec = g_param_spec_string("author", "Author", | |
| 185 "The author of the theme", | |
| 186 NULL, | |
| 187 G_PARAM_READWRITE | G_PARAM_CONSTRUCT); | |
| 188 g_object_class_install_property(obj_class, PROP_AUTHOR, pspec); | |
| 189 | |
| 190 /* TYPE STRING (read only) */ | |
| 191 pspec = g_param_spec_string("type", "Type", | |
| 192 "The string represtenting the type of the theme", | |
| 193 NULL, | |
| 194 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); | |
| 195 g_object_class_install_property(obj_class, PROP_TYPE, pspec); | |
| 196 | |
| 197 /* DIRECTORY */ | |
| 198 pspec = g_param_spec_string("directory", "Directory", | |
| 199 "The directory that contains the theme and all its files", | |
| 200 NULL, | |
| 201 G_PARAM_READWRITE | G_PARAM_CONSTRUCT); | |
| 202 g_object_class_install_property(obj_class, PROP_DIR, pspec); | |
| 203 | |
| 204 /* PREVIEW IMAGE */ | |
| 205 pspec = g_param_spec_string("image", "Image", | |
| 206 "A preview image of the theme", | |
| 207 NULL, | |
| 208 G_PARAM_READWRITE); | |
| 209 g_object_class_install_property(obj_class, PROP_IMAGE, pspec); | |
| 210 } | |
| 211 | |
| 212 | |
| 213 GType | |
| 214 purple_theme_get_type (void) | |
| 215 { | |
| 216 static GType type = 0; | |
| 217 if (type == 0) { | |
| 218 static const GTypeInfo info = { | |
| 219 sizeof (PurpleThemeClass), | |
| 220 NULL, /* base_init */ | |
| 221 NULL, /* base_finalize */ | |
| 222 (GClassInitFunc)purple_theme_class_init, /* class_init */ | |
| 223 NULL, /* class_finalize */ | |
| 224 NULL, /* class_data */ | |
| 225 sizeof (PurpleTheme), | |
| 226 0, /* n_preallocs */ | |
| 227 purple_theme_init, /* instance_init */ | |
| 228 NULL, /* value table */ | |
| 229 }; | |
| 230 type = g_type_register_static (G_TYPE_OBJECT, | |
| 231 "PurpleTheme", | |
| 232 &info, G_TYPE_FLAG_ABSTRACT); | |
| 233 } | |
| 234 return type; | |
| 235 } | |
| 236 | |
| 237 /****************************************************************************** | |
| 238 * Helper Functions | |
| 239 *****************************************************************************/ | |
| 240 | |
| 241 static gchar* | |
| 242 theme_clean_text(const gchar *text) | |
| 243 { | |
| 244 gchar *clean_text = g_markup_escape_text(text, strlen(text)); | |
| 245 g_strdelimit(clean_text, "\n", ' '); | |
| 246 purple_str_strip_char(clean_text, '\r'); | |
| 247 return clean_text; | |
| 248 } | |
| 249 | |
| 250 /***************************************************************************** | |
| 251 * Public API functions | |
| 252 *****************************************************************************/ | |
| 253 | |
| 254 const gchar * | |
| 255 purple_theme_get_name(PurpleTheme *theme) | |
| 256 { | |
| 257 PurpleThemePrivate *priv; | |
| 258 | |
| 259 g_return_val_if_fail(PURPLE_IS_THEME(theme), NULL); | |
| 260 | |
| 261 priv = PURPLE_THEME_GET_PRIVATE(theme); | |
| 262 return priv->name; | |
| 263 } | |
| 264 | |
| 265 void | |
| 266 purple_theme_set_name(PurpleTheme *theme, const gchar *name) | |
| 267 { | |
| 268 PurpleThemePrivate *priv; | |
| 269 | |
| 270 g_return_if_fail(PURPLE_IS_THEME(theme)); | |
| 271 | |
| 272 priv = PURPLE_THEME_GET_PRIVATE(theme); | |
| 273 | |
| 274 g_free(priv->name); | |
| 275 priv->name = theme_clean_text(name); | |
| 276 } | |
| 277 | |
| 278 const gchar * | |
| 279 purple_theme_get_description(PurpleTheme *theme) | |
| 280 { | |
| 281 PurpleThemePrivate *priv; | |
| 282 | |
| 283 g_return_val_if_fail(PURPLE_IS_THEME(theme), NULL); | |
| 284 | |
| 285 priv = PURPLE_THEME_GET_PRIVATE(theme); | |
| 286 return priv->description; | |
| 287 } | |
| 288 | |
| 289 void | |
| 290 purple_theme_set_description(PurpleTheme *theme, const gchar *description) | |
| 291 { | |
| 292 PurpleThemePrivate *priv; | |
| 293 | |
| 294 g_return_if_fail(PURPLE_IS_THEME(theme)); | |
| 295 | |
| 296 priv = PURPLE_THEME_GET_PRIVATE(theme); | |
| 297 | |
| 298 g_free(priv->description); | |
| 299 priv->description = theme_clean_text(description); | |
| 300 } | |
| 301 | |
| 302 const gchar * | |
| 303 purple_theme_get_author(PurpleTheme *theme) | |
| 304 { | |
| 305 PurpleThemePrivate *priv; | |
| 306 | |
| 307 g_return_val_if_fail(PURPLE_IS_THEME(theme), NULL); | |
| 308 | |
| 309 priv = PURPLE_THEME_GET_PRIVATE(theme); | |
| 310 return priv->author; | |
| 311 } | |
| 312 | |
| 313 void | |
| 314 purple_theme_set_author(PurpleTheme *theme, const gchar *author) | |
| 315 { | |
| 316 PurpleThemePrivate *priv; | |
| 317 | |
| 318 g_return_if_fail(PURPLE_IS_THEME(theme)); | |
| 319 | |
| 320 priv = PURPLE_THEME_GET_PRIVATE(theme); | |
| 321 | |
| 322 g_free(priv->author); | |
| 323 priv->author = theme_clean_text(author); | |
| 324 } | |
| 325 | |
| 326 const gchar * | |
| 327 purple_theme_get_type_string(PurpleTheme *theme) | |
| 328 { | |
| 329 PurpleThemePrivate *priv; | |
| 330 | |
| 331 g_return_val_if_fail(PURPLE_IS_THEME(theme), NULL); | |
| 332 | |
| 333 priv = PURPLE_THEME_GET_PRIVATE(theme); | |
| 334 return priv->type; | |
| 335 } | |
| 336 | |
| 337 /* < private > */ | |
| 338 void | |
| 339 purple_theme_set_type_string(PurpleTheme *theme, const gchar *type) | |
| 340 { | |
| 341 PurpleThemePrivate *priv; | |
| 342 | |
| 343 g_return_if_fail(PURPLE_IS_THEME(theme)); | |
| 344 | |
| 345 priv = PURPLE_THEME_GET_PRIVATE(theme); | |
| 346 | |
| 347 g_free(priv->type); | |
| 348 priv->type = g_strdup(type); | |
| 349 } | |
| 350 | |
| 351 const gchar * | |
| 352 purple_theme_get_dir(PurpleTheme *theme) | |
| 353 { | |
| 354 PurpleThemePrivate *priv; | |
| 355 | |
| 356 g_return_val_if_fail(PURPLE_IS_THEME(theme), NULL); | |
| 357 | |
| 358 priv = PURPLE_THEME_GET_PRIVATE(theme); | |
| 359 return priv->dir; | |
| 360 } | |
| 361 | |
| 362 void | |
| 363 purple_theme_set_dir(PurpleTheme *theme, const gchar *dir) | |
| 364 { | |
| 365 PurpleThemePrivate *priv; | |
| 366 | |
| 367 g_return_if_fail(PURPLE_IS_THEME(theme)); | |
| 368 | |
| 369 priv = PURPLE_THEME_GET_PRIVATE(theme); | |
| 370 | |
| 371 g_free(priv->dir); | |
| 372 priv->dir = g_strdup(dir); | |
| 373 } | |
| 374 | |
| 375 const gchar * | |
| 376 purple_theme_get_image(PurpleTheme *theme) | |
| 377 { | |
| 378 PurpleThemePrivate *priv; | |
| 379 | |
| 380 g_return_val_if_fail(PURPLE_IS_THEME(theme), NULL); | |
| 381 | |
| 382 priv = PURPLE_THEME_GET_PRIVATE(theme); | |
| 383 | |
| 384 return priv->img; | |
| 385 } | |
| 386 | |
| 387 gchar * | |
| 388 purple_theme_get_image_full(PurpleTheme *theme) | |
| 389 { | |
| 390 const gchar *filename = purple_theme_get_image(theme); | |
| 391 | |
| 392 g_return_val_if_fail(filename, NULL); | |
| 393 | |
| 394 return g_build_filename(purple_theme_get_dir(PURPLE_THEME(theme)), filename, NULL); | |
| 395 } | |
| 396 | |
| 397 void | |
| 398 purple_theme_set_image(PurpleTheme *theme, const gchar *img) | |
| 399 { | |
| 400 PurpleThemePrivate *priv; | |
| 401 | |
| 402 g_return_if_fail(PURPLE_IS_THEME(theme)); | |
| 403 | |
| 404 priv = PURPLE_THEME_GET_PRIVATE(theme); | |
| 405 | |
| 406 g_free(priv->img); | |
| 407 priv->img = g_strdup(img); | |
| 408 } |
