~ubuntu-branches/ubuntu/trusty/gnome-shell/trusty-proposed

« back to all changes in this revision

Viewing changes to js/ui/status/power.js

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-03-14 13:47:20 UTC
  • mfrom: (1.1.36) (18.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20120314134720-202sbjbu4a3z1fru
Tags: 3.3.90-0ubuntu1
* Sync with Debian experimental svn packaging (LP: #941755, #937709).
  Remaining changes:
  - debian/gnome-shell.gsettings-override: Update for Ubuntu defaults
  - debian/control.in: Recommend cups-pk-helper
  - debian/patches/10-make-NetworkManager-optional.patch: Disabled
  - Don't run dh-autoreconf

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
2
2
 
3
3
const Gio = imports.gi.Gio;
4
 
const DBus = imports.dbus;
5
4
const Lang = imports.lang;
6
5
const Mainloop = imports.mainloop;
7
6
const Shell = imports.gi.Shell;
40
39
    PENDING_DISCHARGE: 6
41
40
};
42
41
 
43
 
const PowerManagerInterface = {
44
 
    name: 'org.gnome.SettingsDaemon.Power',
45
 
    methods: [
46
 
        { name: 'GetDevices', inSignature: '', outSignature: 'a(susdut)' },
47
 
        { name: 'GetPrimaryDevice', inSignature: '', outSignature: '(susdut)' },
48
 
        ],
49
 
    signals: [
50
 
        { name: 'Changed', inSignature: '' },
51
 
        ],
52
 
    properties: [
53
 
        { name: 'Icon', signature: 's', access: 'read' },
54
 
        ]
55
 
};
56
 
let PowerManagerProxy = DBus.makeProxyClass(PowerManagerInterface);
57
 
 
58
 
function Indicator() {
59
 
    this._init.apply(this, arguments);
60
 
}
61
 
 
62
 
Indicator.prototype = {
63
 
    __proto__: PanelMenu.SystemStatusButton.prototype,
 
42
const PowerManagerInterface = <interface name="org.gnome.SettingsDaemon.Power">
 
43
<method name="GetDevices">
 
44
    <arg type="a(susdut)" direction="out" />
 
45
</method>
 
46
<method name="GetPrimaryDevice">
 
47
    <arg type="(susdut)" direction="out" />
 
48
</method>
 
49
<property name="Icon" type="s" access="read" />
 
50
</interface>;
 
51
 
 
52
const PowerManagerProxy = Gio.DBusProxy.makeProxyWrapper(PowerManagerInterface);
 
53
 
 
54
const Indicator = new Lang.Class({
 
55
    Name: 'PowerIndicator',
 
56
    Extends: PanelMenu.SystemStatusButton,
64
57
 
65
58
    _init: function() {
66
 
        PanelMenu.SystemStatusButton.prototype._init.call(this, 'battery-missing');
67
 
        this._proxy = new PowerManagerProxy(DBus.session, BUS_NAME, OBJECT_PATH);
 
59
        this.parent('battery-missing', _("Battery"));
 
60
 
 
61
        this._proxy = new PowerManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH);
68
62
 
69
63
        this._deviceItems = [ ];
70
64
        this._hasPrimary = false;
81
75
        this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
82
76
        this.menu.addSettingsAction(_("Power Settings"), 'gnome-power-panel.desktop');
83
77
 
84
 
        this._proxy.connect('Changed', Lang.bind(this, this._devicesChanged));
 
78
        this._proxy.connect('g-properties-changed',
 
79
                            Lang.bind(this, this._devicesChanged));
85
80
        this._devicesChanged();
86
81
    },
87
82
 
88
83
    _readPrimaryDevice: function() {
89
 
        this._proxy.GetPrimaryDeviceRemote(Lang.bind(this, function(device, error) {
 
84
        this._proxy.GetPrimaryDeviceRemote(Lang.bind(this, function(result, error) {
90
85
            if (error) {
91
86
                this._hasPrimary = false;
92
87
                this._primaryDeviceId = null;
93
88
                this._batteryItem.actor.hide();
94
89
                return;
95
90
            }
96
 
            let [device_id, device_type, icon, percentage, state, seconds] = device;
 
91
            let [[device_id, device_type, icon, percentage, state, seconds]] = result;
97
92
            if (device_type == UPDeviceType.BATTERY) {
98
93
                this._hasPrimary = true;
99
94
                let time = Math.round(seconds / 60);
130
125
    },
131
126
 
132
127
    _readOtherDevices: function() {
133
 
        this._proxy.GetDevicesRemote(Lang.bind(this, function(devices, error) {
 
128
        this._proxy.GetDevicesRemote(Lang.bind(this, function(result, error) {
134
129
            this._deviceItems.forEach(function(i) { i.destroy(); });
135
130
            this._deviceItems = [];
136
131
 
139
134
            }
140
135
 
141
136
            let position = 0;
 
137
            let [devices] = result;
142
138
            for (let i = 0; i < devices.length; i++) {
143
139
                let [device_id, device_type] = devices[i];
144
140
                if (device_type == UPDeviceType.AC_POWER || device_id == this._primaryDeviceId)
153
149
    },
154
150
 
155
151
    _devicesChanged: function() {
156
 
        this._proxy.GetRemote('Icon', Lang.bind(this, function(icon, error) {
157
 
            if (icon) {
158
 
                let gicon = Gio.icon_new_for_string(icon);
159
 
                this.setGIcon(gicon);
160
 
                this.actor.show();
161
 
            } else {
162
 
                this.menu.close();
163
 
                this.actor.hide();
164
 
            }
165
 
        }));
 
152
        let icon = this._proxy.Icon;
 
153
        if (icon) {
 
154
            let gicon = Gio.icon_new_for_string(icon);
 
155
            this.setGIcon(gicon);
 
156
            this.actor.show();
 
157
        } else {
 
158
            this.menu.close();
 
159
            this.actor.hide();
 
160
        }
166
161
        this._readPrimaryDevice();
167
162
        this._readOtherDevices();
168
163
    }
169
 
};
170
 
 
171
 
function DeviceItem() {
172
 
    this._init.apply(this, arguments);
173
 
}
174
 
 
175
 
DeviceItem.prototype = {
176
 
    __proto__: PopupMenu.PopupBaseMenuItem.prototype,
 
164
});
 
165
 
 
166
const DeviceItem = new Lang.Class({
 
167
    Name: 'DeviceItem',
 
168
    Extends: PopupMenu.PopupBaseMenuItem,
177
169
 
178
170
    _init: function(device) {
179
 
        PopupMenu.PopupBaseMenuItem.prototype._init.call(this, { reactive: false });
 
171
        this.parent({ reactive: false });
180
172
 
181
173
        let [device_id, device_type, icon, percentage, state, time] = device;
182
174
 
223
215
            return _("Unknown");
224
216
        }
225
217
    }
226
 
}
 
218
});