Ticket #1652: 3G Support-Connection-Info.patch

File 3G Support-Connection-Info.patch, 6.6 KB (added by Dcastelo, 14 years ago)

3G Support-Connection-Info.patch V1

  • extensions/deviceicon/network.py

    From 486b45510571be462b5c45046b09f0a88d81b12b Mon Sep 17 00:00:00 2001
    From: root <root@localhost.localdomain>
    Date: Thu, 14 Jan 2010 15:41:59 -0200
    Subject: [PATCH 2/3] 3G Connection Info
    
    ---
     extensions/deviceicon/network.py |   62 ++++++++++++++++++++++++++++++++++---
     src/jarabe/model/network.py      |   13 +++++---
     2 files changed, 65 insertions(+), 10 deletions(-)
    
    diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
    index 18f0c4c..088fbd0 100644
    a b import hashlib 
    2323import socket
    2424import struct
    2525import re
    26 
     26import datetime, time
    2727import gtk
    2828import gobject
    2929import gconf
    _NM_PATH = '/org/freedesktop/NetworkManager' 
    5151_NM_DEVICE_IFACE = 'org.freedesktop.NetworkManager.Device'
    5252_NM_WIRED_IFACE = 'org.freedesktop.NetworkManager.Device.Wired'
    5353_NM_WIRELESS_IFACE = 'org.freedesktop.NetworkManager.Device.Wireless'
     54_NM_SERIAL_IFACE = 'org.freedesktop.NetworkManager.Device.Serial'
    5455_NM_ACCESSPOINT_IFACE = 'org.freedesktop.NetworkManager.AccessPoint'
    5556_NM_ACTIVE_CONN_IFACE = 'org.freedesktop.NetworkManager.Connection.Active'
    5657
    class GsmPalette(Palette): 
    221222    }
    222223
    223224    def __init__(self):
     225        def _padded(child, xalign=0, yalign=0.5):
     226            padder = gtk.Alignment(xalign=xalign, yalign=yalign,
     227                                   xscale=1, yscale=0.33)
     228            padder.set_padding(style.DEFAULT_SPACING,
     229                               style.DEFAULT_SPACING,
     230                               style.DEFAULT_SPACING,
     231                               style.DEFAULT_SPACING)
     232            padder.add(child)
     233            return padder
     234
    224235        Palette.__init__(self, label=_('GSM Device'))
    225236
    226237        self._current_state = None
    class GsmPalette(Palette): 
    228239        self._toggle_state_item = gtk.MenuItem('')
    229240        self.set_state(_GSM_STATE_NOT_READY)
    230241
     242        self._info = gtk.VBox()
     243        self._data_label = gtk.Label()
     244        self._data_label.props.xalign = 0.0
     245        self._info.pack_start(_padded(self._data_label))
     246       
     247        self._conn_time_label = gtk.Label()
     248        self._conn_time_label.props.xalign = 0.0
     249        self._info.pack_start(_padded(self._conn_time_label))
     250
     251        self._info.show_all()
     252        self.set_content(self._info)
     253
    231254        self._toggle_state_item.connect('activate', self._toggle_state_cb)
    232255        self.menu.append(self._toggle_state_item)
    233256        self._toggle_state_item.show()
    class GsmDeviceView(TrayIcon): 
    558581    FRAME_POSITION_RELATIVE = 303
    559582
    560583    def __init__(self, device):
     584        self.__connection_time_handler = None
     585        self.__connection_timestamp = None
     586
    561587        client = gconf.client_get_default()
    562588        color = xocolor.XoColor(client.get_string('/desktop/sugar/user/color'))
    563589
    class GsmDeviceView(TrayIcon): 
    572598                                      signal_name='StateChanged',
    573599                                      path=self._device.object_path,
    574600                                      dbus_interface=_NM_DEVICE_IFACE)
    575 
     601        self._bus.add_signal_receiver(self.__ppp_stats_changed_cb,
     602                                      signal_name='PppStats',
     603                                      path=self._device.object_path,
     604                                      dbus_interface=_NM_SERIAL_IFACE)
    576605    def create_palette(self):
    577606        palette = GsmPalette()
    578607
    class GsmDeviceView(TrayIcon): 
    637666
    638667        if state is network.DEVICE_STATE_ACTIVATED:
    639668            gsm_state = _GSM_STATE_CONNECTED
    640 
    641         elif state is network.DEVICE_STATE_DISCONNECTED:
     669            connection = network.find_gsm_connection()
     670            if (connection <> None):
     671                connection.set_connected()
     672                self.__connection_timestamp =  time.time() - connection.get_settings().connection.timestamp
     673                self.__connection_time_handler = gobject.timeout_add(1000, self.connection_timecount_cb)
     674                self.__ppp_stats_changed_cb(0, 0)
     675                self.connection_timecount_cb()               
     676                self._palette._info.show_all()
     677        else:
     678            self.__connection_timestamp = 0
     679            if (self.__connection_time_handler <> None):
     680                gobject.source_remove(self.__connection_time_handler)
     681            self._palette._info.hide_all()
     682        if state is network.DEVICE_STATE_DISCONNECTED:
    642683            gsm_state = _GSM_STATE_DISCONNECTED
    643684
    644685        elif state in [network.DEVICE_STATE_UNMANAGED, _NM_DEVICE_STATE_UNAVAILABLE, _NM_DEVICE_STATE_UNKNOWN]:
    class GsmDeviceView(TrayIcon): 
    655696                                         signal_name='StateChanged',
    656697                                         path=self._device.object_path,
    657698                                         dbus_interface=_NM_DEVICE_IFACE)
    658 
     699       
     700    def __ppp_stats_changed_cb(self, in_bytes, out_bytes):
     701        in_bytes = in_bytes / 1024
     702        out_bytes = out_bytes / 1024
     703        self._palette ._data_label.set_text("Data sent {0} kb / received {1} kb".format(out_bytes ,in_bytes))
     704
     705    def connection_timecount_cb(self):
     706        self.__connection_timestamp = self.__connection_timestamp + 1
     707        connection_time = datetime.datetime.fromtimestamp(self.__connection_timestamp)
     708        self._palette._conn_time_label.set_text("Connection time " + connection_time.strftime('%H : %M : %S'))
     709        return True
     710   
    659711class WirelessDeviceObserver(object):
    660712    def __init__(self, device, tray):
    661713        self._device = device
  • src/jarabe/model/network.py

    diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
    index 7c3849d..18c15d0 100644
    a b class NMSettingsConnection(dbus.service.Object): 
    324324        self._secrets = secrets
    325325
    326326    def set_connected(self):
    327         if not self._settings.connection.autoconnect:
    328             self._settings.connection.autoconnect = True
    329             self._settings.connection.timestamp = int(time.time())
    330             if self._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS:
    331                 self.save()
     327        if self._settings.connection.type == NM_CONNECTION_TYPE_GSM:
     328             self._settings.connection.timestamp = int(time.time())
     329        else:
     330            if not self._settings.connection.autoconnect:
     331                self._settings.connection.autoconnect = True
     332                self._settings.connection.timestamp = int(time.time())
     333                if self._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS:
     334                    self.save()
    332335
    333336    def set_secrets(self, secrets):
    334337        self._secrets = secrets