static GtkWidget *
create_emblem_widget (NautilusEmblemSidebar *emblem_sidebar,
		      const char *name)
{
	GtkWidget *ret;
	const char *display_name;
	char *keyword;
	GdkPixbuf *pixbuf;
	NautilusIconInfo *info;

	info = nautilus_icon_info_lookup_from_name (name, NAUTILUS_ICON_SIZE_STANDARD);

	pixbuf = nautilus_icon_info_get_pixbuf_at_size (info, NAUTILUS_ICON_SIZE_STANDARD);
	
	display_name = nautilus_icon_info_get_display_name (info);
	
	keyword = nautilus_emblem_get_keyword_from_icon_name (name);
	if (display_name == NULL) {
		display_name = keyword;
	}

	ret = create_emblem_widget_with_pixbuf (emblem_sidebar, keyword,
						display_name, pixbuf);
	g_free (keyword);
	g_object_unref (info);
	return ret;
}
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);
}
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);
    }
}
Example #4
0
static void
nautilus_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value)
{
	NautilusListModel *model;
	FileEntry *file_entry;
	NautilusFile *file;
	char *str;
	GdkPixbuf *icon, *rendered_icon;
	GIcon *gicon, *emblemed_icon, *emblem_icon;
	NautilusIconInfo *icon_info;
	GEmblem *emblem;
	GList *emblem_icons, *l;
	int icon_size, icon_scale;
	NautilusZoomLevel zoom_level;
	NautilusFileIconFlags flags;
	cairo_surface_t *surface;
	
	model = (NautilusListModel *)tree_model;

	g_return_if_fail (model->details->stamp == iter->stamp);
	g_return_if_fail (!g_sequence_iter_is_end (iter->user_data));

	file_entry = g_sequence_get (iter->user_data);
	file = file_entry->file;
	
	switch (column) {
	case NAUTILUS_LIST_MODEL_FILE_COLUMN:
		g_value_init (value, NAUTILUS_TYPE_FILE);

		g_value_set_object (value, file);
		break;
	case NAUTILUS_LIST_MODEL_SUBDIRECTORY_COLUMN:
		g_value_init (value, NAUTILUS_TYPE_DIRECTORY);

		g_value_set_object (value, file_entry->subdirectory);
		break;
	case NAUTILUS_LIST_MODEL_SMALLEST_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_SMALLER_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_SMALL_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_STANDARD_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_LARGE_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_LARGER_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_LARGEST_ICON_COLUMN:
		g_value_init (value, CAIRO_GOBJECT_TYPE_SURFACE);

		if (file != NULL) {
			zoom_level = nautilus_list_model_get_zoom_level_from_column_id (column);
			icon_size = nautilus_get_icon_size_for_zoom_level (zoom_level);
			icon_scale = nautilus_list_model_get_icon_scale (model);

			flags = NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS |
				NAUTILUS_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE |
				NAUTILUS_FILE_ICON_FLAGS_USE_MOUNT_ICON_AS_EMBLEM;
			if (model->details->drag_view != NULL) {
				GtkTreePath *path_a, *path_b;
				
				gtk_tree_view_get_drag_dest_row (model->details->drag_view,
								 &path_a,
								 NULL);
				if (path_a != NULL) {
					path_b = gtk_tree_model_get_path (tree_model, iter);

					if (gtk_tree_path_compare (path_a, path_b) == 0) {
						flags |= NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
					}
						
					gtk_tree_path_free (path_a);
					gtk_tree_path_free (path_b);
				}
			}

			gicon = G_ICON (nautilus_file_get_icon_pixbuf (file, icon_size, TRUE, icon_scale, flags));
			emblem_icons = nautilus_file_get_emblem_icons (file);

			/* pick only the first emblem we can render for the list view */
			for (l = emblem_icons; l != NULL; l = l->next) {
				emblem_icon = l->data;
				if (nautilus_icon_theme_can_render (G_THEMED_ICON (emblem_icon))) {
					emblem = g_emblem_new (emblem_icon);
					emblemed_icon = g_emblemed_icon_new (gicon, emblem);

					g_object_unref (gicon);
					g_object_unref (emblem);
					gicon = emblemed_icon;

					break;
				}
			}

			g_list_free_full (emblem_icons, g_object_unref);

			icon_info = nautilus_icon_info_lookup (gicon, icon_size, icon_scale);
			icon = nautilus_icon_info_get_pixbuf_at_size (icon_info, icon_size);

			g_object_unref (icon_info);
			g_object_unref (gicon);

			if (model->details->highlight_files != NULL &&
			    g_list_find_custom (model->details->highlight_files,
			                        file, (GCompareFunc) nautilus_file_compare_location))
			{
				rendered_icon = eel_create_spotlight_pixbuf (icon);

				if (rendered_icon != NULL) {
					g_object_unref (icon);
					icon = rendered_icon;
				}
			}

			surface = gdk_cairo_surface_create_from_pixbuf (icon, icon_scale, NULL);
			g_value_take_boxed (value, surface);
			g_object_unref (icon);
		}
		break;
	case NAUTILUS_LIST_MODEL_FILE_NAME_IS_EDITABLE_COLUMN:
		g_value_init (value, G_TYPE_BOOLEAN);
		
                g_value_set_boolean (value, file != NULL && nautilus_file_can_rename (file));
                break;
 	default:
 		if (column >= NAUTILUS_LIST_MODEL_NUM_COLUMNS || column < NAUTILUS_LIST_MODEL_NUM_COLUMNS + model->details->columns->len) {
			NautilusColumn *nautilus_column;
			GQuark attribute;
			nautilus_column = model->details->columns->pdata[column - NAUTILUS_LIST_MODEL_NUM_COLUMNS];
			
			g_value_init (value, G_TYPE_STRING);
			g_object_get (nautilus_column, 
				      "attribute_q", &attribute, 
				      NULL);
			if (file != NULL) {
				str = nautilus_file_get_string_attribute_with_default_q (file, 
											 attribute);
				g_value_take_string (value, str);
			} else if (attribute == attribute_name_q) {
				if (file_entry->parent->loaded) {
					g_value_set_string (value, _("(Empty)"));
				} else {
					g_value_set_string (value, _("Loading…"));
				}
			}
		} else {
			g_assert_not_reached ();
		}
	}
}