示例#1
0
/* Sets, unsets or changes the pathname and name for an icon.
 * Updates icons_hash and (re)stats the item.
 * If name is NULL then gets the leafname from pathname.
 * If pathname is NULL, frees everything.
 */
void icon_set_path(Icon *icon, const char *pathname, const char *name)
{
	if (icon->path)
	{
		icon_unhash_path(icon);
		icon->src_path = NULL;
		icon->path = NULL;

		diritem_free(icon->item);
		icon->item = NULL;
	}

	if (pathname)
	{
		if (g_utf8_validate(pathname, -1, NULL))
			icon->src_path = g_strdup(pathname);
		else
			icon->src_path = to_utf8(pathname);
		icon->path = expand_path(icon->src_path);

		icon_hash_path(icon);

		if (!name)
			name = g_basename(icon->src_path);

		icon->item = diritem_new(name);
		diritem_restat(icon->path, icon->item, NULL);
	}
}
示例#2
0
文件: run.c 项目: eisnerd/rox-filer
/* Convert uri to path and call run_by_path() */
gboolean run_by_uri(const gchar *uri, gchar **errmsg)
{
	gboolean retval;
	gchar *tmp, *tmp2;
	gchar *scheme;
	gchar *cmd;

	scheme=get_uri_scheme((EscapedPath *) uri);
	if(!scheme)
	{
		*errmsg=g_strdup_printf(_("'%s' is not a valid URI"),
						uri);
		return FALSE;
	}

	if(strcmp(scheme, "file")==0) {
		tmp=get_local_path((EscapedPath *) uri);
		if(tmp) {
			tmp2=pathdup(tmp);
			retval=run_by_path(tmp2);
			if(!retval)
				*errmsg=g_strdup_printf(_("%s not accessable"),
							tmp);
		
			g_free(tmp2);
			g_free(tmp);

		} else {
			retval=FALSE;
			*errmsg=g_strdup_printf(_("Non-local URL %s"), uri);
		}

	} else if((cmd=choices_find_xdg_path_load(scheme, "URI", SITE))) {
		DirItem *item;

		item=diritem_new(scheme);
		diritem_restat(cmd, item, NULL);

		run_with_args(cmd, item, uri);
		retval=TRUE; /* we hope... */

		diritem_free(item);
		g_free(cmd);
		
	} else {
		retval=FALSE;
		*errmsg=g_strdup_printf(_("%s: no handler for %s"),
					uri, scheme);
	}
	
	g_free(scheme);

	return retval;
}
示例#3
0
文件: run.c 项目: eisnerd/rox-filer
/* Attempt to open this item */
gboolean run_by_path(const guchar *full_path)
{
	gboolean retval;
	DirItem	*item;

	/* XXX: Loads an image - wasteful */
	item = diritem_new("");
	diritem_restat(full_path, item, NULL);
	retval = run_diritem(full_path, item, NULL, NULL, FALSE);
	diritem_free(item);
	
	return retval;
}
示例#4
0
文件: mimetype.c 项目: EQ4/samplecat
/* Get the type of this file - stats the file and uses that if
 * possible. For regular or missing files, uses the pathname.
 */
MIME_type *type_get_type(const guchar *path)
{
	DirItem		*item;
	MIME_type	*type = NULL;

	item = diritem_new((guchar*)"");
	diritem_restat(path, item, NULL);
	if (item->base_type != TYPE_ERROR)
		type = item->mime_type;
	diritem_free(item);

	if (type)
		return type;

	type = type_from_path((char*)path);

	if (!type)
		return text_plain;

	return type;
}
示例#5
0
/* Load image 'path' in the background and insert into pixmap_cache.
 * Call callback(data, path) when done (path is NULL => error).
 * If the image is already uptodate, or being created already, calls the
 * callback right away.
 */
void
pixmap_background_thumb(const gchar *path, GFunc callback, gpointer data)
{
	gboolean	found = FALSE;

	MaskedPixmap* image = g_fscache_lookup_full(pixmap_cache, path, FSCACHE_LOOKUP_ONLY_NEW, &found);

	if (found)
	{
		dbg(0, "found");
		// Thumbnail is known, or being created
		if (image) g_object_unref(image);
		callback(data, NULL);
		return;
	}

	dbg(0, "FIXME not found");
#if 0
	pid_t		child;
	ChildThumbnail	*info;
	g_return_if_fail(image == NULL);

	GdkPixbuf* pixbuf = get_thumbnail_for(path);
	
	if (!pixbuf)
	{
		struct stat info1, info2;
		char *dir;

		dir = g_path_get_dirname(path);

		// If the image itself is in ~/.thumbnails, load it now (ie, don't create thumbnails for thumbnails!).
		if (stat(dir, &info1) != 0)
		{
			callback(data, NULL);
			g_free(dir);
			return;
		}
		g_free(dir);

		if (stat(make_path(home_dir, ".thumbnails/normal"),
			    &info2) == 0 &&
			    info1.st_dev == info2.st_dev &&
			    info1.st_ino == info2.st_ino)
		{
			pixbuf = rox_pixbuf_new_from_file_at_scale(path, PIXMAP_THUMB_SIZE, PIXMAP_THUMB_SIZE, TRUE, NULL);
			if (!pixbuf)
			{
				g_fscache_insert(pixmap_cache, path, NULL, TRUE);
				callback(data, NULL);
				return;
			}
		}
	}
		
	if (pixbuf)
	{
		MaskedPixmap *image;

		image = masked_pixmap_new(pixbuf);
		gdk_pixbuf_unref(pixbuf);
		g_fscache_insert(pixmap_cache, path, image, TRUE);
		callback(data, (gchar *) path);
		g_object_unref(G_OBJECT(image));
		return;
	}

	MIME_type* type = type_from_path(path);
	if (!type) type = text_plain;

	// Add an entry, set to NULL, so no-one else tries to load this image.
	g_fscache_insert(pixmap_cache, path, NULL, TRUE);

	gchar* thumb_prog = thumbnail_program(type);

	// Only attempt to load 'images' types ourselves
	if (thumb_prog == NULL && strcmp(type->media_type, "image") != 0)
	{
		callback(data, NULL);
		return;		// Don't know how to handle this type
	}

	child = fork();

	if (child == -1)
	{
		g_free(thumb_prog);
		delayed_error("fork(): %s", g_strerror(errno));
		callback(data, NULL);
		return;
	}

	if (child == 0)
	{
		// We are the child process.  (We are sloppy with freeing memory, but since we go away very quickly, that's ok.)
		if (thumb_prog)
		{
			DirItem *item;
			
			item = diritem_new(g_basename(thumb_prog));

			diritem_restat(thumb_prog, item, NULL);
			if (item->flags & ITEM_FLAG_APPDIR)
				thumb_prog = g_strconcat(thumb_prog, "/AppRun",
						       NULL);

			execl(thumb_prog, thumb_prog, path,
			      thumbnail_path(path),
			      g_strdup_printf("%d", PIXMAP_THUMB_SIZE),
			      NULL);
			_exit(1);
		}

		child_create_thumbnail(path);
		_exit(0);
	}

	g_free(thumb_prog);

	info = g_new(ChildThumbnail, 1);
	info->path = g_strdup(path);
	info->callback = callback;
	info->data = data;
	on_child_death(child, (CallbackFn) thumbnail_child_done, info);
#endif
}