Moved more icon handling code to the VFS pseudo-class

This commit is contained in:
Pierre Pronchery 2012-12-05 15:53:35 +01:00
parent 4c29e9075d
commit d04c2cb550
3 changed files with 67 additions and 46 deletions

View File

@ -1334,55 +1334,12 @@ static void _insert_dir(Browser * browser, char const * name,
GdkPixbuf ** icon_24, GdkPixbuf ** icon_48, GdkPixbuf ** icon_24, GdkPixbuf ** icon_48,
GdkPixbuf ** icon_96, struct stat * st) GdkPixbuf ** icon_96, struct stat * st)
{ {
char const * type = "inode/directory";
char const * icon = NULL;
int flags = GTK_ICON_LOOKUP_FORCE_SIZE;
if(browser->refresh_dev != st->st_dev)
type = "inode/mountpoint";
/* special folder icons */
else if(strcasecmp(name, "Desktop") == 0)
icon = "gnome-fs-desktop";
else if(strcasecmp(name, "Documents") == 0)
icon = "folder-documents";
else if(strcasecmp(name, "Download") == 0
|| strcasecmp(name, "Downloads") == 0)
icon = "folder-download";
else if(strcasecmp(name, "Music") == 0)
icon = "folder-music";
else if(strcasecmp(name, "Pictures") == 0)
icon = "folder-pictures";
else if(strcmp(name, "public_html") == 0
|| strcasecmp(name, "Shared") == 0)
icon = "folder-publicshared";
else if(strcasecmp(name, "Templates") == 0)
icon = "folder-templates";
else if(strcasecmp(name, "Video") == 0
|| strcasecmp(name, "Videos") == 0)
icon = "folder-videos";
if(icon != NULL)
{
/* try to load the special icons */
if(icon_24 != NULL && (*icon_24 = gtk_icon_theme_load_icon(
browser->theme, icon, 24, flags,
NULL)) != NULL)
icon_24 = NULL;
if(icon_48 != NULL && (*icon_48 = gtk_icon_theme_load_icon(
browser->theme, icon, 48, flags,
NULL)) != NULL)
icon_48 = NULL;
if(icon_96 != NULL && (*icon_96 = gtk_icon_theme_load_icon(
browser->theme, icon, 96, flags,
NULL)) != NULL)
icon_96 = NULL;
}
/* generic fallback */
if(icon_24 != NULL) if(icon_24 != NULL)
mime_icons(browser->mime, type, 24, icon_24, -1); *icon_24 = vfs_mime_folder_icon(browser->mime, name, st, 24);
if(icon_48 != NULL) if(icon_48 != NULL)
mime_icons(browser->mime, type, 48, icon_48, -1); *icon_48 = vfs_mime_folder_icon(browser->mime, name, st, 48);
if(icon_96 != NULL) if(icon_96 != NULL)
mime_icons(browser->mime, type, 96, icon_96, -1); *icon_96 = vfs_mime_folder_icon(browser->mime, name, st, 96);
} }
static gboolean _refresh_new_idle(gpointer data) static gboolean _refresh_new_idle(gpointer data)

View File

@ -15,6 +15,9 @@
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include "vfs.h" #include "vfs.h"
@ -34,6 +37,65 @@ int vfs_closedir(DIR * dir)
} }
/* vfs_folder_icon */
GdkPixbuf * vfs_mime_folder_icon(Mime * mime, char const * filename,
struct stat * st, int size)
{
GdkPixbuf * ret = NULL;
char const * icon = NULL;
struct stat s;
char * p;
struct stat lst;
size_t i;
struct
{
char const * name;
char const * icon;
} name_icon[] =
{
{ "Desktop", "gnome-fs-desktop" },
{ "Documents", "folder-documents" },
{ "Download", "folder-download" },
{ "Downloads", "folder-download" },
{ "Music", "folder-music" },
{ "Pictures", "folder-pictures" },
{ "public_html","folder-publicshared" },
{ "Templates", "folder-templates" },
{ "Video", "folder-videos" },
{ "Videos", "folder-videos" },
};
GtkIconTheme * icontheme;
int flags = GTK_ICON_LOOKUP_FORCE_SIZE;
if(st == NULL && lstat(filename, &s) == 0)
st = &s;
/* check if the folder is a mountpoint */
if((p = strdup(filename)) != NULL
&& st != NULL
&& lstat(dirname(p), &lst) == 0
&& st->st_dev != lst.st_dev)
icon = "mount-point";
if(p != NULL && icon == NULL)
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;
}
/* vfs_mime_icon */ /* vfs_mime_icon */
GdkPixbuf * vfs_mime_icon(Mime * mime, char const * type, struct stat * st, GdkPixbuf * vfs_mime_icon(Mime * mime, char const * type, struct stat * st,
int size) int size)

View File

@ -27,6 +27,8 @@
/* public */ /* public */
/* functions */ /* functions */
int vfs_closedir(DIR * dir); int vfs_closedir(DIR * dir);
GdkPixbuf * vfs_mime_folder_icon(Mime * mime, char const * name,
struct stat * st, int size);
int vfs_lstat(char const * filename, struct stat * st); int vfs_lstat(char const * filename, struct stat * st);
GdkPixbuf * vfs_mime_icon(Mime * mime, char const * type, struct stat * st, GdkPixbuf * vfs_mime_icon(Mime * mime, char const * type, struct stat * st,
int size); int size);