3 #include "preview_update.h"
8 static gboolean mapping = FALSE;
11 static GtkListStore *theme_store;
13 static void add_theme_dir(const gchar *dirname);
14 static void reset_theme_names(GtkWidget *w);
15 static void on_theme_names_selection_changed(GtkTreeSelection *sel,
18 void theme_setup_names(GtkWidget *w)
20 GtkCellRenderer *render;
21 GtkTreeViewColumn *column;
22 GtkTreeSelection *select;
27 theme_store = gtk_list_store_new(2, G_TYPE_STRING, GDK_TYPE_PIXBUF);
28 gtk_tree_view_set_model(GTK_TREE_VIEW(w), GTK_TREE_MODEL(theme_store));
29 preview_update_set_list_store(theme_store);
30 g_object_unref (theme_store);
32 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(w)),
33 GTK_SELECTION_SINGLE);
35 /* text column for the names */
36 render = gtk_cell_renderer_text_new();
37 column = gtk_tree_view_column_new_with_attributes
38 ("Name", render, "text", 0, NULL);
39 gtk_tree_view_append_column(GTK_TREE_VIEW(w), column);
41 /* pixbuf column, for theme previews */
42 render = gtk_cell_renderer_pixbuf_new();
43 g_object_set(render, "xalign", 1.0);
44 column = gtk_tree_view_column_new_with_attributes
45 ("Preview", render, "pixbuf", 1, NULL);
46 gtk_tree_view_append_column(GTK_TREE_VIEW(w), column);
49 /* setup the selection handler */
50 select = gtk_tree_view_get_selection(GTK_TREE_VIEW (w));
51 gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);
52 g_signal_connect (G_OBJECT(select), "changed",
53 G_CALLBACK(on_theme_names_selection_changed),
61 static void on_theme_names_selection_changed(GtkTreeSelection *sel,
70 if(gtk_tree_selection_get_selected(sel, &model, &iter)) {
71 gtk_tree_model_get(model, &iter, 0, &name, -1);
75 tree_set_string("theme/name", name);
78 void on_install_theme_clicked(GtkButton *w, gpointer data)
83 GtkFileFilter *filter;
85 d = gtk_file_chooser_dialog_new(_("Choose an Openbox theme"),
87 GTK_FILE_CHOOSER_ACTION_OPEN,
88 GTK_STOCK_OK, GTK_RESPONSE_OK,
89 GTK_STOCK_CANCEL, GTK_RESPONSE_NONE,
92 gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(d), FALSE);
93 filter = gtk_file_filter_new();
94 gtk_file_filter_set_name(filter, _("Openbox theme archives"));
95 gtk_file_filter_add_pattern(filter, "*.obt");
96 //gtk_file_filter_add_pattern(filter, "*.tgz");
97 //gtk_file_filter_add_pattern(filter, "*.tar.gz");
98 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(d), filter);
100 r = gtk_dialog_run(GTK_DIALOG(d));
101 if (r == GTK_RESPONSE_OK)
102 path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d));
103 gtk_widget_destroy(d);
111 void on_theme_archive_clicked(GtkButton *w, gpointer data)
117 d = gtk_file_chooser_dialog_new(_("Choose an Openbox theme"),
119 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
120 GTK_STOCK_OK, GTK_RESPONSE_OK,
121 GTK_STOCK_CANCEL, GTK_RESPONSE_NONE,
124 gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(d), TRUE);
125 r = gtk_dialog_run(GTK_DIALOG(d));
126 if (r == GTK_RESPONSE_OK)
127 path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d));
128 gtk_widget_destroy(d);
131 archive_create(path);
136 void theme_install(const gchar *path)
140 if ((name = archive_install(path))) {
146 w = glade_xml_get_widget(glade, "theme_names");
148 reset_theme_names(w);
151 /* go to the newly installed theme */
152 for (it = themes, i = 0; it; it = g_list_next(it), ++i)
153 if (!strcmp(it->data, name)) break;
155 path = gtk_tree_path_new_from_indices(i, -1);
156 gtk_tree_view_set_cursor(GTK_TREE_VIEW(w), path, NULL, FALSE);
157 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(w), path, NULL,
170 static void reset_theme_names(GtkWidget *w)
177 RrFont *active, *inactive, *menu_t, *menu_i, *osd;
179 name = tree_get_string("theme/name", "TheBear");
181 for (it = themes; it; it = g_list_next(it))
186 p = g_build_filename(g_get_home_dir(), ".themes", NULL);
192 for (it = parse_xdg_data_dir_paths(); it; it = g_slist_next(it)) {
193 p = g_build_filename(it->data, "themes", NULL);
199 add_theme_dir(THEMEDIR);
201 themes = g_list_sort(themes, (GCompareFunc) strcasecmp);
203 gtk_list_store_clear(theme_store);
205 /* return to regular scheduled programming */
207 for (it = themes; it; it = next) {
210 next = g_list_next(it);
212 /* remove duplicates */
213 if (next && !strcmp(it->data, next->data)) {
215 themes = g_list_delete_link(themes, it);
219 gtk_list_store_append(theme_store, &iter);
220 gtk_list_store_set(theme_store, &iter,
225 if(!strcmp(name, it->data)) {
227 path = gtk_tree_path_new_from_indices(i, -1);
228 gtk_tree_view_set_cursor(GTK_TREE_VIEW(w), path, NULL, FALSE);
229 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(w), path, NULL,
237 preview_update_all();
242 static void add_theme_dir(const gchar *dirname)
247 if ((dir = g_dir_open(dirname, 0, NULL))) {
248 while ((n = g_dir_read_name(dir))) {
251 full = g_build_filename(dirname, n, "openbox-3",
253 if (!g_file_test(full,
254 G_FILE_TEST_IS_REGULAR |
255 G_FILE_TEST_IS_SYMLINK))
261 themes = g_list_append(themes, g_strdup(n));