]> icculus.org git repositories - dana/obconf.git/blob - src/preview_update.c
Add Arabic translation
[dana/obconf.git] / src / preview_update.c
1 #include "preview_update.h"
2 #include "preview.h"
3 #include "main.h"
4
5 static gboolean restart_theme_preview_update = TRUE;
6
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;
16
17 static gboolean update_theme_preview_iterate(gpointer data);
18
19 void preview_update_all()
20 {
21     if (!list_store) return;
22     if (!RR_CHECK_VERSION(3,5,0)) return;
23
24     g_idle_remove_by_data(list_store);
25
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 */
30
31     restart_theme_preview_update = TRUE;
32     g_idle_add_full(G_PRIORITY_LOW,
33                     update_theme_preview_iterate,
34                     list_store, NULL);
35 }
36
37 void preview_update_set_tree_view(GtkTreeView *tr, GtkListStore *ls)
38 {
39     g_assert(!!tr == !!ls);
40
41     if (list_store) g_idle_remove_by_data(list_store);
42
43     tree_view = tr;
44     list_store = ls;
45
46     if (list_store) preview_update_all();
47 }
48
49 void preview_update_set_active_font(RrFont *f)
50 {
51     RrFontClose(active_window_font);
52     active_window_font = f;
53     preview_update_all();
54 }
55
56 void preview_update_set_inactive_font(RrFont *f)
57 {
58     RrFontClose(inactive_window_font);
59     inactive_window_font = f;
60     preview_update_all();
61 }
62
63 void preview_update_set_menu_header_font(RrFont *f)
64 {
65     RrFontClose(menu_title_font);
66     menu_title_font = f;
67     preview_update_all();
68 }
69
70 void preview_update_set_menu_item_font(RrFont *f)
71 {
72     RrFontClose(menu_item_font);
73     menu_item_font = f;
74     preview_update_all();
75 }
76
77 void preview_update_set_osd_active_font(RrFont *f)
78 {
79     RrFontClose(osd_active_font);
80     osd_active_font = f;
81     preview_update_all();
82 }
83
84 void preview_update_set_osd_inactive_font(RrFont *f)
85 {
86     RrFontClose(osd_inactive_font);
87     osd_inactive_font = f;
88     preview_update_all();
89 }
90
91 void preview_update_set_title_layout(const gchar *layout)
92 {
93     g_free(title_layout);
94     title_layout = g_strdup(layout);
95     preview_update_all();
96 }
97
98 static gboolean update_theme_preview_iterate(gpointer data)
99 {
100     GtkListStore *ls = data;
101     GdkPixbuf *preview;
102     static GtkTreeIter iter;
103     gchar *name;
104
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 */
109             obconf_show_main();
110             return FALSE;
111         }
112         restart_theme_preview_update = FALSE;
113     } else {
114         /* get the next iterator position if there is such a thing */
115         if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(ls), &iter)) {
116             GtkTreePath *path;
117
118             restart_theme_preview_update = TRUE;
119
120             gtk_tree_view_get_cursor(tree_view, &path, NULL);
121             if (path) {
122                 gtk_tree_view_scroll_to_cell(tree_view, path, NULL,
123                                              FALSE, 0, 0);
124                 gtk_tree_path_free(path);
125             }
126
127             obconf_show_main();
128
129             return FALSE;
130         }
131     }
132
133     gtk_tree_model_get(GTK_TREE_MODEL(ls), &iter, 0, &name, -1);
134
135     preview = preview_theme(name, title_layout, active_window_font,
136                             inactive_window_font, menu_title_font,
137                             menu_item_font, osd_active_font,
138                             osd_inactive_font);
139     if (preview)
140         gtk_list_store_set(GTK_LIST_STORE(ls), &iter, 1, preview, -1);
141
142     return TRUE;
143 }