2006-03-30 00:07:27 +02:00
|
|
|
|
|
|
|
#
|
2006-04-07 22:22:30 +02:00
|
|
|
# gPodder (a media aggregator / podcast client)
|
|
|
|
# Copyright (C) 2005-2006 Thomas Perl <thp at perli.net>
|
2006-03-30 00:07:27 +02:00
|
|
|
#
|
2006-04-07 22:22:30 +02:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
|
2006-03-30 00:07:27 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# libplayers.py -- get list of potential playback apps
|
|
|
|
# thomas perl <thp@perli.net> 20060329
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
from os import listdir
|
|
|
|
from os.path import basename
|
|
|
|
from os.path import splitext
|
|
|
|
from os.path import exists
|
|
|
|
|
|
|
|
from ConfigParser import RawConfigParser
|
|
|
|
|
|
|
|
import gobject
|
|
|
|
|
|
|
|
from gtk import IconTheme
|
|
|
|
from gtk import ListStore
|
|
|
|
|
|
|
|
from gtk.gdk import pixbuf_new_from_file_at_size
|
|
|
|
from gtk.gdk import Pixbuf
|
|
|
|
|
|
|
|
import libgpodder
|
|
|
|
|
|
|
|
# where are the .desktop files located?
|
2006-04-06 16:11:03 +02:00
|
|
|
userappsdirs = [ '/usr/share/applications/', '/usr/local/share/applications/' ]
|
2006-03-30 00:07:27 +02:00
|
|
|
|
|
|
|
# the name of the section in the .desktop files
|
|
|
|
sect = 'Desktop Entry'
|
|
|
|
|
|
|
|
class UserApplication(object):
|
|
|
|
def __init__( self, name, cmd, mime, icon):
|
|
|
|
self.name = name
|
|
|
|
self.cmd = cmd
|
|
|
|
self.icon = icon
|
|
|
|
self.theme = IconTheme()
|
|
|
|
|
|
|
|
def get_icon( self):
|
|
|
|
if self.icon != None:
|
|
|
|
if exists( self.icon):
|
|
|
|
return pixbuf_new_from_file_at_size( self.icon, 24, 24)
|
|
|
|
icon_name = splitext( basename( self.icon))[0]
|
|
|
|
if self.theme.has_icon( icon_name):
|
|
|
|
return self.theme.load_icon( icon_name, 24, 0)
|
|
|
|
|
|
|
|
def get_name( self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def get_action( self):
|
|
|
|
return self.cmd
|
|
|
|
|
|
|
|
|
|
|
|
class UserAppsReader(object):
|
|
|
|
def __init__( self):
|
|
|
|
self.apps = []
|
|
|
|
|
|
|
|
def read( self):
|
2006-04-06 16:11:03 +02:00
|
|
|
for dir in userappsdirs:
|
|
|
|
if exists( dir):
|
|
|
|
files = listdir( dir)
|
|
|
|
for file in files:
|
|
|
|
self.parse_and_append( dir, file)
|
2006-03-30 00:07:27 +02:00
|
|
|
self.apps.append( UserApplication( 'Shell command', '', 'audio/*', 'gtk-execute'))
|
|
|
|
|
2006-04-06 16:11:03 +02:00
|
|
|
def parse_and_append( self, dir, filename):
|
2006-03-30 00:07:27 +02:00
|
|
|
parser = RawConfigParser()
|
2006-04-06 16:11:03 +02:00
|
|
|
parser.read( [ dir + filename ])
|
2006-03-30 00:07:27 +02:00
|
|
|
if not parser.has_section( sect):
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
app_name = parser.get( sect, 'Name')
|
|
|
|
app_cmd = parser.get( sect, 'Exec')
|
|
|
|
app_mime = parser.get( sect, 'MimeType')
|
|
|
|
app_icon = parser.get( sect, 'Icon')
|
|
|
|
if app_mime.find( 'audio/') != -1:
|
|
|
|
if libgpodder.isDebugging():
|
2006-04-06 16:11:03 +02:00
|
|
|
print "found app in " + dir + filename + " ("+app_name+")"
|
2006-03-30 00:07:27 +02:00
|
|
|
self.apps.append( UserApplication( app_name, app_cmd, app_mime, app_icon))
|
|
|
|
except:
|
|
|
|
return
|
|
|
|
|
|
|
|
def get_applications_as_model( self):
|
|
|
|
result = ListStore( gobject.TYPE_STRING, gobject.TYPE_STRING, Pixbuf)
|
|
|
|
for app in self.apps:
|
|
|
|
iter = result.append()
|
|
|
|
result.set_value( iter, 0, app.get_name())
|
|
|
|
result.set_value( iter, 1, app.get_action())
|
|
|
|
result.set_value( iter, 2, app.get_icon())
|
|
|
|
return result
|
|
|
|
# end of UserAppsReader
|
|
|
|
|
2006-06-13 20:52:25 +02:00
|
|
|
|
|
|
|
def dotdesktop_command( command, filename):
|
|
|
|
# the following flags are specified in the FDO standards for ".desktop" files:
|
|
|
|
# http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-0.9.4.html
|
|
|
|
if command.find( '%U') != -1:
|
|
|
|
# A list of URLs. (we only need one, anyway..)
|
2006-06-13 20:55:28 +02:00
|
|
|
return command.replace( '%U', ( '"file://%s"' % (filename) ) )
|
|
|
|
if command.find( '%u') != -1:
|
2006-06-13 20:52:25 +02:00
|
|
|
# A single URL.
|
2006-06-13 20:55:28 +02:00
|
|
|
return command.replace( '%u', ( '"file://%s"' % (filename) ) )
|
|
|
|
if command.find( '%F') != -1:
|
|
|
|
# A list of files. (we only need one...)
|
|
|
|
return command.replace( '%F', filename )
|
|
|
|
if command.find( '%f') != -1:
|
|
|
|
# A single file name, even if multiple files are selected.
|
|
|
|
return command.replace( '%f', filename )
|
|
|
|
|
|
|
|
# default known-good variant: 1st parameter = filename
|
|
|
|
return '%s "%s"' % ( command, filename )
|
2006-06-13 20:52:25 +02:00
|
|
|
# end dotdesktop_command
|
|
|
|
|
|
|
|
|