Beispiel #1
0
/* compose_attach */
int compose_attach(Compose * compose, char const * filename)
{
	const int iconsize = 48;
	GtkIconTheme * theme;
	char const * type;
	GdkPixbuf * pixbuf;
	GtkTreeIter iter;
	char * p;
	FILE * fp;

	if(filename == NULL)
		return compose_attach_dialog(compose);
	if((fp = fopen(filename, "rb")) == NULL)
		return -compose_error(compose, strerror(errno), 1);
	if((p = strdup(filename)) == NULL)
	{
		fclose(fp);
		return -compose_error(compose, strerror(errno), 1);
	}
	compose_set_modified(compose, TRUE);
	theme = gtk_icon_theme_get_default();
	pixbuf = NULL;
	if((type = mime_type(compose->mime, filename)) != NULL)
		mime_icons(compose->mime, type, iconsize, &pixbuf, -1);
	if(pixbuf == NULL)
		pixbuf = gtk_icon_theme_load_icon(theme, GTK_STOCK_FILE,
				iconsize, 0, NULL);
	gtk_list_store_append(compose->a_store, &iter);
	gtk_list_store_set(compose->a_store, &iter, CAC_FILENAME, filename,
			CAC_BASENAME, basename(p), CAC_ICON, pixbuf,
			CAC_FILE_POINTER, fp, -1);
	g_object_unref(pixbuf);
	free(p);
	return 0;
}
Beispiel #2
0
/* compose_attach_dialog */
void compose_attach_dialog(Compose * compose)
{
	GtkWidget * dialog;
	GSList * filenames = NULL;
	GSList * p;
	char const * type;
	GdkPixbuf * pixbuf;
	GtkIconTheme * theme;
	GtkTreeIter iter;

	dialog = gtk_file_chooser_dialog_new(_("Attach file..."),
			GTK_WINDOW(compose->window),
			GTK_FILE_CHOOSER_ACTION_OPEN,
			GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
			GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
	gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
	if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
		filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(
					dialog));
	gtk_widget_destroy(dialog);
	if(filenames == NULL)
		return;
	compose_set_modified(compose, TRUE);
	theme = gtk_icon_theme_get_default();
	for(p = filenames; p != NULL; p = p->next)
	{
		pixbuf = NULL;
		if((type = mime_type(compose->mime, p->data)) != NULL)
			mime_icons(compose->mime, type, 48, &pixbuf, -1);
		if(pixbuf == NULL)
			pixbuf = gtk_icon_theme_load_icon(theme, GTK_STOCK_FILE,
					48, 0, NULL);
		gtk_list_store_append(compose->a_store, &iter);
		gtk_list_store_set(compose->a_store, &iter, CAC_FILENAME,
				p->data, CAC_BASENAME, basename(p->data),
				CAC_ICON, pixbuf, -1);
	}
	g_slist_foreach(filenames, (GFunc)g_free, NULL);
	g_slist_free(filenames);
	gtk_widget_show(compose->a_window);
}
Beispiel #3
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;
}
Beispiel #4
0
static GdkPixbuf * _mime_icon_folder(Mime * mime, char const * filename,
		struct stat * lst, struct stat * st, int size)
{
	GdkPixbuf * ret = NULL;
	char const * icon = NULL;
	struct stat ls;
	struct stat ps;
	char * p;
	size_t i;
	struct
	{
		char const * name;
		char const * icon;
	} name_icon[] =
	{
		{ "DCIM",	"folder-pictures"	},
		{ "Desktop",	"user-desktop"		},
		{ "Documents",	"folder-documents"	},
		{ "Download",	"folder-download"	},
		{ "Downloads",	"folder-download"	},
		{ "Music",	"folder-music"		},
		{ "Pictures",	"folder-pictures"	},
		{ "public_html","folder-publicshare"	},
		{ "Templates",	"folder-templates"	},
		{ "Video",	"folder-videos"		},
		{ "Videos",	"folder-videos"		},
	};
	GtkIconTheme * icontheme;
	const unsigned int flags = GTK_ICON_LOOKUP_FORCE_SIZE;

