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