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

« back to all changes in this revision

Viewing changes to js/ui/status/network.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
const ByteArray = imports.byteArray;
3
 
const DBus = imports.dbus;
4
3
const GLib = imports.gi.GLib;
5
4
const GObject = imports.gi.GObject;
6
5
const Lang = imports.lang;
98
97
    return label;
99
98
}
100
99
 
101
 
function NMNetworkMenuItem() {
102
 
    this._init.apply(this, arguments);
103
 
}
104
 
 
105
 
NMNetworkMenuItem.prototype = {
106
 
    __proto__: PopupMenu.PopupBaseMenuItem.prototype,
 
100
const NMNetworkMenuItem = new Lang.Class({
 
101
    Name: 'NMNetworkMenuItem',
 
102
    Extends: PopupMenu.PopupBaseMenuItem,
107
103
 
108
104
    _init: function(accessPoints, title, params) {
109
 
        PopupMenu.PopupBaseMenuItem.prototype._init.call(this, params);
 
105
        this.parent(params);
110
106
 
111
107
        accessPoints = sortAccessPoints(accessPoints);
112
108
        this.bestAP = accessPoints[0];
117
113
        }
118
114
 
119
115
        this._label = new St.Label({ text: title });
 
116
        this.actor.label_actor = this._label;
120
117
        this.addActor(this._label);
121
118
        this._icons = new St.BoxLayout({ style_class: 'nm-menu-item-icons' });
122
119
        this.addActor(this._icons, { align: St.Align.END });
185
182
            apObj.updateId = 0;
186
183
        }
187
184
 
188
 
        PopupMenu.PopupBaseMenuItem.prototype.destroy.call(this);
 
185
        this.parent();
189
186
    }
190
 
};
191
 
 
192
 
function NMWiredSectionTitleMenuItem() {
193
 
    this._init.apply(this, arguments);
194
 
}
195
 
 
196
 
NMWiredSectionTitleMenuItem.prototype = {
197
 
    __proto__: PopupMenu.PopupSwitchMenuItem.prototype,
 
187
});
 
