~ubuntu-branches/ubuntu/precise/gnome-shell/precise

« back to all changes in this revision

Viewing changes to js/ui/endSessionDialog.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:
18
18
 * 02111-1307, USA.
19
19
 */
20
20
 
21
 
const DBus = imports.dbus;
22
21
const Lang = imports.lang;
23
22
const Signals = imports.signals;
24
23
 
25
24
const AccountsService = imports.gi.AccountsService;
26
25
const Clutter = imports.gi.Clutter;
 
26
const Gio = imports.gi.Gio;
27
27
const GLib = imports.gi.GLib;
28
28
const Gtk = imports.gi.Gtk;
29
29
const Pango = imports.gi.Pango;
30
30
const St = imports.gi.St;
31
31
const Shell = imports.gi.Shell;
32
32
 
33
 
const GnomeSession = imports.misc.gnomeSession
 
33
const GnomeSession = imports.misc.gnomeSession;
34
34
const Lightbox = imports.ui.lightbox;
35
35
const Main = imports.ui.main;
36
36
const ModalDialog = imports.ui.modalDialog;
43
43
 
44
44
const GSM_SESSION_MANAGER_LOGOUT_FORCE = 2;
45
45
 
46
 
const EndSessionDialogIface = {
47
 
    name: 'org.gnome.SessionManager.EndSessionDialog',
48
 
    methods: [{ name: 'Open',
49
 
                inSignature: 'uuuao',
50
 
                outSignature: ''
51
 
              }
52
 
             ],
53
 
    signals: [{ name: 'Canceled',
54
 
                inSignature: '',
55
 
              }],
56
 
    properties: []
57
 
};
 
46
const EndSessionDialogIface = <interface name="org.gnome.SessionManager.EndSessionDialog">
 
47
<method name="Open">
 
48
    <arg type="u" direction="in" />
 
49
    <arg type="u" direction="in" />
 
50
    <arg type="u" direction="in" />
 
51
    <arg type="ao" direction="in" />
 
52
</method>
 
53
<signal name="ConfirmedLogout" />
 
54
<signal name="ConfirmedReboot" />
 
55
<signal name="ConfirmedShutdown" />
 
56
<signal name="Canceled" />
 
57
<signal name="Closed" />
 
58
</interface>;
58
59
 
59
60
const logoutDialogContent = {
60
 
    subjectWithUser: _("Log Out %s"),
61
 
    subject: _("Log Out"),
 
61
    subjectWithUser: C_("title", "Log Out %s"),
 
62
    subject: C_("title", "Log Out"),
62
63
    inhibitedDescription: _("Click Log Out to quit these applications and log out of the system."),
63
64
    uninhibitedDescriptionWithUser: function(user, seconds) {
64
65
        return ngettext("%s will be logged out automatically in %d second.",
72
73
    },
73
74
    endDescription: _("Logging out of the system."),
74
75
    confirmButtons: [{ signal: 'ConfirmedLogout',
75
 
                       label:  _("Log Out") }],
 
76
                       label:  C_("button", "Log Out") }],
76
77
    iconStyleClass: 'end-session-dialog-logout-icon'
77
78
};
78
79
 
79
80
const shutdownDialogContent = {
80
 
    subject: _("Power Off"),
 
81
    subject: C_("title", "Power Off"),
81
82
    inhibitedDescription: _("Click Power Off to quit these applications and power off the system."),
82
83
    uninhibitedDescription: function(seconds) {
83
84
        return ngettext("The system will power off automatically in %d second.",
86
87
    },
87
88
    endDescription: _("Powering off the system."),
88
89
    confirmButtons: [{ signal: 'ConfirmedReboot',
89
 
                       label:  _("Restart") },
 
90
                       label:  C_("button", "Restart") },
90
91
                     { signal: 'ConfirmedShutdown',
91
 
                       label:  _("Power Off") }],
 
92
                       label:  C_("button", "Power Off") }],
