コード例 #1
0
ファイル: copy.c プロジェクト: DeforaOS/Browser
static gboolean _copy_idle_first(gpointer data)
{
	Copy * copy = data;
	char const * filename = copy->filev[copy->filec - 1];
	struct stat st;

	if(browser_vfs_stat(filename, &st) != 0)
	{
		if(errno != ENOENT)
			_copy_filename_error(copy, filename, 0);
		else if(copy->filec > 2)
		{
			errno = ENOTDIR;
			_copy_filename_error(copy, filename, 0);
		}
		else
			_copy_single(copy, copy->filev[0], copy->filev[1]);
	}
	else if(S_ISDIR(st.st_mode))
	{
		g_idle_add(_copy_idle_multiple, copy);
		return FALSE;
	}
	else if(copy->filec > 2)
	{
		errno = ENOTDIR;
		_copy_filename_error(copy, filename, 0);
	}
	else
		_copy_single(copy, copy->filev[0], copy->filev[1]);
	gtk_main_quit();
	return FALSE;
}
コード例 #2
0
static void _on_add_filename(gchar const * pathname, gpointer data)
{
	const char scheme[] = "file://";
	Favorites * favorites = data;
	GtkTreeIter iter;
	struct stat st;
	gchar * filename;
	String * path;
	gint size = 24;
	GdkPixbuf * pixbuf;

	/* XXX ignore non-directories */
	if(browser_vfs_stat(pathname, &st) != 0 || !S_ISDIR(st.st_mode))
		return;
	if((filename = g_path_get_basename(pathname)) == NULL)
		return;
	if((path = string_new_append(scheme, pathname, NULL)) == NULL)
		return;
	gtk_icon_size_lookup(GTK_ICON_SIZE_BUTTON, &size, &size);
	if((pixbuf = browser_vfs_mime_icon(favorites->mime, pathname, NULL,
					NULL, &st, size)) == NULL)
		pixbuf = favorites->folder;
#if GTK_CHECK_VERSION(2, 6, 0)
	gtk_list_store_insert_with_values(favorites->store, &iter, -1,
#else
	gtk_list_store_append(favorites->store, &iter);
	gtk_list_store_set(favorites->store, &iter,
#endif
			FC_ICON, pixbuf, FC_NAME, filename, FC_PATH, path, -1);
	string_delete(path);
	g_free(filename);
	_favorites_save(favorites);
}
コード例 #3
0
static gboolean _mime_icon_folder_in_home(struct stat * pst)
{
	static char const * homedir = NULL;
	static struct stat hst;

	if(homedir == NULL)
	{
		if((homedir = getenv("HOME")) == NULL
				&& (homedir = g_get_home_dir()) == NULL)
			return FALSE;
		if(browser_vfs_stat(homedir, &hst) != 0)
		{
			homedir = NULL;
			return FALSE;
		}
	}
	return (hst.st_dev == pst->st_dev && hst.st_ino == pst->st_ino)
		? TRUE : FALSE;
}
コード例 #4
0
GdkPixbuf * browser_vfs_mime_icon(Mime * mime, char const * filename,
		char const * type, struct stat * lst, struct stat * st,
		int size)
{
	GdkPixbuf * ret = NULL;
	mode_t mode = (lst != NULL) ? lst->st_mode : 0;
	struct stat s;
	char const * emblem;

	if(filename == NULL)
		return NULL;
	if(type == NULL)
		type = browser_vfs_mime_type(mime, filename,
				S_ISLNK(mode) ? 0 : mode);
	if(st == NULL && browser_vfs_stat(filename, &s) == 0)
		st = &s;
	if(S_ISDIR(mode) || (st != NULL && S_ISDIR(st->st_mode)))
		ret = _mime_icon_folder(mime, filename, lst, st, size);
	else if(S_ISLNK(mode) && (st != NULL && S_ISDIR(st->st_mode)))
		ret = _mime_icon_folder(mime, filename, lst, st, size);
	else
		mime_icons(mime, type, size, &ret, -1);
	if(ret == NULL || lst == NULL)
		return ret;
	/* determine the emblem */
	if(S_ISCHR(lst->st_mode) || S_ISBLK(lst->st_mode))
		emblem = "emblem-system";
	else if(S_ISLNK(lst->st_mode))
		emblem = "emblem-symbolic-link";
	else if((lst->st_mode & (S_IRUSR | S_IRGRP | S_IROTH)) == 0)
		emblem = "emblem-unreadable";
	else if((lst->st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) == 0)
		emblem = "emblem-readonly";
	else
		emblem = NULL;
	/* apply the emblem if relevant */
	if(emblem != NULL)
		ret = _mime_icon_emblem(ret, size, emblem);
	return ret;
}
コード例 #5
0
ファイル: copy.c プロジェクト: DeforaOS/Browser
static int _copy_single(Copy * copy, char const * src, char const * dst)
{
	int ret;
	char * p;
	struct stat st;
	struct stat st2;
	guint timeout;

	if((p = g_filename_to_utf8(src, -1, NULL, NULL, NULL)) != NULL)
		gtk_label_set_text(GTK_LABEL(copy->flabel), p);
	else
		gtk_label_set_text(GTK_LABEL(copy->flabel), src);
	free(p);
	gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(copy->fprogress), 0.0);
	gtk_progress_bar_set_text(GTK_PROGRESS_BAR(copy->fprogress), "");
	if(*(copy->prefs) & PREFS_P)
	{
		/* do not follow symlinks */
		if(browser_vfs_lstat(src, &st) != 0 && errno == ENOENT)
			return _copy_filename_error(copy, src, 1);
	}
	else if(browser_vfs_stat(src, &st) != 0 && errno == ENOENT)
		/* follow symlinks */
		return _copy_filename_error(copy, src, 1);
	if(browser_vfs_lstat(dst, &st2) == 0)
	{
		if(st.st_dev == st2.st_dev && st.st_ino == st2.st_ino)
		{
			fprintf(stderr, "%s: %s: \"%s\"%s\n", PROGNAME_COPY,
					dst, src,
					_(" is identical (not copied)"));
			return 0;
		}
		if(*(copy->prefs) & PREFS_i
				&& _copy_filename_confirm(copy, dst) != 1)
			return 0;
		if(unlink(dst) != 0)
			return _copy_filename_error(copy, dst, 1);
	}
	if(S_ISDIR(st.st_mode))
		ret = _single_dir(copy, src, dst, st.st_mode & 0777);
	else if(S_ISFIFO(st.st_mode))
		ret = _single_fifo(copy, dst, st.st_mode & 0666);
	else if(S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))
		ret = _single_nod(copy, src, dst, st.st_mode, st.st_rdev);
	else if(S_ISLNK(st.st_mode))
		ret = _single_symlink(copy, src, dst);
	else if(S_ISREG(st.st_mode))
	{
		ret = _single_regular(copy, src, dst, st.st_mode & 0777);
		timeout = g_timeout_add(250, _single_timeout, copy);
		gtk_main(); /* XXX ugly */
		g_source_remove(timeout);
	}
	else
	{
		errno = ENOSYS;
		return _copy_error(copy, src, 1);
	}
	if(ret != 0)
		return ret;
	if(*(copy->prefs) & PREFS_p) /* XXX TOCTOU */
		_single_p(copy, dst, &st);
	return 0;
}