Ticket #1652: 0002-Patch-Connection-InfoV2.patch

File 0002-Patch-Connection-InfoV2.patch, 6.3 KB (added by Dcastelo, 14 years ago)

3G Support-Connection-Info.patch V2

  • extensions/deviceicon/network.py

    From 956b06db5efb5a6d03fdec178fbf8a885bd71a6c Mon Sep 17 00:00:00 2001
    From: latu <latu@localhost.localdomain>
    Date: Tue, 2 Feb 2010 16:17:43 -0200
    Subject: [PATCH 2/2] Add Connection Information to 3G (GSM) Modem Support- V2
    
    ---
     extensions/deviceicon/network.py |   86 ++++++++++++++++++++++----------------
     1 files changed, 50 insertions(+), 36 deletions(-)
    
    diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
    index 8e8eb64..04b38fd 100644
    a b import hashlib 
    2323import socket
    2424import struct
    2525import re
    26 import datetime, time
     26import datetime
     27import time
    2728import gtk
    2829import gobject
    2930import gconf
    class GsmPalette(Palette): 
    221222                                 gobject.TYPE_NONE, ([])),
    222223    }
    223224
    224     def __init__(self):
    225 
    226         def _padded(child, xalign=0, yalign=0.5):
    227             padder = gtk.Alignment(xalign=xalign, yalign=yalign,
     225    def _add_widget_with_padding(self, child, xalign=0, yalign=0.5):
     226            alignment = gtk.Alignment(xalign=xalign, yalign=yalign,
    228227                                   xscale=1, yscale=0.33)
    229             padder.set_padding(style.DEFAULT_SPACING,
     228            alignment.set_padding(style.DEFAULT_SPACING,
    230229                               style.DEFAULT_SPACING,
    231230                               style.DEFAULT_SPACING,
    232231                               style.DEFAULT_SPACING)
    233             padder.add(child)
    234             return padder
     232            alignment.add(child)
     233            return alignment
     234
     235    def __init__(self):
    235236
    236237        Palette.__init__(self, label=_('Wireless modem'))
    237238
    class GsmPalette(Palette): 
    244245
    245246        self.set_state(_GSM_STATE_NOT_READY)
    246247
    247         self._info = gtk.VBox()
     248        self.info_box = gtk.VBox()
     249
    248250        self._data_label = gtk.Label()
    249251        self._data_label.props.xalign = 0.0
    250         self._info.pack_start(_padded(self._data_label))
    251        
     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
    252257        self._conn_time_label = gtk.Label()
    253258        self._conn_time_label.props.xalign = 0.0
    254         self._info.pack_start(_padded(self._conn_time_label))
     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()
    255263
    256         self._info.show_all()
    257         self.set_content(self._info)
     264        self.info_box.show()
     265        self.set_content(self.info_box)
    258266
    259267    def set_state(self, state):
    260268        self._current_state = state
    class GsmDeviceView(TrayIcon): 
    707715    FRAME_POSITION_RELATIVE = 303
    708716
    709717    def __init__(self, device):
    710         self.__connection_time_handler = None
    711         self.__connection_timestamp = None
     718        self._connection_time_handler = None
     719        self._connection_timestamp = 0
    712720
    713721        client = gconf.client_get_default()
    714722        color = xocolor.XoColor(client.get_string('/desktop/sugar/user/color'))
    class GsmDeviceView(TrayIcon): 
    801809        if state is network.DEVICE_STATE_ACTIVATED:
    802810            gsm_state = _GSM_STATE_CONNECTED
    803811            connection = network.find_gsm_connection()
    804             if (connection <> None):
     812            if connection is not None:
    805813                connection.set_connected()
    806                 self.__connection_timestamp =  time.time() - connection.get_settings().connection.timestamp
    807                 self.__connection_time_handler = gobject.timeout_add(1000, self.connection_timecount_cb)
    808                 self.__ppp_stats_changed_cb(0, 0)
    809                 self.connection_timecount_cb()               
    810                 self._palette._info.show_all()
    811         else:
    812             self.__connection_timestamp = 0
    813             if (self.__connection_time_handler <> None):
    814                 gobject.source_remove(self.__connection_time_handler)
    815             self._palette._info.hide_all()
     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
    816820        if state is network.DEVICE_STATE_DISCONNECTED:
    817821            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()
    818826
    819827        elif state in [network.DEVICE_STATE_UNMANAGED,
    820828                       network.DEVICE_STATE_UNAVAILABLE,
    class GsmDeviceView(TrayIcon): 
    836844                                         dbus_interface=_NM_DEVICE_IFACE)
    837845       
    838846    def __ppp_stats_changed_cb(self, in_bytes, out_bytes):
    839         in_bytes = in_bytes / 1024
    840         out_bytes = out_bytes / 1024
    841         self._palette ._data_label.set_text("Data sent {0} kb / received {1} kb".format(out_bytes ,in_bytes))
    842 
    843     def connection_timecount_cb(self):
    844         self.__connection_timestamp = self.__connection_timestamp + 1
    845         connection_time = datetime.datetime.fromtimestamp(self.__connection_timestamp)
    846         self._palette._conn_time_label.set_text("Connection time " + connection_time.strftime('%H : %M : %S'))
    847         return True
     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'))
    848862   
    849863class WirelessDeviceObserver(object):
    850864    def __init__(self, device, tray, device_type):