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