2
* Copyright (c) 2008 Giuseppe Torelli <colossus73@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU Library General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
GSList *icon_cache = NULL;
23
extern GtkIconTheme *icon_theme;
24
const char *xa_get_stock_mime_icon(char *filename)
27
const char *icon_name = "binary";
29
mime = xdg_mime_get_mime_type_from_file_name(filename);
30
if (strstr(filename,".ogg") || strstr(filename,".flac") )
32
else if (strncmp(mime,"image/",6) == 0)
34
else if (strcmp(mime,"text/html") == 0)
36
else if (strncmp(mime,"text/",5) == 0)
38
else if (strcmp(mime,"application/rtf") == 0 || strcmp(mime,"application/pdf") == 0 || strcmp(mime,"application/msword") == 0
39
|| strcmp (mime,"application/vnd.oasis.opendocument.text") == 0)
40
icon_name = "document";
41
else if (strcmp(mime,"audio/mpeg") == 0 || strcmp(mime,"audio/midi") == 0 || strcmp (mime,"audio/mp2") == 0)
43
else if (strcmp(mime,"application/vnd.ms-excel") == 0 || strcmp(mime,"application/vnd.oasis.opendocument.spreadsheet") == 0)
44
icon_name = "gnome-mime-application-vnd.ms-excel";
45
else if (strcmp(mime,"application/vnd.ms-powerpoint") == 0 || strcmp (mime,"application/vnd.oasis.opendocument.presentation") == 0)
46
icon_name = "gnome-mime-application-vnd.ms-powerpoint";
47
else if (strcmp(mime,"application/zip") == 0 || strcmp(mime,"application/x-rar") == 0 || strcmp(mime,"application/x-tar") == 0
48
|| strcmp(mime,"application/x-7z-compressed") == 0 || strcmp(mime,"application/x-bzip-compressed-tar") == 0
49
|| strcmp (mime,"application/x-compressed-tar") == 0 || strcmp (mime,"application/x-lha") == 0
50
|| strcmp (mime,"application/x-rpm") == 0 || strcmp (mime,"application/x-deb") == 0
51
|| strcmp (mime,"application/x-bzip") == 0 || strcmp (mime,"application/x-gzip") == 0)
52
icon_name = "package";
53
else if (strcmp(mime,"application/x-shockwave-flash") == 0 || strcmp(mime,"video/mpeg") == 0 || strcmp(mime,"video/quicktime") == 0
54
|| strcmp(mime,"video/x-msvideo") == 0 || strcmp (mime,"video/mp4") == 0 || strcmp(mime,"application/x-flash-video") == 0
55
|| strcmp(mime,"video/dv") == 0)
57
else if (strcmp(mime,"application/x-cd-image") == 0)
58
icon_name = "application-x-cd-image";
59
else if (strcmp(mime,"application/x-php") == 0)
60
icon_name = "gnome-mime-application-x-php";
61
else if (strcmp(mime,"application/x-perl") == 0 || strcmp (mime,"application/x-csh") == 0 || strcmp (mime,"application/x-shellscript") == 0)
62
icon_name = "gnome-mime-application-x-perl";
63
else if (strcmp(mime,"application/x-font-ttf") == 0)
64
icon_name = "gnome-mime-application-x-font-ttf";
68
GdkPixbuf *xa_get_pixbuf_icon_from_cache(gchar *filename,gint size)
70
pixbuf_cache *tie = NULL;
71
const gchar *icon_name;
73
GdkPixbuf *pixbuf = NULL;
75
if (strcmp(filename,"folder") == 0)
77
else if (strcmp(filename,"lock") == 0)
78
icon_name = "gtk-dialog-authentication";
80
icon_name = xa_get_stock_mime_icon(filename);
82
tie = g_new0(pixbuf_cache,1);
85
tie->icon_name = g_strdup(icon_name);
86
found = g_slist_find_custom(icon_cache,tie,(GCompareFunc)xa_icon_name_compare_func);
89
g_free (tie->icon_name);
91
return ((pixbuf_cache *)found->data)->pixbuf;
95
pixbuf = gtk_icon_theme_load_icon(icon_theme,icon_name,size,GTK_ICON_LOOKUP_FORCE_SVG,NULL);
99
icon_cache = g_slist_prepend(icon_cache,tie);
106
gint xa_icon_name_compare_func(pixbuf_cache *a, pixbuf_cache *b)
108
return strcmp(a->icon_name, b->icon_name);
111
void xa_free_icon_cache()
113
GSList *x = icon_cache;
117
pixbuf_cache *tie = x->data;
118
g_free (tie->icon_name);
119
g_object_unref (tie->pixbuf);
123
g_slist_free(icon_cache);