Class: MIME::Types

Inherits:
Object show all
Defined in:
lib/unixcmd/aux.rb

Class Method Summary collapse

Class Method Details

.get_icon_names(filepath) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/unixcmd/aux.rb', line 85

def self.get_icon_names(filepath)
    types = MIME::Types.of filepath

    return nil if types == nil || types.count == 0

    script_path = Pathname.new(__FILE__).expand_path.dirname.to_s

    begin
        res = `#{script_path}/../gnome-get-filetype-icon #{types[0]}`
    rescue
        return nil
    end

    return (res.strip.split ' ').drop(2) if $? == 0

    nil
end

.get_icon_path(filepath) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/unixcmd/aux.rb', line 103

def self.get_icon_path(filepath)
    icons_path = Pathname.new '/usr/share/icons/gnome/16x16'

    return icons_path + Pathname.new('places/folder.png') if filepath.directory?

    icon_names = MIME::Types.get_icon_names(filepath.to_s)

    return icons_path + Pathname.new('mimetypes/text-x-generic.png') if icon_names == nil

    icon_names.each do |icon|
        icon_path = icons_path + Pathname.new('mimetypes') + Pathname.new(icon.to_s + '.png')

        return icon_path.to_s if icon_path.exist?
    end

    icons_path + Pathname.new('mimetypes/text-x-generic.png')
end