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 |
23 | 23 | import socket |
24 | 24 | import struct |
25 | 25 | import re |
26 | | |
| 26 | import datetime, time |
27 | 27 | import gtk |
28 | 28 | import gobject |
29 | 29 | import gconf |
… |
… |
_NM_PATH = '/org/freedesktop/NetworkManager' |
51 | 51 | _NM_DEVICE_IFACE = 'org.freedesktop.NetworkManager.Device' |
52 | 52 | _NM_WIRED_IFACE = 'org.freedesktop.NetworkManager.Device.Wired' |
53 | 53 | _NM_WIRELESS_IFACE = 'org.freedesktop.NetworkManager.Device.Wireless' |
| 54 | _NM_SERIAL_IFACE = 'org.freedesktop.NetworkManager.Device.Serial' |
54 | 55 | _NM_ACCESSPOINT_IFACE = 'org.freedesktop.NetworkManager.AccessPoint' |
55 | 56 | _NM_ACTIVE_CONN_IFACE = 'org.freedesktop.NetworkManager.Connection.Active' |
56 | 57 | |
… |
… |
class GsmPalette(Palette): |
221 | 222 | } |
222 | 223 | |
223 | 224 | 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 | |
224 | 235 | Palette.__init__(self, label=_('GSM Device')) |
225 | 236 | |
226 | 237 | self._current_state = None |
… |
… |
class GsmPalette(Palette): |
228 | 239 | self._toggle_state_item = gtk.MenuItem('') |
229 | 240 | self.set_state(_GSM_STATE_NOT_READY) |
230 | 241 | |
| 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 | |
231 | 254 | self._toggle_state_item.connect('activate', self._toggle_state_cb) |
232 | 255 | self.menu.append(self._toggle_state_item) |
233 | 256 | self._toggle_state_item.show() |
… |
… |
class GsmDeviceView(TrayIcon): |
558 | 581 | FRAME_POSITION_RELATIVE = 303 |
559 | 582 | |
560 | 583 | def __init__(self, device): |
| 584 | self.__connection_time_handler = None |
| 585 | self.__connection_timestamp = None |
| 586 | |
561 | 587 | client = gconf.client_get_default() |
562 | 588 | color = xocolor.XoColor(client.get_string('/desktop/sugar/user/color')) |
563 | 589 | |
… |
… |
class GsmDeviceView(TrayIcon): |
572 | 598 | signal_name='StateChanged', |
573 | 599 | path=self._device.object_path, |
574 | 600 | 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) |
576 | 605 | def create_palette(self): |
577 | 606 | palette = GsmPalette() |
578 | 607 | |
… |
… |
class GsmDeviceView(TrayIcon): |
637 | 666 | |
638 | 667 | if state is network.DEVICE_STATE_ACTIVATED: |
639 | 668 | 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: |
642 | 683 | gsm_state = _GSM_STATE_DISCONNECTED |
643 | 684 | |
644 | 685 | elif state in [network.DEVICE_STATE_UNMANAGED, _NM_DEVICE_STATE_UNAVAILABLE, _NM_DEVICE_STATE_UNKNOWN]: |
… |
… |
class GsmDeviceView(TrayIcon): |
655 | 696 | signal_name='StateChanged', |
656 | 697 | path=self._device.object_path, |
657 | 698 | 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 | |
659 | 711 | class WirelessDeviceObserver(object): |
660 | 712 | def __init__(self, device, tray): |
661 | 713 | self._device = device |
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): |
324 | 324 | self._secrets = secrets |
325 | 325 | |
326 | 326 | 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() |
332 | 335 | |
333 | 336 | def set_secrets(self, secrets): |
334 | 337 | self._secrets = secrets |