2
# Copyright (C) 2008-2009 Oprea Dan
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 General Public License for more details.
14
# You should have received a copy of the GNU General Public License along
15
# with this program; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27
self.all_icons = gtk.icon_theme_get_default().list_icons()
29
self.user_path = os.path.expanduser( '~' )
30
self.special_folders = {}
32
self.update_special_folder_icons()
34
def add_special_folder_( self, path, icon_name ):
38
if not icon_name in self.all_icons:
41
self.special_folders[ path ] = icon_name
43
def get_special_folder_path( self, name ):
47
pipe = os.popen( "cat %s/.config/user-dirs.dirs | grep %s=" % ( self.user_path, name ), 'r' )
56
path = path[ len( name ) + 1 : ]
60
path = path.replace( '$HOME', self.user_path )
63
def update_special_folder_icons( self ):
64
self.special_folders = {}
67
self.add_special_folder_( self.get_special_folder_path( 'XDG_DESKTOP_DIR' ), 'user-desktop' )
70
self.add_special_folder_( self.user_path, 'user-home' )
72
def get_icon( self, path ):
73
if not os.path.exists(path):
76
#check if it is a special folder
77
if path in self.special_folders:
78
return self.special_folders[path]
81
mime_type = gnomevfs.get_mime_type( path ).replace( '/', '-' )
84
if mime_type in self.cache:
85
return self.cache[mime_type]
87
#print "path: " + path
88
#print "mime: " + mime_type
91
items = mime_type.split('-')
92
for aux in xrange(len(items)-1):
93
icon_name = "gnome-mime-" + '-'.join(items[:len(items)-aux])
94
if icon_name in self.all_icons:
95
#print "icon: " + icon_name
96
self.cache[mime_type] = icon_name
100
if os.path.isdir( path ):
102
if icon_name in self.all_icons:
103
#print "icon: " + icon_name
104
self.cache[mime_type] = icon_name
107
#print "icon: " + icon_name
108
icon_name = gtk.STOCK_DIRECTORY
109
self.cache[mime_type] = icon_name
113
for aux in xrange(len(items)-1):
114
icon_name = '-'.join(items[:len(items)-aux])
115
if icon_name in self.all_icons:
116
#print "icon: " + icon_name
117
self.cache[mime_type] = icon_name
121
icon_name = gtk.STOCK_FILE
122
self.cache[mime_type] = icon_name