188
 
 
189
const NMWiredSectionTitleMenuItem = new Lang.Class({
 
190
    Name: 'NMWiredSectionTitleMenuItem',
 
191
    Extends: PopupMenu.PopupSwitchMenuItem,
198
192
 
199
193
    _init: function(label, params) {
200
194
        params = params || { };
201
195
        params.style_class = 'popup-subtitle-menu-item';
202
 
        PopupMenu.PopupSwitchMenuItem.prototype._init.call(this, label, false, params);
 
196
        this.parent(label, false, params);
203
197
    },
204
198
 
205
199
    updateForDevice: function(device) {
212
206
    },
213
207
 
214
208
    activate: function(event) {
215
 
        PopupMenu.PopupSwitchMenuItem.prototype.activate.call(this, event);
 
209
        this.parent(event);
216
210
 
217
211
        if (!this._device) {
218
212
            log('Section title activated when there is more than one device, should be non reactive');
231
225
        else
232
226
            this._device.deactivate();
233
227
    }
234
 
};
235
 
 
236
 
function NMWirelessSectionTitleMenuItem() {
237
 
    this._init.apply(this, arguments);
238
 
}
239
 
 
240
 
NMWirelessSectionTitleMenuItem.prototype = {
241
 
    __proto__: PopupMenu.PopupSwitchMenuItem.prototype,
 
228
});
 
229
 
 
230
const NMWirelessSectionTitleMenuItem = new Lang.Class({
 
231
    Name: 'NMWirelessSectionTitleMenuItem',
 
232
    Extends: PopupMenu.PopupSwitchMenuItem,
242
233
 
243
234
    _init: function(client, property, title, params) {
244
235
        params = params || { };
245
236
        params.style_class = 'popup-subtitle-menu-item';
246
 
        PopupMenu.PopupSwitchMenuItem.prototype._init.call(this, title, false, params);
 
237
        this.parent(title, false, params);
247
238
 
248
239
        this._client = client;
249
240
        this._property = property + '_enabled';
259
250
    updateForDevice: function(device) {
260
251
        // we show the switch
261
252
        // - if there not just one device
262
 
        // - if the switch is off
 
253
        // - if the switch is off (but it can be turned on)
263
254
        // - if the device is activated or disconnected
264
 
        if (device && this._softwareEnabled && this._hardwareEnabled) {
 
255
        if (!this._hardwareEnabled) {
 
256
            this.setStatus(_("hardware disabled"));
 
257
        } else if (device && this._softwareEnabled) {
265
258
            let text = device.getStatusLabel();
266
259
            this.setStatus(text);
267
260
        } else
269
262
    },
270
263
 
271
264
    activate: function(event) {
272
 
        PopupMenu.PopupSwitchMenuItem.prototype.activate.call(this, event);
 
265
        this.parent(event);
273
266
 
274
267
        this._client[this._setEnabledFunc](this._switch.state);
275
268
    },
286
279
 
287
280
        this.emit('enabled-changed', enabled);
288
281
    }
289
 
};
290
 
 
291
 
function NMDevice() {
292
 
    throw new TypeError('Instantanting abstract class NMDevice');
293
 
}
294
 
 
295
 
NMDevice.prototype = {
 
282
});
 
283
 
 
284
const NMDevice = new Lang.Class({
 
285
    Name: 'NMDevice',
 
286
    Abstract: true,
 
287
 
296
288
    _init: function(client, device, connections) {
297
289
        this.device = device;
298
290
        if (device) {
338
330
        }
339
331
        this.section = new PopupMenu.PopupMenuSection();
340
332
 
341
 
        this._createSection();
 
333
        this._deferredWorkId = Main.initializeDeferredWork(this.section.actor, Lang.bind(this, this._createSection));
342
334
    },
343
335
 
344
336
    destroy: function() {
405
397
        this._activeConnection = activeConnection;
406
398
 
407
399
        this._clearSection();
408
 
        this._createSection();
 
400
        this._queueCreateSection();
409
401
    },
410
402
 
411
403
    checkConnection: function(connection) {
412
 
        let exists = this._findConnection(connection._uuid) != -1;
 
404
        let pos = this._findConnection(connection._uuid);
 
405
        let exists = pos != -1;
413
406
        let valid = this.connectionValid(connection);
 
407
 
414
408
        if (exists && !valid)
415
409
            this.removeConnection(connection);
416
410
        else if (!exists && valid)
417
411
            this.addConnection(connection);
 
412
        else if (exists && valid) {
 
413
            // propagate changes and update the UI
 
414
 
 
415
            if (this._connections[pos].timestamp != connection._timestamp) {
 
416
                this._connections[pos].timestamp = connection._timestamp;
 
417
                this._connections.sort(this._connectionSortFunction);
 
418
 
 
419
                this._clearSection();
 
420
                this._queueCreateSection();
 
421
            }
 
422
        }
418
423
    },
419
424
 
420
425
    addConnection: function(connection) {
429
434
        this._connections.sort(this._connectionSortFunction);
430
435
 
431
436
        this._clearSection();
432
 
        this._createSection();
 
437
        this._queueCreateSection();
433
438
    },
434
439
 
435
440
    removeConnection: function(connection) {
453
458
            // (or in the case of NMDeviceWired, we want to hide
454
459
            // the only explicit connection)
455
460
            this._clearSection();
456
 
            this._createSection();
 
461
            this._queueCreateSection();
457
462
        }
458
463
    },
459
464
 
537
542
        return -1;
538
543
    },
539
544
 
 
545
    _queueCreateSection: function() {
 
546
        this._clearSection();
 
547
        Main.queueDeferredWork(this._deferredWorkId);
 
548
    },
 
549
 
540
550
    _clearSection: function() {
541
551
        // Clear everything
542
552
        this.section.removeAll();
631
641
        this._updateStatusItem();
632
642
 
633
643
        this._clearSection();
634
 
        this._createSection();
 
644
        this._queueCreateSection();
635
645
        this.emit('state-changed');
636
646
    },
637
647
 
674
684
 
675
685
        return out;
676
686
    }
677
 
};
 
