~ubuntu-branches/ubuntu/dapper/xfce-mcs-plugins/dapper

« back to all changes in this revision

Viewing changes to plugins/gtk_common/gtk_common.c

  • Committer: Bazaar Package Importer
  • Author(s): Simon Huggins
  • Date: 2004-04-27 22:08:03 UTC
  • Revision ID: james.westby@ubuntu.com-20040427220803-vhxi3wkask9cku5d
Tags: upstream-4.0.5
ImportĀ upstreamĀ versionĀ 4.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
6
 
 
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.
 
11
 
 
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.
 
15
 
 
16
        from gnome theme-switcher capplet - (c) Jonathan Blandford <jrb@gnome.org>
 
17
 
 
18
 */
 
19
 
 
20
#ifdef HAVE_CONFIG_H
 
21
#include <config.h>
 
22
#endif
 
23
 
 
24
#ifdef HAVE_SYS_STAT_H
 
25
#include <sys/stat.h>
 
26
#endif
 
27
#ifdef HAVE_SYS_TYPES_H
 
28
#include <sys/types.h>
 
29
#endif
 
30
 
 
31
#ifdef HAVE_DIRENT_H
 
32
#include <dirent.h>
 
33
#endif
 
34
#ifdef HAVE_MEMORY_H
 
35
#include <memory.h>
 
36
#endif
 
37
#ifdef HAVE_STRING_H
 
38
#include <string.h>
 
39
#endif
 
40
#ifdef HAVE_UNISTD_H
 
41
#include <unistd.h>
 
42
#endif
 
43
 
 
44
#include <X11/Xlib.h>
 
45
 
 
46
#include <gtk/gtk.h>
 
47
 
 
48
#include <gtk_common.h>
 
49
 
 
50
#define SUFFIX      "gtk-2.0"
 
51
#define KEY_SUFFIX  "gtk-2.0-key"
 
52
 
 
53
static void
 
54
theme_info_free(ThemeInfo *info)
 
55
{
 
56
    g_free(info->path);
 
57
    g_free(info->name);
 
58
    g_free(info);
 
59
}
 
60
 
 
61
static ThemeInfo *
 
62
find_theme_info_by_name(const gchar *theme_name, GList *theme_list)
 
63
{
 
64
    GList *list;
 
65
 
 
66
    for (list = theme_list; list; list = list->next) {
 
67
        ThemeInfo *info = list->data;
 
68
 
 
69
        if (!strcmp(info->name, theme_name))
 
70
            return(info);
 
71
    }
 
72
 
 
73
    return(NULL);
 
74
}
 
75
 
 
76
static GList *
 
77
update_theme_dir(const gchar *theme_dir, GList *theme_list)
 
78
{
 
79
    ThemeInfo *info;
 
80
    gchar *theme_name;
 
81
    gboolean has_gtk;
 
82
    gboolean has_keybinding;
 
83
    gchar *tmp;
 
84
 
 
85
    tmp = g_build_filename(theme_dir, SUFFIX, NULL);
 
86
    has_gtk = g_file_test(tmp, G_FILE_TEST_IS_DIR);
 
87
    g_free(tmp);
 
88
 
 
89
    tmp = g_build_filename(theme_dir, KEY_SUFFIX, NULL);
 
90
    has_keybinding = g_file_test(tmp, G_FILE_TEST_IS_DIR);
 
91
    g_free(tmp);
 
92
 
 
93
    theme_name = g_strdup(strrchr(theme_dir, G_DIR_SEPARATOR) + 1);
 
94
    info = find_theme_info_by_name(theme_name, theme_list);
 
95
 
 
96
    if (info) {
 
97
        if(!has_gtk && !has_keybinding) {
 
98
            theme_list = g_list_remove(theme_list, info);
 
99
            theme_info_free(info);
 
100
        }
 
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;
 
105
        }
 
106
    }
 
107
    else {
 
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;
 
114
 
 
115
            theme_list = g_list_prepend(theme_list, info);
 
116
        }
 
117
    }
 
118
 
 
119
    g_free(theme_name);
 
120
    
 
121
    return(theme_list);
 
122
}
 
123
 
 
124
static GList *
 
125
themes_common_list_add_dir(const gchar *dirname, GList *theme_list)
 
126
{
 
127
#ifdef HAVE_OPENDIR
 
128
    struct dirent *de;
 
129
    gchar *tmp;
 
130
    DIR *dir;
 
131
 
 
132
    g_return_val_if_fail(dirname != NULL, theme_list);
 
133
 
 
134
    if ((dir = opendir(dirname)) != NULL) {
 
135
        while((de = readdir(dir))) {
 
136
            if (de->d_name[0] == '.')
 
137
                continue;
 
138
 
 
139
            tmp = g_build_filename(dirname, de->d_name, NULL);
 
140
            theme_list = update_theme_dir(tmp, theme_list);
 
141
            g_free(tmp);
 
142
        }
 
143
 
 
144
        closedir(dir);
 
145
    }
 
146
#endif
 
147
 
 
148
    return(theme_list);
 
149
}
 
150
 
 
151
 
 
152
GList *
 
153
theme_common_get_list(GList *theme_list)
 
154
{
 
155
    gchar *dir;
 
156
 
 
157
    dir = g_build_filename(g_get_home_dir(), ".themes", NULL);
 
158
    theme_list = themes_common_list_add_dir(dir, theme_list);
 
159
    g_free(dir);
 
160
 
 
161
    dir = g_build_filename(g_get_home_dir(), ".themes-gtk2.0", NULL);
 
162
    theme_list = themes_common_list_add_dir(dir, theme_list);
 
163
    g_free(dir);
 
164
 
 
165
    dir = gtk_rc_get_theme_dir();
 
166
    theme_list = themes_common_list_add_dir(dir, theme_list);
 
167
    g_free(dir);
 
168
 
 
169
    return(theme_list);
 
170
}