~ubuntu-branches/debian/experimental/backintime/experimental

« back to all changes in this revision

Viewing changes to gnomefileicons.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Wiltshire
  • Date: 2010-12-03 21:56:53 UTC
  • mfrom: (1.2.1 upstream) (3.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20101203215653-scx9roloq4m0dqns
Tags: 1.0.4-1
* New upstream release
    Closes: #555293
    LP: #409130 #507246 #528518 #534829 #522618
* Update debian/copyright
* The following patches are either integrated or fixed properly
  upstream: no-chmod-777.patch allow-root-backup.patch
* Refactor remaining patches and make the headers DEP-3 compliant
* Convert to source format 3.0 (quilt) and drop quilt dependency and
  logic
* Don't depend on a specific version of Python; let dh_python choose
  the best option
* Remove the "earlier-than" restriction for the Conflicts on
  backintime-kde4
* Standards version 3.9.1 (no changes required)
* Update my email address

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#    Back In Time
2
 
#    Copyright (C) 2008-2009 Oprea Dan
3
 
#
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.
8
 
#
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.
13
 
#
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.
17
 
 
18
 
import os.path
19
 
import pygtk
20
 
pygtk.require("2.0")
21
 
import gtk
22
 
import gnomevfs
23
 
 
24
 
 
25
 
class GnomeFileIcons:
26
 
        def __init__( self ):
27
 
                self.all_icons = gtk.icon_theme_get_default().list_icons()
28
 
                self.cache = {}
29
 
                self.user_path = os.path.expanduser( '~' )
30
 
                self.special_folders = {}
31
 
 
32
 
                self.update_special_folder_icons()
33
 
 
34
 
        def add_special_folder_( self, path, icon_name ):
35
 
                if len( path ) <= 0:
36
 
                        return
37
 
 
38
 
                if not icon_name in self.all_icons:
39
 
                        icon_name = 'folder'
40
 
 
41
 
                self.special_folders[ path ] = icon_name
42
 
 
43
 
        def get_special_folder_path( self, name ):
44
 
                path = ''
45
 
 
46
 
                try:
47
 
                        pipe = os.popen( "cat %s/.config/user-dirs.dirs | grep %s=" % ( self.user_path, name ), 'r' )
48
 
                        path = pipe.read()
49
 
                        pipe.close()
50
 
                except:
51
 
                        pass
52
 
 
53
 
                if len( path ) <= 0:
54
 
                        return ''
55
 
 
56
 
                path = path[ len( name ) + 1 : ]
57
 
                if path[ 0 ] == '"':
58
 
                        path = path[ 1 : -2 ]
59
 
 
60
 
                path = path.replace( '$HOME', self.user_path )
61
 
                return path
62
 
 
63
 
        def update_special_folder_icons( self ):
64
 
                self.special_folders = {}
65
 
 
66
 
                #add desktop
67
 
                self.add_special_folder_( self.get_special_folder_path( 'XDG_DESKTOP_DIR' ), 'user-desktop' )
68
 
                
69
 
                #add home
70
 
                self.add_special_folder_( self.user_path, 'user-home' )
71
 
                
72
 
        def get_icon( self, path ):
73
 
                if not os.path.exists(path):
74
 
                        return gtk.STOCK_FILE
75
 
 
76
 
                #check if it is a special folder
77
 
                if path in self.special_folders:
78
 
                        return self.special_folders[path]
79
 
 
80
 
                #get mime type
81
 
                mime_type = gnomevfs.get_mime_type( path ).replace( '/', '-' )
82
 
 
83
 
                #search in the cache
84
 
                if mime_type in self.cache:
85
 
                        return self.cache[mime_type]
86
 
 
87
 
                #print "path: " + path
88
 
                #print "mime: " + mime_type
89
 
 
90
 
                #try gnome mime
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
97
 
                                return icon_name
98
 
 
99
 
                #try folder
100
 
                if os.path.isdir( path ):
101
 
                        icon_name = 'folder'
102
 
                        if icon_name in self.all_icons:
103
 
                                #print "icon: " + icon_name
104
 
                                self.cache[mime_type] = icon_name
105
 
                                return icon_name
106
 
 
107
 
                        #print "icon: " + icon_name
108
 
                        icon_name = gtk.STOCK_DIRECTORY
109
 
                        self.cache[mime_type] = icon_name
110
 
                        return icon_name
111
 
 
112
 
                #try simple mime
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
118
 
                                return icon_name
119
 
 
120
 
                #file icon
121
 
                icon_name = gtk.STOCK_FILE
122
 
                self.cache[mime_type] = icon_name
123
 
                return icon_name
124