From c51ef797a707f4e2c6f9688d4378f2b0e9898a66 Mon Sep 17 00:00:00 2001 From: Perberos Date: Thu, 1 Dec 2011 22:56:10 -0300 Subject: moving from https://github.com/perberos/mate-desktop-environment --- mate-panel/libpanel-util/panel-gtk.c | 83 ++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 mate-panel/libpanel-util/panel-gtk.c (limited to 'mate-panel/libpanel-util/panel-gtk.c') diff --git a/mate-panel/libpanel-util/panel-gtk.c b/mate-panel/libpanel-util/panel-gtk.c new file mode 100644 index 00000000..097367fb --- /dev/null +++ b/mate-panel/libpanel-util/panel-gtk.c @@ -0,0 +1,83 @@ +/* + * panel-gtk.c: various small extensions to gtk+ + * + * Copyright (C) 2010 Novell, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Authors: + * Vincent Untz + */ + +#include + +#include "panel-gtk.h" + +/* + * Originally based on code from panel-properties-dialog.c. This part of the + * code was: + * Copyright (C) 2005 Vincent Untz + */ + +static void +panel_gtk_file_chooser_preview_update (GtkFileChooser *chooser, + gpointer data) +{ + GtkWidget *preview; + char *filename; + GdkPixbuf *pixbuf; + gboolean have_preview; + + preview = GTK_WIDGET (data); + filename = gtk_file_chooser_get_preview_filename (chooser); + + if (filename == NULL) + return; + + 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 (chooser, + have_preview); +} + +void +panel_gtk_file_chooser_add_image_preview (GtkFileChooser *chooser) +{ + GtkFileFilter *filter; + GtkWidget *chooser_preview; + + g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser)); + + filter = gtk_file_filter_new (); + gtk_file_filter_add_pixbuf_formats (filter); + gtk_file_chooser_set_filter (chooser, filter); + + chooser_preview = gtk_image_new (); + gtk_file_chooser_set_preview_widget (chooser, chooser_preview); + g_signal_connect (chooser, "update-preview", + G_CALLBACK (panel_gtk_file_chooser_preview_update), + chooser_preview); +} + +/* + * End of code coming from panel-properties-dialog.c + */ -- cgit v1.2.1