687
});
678
688
Signals.addSignalMethods(NMDevice.prototype);
679
689
 
680
690
 
681
 
function NMDeviceWired() {
682
 
    this._init.apply(this, arguments);
683
 
}
684
 
 
685
 
NMDeviceWired.prototype = {
686
 
    __proto__: NMDevice.prototype,
 
691
const NMDeviceWired = new Lang.Class({
 
692
    Name: 'NMDeviceWired',
 
693
    Extends: NMDevice,
687
694
 
688
695
    _init: function(client, device, connections) {
689
696
        this._autoConnectionName = _("Auto Ethernet");
690
697
        this.category = NMConnectionCategory.WIRED;
691
698
 
692
 
        NMDevice.prototype._init.call(this, client, device, connections);
 
699
        this.parent(client, device, connections);
693
700
    },
694
701
 
695
702
    _createSection: function() {
696
 
        NMDevice.prototype._createSection.call(this);
 
703
        this.parent();
697
704
 
698
705
        // if we have only one connection (normal or automatic)
699
706
        // we hide the connection list, and use the switch to control
718
725
        }));
719
726
        return connection;
720
727
    }
721
 
};
722
 
 
723
 
function NMDeviceModem() {
724
 
    this._init.apply(this, arguments);
725
 
}
726
 
 
727
 
NMDeviceModem.prototype = {
728
 
    __proto__: NMDevice.prototype,
 
728
});
 
729
 
 
730
const NMDeviceModem = new Lang.Class({
 
731
    Name: 'NMDeviceModem',
 
732
    Extends: NMDevice,
729
733
 
730
734
    _init: function(client, device, connections) {
731
735
        let is_wwan = false;
774
778
            }));
775
779
        }
776
780
 
777
 
        NMDevice.prototype._init.call(this, client, device, connections);
 
781
        this.parent(client, device, connections);
778
782
    },
779
783
 
780
784
    setEnabled: function(enabled) {
787
791
                this.statusItem.setStatus(this.getStatusLabel());
788
792
        }
789
793
 
790
 
        NMDevice.prototype.setEnabled.call(this, enabled);
 
794
        this.parent(enabled);
791
795
    },
792
796
 
793
797
    get connected() {
804
808
            this._signalQualityId = 0;
805
809
        }
806
810
 
807
 
        NMDevice.prototype.destroy.call(this);
 
811
        this.parent();
808
812
    },
809
813
 
810
814
    _getSignalIcon: function() {
825
829
            this.section.addMenuItem(this._operatorItem);
826
830
        }
827
831
 
828
 
        NMDevice.prototype._createSection.call(this);
 
832
        this.parent();
829
833
    },
830
834
 
831
835
    _clearSection: function() {
832
836
        this._operatorItem = null;
833
837
 
834
 
        NMDevice.prototype._clearSection.call(this);
 
838
        this.parent();
835
839
    },
836
840
 
837
841
    _createAutomaticConnection: function() {
841
845
                    'connect-3g', this.device.get_path()]);
842
846
        return null;
843
847
    }
844
 
};
845
 
 
846
 
function NMDeviceBluetooth() {
847
 
    this._init.apply(this, arguments);
848
 
}
849
 
 
850
 
NMDeviceBluetooth.prototype = {
851
 
    __proto__: NMDevice.prototype,
 
848
});
 
