Fix some functions descriptions
[pidgin-git.git] / libpurple / theme-loader.c
blob6f9dd9b1be62fed42e5d1b705ea38f50797fece3
1 /*
2 * ThemeLoaders 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-loader.h"
27 #define PURPLE_THEME_LOADER_GET_PRIVATE(PurpleThemeLoader) \
28 (G_TYPE_INSTANCE_GET_PRIVATE((PurpleThemeLoader), PURPLE_TYPE_THEME_LOADER, PurpleThemeLoaderPrivate))
30 void purple_theme_loader_set_type_string(PurpleThemeLoader *loader, const gchar *type);
32 /******************************************************************************
33 * Structs
34 *****************************************************************************/
35 typedef struct {
36 gchar *type;
37 } PurpleThemeLoaderPrivate;
39 /******************************************************************************
40 * Enums
41 *****************************************************************************/
43 enum {
44 PROP_ZERO = 0,
45 PROP_TYPE,
46 PROP_LAST
49 /******************************************************************************
50 * Globals
51 *****************************************************************************/
53 static GObjectClass *parent_class = NULL;
54 static GParamSpec *properties[PROP_LAST];
56 /******************************************************************************
57 * GObject Stuff *
58 *****************************************************************************/
60 static void
61 purple_theme_loader_get_property(GObject *obj, guint param_id, GValue *value,
62 GParamSpec *psec)
64 PurpleThemeLoader *theme_loader = PURPLE_THEME_LOADER(obj);
66 switch (param_id) {
67 case PROP_TYPE:
68 g_value_set_string(value, purple_theme_loader_get_type_string(theme_loader));
69 break;
70 default:
71 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
72 break;
76 static void
77 purple_theme_loader_set_property(GObject *obj, guint param_id, const GValue *value,
78 GParamSpec *psec)
80 PurpleThemeLoader *loader = PURPLE_THEME_LOADER(obj);
82 switch (param_id) {
83 case PROP_TYPE:
84 purple_theme_loader_set_type_string(loader, g_value_get_string(value));
85 break;
86 default:
87 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
88 break;
92 static gboolean
93 purple_theme_loader_probe_directory(PurpleThemeLoader *loader, const gchar *dir)
95 const gchar *type = purple_theme_loader_get_type_string(loader);
96 char *themedir;
97 gboolean result;
99 /* Checks for directory as $root/purple/$type */
100 themedir = g_build_filename(dir, "purple", type, NULL);
101 result = g_file_test(themedir, G_FILE_TEST_IS_DIR);
102 g_free(themedir);
104 return result;
107 static void
108 purple_theme_loader_finalize(GObject *obj)
110 PurpleThemeLoader *loader = PURPLE_THEME_LOADER(obj);
111 PurpleThemeLoaderPrivate *priv = PURPLE_THEME_LOADER_GET_PRIVATE(loader);
113 g_free(priv->type);
115 parent_class->finalize(obj);
118 static void
119 purple_theme_loader_class_init(PurpleThemeLoaderClass *klass)
121 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
123 parent_class = g_type_class_peek_parent(klass);
125 g_type_class_add_private(klass, sizeof(PurpleThemeLoaderPrivate));
127 obj_class->get_property = purple_theme_loader_get_property;
128 obj_class->set_property = purple_theme_loader_set_property;
129 obj_class->finalize = purple_theme_loader_finalize;
131 /* TYPE STRING (read only) */
132 properties[PROP_TYPE] = g_param_spec_string("type", "Type",
133 "The string representing the type of the theme",
134 NULL,
135 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
136 G_PARAM_STATIC_STRINGS);
138 g_object_class_install_properties(obj_class, PROP_LAST, properties);
141 GType
142 purple_theme_loader_get_type(void)
144 static GType type = 0;
145 if (type == 0) {
146 static const GTypeInfo info = {
147 sizeof(PurpleThemeLoaderClass),
148 NULL, /* base_init */
149 NULL, /* base_finalize */
150 (GClassInitFunc)purple_theme_loader_class_init, /* class_init */
151 NULL, /* class_finalize */
152 NULL, /* class_data */
153 sizeof(PurpleThemeLoader),
154 0, /* n_preallocs */
155 NULL, /* instance_init */
156 NULL, /* value table */
158 type = g_type_register_static(G_TYPE_OBJECT,
159 "PurpleThemeLoader", &info, G_TYPE_FLAG_ABSTRACT);
161 return type;
164 /*****************************************************************************
165 * Public API functions
166 *****************************************************************************/
168 const gchar *
169 purple_theme_loader_get_type_string(PurpleThemeLoader *theme_loader)
171 PurpleThemeLoaderPrivate *priv = NULL;
173 g_return_val_if_fail(PURPLE_IS_THEME_LOADER(theme_loader), NULL);
175 priv = PURPLE_THEME_LOADER_GET_PRIVATE(theme_loader);
176 return priv->type;
179 /* < private > */
180 void
181 purple_theme_loader_set_type_string(PurpleThemeLoader *loader, const gchar *type)
183 PurpleThemeLoaderPrivate *priv;
185 g_return_if_fail(PURPLE_IS_THEME_LOADER(loader));
187 priv = PURPLE_THEME_LOADER_GET_PRIVATE(loader);
189 g_free(priv->type);
190 priv->type = g_strdup(type);
192 g_object_notify_by_pspec(G_OBJECT(loader), properties[PROP_TYPE]);
195 PurpleTheme *
196 purple_theme_loader_build(PurpleThemeLoader *loader, const gchar *dir)
198 return PURPLE_THEME_LOADER_GET_CLASS(loader)->purple_theme_loader_build(dir);
201 gboolean
202 purple_theme_loader_probe(PurpleThemeLoader *loader, const gchar *dir)
204 if (PURPLE_THEME_LOADER_GET_CLASS(loader)->probe_directory != NULL)
205 return PURPLE_THEME_LOADER_GET_CLASS(loader)->probe_directory(dir);
206 else
207 return purple_theme_loader_probe_directory(loader, dir);