Ticket #1759: Showing Errors-Palette Mockup-V2.patch
File Showing Errors-Palette Mockup-V2.patch, 16.6 KB (added by Dcastelo, 14 years ago) |
---|
-
extensions/deviceicon/network.py
From a31aeefde5a0317335642f977d092e40a457dd29 Mon Sep 17 00:00:00 2001 From: latu <latu@localhost.localdomain> Date: Tue, 2 Mar 2010 16:30:20 -0200 Subject: [PATCH] Showing Errors- Apply Mockup --- extensions/deviceicon/network.py | 184 ++++++++++++++++++++++++++------------ src/jarabe/model/network.py | 34 +++++--- 2 files changed, 148 insertions(+), 70 deletions(-) diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py index 94a4293..c278a4c 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 42 44 43 45 from jarabe.model import network 44 46 from jarabe.model.network import Settings … … _GSM_STATE_NOT_READY = 0 63 65 _GSM_STATE_DISCONNECTED = 1 64 66 _GSM_STATE_CONNECTING = 2 65 67 _GSM_STATE_CONNECTED = 3 66 _GSM_STATE_ NEED_AUTH= 468 _GSM_STATE_FAILED = 4 67 69 68 70 def frequency_to_channel(frequency): 69 71 ftoc = { 2412: 1, 2417: 2, 2422: 3, 2427: 4, … … class WiredPalette(Palette): 214 216 ip_address_text = "" 215 217 self._ip_address_label.set_text(ip_address_text) 216 218 219 217 220 class GsmPalette(Palette): 218 221 __gtype_name__ = 'SugarGsmPalette' 219 222 … … class GsmPalette(Palette): 227 230 def __init__(self): 228 231 229 232 Palette.__init__(self, label=_('Wireless modem')) 230 231 233 self._current_state = None 234 self._alert = False 232 235 233 self._toggle_state_item = gtk.MenuItem('')236 self._toggle_state_item = MenuItem('') 234 237 self._toggle_state_item.connect('activate', self.__toggle_state_cb) 235 238 self.menu.append(self._toggle_state_item) 236 239 self._toggle_state_item.show() 237 240 238 self.set_state(_GSM_STATE_NOT_READY)239 240 241 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() 242 self.connection_info_box = gtk.HBox() 243 244 icon = Icon(icon_name='go-up', icon_size=gtk.ICON_SIZE_MENU) 245 self.connection_info_box.pack_start(icon) 246 icon.show() 247 self._data_label_up = gtk.Label() 248 self._data_label_up.props.xalign = 0.0 249 label_alignment = self._add_widget_with_padding(self._data_label_up) 250 self.connection_info_box.pack_start(label_alignment) 251 self._data_label_up.show() 247 252 label_alignment.show() 248 253 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() 254 icon = Icon(icon_name='go-down', icon_size=gtk.ICON_SIZE_MENU) 255 self.connection_info_box.pack_start(icon) 256 icon.show() 257 self._data_label_down = gtk.Label() 258 self._data_label_down.props.xalign = 0.0 259 label_alignment = self._add_widget_with_padding(self._data_label_down) 260 self.connection_info_box.pack_start(label_alignment) 261 self._data_label_down.show() 255 262 label_alignment.show() 256 263 264 self.connection_info_box.show() 265 self.info_box.pack_start(self.connection_info_box) 266 267 self._error_accept_item = MenuItem('') 268 self._error_accept_item.connect('activate', self.__error_accept_cb) 269 self.menu.append(self._error_accept_item) 270 257 271 self.info_box.show() 258 272 self.set_content(self.info_box) 259 273 274 self.set_state(_GSM_STATE_NOT_READY) 275 260 276 def _add_widget_with_padding(self, child, xalign=0, yalign=0.5): 261 277 alignment = gtk.Alignment(xalign=xalign, yalign=yalign, 262 278 xscale=1, yscale=0.33) … … class GsmPalette(Palette): 267 283 alignment.add(child) 268 284 return alignment 269 285 270 def set_state(self, state ):286 def set_state(self, state, reason=0): 271 287 self._current_state = state 272 self._update_label_and_text( )288 self._update_label_and_text(reason) 273 289 274 def _update_label_and_text(self): 290 def _update_label_and_text(self, reason=0): 291 275 292 if self._current_state == _GSM_STATE_NOT_READY: 276 293 self._toggle_state_item.get_child().set_label('...') 277 294 self.props.secondary_text = _('Please wait...') 278 295 279 296 elif self._current_state == _GSM_STATE_DISCONNECTED: 280 297 self._toggle_state_item.get_child().set_label(_('Connect')) 281 self.props.secondary_text = _('Disconnected') 282 298 if not self._alert: 299 self.props.secondary_text = _('Disconnected') 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(_('Connection Error'), \ 320 self._get_error_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._alert = True 328 self.props.secondary_text = title 329 self._error_accept_item.get_child().set_label(message) 330 self._error_accept_item.show() 331 self._toggle_state_item.set_sensitive(False) 332 333 def __error_accept_cb(self, alert): 334 self._alert = False 335 self._update_label_and_text() 336 self._error_accept_item.get_child().set_label('') 337 self._error_accept_item.hide() 338 self._toggle_state_item.set_sensitive(True) 339 340 def update_connection_time(self, connection_time=None): 341 if (connection_time is not None): 342 self.props.secondary_text = _('Connected for ' + \ 343 connection_time.strftime('%H:%M:%S')) 344 else: 345 self.props.secondary_text = _('Connected for ' \ 346 + '00:00:00') 347 348 def update_stats(self, in_bytes, out_bytes): 349 in_KBytes = in_bytes / 1024 350 out_KBytes = out_bytes / 1024 351 self._data_label_up.set_text(_("%d KB") % (out_KBytes)) 352 self._data_label_down.set_text(_("%d KB") % (in_KBytes)) 353 354 def _get_error_by_nm_reason(self, reason): 355 if reason in [network.NM_DEVICE_STATE_REASON_NO_SECRETS, network.NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED]: 356 message = _('The Pin/Puk configuration is not valid.') 357 elif reason in [network.NM_DEVICE_STATE_REASON_PPP_DISCONNECT, network.NM_DEVICE_STATE_REASON_PPP_FAILED]: 358 message = _('Check the APN configuration.') 359 elif reason in [network.NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER]: 360 message = _('Check the tel number configuration.') 361 elif reason in [network.NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT]: 362 message = _('Time out. Check the tel configuration') 363 else: 364 message = _('Unexpected error.') 365 return message 366 299 367 def __toggle_state_cb(self, menuitem): 300 368 if self._current_state == _GSM_STATE_NOT_READY: 301 369 pass … … class GsmPalette(Palette): 305 373 self.emit('gsm-disconnect') 306 374 elif self._current_state == _GSM_STATE_CONNECTED: 307 375 self.emit('gsm-disconnect') 308 elif self._current_state == _GSM_STATE_NEED_AUTH:309 self.emit('gsm-disconnect')310 376 else: 311 377 raise ValueError('Invalid GSM state while emitting signal, %s' % \ 312 378 str(self._current_state)) 313 379 314 380 315 381 class WirelessDeviceView(ToolButton): 316 382 … … class GsmDeviceView(TrayIcon): 747 813 signal_name='PppStats', 748 814 path=self._device.object_path, 749 815 dbus_interface=_NM_SERIAL_IFACE) 816 750 817 def create_palette(self): 751 818 palette = GsmPalette() 752 819 … … class GsmDeviceView(TrayIcon): 774 841 '/', 775 842 reply_handler=self.__connect_cb, 776 843 error_handler=self.__connect_error_cb) 844 else: 845 self._palette.add_alert(_('Connection Error'), \ 846 _('There is no gsm connection available')) 777 847 778 848 def __connect_cb(self, active_connection): 779 849 logging.debug('Connected successfully to gsm device, %s', … … class GsmDeviceView(TrayIcon): 807 877 808 878 def __state_changed_cb(self, new_state, old_state, reason): 809 879 logging.debug('State: %s to %s, reason %s', old_state, new_state, reason) 810 self._update_state(int(new_state) )880 self._update_state(int(new_state), int(old_state), int(reason)) 811 881 812 882 def __current_state_check_cb(self, properties): 813 self._update_state(int(properties['State']) )883 self._update_state(int(properties['State']), 0, 0) 814 884 815 885 def __current_state_check_error_cb(self, error): 816 886 raise RuntimeError('Error when checking gsm device state, %s' % error) 817 887 818 def _update_state(self, state ):888 def _update_state(self, state, old_state, reason): 819 889 gsm_state = None 820 890 821 891 if state is network.DEVICE_STATE_ACTIVATED: … … class GsmDeviceView(TrayIcon): 823 893 connection = network.find_gsm_connection() 824 894 if connection is not None: 825 895 connection.set_connected() 826 self._connection_timestamp = 896 self._connection_timestamp = time.time() - \ 827 897 connection.get_settings().connection.timestamp 828 898 self._connection_time_handler = gobject.timeout_add_seconds( \ 829 899 1, self.__connection_timecount_cb) 830 self._update_stats(0, 0) 831 self._update_connection_time() 832 self._palette.info_box.show() 900 self._palette.update_connection_time() 901 self._palette.update_stats(0, 0) 902 if self._palette is not None: 903 self._palette.connection_info_box.show() 833 904 834 905 elif state is network.DEVICE_STATE_DISCONNECTED: 835 906 gsm_state = _GSM_STATE_DISCONNECTED 836 907 self._connection_timestamp = 0 837 908 if self._connection_time_handler is not None: 838 909 gobject.source_remove(self._connection_time_handler) 839 self._palette.info_box.hide() 910 if self._palette is not None: 911 self._palette.connection_info_box.hide() 840 912 841 913 elif state in [network.DEVICE_STATE_UNMANAGED, 842 914 network.DEVICE_STATE_UNAVAILABLE, … … class GsmDeviceView(TrayIcon): 845 917 846 918 elif state in [network.DEVICE_STATE_PREPARE, 847 919 network.DEVICE_STATE_CONFIG, 848 network.DEVICE_STATE_IP_CONFIG]: 920 network.DEVICE_STATE_IP_CONFIG, 921 network.DEVICE_STATE_NEED_AUTH]: 849 922 gsm_state = _GSM_STATE_CONNECTING 850 851 elif state in [network.DEVICE_STATE_NEED_AUTH]:852 gsm_state = _GSM_STATE_ NEED_AUTH923 924 elif state == network.DEVICE_STATE_FAILED: 925 gsm_state = _GSM_STATE_FAILED 853 926 854 927 if self._palette is not None: 855 self._palette.set_state(gsm_state )928 self._palette.set_state(gsm_state, reason) 856 929 857 930 def disconnect(self): 858 931 self._bus.remove_signal_receiver(self.__state_changed_cb, … … class GsmDeviceView(TrayIcon): 861 934 dbus_interface=_NM_DEVICE_IFACE) 862 935 863 936 def __ppp_stats_changed_cb(self, in_bytes, out_bytes): 864 self._update_stats(in_bytes, out_bytes) 865 866 def _update_stats(self, in_bytes, out_bytes): 867 in_KBytes = in_bytes / 1024 868 out_KBytes = out_bytes / 1024 869 text = _("Data sent %d KB / received %d KB") % (out_KBytes, in_KBytes) 870 self._palette.data_label.set_text(text) 937 self._palette.update_stats(in_bytes, out_bytes) 871 938 872 939 def __connection_timecount_cb(self): 873 940 self._connection_timestamp = self._connection_timestamp + 1 874 self._update_connection_time() 941 connection_time = \ 942 datetime.datetime.fromtimestamp(self._connection_timestamp) 943 self._palette.update_connection_time(connection_time) 875 944 return True 876 945 877 def _update_connection_time(self):878 connection_time = datetime.datetime.fromtimestamp( \879 self._connection_timestamp)880 text = _("Connection time ") + connection_time.strftime('%H : %M : %S')881 self._palette.connection_time_label.set_text(text)882 946 947 883 948 class WirelessDeviceObserver(object): 884 949 def __init__(self, device, tray, device_type): 885 950 self._device = device … … class WiredDeviceObserver(object): 950 1015 del self._device_view 951 1016 self._device_view = None 952 1017 1018 953 1019 class GsmDeviceObserver(object): 954 1020 def __init__(self, device, tray): 955 1021 self._device = device -
src/jarabe/model/network.py
diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py index 3a949da..579ed8d 100644
a b NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0 54 54 NM_ACTIVE_CONNECTION_STATE_ACTIVATING = 1 55 55 NM_ACTIVE_CONNECTION_STATE_ACTIVATED = 2 56 56 57 NM_DEVICE_STATE_REASON_NO_SECRETS = 7 58 NM_DEVICE_STATE_REASON_PPP_DISCONNECT = 13 59 NM_DEVICE_STATE_REASON_PPP_FAILED = 14 60 NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER = 25 61 NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT = 26 62 NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED = 34 63 57 64 NM_802_11_AP_FLAGS_NONE = 0x00000000 58 65 NM_802_11_AP_FLAGS_PRIVACY = 0x00000001 59 66 … … class NMSettingsConnection(dbus.service.Object): 444 451 def GetSecrets(self, setting_name, hints, request_new, reply, error): 445 452 logging.debug('Secrets requested for connection %s request_new=%s', 446 453 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 454 if self._settings.connection.type is not 'gsm': 455 if request_new or self._secrets is None: 456 # request_new is for example the case when the pw on the AP changes 457 response = SecretsResponse(self, reply, error) 458 try: 459 self.secrets_request.send(self, response=response) 460 except Exception: 461 logging.exception('Error requesting the secrets via dialog') 462 else: 463 reply(self._secrets.get_dict()) 464 else: 465 if not request_new: 466 reply(self._secrets.get_dict()) 467 else: 468 raise Exception('The stored GSM secret has already been supplied ') 469 458 470 class AccessPoint(gobject.GObject): 459 471 __gsignals__ = { 460 472 'props-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,