[zenity] Added support to --imagelist on tree. Thanks to Joshua Nathaniel Pritikin <jpritikin pobox com> now



commit c17eff5863009c69196e92520b150643f1f7937d
Author: Arx Cruz <arxcruz gnome org>
Date:   Thu Jul 19 14:22:25 2012 -0300

    Added support to --imagelist on tree. Thanks to Joshua Nathaniel Pritikin <jpritikin pobox com> now the first column can have an image.

 src/option.c |   16 ++++++++++++++++
 src/tree.c   |   53 +++++++++++++++++++++++++++++++++++++++++++++++------
 src/zenity.h |    1 +
 3 files changed, 64 insertions(+), 6 deletions(-)
---
diff --git a/src/option.c b/src/option.c
index 334ec86..ee0e9c2 100644
--- a/src/option.c
+++ b/src/option.c
@@ -78,6 +78,7 @@ static gboolean zenity_list_radiolist;
 static gchar   *zenity_list_print_column;
 static gchar   *zenity_list_hide_column;
 static gboolean zenity_list_hide_header;
+static gboolean zenity_list_imagelist;
 
 #ifdef HAVE_LIBNOTIFY
 /* Notification Dialog Options */
@@ -525,6 +526,15 @@ static GOptionEntry list_options[] = {
     NULL
   },
   {
+    "imagelist",
+    '\0',
+    0,
+    G_OPTION_ARG_NONE,
+    &zenity_list_imagelist,
+    N_("Use an image for first column"),
+    NULL
+  },
+  {
     "separator",
     '\0',
     G_OPTION_FLAG_NOALIAS,
@@ -1356,6 +1366,7 @@ zenity_list_pre_callback (GOptionContext *context,
   zenity_list_columns = NULL;
   zenity_list_checklist = FALSE;
   zenity_list_radiolist = FALSE;
+  zenity_list_imagelist = FALSE;
   zenity_list_hide_header = FALSE;
   zenity_list_print_column = NULL;
   zenity_list_hide_column = NULL;
@@ -1687,6 +1698,7 @@ zenity_list_post_callback (GOptionContext *context,
     
     results->tree_data->checkbox = zenity_list_checklist;
     results->tree_data->radiobox = zenity_list_radiolist;
+    results->tree_data->imagebox = zenity_list_imagelist;
     results->tree_data->multi = zenity_general_multiple;
     results->tree_data->editable = zenity_general_editable;
     results->tree_data->print_column = zenity_list_print_column;
@@ -1706,6 +1718,10 @@ zenity_list_post_callback (GOptionContext *context,
       zenity_option_error (zenity_option_get_name (list_options, &zenity_list_radiolist),
                            ERROR_SUPPORT);
 
+    if (zenity_list_imagelist)
+      zenity_option_error (zenity_option_get_name (list_options, &zenity_list_imagelist), 
+                           ERROR_SUPPORT);
+
     if (zenity_list_print_column)
       zenity_option_error (zenity_option_get_name (list_options, &zenity_list_print_column),
                            ERROR_SUPPORT);
diff --git a/src/tree.c b/src/tree.c
index b347b15..4234fc1 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -87,6 +87,44 @@ zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, g
   gtk_tree_path_free (path);
 }
 
+static void
+zenity_load_pixbuf (GtkTreeViewColumn *tree_column,
+                    GtkCellRenderer *cell,
+                    GtkTreeModel *tree_model,
+                    GtkTreeIter *iter,
+                    gpointer data)
+{
+  static GHashTable *pixbuf_cache = NULL;
+  GError *error = NULL;
+  GdkPixbuf *pixbuf;
+  gchar *str;
+
+  gtk_tree_model_get (tree_model, iter, 0, &str, -1);
+
+  if (!str) 
+    return;
+
+  if (!pixbuf_cache) {
+    pixbuf_cache = g_hash_table_new (g_str_hash, g_str_equal);
+    g_assert(pixbuf_cache);
+  }
+
+  pixbuf = g_hash_table_lookup (pixbuf_cache, str);
+
+  if (!pixbuf) {
+    pixbuf = gdk_pixbuf_new_from_file (str, &error);
+    if (!pixbuf) 
+      g_warning ("Failed to load '%s'", str);
+
+    g_hash_table_insert (pixbuf_cache, g_strdup (str), pixbuf);
+  }
+
+  if (pixbuf) 
+    g_object_set (cell, "pixbuf", pixbuf, NULL);
+
+  g_free (str);
+}
+
 static gboolean
 zenity_tree_handle_stdin (GIOChannel  *channel,
                           GIOCondition condition,
@@ -249,7 +287,7 @@ zenity_tree_fill_entries (GtkTreeView  *tree_view,
       GtkWidget *scrolled_window;
       GtkRequisition rectangle;
 
-      gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle);
+      gtk_widget_get_preferred_size (GTK_WIDGET (tree_view), &rectangle, NULL);
       scrolled_window = GTK_WIDGET (gtk_builder_get_object (builder,
       							 "zenity_tree_window"));
       gtk_widget_set_size_request (scrolled_window, -1, rectangle.height);
@@ -329,7 +367,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
     return;
   }
 
-  if (tree_data->checkbox && tree_data->radiobox) {
+  if (tree_data->checkbox + tree_data->radiobox + tree_data->imagebox > 1) {
     g_printerr (_("You should use only one List dialog type.\n")); 
     data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
     return;
@@ -433,6 +471,12 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
         column = gtk_tree_view_column_new_with_attributes (tmp->data,
                                                            cell_renderer, 
                                                            "active", column_index, NULL);
+      } else if (tree_data->imagebox) {
+        GtkCellRenderer *cell_renderer = gtk_cell_renderer_pixbuf_new ();
+        column = gtk_tree_view_column_new_with_attributes (tmp->data,
+                                                           cell_renderer, NULL);
+        gtk_tree_view_column_set_cell_data_func (column, cell_renderer, 
+                                                 zenity_load_pixbuf, NULL, NULL);
       }
       else  {
         if (tree_data->editable) {
@@ -657,10 +701,7 @@ zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path,
 {
   ZenityData *zen_data = data;
   GtkTreeSelection *selection; 
-  GtkTreeModel *model;
-
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
-
+  
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
   gtk_tree_selection_selected_foreach (selection, 
                                        (GtkTreeSelectionForeachFunc) zenity_tree_dialog_get_selected, 
diff --git a/src/zenity.h b/src/zenity.h
index c5414fe..30c497b 100644
--- a/src/zenity.h
+++ b/src/zenity.h
@@ -121,6 +121,7 @@ typedef struct {
   gboolean      checkbox;
   gboolean      radiobox;
   gboolean      hide_header;
+  gboolean      imagebox;
   gchar        *separator;
   gboolean      multi;
   gboolean      editable;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]