+static void
+update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
+{
+ GtkWidget *preview;
+ char *filename;
+ GdkPixbuf *pixbuf;
+ gboolean have_preview;
+
+ preview = GTK_WIDGET (data);
+ filename = gtk_file_chooser_get_preview_filename (file_chooser);
+
+ pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
+ have_preview = (pixbuf != NULL);
+ g_free (filename);
+
+ gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
+ if (pixbuf)
+ g_object_unref (pixbuf);
+
+ gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
+}
+
+static void
+categoria_on_btn_icona_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ GtkWidget *dlg;
+ GtkWidget *preview;
+
+ Categoria *categoria = (Categoria *)user_data;
+ CategoriaPrivate *priv = CATEGORIA_GET_PRIVATE (categoria);
+
+ preview = gtk_image_new ();
+
+ dlg = gtk_file_chooser_dialog_new ("Scegli icona",
+ GTK_WINDOW (priv->w),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dlg), preview);
+ g_signal_connect (dlg, "update-preview",
+ G_CALLBACK (update_preview_cb), preview);
+
+ if (gtk_dialog_run (GTK_DIALOG (dlg)) == GTK_RESPONSE_ACCEPT)
+ {
+ gchar *filename;
+
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlg));
+
+ gtk_image_set_from_file (GTK_IMAGE (gtk_builder_get_object (priv->commons->gtkbuilder, "image1")), filename);
+ if (gtk_image_get_pixbuf (GTK_IMAGE (gtk_builder_get_object (priv->commons->gtkbuilder, "image1"))) != NULL)
+ {
+ gtk_label_set_text (GTK_LABEL (priv->lbl_icona_percorso), filename);
+ }
+ else
+ {
+ gtk_label_set_text (GTK_LABEL (priv->lbl_icona_percorso), "");
+ }
+
+ g_free (filename);
+ }
+ gtk_widget_destroy (dlg);
+}
+