1 #include "preview_update.h"
5 static gboolean restart_theme_preview_update = TRUE;
7 static GtkTreeView *tree_view = NULL;
8 static GtkListStore *list_store = NULL;
9 static gchar *title_layout = NULL;
10 static RrFont *active_window_font = NULL;
11 static RrFont *inactive_window_font = NULL;
12 static RrFont *menu_title_font = NULL;
13 static RrFont *menu_item_font = NULL;
14 static RrFont *osd_active_font = NULL;
15 static RrFont *osd_inactive_font = NULL;
17 static gboolean update_theme_preview_iterate(gpointer data);
19 void preview_update_all()
21 if (!list_store) return;
22 if (!RR_CHECK_VERSION(3,5,0)) return;
24 g_idle_remove_by_data(list_store);
26 if (!(title_layout && active_window_font && inactive_window_font &&
27 menu_title_font && menu_item_font &&
28 osd_active_font && osd_inactive_font))
29 return; /* not set up */
31 restart_theme_preview_update = TRUE;
32 g_idle_add_full(G_PRIORITY_LOW,
33 update_theme_preview_iterate,
37 void preview_update_set_tree_view(GtkTreeView *tr, GtkListStore *ls)
39 g_assert(!!tr == !!ls);
41 if (list_store) g_idle_remove_by_data(list_store);
46 if (list_store) preview_update_all();
49 void preview_update_set_active_font(RrFont *f)
51 RrFontClose(active_window_font);
52 active_window_font = f;
56 void preview_update_set_inactive_font(RrFont *f)
58 RrFontClose(inactive_window_font);
59 inactive_window_font = f;
63 void preview_update_set_menu_header_font(RrFont *f)
65 RrFontClose(menu_title_font);
70 void preview_update_set_menu_item_font(RrFont *f)
72 RrFontClose(menu_item_font);
77 void preview_update_set_osd_active_font(RrFont *f)
79 RrFontClose(osd_active_font);
84 void preview_update_set_osd_inactive_font(RrFont *f)
86 RrFontClose(osd_inactive_font);
87 osd_inactive_font = f;
91 void preview_update_set_title_layout(const gchar *layout)
94 title_layout = g_strdup(layout);
98 static gboolean update_theme_preview_iterate(gpointer data)
100 GtkListStore *ls = data;
102 static GtkTreeIter iter;
105 if (restart_theme_preview_update) {
106 /* get the first iterator position if there is such a thing */
107 if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ls), &iter)) {
108 /* nothing to show */
112 restart_theme_preview_update = FALSE;
114 /* get the next iterator position if there is such a thing */
115 if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(ls), &iter)) {
118 restart_theme_preview_update = TRUE;
120 gtk_tree_view_get_cursor(tree_view, &path, NULL);
122 gtk_tree_view_scroll_to_cell(tree_view, path, NULL,
124 gtk_tree_path_free(path);
133 gtk_tree_model_get(GTK_TREE_MODEL(ls), &iter, 0, &name, -1);
135 preview = preview_theme(name, title_layout, active_window_font,
136 inactive_window_font, menu_title_font,
137 menu_item_font, osd_active_font,
140 gtk_list_store_set(GTK_LIST_STORE(ls), &iter, 1, preview, -1);
141 g_object_unref(preview);