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 |
23 | 23 | import socket |
24 | 24 | import struct |
25 | 25 | import re |
26 | | import datetime, time |
| 26 | import datetime |
| 27 | import time |
27 | 28 | import gtk |
28 | 29 | import gobject |
29 | 30 | import gconf |
… |
… |
class GsmPalette(Palette): |
221 | 222 | gobject.TYPE_NONE, ([])), |
222 | 223 | } |
223 | 224 | |
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, |
228 | 227 | xscale=1, yscale=0.33) |
229 | | padder.set_padding(style.DEFAULT_SPACING, |
| 228 | alignment.set_padding(style.DEFAULT_SPACING, |
230 | 229 | style.DEFAULT_SPACING, |
231 | 230 | style.DEFAULT_SPACING, |
232 | 231 | style.DEFAULT_SPACING) |
233 | | padder.add(child) |
234 | | return padder |
| 232 | alignment.add(child) |
| 233 | return alignment |
| 234 | |
| 235 | def __init__(self): |
235 | 236 | |
236 | 237 | Palette.__init__(self, label=_('Wireless modem')) |
237 | 238 | |
… |
… |
class GsmPalette(Palette): |
244 | 245 | |
245 | 246 | self.set_state(_GSM_STATE_NOT_READY) |
246 | 247 | |
247 | | self._info = gtk.VBox() |
| 248 | self.info_box = gtk.VBox() |
| 249 | |
248 | 250 | self._data_label = gtk.Label() |
249 | 251 | 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 | |
252 | 257 | self._conn_time_label = gtk.Label() |
253 | 258 | 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() |
255 | 263 | |
256 | | self._info.show_all() |
257 | | self.set_content(self._info) |
| 264 | self.info_box.show() |
| 265 | self.set_content(self.info_box) |
258 | 266 | |
259 | 267 | def set_state(self, state): |
260 | 268 | self._current_state = state |
… |
… |
class GsmDeviceView(TrayIcon): |
707 | 715 | FRAME_POSITION_RELATIVE = 303 |
708 | 716 | |
709 | 717 | 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 |
712 | 720 | |
713 | 721 | client = gconf.client_get_default() |
714 | 722 | color = xocolor.XoColor(client.get_string('/desktop/sugar/user/color')) |
… |
… |
class GsmDeviceView(TrayIcon): |
801 | 809 | if state is network.DEVICE_STATE_ACTIVATED: |
802 | 810 | gsm_state = _GSM_STATE_CONNECTED |
803 | 811 | connection = network.find_gsm_connection() |
804 | | if (connection <> None): |
| 812 | if connection is not None: |
805 | 813 | 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 | |
816 | 820 | if state is network.DEVICE_STATE_DISCONNECTED: |
817 | 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() |
818 | 826 | |
819 | 827 | elif state in [network.DEVICE_STATE_UNMANAGED, |
820 | 828 | network.DEVICE_STATE_UNAVAILABLE, |
… |
… |
class GsmDeviceView(TrayIcon): |
836 | 844 | dbus_interface=_NM_DEVICE_IFACE) |
837 | 845 | |
838 | 846 | 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')) |
848 | 862 | |
849 | 863 | class WirelessDeviceObserver(object): |
850 | 864 | def __init__(self, device, tray, device_type): |