~straemer/ubuntu/quantal/update-manager/fix-for-1058070

« back to all changes in this revision

Viewing changes to UpdateManager/Core/AlertWatcher.py

  • Committer: Package Import Robot
  • Author(s): Michael Terry
  • Date: 2012-06-29 10:59:30 UTC
  • mfrom: (389.1.2 precise-security)
  • Revision ID: package-import@ubuntu.com-20120629105930-0oaj9vdvykmvkjum
Tags: 1:0.165
* Implementation of "update on start" feature from spec
  https://wiki.ubuntu.com/SoftwareUpdates
* Use a single main window that changes instead of having modal dialogs
* Implement several special-purpose dialogs like "No updates" or
  "Dist upgrade needed" accordingn to the above spec
* Split out release upgrader code and DistUpgrade module into a separate
  source package
* Drop python-update-manager, as it is unused
* debian/tests:
  - Add dep8 tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# AlertWatcher.py 
 
1
# AlertWatcher.py
 
2
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
2
3
#
3
4
#  Copyright (c) 2010 Mohamed Amine IL Idrissi
4
 
#  
 
5
#
5
6
#  Author: Mohamed Amine IL Idrissi <ilidrissiamine@gmail.com>
6
 
7
 
#  This program is free software; you can redistribute it and/or 
8
 
#  modify it under the terms of the GNU General Public License as 
 
7
#
 
8
#  This program is free software; you can redistribute it and/or
 
9
#  modify it under the terms of the GNU General Public License as
9
10
#  published by the Free Software Foundation; either version 2 of the
10
11
#  License, or (at your option) any later version.
11
 
 
12
#
12
13
#  This program is distributed in the hope that it will be useful,
13
14
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
15
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
16
#  GNU General Public License for more details.
16
 
 
17
#
17
18
#  You should have received a copy of the GNU General Public License
18
19
#  along with this program; if not, write to the Free Software
19
20
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25
26
import dbus
26
27
from dbus.mainloop.glib import DBusGMainLoop
27
28
 
 
29
 
28
30
class AlertWatcher(GObject.GObject):
29
31
    """ a class that checks for alerts and reports them, like a battery
30
32
    or network warning """
31
 
    
 
33
 
32
34
    __gsignals__ = {"network-alert": (GObject.SignalFlags.RUN_FIRST,
33
35
                                      None,
34
36
                                      (GObject.TYPE_INT,)),
37
39
                                      (GObject.TYPE_BOOLEAN,)),
38
40
                    "network-3g-alert": (GObject.SignalFlags.RUN_FIRST,
39
41
                                         None,
40
 
                                        (GObject.TYPE_BOOLEAN,
41
 
                                         GObject.TYPE_BOOLEAN,)),
 
42
                                         (GObject.TYPE_BOOLEAN,
 
43
                                          GObject.TYPE_BOOLEAN,)),
42
44
                    }
43
 
    
 
45
 
44
46
    def __init__(self):
45
47
        GObject.GObject.__init__(self)
46
48
        DBusGMainLoop(set_as_default=True)
47
49
        self.bus = dbus.Bus(dbus.Bus.TYPE_SYSTEM)
48
 
        self.network_state = 3 # make it always connected if NM isn't available
49
 
        
 
50
        # make it always connected if NM isn't available
 
51
        self.network_state = 3
 
52
 
50
53
    def check_alert_state(self):
51
54
        try:
52
55
            obj = self.bus.get_object("org.freedesktop.NetworkManager",
53
56
                                      "/org/freedesktop/NetworkManager")
54
 
            obj.connect_to_signal("StateChanged",
55
 
                                  self._on_network_state_changed,
56
 
                                  dbus_interface="org.freedesktop.NetworkManager")
 
57
            obj.connect_to_signal(
 
58
                "StateChanged",
 
59
                self._on_network_state_changed,
 
60
                dbus_interface="org.freedesktop.NetworkManager")
57
61
            interface = dbus.Interface(obj, "org.freedesktop.DBus.Properties")
58
 
            self.network_state = interface.Get("org.freedesktop.NetworkManager", "State")
 
62
            self.network_state = interface.Get(
 
63
                "org.freedesktop.NetworkManager", "State")
59
64
            self._network_alert(self.network_state)
60
65
            # power
61
66
            obj = self.bus.get_object('org.freedesktop.UPower',
81
86
 
82
87
    def _network_3g_alert(self, on_3g, is_roaming):
83
88
        self.emit("network-3g-alert", on_3g, is_roaming)
84
 
    
 
89
 
85
90
    def _network_alert(self, state):
86
91
        self.network_state = state
87
92
        self.emit("network-alert", state)
88
 
        
 
93
 
89
94
    def _power_changed(self):
90
 
        obj = self.bus.get_object("org.freedesktop.UPower", \
91
 
                                "/org/freedesktop/UPower")
 
95
        obj = self.bus.get_object("org.freedesktop.UPower",
 
96
                                  "/org/freedesktop/UPower")
92
97
        interface = dbus.Interface(obj, "org.freedesktop.DBus.Properties")
93
98
        on_battery = interface.Get("org.freedesktop.UPower", "OnBattery")
94
99
        self.emit("battery-alert", on_battery)
95
 
        
96