ad7cac
From 10a47a23aab29d805a4e87ef181d4141d5500707 Mon Sep 17 00:00:00 2001
12ec7d
From: Ray Strode <rstrode@redhat.com>
12ec7d
Date: Tue, 19 Apr 2016 13:12:46 -0400
12ec7d
Subject: [PATCH] loginDialog: allow timed login with disabled user list
12ec7d
ad7cac
At the moment the timed login feature is implemented in the user list.
ad7cac
If there's no user list, we don't show the indicator anywhere and
ad7cac
don't proceed with timed login.
ad7cac
ad7cac
This commit allows timed login to work when the user list is disabled.
ad7cac
It accomplishes this by putting the timed login indicator on the
ad7cac
auth prompt, in that scenario.
12ec7d
---
ad7cac
 data/theme/gnome-shell-sass/_common.scss |  4 +++
ad7cac
 js/gdm/authPrompt.js                     | 40 ++++++++++++++++++++++++
ad7cac
 js/gdm/loginDialog.js                    | 28 +++++++++++++++--
ad7cac
 3 files changed, 70 insertions(+), 2 deletions(-)
12ec7d
ad7cac
diff --git a/data/theme/gnome-shell-sass/_common.scss b/data/theme/gnome-shell-sass/_common.scss
ad7cac
index 2f05098df..4e82ef58b 100644
ad7cac
--- a/data/theme/gnome-shell-sass/_common.scss
ad7cac
+++ b/data/theme/gnome-shell-sass/_common.scss
ad7cac
@@ -1825,6 +1825,10 @@ StScrollBar {
ad7cac
       padding-bottom: 12px;
ad7cac
       spacing: 8px;
ad7cac
       width: 23em;
ad7cac
+      .login-dialog-timed-login-indicator {
ad7cac
+          height: 2px;
ad7cac
+          background-color: darken($fg_color,40%);
ad7cac
+      }
ad7cac
   }
ad7cac
 
