Package flumotion :: Package component :: Package misc :: Package httpserver :: Module admin_gtk
[hide private]

Source Code for Module flumotion.component.misc.httpserver.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 webbrowser 
 25   
 26  from flumotion.common.format import formatStorage 
 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  __version__ = "$Rev: 6784 $" 
 32  _ = gettext.gettext 
 33   
 34   
35 -class StatisticsAdminGtkNode(BaseAdminGtkNode):
36 gladeFile = os.path.join('flumotion', 'component', 'misc', 37 'httpserver', 'httpserver.glade') 38
39 - def __init__(self, *args, **kwargs):
40 BaseAdminGtkNode.__init__(self, *args, **kwargs) 41 self._shown = False 42 self._statistics = None 43 self._stats = None 44 self._labels = {} 45 self._link = None
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 for labelType in ['bytes-transferred', 'connected-clients']: 54 self._registerLabel(labelType) 55 56 self._updateLabels({ 57 'bytes-transferred': 0, 58 'connected-clients': 0, 59 }) 60 if self._stats: 61 self.shown = True 62 self._updateLabels(self._stats) 63 self._statistics.show_all() 64 65 return self._statistics
66 67 # Public API 68
69 - def setStats(self, stats):
70 """Update the state containing all information used by this 71 interface 72 @param stats: 73 @type stats: AdminComponentUIState 74 """ 75 # Set _stats regardless of if condition 76 # Used to be a race where _stats was 77 # not set if widget tree was gotten before 78 # ui state 79 self._stats = stats 80 81 if not self._statistics: 82 # widget tree not created yet 83 return 84 85 self._updateLabels(stats) 86 87 if not self._shown: 88 # widget tree created but not yet shown 89 self._shown = True 90 self._statistics.show_all()
91 92 # Private 93
94 - def _updateLabels(self, state):
95 for name in self._labels: 96 text = state.get(name) 97 if text is not None: 98 if name == 'bytes-transferred': 99 text = formatStorage(int(text)) + _('Byte') 100 self._labels[name].set_text(str(text)) 101 102 uri = state.get('stream-url') 103 if uri is not None: 104 if not self._link: 105 self._link = self._createLinkWidget(uri) 106 else: 107 self._link.set_uri(uri)
108
109 - def _registerLabel(self, name):
110 #widgetname = name.replace('-', '_') 111 # FIXME: make object member directly 112 widget = self.wtree.get_widget('label-' + name) 113 if not widget: 114 self.warning("FIXME: no widget %s" % name) 115 return 116 117 self._labels[name] = widget
118
119 - def _createLinkWidget(self, uri):
120 link = LinkWidget(uri) 121 link.set_callback(self._on_link_show_url) 122 link.show_all() 123 holder = self.wtree.get_widget('link-holder') 124 holder.add(link) 125 return link
126 127 # Callbacks 128
131 132
133 -class HTTPFileAdminGtk(BaseAdminGtk):
134 - def setup(self):
135 statistics = StatisticsAdminGtkNode(self.state, self.admin, 136 _("Statistics")) 137 self.nodes['Statistics'] = statistics 138 # FIXME: maybe make a protocol instead of overriding 139 return BaseAdminGtk.setup(self)
140
141 - def uiStateChanged(self, state):
142 self.nodes['Statistics'].setStats(state)
143 144 GUIClass = HTTPFileAdminGtk 145