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

Source Code for Module flumotion.component.consumers.httpstreamer.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,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  import time 
 25   
 26  from flumotion.common.mimetypes import launchApplicationByUrl 
 27  from flumotion.component.base.admin_gtk import BaseAdminGtk 
 28  from flumotion.component.base.baseadminnode import BaseAdminGtkNode 
 29  from flumotion.ui.linkwidget import LinkWidget 
 30   
 31  _ = gettext.gettext 
 32  __version__ = "$Rev: 6981 $" 
 33   
 34   
35 -class StatisticsAdminGtkNode(BaseAdminGtkNode):
36 gladeFile = os.path.join('flumotion', 'component', 'consumers', 37 'httpstreamer', 'httpstreamer.glade') 38
39 - def __init__(self, *args, **kwargs):
40 BaseAdminGtkNode.__init__(self, *args, **kwargs) 41 self._statistics = None 42 self._shown = False 43 self._stats = None 44 self._link = None 45 self._labels = {}
46 47 # BaseAdminGtkNode 48
49 - def haveWidgetTree(self):
50 self._labels = {} 51 self._statistics = self.wtree.get_widget('main_vbox') 52 self.widget = self._statistics 53 54 for name in ['uptime', 'mime', 'current-bitrate', 'bitrate', 55 'totalbytes']: 56 self._registerLabel('stream-' + name) 57 for name in ['current', 'average', 'max', 'peak', 'peak-time']: 58 self._registerLabel('clients-' + name) 59 for name in ['bitrate', 'bitrate-current', 'totalbytes']: 60 self._registerLabel('consumption-' + name) 61 62 if self._stats: 63 self._shown = True 64 self._updateLabels(self._stats) 65 self._statistics.show_all() 66 67 return self._statistics
68
69 - def setStats(self, stats):
70 # Set _stats regardless of if condition 71 # Used to be a race where _stats was 72 # not set if widget tree was gotten before 73 # ui state 74 self._stats = stats 75 if not self._statistics: 76 return 77 78 self._updateLabels(stats) 79 80 if not self._shown: 81 # widget tree created but not yet shown 82 self._shown = True 83 self._statistics.show_all()
84 85 # Private 86
87 - def _registerLabel(self, name):
88 # widgetname = name.replace('-', '_') 89 # FIXME: make object member directly 90 widget = self.wtree.get_widget('label-' + name) 91 if not widget: 92 print "FIXME: no widget %s" % name 93 return 94 95 self._labels[name] = widget
96
97 - def _updateLabels(self, state):
98 # changed in 0.1.9.1 to be int so we can localize time 99 peakTime = state.get('clients-peak-time') 100 if not isinstance(peakTime, str): 101 peakTime = time.strftime("%c", time.localtime(peakTime)) 102 103 self._labels['clients-peak-time'].set_text(peakTime) 104 105 for name in self._labels: 106 if name == 'clients-peak-time': 107 continue 108 text = state.get(name) 109 if text is None: 110 text = '' 111 112 self._labels[name].set_text(text) 113 114 uri = state.get('stream-url') or '' 115 if not self._link: 116 self._link = self._createLinkWidget(uri) 117 118 if self._link is not None: 119 self._link.set_uri(uri)
120
121 - def _createLinkWidget(self, uri):
122 holder = self.wtree.get_widget('link-holder') 123 if holder is None: 124 return 125 link = LinkWidget(uri) 126 link.set_callback(self._on_link_show_url) 127 link.show_all() 128 holder.add(link) 129 return link
130 131 # Callbacks 132
135 136
137 -class HTTPStreamerAdminGtk(BaseAdminGtk):
138 - def setup(self):
139 statistics = StatisticsAdminGtkNode(self.state, self.admin, 140 _("Statistics")) 141 self.nodes['Statistics'] = statistics 142 # FIXME: maybe make a protocol instead of overriding 143 return BaseAdminGtk.setup(self)
144
145 - def uiStateChanged(self, state):
146 self.nodes['Statistics'].setStats(state)
147 148 # FIXME: tie this to the statistics node better
149 - def component_statsChanged(self, stats):
150 # FIXME: decide on state/stats/statistics 151 self.nodes['Statistics'].setStats(stats)
152
153 - def component_logMessage(self, message):
154 self.nodes['Log'].logMessage(message)
155 156 GUIClass = HTTPStreamerAdminGtk 157