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