9c8b138d3ed7f5b23742a26d96b26a14123e2af4
[lxde/lxappearance.git] / src / main-dlg.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
4
5 #include <gtk/gtk.h>
6
7 #include "main-dlg.h"
8 #include "main-dlg-ui.h"
9 #include "glade-support.h"
10
11 #define GET_WIDGET( name ) name = lookup_widget( dlg, #name )
12 #define INIT_LIST(name, prop) \
13 GET_WIDGET( name##_view ); \
14 name##_list = init_tree_view( name##_view, G_CALLBACK(on_list_sel_changed), prop ); \
15 load_##name##s( name##_list );
16
17 static GtkTreeView* gtk_theme_view = NULL;
18 GtkListStore* gtk_theme_list = NULL;
19
20 static GtkTreeView* icon_theme_view = NULL;
21 GtkListStore* icon_theme_list = NULL;
22
23 static GtkTreeView* font_view = NULL;
24 GtkListStore* font_list = NULL;
25
26 static on_list_sel_changed( GtkTreeSelection* sel, const char* prop )
27 {
28 GtkTreeIter it;
29 GtkTreeModel* model;
30 if( gtk_tree_selection_get_selected( sel, &model, &it ) )
31 {
32 char* name;
33 gtk_tree_model_get( model, &it, 0, &name, -1 );
34 if( model == font_list ) /* this is a font */
35 {
36
37 }
38 g_object_set( gtk_settings_get_default(), prop, name, NULL );
39 g_free( name );
40 }
41 }
42
43 static GtkListStore* init_tree_view( GtkTreeView* view, GCallback on_sel_changed, const char* prop )
44 {
45 GtkTreeViewColumn* col;
46 GtkListStore* list;
47 col = gtk_tree_view_column_new_with_attributes( NULL, gtk_cell_renderer_text_new(), "text", 0, NULL );
48 gtk_tree_view_append_column( view, col );
49 g_signal_connect( gtk_tree_view_get_selection(view), "changed", on_sel_changed, prop );
50
51 list = gtk_list_store_new( 1, G_TYPE_STRING );
52 gtk_tree_view_set_model( view, (GtkTreeModel*)list );
53 g_object_unref( list );
54 return list;
55 }
56
57 static void load_themes_from_dir( GtkListStore* list,
58 const char* dir_path,
59 const char* lookup )
60 {
61 GDir* dir;
62 if( dir = g_dir_open( dir_path, 0, NULL ) )
63 {
64 char* name;
65 while( name = g_dir_read_name( dir ) )
66 {
67 char* file = g_build_filename( dir_path, name, lookup, NULL );
68 if( g_file_test( file, G_FILE_TEST_EXISTS ) )
69 {
70 GtkTreeIter it;
71 gtk_list_store_append( list, &it );
72 gtk_list_store_set( list, &it, 0, name, -1 );
73 }
74 g_free( file );
75 }
76 g_dir_close( dir );
77 }
78 }
79
80 static void load_from_data_dirs( GtkListStore* list,
81 const char* relative_path,
82 const char* lookup )
83 {
84 const char* const *dirs = g_get_system_data_dirs();
85 const char* const *dir;
86 char* dir_path;
87 for( dir = dirs; *dir; ++dir )
88 {
89 dir_path = g_build_filename( *dir, relative_path, NULL );
90 load_themes_from_dir( list, dir_path, lookup );
91 g_free( dir_path );
92 }
93 dir_path = g_build_filename( g_get_user_data_dir(), relative_path, NULL );
94 load_themes_from_dir( list, dir_path, lookup );
95 g_free( dir_path );
96 }
97
98 static void load_gtk_themes( GtkListStore* list )
99 {
100 load_from_data_dirs( list, "themes", "gtk-2.0" );
101 }
102
103 static void load_icon_themes( GtkListStore* list )
104 {
105 char* path;
106 load_from_data_dirs( list, "icons", "index.theme" );
107 path = g_build_filename( g_get_home_dir(), ".icons", NULL );
108 load_themes_from_dir( list, path, "index.theme" );
109 g_free( path );
110 }
111
112 static void load_fonts( GtkListStore* list )
113 {
114
115 }
116
117 void main_dlg_init( GtkWidget* dlg )
118 {
119 INIT_LIST( gtk_theme, "gtk-theme-name" )
120 INIT_LIST( icon_theme, "gtk-icon-theme-name" )
121 INIT_LIST( font, "gtk-font-name" )
122
123 }
124
125 void
126 on_apply_clicked (GtkButton *button,
127 gpointer user_data)
128 {
129
130 }
131