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
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"
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 /******************************************************************************
34 *****************************************************************************/
37 } PurpleThemeLoaderPrivate
;
39 /******************************************************************************
41 *****************************************************************************/
49 /******************************************************************************
51 *****************************************************************************/
53 static GObjectClass
*parent_class
= NULL
;
54 static GParamSpec
*properties
[PROP_LAST
];
56 /******************************************************************************
58 *****************************************************************************/
61 purple_theme_loader_get_property(GObject
*obj
, guint param_id
, GValue
*value
,
64 PurpleThemeLoader
*theme_loader
= PURPLE_THEME_LOADER(obj
);
68 g_value_set_string(value
, purple_theme_loader_get_type_string(theme_loader
));
71 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, psec
);
77 purple_theme_loader_set_property(GObject
*obj
, guint param_id
, const GValue
*value
,
80 PurpleThemeLoader
*loader
= PURPLE_THEME_LOADER(obj
);
84 purple_theme_loader_set_type_string(loader
, g_value_get_string(value
));
87 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, psec
);
93 purple_theme_loader_probe_directory(PurpleThemeLoader
*loader
, const gchar
*dir
)
95 const gchar
*type
= purple_theme_loader_get_type_string(loader
);
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
);
108 purple_theme_loader_finalize(GObject
*obj
)
110 PurpleThemeLoader
*loader
= PURPLE_THEME_LOADER(obj
);
111 PurpleThemeLoaderPrivate
*priv
= PURPLE_THEME_LOADER_GET_PRIVATE(loader
);
115 parent_class
->finalize(obj
);
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",
135 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
|
136 G_PARAM_STATIC_STRINGS
);
138 g_object_class_install_properties(obj_class
, PROP_LAST
, properties
);
142 purple_theme_loader_get_type(void)
144 static GType 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
),
155 NULL
, /* instance_init */
156 NULL
, /* value table */
158 type
= g_type_register_static(G_TYPE_OBJECT
,
159 "PurpleThemeLoader", &info
, G_TYPE_FLAG_ABSTRACT
);
164 /*****************************************************************************
165 * Public API functions
166 *****************************************************************************/
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
);
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
);
190 priv
->type
= g_strdup(type
);
192 g_object_notify_by_pspec(G_OBJECT(loader
), properties
[PROP_TYPE
]);
196 purple_theme_loader_build(PurpleThemeLoader
*loader
, const gchar
*dir
)
198 return PURPLE_THEME_LOADER_GET_CLASS(loader
)->purple_theme_loader_build(dir
);
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
);
207 return purple_theme_loader_probe_directory(loader
, dir
);