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