From a0387e4e07862bcdf066eee43219834c4ab58cd3 Mon Sep 17 00:00:00 2001
From: latu <latu@localhost.localdomain>
Date: Tue, 9 Feb 2010 15:12:37 -0200
Subject: [PATCH] 3G Connection Info
---
extensions/deviceicon/network.py | 77 +++++++++++++++++++++++++++++++++++--
src/jarabe/model/network.py | 13 ++++--
2 files changed, 80 insertions(+), 10 deletions(-)
diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
index 2ca6a88..04b38fd 100644
a
|
b
|
import hashlib |
23 | 23 | import socket |
24 | 24 | import struct |
25 | 25 | import re |
26 | | |
| 26 | import datetime |
| 27 | import time |
27 | 28 | import gtk |
28 | 29 | import gobject |
29 | 30 | import gconf |
… |
… |
_NM_PATH = '/org/freedesktop/NetworkManager' |
52 | 53 | _NM_DEVICE_IFACE = 'org.freedesktop.NetworkManager.Device' |
53 | 54 | _NM_WIRED_IFACE = 'org.freedesktop.NetworkManager.Device.Wired' |
54 | 55 | _NM_WIRELESS_IFACE = 'org.freedesktop.NetworkManager.Device.Wireless' |
| 56 | _NM_SERIAL_IFACE = 'org.freedesktop.NetworkManager.Device.Serial' |
55 | 57 | _NM_OLPC_MESH_IFACE = 'org.freedesktop.NetworkManager.Device.OlpcMesh' |
56 | 58 | _NM_ACCESSPOINT_IFACE = 'org.freedesktop.NetworkManager.AccessPoint' |
57 | 59 | _NM_ACTIVE_CONN_IFACE = 'org.freedesktop.NetworkManager.Connection.Active' |
… |
… |
class GsmPalette(Palette): |
220 | 222 | gobject.TYPE_NONE, ([])), |
221 | 223 | } |
222 | 224 | |
| 225 | def _add_widget_with_padding(self, child, xalign=0, yalign=0.5): |
| 226 | alignment = gtk.Alignment(xalign=xalign, yalign=yalign, |
| 227 | xscale=1, yscale=0.33) |
| 228 | alignment.set_padding(style.DEFAULT_SPACING, |
| 229 | style.DEFAULT_SPACING, |
| 230 | style.DEFAULT_SPACING, |
| 231 | style.DEFAULT_SPACING) |
| 232 | alignment.add(child) |
| 233 | return alignment |
| 234 | |
223 | 235 | def __init__(self): |
| 236 | |
224 | 237 | Palette.__init__(self, label=_('Wireless modem')) |
225 | 238 | |
226 | 239 | self._current_state = None |
… |
… |
class GsmPalette(Palette): |
232 | 245 | |
233 | 246 | self.set_state(_GSM_STATE_NOT_READY) |
234 | 247 | |
| 248 | self.info_box = gtk.VBox() |
| 249 | |
| 250 | self._data_label = gtk.Label() |
| 251 | self._data_label.props.xalign = 0.0 |
| 252 | label_alignment = self._add_widget_with_padding(self._data_label) |
| 253 | self.info_box.pack_start(label_alignment) |
| 254 | self._data_label.show() |
| 255 | label_alignment.show() |
| 256 | |
| 257 | self._conn_time_label = gtk.Label() |
| 258 | self._conn_time_label.props.xalign = 0.0 |
| 259 | label_alignment = self._add_widget_with_padding(self._conn_time_label) |
| 260 | self.info_box.pack_start(label_alignment) |
| 261 | self._conn_time_label.show() |
| 262 | label_alignment.show() |
| 263 | |
| 264 | self.info_box.show() |
| 265 | self.set_content(self.info_box) |
| 266 | |
235 | 267 | def set_state(self, state): |
236 | 268 | self._current_state = state |
237 | 269 | self._update_label_and_text() |
… |
… |
class GsmDeviceView(TrayIcon): |
683 | 715 | FRAME_POSITION_RELATIVE = 303 |
684 | 716 | |
685 | 717 | def __init__(self, device): |
| 718 | self._connection_time_handler = None |
| 719 | self._connection_timestamp = 0 |
| 720 | |
686 | 721 | client = gconf.client_get_default() |
687 | 722 | color = xocolor.XoColor(client.get_string('/desktop/sugar/user/color')) |
688 | 723 | |
… |
… |
class GsmDeviceView(TrayIcon): |
697 | 732 | signal_name='StateChanged', |
698 | 733 | path=self._device.object_path, |
699 | 734 | dbus_interface=_NM_DEVICE_IFACE) |
700 | | |
| 735 | self._bus.add_signal_receiver(self.__ppp_stats_changed_cb, |
| 736 | signal_name='PppStats', |
| 737 | path=self._device.object_path, |
| 738 | dbus_interface=_NM_SERIAL_IFACE) |
701 | 739 | def create_palette(self): |
702 | 740 | palette = GsmPalette() |
703 | 741 | |
… |
… |
class GsmDeviceView(TrayIcon): |
770 | 808 | |
771 | 809 | if state is network.DEVICE_STATE_ACTIVATED: |
772 | 810 | gsm_state = _GSM_STATE_CONNECTED |
773 | | |
774 | | elif state is network.DEVICE_STATE_DISCONNECTED: |
| 811 | connection = network.find_gsm_connection() |
| 812 | if connection is not None: |
| 813 | connection.set_connected() |
| 814 | self._connection_timestamp = time.time() - connection.get_settings().connection.timestamp |
| 815 | self._connection_time_handler = gobject.timeout_add(1000, self.__connection_timecount_cb) |
| 816 | self._update_stats(0, 0) |
| 817 | self._update_connectiontime() |
| 818 | self._palette.info_box.show() |
| 819 | |
| 820 | if state is network.DEVICE_STATE_DISCONNECTED: |
775 | 821 | gsm_state = _GSM_STATE_DISCONNECTED |
| 822 | self._connection_timestamp = 0 |
| 823 | if self._connection_time_handler is not None: |
| 824 | gobject.source_remove(self._connection_time_handler) |
| 825 | self._palette.info_box.hide() |
776 | 826 | |
777 | 827 | elif state in [network.DEVICE_STATE_UNMANAGED, |
778 | 828 | network.DEVICE_STATE_UNAVAILABLE, |
… |
… |
class GsmDeviceView(TrayIcon): |
792 | 842 | signal_name='StateChanged', |
793 | 843 | path=self._device.object_path, |
794 | 844 | dbus_interface=_NM_DEVICE_IFACE) |
795 | | |
| 845 | |
| 846 | def __ppp_stats_changed_cb(self, in_bytes, out_bytes): |
| 847 | self._update_stats(in_bytes, out_bytes) |
| 848 | |
| 849 | def _update_stats(self, in_bytes, out_bytes): |
| 850 | in_kbytes = in_bytes / 1024 |
| 851 | out_kbytes = out_bytes / 1024 |
| 852 | self._palette._data_label.set_text(_("Data sent %d kb / received %d kb") % (out_kbytes ,in_kbytes)) |
| 853 | |
| 854 | def __connection_timecount_cb(self): |
| 855 | self._connection_timestamp = self._connection_timestamp + 1 |
| 856 | self._update_connectiontime() |
| 857 | return True |
| 858 | |
| 859 | def _update_connectiontime(self): |
| 860 | connection_time = datetime.datetime.fromtimestamp(self._connection_timestamp) |
| 861 | self._palette._conn_time_label.set_text(_("Connection time ") + connection_time.strftime('%H : %M : %S')) |
| 862 | |
796 | 863 | class WirelessDeviceObserver(object): |
797 | 864 | def __init__(self, device, tray, device_type): |
798 | 865 | self._device = device |
diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
index 696dc91..00db4e7 100644
a
|
b
|
class NMSettingsConnection(dbus.service.Object): |
350 | 350 | self._secrets = secrets |
351 | 351 | |
352 | 352 | def set_connected(self): |
353 | | if not self._settings.connection.autoconnect: |
354 | | self._settings.connection.autoconnect = True |
355 | | self._settings.connection.timestamp = int(time.time()) |
356 | | if self._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS: |
357 | | self.save() |
| 353 | if self._settings.connection.type == NM_CONNECTION_TYPE_GSM: |
| 354 | self._settings.connection.timestamp = int(time.time()) |
| 355 | else: |
| 356 | if not self._settings.connection.autoconnect: |
| 357 | self._settings.connection.autoconnect = True |
| 358 | self._settings.connection.timestamp = int(time.time()) |
| 359 | if self._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS: |
| 360 | self.save() |
358 | 361 | |
359 | 362 | def set_secrets(self, secrets): |
360 | 363 | self._secrets = secrets |