849
 
 
850
const NMDeviceBluetooth = new Lang.Class({
 
851
    Name: 'NMDeviceBluetooth',
 
852
    Extends: NMDevice,
852
853
 
853
854
    _init: function(client, device, connections) {
854
855
        this._autoConnectionName = this._makeConnectionName(device);
856
857
 
857
858
        this.category = NMConnectionCategory.WWAN;
858
859
 
859
 
        NMDevice.prototype._init.call(this, client, device, connections);
 
860
        this.parent(client, device, connections);
860
861
    },
861
862
 
862
863
    _createAutomaticConnection: function() {
884
885
        this._autoConnectionName = this._makeConnectionName(this.device);
885
886
 
886
887
        this._clearSection();
887
 
        this._createSection();
 
888
        this._queueCreateSection();
 
889
        this._updateStatusItem();
 
890
    },
 
891
 
 
892
    _getDescription: function() {
 
893
        return this.device.name || _("Bluetooth");
888
894
    }
889
 
};
 
895
});
890
896
 
891
897
 
892
898
// Not a real device, but I save a lot code this way
893
 
function NMDeviceVPN() {
894
 
    this._init.apply(this, arguments);
895
 
}
896
 
 
897
 
NMDeviceVPN.prototype = {
898
 
    __proto__: NMDevice.prototype,
 
899
const NMDeviceVPN = new Lang.Class({
 
900
    Name: 'NMDeviceVPN',
 
901
    Extends: NMDevice,
899
902
 
900
903
    _init: function(client) {
901
904
        // Disable autoconnections
902
905
        this._autoConnectionName = null;
903
906
        this.category = NMConnectionCategory.VPN;
904
907
 
905
 
        NMDevice.prototype._init.call(this, client, null, [ ]);
 
908
        this.parent(client, null, [ ]);
906
909
    },
907
910
 
908
911
    connectionValid: function(connection) {
918
921
    },
919
922
 
920
923
    setActiveConnection: function(activeConnection) {
921
 
        NMDevice.prototype.setActiveConnection.call(this, activeConnection);
 
924
        this.parent(activeConnection);
922
925
 
923
926
        this.emit('active-connection-changed');
924
927
    },
935
938
    getStatusLabel: function() {
936
939
        return null;
937
940
    }
938
 
};
939
 
 
940
 
function NMDeviceWireless() {
941
 
    this._init.apply(this, arguments);
942
 
}
943
 
 
944
 
NMDeviceWireless.prototype = {
945
 
    __proto__: NMDevice.prototype,
 
941
});
 
942
 
 
943
const NMDeviceWireless = new Lang.Class({
 
944
    Name: 'NMDeviceWireless',
 
945
    Extends: NMDevice,
946
946
 
947
947
    _init: function(client, device, connections) {
948
948
        this.category = NMConnectionCategory.WIRELESS;
1014
1014
        this._apAddedId = device.connect('access-point-added', Lang.bind(this, this._accessPointAdded));
1015
1015
        this._apRemovedId = device.connect('access-point-removed', Lang.bind(this, this._accessPointRemoved));
1016
1016
 
1017
 
        NMDevice.prototype._init.call(this, client, device, validConnections);
 
1017
        this.parent(client, device, validConnections);
1018
1018
    },
1019
1019
 
1020
1020
    destroy: function() {
1034
1034
            this._apRemovedId = 0;
1035
1035
        }
1036
1036
 
1037
 
        NMDevice.prototype.destroy.call(this);
 
1037
        this.parent();
1038
1038
    },
1039
1039
 
1040
1040
    setEnabled: function(enabled) {
1235
1235
                      accessPoints: [ accessPoint ]
1236
1236
                    };
1237
1237
            apObj.ssidText = ssidToLabel(apObj.ssid);
1238
 
            needsupdate = true;
1239
1238
        }
1240
1239
 
1241
1240
        // check if this enables new connections for this group
1250
1249
            }
1251
1250
        }
1252
1251
 
