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