2010-01-09 16:43:14 +00:00
|
|
|
#include <string.h>
|
2009-11-17 10:03:39 +00:00
|
|
|
#include "theme_view.h"
|
|
|
|
|
|
|
|
|
|
|
|
GtkListStore *g_store;
|
|
|
|
|
|
|
|
enum { PROP_TITLE = 1, };
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-03-26 23:16:25 +00:00
|
|
|
GtkWidget *create_view(void)
|
2009-11-17 10:03:39 +00:00
|
|
|
{
|
2010-03-26 23:16:25 +00:00
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
GtkTreeViewColumn *col;
|
|
|
|
GtkTreeSelection *sel;
|
|
|
|
GtkListStore *liststore;
|
|
|
|
GtkWidget *view;
|
2009-11-17 10:03:39 +00:00
|
|
|
|
2010-03-26 23:16:25 +00:00
|
|
|
g_store = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING, GDK_TYPE_PIXBUF);
|
2009-11-17 10:03:39 +00:00
|
|
|
view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(g_store));
|
2010-03-26 23:16:25 +00:00
|
|
|
//gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
|
|
|
|
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view), TRUE);
|
|
|
|
//gtk_tree_view_set_fixed_height_mode(GTK_TREE_VIEW(view), TRUE);
|
2009-11-17 10:03:39 +00:00
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new();
|
2010-03-26 23:16:25 +00:00
|
|
|
col = gtk_tree_view_column_new();
|
|
|
|
gtk_tree_view_column_pack_start(col, renderer, TRUE);
|
|
|
|
gtk_tree_view_column_add_attribute(col, renderer, "text", COL_TEXT);
|
|
|
|
gtk_tree_view_column_set_title(col, " items 1 ");
|
2009-11-17 10:03:39 +00:00
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
|
2010-03-26 23:16:25 +00:00
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_pixbuf_new();
|
2009-11-17 10:03:39 +00:00
|
|
|
col = gtk_tree_view_column_new();
|
2010-03-26 23:16:25 +00:00
|
|
|
gtk_tree_view_column_pack_start(col, renderer, TRUE);
|
|
|
|
gtk_tree_view_column_add_attribute(col, renderer, "pixbuf", COL_PIX);
|
|
|
|
gtk_tree_view_column_set_title(col, " image ");
|
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
|
2009-11-17 10:03:39 +00:00
|
|
|
|
|
|
|
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
|
2010-03-26 23:16:25 +00:00
|
|
|
gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
|
|
|
|
g_signal_connect(sel, "changed", G_CALLBACK(on_changed), g_store);
|
2009-11-17 10:03:39 +00:00
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void on_changed(GtkWidget *widget, gpointer label)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
char *value;
|
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(widget), &model, &iter)) {
|
|
|
|
gtk_tree_model_get(model, &iter, COL_TEXT, &value, -1);
|
|
|
|
//gtk_label_set_text(GTK_LABEL(label), value);
|
|
|
|
g_free(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void add_to_list(GtkWidget *list, const gchar *str)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
2010-03-26 23:16:25 +00:00
|
|
|
gchar *cmd, *name, *snapshot;
|
|
|
|
GdkPixbuf *icon;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
//printf(" %s\n", str);
|
|
|
|
snapshot = g_build_filename (g_get_user_config_dir(), "tint2", "snap.jpg", NULL);
|
|
|
|
cmd = g_strdup_printf("tint2 -c \'%s\' -s \'%s\'", str, snapshot, NULL);
|
|
|
|
system(cmd);
|
|
|
|
|
|
|
|
icon = gdk_pixbuf_new_from_file(snapshot, &error);
|
|
|
|
g_free(snapshot);
|
|
|
|
if (error) {
|
|
|
|
g_warning ("Could not load icon: %s\n", error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
return;
|
2009-11-17 10:03:39 +00:00
|
|
|
}
|
|
|
|
|
2010-03-26 23:16:25 +00:00
|
|
|
gtk_list_store_append(g_store, &iter);
|
|
|
|
gtk_list_store_set(g_store, &iter, COL_TEXT, str, COL_PIX, icon, -1);
|
2009-11-17 10:03:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|