[gnome-shell/wip/reorg: 7/15] loginDialog: move session list to its own file



commit 4de18f2d4b7366fe96d5b4fd863b102334f52008
Author: Ray Strode <rstrode redhat com>
Date:   Fri Jun 14 08:00:06 2013 -0400

    loginDialog: move session list to its own file
    
    The sessionList code has no dependencies on anything else in
    loginDialog.js so move it to its own file.
    
    This is part of the greater reorganization effort to clean up
    the login dialog / unlock dialog situation.

 js/Makefile.am            |    1 +
 js/ui/auth/loginDialog.js |  186 +---------------------------------------
 js/ui/auth/sessionList.js |  208 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 211 insertions(+), 184 deletions(-)
---
diff --git a/js/Makefile.am b/js/Makefile.am
index 0cd30ef..3b41635 100644
--- a/js/Makefile.am
+++ b/js/Makefile.am
@@ -107,6 +107,7 @@ nobase_dist_js_DATA =       \
        ui/auth/loginDialog.js  \
        ui/auth/powerMenu.js    \
        ui/auth/realmd.js       \
+       ui/auth/sessionList.js  \
        ui/auth/unlockDialog.js \
        ui/auth/util.js         \
        ui/components/__init__.js               \
diff --git a/js/ui/auth/loginDialog.js b/js/ui/auth/loginDialog.js
index 4503984..75a88d2 100644
--- a/js/ui/auth/loginDialog.js
+++ b/js/ui/auth/loginDialog.js
@@ -39,6 +39,7 @@ const Batch = imports.misc.batch;
 const Fprint = imports.ui.auth.fingerprint;
 const Main = imports.ui.main;
 const ModalDialog = imports.ui.modalDialog;
+const SessionList = imports.ui.auth.sessionList;
 const Tweener = imports.ui.tweener;
 const UserAvatar = imports.ui.userAvatar;
 const UserWidget = imports.ui.userWidget;
@@ -286,189 +287,6 @@ const UserList = new Lang.Class({
 });
 Signals.addSignalMethods(UserList.prototype);
 
