endSessionDialog: Convert to the standard _sync pattern

... for starting and stopping the timer. This helps clean up the
state transitions in the code when caring about multiple things.

https://bugzilla.gnome.org/show_bug.cgi?id=706612
This commit is contained in:
Jasper St. Pierre 2013-08-22 14:48:28 -04:00
parent 2e65c852c3
commit aaaf25d578

View File

@ -242,11 +242,8 @@ const EndSessionDialog = new Lang.Class({
this.connect('opened', this.connect('opened',
Lang.bind(this, this._onOpened)); Lang.bind(this, this._onOpened));
this._userLoadedId = this._user.connect('notify::is_loaded', this._userLoadedId = this._user.connect('notify::is_loaded', Lang.bind(this, this._sync));
Lang.bind(this, this._updateContent)); this._userChangedId = this._user.connect('changed', Lang.bind(this, this._sync));
this._userChangedId = this._user.connect('changed',
Lang.bind(this, this._updateContent));
let mainContentLayout = new St.BoxLayout({ vertical: false }); let mainContentLayout = new St.BoxLayout({ vertical: false });
this.contentLayout.add(mainContentLayout, this.contentLayout.add(mainContentLayout,
@ -314,18 +311,17 @@ const EndSessionDialog = new Lang.Class({
return (this._inhibitors.length > 0) || (this._sessions.length > 0); return (this._inhibitors.length > 0) || (this._sessions.length > 0);
}, },
_updateDescription: function() { _sync: function() {
if (this.state != ModalDialog.State.OPENING && let open = (this.state == ModalDialog.State.OPENING || this.state == ModalDialog.State.OPENED);
this.state != ModalDialog.State.OPENED) if (!open)
return; return;
let dialogContent = DialogContent[this._type]; let dialogContent = DialogContent[this._type];
let subject = dialogContent.subject; let subject = dialogContent.subject;
let description;
let description;
if (this._hasInhibitors()) { if (this._hasInhibitors()) {
this._stopTimer();
description = dialogContent.inhibitedDescription; description = dialogContent.inhibitedDescription;
} else if (this._secondsLeft > 0) { } else if (this._secondsLeft > 0) {
let displayTime = _roundSecondsToInterval(this._totalSecondsToStayOpen, let displayTime = _roundSecondsToInterval(this._totalSecondsToStayOpen,
@ -352,14 +348,8 @@ const EndSessionDialog = new Lang.Class({
description = dialogContent.endDescription; description = dialogContent.endDescription;
} }
_setLabelText(this._subjectLabel, subject);
_setLabelText(this._descriptionLabel, description); _setLabelText(this._descriptionLabel, description);
}, _setLabelText(this._subjectLabel, subject);
_updateContent: function() {
if (this.state != ModalDialog.State.OPENING &&
this.state != ModalDialog.State.OPENED)
return;
let dialogContent = DialogContent[this._type]; let dialogContent = DialogContent[this._type];
if (dialogContent.iconName) { if (dialogContent.iconName) {
@ -374,7 +364,10 @@ const EndSessionDialog = new Lang.Class({
avatarWidget.update(); avatarWidget.update();
} }
this._updateDescription(); if (this._hasInhibitors())
this._stopTimer();
else
this._startTimer();
}, },
_updateButtons: function() { _updateButtons: function() {
@ -420,14 +413,12 @@ const EndSessionDialog = new Lang.Class({
}, },
_onOpened: function() { _onOpened: function() {
if (!this._hasInhibitors()) this._sync();
this._startTimer();
}, },
_startTimer: function() { _startTimer: function() {
let startTime = GLib.get_monotonic_time(); let startTime = GLib.get_monotonic_time();
this._secondsLeft = this._totalSecondsToStayOpen; this._secondsLeft = this._totalSecondsToStayOpen;
this._updateDescription();
this._timerId = Mainloop.timeout_add_seconds(1, Lang.bind(this, this._timerId = Mainloop.timeout_add_seconds(1, Lang.bind(this,
function() { function() {
@ -436,7 +427,7 @@ const EndSessionDialog = new Lang.Class({
this._secondsLeft = this._totalSecondsToStayOpen - secondsElapsed; this._secondsLeft = this._totalSecondsToStayOpen - secondsElapsed;
if (this._secondsLeft > 0) { if (this._secondsLeft > 0) {
this._updateDescription(); this._sync();
return true; return true;
} }
@ -469,13 +460,12 @@ const EndSessionDialog = new Lang.Class({
let [reason] = inhibitor.GetReasonSync(); let [reason] = inhibitor.GetReasonSync();
let item = new ListItem(app.create_icon_texture(_ITEM_ICON_SIZE), app.get_name(), reason); let item = new ListItem(app.create_icon_texture(_ITEM_ICON_SIZE), app.get_name(), reason);
this._applicationList.add(item.actor, { x_fill: true }); this._applicationList.add(item.actor, { x_fill: true });
this._stopTimer();
} else { } else {
// inhibiting app is a service, not an application // inhibiting app is a service, not an application
this._inhibitors.splice(this._inhibitors.indexOf(inhibitor), 1); this._inhibitors.splice(this._inhibitors.indexOf(inhibitor), 1);
} }
this._updateContent(); this._sync();
}, },
_loadSessions: function() { _loadSessions: function() {
@ -526,8 +516,7 @@ const EndSessionDialog = new Lang.Class({
break; break;
} }
if (n > 0) this._sync();
this._stopTimer();
})); }));
}, },
@ -562,7 +551,7 @@ const EndSessionDialog = new Lang.Class({
return; return;
} }
this._updateContent(); this._sync();
let signalId = this.connect('opened', let signalId = this.connect('opened',
Lang.bind(this, function() { Lang.bind(this, function() {