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 void purple_theme_set_type_string(PurpleTheme
*theme
, const gchar
*type
);
30 /******************************************************************************
32 *****************************************************************************/
43 /******************************************************************************
45 *****************************************************************************/
58 /******************************************************************************
60 *****************************************************************************/
62 static GParamSpec
*properties
[PROP_LAST
];
64 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(PurpleTheme
, purple_theme
, G_TYPE_OBJECT
);
66 /******************************************************************************
68 *****************************************************************************/
71 purple_theme_get_property(GObject
*obj
, guint param_id
, GValue
*value
,
74 PurpleTheme
*theme
= PURPLE_THEME(obj
);
78 g_value_set_string(value
, purple_theme_get_name(theme
));
80 case PROP_DESCRIPTION
:
81 g_value_set_string(value
, purple_theme_get_description(theme
));
84 g_value_set_string(value
, purple_theme_get_author(theme
));
87 g_value_set_string(value
, purple_theme_get_type_string(theme
));
90 g_value_set_string(value
, purple_theme_get_dir(theme
));
93 g_value_set_string(value
, purple_theme_get_image(theme
));
96 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, psec
);
102 purple_theme_set_property(GObject
*obj
, guint param_id
, const GValue
*value
,
105 PurpleTheme
*theme
= PURPLE_THEME(obj
);
109 purple_theme_set_name(theme
, g_value_get_string(value
));
111 case PROP_DESCRIPTION
:
112 purple_theme_set_description(theme
, g_value_get_string(value
));
115 purple_theme_set_author(theme
, g_value_get_string(value
));
118 purple_theme_set_type_string(theme
, g_value_get_string(value
));
121 purple_theme_set_dir(theme
, g_value_get_string(value
));
124 purple_theme_set_image(theme
, g_value_get_string(value
));
127 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, psec
);
133 purple_theme_init(PurpleTheme
*theme
)
138 purple_theme_finalize(GObject
*obj
)
140 PurpleTheme
*theme
= PURPLE_THEME(obj
);
141 PurpleThemePrivate
*priv
= purple_theme_get_instance_private(theme
);
144 g_free(priv
->description
);
145 g_free(priv
->author
);
150 G_OBJECT_CLASS(purple_theme_parent_class
)->finalize(obj
);
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
;
163 properties
[PROP_NAME
] = g_param_spec_string("name", "Name",
164 "The name of the theme",
166 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
| G_PARAM_STATIC_STRINGS
);
169 properties
[PROP_DESCRIPTION
] = g_param_spec_string("description",
171 "The description of the theme",
173 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
| G_PARAM_STATIC_STRINGS
);
176 properties
[PROP_AUTHOR
] = g_param_spec_string("author", "Author",
177 "The author of the theme",
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",
185 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
|
186 G_PARAM_STATIC_STRINGS
);
189 properties
[PROP_DIR
] = g_param_spec_string("directory", "Directory",
190 "The directory that contains the theme and all its files",
192 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
| G_PARAM_STATIC_STRINGS
);
195 properties
[PROP_IMAGE
] = g_param_spec_string("image", "Image",
196 "A preview image of the theme",
198 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
);
200 g_object_class_install_properties(obj_class
, PROP_LAST
, properties
);
203 /******************************************************************************
205 *****************************************************************************/
208 theme_clean_text(const gchar
*text
)
210 gchar
*clean_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');
219 /*****************************************************************************
220 * Public API function
221 *****************************************************************************/
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
);
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
);
244 priv
->name
= theme_clean_text(name
);
246 g_object_notify_by_pspec(G_OBJECT(theme
), properties
[PROP_NAME
]);
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
;
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
]);
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
);
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
]);
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
);
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
);
323 priv
->type
= g_strdup(type
);
325 g_object_notify_by_pspec(G_OBJECT(theme
), properties
[PROP_TYPE
]);
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
);
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
);
349 priv
->dir
= g_strdup(dir
);
351 g_object_notify_by_pspec(G_OBJECT(theme
), properties
[PROP_DIR
]);
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
);
367 purple_theme_get_image_full(PurpleTheme
*theme
)
369 const gchar
*filename
= purple_theme_get_image(theme
);
372 return g_build_filename(purple_theme_get_dir(PURPLE_THEME(theme
)), filename
, NULL
);
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
);
387 priv
->img
= g_strdup(img
);
389 g_object_notify_by_pspec(G_OBJECT(theme
), properties
[PROP_IMAGE
]);