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