92
93
    iconName: 'system-shutdown',
93
94
    iconStyleClass: 'end-session-dialog-shutdown-icon'
94
95
};
95
96
 
96
97
const restartDialogContent = {
97
 
    subject: _("Restart"),
 
98
    subject: C_("title", "Restart"),
98
99
    inhibitedDescription: _("Click Restart to quit these applications and restart the system."),
99
100
    uninhibitedDescription: function(seconds) {
100
101
        return ngettext("The system will restart automatically in %d second.",
103
104
    },
104
105
    endDescription: _("Restarting the system."),
105
106
    confirmButtons: [{ signal: 'ConfirmedReboot',
106
 
                       label:  _("Restart") }],
 
107
                       label:  C_("button", "Restart") }],
107
108
    iconName: 'system-shutdown',
108
109
    iconStyleClass: 'end-session-dialog-shutdown-icon'
109
110
};
141
142
    return app;
142
143
}
143
144
 
144
 
function ListItem(app, reason) {
145
 
    this._init(app, reason);
146
 
}
 
145
const ListItem = new Lang.Class({
 
146
    Name: 'ListItem',
147
147
 
148
 
ListItem.prototype = {
149
148
    _init: function(app, reason) {
150
149
        this._app = app;
151
150
        this._reason = reason;
191
190
        this.emit('activate');
192
191
        this._app.activate();
193
192
    }
194
 
};
 
193
});
195
194
Signals.addSignalMethods(ListItem.prototype);
196
195
 
197
196
// The logout timer only shows updates every 10 seconds
229
228
    }
230
229
}
231
230
 
232
 
function EndSessionDialog() {
233
 
    if (_endSessionDialog == null) {
234
 
        this._init();
235
 
        DBus.session.exportObject('/org/gnome/SessionManager/EndSessionDialog',
236
 
                                  this);
237
 
        _endSessionDialog = this;
238
 
    }
239
 
 
240
 
    return _endSessionDialog;
241
 
}
242
 
 
243
231
function init() {
244
232
    // This always returns the same singleton object
245
233
    // By instantiating it initially, we register the
246
234
    // bus object, etc.
247
 
    let dialog = new EndSessionDialog();
 
235
    _endSessionDialog = new EndSessionDialog();
248
236
}
249
237
 
250
 
EndSessionDialog.prototype = {
251
 
    __proto__: ModalDialog.ModalDialog.prototype,
 
238
const EndSessionDialog = new Lang.Class({
 
239
    Name: 'EndSessionDialog',
 
240
    Extends: ModalDialog.ModalDialog,
252
241
 
253
242
    _init: function() {
254
 
        ModalDialog.ModalDialog.prototype._init.call(this, { styleClass: 'end-session-dialog' });
 
243
        this.parent({ styleClass: 'end-session-dialog' });
255
244
 
256
245
        this._user = AccountsService.UserManager.get_default().get_user(GLib.get_user_name());
257
246
 
326
315
                                          if (this._applicationList.get_children().length == 0)
327
316
                                              scrollView.hide();
328
317
                                      }));
 
318
 
 
319
        this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(EndSessionDialogIface, this);
 
320
        this._dbusImpl.export(Gio.DBus.session, '/org/gnome/SessionManager/EndSessionDialog');
329
321
    },
330
322
 
331
323
    _onDestroy: function() {
341
333
        this._iconBin.child = null;
342
334
        if (iconFile) {
343
335
            this._iconBin.show();
344
 
            this._iconBin.set_style('background-image: url("' + iconFile + '");');
 
336
            this._iconBin.set_style('background-image: url("' + iconFile + '");' +
 
337
                                    'background-size: contain;');
345
338
        } else {
346
339
            this._iconBin.hide();
347
340
        }
439
432
    },
440
433
 
