1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 __maintainer__ = 'Benjamin Kampmann <benjamin@fluendo.com>'
19
20 from elisa.core.component import Component
21 from elisa.core.media_uri import MediaUri, ParseException
22
23 from elisa.extern.translation import TranslatableSingular
24
26 """
27 Create L{elisa.core.base_components.model.Model} for specific MenuEntry XML
28 tags.
29
30 @ivar activity: activity which instantiated self
31 @type activity: L{elisa.core.base_components.activity.Activity}
32 @ivar menu_entry_identifiers: MenuEntry identifiers it can handle; in the
33 XML it is the attribute 'type' of the
34 'MenuEntry' tags
35 @ivar menu_entry_identifiers: list of string
36 @ivar model_configs: the cache of the models. each model should
37 be referenced there with a key
38 @type model_configs: L{weakref.WeakKeyDirectory}
39 """
40
43
45 """
46 Fills in L{parent} with models created from the XML description
47 L{xml_node}.
48
49 If the created models have an attribute 'xml_tag' containing a
50 cElementTree, the activity is trying to find a suitable menu_component
51 for its children again at loadmore. Don't forget that in that case the
52 models needs to be marked as having children.
53
54 @param parent: the parent, where the menu_entry is in
55 @type parent: L{elisa.plugins.base.models.menu_node_model.MenuNodeModel}
56 @param xml_node: XML MenuEntry tag out of which the menu entry is built
57 @type xml_node: cElementTree
58
59 @rtype: L{twisted.internet.defer.Deferred}
60 @return: the callback of this Deferred is a list of the created
61 models
62 """
63 raise NotImplemented
64
65
66
68 """
69 make a label out of the label_tag. The return is something that can be
70 used in in the menu_node_model-label directly
71 """
72 if label_tag == None:
73 return '<Not specified>'
74
75 domain = label_tag.get('translate-domain', None)
76 if domain != None:
77 return TranslatableSingular(domain, label_tag.text)
78
79 return label_tag.text
80
82 """
83 Read the configuration node and return a new L{ModelConfig}, that
84 contains the configuration for this subpart. This is a mix of the
85 default configuration it got and the new it read. The new ones are
86 priorized.
87 """
88
89 config = default.copy()
90
91
92 if config.has_key('xml_tag'):
93 config.pop('xml_tag')
94
95
96 if node == None:
97 return config
98
99 overwriter = ['DefaultFilesIcon',
100 'DefaultDirsIcon',
101 'ContentType',
102 'MediaFilter']
103
104
105 for key in overwriter:
106 sub_node = node.find(key)
107 if sub_node != None:
108 self.debug("Setting %s to %s" % (key, sub_node.text))
109 config[key] = sub_node.text
110
111 return config
112
113
115 """
116 Set the icon on the model according to the icon_tag
117 """
118 if icon_tag == None:
119 if fallback:
120 model.theme_icon = fallback
121 return
122
123 i_type = icon_tag.get('type', 'theme').lower()
124 value = icon_tag.text
125
126 if i_type == 'theme':
127 model.theme_icon = value
128
129 elif i_type == 'uri':
130 try:
131 uri = MediaUri(value)
132 model.thumbnail_source = uri
133 except ParseException, exc:
134 self.warning("'%s' is not a valid uri: %s" % (value, exc))
135
136 elif i_type == 'path':
137 try:
138 uri = MediaUri("file://%s" % value)
139 model.thumbnail_source = uri
140 except ParseException, exc:
141 self.warning("'%s' is not a valid path: %s" % (value, exc))
142
143 else:
144 self.warning("%s has an unsupported type" % icon_tag)
145