]> icculus.org git repositories - dana/obconf.git/blob - src/preview_update.c
small cleanup for themes.c
[dana/obconf.git] / src / preview_update.c
1 #include "preview_update.h"
2
3 static gboolean restart_theme_preview_update = TRUE;
4
5 static GtkListStore *list_store           = NULL;
6 static gchar        *title_layout         = NULL;
7 static RrFont       *active_window_font   = NULL;
8 static RrFont       *inactive_window_font = NULL;
9 static RrFont       *menu_title_font      = NULL;
10 static RrFont       *menu_item_font       = NULL;
11 static RrFont       *osd_font             = NULL;
12
13 static gboolean update_theme_preview_iterate(gpointer data);
14
15 void preview_update_all()
16 {
17     if (!list_store) return;
18
19     g_idle_remove_by_data(list_store);
20
21     if (!(title_layout && active_window_font && inactive_window_font &&
22           menu_title_font && menu_item_font && osd_font))
23         return; /* not set up */
24
25     restart_theme_preview_update = TRUE;
26     g_idle_add_full(G_PRIORITY_LOW,
27                     update_theme_preview_iterate,
28                     list_store, NULL);
29 }
30
31 void preview_update_set_list_store(GtkListStore *ls)
32 {
33     if (list_store) g_idle_remove_by_data(list_store);
34
35     list_store = ls;
36
37     if (list_store) preview_update_all();
38 }
39
40 void preview_update_set_active_font(RrFont *f)
41 {
42     RrFontClose(active_window_font);
43     active_window_font = f;
44     preview_update_all();
45 }
46
47 void preview_update_set_inactive_font(RrFont *f)
48 {
49     RrFontClose(inactive_window_font);
50     inactive_window_font = f;
51     preview_update_all();
52 }
53
54 void preview_update_set_menu_header_font(RrFont *f)
55 {
56     RrFontClose(menu_title_font);
57     menu_title_font = f;
58     preview_update_all();
59 }
60
61 void preview_update_set_menu_item_font(RrFont *f)
62 {
63     RrFontClose(menu_item_font);
64     menu_item_font = f;
65     preview_update_all();
66 }
67
68 void preview_update_set_osd_font(RrFont *f)
69 {
70     RrFontClose(osd_font);
71     osd_font = f;
72     preview_update_all();
73 }
74
75 void preview_update_set_title_layout(const gchar *layout)
76 {
77     g_free(title_layout);
78     title_layout = g_strdup(layout);
79     preview_update_all();
80 }
81
82 static gboolean update_theme_preview_iterate(gpointer data)
83 {
84     GtkListStore *ls = data;
85     static GtkTreeIter iter;
86     gchar *name;
87
88     if (restart_theme_preview_update) {
89         if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ls), &iter))
90             return;
91         restart_theme_preview_update = FALSE;
92     } else {
93         if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(ls), &iter)) {
94             restart_theme_preview_update = TRUE;
95             return;
96         }
97     }
98
99     gtk_tree_model_get(GTK_TREE_MODEL(ls), &iter, 0, &name, -1);
100
101     gtk_list_store_set(GTK_LIST_STORE(ls), &iter, 1,
102                        preview_theme(name, title_layout, active_window_font,
103                                      inactive_window_font, menu_title_font,
104                                      menu_item_font, osd_font),
105                        -1);
106 }