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 2>/dev/null | 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( gnomevfs.escape_path_string( path ) )
82
mime_type = mime_type.replace( '/', '-' )
85
if mime_type in self.cache:
86
return self.cache[mime_type]
88
#print "path: " + path
89
#print "mime: " + mime_type
92
items = mime_type.split('-')
93
for aux in xrange(len(items)-1):
94
icon_name = "gnome-mime-" + '-'.join(items[:len(items)-aux])
95
if icon_name in self.all_icons:
96
#print "icon: " + icon_name
97
self.cache[mime_type] = icon_name
101
if os.path.isdir( path ):
103
if icon_name in self.all_icons:
104
#print "icon: " + icon_name
105
self.cache[mime_type] = icon_name
108
#print "icon: " + icon_name
109
icon_name = gtk.STOCK_DIRECTORY
110
self.cache[mime_type] = icon_name
114
for aux in xrange(len(items)-1):
115
icon_name = '-'.join(items[:len(items)-aux])
116
if icon_name in self.all_icons:
117
#print "icon: " + icon_name
118
self.cache[mime_type] = icon_name
122
icon_name = gtk.STOCK_FILE
123
self.cache[mime_type] = icon_name