1253
 
        if (needsupdate) {
1254
 
            if (apObj.item)
1255
 
                apObj.item.destroy();
1256
 
 
 
1252
        if (pos == -1 || needsupdate) {
1257
1253
            if (pos != -1)
1258
1254
                this._networks.splice(pos, 1);
1259
 
 
1260
 
            if (this._networks.length == 0) {
1261
 
                // only network in the list
1262
 
                this._networks.push(apObj);
1263
 
                this._clearSection();
1264
 
                this._createSection();
1265
 
                return;
1266
 
            }
1267
 
 
1268
 
            // skip networks that should appear earlier
1269
 
            let menuPos = 0;
1270
 
            for (pos = 0;
1271
 
                 pos < this._networks.length &&
1272
 
                 this._networkSortFunction(this._networks[pos], apObj) < 0; ++pos) {
1273
 
                if (this._networks[pos] != this._activeNetwork)
1274
 
                    menuPos++;
1275
 
            }
1276
 
 
1277
 
            // (re-)add the network
1278
 
            this._networks.splice(pos, 0, apObj);
1279
 
 
1280
 
            if (this._shouldShowConnectionList()) {
1281
 
                menuPos += (this._activeConnectionItem ? 1 : 0);
1282
 
                this._createNetworkItem(apObj, menuPos);
1283
 
            }
 
1255
            pos = Util.insertSorted(this._networks, apObj, this._networkSortFunction);
 
1256
 
 
1257
            this._clearSection();
 
1258
            this._queueCreateSection();
1284
1259
        }
1285
1260
    },
1286
1261
 
1348
1323
    },
1349
1324
 