	if(lst == NULL && browser_vfs_lstat(filename, &ls) == 0)
		lst = &ls;
	/* check if the folder is special */
	if((p = strdup(filename)) != NULL
			&& (lst == NULL || !S_ISLNK(lst->st_mode))
			&& st != NULL
			&& browser_vfs_lstat(dirname(p), &ps) == 0)
	{
		if(st->st_dev != ps.st_dev || st->st_ino == ps.st_ino)
			icon = "mount-point";
		else if(_mime_icon_folder_is_home(st))
			icon = "folder_home";
		else if(_mime_icon_folder_in_home(&ps))
			/* check if the folder is special */
			for(i = 0; i < sizeof(name_icon) / sizeof(*name_icon);
					i++)
				if(strcasecmp(basename(p), name_icon[i].name)
						== 0)
				{
					icon = name_icon[i].icon;
					break;
				}
	}
	free(p);
	if(icon != NULL)
	{
		icontheme = gtk_icon_theme_get_default();
		ret = gtk_icon_theme_load_icon(icontheme, icon, size, flags,
				NULL);
	}
	/* generic fallback */
	if(ret == NULL)
		mime_icons(mime, "inode/directory", size, &ret, -1);
	return ret;
}
Beispiel #5
0
/* desktopicon_new */
DesktopIcon * desktopicon_new(Desktop * desktop, char const * name,
		char const * path)
{
	DesktopIcon * desktopicon;
	struct stat st;
	Mime * mime;
	char const * mimetype = NULL;
	gboolean isdir = FALSE;
	gboolean isexec = FALSE;
	GdkPixbuf * image = NULL;
	GError * error = NULL;
	char * p;
	GtkTargetEntry targets[] = { { "deforaos_browser_dnd", 0, 0 } };
	size_t targets_cnt = sizeof(targets) / sizeof(*targets);

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(%p, \"%s\", \"%s\")\n", __func__,
			(void *)desktop, name, path);
#endif
	if(path != NULL && stat(path, &st) == 0)
	{
		mime = desktop_get_mime(desktop);
		if(S_ISDIR(st.st_mode))
		{
			isdir = TRUE;
			image = desktop_get_folder(desktop);
		}
		else if(st.st_mode & S_IXUSR)
		{
			/* FIXME use access() for this */
			isexec = TRUE;
			mime_icons(desktop_get_mime(desktop),
					"application/x-executable",
					DESKTOPICON_ICON_SIZE, &image, -1);
		}
		else if((mimetype = mime_type(mime, path)) != NULL)
			mime_icons(mime, mimetype, DESKTOPICON_ICON_SIZE,
					&image, -1);
	}
	if(name == NULL)
	{
		if((p = g_filename_to_utf8(path, -1, NULL, NULL, &error))
				== NULL)
		{
			fprintf(stderr, "%s%s\n", "desktop: ", error->message);
			name = path;
		}
		else
			name = p;
		if((name = strrchr(name, '/')) != NULL)
			name++;
	}
	if((desktopicon = _desktopicon_new_do(desktop, image, name)) == NULL)
		return NULL;
	gtk_drag_source_set(desktopicon->event, GDK_BUTTON1_MASK, targets,
			targets_cnt, GDK_ACTION_COPY | GDK_ACTION_MOVE);
	gtk_drag_dest_set(desktopicon->event, GTK_DEST_DEFAULT_ALL, targets,
			targets_cnt, GDK_ACTION_COPY | GDK_ACTION_MOVE);
	g_signal_connect(G_OBJECT(desktopicon->event), "drag-data-get",
			G_CALLBACK(_on_icon_drag_data_get), desktopicon);
	g_signal_connect(G_OBJECT(desktopicon->event), "drag-data-received",
			G_CALLBACK(_on_icon_drag_data_received), desktopicon);
	desktopicon->isdir = isdir;
	desktopicon_set_executable(desktopicon, isexec);
	desktopicon->mimetype = mimetype;
	if(path != NULL && (desktopicon->path = strdup(path)) == NULL)
	{
		desktopicon_delete(desktopicon);
		return NULL;
	}
	return desktopicon;
}