ad7cac
   .login-dialog-prompt-label {
12ec7d
diff --git a/js/gdm/authPrompt.js b/js/gdm/authPrompt.js
ad7cac
index 89cef4d5d..e44281117 100644
12ec7d
--- a/js/gdm/authPrompt.js
12ec7d
+++ b/js/gdm/authPrompt.js
12ec7d
@@ -2,6 +2,7 @@
12ec7d
 
12ec7d
 const Clutter = imports.gi.Clutter;
12ec7d
 const Gio = imports.gi.Gio;
12ec7d
+const GLib = imports.gi.GLib;
12ec7d
 const Lang = imports.lang;
12ec7d
 const Pango = imports.gi.Pango;
12ec7d
 const Signals = imports.signals;
ad7cac
@@ -117,6 +118,11 @@ var AuthPrompt = new Lang.Class({
12ec7d
 
12ec7d
         this._entry.grab_key_focus();
12ec7d
 
12ec7d
+        this._timedLoginIndicator = new St.Bin({ style_class: 'login-dialog-timed-login-indicator',
12ec7d
+                                                 scale_x: 0 });
12ec7d
+
12ec7d
+        this.actor.add(this._timedLoginIndicator);
12ec7d
+
12ec7d
         this._message = new St.Label({ opacity: 0,
12ec7d
                                        styleClass: 'login-dialog-message' });
12ec7d
         this._message.clutter_text.line_wrap = true;
ad7cac
@@ -142,6 +148,40 @@ var AuthPrompt = new Lang.Class({
12ec7d
         this._defaultButtonWell.add_child(this._spinner.actor);
12ec7d
     },
12ec7d
 
ad7cac
+    showTimedLoginIndicator(time) {
12ec7d
+        let hold = new Batch.Hold();
12ec7d
+
12ec7d
+        this.hideTimedLoginIndicator();
12ec7d
+
12ec7d
+        let startTime = GLib.get_monotonic_time();
12ec7d
+
ad7cac
+        this._timedLoginTimeoutId = GLib.timeout_add (GLib.PRIORITY_DEFAULT, 33,
ad7cac
+            () => {
ad7cac
+                let currentTime = GLib.get_monotonic_time();
ad7cac
+                let elapsedTime = (currentTime - startTime) / GLib.USEC_PER_SEC;
ad7cac
+                this._timedLoginIndicator.scale_x = elapsedTime / time;
ad7cac
+                if (elapsedTime >= time) {
ad7cac
+                    this._timedLoginTimeoutId = 0;
ad7cac
+                    hold.release();
ad7cac
+                    return GLib.SOURCE_REMOVE;
ad7cac
+                }
ad7cac
+
ad7cac
+                return GLib.SOURCE_CONTINUE;
ad7cac
+            });
12ec7d
+
12ec7d
+        GLib.Source.set_name_by_id(this._timedLoginTimeoutId, '[gnome-shell] this._timedLoginTimeoutId');
12ec7d
+
12ec7d
+        return hold;
12ec7d
+    },
12ec7d
+
ad7cac
+    hideTimedLoginIndicator() {
12ec7d
+        if (this._timedLoginTimeoutId) {
12ec7d
+            GLib.source_remove(this._timedLoginTimeoutId);
12ec7d
+            this._timedLoginTimeoutId = 0;
12ec7d
+        }
12ec7d
+        this._timedLoginIndicator.scale_x = 0.;
12ec7d
+    },
12ec7d
+
ad7cac
     _onDestroy() {
12ec7d
         if (this._preemptiveAnswerWatchId) {
12ec7d
             this._idleMonitor.remove_watch(this._preemptiveAnswerWatchId);
12ec7d
diff --git a/js/gdm/loginDialog.js b/js/gdm/loginDialog.js
ad7cac
index 4a93545af..65d9edf1a 100644
12ec7d
--- a/js/gdm/loginDialog.js
12ec7d
+++ b/js/gdm/loginDialog.js
ad7cac
@@ -738,6 +738,9 @@ var LoginDialog = new Lang.Class({
12ec7d
 
12ec7d
             if (this._authPrompt.verificationStatus == AuthPrompt.AuthPromptStatus.NOT_VERIFYING)
12ec7d
                 this._authPrompt.reset();
12ec7d
+
12ec7d
+            if (this._disableUserList && this._timedLoginUserListHold)
12ec7d
+                this._timedLoginUserListHold.release();
12ec7d
         }
12ec7d
     },
12ec7d
 
ad7cac
@@ -1019,17 +1022,33 @@ var LoginDialog = new Lang.Class({
12ec7d
     },
12ec7d
 
ad7cac
     _startTimedLogin(userName, delay) {
12ec7d
+        this._timedLoginUserName = userName;
12ec7d
         this._timedLoginItem = null;
12ec7d
         this._timedLoginDelay = delay;
12ec7d
         this._timedLoginAnimationTime = delay;
ad7cac
 
ad7cac
-        let tasks = [() => this._waitForItemForUser(userName),
ad7cac
+        let tasks = [() => {
12ec7d
+                         if (this._disableUserList)
12ec7d
+                             return;
12ec7d
+
12ec7d
+                         this._timedLoginUserListHold = this._waitForItemForUser(userName);
12ec7d
+
12ec7d
+                         return this._timedLoginUserListHold;
ad7cac
+                     },
12ec7d
 
ad7cac
                      () => {
12ec7d
+                         this._timedLoginUserListHold = null;
12ec7d
+
12ec7d
+                         if (this._disableUserList)
12ec7d
+                             return;
ad7cac
+
12ec7d
                          this._timedLoginItem = this._userList.getItemFromUserName(userName);
12ec7d
                      },
12ec7d
 
ad7cac
                      () => {
12ec7d
+                         if (this._disableUserList)
12ec7d
+                             return;
12ec7d
+
12ec7d
                          // If we're just starting out, start on the right
12ec7d
                          // item.
12ec7d
                          if (!this._userManager.is_loaded) {
ad7cac
@@ -1040,6 +1059,9 @@ var LoginDialog = new Lang.Class({
12ec7d
                      this._blockTimedLoginUntilIdle,
12ec7d
 
ad7cac
                      () => {
12ec7d
+                         if (this._disableUserList)
12ec7d
+                             return;
12ec7d
+
12ec7d
                          this._userList.scrollToItem(this._timedLoginItem);
12ec7d
                      },
12ec7d
 
ad7cac
@@ -1064,7 +1086,9 @@ var LoginDialog = new Lang.Class({
12ec7d
         if (this._timedLoginItem)
12ec7d
             this._timedLoginItem.hideTimedLoginIndicator();
12ec7d
 
12ec7d
-        let userName = this._timedLoginItem.user.get_user_name();
12ec7d
+        this._authPrompt.hideTimedLoginIndicator();
12ec7d
+
12ec7d
+        let userName = this._timedLoginUserName;
12ec7d
 
12ec7d
         if (userName)
12ec7d
             this._startTimedLogin(userName, this._timedLoginDelay);
12ec7d
-- 
ad7cac
2.17.1
12ec7d