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