2
This program is free software; you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation; You may only use version 2 of the License,
5
you have no option to use any other version.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
from gnome theme-switcher capplet - (c) Jonathan Blandford <jrb@gnome.org>
24
#ifdef HAVE_SYS_STAT_H
27
#ifdef HAVE_SYS_TYPES_H
28
#include <sys/types.h>
48
#include <gtk_common.h>
50
#define SUFFIX "gtk-2.0"
51
#define KEY_SUFFIX "gtk-2.0-key"
54
theme_info_free(ThemeInfo *info)
62
find_theme_info_by_name(const gchar *theme_name, GList *theme_list)
66
for (list = theme_list; list; list = list->next) {
67
ThemeInfo *info = list->data;
69
if (!strcmp(info->name, theme_name))
77
update_theme_dir(const gchar *theme_dir, GList *theme_list)
82
gboolean has_keybinding;
85
tmp = g_build_filename(theme_dir, SUFFIX, NULL);
86
has_gtk = g_file_test(tmp, G_FILE_TEST_IS_DIR);
89
tmp = g_build_filename(theme_dir, KEY_SUFFIX, NULL);
90
has_keybinding = g_file_test(tmp, G_FILE_TEST_IS_DIR);
93
theme_name = g_strdup(strrchr(theme_dir, G_DIR_SEPARATOR) + 1);
94
info = find_theme_info_by_name(theme_name, theme_list);
97
if(!has_gtk && !has_keybinding) {
98
theme_list = g_list_remove(theme_list, info);
99
theme_info_free(info);
101
else if ((info->has_keybinding != has_keybinding) ||
102
(info->has_gtk != has_gtk)) {
103
info->has_keybinding = has_keybinding;
104
info->has_gtk = has_gtk;
108
if (has_gtk || has_keybinding) {
109
info = g_new0(ThemeInfo, 1);
110
info->path = g_strdup(theme_dir);
111
info->name = g_strdup(theme_name);
112
info->has_gtk = has_gtk;
113
info->has_keybinding = has_keybinding;
115
theme_list = g_list_prepend(theme_list, info);
125
themes_common_list_add_dir(const gchar *dirname, GList *theme_list)
132
g_return_val_if_fail(dirname != NULL, theme_list);
134
if ((dir = opendir(dirname)) != NULL) {
135
while((de = readdir(dir))) {
136
if (de->d_name[0] == '.')
139
tmp = g_build_filename(dirname, de->d_name, NULL);
140
theme_list = update_theme_dir(tmp, theme_list);
153
theme_common_get_list(GList *theme_list)
157
dir = g_build_filename(g_get_home_dir(), ".themes", NULL);
158
theme_list = themes_common_list_add_dir(dir, theme_list);
161
dir = g_build_filename(g_get_home_dir(), ".themes-gtk2.0", NULL);
162
theme_list = themes_common_list_add_dir(dir, theme_list);
165
dir = gtk_rc_get_theme_dir();
166
theme_list = themes_common_list_add_dir(dir, theme_list);