]>
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
, 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
);
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
);
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
);
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
);
78 void custom_list_append(const gchar
*name
)
82 gtk_list_store_append(g_store
, &iter
);
83 gtk_list_store_set(g_store
, &iter
, COL_THEME_FILE
, name
, -1);
86 b
= strrchr(name
, '/');
90 gtk_list_store_set(g_store
, &iter
, COL_THEME_NAME
, n
, -1);
94 gboolean
update_snapshot()
99 gboolean have_iter
, found
= FALSE
;
101 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(g_theme_view
));
102 have_iter
= gtk_tree_model_get_iter_first(model
, &iter
);
104 gtk_tree_model_get(model
, &iter
, COL_SNAPSHOT
, &icon
, -1);
106 g_object_unref(icon
);
107 have_iter
= gtk_tree_model_iter_next(model
, &iter
);
116 // build panel's snapshot
118 gchar
*name
, *snap
, *cmd
;
119 gint pixWidth
, pixHeight
;
120 gboolean changeSize
= FALSE
;
122 snap
= g_build_filename (g_get_user_config_dir(), "tint2", "snap.jpg", NULL
);
125 gtk_tree_model_get(model
, &iter
, COL_THEME_FILE
, &name
, -1);
126 cmd
= g_strdup_printf("tint2 -c \'%s\' -s \'%s\'", name
, snap
);
130 pixbuf
= gdk_pixbuf_new_from_file(snap
, NULL
);
131 if (pixbuf
== NULL
) {
132 printf("snapshot NULL : %s\n", cmd
);
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
;
145 if (g_height_list
!= (pixHeight
+30)) {
146 g_height_list
= pixHeight
+30;
150 gtk_cell_renderer_set_fixed_size(g_renderer
, g_width_list
, g_height_list
);
152 gtk_list_store_set(g_store
, &iter
, COL_SNAPSHOT
, pixbuf
, -1);
This page took 0.044545 seconds and 4 git commands to generate.