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