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,2008 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  """connection widgets and dialogs""" 
 23   
 24  import os 
 25  import gettext 
 26   
 27  import gobject 
 28  import gtk 
 29  from kiwi.ui.objectlist import Column 
 30  from pango import ELLIPSIZE_MIDDLE 
 31   
 32  from flumotion.admin.connections import getRecentConnections, \ 
 33       hasRecentConnections 
 34  from flumotion.common.pygobject import gsignal, gproperty 
 35  from flumotion.ui.glade import GladeWidget, GladeWindow 
 36   
 37  __version__ = "$Rev: 7956 $" 
 38  _ = gettext.gettext 
 39   
 40   
41 -def format_timestamp(stamp):
42 return stamp.strftime('%x')
43 44
45 -class Connections(GladeWidget):
46 gladeFile = 'connections.glade' 47 48 gsignal('have-connection', bool) 49 gsignal('connection-activated', object) 50 gsignal('connections-cleared') 51
52 - def __init__(self):
53 GladeWidget.__init__(self) 54 55 self.connections.set_columns( 56 [Column("host", title=_("Hostname"), searchable=True, 57 ellipsize=ELLIPSIZE_MIDDLE, expand=True, width=100), 58 Column("timestamp", title=_("Last used"), 59 sorted=True, 60 order=gtk.SORT_DESCENDING, 61 format_func=format_timestamp), 62 ]) 63 self.connections.add_list(getRecentConnections()) 64 self.connections.get_treeview().set_search_equal_func( 65 self._searchEqual) 66 self.connections.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) 67 self.connections.set_property('selection-mode', gtk.SELECTION_SINGLE) 68 self.connections.set_size_request(-1, 160) 69 70 self._updateButtons()
71
72 - def _updateButtons(self):
73 canClear = hasRecentConnections() 74 self.button_clear.set_sensitive(canClear) 75 self.button_clear_all.set_sensitive(canClear) 76 if not canClear: 77 self.emit('connections-cleared')
78
79 - def _searchEqual(self, model, column, key, iter):
80 connection = model.get(iter, column)[0] 81 if key in connection.name: 82 return False 83 84 # True means doesn't match 85 return True
86
87 - def _clear_all(self):
88 for conn in self.connections: 89 os.unlink(conn.filename) 90 self.connections.clear()
91
92 - def _clear(self, conn):
93 self.connections.remove(conn) 94 os.unlink(conn.filename)
95 96 # Public API 97
98 - def grab_focus(self):
99 if len(self.connections): 100 self.connections.select(self.connections[0]) 101 self.connections.grab_focus()
102
103 - def get_selected(self):
104 return self.connections.get_selected()
105
106 - def update(self, connection):
107 os.utime(connection.filename, None)
108 109 # Callbacks 110
111 - def on_button_clear_clicked(self, button):
112 conn = self.connections.get_selected() 113 if conn: 114 self._clear(conn) 115 self._updateButtons()
116
117 - def on_button_clear_all_clicked(self, button):
118 self._clear_all() 119 self._updateButtons()
120
121 - def _on_connections_row_activated(self, connections, connection):
122 self.emit('connection-activated', connection)
123
124 - def _on_connections_selection_changed(self, connections, connection):
125 self.emit('have-connection', bool(connection))
126 127 gobject.type_register(Connections) 128 129
130 -class ConnectionsDialog(GladeWindow):
131 gladeFile = 'connection-dialog.glade' 132 133 gsignal('have-connection', object) 134
135 - def on_connection_activated(self, widget, state):
136 self.emit('have-connection', state)
137
138 - def on_cancel(self, button):
139 self.destroy()
140
141 - def on_ok(self, button):
142 self.emit('have-connection', 143 self.widgets['connections'].get_selected())
144
145 - def on_delete_event(self, dialog, event):
146 self.destroy()
147
148 - def on_connections_cleared(self, widget):
149 self.button_ok.set_sensitive(False)
150 151 gobject.type_register(ConnectionsDialog) 152 153
154 -class OpenConnection(GladeWidget):
155 gladeFile = 'open-connection.glade' 156 157 gproperty(bool, 'can-activate', 'If the state of the widget is complete', 158 False) 159
160 - def __init__(self):
161 self.host_entry = self.port_entry = self.ssl_check = None 162 GladeWidget.__init__(self) 163 self.set_property('can-activate', False) 164 self.on_entries_changed() 165 self.connect('grab-focus', self.on_grab_focus)
166
167 - def on_grab_focus(self, *args):
168 self.host_entry.grab_focus() 169 return True
170
171 - def on_entries_changed(self, *args):
172 old_can_act = self.get_property('can-activate') 173 can_act = self.host_entry.get_text() and self.port_entry.get_text() 174 # fixme: validate input 175 if old_can_act != can_act: 176 self.set_property('can-activate', can_act)
177
178 - def on_ssl_check_toggled(self, button):
179 if button.get_active(): 180 self.port_entry.set_text('7531') 181 else: 182 self.port_entry.set_text('8642')
183
184 - def set_state(self, state):
185 self.host_entry.set_text(state['host']) 186 self.port_entry.set_text(str(state['port'])) 187 self.ssl_check.set_active(not state['use_insecure'])
188
189 - def get_state(self):
190 return {'host': self.host_entry.get_text(), 191 'port': int(self.port_entry.get_text()), 192 'use_insecure': not self.ssl_check.get_active()}
193 gobject.type_register(OpenConnection) 194 195
196 -class Authenticate(GladeWidget):
197 gladeFile = 'authenticate.glade' 198 199 gproperty(bool, 'can-activate', 'If the state of the widget is complete', 200 False) 201 202 # pychecker sacrifices 203 auth_method_combo = None 204 user_entry = None 205 passwd_entry = None 206
207 - def __init__(self, *args):
208 GladeWidget.__init__(self, *args) 209 self.set_property('can-activate', False) 210 self.user_entry.connect('activate', 211 lambda *x: self.passwd_entry.grab_focus()) 212 self.connect('grab-focus', self.on_grab_focus)
213
214 - def on_passwd_entry_activate(self, entry):
215 toplevel = self.get_toplevel() 216 toplevel.wizard.next()
217
218 - def on_grab_focus(self, *args):
220
221 - def on_entries_changed(self, *args):
222 can_act = self.user_entry.get_text() and self.passwd_entry.get_text() 223 self.set_property('can-activate', can_act)
224
225 - def set_state(self, state):
226 if state and 'user' in state: 227 self.user_entry.set_text(state['user']) 228 self.passwd_entry.set_text(state['passwd']) 229 else: 230 self.user_entry.set_text('') 231 self.passwd_entry.set_text('')
232
233 - def get_state(self):
234 return {'user': self.user_entry.get_text(), 235 'passwd': self.passwd_entry.get_text()}
236 gobject.type_register(Authenticate) 237