add the showDelay and noStrut options to dock tab
[dana/obconf.git] / src / preview_update.c
1 #include "preview_update.h"
2 #include "main.h"
3
4 static gboolean restart_theme_preview_update = TRUE;
5
6 static GtkTreeView  *tree_view            = NULL;
7 static GtkListStore *list_store           = NULL;
8 static gchar        *title_layout         = NULL;
9 static RrFont       *active_window_font   = NULL;
10 static RrFont       *inactive_window_font = NULL;
11 static RrFont       *menu_title_font      = NULL;
12 static RrFont       *menu_item_font       = NULL;
13 static RrFont       *osd_font             = NULL;
14
15 static gboolean update_theme_preview_iterate(gpointer data);
16
17 void preview_update_all()
18 {
19     if (!list_store) return;
20
21     g_idle_remove_by_data(list_store);
22
23     if (!(title_layout && active_window_font && inactive_window_font &&
24           menu_title_font && menu_item_font && osd_font))
25         return; /* not set up */
26
27     restart_theme_preview_update = TRUE;
28     g_idle_add_full(G_PRIORITY_LOW,
29                     update_theme_preview_iterate,
30                     list_store, NULL);
31 }
32
33 void preview_update_set_tree_view(GtkTreeView *tr, GtkListStore *ls)
34 {
35     g_assert(!!tr == !!ls);
36
37     if (list_store) g_idle_remove_by_data(list_store);
38
39     tree_view = tr;
40     list_store = ls;
41
42     if (list_store) preview_update_all();
43 }
44
45 void preview_update_set_active_font(RrFont *f)
46 {
47     RrFontClose(active_window_font);
48     active_window_font = f;
49     preview_update_all();
50 }
51
52 void preview_update_set_inactive_font(RrFont *f)
53 {
54     RrFontClose(inactive_window_font);
55     inactive_window_font = f;
56     preview_update_all();
57 }
58
59 void preview_update_set_menu_header_font(RrFont *f)
60 {
61     RrFontClose(menu_title_font);
62     menu_title_font = f;
63     preview_update_all();
64 }
65
66 void preview_update_set_menu_item_font(RrFont *f)
67 {
68     RrFontClose(menu_item_font);
69     menu_item_font = f;
70     preview_update_all();
71 }
72
73 void preview_update_set_osd_font(RrFont *f)
74 {
75     RrFontClose(osd_font);
76     osd_font = f;
77     preview_update_all();
78 }
79
80 void preview_update_set_title_layout(const gchar *layout)
81 {
82     g_free(title_layout);
83     title_layout = g_strdup(layout);
84     preview_update_all();
85 }
86
87 static gboolean update_theme_preview_iterate(gpointer data)
88 {
89     GtkListStore *ls = data;
90     static GtkTreeIter iter;
91     gchar *name;
92
93     if (restart_theme_preview_update) {
94         if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ls), &iter))
95             return FALSE;
96         restart_theme_preview_update = FALSE;
97     } else {
98         if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(ls), &iter)) {
99             GtkTreePath *path;
100
101             restart_theme_preview_update = TRUE;
102
103             gtk_tree_view_get_cursor(tree_view, &path, NULL);
104             gtk_tree_view_scroll_to_cell(tree_view, path, NULL,
105                                          FALSE, 0, 0);
106             gtk_tree_path_free(path);
107
108             obconf_show_main();
109
110             return FALSE;
111         }
112     }
113
114     gtk_tree_model_get(GTK_TREE_MODEL(ls), &iter, 0, &name, -1);
115
116     gtk_list_store_set(GTK_LIST_STORE(ls), &iter, 1,
117                        preview_theme(name, title_layout, active_window_font,
118                                      inactive_window_font, menu_title_font,
119                                      menu_item_font, osd_font),
120                        -1);
121
122     return TRUE;
123 }