Adding upstream version 0.3.0+svn20091218.
[debian/lxappearance.git] / src / main-dlg.c
CommitLineData
08024023
DB
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <gtk/gtk.h>
6#include <gdk/gdkx.h>
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <unistd.h>
11#include <string.h>
12
13/* for kill & waitpid */
14#include <sys/types.h>
15#include <signal.h>
16#include <sys/wait.h>
17
18#include "main-dlg.h"
19#include "main-dlg-ui.h"
20#include "glade-support.h"
21
bd2899cf
DB
22enum {
23 COL_DISP_NAME,
24 COL_NAME,
25 N_COLS
26};
27
28#define GET_WIDGET_WITH_TYPE(name, type) name = type( lookup_widget( dlg, #name ))
08024023
DB
29
30#define INIT_LIST(name, prop) \
bd2899cf
DB
31 GET_WIDGET_WITH_TYPE( name##_view, GTK_TREE_VIEW ); \
32 name##_list = init_tree_view( name##_view, G_CALLBACK(on_list_sel_changed), prop); \
08024023
DB
33 load_##name##s( name##_list, name##_name );
34
bd2899cf
DB
35#define enable_apply() gtk_dialog_set_response_sensitive(GTK_DIALOG (main_dlg), GTK_RESPONSE_APPLY, TRUE )
36#define disable_apply() gtk_dialog_set_response_sensitive(GTK_DIALOG (main_dlg), GTK_RESPONSE_APPLY, FALSE )
08024023 37
13f1ec51 38extern gboolean under_lxsession; /* wether we are under lxsession */
08024023
DB
39
40extern GtkWidget* main_dlg; /* defined in main.c */
41
42static GtkTreeView* gtk_theme_view = NULL;
43static GtkListStore* gtk_theme_list = NULL;
44
45static GtkTreeView* icon_theme_view = NULL;
46static GtkListStore* icon_theme_list = NULL;
47
7fbfd5a0 48#if CURSOR_THEME
13f1ec51
DB
49static GtkTreeView* cursor_theme_view = NULL;
50static GtkListStore* cursor_theme_list = NULL;
7fbfd5a0 51#endif
13f1ec51 52
08024023
DB
53static char* gtk_theme_name = NULL;
54static char* icon_theme_name = NULL;
55static char* font_name = NULL;
13f1ec51
DB
56static char* cursor_theme_name = NULL;
57static gint cursor_theme_size = 0;
08024023
DB
58static GtkToolbarStyle tb_style = GTK_TOOLBAR_BOTH;
59
60extern char tmp_rc_file[];
61static char* rc_file = NULL;
62
63/*
64static GtkTreeView* font_view = NULL;
65static GtkListStore* font_list = NULL;
66*/
67static GtkWidget* demo_box = NULL;
68static GtkWidget* demo_socket = NULL;
69static GPid demo_pid = 0;
70
13f1ec51 71static const char* session_name = NULL;
08024023 72
13f1ec51 73extern Atom lxsession_atom; /* defined in main.c */
08024023
DB
74
75static void reload_demo_process()
76{
77 char* argv[5];
78 char wid[16];
79
80 if( demo_pid > 0 ) /* kill old demo */
81 {
82 int stat;
83 kill( demo_pid, SIGTERM );
84 waitpid( demo_pid, &stat, 0 );
85 demo_pid = 0;
86 }
87
bd2899cf 88 g_snprintf( wid, 16, "%ld", gtk_socket_get_id(GTK_SOCKET (demo_socket)) );
08024023
DB
89
90 argv[0] = g_get_prgname();
91 argv[1] = "demo";
92 argv[2] = wid;
93 argv[3] = tmp_rc_file;
94 argv[4] = NULL;
95 g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &demo_pid, NULL );
96
97 /* reloading demo means the current selected theme is changed */
98 enable_apply();
99}
100
101static void write_rc_file( const char* path )
102{
103 FILE* f;
104 static char* tb_styles[] = {
105 "GTK_TOOLBAR_ICONS",
106 "GTK_TOOLBAR_TEXT",
107 "GTK_TOOLBAR_BOTH",
108 "GTK_TOOLBAR_BOTH_HORIZ"
109 };
110
111 if( f = fopen( path, "w" ) )
112 {
113 fputs( "# DO NOT EDIT! This file will be overwritten by LXAppearance.\n"
114 "# Any customization should be done in ~/.gtkrc-2.0.mine\n\n", f );
115
116 fprintf( f, "gtk-theme-name=\"%s\"\n", gtk_theme_name );
117 fprintf( f, "gtk-icon-theme-name=\"%s\"\n", icon_theme_name );
118 fprintf( f, "gtk-font-name=\"%s\"\n", font_name );
119 fprintf( f, "gtk-toolbar-style=%d\n", tb_style );
13f1ec51
DB
120 fprintf( f, "gtk-cursor-theme-name=\"%s\"\n", cursor_theme_name );
121 fprintf( f, "gtk-cursor-theme-size=%d\n", cursor_theme_size );
08024023
DB
122
123 fprintf( f, "include \"%s/.gtkrc-2.0.mine\"\n", g_get_home_dir() );
124
125 fclose( f );
126 }
127}
128
13f1ec51 129static void create_lxsession_config_dir()
08024023 130{
13f1ec51 131 char* dir = g_build_filename( g_get_user_config_dir(), "lxsession", session_name, NULL );
08024023 132 g_mkdir_with_parents( dir, 0755 );
08024023
DB
133 g_free( dir );
134}
135
13f1ec51 136static void write_lxsession_config()
08024023
DB
137{
138 FILE* f;
13f1ec51
DB
139 char* file, *data;
140 gsize len;
141 GKeyFile* kf = g_key_file_new();
142 gboolean ret;
08024023 143
13f1ec51
DB
144 file = g_build_filename( g_get_user_config_dir(), "lxsession", session_name, "desktop.conf", NULL );
145 ret = g_key_file_load_from_file( kf, file, G_KEY_FILE_KEEP_COMMENTS, NULL );
08024023 146
13f1ec51
DB
147 if( ! ret )
148 {
149 const gchar* const * dir;
150 const gchar* const * dirs = g_get_system_config_dirs();
151 create_lxsession_config_dir();
152
153 /* load system-wide config file */
154 for( dir = dirs; *dir; ++dir )
155 {
156 char* path = g_build_filename( *dir, "lxsession", session_name, "desktop.conf", NULL );
157 ret = g_key_file_load_from_file( kf, path, G_KEY_FILE_KEEP_COMMENTS, NULL );
158 g_free( path );
159 if( ret )
160 break;
161 }
162 }
08024023 163
13f1ec51
DB
164 g_key_file_set_string( kf, "GTK", "sNet/ThemeName", gtk_theme_name );
165 g_key_file_set_string( kf, "GTK", "sNet/IconThemeName", icon_theme_name );
166 g_key_file_set_string( kf, "GTK", "sGtk/FontName", font_name );
167 g_key_file_set_integer( kf, "GTK", "iGtk/ToolbarStyle", tb_style );
168 g_key_file_set_string( kf, "GTK", "sGtk/CursorThemeName", cursor_theme_name );
169 g_key_file_set_integer( kf, "GTK", "iGtk/CursorThemeSize", cursor_theme_size );
08024023 170
13f1ec51
DB
171 data = g_key_file_to_data( kf, &len, NULL );
172 g_key_file_free( kf );
08024023
DB
173
174 if( f = fopen( file, "w" ) )
175 {
176 fwrite( data, sizeof(char), len, f );
177 fclose( f );
178 }
179 g_free( data );
180}
181
182static void reload_theme()
183{
184
185 gtk_rc_reparse_all();
186}
187
188static void on_list_sel_changed( GtkTreeSelection* sel, const char* prop )
189{
190 GtkTreeIter it;
191 GtkTreeModel* model;
192 if( gtk_tree_selection_get_selected( sel, &model, &it ) )
193 {
194 char* name;
bd2899cf 195 gtk_tree_model_get( model, &it, COL_NAME, &name, -1 );
08024023 196
bd2899cf 197 if( model == GTK_TREE_MODEL (gtk_theme_list) ) /* gtk+ theme */
08024023
DB
198 {
199 if( name && gtk_theme_name && 0 == strcmp( name, gtk_theme_name ) )
200 goto out;
201 g_free( gtk_theme_name );
202 gtk_theme_name = name;
203
13f1ec51 204 if( under_lxsession )
08024023
DB
205 g_object_set( gtk_settings_get_default(), "gtk-theme-name", name, NULL );
206 }
bd2899cf 207 else if( model == GTK_TREE_MODEL (icon_theme_list) ) /* icon theme */
08024023
DB
208 {
209 if( name && icon_theme_name && 0 == strcmp( name, icon_theme_name ) )
210 goto out;
211 g_free( icon_theme_name );
212 icon_theme_name = name;
213
13f1ec51 214 if( under_lxsession )
08024023
DB
215 g_object_set( gtk_settings_get_default(), "gtk-icon-theme-name", name, NULL );
216 }
7fbfd5a0 217#if CURSOR_THEME
13f1ec51
DB
218 else if( model == GTK_TREE_MODEL (cursor_theme_list) ) /* cursor theme */
219 {
220 if( name && cursor_theme_name && 0 == strcmp( name, cursor_theme_name ) )
221 goto out;
222 g_free( cursor_theme_name );
223 cursor_theme_name = g_strdup(name);
224 //gdk_x11_display_set_cursor_theme ( gdk_display_get_default (), name, cursor_theme_size );
08024023 225
13f1ec51
DB
226 if( under_lxsession )
227 g_object_set( gtk_settings_get_default(), "gtk-cursor-theme-name", name, NULL );
228 }
7fbfd5a0 229#endif
13f1ec51
DB
230
231 if( under_lxsession )
bd2899cf
DB
232 {
233 enable_apply();
234 }
235 else
236 {
237 write_rc_file( tmp_rc_file );
238 //gtk_rc_reparse_all_for_settings(gtk_settings_get_default(), TRUE);
239 reload_demo_process();
240 }
08024023
DB
241 return;
242 out:
243 g_free( name );
244 }
245}
246
247static gint sort_func( GtkTreeModel* model, GtkTreeIter* it1, GtkTreeIter* it2, gpointer data )
248{
249 char* str1, *str2;
250 int ret;
bd2899cf
DB
251 gtk_tree_model_get( model, it1, COL_DISP_NAME, &str1, -1 );
252 gtk_tree_model_get( model, it2, COL_DISP_NAME, &str2, -1 );
253 ret = g_utf8_collate( str1, str2 );
08024023
DB
254 g_free( str1 );
255 g_free( str2 );
256 return ret;
257}
258
259static GtkListStore* init_tree_view( GtkTreeView* view, GCallback on_sel_changed, const char* prop )
260{
261 GtkTreeViewColumn* col;
262 GtkListStore* list;
263 GtkTreeSelection* sel;
13f1ec51 264 int text_col = strcmp(prop, "gtk-theme-name") && strcmp(prop, "gtk-cursor-theme-name") ? COL_DISP_NAME : COL_NAME;
bd2899cf
DB
265
266 col = gtk_tree_view_column_new_with_attributes( NULL, gtk_cell_renderer_text_new(),
267 "text", text_col, NULL );
08024023 268 gtk_tree_view_append_column( view, col );
bd2899cf 269
08024023 270 sel = gtk_tree_view_get_selection(view);
bd2899cf 271 g_signal_connect( sel, "changed", on_sel_changed, GINT_TO_POINTER(prop) );
08024023 272
bd2899cf
DB
273 list = gtk_list_store_new( N_COLS, G_TYPE_STRING, G_TYPE_STRING );
274 gtk_tree_sortable_set_sort_func( (GtkTreeSortable*)list, text_col, sort_func, NULL, NULL );
08024023
DB
275 gtk_tree_view_set_model( view, (GtkTreeModel*)list );
276 g_object_unref( list );
277 return list;
278}
279
bd2899cf
DB
280typedef gboolean (*ThemeFunc)(const char* file, const char* dir, const char* name, GtkListStore* list, GtkTreeIter* it);
281
08024023 282static void load_themes_from_dir( GtkListStore* list,
bd2899cf
DB
283 const char* dir_path,
284 const char* lookup,
285 GtkTreeSelection* sel,
286 const char* init_sel,
287 ThemeFunc theme_func )
08024023
DB
288{
289 GDir* dir;
290 if( dir = g_dir_open( dir_path, 0, NULL ) )
291 {
bd2899cf 292 const char* name;
08024023
DB
293 while( name = g_dir_read_name( dir ) )
294 {
295 char* file = g_build_filename( dir_path, name, lookup, NULL );
296 if( g_file_test( file, G_FILE_TEST_EXISTS ) )
297 {
bd2899cf 298 gboolean add = TRUE;
08024023 299 GtkTreeIter it;
bd2899cf
DB
300
301 /* prevent duplication */
302 if( gtk_tree_model_get_iter_first(GTK_TREE_MODEL (list), &it ) )
08024023 303 {
bd2899cf
DB
304 char* _name;
305 do {
306 _name = NULL;
307 gtk_tree_model_get(GTK_TREE_MODEL (list), &it, COL_NAME, &_name, -1);
308 if( _name && strcmp(_name, name) == 0 )
309 {
310 add = FALSE;
311 g_free(_name);
312 break;
313 }
314 g_free(_name);
315 }
316 while( gtk_tree_model_iter_next(GTK_TREE_MODEL (list), &it ) );
317 }
318
319 if( add )
320 {
321 gtk_list_store_append( list, &it );
322 gtk_list_store_set( list, &it, COL_NAME, name, -1 );
323
324 if( theme_func )
325 {
326 if( ! theme_func(file, (char *) dir, name, list, &it) )
327 add = FALSE;
328 }
329
330 if( add )
331 {
332 if( 0 == strcmp( name, init_sel ) )
333 {
334 GtkTreeView* view;
335 GtkTreePath* tp;
336 gtk_tree_selection_select_iter( sel, &it );
337 view = gtk_tree_selection_get_tree_view( sel );
338 tp = gtk_tree_model_get_path( (GtkTreeModel*)list, &it );
339 gtk_tree_view_scroll_to_cell( view, tp, NULL, FALSE, 0, 0 );
340 gtk_tree_path_free( tp );
341 }
342 }
343 else
344 gtk_list_store_remove( list, &it );
08024023
DB
345 }
346 }
347 g_free( file );
348 }
349 g_dir_close( dir );
350 }
351}
352
353static void load_from_data_dirs( GtkListStore* list,
bd2899cf
DB
354 const char* relative_path,
355 const char* lookup,
356 GtkTreeSelection* sel,
357 const char* init_sel,
358 ThemeFunc theme_func )
08024023
DB
359{
360 const char* const *dirs = g_get_system_data_dirs();
361 const char* const *dir;
362 char* dir_path;
363 for( dir = dirs; *dir; ++dir )
364 {
365 dir_path = g_build_filename( *dir, relative_path, NULL );
bd2899cf 366 load_themes_from_dir( list, dir_path, lookup, sel, init_sel, theme_func );
08024023
DB
367 g_free( dir_path );
368 }
369 dir_path = g_build_filename( g_get_user_data_dir(), relative_path, NULL );
bd2899cf 370 load_themes_from_dir( list, dir_path, lookup, sel, init_sel, theme_func );
08024023
DB
371 g_free( dir_path );
372}
373
bd2899cf
DB
374static gboolean icon_theme_func(const char* file, const char* dir, const char* name, GtkListStore* list, GtkTreeIter* it)
375{
376 GKeyFile* kf;
377 char* disp_name = NULL;
378 if( g_str_has_prefix( name, "default." ) )
379 return FALSE;
380
381 kf = g_key_file_new();
382 if( g_key_file_load_from_file(kf, file, 0, NULL) )
383 {
384 if( g_key_file_has_key(kf, "Icon Theme", "Directories", NULL)
385 && ! g_key_file_get_boolean(kf, "Icon Theme", "Hidden", NULL) )
386 {
387 disp_name = g_key_file_get_locale_string(kf, "Icon Theme", "Name", NULL, NULL);
388 gtk_list_store_set( list, it, COL_DISP_NAME, disp_name ? disp_name : name, -1 );
389 }
390 }
391 g_key_file_free(kf);
392 return disp_name != NULL;
393}
394
7fbfd5a0 395#if CURSOR_THEME
bd2899cf
DB
396static gboolean cursor_theme_func(const char* dir, const char* name, const char* lookup)
397{
398 char* ret = NULL;
399/*
400 GKeyFile* kf = g_key_file_new();
401 if( g_key_file_load_from_file(kf, lookup, 0, NULL) )
402 {
403 if( g_key_file_has_key(kf, "Icon Theme", "Directories", NULL) )
404 {
405 ret = g_key_file_get_locale_string(kf, "Icon Theme", "Name", NULL, NULL);
406 }
407 }
408 g_key_file_free(kf);
409*/
410 return ret != NULL;
411}
7fbfd5a0 412#endif
bd2899cf 413
08024023
DB
414static void load_gtk_themes( GtkListStore* list, const char* cur_sel )
415{
416 char* path;
417 GtkTreeSelection* sel = gtk_tree_view_get_selection( gtk_theme_view );
bd2899cf 418 load_from_data_dirs( list, "themes", "gtk-2.0", sel, cur_sel, NULL );
08024023 419 path = g_build_filename( g_get_home_dir(), ".themes", NULL );
bd2899cf 420 load_themes_from_dir( list, path, "gtk-2.0", sel, cur_sel, NULL );
08024023
DB
421 g_free( path );
422 gtk_tree_sortable_set_sort_column_id( (GtkTreeSortable*)list, 0, GTK_SORT_ASCENDING );
423}
424
425static void load_icon_themes( GtkListStore* list, const char* cur_sel )
426{
427 char* path;
428 GtkTreeSelection* sel = gtk_tree_view_get_selection( icon_theme_view );
bd2899cf 429 load_from_data_dirs( list, "icons", "index.theme", sel, cur_sel, icon_theme_func );
08024023 430 path = g_build_filename( g_get_home_dir(), ".icons", NULL );
bd2899cf 431 load_themes_from_dir( list, path, "index.theme", sel, cur_sel, icon_theme_func );
08024023
DB
432 g_free( path );
433 gtk_tree_sortable_set_sort_column_id( (GtkTreeSortable*)list, 0, GTK_SORT_ASCENDING );
434}
435
7fbfd5a0 436#if CURSOR_THEME
13f1ec51
DB
437static void load_cursor_themes( GtkListStore* list, const char* cur_sel )
438{
439 char* path;
440 GtkTreeSelection* sel = gtk_tree_view_get_selection( cursor_theme_view );
441 load_from_data_dirs( list, "icons", "cursors", sel, cur_sel, NULL );
442 path = g_build_filename( g_get_home_dir(), ".icons", NULL );
443 load_themes_from_dir( list, path, "cursors", sel, cur_sel, NULL );
444 g_free( path );
445 gtk_tree_sortable_set_sort_column_id( (GtkTreeSortable*)list, 0, GTK_SORT_ASCENDING );
446}
7fbfd5a0
DB
447#endif
448
08024023
DB
449/*
450static void load_fonts( GtkListStore* list )
451{
452
453}
454*/
455
bd2899cf 456gboolean center_win( GtkWidget* dlg )
08024023
DB
457{
458 gtk_widget_show( dlg );
459 return FALSE;
460}
461
462static void on_demo_loaded( GtkSocket* socket, GtkWidget* dlg )
463{
464 /* sleep for 0.8 sec for loading of the demo window */
465 /* FIXME: we need a better way to do this, such as IPC */
466 g_timeout_add_full( G_PRIORITY_LOW, 800, (GSourceFunc)center_win, dlg, NULL );
467 g_signal_handlers_disconnect_by_func( socket, on_demo_loaded, dlg );
468}
469
470void main_dlg_init( GtkWidget* dlg )
471{
472 char* files[] = { tmp_rc_file, NULL };
473 char** def_files = gtk_rc_get_default_files();
474 char** file;
475
13f1ec51
DB
476 if( under_lxsession )
477 {
478 session_name = g_getenv("DESKTOP_SESSION");
479 }
480 else
08024023 481 {
13f1ec51 482 /* no lxsession-settings daemon, use gtkrc-2.0 */
08024023
DB
483 for( file = def_files; *file; ++file )
484 {
485 if( 0 == access( *file, W_OK ) )
486 rc_file = *file;
487 }
488 if( rc_file )
489 rc_file = g_strdup( rc_file );
490 else
491 rc_file = g_build_filename( g_get_home_dir(), ".gtkrc-2.0", NULL );
492 }
493
494 g_object_get( gtk_settings_get_default(),
495 "gtk-theme-name", &gtk_theme_name,
496 "gtk-icon-theme-name", &icon_theme_name,
497 "gtk-font-name", &font_name,
498 "gtk-toolbar-style", &tb_style,
7fbfd5a0 499#if CURSOR_THEME
13f1ec51
DB
500 "gtk-cursor-theme-name", &cursor_theme_name,
501 "gtk-cursor-theme-size", &cursor_theme_size,
7fbfd5a0 502#endif
08024023
DB
503 NULL );
504
505 if( ! gtk_theme_name )
506 gtk_theme_name = g_strdup( "Raleigh" );
507 if( ! icon_theme_name )
13f1ec51 508 icon_theme_name = g_strdup( "hicolor" );
7fbfd5a0 509#if CURSOR_THEME
13f1ec51
DB
510 if( ! cursor_theme_name )
511 cursor_theme_name = g_strdup( "default" );
7fbfd5a0 512#endif
08024023
DB
513 if( ! font_name )
514 font_name = g_strdup( "Sans 10" );
13f1ec51
DB
515 if( ! cursor_theme_size )
516 cursor_theme_size = 16;
08024023 517
13f1ec51
DB
518 /* no lxsession-settings daemon, use gtkrc-2.0 */
519 if( ! under_lxsession )
08024023
DB
520 write_rc_file( tmp_rc_file );
521
522 INIT_LIST( gtk_theme, "gtk-theme-name" )
523 INIT_LIST( icon_theme, "gtk-icon-theme-name" )
7fbfd5a0
DB
524
525#if CURSOR_THEME
13f1ec51 526 INIT_LIST( cursor_theme, "gtk-cursor-theme-name" )
7fbfd5a0
DB
527#endif
528
08024023 529 gtk_font_button_set_font_name( (GtkFontButton*)lookup_widget(dlg, "font"), font_name );
7fbfd5a0
DB
530
531#if CURSOR_THEME
13f1ec51 532 gtk_range_set_value( GTK_RANGE(lookup_widget(dlg, "cursor_theme_size")), cursor_theme_size );
7fbfd5a0 533#endif
08024023
DB
534
535 gtk_combo_box_set_active( (GtkComboBox*)lookup_widget(dlg, "tb_style"), tb_style < 4 ? tb_style : 3 );
536
bd2899cf 537 GET_WIDGET_WITH_TYPE( demo_box, GTK_WIDGET );
08024023
DB
538 gtk_widget_show( demo_box );
539
13f1ec51 540 if( under_lxsession )
08024023 541 {
13f1ec51 542 /* XSettings daemon of lxsession is running, gtkrc is useless.
08024023
DB
543 * We should set properties of GtkSettings object on the fly.
544 * This will cause problems with some themes, but we have no choice.
545 */
546 show_demo( (GdkNativeWindow)demo_box );
547 gtk_widget_show_all( dlg );
548 }
549 else
550 {
13f1ec51 551 /* no lxsession-settings daemon, use gtkrc-2.0 and load preview in another process */
08024023
DB
552 demo_socket = gtk_socket_new();
553 g_signal_connect( demo_socket, "plug-added", G_CALLBACK(on_demo_loaded), dlg );
554 g_signal_connect( demo_socket, "plug-removed", G_CALLBACK(gtk_true), NULL );
555 gtk_widget_show( demo_socket );
556 gtk_container_add( (GtkContainer*)demo_box, demo_socket );
557
558 gtk_widget_realize( dlg );
559 reload_demo_process();
560 }
561
562 disable_apply();
563}
564
565static void reload_all_programs( gboolean icon_only )
566{
567 GdkEventClient event;
568 event.type = GDK_CLIENT_EVENT;
569 event.send_event = TRUE;
570 event.window = NULL;
571
13f1ec51 572 if( under_lxsession )
08024023 573 {
13f1ec51
DB
574/*
575 char* argv[]={"lxsession", "-r", NULL};
576 g_spawn_sync(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, NULL, NULL);
577 return;
578*/
579 event.message_type = gdk_atom_intern_static_string("_LXSESSION");
08024023
DB
580 event.data.b[0] = 0; /* LXS_RELOAD */
581 }
582 else
583 {
584 if( icon_only )
585 event.message_type = gdk_atom_intern("_GTK_LOAD_ICONTHEMES", FALSE);
586 else
587 event.message_type = gdk_atom_intern("_GTK_READ_RCFILES", FALSE);
588 }
589 event.data_format = 8;
590 gdk_event_send_clientmessage_toall((GdkEvent *)&event);
591}
592
593void
594on_apply_clicked (GtkButton *button,
595 gpointer user_data)
596{
13f1ec51
DB
597 if( under_lxsession )
598 write_lxsession_config();
08024023
DB
599 else
600 write_rc_file( rc_file );
601
602 reload_all_programs( FALSE );
603 disable_apply();
604}
605
606
607void
608on_font_changed (GtkFontButton *fontbutton,
609 gpointer user_data)
610{
611 const char* name = gtk_font_button_get_font_name(fontbutton);
612 if( name && font_name && 0 == strcmp( name, font_name ) )
613 return;
614 g_free( font_name );
615 font_name = g_strdup( name );
616
13f1ec51 617 if( under_lxsession )
08024023
DB
618 {
619 g_object_set( gtk_settings_get_default(), "gtk-font-name", font_name, NULL );
620
621 enable_apply();
622 }
623 else
624 {
625 write_rc_file( tmp_rc_file );
626 reload_demo_process();
627 }
628}
629
630void
631on_install_theme_clicked (GtkButton *button,
632 gpointer user_data)
633{
634 GtkFileFilter* filter = gtk_file_filter_new();
635 GtkWidget* fc = gtk_file_chooser_dialog_new( _("Select an icon theme"), NULL,
636 GTK_FILE_CHOOSER_ACTION_OPEN,
637 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
638 GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL );
639
640 gtk_file_filter_add_pattern( filter, "*.tar.gz" );
641 gtk_file_filter_add_pattern( filter, "*.tar.bz2" );
642 gtk_file_filter_set_name( filter, _("*.tar.gz, *.tar.bz2 (Icon Theme)") );
643
bd2899cf
DB
644 gtk_file_chooser_add_filter( GTK_FILE_CHOOSER(fc), filter );
645 gtk_file_chooser_set_filter( GTK_FILE_CHOOSER(fc), filter );
08024023
DB
646
647 if( gtk_dialog_run( (GtkDialog*)fc ) == GTK_RESPONSE_OK )
648 {
bd2899cf 649 char* file = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(fc) );
08024023
DB
650 char* argv[]={
651 PACKAGE_DATA_DIR"/lxappearance/install-icon-theme.sh",
652 file, NULL };
653 int status = 0;
654 char* stdo = NULL;
655 if( g_spawn_sync( NULL, argv, NULL, 0, NULL, NULL, &stdo, NULL, &status, NULL ) && 0 == status )
656 {
657 char* sep = stdo ? strchr( stdo, '\n' ) : NULL;
658 if( sep )
659 *sep = '\0';
660
661 /* reload all icon themes */
662 gtk_list_store_clear( icon_theme_list );
663 load_icon_themes( icon_theme_list, stdo ? stdo : "" );
13f1ec51 664
7fbfd5a0 665#if CURSOR_THEME
13f1ec51
DB
666 /* reload all cursor themes */
667 gtk_list_store_clear( cursor_theme_list );
668 load_cursor_themes( cursor_theme_list, stdo ? stdo : "" );
7fbfd5a0 669#endif
08024023
DB
670 }
671 g_free( file );
672 }
673
674 gtk_widget_destroy( fc );
675}
676
677
678void
679on_remove_theme_clicked (GtkButton *button,
680 gpointer user_data)
681{
682
683}
684
7fbfd5a0 685#if CURSOR_THEME
13f1ec51
DB
686void
687on_cursor_size_changed (GtkHScale *cursorsizescale,
688 gpointer user_data)
689{
690 cursor_theme_size = gtk_range_get_value( GTK_RANGE(cursorsizescale) );
691
692 if( under_lxsession )
693 {
694 g_object_set( gtk_settings_get_default(), "gtk-cursor-theme-size", cursor_theme_size, NULL );
695 enable_apply();
696 }
697 else
698 {
699 write_rc_file( tmp_rc_file );
700 reload_demo_process();
701 }
702}
7fbfd5a0 703#endif
08024023
DB
704
705void
706on_tb_style_changed (GtkComboBox *combobox,
707 gpointer user_data)
708{
709 int sel = gtk_combo_box_get_active( combobox );
710 if( sel == tb_style || sel < 0 )
711 return;
712 tb_style = sel;
713
13f1ec51 714 if( under_lxsession )
08024023
DB
715 {
716 g_object_set( gtk_settings_get_default(), "gtk-toolbar-style", tb_style, NULL );
717 enable_apply();
718 }
719 else
720 {
721 write_rc_file( tmp_rc_file );
722 reload_demo_process();
723 }
724}
725