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 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 time 
 24   
 25  import gtk 
 26   
 27  from gettext import gettext as _ 
 28   
 29  from flumotion.component.base.admin_gtk import BaseAdminGtk, BaseAdminGtkNode 
 30   
31 -class StatisticsAdminGtkNode(BaseAdminGtkNode):
32 glade_file = os.path.join('flumotion', 'component', 'consumers', 33 'httpstreamer', 'http.glade') 34
35 - def __init__(self, *args, **kwargs):
36 BaseAdminGtkNode.__init__(self, *args, **kwargs) 37 self.shown = False 38 self._stats = None 39 self._hasgnomevfs = False 40 try: 41 __import__('gnomevfs') 42 self._hasgnomevfs = True 43 except: 44 pass
45
46 - def error_dialog(self, message):
47 # FIXME: dialogize 48 print 'ERROR:', message
49
50 - def cb_getMimeType(self, mime, label):
51 label.set_text(_('Mime type:') + " %s" % mime) 52 label.show()
53
54 - def setStats(self, stats):
55 # Set _stats regardless of if condition 56 # Used to be a race where _stats was 57 # not set if widget tree was gotten before 58 # ui state 59 self._stats = stats 60 if not hasattr(self, 'statistics'): 61 # widget tree not created yet 62 return 63 64 self.updateLabels(stats) 65 66 if not self.shown: 67 # widget tree created but not yet shown 68 self.shown = True 69 self.statistics.show_all()
70
71 - def registerLabel(self, name):
72 #widgetname = name.replace('-', '_') 73 #FIXME: make object member directly 74 widget = self.wtree.get_widget('label-' + name) 75 if widget: 76 self.labels[name] = widget 77 else: 78 print "FIXME: no widget %s" % name
79
80 - def hideLabels(self):
81 for name in self.labels.keys(): 82 self.labels[name].hide()
83
84 - def updateLabels(self, state):
85 if not hasattr(self, 'labels'): 86 return 87 88 # changed in 0.1.9.1 to be int so we can localize time 89 peakTime = state.get('clients-peak-time') 90 if not isinstance(peakTime, str): 91 peakTime = time.strftime("%c", time.localtime(peakTime)) 92 93 self.labels['clients-peak-time'].set_text(peakTime) 94 95 for name in self.labels.keys(): 96 if name == 'clients-peak-time': 97 continue 98 text = state.get(name) 99 if text == None: 100 text = '' 101 # set http url with nice pango markup if gnomevfs present 102 # if not it should be black...so ppl dont click on it 103 if name == 'stream-url' and self._hasgnomevfs: 104 text = '<span foreground="blue">%s</span>' % text 105 self.labels[name].set_markup(text) 106 else: 107 self.labels[name].set_text(text)
108
109 - def haveWidgetTree(self):
110 self.labels = {} 111 self.statistics = self.wtree.get_widget('statistics-widget') 112 self.widget = self.statistics 113 for type in ('uptime', 'mime', 'bitrate', 'totalbytes', 'url'): 114 self.registerLabel('stream-' + type) 115 for type in ('current', 'average', 'max', 'peak', 'peak-time'): 116 self.registerLabel('clients-' + type) 117 for type in ('bitrate', 'totalbytes'): 118 self.registerLabel('consumption-' + type) 119 120 if self._stats: 121 self.shown = True 122 self.updateLabels(self._stats) 123 self.statistics.show_all() 124 125 # add signal handler for Stream URL only if we have gnomevfs 126 # also signal handler to notify when mouse has gone over label 127 # so cursor changes 128 # add popup menu to let you open url or copy link location 129 130 if self._hasgnomevfs: 131 streamurl_widget_eventbox = self.wtree.get_widget('eventbox-stream-url') 132 streamurl_widget_eventbox.set_visible_window(False) 133 streamurl_widget_eventbox.connect('button-press-event', self._streamurl_clicked) 134 streamurl_widget_eventbox.connect('enter-notify-event', self._streamurl_enter) 135 streamurl_widget_eventbox.connect('leave-notify-event', self._streamurl_leave) 136 self._streamurl_popupmenu = gtk.Menu() 137 item = gtk.ImageMenuItem('_Open Link') 138 image = gtk.Image() 139 image.set_from_stock(gtk.STOCK_JUMP_TO, gtk.ICON_SIZE_MENU) 140 item.set_image(image) 141 item.show() 142 item.connect('activate', self._streamurl_openlink, streamurl_widget_eventbox) 143 self._streamurl_popupmenu.add(item) 144 item = gtk.ImageMenuItem('Copy _Link Address') 145 image = gtk.Image() 146 image.set_from_stock(gtk.STOCK_COPY, gtk.ICON_SIZE_MENU) 147 item.set_image(image) 148 item.show() 149 item.connect('activate', self._streamurl_copylink, streamurl_widget_eventbox) 150 self._streamurl_popupmenu.add(item) 151 152 return self.statistics
153 154 # signal handler for button press on stream url
155 - def _streamurl_clicked(self, widget, event):
156 # check if left click 157 if event.button == 1: 158 url = widget.get_children()[0].get_text() 159 import gnomevfs 160 if self._stats: 161 app_to_run = gnomevfs.mime_get_default_application( 162 self._stats.get('stream-mime')) 163 if app_to_run: 164 os.system("%s %s &" % (app_to_run[2],url)) 165 elif event.button == 3: 166 self._streamurl_popupmenu.popup(None, None, None, event.button, event.time)
167 168 # signal handler for open link menu item activation 169 # eventbox is the eventbox that contains the label the url is in 178 179 # signal handler for copy link menu item activation 180 # eventbox is the eventbox that contains the label the url is in 185 186 # motion event handles
187 - def _streamurl_enter(self, widget, event):
188 cursor = gtk.gdk.Cursor(widget.get_display(), gtk.gdk.HAND2) 189 window = widget.window 190 window.set_cursor(cursor)
191
192 - def _streamurl_leave(self, widget, event):
193 window = widget.window 194 window.set_cursor(None)
195 196
197 -class HTTPStreamerAdminGtk(BaseAdminGtk):
198 - def setup(self):
199 statistics = StatisticsAdminGtkNode(self.state, self.admin, 200 _("Statistics")) 201 self.nodes['Statistics'] = statistics 202 # FIXME: maybe make a protocol instead of overriding 203 return BaseAdminGtk.setup(self)
204
205 - def uiStateChanged(self, state):
206 self.nodes['Statistics'].setStats(state)
207 208 # FIXME: tie this to the statistics node better
209 - def component_statsChanged(self, stats):
210 # FIXME: decide on state/stats/statistics 211 self.nodes['Statistics'].setStats(stats)
212
213 - def component_logMessage(self, message):
214 self.nodes['Log'].logMessage(message)
215 216 GUIClass = HTTPStreamerAdminGtk 217