Use correct memory functions for GG oauth.
[pidgin-git.git] / libpurple / theme-loader.c
blobf0babab4f9abb9014011ee668fcf10adf7a3f372
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 void purple_theme_loader_set_type_string(PurpleThemeLoader *loader, const gchar *type);
29 /******************************************************************************
30 * Structs
31 *****************************************************************************/
32 typedef struct {
33 gchar *type;
34 } PurpleThemeLoaderPrivate;
36 /******************************************************************************
37 * Enums
38 *****************************************************************************/
40 enum {
41 PROP_ZERO = 0,
42 PROP_TYPE,
43 PROP_LAST
46 /******************************************************************************
47 * Globals
48 *****************************************************************************/
50 static GParamSpec *properties[PROP_LAST];
52 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(PurpleThemeLoader, purple_theme_loader,
53 G_TYPE_OBJECT);
55 /******************************************************************************
56 * GObject Stuff *
57 *****************************************************************************/
59 static void
60 purple_theme_loader_get_property(GObject *obj, guint param_id, GValue *value,
61 GParamSpec *psec)
63 PurpleThemeLoader *theme_loader = PURPLE_THEME_LOADER(obj);
65 switch (param_id) {
66 case PROP_TYPE:
67 g_value_set_string(value, purple_theme_loader_get_type_string(theme_loader));
68 break;
69 default:
70 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
71 break;
75 static void
76 purple_theme_loader_set_property(GObject *obj, guint param_id, const GValue *value,
77 GParamSpec *psec)
79 PurpleThemeLoader *loader = PURPLE_THEME_LOADER(obj);
81 switch (param_id) {
82 case PROP_TYPE:
83 purple_theme_loader_set_type_string(loader, g_value_get_string(value));
84 break;
85 default:
86 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
87 break;
91 static gboolean
92 purple_theme_loader_probe_directory(PurpleThemeLoader *loader, const gchar *dir)
94 const gchar *type = purple_theme_loader_get_type_string(loader);
95 char *themedir;
96 gboolean result;
98 /* Checks for directory as $root/purple/$type */
99 themedir = g_build_filename(dir, "purple", type, NULL);
100 result = g_file_test(themedir, G_FILE_TEST_IS_DIR);
101 g_free(themedir);
103 return result;
106 static void
107 purple_theme_loader_init(PurpleThemeLoader *loader)
111 static void
112 purple_theme_loader_finalize(GObject *obj)
114 PurpleThemeLoader *loader = PURPLE_THEME_LOADER(obj);
115 PurpleThemeLoaderPrivate *priv =
116 purple_theme_loader_get_instance_private(loader);
118 g_free(priv->type);
120 G_OBJECT_CLASS(purple_theme_loader_parent_class)->finalize(obj);
123 static void
124 purple_theme_loader_class_init(PurpleThemeLoaderClass *klass)
126 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
128 obj_class->get_property = purple_theme_loader_get_property;
129 obj_class->set_property = purple_theme_loader_set_property;
130 obj_class->finalize = purple_theme_loader_finalize;
132 /* TYPE STRING (read only) */
133 properties[PROP_TYPE] = g_param_spec_string("type", "Type",
134 "The string representing the type of the theme",
135 NULL,
136 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
137 G_PARAM_STATIC_STRINGS);
139 g_object_class_install_properties(obj_class, PROP_LAST, properties);
142 /*****************************************************************************
143 * Public API functions
144 *****************************************************************************/
146 const gchar *
147 purple_theme_loader_get_type_string(PurpleThemeLoader *theme_loader)
149 PurpleThemeLoaderPrivate *priv = NULL;
151 g_return_val_if_fail(PURPLE_IS_THEME_LOADER(theme_loader), NULL);
153 priv = purple_theme_loader_get_instance_private(theme_loader);
154 return priv->type;
157 /* < private > */
158 void
159 purple_theme_loader_set_type_string(PurpleThemeLoader *loader, const gchar *type)
161 PurpleThemeLoaderPrivate *priv;
163 g_return_if_fail(PURPLE_IS_THEME_LOADER(loader));
165 priv = purple_theme_loader_get_instance_private(loader);
167 g_free(priv->type);
168 priv->type = g_strdup(type);
170 g_object_notify_by_pspec(G_OBJECT(loader), properties[PROP_TYPE]);
173 PurpleTheme *
174 purple_theme_loader_build(PurpleThemeLoader *loader, const gchar *dir)
176 return PURPLE_THEME_LOADER_GET_CLASS(loader)->purple_theme_loader_build(dir);
179 gboolean
180 purple_theme_loader_probe(PurpleThemeLoader *loader, const gchar *dir)
182 if (PURPLE_THEME_LOADER_GET_CLASS(loader)->probe_directory != NULL)
183 return PURPLE_THEME_LOADER_GET_CLASS(loader)->probe_directory(dir);
184 else
185 return purple_theme_loader_probe_directory(loader, dir);