Ticket #1652: 0001-3G-Connection-Info.2.patch

File 0001-3G-Connection-Info.2.patch, 7.1 KB (added by Dcastelo, 14 years ago)

3G-Connection-Info.patch (mixed of previous patches)

  • extensions/deviceicon/network.py

    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 
    2323import socket
    2424import struct
    2525import re
    26 
     26import datetime
     27import time
    2728import gtk
    2829import gobject
    2930import gconf
    _NM_PATH = '/org/freedesktop/NetworkManager' 
    5253_NM_DEVICE_IFACE = 'org.freedesktop.NetworkManager.Device'
    5354_NM_WIRED_IFACE = 'org.freedesktop.NetworkManager.Device.Wired'
    5455_NM_WIRELESS_IFACE = 'org.freedesktop.NetworkManager.Device.Wireless'
     56_NM_SERIAL_IFACE = 'org.freedesktop.NetworkManager.Device.Serial'
    5557_NM_OLPC_MESH_IFACE = 'org.freedesktop.NetworkManager.Device.OlpcMesh'
    5658_NM_ACCESSPOINT_IFACE = 'org.freedesktop.NetworkManager.AccessPoint'
    5759_NM_ACTIVE_CONN_IFACE = 'org.freedesktop.NetworkManager.Connection.Active'
    class GsmPalette(Palette): 
    220222                                 gobject.TYPE_NONE, ([])),
    221223    }
    222224
     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
    223235    def __init__(self):
     236
    224237        Palette.__init__(self, label=_('Wireless modem'))
    225238
    226239        self._current_state = None
    class GsmPalette(Palette): 
    232245
    233246        self.set_state(_GSM_STATE_NOT_READY)
    234247
     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
    235267    def set_state(self, state):
    236268        self._current_state = state
    237269        self._update_label_and_text()
    class GsmDeviceView(TrayIcon): 
    683715    FRAME_POSITION_RELATIVE = 303
    684716
    685717    def __init__(self, device):
     718        self._connection_time_handler = None
     719        self._connection_timestamp = 0
     720
    686721        client = gconf.client_get_default()
    687722        color = xocolor.XoColor(client.get_string('/desktop/sugar/user/color'))
    688723
    class GsmDeviceView(TrayIcon): 
    697732                                      signal_name='StateChanged',
    698733                                      path=self._device.object_path,
    699734                                      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)
    701739    def create_palette(self):
    702740        palette = GsmPalette()
    703741
    class GsmDeviceView(TrayIcon): 
    770808
    771809        if state is network.DEVICE_STATE_ACTIVATED:
    772810            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:
    775821            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()
    776826
    777827        elif state in [network.DEVICE_STATE_UNMANAGED,
    778828                       network.DEVICE_STATE_UNAVAILABLE,
    class GsmDeviceView(TrayIcon): 
    792842                                         signal_name='StateChanged',
    793843                                         path=self._device.object_path,
    794844                                         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   
    796863class WirelessDeviceObserver(object):
    797864    def __init__(self, device, tray, device_type):
    798865        self._device = device
  • src/jarabe/model/network.py

    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): 
    350350        self._secrets = secrets
    351351
    352352    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()
    358361
    359362    def set_secrets(self, secrets):
    360363        self._secrets = secrets