Ticket #1759: 0002-Showing-Errors-Palette-Mockup.patch
File 0002-Showing-Errors-Palette-Mockup.patch, 17.7 KB (added by Dcastelo, 14 years ago) |
---|
-
extensions/deviceicon/network.py
From 834d8070102ffceae5b4e002a502257d784f25a7 Mon Sep 17 00:00:00 2001 From: latu <latu@localhost.localdomain> Date: Fri, 26 Feb 2010 16:48:23 -0200 Subject: [PATCH 2/2] Showing Errors - Palette Mockup --- extensions/deviceicon/network.py | 176 +++++++++++++++++++++++++------------- src/jarabe/model/network.py | 70 +++++++++++++--- 2 files changed, 176 insertions(+), 70 deletions(-) diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py index fc72b6d..b4296d1 100644
a b from sugar.graphics.tray import TrayIcon 39 39 from sugar.graphics import xocolor 40 40 from sugar.util import unique_id 41 41 from sugar import profile 42 from sugar.graphics.icon import Icon 43 from sugar.graphics.menuitem import MenuItem 44 from sugar.graphics.alert import NotifyAlert 42 45 43 46 from jarabe.model import network 44 47 from jarabe.model.network import Settings … … _GSM_STATE_NOT_READY = 0 63 66 _GSM_STATE_DISCONNECTED = 1 64 67 _GSM_STATE_CONNECTING = 2 65 68 _GSM_STATE_CONNECTED = 3 66 _GSM_STATE_ NEED_AUTH= 469 _GSM_STATE_FAILED = 4 67 70 68 71 def frequency_to_channel(frequency): 69 72 ftoc = { 2412: 1, 2417: 2, 2422: 3, 2427: 4, … … class WiredPalette(Palette): 214 217 ip_address_text = "" 215 218 self._ip_address_label.set_text(ip_address_text) 216 219 220 217 221 class GsmPalette(Palette): 218 222 __gtype_name__ = 'SugarGsmPalette' 219 223 … … class GsmPalette(Palette): 225 229 } 226 230 227 231 def __init__(self): 228 232 229 233 Palette.__init__(self, label=_('Wireless modem')) 230 231 234 self._current_state = None 232 233 self._toggle_state_item = gtk.MenuItem('') 235 self._alert = None 236 237 self._toggle_state_item = MenuItem('') 234 238 self._toggle_state_item.connect('activate', self.__toggle_state_cb) 235 239 self.menu.append(self._toggle_state_item) 236 240 self._toggle_state_item.show() 237 241 238 self.set_state(_GSM_STATE_NOT_READY)239 240 242 self.info_box = gtk.VBox() 241 242 self.data_label = gtk.Label() 243 self.data_label.props.xalign = 0.0 244 label_alignment = self._add_widget_with_padding(self.data_label) 245 self.info_box.pack_start(label_alignment) 246 self.data_label.show() 243 self.conn_info_box = gtk.HBox() 244 245 icon = Icon(icon_name='go-up', icon_size=gtk.ICON_SIZE_MENU) 246 self.conn_info_box.pack_start(icon) 247 icon.show() 248 self._data_label_up = gtk.Label() 249 self._data_label_up.props.xalign = 0.0 250 label_alignment = self._add_widget_with_padding(self._data_label_up) 251 self.conn_info_box.pack_start(label_alignment) 252 self._data_label_up.show() 247 253 label_alignment.show() 248 254 249 self.connection_time_label = gtk.Label() 250 self.connection_time_label.props.xalign = 0.0 251 label_alignment = self._add_widget_with_padding( \ 252 self.connection_time_label) 253 self.info_box.pack_start(label_alignment) 254 self.connection_time_label.show() 255 icon = Icon(icon_name='go-down', icon_size=gtk.ICON_SIZE_MENU) 256 self.conn_info_box.pack_start(icon) 257 icon.show() 258 self._data_label_down = gtk.Label() 259 self._data_label_down.props.xalign = 0.0 260 label_alignment = self._add_widget_with_padding(self._data_label_down) 261 self.conn_info_box.pack_start(label_alignment) 262 self._data_label_down.show() 255 263 label_alignment.show() 256 264 265 self.conn_info_box.show() 266 self.info_box.pack_start(self.conn_info_box) 267 268 self._error_accept_item = MenuItem('') 269 self._error_accept_item.connect('activate', self.__error_accept_cb) 270 self.menu.append(self._error_accept_item) 271 257 272 self.info_box.show() 258 273 self.set_content(self.info_box) 259 274 275 self.set_state(_GSM_STATE_NOT_READY) 276 260 277 def _add_widget_with_padding(self, child, xalign=0, yalign=0.5): 261 278 alignment = gtk.Alignment(xalign=xalign, yalign=yalign, 262 279 xscale=1, yscale=0.33) … … class GsmPalette(Palette): 267 284 alignment.add(child) 268 285 return alignment 269 286 270 def set_state(self, state ):287 def set_state(self, state, reason=0): 271 288 self._current_state = state 272 self._update_label_and_text( )289 self._update_label_and_text(reason) 273 290 274 def _update_label_and_text(self): 291 def _update_label_and_text(self, reason=0): 292 275 293 if self._current_state == _GSM_STATE_NOT_READY: 276 294 self._toggle_state_item.get_child().set_label('...') 277 295 self.props.secondary_text = _('Please wait...') 278 296 279 297 elif self._current_state == _GSM_STATE_DISCONNECTED: 280 298 self._toggle_state_item.get_child().set_label(_('Connect')) 281 299 self.props.secondary_text = _('Disconnected') 282 300 icon = Icon(icon_name='media-playback-start', \ 301 icon_size=gtk.ICON_SIZE_MENU) 302 self._toggle_state_item.set_image(icon) 303 283 304 elif self._current_state == _GSM_STATE_CONNECTING: 284 305 self._toggle_state_item.get_child().set_label(_('Cancel')) 285 306 self.props.secondary_text = _('Connecting...') 307 icon = Icon(icon_name='media-playback-stop', \ 308 icon_size=gtk.ICON_SIZE_MENU) 309 self._toggle_state_item.set_image(icon) 286 310 287 311 elif self._current_state == _GSM_STATE_CONNECTED: 288 312 self._toggle_state_item.get_child().set_label(_('Disconnect')) 289 self.props.secondary_text = _('Connected') 290 291 elif self._current_state == _GSM_STATE_NEED_AUTH: 292 self._toggle_state_item.get_child().set_label(_('Sim requires Pin/Puk')) 293 self.props.secondary_text = _('Authentication Error') 313 self.update_connection_time() 314 icon = Icon(icon_name='media-eject', \ 315 icon_size=gtk.ICON_SIZE_MENU) 316 self._toggle_state_item.set_image(icon) 317 318 elif self._current_state == _GSM_STATE_FAILED: 319 self.add_alert(_('Error'), \ 320 self._get_connection_errors_by_nm_reason(reason)) 294 321 295 322 else: 296 323 raise ValueError('Invalid GSM state while updating label and ' \ 297 324 'text, %s' % str(self._current_state)) 298 325 326 def add_alert(self, title, message): 327 self._error_accept_item.get_child().set_label(title + ' : ' + message) 328 self._error_accept_item.show() 329 self._toggle_state_item.set_sensitive(False) 330 331 def __error_accept_cb(self, alert): 332 self._update_label_and_text() 333 self._error_accept_item.get_child().set_label('') 334 self._error_accept_item.hide() 335 self._toggle_state_item.set_sensitive(True) 336 337 def update_connection_time(self, connection_time=None): 338 if (connection_time is not None): 339 self.props.secondary_text = _('Connected for ' + \ 340 connection_time.strftime('%H:%M:%S')) 341 else: 342 self.props.secondary_text = _('Connected for ' \ 343 + '00:00:00') 344 345 def update_stats(self, in_bytes, out_bytes): 346 in_KBytes = in_bytes / 1024 347 out_KBytes = out_bytes / 1024 348 self._data_label_up.set_text(_("%d KB") % (out_KBytes)) 349 self._data_label_down.set_text(_("%d KB") % (in_KBytes)) 350 351 def _get_connection_errors_by_nm_reason(self, reason): 352 if reason in [network.NM_DEVICE_STATE_REASON_NO_SECRETS]: 353 message = _('The Pin/Puk configuration is not valid') 354 elif reason in [network.NM_DEVICE_STATE_REASON_PPP_DISCONNECT]: 355 message = _('Check the connection configuration') 356 else: 357 message = _('Check the connection configuration') 358 return message 359 299 360 def __toggle_state_cb(self, menuitem): 300 361 if self._current_state == _GSM_STATE_NOT_READY: 301 362 pass … … class GsmPalette(Palette): 305 366 self.emit('gsm-disconnect') 306 367 elif self._current_state == _GSM_STATE_CONNECTED: 307 368 self.emit('gsm-disconnect') 308 elif self._current_state == _GSM_STATE_NEED_AUTH:309 self.emit('gsm-disconnect')310 369 else: 311 370 raise ValueError('Invalid GSM state while emitting signal, %s' % \ 312 371 str(self._current_state)) 313 372 314 373 315 374 class WirelessDeviceView(ToolButton): 316 375 … … class GsmDeviceView(TrayIcon): 747 806 signal_name='PppStats', 748 807 path=self._device.object_path, 749 808 dbus_interface=_NM_SERIAL_IFACE) 809 750 810 def create_palette(self): 751 811 palette = GsmPalette() 752 812 … … class GsmDeviceView(TrayIcon): 775 835 reply_handler=self.__connect_cb, 776 836 error_handler=self.__connect_error_cb) 777 837 else: 778 raise RuntimeError('There is no gsm connection available') 838 self._palette.add_alert(_('Error'), \ 839 _('There is no gsm connection available')) 779 840 780 841 def __connect_cb(self, active_connection): 781 842 logging.debug('Connected successfully to gsm device, %s', … … class GsmDeviceView(TrayIcon): 809 870 810 871 def __state_changed_cb(self, new_state, old_state, reason): 811 872 logging.debug('State: %s to %s, reason %s', old_state, new_state, reason) 812 self._update_state(int(new_state) )873 self._update_state(int(new_state), int(old_state), int(reason)) 813 874 814 875 def __current_state_check_cb(self, properties): 815 self._update_state(int(properties['State']) )876 self._update_state(int(properties['State']), 0, 0) 816 877 817 878 def __current_state_check_error_cb(self, error): 818 879 raise RuntimeError('Error when checking gsm device state, %s' % error) 819 880 820 def _update_state(self, state ):881 def _update_state(self, state, old_state, reason): 821 882 gsm_state = None 822 883 823 884 if state is network.DEVICE_STATE_ACTIVATED: … … class GsmDeviceView(TrayIcon): 829 890 connection.get_settings().connection.timestamp 830 891 self._connection_time_handler = gobject.timeout_add_seconds( \ 831 892 1, self.__connection_timecount_cb) 832 self._update_stats(0, 0) 833 self._update_connection_time() 834 self._palette.info_box.show() 893 self._palette.update_connection_time() 894 self._palette.update_stats(0, 0) 895 if self._palette is not None: 896 self._palette.conn_info_box.show() 835 897 836 898 elif state is network.DEVICE_STATE_DISCONNECTED: 837 899 gsm_state = _GSM_STATE_DISCONNECTED 838 900 self._connection_timestamp = 0 839 901 if self._connection_time_handler is not None: 840 902 gobject.source_remove(self._connection_time_handler) 841 self._palette.info_box.hide() 903 if self._palette is not None: 904 self._palette.conn_info_box.hide() 842 905 843 906 elif state in [network.DEVICE_STATE_UNMANAGED, 844 907 network.DEVICE_STATE_UNAVAILABLE, … … class GsmDeviceView(TrayIcon): 847 910 848 911 elif state in [network.DEVICE_STATE_PREPARE, 849 912 network.DEVICE_STATE_CONFIG, 850 network.DEVICE_STATE_IP_CONFIG]: 913 network.DEVICE_STATE_IP_CONFIG, 914 network.DEVICE_STATE_NEED_AUTH]: 851 915 gsm_state = _GSM_STATE_CONNECTING 852 853 elif state in [network.DEVICE_STATE_NEED_AUTH]:854 gsm_state = _GSM_STATE_ NEED_AUTH916 917 elif state == network.DEVICE_STATE_FAILED: 918 gsm_state = _GSM_STATE_FAILED 855 919 856 920 if self._palette is not None: 857 self._palette.set_state(gsm_state )921 self._palette.set_state(gsm_state, reason) 858 922 859 923 def disconnect(self): 860 924 self._bus.remove_signal_receiver(self.__state_changed_cb, … … class GsmDeviceView(TrayIcon): 863 927 dbus_interface=_NM_DEVICE_IFACE) 864 928 865 929 def __ppp_stats_changed_cb(self, in_bytes, out_bytes): 866 self._ update_stats(in_bytes, out_bytes)930 self._palette.update_stats(in_bytes, out_bytes) 867 931 868 def _update_stats(self, in_bytes, out_bytes):869 in_KBytes = in_bytes / 1024870 out_KBytes = out_bytes / 1024871 text = _("Data sent %d KB / received %d KB") % (out_KBytes, in_KBytes)872 self._palette.data_label.set_text(text)873 932 874 933 def __connection_timecount_cb(self): 875 934 self._connection_timestamp = self._connection_timestamp + 1 876 self._update_connection_time() 935 connection_time = \ 936 datetime.datetime.fromtimestamp(self._connection_timestamp) 937 self._palette.update_connection_time(connection_time) 877 938 return True 878 939 879 def _update_connection_time(self):880 connection_time = datetime.datetime.fromtimestamp( \881 self._connection_timestamp)882 text = _("Connection time ") + connection_time.strftime('%H : %M : %S')883 self._palette.connection_time_label.set_text(text)884 940 941 885 942 class WirelessDeviceObserver(object): 886 943 def __init__(self, device, tray, device_type): 887 944 self._device = device … … class WiredDeviceObserver(object): 952 1009 del self._device_view 953 1010 self._device_view = None 954 1011 1012 955 1013 class GsmDeviceObserver(object): 956 1014 def __init__(self, device, tray): 957 1015 self._device = device -
src/jarabe/model/network.py
diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py index 03d48c4..9a32897 100644
a b 18 18 # along with this program; if not, write to the Free Software 19 19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 20 21 from gettext import gettext as _ 21 22 import logging 22 23 import os 23 24 import time … … NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0 54 55 NM_ACTIVE_CONNECTION_STATE_ACTIVATING = 1 55 56 NM_ACTIVE_CONNECTION_STATE_ACTIVATED = 2 56 57 58 NM_DEVICE_STATE_REASON_UNKNOWN = 0 59 NM_DEVICE_STATE_REASON_NONE = 1 60 NM_DEVICE_STATE_REASON_NOW_MANAGED = 2 61 NM_DEVICE_STATE_REASON_NOW_UNMANAGED = 3 62 NM_DEVICE_STATE_REASON_CONFIG_FAILED = 4 63 NM_DEVICE_STATE_REASON_CONFIG_UNAVAILABLE = 5 64 NM_DEVICE_STATE_REASON_CONFIG_EXPIRED = 6 65 NM_DEVICE_STATE_REASON_NO_SECRETS = 7 66 NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT = 8 67 NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED = 9 68 NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED = 10 69 NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT = 11 70 NM_DEVICE_STATE_REASON_PPP_START_FAILED = 12 71 NM_DEVICE_STATE_REASON_PPP_DISCONNECT = 13 72 NM_DEVICE_STATE_REASON_PPP_FAILED = 14 73 NM_DEVICE_STATE_REASON_DHCP_START_FAILED = 15 74 NM_DEVICE_STATE_REASON_DHCP_ERROR = 16 75 NM_DEVICE_STATE_REASON_DHCP_FAILED = 17 76 NM_DEVICE_STATE_REASON_SHARED_START_FAILED = 18 77 NM_DEVICE_STATE_REASON_SHARED_FAILED = 19 78 NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED = 20 79 NM_DEVICE_STATE_REASON_AUTOIP_ERROR = 21 80 NM_DEVICE_STATE_REASON_AUTOIP_FAILED = 22 81 NM_DEVICE_STATE_REASON_MODEM_BUSY = 23 82 NM_DEVICE_STATE_REASON_MODEM_NO_DIAL_TONE = 24 83 NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER = 25 84 NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT = 26 85 NM_DEVICE_STATE_REASON_MODEM_DIAL_FAILED = 27 86 NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED = 28 87 NM_DEVICE_STATE_REASON_GSM_APN_FAILED = 29 88 NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING = 30 89 NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED = 31 90 NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT = 32 91 NM_DEVICE_STATE_REASON_GSM_REGISTRATION_FAILED = 33 92 NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED = 34 93 NM_DEVICE_STATE_REASON_FIRMWARE_MISSING = 35 94 NM_DEVICE_STATE_REASON_REMOVED = 36 95 NM_DEVICE_STATE_REASON_SLEEPING = 37 96 NM_DEVICE_STATE_REASON_CONNECTION_REMOVED = 38 97 NM_DEVICE_STATE_REASON_USER_REQUESTED = 39 98 NM_DEVICE_STATE_REASON_CARRIER = 40 99 57 100 NM_802_11_AP_FLAGS_NONE = 0x00000000 58 101 NM_802_11_AP_FLAGS_PRIVACY = 0x00000001 59 102 … … class NMSettingsConnection(dbus.service.Object): 444 487 def GetSecrets(self, setting_name, hints, request_new, reply, error): 445 488 logging.debug('Secrets requested for connection %s request_new=%s', 446 489 self.path, request_new) 447 if request_new or self._secrets is None: 448 # request_new is for example the case when the pw on the AP changes 449 response = SecretsResponse(self, reply, error) 450 try: 451 self.secrets_request.send(self, response=response) 452 except Exception: 453 logging.exception('Error requesting the secrets via dialog') 454 else: 455 reply(self._secrets.get_dict()) 456 457 490 if self._settings.connection.type is not 'gsm': 491 if request_new or self._secrets is None: 492 # request_new is for example the case when the pw on the AP changes 493 response = SecretsResponse(self, reply, error) 494 try: 495 self.secrets_request.send(self, response=response) 496 except Exception: 497 logging.exception('Error requesting the secrets via dialog') 498 else: 499 reply(self._secrets.get_dict()) 500 else: 501 if not request_new: 502 reply(self._secrets.get_dict()) 503 else: 504 raise Exception('The stored GSM secret has already been supplied ') 505 458 506 class AccessPoint(gobject.GObject): 459 507 __gsignals__ = { 460 508 'props-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,