servicemp3.cpp: more simple/flexible streaming detection
[enigma2.git] / lib / python / Plugins / Plugin.py
1 from Components.config import ConfigSubsection, config
2 from Tools.LoadPixmap import LoadPixmap
3
4 config.plugins = ConfigSubsection()
5
6 class PluginDescriptor:
7         """An object to describe a plugin."""
8         
9         # where to list the plugin. Note that there are different call arguments,
10         # so you might not be able to combine them.
11         
12         # supported arguments are:
13         #   session
14         #   servicereference
15         #   reason
16         
17         # you have to ignore unknown kwargs!
18         
19         # argument: session
20         WHERE_EXTENSIONSMENU = 0
21         WHERE_MAINMENU = 1
22         WHERE_PLUGINMENU  = 2
23         # argument: session, serviceref (currently selected)
24         WHERE_MOVIELIST = 3
25         # argument: menuid. Fnc must return list with menuitems (4-tuple of name, fnc to call, entryid or None, weight or None)
26         WHERE_MENU = 4
27         
28         # reason (0: start, 1: end)
29         WHERE_AUTOSTART = 5
30         
31         # start as wizard. In that case, fnc must be tuple (priority,class) with class being a screen class!
32         WHERE_WIZARD = 6
33         
34         # like autostart, but for a session. currently, only session starts are 
35         # delivered, and only on pre-loaded plugins
36         WHERE_SESSIONSTART = 7
37         
38         # start as teletext plugin. arguments: session, serviceref
39         WHERE_TELETEXT = 8
40         
41         # file-scanner, fnc must return a list of Scanners
42         WHERE_FILESCAN = 9
43         
44         # fnc must take an interface name as parameter and return None if the plugin supports an extended setup
45         # or return a function which is called with session and the interface name for extended setup of this interface
46         WHERE_NETWORKSETUP = 10
47         
48         # show up this plugin (or a choicebox with all of them) for long INFO keypress
49         # or return a function which is called with session and the interface name for extended setup of this interface
50         WHERE_EVENTINFO = 11
51
52         # reason (True: Networkconfig read finished, False: Networkconfig reload initiated )
53         WHERE_NETWORKCONFIG_READ = 12
54
55         WHERE_AUDIOMENU = 13
56
57         # fnc 'SoftwareSupported' or  'AdvancedSoftwareSupported' must take a parameter and return None
58         # if the plugin should not be displayed inside Softwaremanger or return a function which is called with session
59         # and 'None' as parameter to call the plugin from the Softwaremanager menus. "menuEntryName" and "menuEntryDescription"
60         # should be provided to name and describe the new menu entry.
61         WHERE_SOFTWAREMANAGER = 14
62
63
64         def __init__(self, name = "Plugin", where = [ ], description = "", icon = None, fnc = None, wakeupfnc = None, needsRestart = None, internal = False, weight = 0):
65                 self.name = name
66                 self.internal = internal
67                 self.needsRestart = needsRestart
68                 self.path = None
69                 if isinstance(where, list):
70                         self.where = where
71                 else:
72                         self.where = [ where ]
73                 self.description = description
74
75                 if icon is None or isinstance(icon, str):
76                         self.iconstr = icon
77                         self.icon = None
78                 else:
79                         self.icon = icon
80
81                 self.weight = weight
82
83                 self.wakeupfnc = wakeupfnc
84
85                 self.__call__ = fnc
86
87         def updateIcon(self, path):
88                 if isinstance(self.iconstr, str):
89                         self.icon = LoadPixmap('/'.join((path, self.iconstr)))
90                 else:
91                         self.icon = None
92
93         def getWakeupTime(self):
94                 return self.wakeupfnc and self.wakeupfnc() or -1
95
96         def __eq__(self, other):
97                 return self.__call__ == other.__call__