]>
Dogcows Code - chaz/tint2/blob - src/tint2conf/theme_view.c
1 /**************************************************************************
5 * Copyright (C) 2009 Thierry lorthiois (lorthiois@bbsoft.fr) from Omega distribution
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.
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 **************************************************************************/
22 #include "theme_view.h"
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
;
32 GtkWidget
*create_view()
34 GtkTreeViewColumn
*col
;
35 GtkCellRenderer
*renderer
;
38 g_store
= gtk_list_store_new(NB_COL
, G_TYPE_STRING
, GDK_TYPE_PIXBUF
);
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
);
44 g_object_unref(g_store
); // destroy store automatically with view
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
);
55 g_renderer
= gtk_cell_renderer_pixbuf_new();
56 g_object_set(g_renderer
, "xalign", 0.0, NULL
);
57 gtk_cell_renderer_set_fixed_size(g_renderer
, g_width_list
, g_height_list
);
58 // specific to gtk-2.18 or higher
59 //gtk_cell_renderer_set_padding(g_renderer, 5, 5);
60 col
= gtk_tree_view_column_new();
61 gtk_tree_view_column_pack_start(col
, g_renderer
, TRUE
);
62 gtk_tree_view_column_add_attribute(col
, g_renderer
, "pixbuf", COL_SNAPSHOT
);
63 gtk_tree_view_append_column(GTK_TREE_VIEW(view
),col
);
65 GtkTreeSortable
*sortable
;
66 sortable
= GTK_TREE_SORTABLE(g_store
);
67 gtk_tree_sortable_set_sort_column_id(sortable
, COL_THEME_FILE
, GTK_SORT_ASCENDING
);
72 void custom_list_append(const gchar
*name
)
76 gtk_list_store_append(g_store
, &iter
);
77 gtk_list_store_set(g_store
, &iter
, COL_THEME_FILE
, name
, -1);
81 gboolean
update_snapshot()
86 gboolean have_iter
, found
= FALSE
;
88 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(g_theme_view
));
89 have_iter
= gtk_tree_model_get_iter_first(model
, &iter
);
91 gtk_tree_model_get(model
, &iter
, COL_SNAPSHOT
, &icon
, -1);
94 have_iter
= gtk_tree_model_iter_next(model
, &iter
);
103 // build panel's snapshot
105 gchar
*name
, *snap
, *cmd
;
106 gint pixWidth
, pixHeight
;
107 gboolean changeSize
= FALSE
;
109 snap
= g_build_filename (g_get_user_config_dir(), "tint2", "snap.jpg", NULL
);
112 gtk_tree_model_get(model
, &iter
, COL_THEME_FILE
, &name
, -1);
113 cmd
= g_strdup_printf("tint2 -c \'%s\' -s \'%s\'", name
, snap
);
117 pixbuf
= gdk_pixbuf_new_from_file(snap
, NULL
);
118 if (pixbuf
== NULL
) {
119 printf("snapshot NULL : %s\n", cmd
);
126 pixWidth
= gdk_pixbuf_get_width(pixbuf
);
127 pixHeight
= gdk_pixbuf_get_height(pixbuf
);
128 if (g_width_list
!= pixWidth
) {
129 g_width_list
= pixWidth
;
132 if (g_height_list
!= (pixHeight
+30)) {
133 g_height_list
= pixHeight
+30;
137 gtk_cell_renderer_set_fixed_size(g_renderer
, g_width_list
, g_height_list
);
139 gtk_list_store_set(g_store
, &iter
, COL_SNAPSHOT
, pixbuf
, -1);
This page took 0.042347 seconds and 4 git commands to generate.