Implement UI for icon and cursor 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;
41}
42
43/* check if current gtk+ widget theme supports color schemes */
44void color_scheme_update()
45{
46 gboolean supported = FALSE;
47 if(app.widget_theme)
48 {
49 gboolean file_found;
50 char* gtkrc = g_build_filename(g_get_home_dir(), ".themes", app.widget_theme, "gtk-2.0/gtkrc", NULL);
51 file_found = gtkrc_supports_colors(gtkrc, &supported);
52 g_free(gtkrc);
53
54 if(!file_found)
55 {
56 gtkrc = g_build_filename(gtk_rc_get_theme_dir(), app.widget_theme, "gtk-2.0/gtkrc", NULL);
57 gtkrc_supports_colors(gtkrc, &supported);
58 g_free(gtkrc);
59 }
60 }
61
62 g_free(app.color_scheme);
63 if(supported)
64 {
65 g_object_get(gtk_settings_get_default(), "gtk-color-scheme", &app.color_scheme, NULL);
66 g_debug("color-scheme: %s", app.color_scheme);
67 //gtk_widget_set_sensitive(, TRUE);
68 }
69 else
70 {
71 app.color_scheme = NULL;
72 //gtk_widget_set_sensitive(, FALSE);
73 g_debug("color-scheme is not supported by this theme");
74 }
75}
76