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