1350
1325
    _clearSection: function() {
1351
 
        NMDevice.prototype._clearSection.call(this);
 
1326
        this.parent();
1352
1327
 
1353
1328
        for (let i = 0; i < this._networks.length; i++)
1354
1329
            this._networks[i].item = null;
1367
1342
        let obj = this._connections[pos];
1368
1343
        this._connections.splice(pos, 1);
1369
1344
 
1370
 
        let anyauto = false, forceupdate = false;
 
1345
        let forceupdate = false;
1371
1346
        for (let i = 0; i < this._networks.length; i++) {
1372
1347
            let apObj = this._networks[i];
1373
1348
            let connections = apObj.connections;
1375
1350
                if (connections[k]._uuid == connection._uuid) {
1376
1351
                    // remove the connection from the access point group
1377
1352
                    connections.splice(k);
1378
 
                    anyauto = connections.length == 0;
 
1353
                    forceupdate = forceupdate || connections.length == 0;
1379
1354
 
1380
 
                    if (anyauto) {
1381
 
                        // this potentially changes the sorting order
1382
 
                        forceupdate = true;
 
1355
                    if (forceupdate)
1383
1356
                        break;
1384
 
                    }
 
1357
 
1385
1358
                    if (apObj.item) {
1386
1359
                        if (apObj.item instanceof PopupMenu.PopupSubMenuMenuItem) {
1387
 
                            let items = apObj.item.menu.getMenuItems();
 
1360
                            let items = apObj.item.menu._getMenuItems();
1388
1361
                            if (items.length == 2) {
1389
1362
                                // we need to update the connection list to convert this to a normal item
1390
1363
                                forceupdate = true;
1406
1379
            }
1407
1380
        }
1408
1381
 
1409
 
        if (forceupdate || anyauto) {
 
1382
        if (forceupdate) {
1410
1383
            this._networks.sort(this._networkSortFunction);
1411
1384
            this._clearSection();
1412
 
            this._createSection();
 
1385
            this._queueCreateSection();
1413
1386
        }
1414
1387
    },
1415
1388
 
1442
1415
        if (forceupdate) {
1443
1416
            this._networks.sort(this._networkSortFunction);
1444
1417
            this._clearSection();
1445
 
            this._createSection();
 
1418
            this._queueCreateSection();
1446
1419
        }
1447
1420
    },
1448
1421
 
1449
1422
    _createActiveConnectionItem: function() {
1450
1423
        let icon, title;
1451
 
        if (this._activeConnection._connection) {
 
1424
        if (this._activeConnection && this._activeConnection._connection) {
1452
1425
            let connection = this._activeConnection._connection;
1453
1426
            if (this._activeNetwork)
1454
1427
                this._activeConnectionItem = new NMNetworkMenuItem(this._activeNetwork.accessPoints, undefined,
1541
1514
        if (!this._shouldShowConnectionList())
1542
1515
            return;
1543
1516
 
1544
 
        if(this._activeConnection) {
 
1517
        if (this._activeNetwork) {
1545
1518
            this._createActiveConnectionItem();
1546
1519
            this.section.addMenuItem(this._activeConnectionItem);
1547
1520
        }
1550
1523
 
1551
1524
        for(let j = 0; j < this._networks.length; j++) {
1552
1525
            let apObj = this._networks[j];
1553
 
            if (apObj == this._activeNetwork)
 
1526
            if (apObj == this._activeNetwork) {
 
1527
                activeOffset--;
1554
1528
                continue;
 
1529
            }
1555
1530
 
1556
1531
            this._createNetworkItem(apObj, j + activeOffset);
1557
1532
        }
1558
1533
    },
1559
 
};
 
1534
});
1560
1535
 
1561
 
function NMApplet() {
1562
 
    this._init.apply(this, arguments);
1563
 
}
1564
 
NMApplet.prototype = {
1565
 
    __proto__: PanelMenu.SystemStatusButton.prototype,
 
1536
const NMApplet = new Lang.Class({
 
1537
    Name: 'NMApplet',
 
1538
    Extends: PanelMenu.SystemStatusButton,
1566
1539
 
1567
1540
    _init: function() {
1568
 
        PanelMenu.SystemStatusButton.prototype._init.call(this, 'network-error');
 
1541
        this.parent('network-error', _("Network"));
1569
1542
 
1570
1543
        this._client = NMClient.Client.new();
1571
1544
 
1831
1804
        let activating = null;
1832
1805
        let default_ip4 = null;
1833
1806
        let default_ip6 = null;
 
1807
        let active_vpn = null;
1834
1808
        for (let i = 0; i < this._activeConnections.length; i++) {
1835
1809
            let a = this._activeConnections[i];
1836
1810
 
1860
1834
                default_ip4 = a;
1861
1835
            if (a.default6)
1862
1836
                default_ip6 = a;
 
1837
            if (a._type == 'vpn')
 
1838
                active_vpn = a;
1863
1839
 
1864
1840
            if (a.state == NetworkManager.ActiveConnectionState.ACTIVATING)
1865
1841
                activating = a;
1890
1866
            }
1891
1867
        }
1892
1868
 
1893
 
        this._mainConnection = activating || default_ip4 || default_ip6 || this._activeConnections[0] || null;
 
1869
        this._mainConnection = activating || active_vpn || default_ip4 || default_ip6 || this._activeConnections[0] || null;
1894
1870
    },
1895
1871
 
1896
1872
    _notifyActivated: function(activeConnection) {
2131
2107
            this._mobileUpdateId = 0;
2132
2108
        }
2133
2109
    }
2134
 
};
2135
 
 
2136
 
function NMMessageTraySource() {
2137
 
    this._init();
2138
 
}
2139
 
 
2140
 
NMMessageTraySource.prototype = {
2141
 
    __proto__: MessageTray.Source.prototype,
 
2110
});
 
2111
 
 
2112
const NMMessageTraySource = new Lang.Class({
 
2113
    Name: 'NMMessageTraySource',
 
2114
    Extends: MessageTray.Source,
2142
2115
 
2143
2116
    _init: function() {
2144
 
        MessageTray.Source.prototype._init.call(this, _("Network Manager"));
 
2117
        this.parent(_("Network Manager"));
2145
2118
 
2146
2119
        let icon = new St.Icon({ icon_name: 'network-transmit-receive',
2147
2120
                                 icon_type: St.IconType.SYMBOLIC,
2149
2122
                               });
2150
2123
        this._setSummaryIcon(icon);
2151
2124
    }
2152
 
};
 
2125
});