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

Source Code for Module flumotion.component.consumers.disker.admin_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 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 os 
 23  import gtk 
 24   
 25  from flumotion.common import errors 
 26   
 27  from flumotion.component.base.admin_gtk import BaseAdminGtk 
 28  from flumotion.component.base.baseadminnode import BaseAdminGtkNode 
 29   
 30  __version__ = "$Rev: 6784 $" 
 31   
 32   
33 -class FilenameNode(BaseAdminGtkNode):
34 gladeFile = os.path.join('flumotion', 'component', 'consumers', 35 'disker', 'disker.glade') 36 37 currentFilenameLabel = None 38 currentFilenamePendingText = None 39 stopbutton = None 40 hasIcal = False 41
42 - def haveWidgetTree(self):
43 self.labels = {} 44 self.widget = self.wtree.get_widget('filename-widget') 45 self.currentFilenameLabel = self.wtree.get_widget('label-current') 46 if self.currentFilenamePendingText: 47 self.currentFilenameLabel.set_text(self.currentFilenamePendingText) 48 newbutton = self.wtree.get_widget('button-new') 49 newbutton.connect('clicked',self.cb_changefile_button_clicked) 50 self.stopbutton = self.wtree.get_widget('button-stop') 51 self.stopbutton.connect('clicked', self.cb_stop_button_clicked) 52 if self.hasIcal: 53 self.addScheduleWidget()
54
55 - def cb_changefile_button_clicked(self, button):
56 d = self.callRemote("changeFilename") 57 d.addErrback(self.changeFilenameErrback)
58
59 - def changeFilenameErrback(self,failure):
60 self.warning("Failure %s changing filename: %s" % ( 61 failure.type, failure.getErrorMessage())) 62 return None
63
64 - def cb_stop_button_clicked(self, button):
65 d = self.callRemote("stopRecording") 66 d.addErrback(self.stopRecordingErrback)
67
68 - def stopRecordingErrback(self, failure):
69 self.warning("Failure %s stopping recording: %s" % ( 70 failure.type, failure.getErrorMessage())) 71 return None
72
73 - def setUIState(self, state):
74 BaseAdminGtkNode.setUIState(self, state) 75 self.stateSet(state, 'filename', state.get('filename')) 76 self.stateSet(state, 'recording', state.get('recording')) 77 self.stateSet(state, 'can-schedule', state.get('can-schedule'))
78
79 - def stateSet(self, state, key, value):
80 if key == 'filename': 81 if self.currentFilenameLabel: 82 self.currentFilenameLabel.set_text(value or '<waiting>') 83 else: 84 self.currentFilenamePendingText = value 85 if key == 'recording': 86 if not value: 87 if self.currentFilenameLabel: 88 self.currentFilenameLabel.set_text('None') 89 else: 90 self.currentFilenamePendingText = "None" 91 if self.stopbutton: 92 self.stopbutton.set_sensitive(value) 93 if key == 'can-schedule' and value: 94 self.hasIcal = True 95 if self.widget: 96 self.addScheduleWidget()
97
98 - def addScheduleWidget(self):
99 self.filechooser = gtk.FileChooserButton("Upload a schedule") 100 self.filechooser.set_local_only(True) 101 self.filechooser.set_action(gtk.FILE_CHOOSER_ACTION_OPEN) 102 filefilter = gtk.FileFilter() 103 filefilter.add_pattern("*.ics") 104 filefilter.set_name("vCalendar files") 105 self.filechooser.add_filter(filefilter) 106 self.filechooser.show() 107 scheduleButton = gtk.Button("Schedule recordings") 108 scheduleButton.show() 109 scheduleButton.connect("clicked", self.cb_schedule_recordings) 110 self.widget.attach(scheduleButton, 0, 1, 1, 2, 111 xoptions=0, yoptions=0, xpadding=6, ypadding=6) 112 self.widget.attach(self.filechooser, 1, 2, 1, 2, 113 xoptions = gtk.EXPAND|gtk.FILL, yoptions=0, xpadding=6, ypadding=6)
114
115 - def cb_schedule_recordings(self, widget):
116 filename = self.filechooser.get_filename() 117 self.debug("filename is %r, uri %r, %r", filename, self.filechooser.get_uri(), self.filechooser) 118 if filename: 119 icsStr = open(filename, "rb").read() 120 d = self.callRemote("scheduleRecordings", icsStr) 121 d.addErrback(self.scheduleRecordingsErrback) 122 else: 123 self.warning("No filename selected")
124
125 - def scheduleRecordingsErrback(self, failure):
126 self.warning("Failure %s scheduling recordings: %s" % ( 127 failure.type, failure.getErrorMessage())) 128 return None
129
130 -class DiskerAdminGtk(BaseAdminGtk):
131 - def setup(self):
132 filename = FilenameNode(self.state, self.admin, "Filename") 133 self.nodes['Filename'] = filename 134 return BaseAdminGtk.setup(self)
135 136 GUIClass = DiskerAdminGtk 137