Implement UI for icon and cursor themes.
[lxde/lxappearance.git] / src / lxappearance2.c
CommitLineData
0cd84ed6
HJYP
1/*
2 * lxappearance2.c
3 *
4 * Copyright 2010 PCMan <pcman.tw@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
22#ifdef HAVE_CONFIG_H
23#include <config.h>
24#endif
25
15c155a6
HJYP
26#include "lxappearance2.h"
27
0cd84ed6
HJYP
28#include <gtk/gtk.h>
29#include <glib/gi18n.h>
15c155a6
HJYP
30
31#include <X11/X.h>
32#include <X11/Xatom.h>
33#include <X11/Xlib.h>
34#include <gdk/gdkx.h>
35
0cd84ed6
HJYP
36#include "widget-theme.h"
37#include "icon-theme.h"
38#include "cursor-theme.h"
39
15c155a6
HJYP
40LXAppearance app = {0};
41
42Atom lxsession_atom = 0;
43
44static void check_lxsession()
45{
46 lxsession_atom = XInternAtom( GDK_DISPLAY(), "_LXSESSION", True );
47 if( lxsession_atom != None )
48 {
49 XGrabServer( GDK_DISPLAY() );
50 if( XGetSelectionOwner( GDK_DISPLAY(), lxsession_atom ) )
51 app.use_lxsession = TRUE;
52 XUngrabServer( GDK_DISPLAY() );
53 }
54}
55
0cd84ed6
HJYP
56static GOptionEntry option_entries[] =
57{
58 { NULL }
59};
60
15c155a6
HJYP
61static void lxappearance_save_gtkrc()
62{
63
64}
65
66static void lxappearance_save_lxsession()
67{
68
69}
70
71static void on_dlg_response(GtkDialog* dlg, int res, gpointer user_data)
72{
73 switch(res)
74 {
75 case GTK_RESPONSE_APPLY:
76
77 if(app.use_lxsession)
78 lxappearance_save_lxsession();
79 else
80 lxappearance_save_gtkrc();
81
82 app.changed = FALSE;
83 gtk_dialog_set_response_sensitive(app.dlg, GTK_RESPONSE_APPLY, FALSE);
84 break;
85 case 1: /* about dialog */
86 {
87 GtkBuilder* b = gtk_builder_new();
88 if(gtk_builder_add_from_file(b, PACKAGE_UI_DIR "/about.ui", NULL))
89 {
90 GtkWidget* dlg = GTK_WIDGET(gtk_builder_get_object(b, "dlg"));
91 gtk_dialog_run(dlg);
92 gtk_widget_destroy(dlg);
93 }
94 g_object_unref(b);
95 }
96 break;
97 default:
98 gtk_main_quit();
99 }
100}
101
102static void settings_init()
103{
104 g_object_get(gtk_settings_get_default(), "gtk-theme-name", &app.widget_theme, NULL);
105 g_object_get(gtk_settings_get_default(), "gtk-icon-theme-name", &app.icon_theme, NULL);
106
107 /* try to figure out cursor theme used. */
108 g_object_get(gtk_settings_get_default(), "gtk-cursor-theme-name", &app.cursor_theme, NULL);
109 if(!app.cursor_theme || g_strcmp0(app.cursor_theme, "default") == 0)
110 {
111 /* get the real theme name from default. */
112 GKeyFile* kf = g_key_file_new();
113 char* fpath = g_build_filename(g_get_home_dir(), ".icons/default/index.theme", NULL);
114 gboolean ret = g_key_file_load_from_file(kf, fpath, 0, NULL);
115 g_free(fpath);
116
117 if(!ret)
118 ret = g_key_file_load_from_data_dirs(kf, "icons/default/index.theme", NULL, 0, NULL);
119
120 if(ret)
121 {
122 app.cursor_theme = g_key_file_get_string(kf, "Icon Theme", "Inherits", NULL);
123 g_debug("cursor theme name: %s", app.cursor_theme);
124 }
125 g_key_file_free(kf);
126 }
127}
128
0cd84ed6
HJYP
129int main(int argc, char** argv)
130{
131 GError* err = NULL;
132 GtkBuilder* b;
0cd84ed6
HJYP
133
134 /* gettext support */
135#ifdef ENABLE_NLS
136 bindtextdomain ( GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR );
137 bind_textdomain_codeset ( GETTEXT_PACKAGE, "UTF-8" );
138 textdomain ( GETTEXT_PACKAGE );
139#endif
140
141 /* init threading support */
142 /*
143 g_thread_init(NULL);
144 gdk_threads_init();
145 */
146
147 /* initialize GTK+ and parse the command line arguments */
148 if( G_UNLIKELY( ! gtk_init_with_args( &argc, &argv, "", option_entries, GETTEXT_PACKAGE, &err ) ) )
149 {
150 g_print( "Error: %s\n", err->message );
151 return 1;
152 }
153
15c155a6
HJYP
154 /* check if we're under LXSession */
155 check_lxsession();
156
157 /* load config values */
158 settings_init();
159
0cd84ed6
HJYP
160 /* create GUI here */
161 b = gtk_builder_new();
162 if(!gtk_builder_add_from_file(b, PACKAGE_UI_DIR "/lxappearance.ui", NULL))
163 return 1;
164
165 widget_theme_init(b);
166 icon_theme_init(b);
167 cursor_theme_init(b);
168
15c155a6
HJYP
169 app.dlg = GTK_WIDGET(gtk_builder_get_object(b, "dlg"));
170 g_signal_connect(app.dlg, "response", G_CALLBACK(on_dlg_response), NULL);
0cd84ed6 171
15c155a6 172 gtk_window_present(GTK_WINDOW(app.dlg));
0cd84ed6
HJYP
173 g_object_unref(b);
174
175 gtk_main();
176
177 return 0;
178}
15c155a6
HJYP
179
180void lxappearance_changed()
181{
182 if(!app.changed)
183 {
184 app.changed = TRUE;
185 gtk_dialog_set_response_sensitive(app.dlg, GTK_RESPONSE_APPLY, TRUE);
186 }
187}