441
434
    close: function() {
442
 
        ModalDialog.ModalDialog.prototype.close.call(this);
443
 
        DBus.session.emit_signal('/org/gnome/SessionManager/EndSessionDialog',
444
 
                                 'org.gnome.SessionManager.EndSessionDialog',
445
 
                                 'Closed', '', []);
 
435
        this.parent();
 
436
        this._dbusImpl.emit_signal('Closed', null);
446
437
    },
447
438
 
448
439
    cancel: function() {
449
440
        this._stopTimer();
450
 
        DBus.session.emit_signal('/org/gnome/SessionManager/EndSessionDialog',
451
 
                                 'org.gnome.SessionManager.EndSessionDialog',
452
 
                                 'Canceled', '', []);
 
441
        this._dbusImpl.emit_signal('Canceled', null);
453
442
        this.close(global.get_current_time());
454
443
    },
455
444
 
456
445
    _confirm: function(signal) {
457
446
        this._fadeOutDialog();
458
447
        this._stopTimer();
459
 
        DBus.session.emit_signal('/org/gnome/SessionManager/EndSessionDialog',
460
 
                                 'org.gnome.SessionManager.EndSessionDialog',
461
 
                                 signal, '', []);
 
448
        this._dbusImpl.emit_signal(signal, null);
462
449
    },
463
450
 
464
451
    _onOpened: function() {
510
497
        this._updateContent();
511
498
    },
512
499
 
513
 
    OpenAsync: function(type, timestamp, totalSecondsToStayOpen, inhibitorObjectPaths, callback) {
 
500
    OpenAsync: function(parameters, invocation) {
 
501
        let [type, timestamp, totalSecondsToStayOpen, inhibitorObjectPaths] = parameters;
514
502
        this._totalSecondsToStayOpen = totalSecondsToStayOpen;
515
503
        this._inhibitors = [];
516
 
        this._applicationList.destroy_children();
 
504
        this._applicationList.destroy_all_children();
517
505
        this._type = type;
518
506
 
519
 
        if (!(this._type in DialogContent))
520
 
            throw new DBus.DBusError('org.gnome.Shell.ModalDialog.TypeError',
521
 
                                     "Unknown dialog type requested");
 
507
        if (!(this._type in DialogContent)) {
 
508
            invocation.report_dbus_error('org.gnome.Shell.ModalDialog.TypeError',
 
509
                                         "Unknown dialog type requested");
 
510
            return;
 
511
        }
522
512
 
523
513
        for (let i = 0; i < inhibitorObjectPaths.length; i++) {
524
 
            let inhibitor = new GnomeSession.Inhibitor(inhibitorObjectPaths[i]);
 
514
            let inhibitor = new GnomeSession.Inhibitor(inhibitorObjectPaths[i], Lang.bind(this, function(proxy, error) {
 
515
                this._onInhibitorLoaded(proxy);
 
516
            }));
525
517
 
526
 
            inhibitor.connect('is-loaded',
527
 
                              Lang.bind(this, function() {
528
 
                                  this._onInhibitorLoaded(inhibitor);
529
 
                              }));
530
518
            this._inhibitors.push(inhibitor);
531
519
        }
532
520
 
533
521
        this._updateButtons();
534
522
 
535
 
        if (!this.open(timestamp))
536
 
            throw new DBus.DBusError('org.gnome.Shell.ModalDialog.GrabError',
537
 
                                     "Cannot grab pointer and keyboard");
 
523
        if (!this.open(timestamp)) {
 
524
            invocation.report_dbus_error('org.gnome.Shell.ModalDialog.GrabError',
 
525
                                         "Cannot grab pointer and keyboard");
 
526
            return;
 
527
        }
538
528
 
539
529
        this._updateContent();
540
530
 
541
531
        let signalId = this.connect('opened',
542
532
                                    Lang.bind(this, function() {
543
 
                                        callback();
 
533
                                        invocation.return_value(null);
544
534
                                        this.disconnect(signalId);
545
535
                                    }));
546
536
    }
547
 
};
548
 
DBus.conformExport(EndSessionDialog.prototype, EndSessionDialogIface);
 
537
});