GtkAction *
nautilus_action_from_menu_item (NautilusMenuItem *item)
{
	char *name, *label, *tip, *icon_name;
	gboolean sensitive, priority;
	GtkAction *action;
	GdkPixbuf *pixbuf;
	NautilusIconInfo *info;
	
	g_object_get (G_OBJECT (item), 
		      "name", &name, "label", &label, 
		      "tip", &tip, "icon", &icon_name,
		      "sensitive", &sensitive,
		      "priority", &priority,
		      NULL);
	
	action = gtk_action_new (name,
				 label,
				 tip,
				 icon_name);
	
	if (icon_name != NULL) {
		info = nautilus_icon_info_lookup_from_name (icon_name,
							    nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU));

		pixbuf = nautilus_icon_info_get_pixbuf_nodefault_at_size (info,
									  nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU));
		if (pixbuf != NULL) {
			g_object_set_data_full (G_OBJECT (action), "menu-icon",
						pixbuf,
						g_object_unref);
		}
		g_object_unref (info);
	}
	
	gtk_action_set_sensitive (action, sensitive);
	g_object_set (action, "is-important", priority, NULL);
	
	g_signal_connect_data (action, "activate",
			       G_CALLBACK (extension_action_callback),
			       g_object_ref (item), 
			       (GClosureNotify)g_object_unref, 0);
	
	g_free (name);
	g_free (label);
	g_free (tip);
	g_free (icon_name);
	
	return action;
}
GdkPixbuf *
nautilus_ui_get_menu_icon (const char *icon_name)
{
	NautilusIconInfo *info;
	GdkPixbuf *pixbuf;
	int size;

	size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);

	if (g_path_is_absolute (icon_name)) {
		info = nautilus_icon_info_lookup_from_path (icon_name, size);
	} else {
		info = nautilus_icon_info_lookup_from_name (icon_name, size);
	}
	pixbuf = nautilus_icon_info_get_pixbuf_nodefault_at_size (info, size);
	g_object_unref (info);

	return pixbuf;
}
static void
nautilus_file_management_properties_dialog_setup_media_page (GladeXML *xml_dialog)
{
	unsigned int n;
	GList *l;
	GList *content_types;
	GtkWidget *other_type_combo_box;
	GtkListStore *other_type_list_store;
	GtkCellRenderer *renderer;
	GtkTreeIter iter;
	const char *s[] = {"media_audio_cdda_combobox",   "x-content/audio-cdda",
			   "media_video_dvd_combobox",    "x-content/video-dvd",
			   "media_music_player_combobox", "x-content/audio-player",
			   "media_dcf_combobox",          "x-content/image-dcf",
			   "media_software_combobox",     "x-content/software",
			   NULL};

	for (n = 0; s[n*2] != NULL; n++) {
		nautilus_autorun_prepare_combo_box (glade_xml_get_widget (xml_dialog, s[n*2]), s[n*2 + 1],
						    TRUE, TRUE, NULL, NULL); 
	}

	other_type_combo_box = glade_xml_get_widget (xml_dialog, "media_other_type_combobox");

	other_type_list_store = gtk_list_store_new (3, 
						    GDK_TYPE_PIXBUF, 
						    G_TYPE_STRING, 
						    G_TYPE_STRING);

	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (other_type_list_store),
					      1, GTK_SORT_ASCENDING);


	content_types = g_content_types_get_registered ();

	for (l = content_types; l != NULL; l = l->next) {
		char *content_type = l->data;
		char *description;
		GIcon *icon;
		NautilusIconInfo *icon_info;
		GdkPixbuf *pixbuf;
		int icon_size;

		if (!g_str_has_prefix (content_type, "x-content/"))
			continue;
		for (n = 0; s[n*2] != NULL; n++) {
			if (strcmp (content_type, s[n*2 + 1]) == 0) {
				goto skip;
			}
		}

		icon_size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);

		description = g_content_type_get_description (content_type);
		gtk_list_store_append (other_type_list_store, &iter);
		icon = g_content_type_get_icon (content_type);
		if (icon != NULL) {
			icon_info = nautilus_icon_info_lookup (icon, icon_size);
			g_object_unref (icon);
			pixbuf = nautilus_icon_info_get_pixbuf_nodefault_at_size (icon_info, icon_size);
			g_object_unref (icon_info);
		} else {
			pixbuf = NULL;
		}

		gtk_list_store_set (other_type_list_store, &iter, 
				    0, pixbuf, 
				    1, description, 
				    2, content_type, 
				    -1);
		if (pixbuf != NULL)
			g_object_unref (pixbuf);
		g_free (description);
	skip:
		;
	}
	g_list_foreach (content_types, (GFunc) g_free, NULL);
	g_list_free (content_types);

	gtk_combo_box_set_model (GTK_COMBO_BOX (other_type_combo_box), GTK_TREE_MODEL (other_type_list_store));
	
	renderer = gtk_cell_renderer_pixbuf_new ();
	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (other_type_combo_box), renderer, FALSE);
	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (other_type_combo_box), renderer,
					"pixbuf", 0,
					NULL);
	renderer = gtk_cell_renderer_text_new ();
	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (other_type_combo_box), renderer, TRUE);
	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (other_type_combo_box), renderer,
					"text", 1,
					NULL);

	g_signal_connect (G_OBJECT (other_type_combo_box),
			  "changed",
			  G_CALLBACK (other_type_combo_box_changed),
			  glade_xml_get_widget (xml_dialog, "media_other_action_combobox"));

	gtk_combo_box_set_active (GTK_COMBO_BOX (other_type_combo_box), 0);

	nautilus_file_management_properties_dialog_update_media_sensitivity (xml_dialog);
}
void
nautilus_x_content_bar_set_x_content_type (NautilusXContentBar *bar, const char *x_content_type)
{					  
	char *message;
	char *description;
	GAppInfo *default_app;

	g_free (bar->priv->x_content_type);
	bar->priv->x_content_type = g_strdup (x_content_type);

	description = g_content_type_get_description (x_content_type);

	/* Customize greeting for well-known x-content types */
	if (strcmp (x_content_type, "x-content/audio-cdda") == 0) {
		message = g_strdup (_("These files are on an Audio CD."));
	} else if (strcmp (x_content_type, "x-content/audio-dvd") == 0) {
		message = g_strdup (_("These files are on an Audio DVD."));
	} else if (strcmp (x_content_type, "x-content/video-dvd") == 0) {
		message = g_strdup (_("These files are on a Video DVD."));
	} else if (strcmp (x_content_type, "x-content/video-vcd") == 0) {
		message = g_strdup (_("These files are on a Video CD."));
	} else if (strcmp (x_content_type, "x-content/video-svcd") == 0) {
		message = g_strdup (_("These files are on a Super Video CD."));
	} else if (strcmp (x_content_type, "x-content/image-photocd") == 0) {
		message = g_strdup (_("These files are on a Photo CD."));
	} else if (strcmp (x_content_type, "x-content/image-picturecd") == 0) {
		message = g_strdup (_("These files are on a Picture CD."));
	} else if (strcmp (x_content_type, "x-content/image-dcf") == 0) {
		message = g_strdup (_("The media contains digital photos."));
	} else if (strcmp (x_content_type, "x-content/audio-player") == 0) {
		message = g_strdup (_("These files are on a digital audio player."));
	} else if (strcmp (x_content_type, "x-content/software") == 0) {
		message = g_strdup (_("The media contains software."));
	} else {
		/* fallback to generic greeting */
		message = g_strdup_printf (_("The media has been detected as \"%s\"."), description);
	}


	gtk_label_set_text (GTK_LABEL (bar->priv->label), message);
	gtk_widget_show (bar->priv->label);

	/* TODO: We really need a GtkBrowserBackButton-ish widget here.. until then, we only
	 *       show the default application. */

 	default_app = g_app_info_get_default_for_type (x_content_type, FALSE);
	if (default_app != NULL) {
		char *button_text;
		const char *name;
		GIcon *icon;
		GtkWidget *image;

		icon = g_app_info_get_icon (default_app);
		if (icon != NULL) {
			GdkPixbuf *pixbuf;
			int icon_size;
			NautilusIconInfo *icon_info;
			icon_size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON);
			icon_info = nautilus_icon_info_lookup (icon, icon_size);
			pixbuf = nautilus_icon_info_get_pixbuf_at_size (icon_info, icon_size);
			image = gtk_image_new_from_pixbuf (pixbuf);
			g_object_unref (pixbuf);
			g_object_unref (icon_info);
		} else {
			image = NULL;
		}

		name = g_app_info_get_name (default_app);
		button_text = g_strdup_printf (_("Open %s"), name);

		gtk_button_set_image (GTK_BUTTON (bar->priv->button), image);
		gtk_button_set_label (GTK_BUTTON (bar->priv->button), button_text);
		gtk_widget_show (bar->priv->button);
		g_free (button_text);
		g_object_unref (default_app);
	} else {
		gtk_widget_hide (bar->priv->button);
	}

	g_free (message);
	g_free (description);
}
Esempio n. 5
0
static void
present_autorun_for_software_dialog (GMount *mount)
{
    GIcon *icon;
    int icon_size;
    g_autoptr (NautilusIconInfo) icon_info = NULL;
    g_autoptr (GdkPixbuf) pixbuf = NULL;
    g_autofree char *mount_name = NULL;
    GtkWidget *dialog;
    AutorunSoftwareDialogData *data;

    mount_name = g_mount_get_name (mount);

    dialog = gtk_message_dialog_new (NULL,     /* TODO: parent window? */
                                     0,
                                     GTK_MESSAGE_OTHER,
                                     GTK_BUTTONS_CANCEL,
                                     _("“%s” contains software intended to be automatically started. Would you like to run it?"),
                                     mount_name);
    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
                                              "%s",
                                              _("If you don’t trust this location or aren’t sure, press Cancel."));

    /* This is required because we don't show dialogs in the
     *  window picker and if the window pops under another window
     *  there is no way to get it back. */
    gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);

    /* TODO: in a star trek future add support for verifying
     * software on media (e.g. if it has a certificate, check it
     * etc.)
     */


    icon = g_mount_get_icon (mount);
    icon_size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_DIALOG);
    icon_info = nautilus_icon_info_lookup (icon, icon_size,
                                           gtk_widget_get_scale_factor (GTK_WIDGET (dialog)));
    pixbuf = nautilus_icon_info_get_pixbuf_at_size (icon_info, icon_size);

    gtk_window_set_icon (GTK_WINDOW (dialog), pixbuf);

    data = g_new0 (AutorunSoftwareDialogData, 1);
    data->dialog = dialog;
    data->mount = g_object_ref (mount);

    g_signal_connect (G_OBJECT (mount),
                      "unmounted",
                      G_CALLBACK (autorun_software_dialog_mount_unmounted),
                      data);

    gtk_dialog_add_button (GTK_DIALOG (dialog),
                           _("_Run"),
                           GTK_RESPONSE_OK);

    gtk_widget_show_all (dialog);

    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
    {
        gtk_widget_destroy (dialog);
        autorun (mount);
    }
}