]> Dogcows Code - chaz/tint2/blob - src/tint2conf/theme_view.c
panel switcher : sorted by name
[chaz/tint2] / src / tint2conf / theme_view.c
1
2 #include <stdlib.h>
3 #include <glib.h>
4 #include <glib/gstdio.h>
5
6 #include "theme_view.h"
7
8 // The data columns that we export via the tree model interface
9 GtkWidget *g_theme_view;
10 GtkListStore *g_store;
11 int g_width_list, g_height_list;
12 GtkCellRenderer *g_renderer;
13
14
15
16 GtkWidget *create_view()
17 {
18 GtkTreeViewColumn *col;
19 GtkCellRenderer *renderer;
20 GtkWidget *view;
21
22 g_store = gtk_list_store_new(NB_COL, G_TYPE_STRING, GDK_TYPE_PIXBUF);
23
24 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(g_store));
25 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view), TRUE);
26 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
27
28 g_object_unref(g_store); // destroy store automatically with view
29
30 renderer = gtk_cell_renderer_text_new();
31 col = gtk_tree_view_column_new();
32 gtk_tree_view_column_pack_start(col, renderer, TRUE);
33 gtk_tree_view_column_add_attribute(col, renderer, "text", COL_THEME_FILE);
34 gtk_tree_view_column_set_visible(col, FALSE);
35 gtk_tree_view_append_column(GTK_TREE_VIEW(view),col);
36
37 g_width_list = 200;
38 g_height_list = 30;
39 g_renderer = gtk_cell_renderer_pixbuf_new();
40 g_object_set(g_renderer, "xalign", 0.0, NULL);
41 gtk_cell_renderer_set_fixed_size(g_renderer, g_width_list, g_height_list);
42 // specific to gtk-2.18 or higher
43 //gtk_cell_renderer_set_padding(g_renderer, 5, 5);
44 col = gtk_tree_view_column_new();
45 gtk_tree_view_column_pack_start(col, g_renderer, TRUE);
46 gtk_tree_view_column_add_attribute(col, g_renderer, "pixbuf", COL_SNAPSHOT);
47 gtk_tree_view_append_column(GTK_TREE_VIEW(view),col);
48
49 GtkTreeSortable *sortable;
50 sortable = GTK_TREE_SORTABLE(g_store);
51 gtk_tree_sortable_set_sort_column_id(sortable, COL_THEME_FILE, GTK_SORT_ASCENDING);
52 return view;
53 }
54
55
56 void custom_list_append(const gchar *name)
57 {
58 GtkTreeIter iter;
59
60 gtk_list_store_append(g_store, &iter);
61 gtk_list_store_set(g_store, &iter, COL_THEME_FILE, name, -1);
62 }
63
64
65 gboolean update_snapshot()
66 {
67 GtkTreeModel *model;
68 GtkTreeIter iter;
69 GdkPixbuf *icon;
70 gboolean have_iter, found = FALSE;
71
72 model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_theme_view));
73 have_iter = gtk_tree_model_get_iter_first(model, &iter);
74 while (have_iter) {
75 gtk_tree_model_get(model, &iter, COL_SNAPSHOT, &icon, -1);
76 if (icon != NULL) {
77 g_object_unref(icon);
78 have_iter = gtk_tree_model_iter_next(model, &iter);
79 }
80 else {
81 found = TRUE;
82 break;
83 }
84 }
85
86 if (found) {
87 // build panel's snapshot
88 GdkPixbuf *pixbuf;
89 gchar *name, *snap, *cmd;
90 gint pixWidth, pixHeight;
91 gboolean changeSize = FALSE;
92
93 snap = g_build_filename (g_get_user_config_dir(), "tint2", "snap.jpg", NULL);
94 g_remove(snap);
95
96 gtk_tree_model_get(model, &iter, COL_THEME_FILE, &name, -1);
97 cmd = g_strdup_printf("tint2 -c \'%s\' -s \'%s\'", name, snap);
98 system(cmd);
99
100 // load
101 pixbuf = gdk_pixbuf_new_from_file(snap, NULL);
102 if (pixbuf == NULL) {
103 printf("snapshot NULL : %s\n", cmd);
104 found = FALSE;
105 }
106 g_free(snap);
107 g_free(cmd);
108 g_free(name);
109
110 pixWidth = gdk_pixbuf_get_width(pixbuf);
111 pixHeight = gdk_pixbuf_get_height(pixbuf);
112 if (g_width_list < pixWidth) {
113 g_width_list = pixWidth;
114 changeSize = TRUE;
115 }
116 if (g_height_list < (pixHeight+6)) {
117 g_height_list = pixHeight+6;
118 changeSize = TRUE;
119 }
120 if (changeSize)
121 gtk_cell_renderer_set_fixed_size(g_renderer, g_width_list, g_height_list);
122
123 gtk_list_store_set(g_store, &iter, COL_SNAPSHOT, pixbuf, -1);
124 }
125 return found;
126 }
127
128
129
This page took 0.045155 seconds and 4 git commands to generate.