-const SessionListItem = new Lang.Class({
-    Name: 'SessionListItem',
-
-    _init: function(id, name) {
-        this.id = id;
-
-        this.actor = new St.Button({ style_class: 'login-dialog-session-list-item',
-                                     button_mask: St.ButtonMask.ONE | St.ButtonMask.THREE,
-                                     can_focus: true,
-                                     reactive: true,
-                                     x_fill: true,
-                                     x_align: St.Align.START });
-
-        this._box = new St.BoxLayout({ style_class: 'login-dialog-session-list-item-box' });
-
-        this.actor.add_actor(this._box);
-        this.actor.connect('clicked', Lang.bind(this, this._onClicked));
-
-        this._dot = new St.DrawingArea({ style_class: 'login-dialog-session-list-item-dot' });
-        this._dot.connect('repaint', Lang.bind(this, this._onRepaintDot));
-        this._box.add_actor(this._dot);
-        this.setShowDot(false);
-
-        let label = new St.Label({ style_class: 'login-dialog-session-list-item-label',
-                                   text: name });
-        this.actor.label_actor = label;
-
-        this._box.add_actor(label);
-    },
-
-    setShowDot: function(show) {
-        if (show)
-            this._dot.opacity = 255;
-        else
-            this._dot.opacity = 0;
-    },
-
-    _onRepaintDot: function(area) {
-        let cr = area.get_context();
-        let [width, height] = area.get_surface_size();
-        let color = area.get_theme_node().get_foreground_color();
-
-        cr.setSourceRGBA (color.red / 255,
-                          color.green / 255,
-                          color.blue / 255,
-                          color.alpha / 255);
-        cr.arc(width / 2, height / 2, width / 3, 0, 2 * Math.PI);
-        cr.fill();
-        cr.$dispose();
-    },
-
-    _onClicked: function() {
-        this.emit('activate');
-    }
-});
-Signals.addSignalMethods(SessionListItem.prototype);
-
-const SessionList = new Lang.Class({
-    Name: 'SessionList',
-
-    _init: function() {
-        this.actor = new St.Bin();
-
-        this._box = new St.BoxLayout({ style_class: 'login-dialog-session-list',
-                                       vertical: true});
-        this.actor.child = this._box;
-
-        this._button = new St.Button({ style_class: 'login-dialog-session-list-button',
-                                       button_mask: St.ButtonMask.ONE | St.ButtonMask.THREE,
-                                       can_focus: true,
-                                       x_fill: true,
-                                       y_fill: true });
-        let box = new St.BoxLayout();
-        this._button.add_actor(box);
-
-        this._triangle = new St.Label({ style_class: 'login-dialog-session-list-triangle',
-                                        text: '\u25B8' });
-        box.add_actor(this._triangle);
-
-        let label = new St.Label({ style_class: 'login-dialog-session-list-label',
-                                   text: _("Session…") });
-        box.add_actor(label);
-
-        this._button.connect('clicked',
-                             Lang.bind(this, this._onClicked));
-        this._box.add_actor(this._button);
-        this._scrollView = new St.ScrollView({ style_class: 'login-dialog-session-list-scroll-view'});
-        this._scrollView.set_policy(Gtk.PolicyType.NEVER,
-                                    Gtk.PolicyType.AUTOMATIC);
-        this._box.add_actor(this._scrollView);
-        this._itemList = new St.BoxLayout({ style_class: 'login-dialog-session-item-list',
-                                            vertical: true });
-        this._scrollView.add_actor(this._itemList);
-        this._scrollView.hide();
-        this.isOpen = false;
-        this._populate();
-    },
-
-    open: function() {
-        if (this.isOpen)
-            return;
-
-        this._button.add_style_pseudo_class('open');
-        this._scrollView.show();
-        this._triangle.set_text('\u25BE');
-
-        this.isOpen = true;
-    },
-
-    close: function() {
-        if (!this.isOpen)
-            return;
-
-        this._button.remove_style_pseudo_class('open');
-        this._scrollView.hide();
-        this._triangle.set_text('\u25B8');
-
-        this.isOpen = false;
-    },
-
-    _onClicked: function() {
-        if (!this.isOpen)
-            this.open();
-        else
-            this.close();
-    },
-
-    updateSensitivity: function(sensitive) {
-        this._button.reactive = sensitive;
-        this._button.can_focus = sensitive;
-
-        for (let id in this._items)
-            this._items[id].actor.reactive = sensitive;
-    },
-
-    setActiveSession: function(sessionId) {
-         if (sessionId == this._activeSessionId)
-             return;
-
-         if (this._activeSessionId)
-             this._items[this._activeSessionId].setShowDot(false);
-
-         this._items[sessionId].setShowDot(true);
-         this._activeSessionId = sessionId;
-
-         this.emit('session-activated', this._activeSessionId);
-    },
-
-    _populate: function() {
-        this._itemList.destroy_all_children();
-        this._activeSessionId = null;
-        this._items = {};
-
-        let ids = Gdm.get_session_ids();
-        ids.sort();
-
-        if (ids.length <= 1) {
-            this._box.hide();
-            this._button.hide();
-        } else {
-            this._button.show();
-            this._box.show();
-        }
-
-        for (let i = 0; i < ids.length; i++) {
-            let [sessionName, sessionDescription] = Gdm.get_session_name_and_description(ids[i]);
-
-            let item = new SessionListItem(ids[i], sessionName);
-            this._itemList.add_actor(item.actor);
-            this._items[ids[i]] = item;
-
-            if (!this._activeSessionId)
-                this.setActiveSession(ids[i]);
-
-            item.connect('activate',
-                         Lang.bind(this, function() {
-                             this.setActiveSession(item.id);
-                         }));
-        }
-    }
-});
-Signals.addSignalMethods(SessionList.prototype);
-
 const LoginDialog = new Lang.Class({
     Name: 'LoginDialog',
     Extends: ModalDialog.ModalDialog,
@@ -580,7 +398,7 @@ const LoginDialog = new Lang.Class({
 
         this._signInButton = null;
 
-        this._sessionList = new SessionList();
+        this._sessionList = new SessionList.SessionList();
         this._sessionList.connect('session-activated',
                                   Lang.bind(this, function(list, sessionId) {
                                                 this._greeter.call_select_session_sync (sessionId, null);
diff --git a/js/ui/auth/sessionList.js b/js/ui/auth/sessionList.js
new file mode 100644
index 0000000..8ef4ded
--- /dev/null
+++ b/js/ui/auth/sessionList.js
@@ -0,0 +1,208 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+/*
+ * Copyright 2011 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+const Gtk = imports.gi.Gtk;
+const Lang = imports.lang;
+const Signals = imports.signals;
+const St = imports.gi.St;
+const Gdm = imports.gi.Gdm;
+
+const SessionListItem = new Lang.Class({
+    Name: 'SessionListItem',
+
+    _init: function(id, name) {
+        this.id = id;
+
+        this.actor = new St.Button({ style_class: 'login-dialog-session-list-item',
+                                     button_mask: St.ButtonMask.ONE | St.ButtonMask.THREE,
+                                     can_focus: true,
+                                     reactive: true,
+                                     x_fill: true,
+                                     x_align: St.Align.START });
+
+        this._box = new St.BoxLayout({ style_class: 'login-dialog-session-list-item-box' });
+
+        this.actor.add_actor(this._box);
+        this.actor.connect('clicked', Lang.bind(this, this._onClicked));
+
+        this._dot = new St.DrawingArea({ style_class: 'login-dialog-session-list-item-dot' });
+        this._dot.connect('repaint', Lang.bind(this, this._onRepaintDot));
+        this._box.add_actor(this._dot);
+        this.setShowDot(false);
+
+        let label = new St.Label({ style_class: 'login-dialog-session-list-item-label',
+                                   text: name });
+        this.actor.label_actor = label;
+
+        this._box.add_actor(label);
+    },
+
+    setShowDot: function(show) {
+        if (show)
+            this._dot.opacity = 255;
+        else
+            this._dot.opacity = 0;
+    },
+
+    _onRepaintDot: function(area) {
+        let cr = area.get_context();
+        let [width, height] = area.get_surface_size();
+        let color = area.get_theme_node().get_foreground_color();
+
+        cr.setSourceRGBA (color.red / 255,
+                          color.green / 255,
+                          color.blue / 255,
+                          color.alpha / 255);
+        cr.arc(width / 2, height / 2, width / 3, 0, 2 * Math.PI);
+        cr.fill();
+        cr.$dispose();
+    },
+
+    _onClicked: function() {
+        this.emit('activate');
+    }
+});
+Signals.addSignalMethods(SessionListItem.prototype);
+
+const SessionList = new Lang.Class({
+    Name: 'SessionList',
+
+    _init: function() {
+        this.actor = new St.Bin();
+
+        this._box = new St.BoxLayout({ style_class: 'login-dialog-session-list',
+                                       vertical: true});
+        this.actor.child = this._box;
+
+        this._button = new St.Button({ style_class: 'login-dialog-session-list-button',
+                                       button_mask: St.ButtonMask.ONE | St.ButtonMask.THREE,
+                                       can_focus: true,
+                                       x_fill: true,
+                                       y_fill: true });
+        let box = new St.BoxLayout();
+        this._button.add_actor(box);
+
+        this._triangle = new St.Label({ style_class: 'login-dialog-session-list-triangle',
+                                        text: '\u25B8' });
+        box.add_actor(this._triangle);
+
+        let label = new St.Label({ style_class: 'login-dialog-session-list-label',
+                                   text: _("Session…") });
+        box.add_actor(label);
+
+        this._button.connect('clicked',
+                             Lang.bind(this, this._onClicked));
+        this._box.add_actor(this._button);
+        this._scrollView = new St.ScrollView({ style_class: 'login-dialog-session-list-scroll-view'});
+        this._scrollView.set_policy(Gtk.PolicyType.NEVER,
+                                    Gtk.PolicyType.AUTOMATIC);
+        this._box.add_actor(this._scrollView);
+        this._itemList = new St.BoxLayout({ style_class: 'login-dialog-session-item-list',
+                                            vertical: true });
+        this._scrollView.add_actor(this._itemList);
+        this._scrollView.hide();
+        this.isOpen = false;
+        this._populate();
+    },
+
+    open: function() {
+        if (this.isOpen)
+            return;
+
+        this._button.add_style_pseudo_class('open');
+        this._scrollView.show();
+        this._triangle.set_text('\u25BE');
+
+        this.isOpen = true;
+    },
+
+    close: function() {
+        if (!this.isOpen)
+            return;
+
+        this._button.remove_style_pseudo_class('open');
+        this._scrollView.hide();
+        this._triangle.set_text('\u25B8');
+
+        this.isOpen = false;
+    },
+
+    _onClicked: function() {
+        if (!this.isOpen)
+            this.open();
+        else
+            this.close();
+    },
+
+    updateSensitivity: function(sensitive) {
+        this._button.reactive = sensitive;
+        this._button.can_focus = sensitive;
+
+        for (let id in this._items)
+            this._items[id].actor.reactive = sensitive;
+    },
+
+    setActiveSession: function(sessionId) {
+         if (sessionId == this._activeSessionId)
+             return;
+
+         if (this._activeSessionId)
+             this._items[this._activeSessionId].setShowDot(false);
+
+         this._items[sessionId].setShowDot(true);
+         this._activeSessionId = sessionId;
+
+         this.emit('session-activated', this._activeSessionId);
+    },
+
+    _populate: function() {
+        this._itemList.destroy_all_children();
+        this._activeSessionId = null;
+        this._items = {};
+
+        let ids = Gdm.get_session_ids();
+        ids.sort();
+
+        if (ids.length <= 1) {
+            this._box.hide();
+            this._button.hide();
+        } else {
+            this._button.show();
+            this._box.show();
+        }
+
+        for (let i = 0; i < ids.length; i++) {
+            let [sessionName, sessionDescription] = Gdm.get_session_name_and_description(ids[i]);
+
+            let item = new SessionListItem(ids[i], sessionName);
+            this._itemList.add_actor(item.actor);
+            this._items[ids[i]] = item;
+
+            if (!this._activeSessionId)
+                this.setActiveSession(ids[i]);
+
+            item.connect('activate',
+                         Lang.bind(this, function() {
+                             this.setActiveSession(item.id);
+                         }));
+        }
+    }
+});
+Signals.addSignalMethods(SessionList.prototype);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]