Package flumotion :: Package component :: Package consumers :: Package disker :: Module wizard_gtk
[hide private]

Source Code for Module flumotion.component.consumers.disker.wizard_gtk

  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,2009 Fluendo, S.L. 
  6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
  7  # All rights reserved. 
  8  # 
  9  # This file may be distributed and/or modified under the terms of 
 10  # the GNU Lesser General Public License version 2.1 as published by 
 11  # the Free Software Foundation. 
 12  # This file is distributed without any warranty; without even the implied 
 13  # warranty of merchantability or fitness for a particular purpose. 
 14  # See "LICENSE.LGPL" in the source distribution for more information. 
 15  # 
 16  # Headers in this file shall remain intact. 
 17   
 18  import gettext 
 19  import os 
 20   
 21  from zope.interface import implements 
 22  import gtk 
 23   
 24  from flumotion.admin.assistant.interfaces import IConsumerPlugin 
 25  from flumotion.admin.assistant.models import Consumer 
 26  from flumotion.admin.gtk.basesteps import ConsumerStep 
 27  from flumotion.ui.fileselector import FileSelectorDialog 
 28   
 29  __version__ = "$Rev$" 
 30  _ = gettext.gettext 
 31   
 32  (SIZE_KB, 
 33   SIZE_MB, 
 34   SIZE_GB, 
 35   SIZE_TB) = tuple([1 << (10L*i) for i in range(1, 5)]) 
 36   
 37  TIME_MINUTE = 60 
 38  TIME_HOUR = 60*60 
 39  TIME_DAY = 60*60*24 
 40  TIME_WEEK = 60*60*24*7 
 41   
 42   
43 -class Disker(Consumer):
44 """I am a model representing the configuration file for a 45 Disk consumer. 46 47 @ivar has_time: if rotation should be done based on time 48 @ivar has_size: if rotation should be done based on size 49 @ivar time_unit: the selected size unit, 50 size will be multiplied by this value when saved 51 @ivar size_unit: the selected time unit, 52 time will be multiplied by this value when saved 53 """ 54 componentType = 'disk-consumer' 55 prefix = 'disk' 56
57 - def __init__(self):
58 super(Disker, self).__init__() 59 self.has_size = False 60 self.has_time = False 61 self.size = 10 62 self.size_unit = SIZE_KB 63 self.time = 12 64 self.time_unit = TIME_HOUR 65 66 self.properties.directory = "/tmp" 67 self.properties.start_recording = False
68
69 - def _getRotationType(self):
70 if self.has_time: 71 return 'time' 72 elif self.has_size: 73 return 'size' 74 else: 75 return 'none'
76 77 # Component 78
79 - def getProperties(self):
80 properties = super(Disker, self).getProperties() 81 properties.rotate_type = self._getRotationType() 82 if 'size' == properties.rotate_type: 83 properties.size = self.size_unit * self.size 84 elif 'time' == properties.rotate_type: 85 properties.time = self.time_unit * self.time 86 87 return properties
88 89
90 -class DiskStep(ConsumerStep):
91 gladeFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 92 'wizard.glade') 93 icon = 'kcmdevices.png' 94
95 - def __init__(self, wizard):
96 self.model = Disker() 97 ConsumerStep.__init__(self, wizard)
98 99 # ConsumerStep 100
101 - def getConsumerModel(self):
102 return self.model
103 104 # WizardStep 105
106 - def setup(self):
107 self.directory.data_type = str 108 self.has_size.data_type = bool 109 self.has_time.data_type = bool 110 self.size.data_type = int 111 self.size_unit.data_type = long 112 self.start_recording.data_type = bool 113 self.time.data_type = int 114 self.time_unit.data_type = int 115 116 self.size_unit.prefill([ 117 (_('kB'), SIZE_KB), 118 (_('MB'), SIZE_MB), 119 (_('GB'), SIZE_GB), 120 (_('TB'), SIZE_TB), 121 ]) 122 self.time_unit.prefill([ 123 (_('minute(s)'), TIME_MINUTE), 124 (_('hour(s)'), TIME_HOUR), 125 (_('day(s)'), TIME_DAY), 126 (_('week(s)'), TIME_WEEK)]) 127 self.time_unit.select(TIME_HOUR) 128 129 self.add_proxy(self.model, 130 ['has_size', 131 'has_time', 132 'rotate', 133 'size_unit', 134 'time_unit', 135 'time', 136 'size']) 137 138 self._proxy = self.add_proxy(self.model.properties, 139 ['directory', 140 'start_recording'])
141
142 - def workerChanged(self, worker):
143 self.model.worker = worker 144 self.wizard.requireElements(self.worker, 'multifdsink')
145 146 # Private 147
148 - def _updateRadio(self):
149 rotate = self.rotate.get_active() 150 self.has_size.set_sensitive(rotate) 151 self.has_time.set_sensitive(rotate) 152 153 hasSize = rotate and self.has_size.get_active() 154 self.size.set_sensitive(hasSize) 155 self.size_unit.set_sensitive(hasSize) 156 self.model.has_size = hasSize 157 158 hasTime = rotate and self.has_time.get_active() 159 self.time.set_sensitive(hasTime) 160 self.time_unit.set_sensitive(hasTime) 161 self.model.has_time = hasTime
162
163 - def _select(self):
164 165 def response(fs, response): 166 fs.hide() 167 if response == gtk.RESPONSE_OK: 168 self.model.properties.directory = fs.getFilename() 169 self._proxy.update('directory')
170 171 def deleteEvent(fs, event): 172 pass
173 fs = FileSelectorDialog(self.wizard.window, 174 self.wizard.getAdminModel()) 175 fs.connect('response', response) 176 fs.connect('delete-event', deleteEvent) 177 fs.selector.setWorkerName(self.model.worker) 178 fs.setDirectory(self.model.properties.directory) 179 fs.show_all() 180 181 # Callbacks 182
183 - def on_has_time__toggled(self, radio):
184 self._updateRadio()
185
186 - def on_has_size__toggled(self, radio):
187 self._updateRadio()
188
189 - def on_rotate__toggled(self, check):
190 self._updateRadio()
191
192 - def on_select__clicked(self, check):
193 self._select()
194 195
196 -class DiskBothStep(DiskStep):
197 name = 'Disk (audio & video)' 198 title = _('Disk (Audio and Video)') 199 sidebarName = _('Disk Audio/Video') 200 201 # ConsumerStep 202
203 - def getConsumerType(self):
204 return 'audio-video'
205 206
207 -class DiskAudioStep(DiskStep):
208 name = 'Disk (audio only)' 209 title = _('Disk (Audio Only)') 210 sidebarName = _('Disk Audio') 211 212 # ConsumerStep 213
214 - def getConsumerType(self):
215 return 'audio'
216 217
218 -class DiskVideoStep(DiskStep):
219 name = 'Disk (video only)' 220 title = _('Disk (Video Only)') 221 sidebarName = _('Disk Video') 222 223 # ConsumerStep 224
225 - def getConsumerType(self):
226 return 'video'
227 228
229 -class DiskConsumerWizardPlugin(object):
230 implements(IConsumerPlugin) 231
232 - def __init__(self, wizard):
233 self.wizard = wizard
234
235 - def getConsumptionStep(self, type):
236 if type == 'video': 237 return DiskVideoStep(self.wizard) 238 elif type == 'audio': 239 return DiskAudioStep(self.wizard) 240 elif type == 'audio-video': 241 return DiskBothStep(self.wizard)
242