Exemple #1
0
/**
 * gul_gui_image_set_from_mime_type:
 * @image: a #GtkImage
 * @mime_type: a MIME type
 * @icon_size: a stock icon size
 *
 * Set the @image to display the icon for MIME type @mime_type.  Sample MIME
 * types are "text/plain", "application/ogg".  Sample stock sizes are
 * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_DIALOG.
 */
void
gul_gui_image_set_from_mime_type (GtkWidget  *image,
		                  const char *mime_type,
				  GtkIconSize icon_size)
{
	GtkIconTheme *theme;
	char           *icon;
	GtkIconSource  *source;
	GtkIconSet     *icon_set;

	g_return_if_fail (GTK_IS_IMAGE(image));
	g_return_if_fail (mime_type != NULL);

	theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (image));

	icon = gnome_icon_lookup (theme, NULL, NULL, NULL, NULL,
				  mime_type,
				  GNOME_ICON_LOOKUP_FLAGS_NONE, NULL);

	if (!g_path_is_absolute (icon))
	{
		int   width, height;
		GtkIconInfo *icon_info;

		if (!gtk_icon_size_lookup_for_settings 
			(gtk_widget_get_settings (GTK_WIDGET(image)),
			 icon_size, &width, &height))
		{
			width = height = -1;
		}

		icon_info = gtk_icon_theme_lookup_icon (theme, icon, height,0);
		g_free (icon);

		g_return_if_fail (icon_info != NULL);

		icon = g_strdup (gtk_icon_info_get_filename (icon_info));
		gtk_icon_info_free (icon_info);
	}

	/* Now that we have the icon filename, wrap it into an GtkIconSet so
	 * that we really get the desired size; the icon size in the file may
	 * still be arbitrary, in case of SVG themes, for example.
	 */

	source = gtk_icon_source_new ();
	gtk_icon_source_set_filename (source, icon);
	g_free (icon);

	icon_set = gtk_icon_set_new ();
	gtk_icon_set_add_source (icon_set, source);
	gtk_icon_source_free (source);

	gtk_image_set_from_icon_set (GTK_IMAGE(image), icon_set, icon_size);

	gtk_icon_set_unref (icon_set);
}
Exemple #2
0
static VALUE
rg_set_from_icon_set(int argc, VALUE *argv, VALUE self)
{
    GtkImage *image;
    VALUE rb_icon_set, rb_size;

    image = RVAL2GTKIMAGE(self);
    rb_scan_args(argc, argv, "11", &rb_icon_set, &rb_size);
    gtk_image_set_from_icon_set(image,
                                RVAL2GTKICONSET(rb_icon_set),
                                icon_size_from_ruby(image, rb_size));
    return self;
}
Exemple #3
0
void nsgtk_about_dialog_init(GtkWindow *parent,
			     struct browser_window *bw,
			     const char *version)
{
	GtkWidget *dialog, *vbox, *button, *image, *label;
	gchar *name_string;
	GList *pixbufs = gtk_window_get_default_icon_list();

	name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">NetSurf %s</span>", version);


	/* Create the widgets */
	dialog = gtk_dialog_new_with_buttons("About NetSurf",
					     parent,
					     GTK_DIALOG_DESTROY_WITH_PARENT,
					     NULL);

	vbox = gtk_vbox_new (FALSE, 8);

	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), vbox, TRUE, TRUE, 0);
	
	if (pixbufs != NULL) {
		GtkIconSet *icon_set = gtk_icon_set_new_from_pixbuf(GDK_PIXBUF(g_list_nth_data(pixbufs, 0)));

		image = gtk_image_new();

		gtk_image_set_from_icon_set (GTK_IMAGE (image),
					     icon_set, GTK_ICON_SIZE_DIALOG);

		gtk_icon_set_unref (icon_set);
		g_list_free (pixbufs);

		gtk_box_pack_start(GTK_BOX (vbox), image, FALSE, FALSE, 0);
	}
	

	label = gtk_label_new (NULL);
	gtk_label_set_markup (GTK_LABEL (label), name_string);
	g_free (name_string);
	gtk_label_set_selectable (GTK_LABEL (label), TRUE);
	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
	gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

        label = gtk_label_new("NetSurf is a small fast web browser");
	gtk_label_set_selectable(GTK_LABEL (label), TRUE);
	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
	gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
	gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

	label = gtk_label_new("Copyright © 2003 - 2012 The NetSurf Developers");
	gtk_label_set_selectable(GTK_LABEL(label), TRUE);
	gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
	gtk_box_pack_start(GTK_BOX (vbox), label, FALSE, FALSE, 0);


	nsgtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);

	/* Add the OK button */
	gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
	gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE);

	/* Add the credits button */
	button = gtk_button_new_from_stock ("Credits");
	gtk_box_pack_end(GTK_BOX (GTK_DIALOG (dialog)->action_area),
			 button, FALSE, TRUE, 0);
	gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (dialog)->action_area), button, TRUE);
	g_signal_connect(button, "clicked", G_CALLBACK(nsgtk_about_dialog_credits), (gpointer)bw);

	/* Add the Licence button */
	button = gtk_button_new_from_stock ("Licence");
	gtk_box_pack_end(GTK_BOX (GTK_DIALOG (dialog)->action_area),
			 button, FALSE, TRUE, 0);
	gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (dialog)->action_area), button, TRUE);
	g_signal_connect(button, "clicked", G_CALLBACK(nsgtk_about_dialog_licence), (gpointer)bw);


	/* Ensure that the dialog box is destroyed when the user responds. */
	g_signal_connect_swapped(dialog,
				  "response",
				  G_CALLBACK (gtk_widget_destroy),
				  dialog);

	/* Add the label, and show everything we've added to the dialog. */
	gtk_widget_show_all(dialog);
}