Package flumotion :: Package component :: Package bouncers :: Module admin_gtk
[hide private]

Source Code for Module flumotion.component.bouncers.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   
 24  import gettext 
 25  import gtk 
 26   
 27  from twisted.internet import defer 
 28   
 29  from flumotion.common import errors, componentui 
 30  from flumotion.twisted import flavors 
 31  from flumotion.component.base.admin_gtk import BaseAdminGtk 
 32  from flumotion.component.base.baseadminnode import BaseAdminGtkNode 
 33   
 34  _ = gettext.gettext 
 35  __version__ = "$Rev: 6981 $" 
 36  ( 
 37    COLUMN_ID, 
 38    COLUMN_USER, 
 39    COLUMN_ADDRESS, 
 40  ) = range(3) 
 41   
 42   
43 -class KeycardsNode(BaseAdminGtkNode):
44 - def render(self):
45 self._iters = {} # iter -> data dict mapping 46 self.model = gtk.ListStore(str, str, str) 47 48 gladeFile = os.path.join('flumotion', 'component', 'bouncers', 49 'bouncer.glade') 50 d = self.loadGladeFile(gladeFile) 51 d.addCallback(self._loadGladeFileCallback) 52 return d
53
54 - def stateAppend(self, state, key, value):
55 self._append(value)
56
57 - def stateRemove(self, state, key, value):
58 self._remove(value)
59
60 - def _loadGladeFileCallback(self, widgetTree):
61 self.wtree = widgetTree 62 63 self.widget = self.wtree.get_widget('keycards-widget') 64 self.tree = self.wtree.get_widget('keycards-treeview') 65 self.tree.set_model(self.model) 66 self.tree.set_headers_clickable(True) 67 treeselection = self.tree.get_selection() 68 treeselection.set_mode(gtk.SELECTION_MULTIPLE) 69 70 button = self.wtree.get_widget('expire-button') 71 button.connect('clicked', self._expire_clicked, treeselection) 72 73 col = gtk.TreeViewColumn('ID', gtk.CellRendererText(), text=COLUMN_ID) 74 self.tree.append_column(col) 75 col = gtk.TreeViewColumn('user', gtk.CellRendererText(), 76 text=COLUMN_USER) 77 self.tree.append_column(col) 78 col = gtk.TreeViewColumn('address', gtk.CellRendererText(), 79 text=COLUMN_ADDRESS) 80 self.tree.append_column(col) 81 82 d = self.callRemote('getUIState') 83 d.addCallback(self._gotStateCallback) 84 d.addCallback(lambda x: self.widget) 85 return d
86
87 - def _gotStateCallback(self, result):
88 # we need to store the state ref we get; if not, it gets GC'd here, 89 # and then in the manager, and then our listener doesn't work anymore 90 self._uiState = result 91 keycardsData = result.get('keycards') 92 self.debug('_gotState: got %d keycards' % len(keycardsData)) 93 94 for data in keycardsData: 95 self._append(data)
96
97 - def _expire_clicked(self, button, treeselection):
98 (model, pathlist) = treeselection.get_selected_rows() 99 ids = [] 100 for path in pathlist: 101 model_iter = model.get_iter(path) 102 ids.append(model.get_value(model_iter, COLUMN_ID)) 103 104 self.debug('expiring %d keycards' % len(ids)) 105 106 d = defer.succeed(None) 107 for keycard_id in ids: 108 # we need to pass in i as well, to make sure we actually iterate 109 # instead of adding a bunch of lambdas with the same id to expire 110 d.addCallback(lambda res, i: self.callRemote('expireKeycardId', i), 111 keycard_id) 112 113 return d
114
115 - def _append(self, data):
116 keycard_id = data['id'] 117 model_iter = self.model.append() 118 # GtkListStore garantuees validity of iter as long as row lives 119 self._iters[keycard_id] = model_iter 120 self.model.set_value(model_iter, COLUMN_ID, keycard_id) 121 122 if 'username' in data.keys(): 123 self.model.set_value(model_iter, COLUMN_USER, data['username']) 124 if 'address' in data.keys(): 125 self.model.set_value(model_iter, COLUMN_ADDRESS, data['address'])
126
127 - def _remove(self, data):
128 keycard_id = data['id'] 129 model_iter = self._iters[keycard_id] 130 del self._iters[keycard_id] 131 self.model.remove(model_iter)
132
133 -class HTPasswdCryptAdminGtk(BaseAdminGtk):
134 - def setup(self):
135 # FIXME: have constructor take self instead ? 136 keycards = KeycardsNode(self.state, self.admin, _("Keycards")) 137 self.nodes['Keycards'] = keycards 138 return BaseAdminGtk.setup(self)
139 140 GUIClass = HTPasswdCryptAdminGtk 141