Support removing installed themes.
[lxde/lxappearance.git] / src / color-scheme.c
CommitLineData
15c155a6
HJYP
1// color-scheme.c
2//
3// Copyright 2010 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18// MA 02110-1301, USA.
19
20#include "lxappearance2.h"
21#include "color-scheme.h"
22#include <string.h>
23
24void color_scheme_init()
25{
26 color_scheme_update();
27}
28
29static gboolean gtkrc_supports_colors(const char* gtkrc_file, gboolean* support)
30{
31 char* content;
32 gboolean support_colors = FALSE;
33 if(g_file_get_contents(gtkrc_file, &content, NULL, NULL))
34 {
35 /* FIXME: check included gtkrc files, too. */
36 if(strstr(content, "gtk-color-scheme"))
37 support_colors = TRUE;
38 g_free(content);
39 }
40 *support = support_colors;
d023f0a4
AF
41
42 return TRUE;
15c155a6
HJYP
43}
44
45/* check if current gtk+ widget theme supports color schemes */
46void color_scheme_update()
47{
48 gboolean supported = FALSE;
49 if(app.widget_theme)
50 {
51 gboolean file_found;
52 char* gtkrc = g_build_filename(g_get_home_dir(), ".themes", app.widget_theme, "gtk-2.0/gtkrc", NULL);
53 file_found = gtkrc_supports_colors(gtkrc, &supported);
54 g_free(gtkrc);
55
56 if(!file_found)
57 {
58 gtkrc = g_build_filename(gtk_rc_get_theme_dir(), app.widget_theme, "gtk-2.0/gtkrc", NULL);
59 gtkrc_supports_colors(gtkrc, &supported);
60 g_free(gtkrc);
61 }
62 }
63
64 g_free(app.color_scheme);
65 if(supported)
66 {
67 g_object_get(gtk_settings_get_default(), "gtk-color-scheme", &app.color_scheme, NULL);
68 g_debug("color-scheme: %s", app.color_scheme);
69 //gtk_widget_set_sensitive(, TRUE);
70 }
71 else
72 {
73 app.color_scheme = NULL;
74 //gtk_widget_set_sensitive(, FALSE);
75 g_debug("color-scheme is not supported by this theme");
76 }
77}
78