Package flumotion :: Package admin :: Package gtk :: Module connections
[hide private]

Source Code for Module flumotion.admin.gtk.connections

  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 th 
 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   
 23  import os 
 24   
 25  import gtk 
 26  import gtk.glade 
 27  import gobject 
 28   
 29  from flumotion.ui.glade import GladeWidget, GladeWindow 
 30  from flumotion.configure import configure 
 31  from flumotion.common import pygobject 
 32  from flumotion.common.pygobject import gsignal, gproperty 
 33   
 34  from flumotion.admin import connections 
 35   
 36           
37 -class Connections(GladeWidget):
38 glade_file = 'connections.glade' 39 40 STR_COL = 0 41 FILE_COL = 1 42 STATE_COL = 2 43 44 model = None 45 gsignal('has-selection', bool) 46 gsignal('connection-activated', object) 47 48 treeview_connections = None 49
50 - def __init__(self):
51 GladeWidget.__init__(self) 52 v = self.treeview_connections 53 54 c = gtk.TreeViewColumn('Host', gtk.CellRendererText(), 55 text=self.STR_COL) 56 v.append_column(c) 57 58 self._populate_liststore() 59 v.set_model(self.model) 60 61 # Bizarre. This doesn't work at all. 62 #self.scrolledwindow1.set_property('can-focus', False) 63 64 self.connect('grab-focus', self.on_grab_focus) 65 66 s = self.treeview_connections.get_selection() 67 s.set_mode(gtk.SELECTION_SINGLE) 68 if self.model.get_iter_first(): 69 s.select_path((0,)) 70 self.emit('has-selection', True) 71 else: 72 self.emit('has-selection', False)
73
74 - def _populate_liststore(self):
75 self.model = gtk.ListStore(str, str, object) 76 for x in connections.get_recent_connections(): 77 i = self.model.append() 78 self.model.set(i, self.STR_COL, x['name'], self.FILE_COL, x['file'], 79 self.STATE_COL, x['info'])
80
81 - def _clear_iter(self, i):
82 os.unlink(self.model.get_value(i, self.FILE_COL)) 83 self.model.remove(i)
84
85 - def on_grab_focus(self, *args):
86 v = self.treeview_connections 87 model, i = v.get_selection().get_selected() 88 if model: 89 v.set_cursor(model.get_path(i), None, False) 90 self.treeview_connections.grab_focus() 91 return True
92
93 - def on_clear_all(self, *args):
94 m = self.model 95 i = m.get_iter_first() 96 while i: 97 self._clear_iter(i) 98 i = m.get_iter_first() 99 self.emit('has-selection', False)
100
101 - def on_clear(self, *args):
102 s = self.treeview_connections.get_selection() 103 model, i = s.get_selected() 104 if i: 105 self._clear_iter(i) 106 if model.get_iter_first(): 107 s.select_path((0,)) 108 else: 109 self.emit('has-selection', False)
110
111 - def on_row_activated(self, *args):
112 self.emit('connection-activated', self.get_selected())
113
114 - def get_selected(self):
115 s = self.treeview_connections.get_selection() 116 model, i = s.get_selected() 117 if i: 118 return model.get_value(i, self.STATE_COL) 119 else: 120 return None
121 pygobject.type_register(Connections) 122 123
124 -class ConnectionsDialog(GladeWindow):
125 glade_file = 'connection-dialog.glade' 126 127 gsignal('have-connection', object) 128
129 - def on_has_selection(self, widget, has_selection):
130 self.widgets['button_ok'].set_sensitive(has_selection)
131
132 - def on_connection_activated(self, widget, state):
133 self.emit('have-connection', state)
134
135 - def on_cancel(self, widget):
136 self.destroy()
137
138 - def on_ok(self, x):
139 self.emit('have-connection', 140 self.widgets['connections'].get_selected())
141 pygobject.type_register(ConnectionsDialog) 142 143
144 -class OpenConnection(GladeWidget):
145 glade_file = 'open-connection.glade' 146 147 gproperty(bool, 'can-activate', 'If the state of the widget is complete', 148 False) 149
150 - def __init__(self):
151 self.host_entry = self.port_entry = self.ssl_check = None 152 GladeWidget.__init__(self) 153 self.set_property('can-activate', False) 154 self.on_entries_changed() 155 self.connect('grab-focus', self.on_grab_focus)
156
157 - def on_grab_focus(self, *args):
158 self.host_entry.grab_focus() 159 return True
160
161 - def on_entries_changed(self, *args):
162 old_can_act = self.get_property('can-activate') 163 can_act = self.host_entry.get_text() and self.port_entry.get_text() 164 # fixme: validate input 165 if old_can_act != can_act: 166 self.set_property('can-activate', can_act)
167
168 - def on_ssl_check_toggled(self, button):
169 if button.get_active(): 170 self.port_entry.set_text('7531') 171 else: 172 self.port_entry.set_text('8642')
173
174 - def set_state(self, state):
175 self.host_entry.set_text(state['host']) 176 self.port_entry.set_text(str(state['port'])) 177 self.ssl_check.set_active(not state['use_insecure'])
178
179 - def get_state(self):
180 return {'host': self.host_entry.get_text(), 181 'port': int(self.port_entry.get_text()), 182 'use_insecure': not self.ssl_check.get_active()}
183 pygobject.type_register(OpenConnection) 184 185
186 -class Authenticate(GladeWidget):
187 glade_file = 'authenticate.glade' 188 189 gproperty(bool, 'can-activate', 'If the state of the widget is complete', 190 False) 191 192 # pychecker sacrifices 193 auth_method_combo = None 194 user_entry = None 195 passwd_entry = None 196
197 - def __init__(self, *args):
198 GladeWidget.__init__(self, *args) 199 self.auth_method_combo.set_active(0) 200 self.set_property('can-activate', False) 201 self.user_entry.connect('activate', 202 lambda *x: self.passwd_entry.grab_focus()) 203 self.connect('grab-focus', self.on_grab_focus)
204
205 - def on_grab_focus(self, *args):
206 self.user_entry.grab_focus()
207
208 - def on_entries_changed(self, *args):
209 can_act = self.user_entry.get_text() and self.passwd_entry.get_text() 210 self.set_property('can-activate', can_act)
211
212 - def set_state(self, state):
213 if state and 'user' in state: 214 self.user_entry.set_text(state['user']) 215 self.passwd_entry.set_text(state['passwd']) 216 else: 217 self.user_entry.set_text('') 218 self.passwd_entry.set_text('')
219
220 - def get_state(self):
221 return {'user': self.user_entry.get_text(), 222 'passwd': self.passwd_entry.get_text()}
223 pygobject.type_register(Authenticate) 224