diff options
author | Sayamindu Dasgupta <sayamindu@gmail.com> | 2010-05-10 13:49:41 (GMT) |
---|---|---|
committer | Sayamindu Dasgupta <sayamindu@gmail.com> | 2010-05-10 13:49:41 (GMT) |
commit | 9120396410113ab7993d94f930c9212b52456b46 (patch) | |
tree | 38c8ffe33af487ba851287ecdcdd88c17e0d6c4c | |
parent | 407fe9d56e438c9f9fe5a7b1472929a7ae9f3289 (diff) |
Add Connection Information to 3G Support (Daniel Castelo, Plan Ceibal)
-rw-r--r-- | extensions/deviceicon/network.py | 84 | ||||
-rw-r--r-- | src/jarabe/model/network.py | 10 |
2 files changed, 85 insertions, 9 deletions
diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py index 0ff044c..5663305 100644 --- a/extensions/deviceicon/network.py +++ b/extensions/deviceicon/network.py @@ -23,7 +23,8 @@ import sha import socket import struct import re - +import datetime +import time import gtk import gobject import gconf @@ -51,6 +52,7 @@ _NM_PATH = '/org/freedesktop/NetworkManager' _NM_DEVICE_IFACE = 'org.freedesktop.NetworkManager.Device' _NM_WIRED_IFACE = 'org.freedesktop.NetworkManager.Device.Wired' _NM_WIRELESS_IFACE = 'org.freedesktop.NetworkManager.Device.Wireless' +_NM_SERIAL_IFACE = 'org.freedesktop.NetworkManager.Device.Serial' _NM_ACCESSPOINT_IFACE = 'org.freedesktop.NetworkManager.AccessPoint' _NM_ACTIVE_CONN_IFACE = 'org.freedesktop.NetworkManager.Connection.Active' @@ -209,6 +211,7 @@ class GsmPalette(Palette): } def __init__(self): + Palette.__init__(self, label=_('Wireless modem')) self._current_state = None @@ -220,6 +223,36 @@ class GsmPalette(Palette): self.set_state(_GSM_STATE_NOT_READY) + self.info_box = gtk.VBox() + + self.data_label = gtk.Label() + self.data_label.props.xalign = 0.0 + label_alignment = self._add_widget_with_padding(self.data_label) + self.info_box.pack_start(label_alignment) + self.data_label.show() + label_alignment.show() + + self.connection_time_label = gtk.Label() + self.connection_time_label.props.xalign = 0.0 + label_alignment = self._add_widget_with_padding( \ + self.connection_time_label) + self.info_box.pack_start(label_alignment) + self.connection_time_label.show() + label_alignment.show() + + self.info_box.show() + self.set_content(self.info_box) + + def _add_widget_with_padding(self, child, xalign=0, yalign=0.5): + alignment = gtk.Alignment(xalign=xalign, yalign=yalign, + xscale=1, yscale=0.33) + alignment.set_padding(style.DEFAULT_SPACING, + style.DEFAULT_SPACING, + style.DEFAULT_SPACING, + style.DEFAULT_SPACING) + alignment.add(child) + return alignment + def set_state(self, state): self._current_state = state self._update_label_and_text() @@ -498,7 +531,8 @@ class WirelessDeviceView(ToolButton): # truncate the nick and use a regex to drop any partial characters # at the end nick = nick.encode('utf-8')[:name_limit] - nick = re.sub("([\xf6-\xf7][\x80-\xbf]{0,2}|[\xe0-\xef][\x80-\xbf]{0,1}|[\xc0-\xdf])$", '', nick) + pattern = "([\xf6-\xf7][\x80-\xbf]{0,2}|[\xe0-\xef][\x80-\xbf]{0,1}|[\xc0-\xdf])$" + nick = re.sub(pattern, '', nick) connection_name = format % nick connection_name += color_suffix @@ -557,6 +591,9 @@ class GsmDeviceView(TrayIcon): FRAME_POSITION_RELATIVE = 303 def __init__(self, device): + self._connection_time_handler = None + self._connection_timestamp = 0 + client = gconf.client_get_default() color = xocolor.XoColor(client.get_string('/desktop/sugar/user/color')) @@ -571,7 +608,10 @@ class GsmDeviceView(TrayIcon): signal_name='StateChanged', path=self._device.object_path, dbus_interface=_NM_DEVICE_IFACE) - + self._bus.add_signal_receiver(self.__ppp_stats_changed_cb, + signal_name='PppStats', + path=self._device.object_path, + dbus_interface=_NM_SERIAL_IFACE) def create_palette(self): palette = GsmPalette() @@ -645,9 +685,23 @@ class GsmDeviceView(TrayIcon): if state is network.DEVICE_STATE_ACTIVATED: gsm_state = _GSM_STATE_CONNECTED - - elif state is network.DEVICE_STATE_DISCONNECTED: + connection = network.find_gsm_connection() + if connection is not None: + connection.set_connected() + self._connection_timestamp = time.time() - \ + connection.get_settings().connection.timestamp + self._connection_time_handler = gobject.timeout_add( \ + 1000, self.__connection_timecount_cb) + self._update_stats(0, 0) + self._update_connection_time() + self._palette.info_box.show() + + if state is network.DEVICE_STATE_DISCONNECTED: gsm_state = _GSM_STATE_DISCONNECTED + self._connection_timestamp = 0 + if self._connection_time_handler is not None: + gobject.source_remove(self._connection_time_handler) + self._palette.info_box.hide() elif state in [network.DEVICE_STATE_UNMANAGED, network.DEVICE_STATE_UNAVAILABLE, @@ -671,6 +725,26 @@ class GsmDeviceView(TrayIcon): path=self._device.object_path, dbus_interface=_NM_DEVICE_IFACE) + def __ppp_stats_changed_cb(self, in_bytes, out_bytes): + self._update_stats(in_bytes, out_bytes) + + def _update_stats(self, in_bytes, out_bytes): + in_kbytes = in_bytes / 1024 + out_kbytes = out_bytes / 1024 + text = _("Data sent %d kb / received %d kb") % (out_kbytes, in_kbytes) + self._palette.data_label.set_text(text) + + def __connection_timecount_cb(self): + self._connection_timestamp = self._connection_timestamp + 1 + self._update_connectiontime() + return True + + def _update_connection_time(self): + connection_time = datetime.datetime.fromtimestamp( \ + self._connection_timestamp) + text = _("Connection time ") + connection_time.strftime('%H : %M : %S') + self._palette.connection_time_label.set_text(text) + class WirelessDeviceObserver(object): def __init__(self, device, tray): self._device = device diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py index dcd23a1..9de954a 100644 --- a/src/jarabe/model/network.py +++ b/src/jarabe/model/network.py @@ -177,8 +177,8 @@ class Ppp(object): pass def get_dict(self): - ppp = {} - return ppp + ppp = {} + return ppp class Gsm(object): def __init__(self): @@ -347,9 +347,11 @@ class NMSettingsConnection(dbus.service.Object): pass def set_connected(self): - if not self._settings.connection.autoconnect: - self._settings.connection.autoconnect = True + if self._settings.connection.type == NM_CONNECTION_TYPE_GSM: + self._settings.connection.timestamp = int(time.time()) + elif not self._settings.connection.autoconnect: self._settings.connection.timestamp = int(time.time()) + self._settings.connection.autoconnect = True self.Updated(self._settings.get_dict()) self.save() |