Package flumotion :: Package wizard :: Module consumptionsteps
[hide private]

Source Code for Module flumotion.wizard.consumptionsteps

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007,2008 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22  import gettext 
 23   
 24  from flumotion.common.python import any as pany 
 25  from flumotion.configure import configure 
 26  from flumotion.ui.wizard import WizardStep 
 27  from flumotion.wizard.httpstreamersteps import HTTPBothStep, HTTPAudioStep, \ 
 28       HTTPVideoStep 
 29  from flumotion.wizard.diskersteps import DiskBothStep, DiskAudioStep, \ 
 30       DiskVideoStep 
 31  from flumotion.wizard.models import Porter 
 32  from flumotion.wizard.shout2steps import Shout2BothStep, Shout2AudioStep, \ 
 33       Shout2VideoStep 
 34  from flumotion.wizard.workerstep import WorkerWizardStep 
 35   
 36  __version__ = "$Rev: 7087 $" 
 37  _ = gettext.gettext 
 38   
 39   
40 -class HTTPCommon(object):
41 - def __init__(self):
42 self.has_client_limit = False 43 self.has_bandwidth_limit = False 44 self.client_limit = 1000 45 self.bandwidth_limit = 500.0 46 self.burst_on_connect = False
47 48
49 -class ConsumptionStep(WizardStep):
50 name = 'Consumption' 51 title = _('Consumption') 52 section = _('Consumption') 53 icon = 'consumption.png' 54 gladeFile = 'consumption-wizard.glade' 55
56 - def __init__(self, wizard):
57 self._httpCommon = HTTPCommon() 58 self._httpPorter = Porter( 59 worker=None, port=configure.defaultHTTPStreamPort) 60 WizardStep.__init__(self, wizard)
61 62 # Public 63
64 - def getHTTPCommon(self):
65 return self._httpCommon
66
67 - def getHTTPPorter(self):
68 return self._httpPorter
69 70 # WizardStep 71
72 - def activated(self):
73 has_audio = self.wizard.hasAudio() 74 has_video = self.wizard.hasVideo() 75 has_both = has_audio and has_video 76 77 # Hide all checkbuttons if we don't have both audio and video selected 78 for checkbutton in (self.http_audio_video, 79 self.http_audio, 80 self.http_video, 81 self.disk_audio_video, 82 self.disk_audio, 83 self.disk_video, 84 self.shout2_audio_video, 85 self.shout2_audio, 86 self.shout2_video): 87 checkbutton.set_property('visible', has_both)
88
89 - def getNext(self, step=None):
90 steps = self._getSteps() 91 assert steps 92 93 if step is None: 94 step_class = steps[0] 95 else: 96 step_class = step.__class__ 97 if step_class in steps and steps[-1] != step_class: 98 step_class = steps[steps.index(step_class)+1] 99 else: 100 return 101 102 return step_class(self.wizard)
103 104 # Private 105
106 - def _verify(self):
107 disk = self.disk.get_active() 108 disk_audio = self.disk_audio.get_active() 109 disk_video = self.disk_video.get_active() 110 disk_audio_video = self.disk_audio_video.get_active() 111 http = self.http.get_active() 112 http_audio = self.http_audio.get_active() 113 http_video = self.http_video.get_active() 114 http_audio_video = self.http_audio_video.get_active() 115 shout2 = self.shout2.get_active() 116 shout2_audio = self.shout2_audio.get_active() 117 shout2_video = self.shout2_video.get_active() 118 shout2_audio_video = self.shout2_audio_video.get_active() 119 120 blockNext = True 121 if ((disk and pany([disk_audio, disk_video, disk_audio_video])) or 122 (http and pany([http_audio, http_video, http_audio_video])) or 123 (shout2 and pany([shout2_audio, shout2_video, shout2_audio_video]))): 124 blockNext = False 125 self.wizard.blockNext(blockNext)
126
127 - def _getSteps(self):
128 uielements = [] 129 retval = [] 130 if self.http.get_active(): 131 retval.append(HTTPConsumptionStep) 132 uielements.append( 133 ([HTTPAudioStep, HTTPVideoStep, HTTPBothStep], 134 [self.http_audio, 135 self.http_video, 136 self.http_audio_video])) 137 if self.disk.get_active(): 138 uielements.append( 139 ([DiskAudioStep, DiskVideoStep, DiskBothStep], 140 [self.disk_audio, 141 self.disk_video, 142 self.disk_audio_video])) 143 if self.shout2.get_active(): 144 uielements.append( 145 ([Shout2AudioStep, Shout2VideoStep, Shout2BothStep], 146 [self.shout2_audio, 147 self.shout2_video, 148 self.shout2_audio_video])) 149 150 has_audio = self.wizard.hasAudio() 151 has_video = self.wizard.hasVideo() 152 153 for steps, (audio, video, audio_video) in uielements: 154 # Audio & Video, all checkbuttons are visible and 155 # changeable by the user 156 if has_audio and has_video: 157 enable_audio_video = audio_video.get_active() 158 enable_audio = audio.get_active() 159 enable_video = video.get_active() 160 # Audio only, user cannot chose, the checkbuttons are not 161 # visible and it is not possible for the user to change, 162 # just add audio, and nothing else 163 elif has_audio and not has_video: 164 enable_audio_video = False 165 enable_audio = True 166 enable_video = False 167 # Video only, like audio only but with video 168 elif has_video and not has_audio: 169 enable_audio_video = False 170 enable_audio = False 171 enable_video = True 172 else: 173 raise AssertionError 174 175 audio_step, video_step, audio_video_step = steps 176 if enable_audio_video: 177 retval.append(audio_video_step) 178 if enable_audio: 179 retval.append(audio_step) 180 if enable_video: 181 retval.append(video_step) 182 183 return retval
184 185 # Callbacks 186
187 - def on_disk__toggled(self, button):
188 value = self.disk.get_active() 189 self.disk_audio_video.set_sensitive(value) 190 self.disk_audio.set_sensitive(value) 191 self.disk_video.set_sensitive(value) 192 193 self._verify()
194
195 - def on_shout2__toggled(self, button):
196 value = self.shout2.get_active() 197 self.shout2_audio_video.set_sensitive(value) 198 self.shout2_audio.set_sensitive(value) 199 self.shout2_video.set_sensitive(value) 200 201 self._verify()
202
203 - def on_http_audio_video__toggled(self, button):
204 self._verify()
205
206 - def on_http_audio__toggled(self, button):
207 self._verify()
208
209 - def on_http_video__toggled(self, button):
210 self._verify()
211
212 - def on_http__toggled(self, button):
213 value = self.http.get_active() 214 self.http_audio_video.set_sensitive(value) 215 self.http_audio.set_sensitive(value) 216 self.http_video.set_sensitive(value) 217 218 self._verify()
219 220
221 -class HTTPConsumptionStep(WorkerWizardStep):
222 """I am a step of the configuration wizard which allows you 223 to configure the common http properties of a stream 224 """ 225 name = 'HTTPStreaming' 226 title = _('HTTP Streaming') 227 section = _('Consumption') 228 icon = 'consumption.png' 229 gladeFile = 'http-wizard.glade' 230
231 - def __init__(self, wizard):
232 consumptionStep = wizard.getStep('Consumption') 233 self.common = consumptionStep.getHTTPCommon() 234 self.porter = consumptionStep.getHTTPPorter() 235 WorkerWizardStep.__init__(self, wizard)
236 237 # WizardStep 238
239 - def setup(self):
240 self.bandwidth_limit.data_type = float 241 self.burst_on_connect.data_type = bool 242 self.client_limit.data_type = int 243 self.port.data_type = int 244 245 self.add_proxy(self.porter.properties, ['port']) 246 self.add_proxy(self.common, ['has_client_limit', 247 'has_bandwidth_limit', 248 'client_limit', 249 'bandwidth_limit', 250 'burst_on_connect'])
251
252 - def activated(self):
253 self._verify()
254
255 - def getNext(self):
256 return self.wizard.getStep('Consumption').getNext(self)
257
258 - def workerChanged(self, worker):
259 self.porter.worker = worker
260 261 # Private 262
263 - def _verify(self):
264 self.client_limit.set_sensitive( 265 self.has_client_limit.get_active()) 266 self.bandwidth_limit.set_sensitive( 267 self.has_bandwidth_limit.get_active())
268 269 # Callbacks 270
271 - def on_has_client_limit_toggled(self, checkbutton):
272 self._verify()
273
274 - def on_has_bandwidth_limit_toggled(self, checkbutton):
275 self._verify()
276