]> Dogcows Code - chaz/tint2/blob - src/tint2conf/theme_view.c
tint2conf: work in progress
[chaz/tint2] / src / tint2conf / theme_view.c
1 /**************************************************************************
2 *
3 * Tint2conf
4 *
5 * Copyright (C) 2009 Thierry lorthiois (lorthiois@bbsoft.fr) from Omega distribution
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 **************************************************************************/
19
20
21 #include "main.h"
22 #include "theme_view.h"
23
24 // The data columns that we export via the tree model interface
25 GtkWidget *g_theme_view;
26 GtkListStore *g_store;
27 int g_width_list, g_height_list;
28 GtkCellRenderer *g_renderer;
29
30
31
32 GtkWidget *create_view()
33 {
34 GtkTreeViewColumn *col;
35 GtkCellRenderer *renderer;
36 GtkWidget *view;
37
38 g_store = gtk_list_store_new(NB_COL, G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF);
39
40 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(g_store));
41 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view), TRUE);
42 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
43
44 g_object_unref(g_store); // destroy store automatically with view
45
46 renderer = gtk_cell_renderer_text_new();
47 col = gtk_tree_view_column_new();
48 gtk_tree_view_column_pack_start(col, renderer, TRUE);
49 gtk_tree_view_column_add_attribute(col, renderer, "text", COL_THEME_FILE);
50 gtk_tree_view_column_set_visible(col, FALSE);
51 gtk_tree_view_append_column(GTK_TREE_VIEW(view),col);
52
53 renderer = gtk_cell_renderer_text_new();
54 col = gtk_tree_view_column_new();
55 gtk_tree_view_column_pack_start(col, renderer, TRUE);
56 gtk_tree_view_column_add_attribute(col, renderer, "text", COL_THEME_NAME);
57 gtk_tree_view_append_column(GTK_TREE_VIEW(view),col);
58
59 g_width_list = 200;
60 g_height_list = 30;
61 g_renderer = gtk_cell_renderer_pixbuf_new();
62 g_object_set(g_renderer, "xalign", 0.0, NULL);
63 gtk_cell_renderer_set_fixed_size(g_renderer, g_width_list, g_height_list);
64 // specific to gtk-2.18 or higher
65 //gtk_cell_renderer_set_padding(g_renderer, 5, 5);
66 col = gtk_tree_view_column_new();
67 gtk_tree_view_column_pack_start(col, g_renderer, TRUE);
68 gtk_tree_view_column_add_attribute(col, g_renderer, "pixbuf", COL_SNAPSHOT);
69 gtk_tree_view_append_column(GTK_TREE_VIEW(view),col);
70
71 GtkTreeSortable *sortable;
72 sortable = GTK_TREE_SORTABLE(g_store);
73 gtk_tree_sortable_set_sort_column_id(sortable, COL_THEME_FILE, GTK_SORT_ASCENDING);
74 return view;
75 }
76
77
78 void custom_list_append(const gchar *name)
79 {
80 GtkTreeIter iter;
81
82 gtk_list_store_append(g_store, &iter);
83 gtk_list_store_set(g_store, &iter, COL_THEME_FILE, name, -1);
84
85 gchar *b, *n;
86 b = strrchr(name, '/');
87 n = g_strdup(b+1);
88 b = strrchr(n, '.');
89 *b = '\0';
90 gtk_list_store_set(g_store, &iter, COL_THEME_NAME, n, -1);
91 }
92
93
94 gboolean update_snapshot()
95 {
96 GtkTreeModel *model;
97 GtkTreeIter iter;
98 GdkPixbuf *icon;
99 gboolean have_iter, found = FALSE;
100
101 model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_theme_view));
102 have_iter = gtk_tree_model_get_iter_first(model, &iter);
103 while (have_iter) {
104 gtk_tree_model_get(model, &iter, COL_SNAPSHOT, &icon, -1);
105 if (icon != NULL) {
106 g_object_unref(icon);
107 have_iter = gtk_tree_model_iter_next(model, &iter);
108 }
109 else {
110 found = TRUE;
111 break;
112 }
113 }
114
115 if (found) {
116 // build panel's snapshot
117 GdkPixbuf *pixbuf;
118 gchar *name, *snap, *cmd;
119 gint pixWidth, pixHeight;
120 gboolean changeSize = FALSE;
121
122 snap = g_build_filename (g_get_user_config_dir(), "tint2", "snap.jpg", NULL);
123 g_remove(snap);
124
125 gtk_tree_model_get(model, &iter, COL_THEME_FILE, &name, -1);
126 cmd = g_strdup_printf("tint2 -c \'%s\' -s \'%s\'", name, snap);
127 system(cmd);
128
129 // load
130 pixbuf = gdk_pixbuf_new_from_file(snap, NULL);
131 if (pixbuf == NULL) {
132 printf("snapshot NULL : %s\n", cmd);
133 found = FALSE;
134 }
135 g_free(snap);
136 g_free(cmd);
137 g_free(name);
138
139 pixWidth = gdk_pixbuf_get_width(pixbuf);
140 pixHeight = gdk_pixbuf_get_height(pixbuf);
141 if (g_width_list != pixWidth) {
142 g_width_list = pixWidth;
143 changeSize = TRUE;
144 }
145 if (g_height_list != (pixHeight+30)) {
146 g_height_list = pixHeight+30;
147 changeSize = TRUE;
148 }
149 if (changeSize)
150 gtk_cell_renderer_set_fixed_size(g_renderer, g_width_list, g_height_list);
151
152 gtk_list_store_set(g_store, &iter, COL_SNAPSHOT, pixbuf, -1);
153 }
154 return found;
155 }
156
157
158
This page took 0.044545 seconds and 4 git commands to generate.