[gnome-shell/wip/gdm-shell: 15/16] main: Factor out user session specific bits



commit f28396c4a3736be8a01b9d9f633fcfc694e882aa
Author: Ray Strode <rstrode redhat com>
Date:   Tue Aug 23 21:53:02 2011 -0400

    main: Factor out user session specific bits
    
    The shell has a number of things are are only relevant for
    logged in users (e.g. calendar events, telepathy integration, a
    user menu, etc).
    
    This commit moves those user session specific bits into their
    own functions in preparation for making the shell code ready
    for use at login time.

 js/ui/main.js      |  136 +++++++++++++++++++++++++++++++---------------------
 js/ui/panel.js     |   34 ++++++++-----
 js/ui/popupMenu.js |    4 ++
 3 files changed, 105 insertions(+), 69 deletions(-)
---
diff --git a/js/ui/main.js b/js/ui/main.js
index a417f30..d03570a 100644
--- a/js/ui/main.js
+++ b/js/ui/main.js
@@ -70,6 +70,70 @@ let _cssStylesheet = null;
 
 let background = null;
 
+function _createUserSession() {
+    // Load the calendar server. Note that we are careful about
+    // not loading any events until the user presses the clock
+    global.launch_calendar_server();
+
+    placesManager = new PlaceDisplay.PlacesManager();
+    overview = new Overview.Overview();
+    telepathyClient = new TelepathyClient.Client();
+    automountManager = new AutomountManager.AutomountManager();
+    autorunManager = new AutorunManager.AutorunManager();
+}
+
+function _initRecorder() {
+    let recorderSettings = new Gio.Settings({ schema: 'org.gnome.shell.recorder' });
+
+    global.screen.connect('toggle-recording', function() {
+        if (recorder == null) {
+            recorder = new Shell.Recorder({ stage: global.stage });
+        }
+
+        if (recorder.is_recording()) {
+            recorder.pause();
+        } else {
+            // read the parameters from GSettings always in case they have changed
+            recorder.set_framerate(recorderSettings.get_int('framerate'));
+            recorder.set_filename('shell-%d%u-%c.' + recorderSettings.get_string('file-extension'));
+            let pipeline = recorderSettings.get_string('pipeline');
+
+            if (!pipeline.match(/^\s*$/))
+                recorder.set_pipeline(pipeline);
+            else
+                recorder.set_pipeline(null);
+
+            recorder.record();
+        }
+    });
+}
+
+function _initUserSession() {
+    overview.init();
+
+    _initRecorder();
+
+    global.screen.override_workspace_layout(Meta.ScreenCorner.TOPLEFT, false, -1, 1);
+
+    ExtensionSystem.init();
+    ExtensionSystem.loadExtensions();
+
+    let shellwm = global.window_manager;
+
+    shellwm.takeover_keybinding('panel_run_dialog');
+    shellwm.connect('keybinding::panel_run_dialog', function () {
+       getRunDialog().open();
+    });
+
+    shellwm.takeover_keybinding('panel_main_menu');
+    shellwm.connect('keybinding::panel_main_menu', function () {
+        overview.toggle();
+    });
+
+    global.display.connect('overlay-key', Lang.bind(overview, overview.toggle));
+
+}
+
 function start() {
     // Monkey patch utility functions into the global proxy;
     // This is easier and faster than indirecting down into global
@@ -89,10 +153,6 @@ function start() {
     // back into sync ones.
     DBus.session.flush();
 
-    // Load the calendar server. Note that we are careful about
-    // not loading any events until the user presses the clock
-    global.launch_calendar_server();
-
     // Ensure ShellWindowTracker and ShellAppUsage are initialized; this will
     // also initialize ShellAppSystem first.  ShellAppSystem
     // needs to load all the .desktop files, and ShellWindowTracker
@@ -113,16 +173,6 @@ function start() {
     _defaultCssStylesheet = global.datadir + '/theme/gnome-shell.css';
     loadTheme();
 
-    let shellwm = global.window_manager;
-    shellwm.takeover_keybinding('panel_main_menu');
-    shellwm.connect('keybinding::panel_main_menu', function () {
-        overview.toggle();
-    });
-    shellwm.takeover_keybinding('panel_run_dialog');
-    shellwm.connect('keybinding::panel_run_dialog', function () {
-       getRunDialog().open();
-    });
-
     // Set up stage hierarchy to group all UI actors under one container.
     uiGroup = new Clutter.Group();
     St.set_ui_root(global.stage, uiGroup);
@@ -131,10 +181,12 @@ function start() {
     global.stage.add_actor(uiGroup);
 
     layoutManager = new Layout.LayoutManager();
-    placesManager = new PlaceDisplay.PlacesManager();
     xdndHandler = new XdndHandler.XdndHandler();
     ctrlAltTabManager = new CtrlAltTab.CtrlAltTabManager();
-    overview = new Overview.Overview();
+
+    if (global.session_type == Shell.SessionType.USER)
+        _createUserSession();
+
     magnifier = new Magnifier.Magnifier();
     statusIconDispatcher = new StatusIconDispatcher.StatusIconDispatcher();
     panel = new Panel.Panel();
@@ -142,41 +194,13 @@ function start() {
     messageTray = new MessageTray.MessageTray();
     notificationDaemon = new NotificationDaemon.NotificationDaemon();
     windowAttentionHandler = new WindowAttentionHandler.WindowAttentionHandler();
-    telepathyClient = new TelepathyClient.Client();
-    automountManager = new AutomountManager.AutomountManager();
-    autorunManager = new AutorunManager.AutorunManager();
 
     layoutManager.init();
-    overview.init();
-    statusIconDispatcher.start(messageTray.actor);
-
-    _startDate = new Date();
-
-    let recorderSettings = new Gio.Settings({ schema: 'org.gnome.shell.recorder' });
-
-    global.screen.connect('toggle-recording', function() {
-        if (recorder == null) {
-            recorder = new Shell.Recorder({ stage: global.stage });
-        }
 
-        if (recorder.is_recording()) {
-            recorder.pause();
-        } else {
-            // read the parameters from GSettings always in case they have changed
-            recorder.set_framerate(recorderSettings.get_int('framerate'));
-            recorder.set_filename('shell-%d%u-%c.' + recorderSettings.get_string('file-extension'));
-            let pipeline = recorderSettings.get_string('pipeline');
-
-            if (!pipeline.match(/^\s*$/))
-                recorder.set_pipeline(pipeline);
-            else
-                recorder.set_pipeline(null);
-
-            recorder.record();
-        }
-    });
+    if (global.session_type == Shell.SessionType.USER)
+        _initUserSession();
 
-    global.screen.override_workspace_layout(Meta.ScreenCorner.TOPLEFT, false, -1, 1);
+    statusIconDispatcher.start(messageTray.actor);
 
     // Provide the bus object for gnome-session to
     // initiate logouts.
@@ -185,15 +209,11 @@ function start() {
     // Attempt to become a PolicyKit authentication agent
     PolkitAuthenticationAgent.init()
 
-    ExtensionSystem.init();
-    ExtensionSystem.loadExtensions();
+    _startDate = new Date();
 
     panel.startStatusArea();
     panel.startupAnimation();
 
-    if (overview)
-        global.display.connect('overlay-key', Lang.bind(overview, overview.toggle));
-
     global.stage.connect('captured-event', _globalKeyPressHandler);
 
     _log('info', 'loaded at ' + _startDate);
@@ -554,6 +574,15 @@ function _globalKeyPressHandler(actor, event) {
         return true;
     }
 
+    if (action == Meta.KeyBindingAction.SWITCH_PANELS) {
+        ctrlAltTabManager.popup(modifierState & Clutter.ModifierType.SHIFT_MASK);
+        return true;
+    }
+
+    // None of the other bindings are relevant outside of the user's session
+    if (global.session_type != Shell.SessionType.USER)
+        return false;
+
     switch (action) {
         // left/right would effectively act as synonyms for up/down if we enabled them;
         // but that could be considered confusing; we also disable them in the main view.
@@ -578,9 +607,6 @@ function _globalKeyPressHandler(actor, event) {
             if (overview)
                 overview.hide();
             return true;
-        case Meta.KeyBindingAction.SWITCH_PANELS:
-            ctrlAltTabManager.popup(modifierState & Clutter.ModifierType.SHIFT_MASK);
-            return true;
     }
 
     return false;
diff --git a/js/ui/panel.js b/js/ui/panel.js
index 012f9dc..95358e3 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -844,7 +844,10 @@ Panel.prototype = {
         }
 
         /* center */
-        this._dateMenu = new DateMenu.DateMenuButton();
+        if (global.session_type == Shell.SessionType.USER)
+            this._dateMenu = new DateMenu.DateMenuButton({ showEvents: true });
+        else
+            this._dateMenu = new DateMenu.DateMenuButton({ showEvents: false });
         this._centerBox.add(this._dateMenu.actor, { y_fill: true });
         this._menus.addMenu(this._dateMenu.menu);
 
@@ -860,18 +863,20 @@ Panel.prototype = {
         this._rightBox.add(this._trayBox);
         this._rightBox.add(this._statusBox);
 
-        this._userMenu = new StatusMenu.StatusMenuButton();
-        this._userMenu.actor.name = 'panelStatus';
-        this._rightBox.add(this._userMenu.actor);
-
-        // Synchronize the buttons pseudo classes with its corner
-        this._userMenu.actor.connect('style-changed', Lang.bind(this,
-            function(actor) {
-                let rtl = actor.get_direction() == St.TextDirection.RTL;
-                let corner = rtl ? this._leftCorner : this._rightCorner;
-                let pseudoClass = actor.get_style_pseudo_class();
-                corner.actor.set_style_pseudo_class(pseudoClass);
-            }));
+        if (global.session_type == Shell.SessionType.USER) {
+            this._userMenu = new StatusMenu.StatusMenuButton();
+            this._userMenu.actor.name = 'panelStatus';
+            this._rightBox.add(this._userMenu.actor);
+
+            // Synchronize the buttons pseudo classes with its corner
+            this._userMenu.actor.connect('style-changed', Lang.bind(this,
+                function(actor) {
+                    let rtl = actor.get_direction() == St.TextDirection.RTL;
+                    let corner = rtl ? this._leftCorner : this._rightCorner;
+                    let pseudoClass = actor.get_style_pseudo_class();
+                    corner.actor.set_style_pseudo_class(pseudoClass);
+                }));
+        }
 
         Main.statusIconDispatcher.connect('status-icon-added', Lang.bind(this, this._onTrayIconAdded));
         Main.statusIconDispatcher.connect('status-icon-removed', Lang.bind(this, this._onTrayIconRemoved));
@@ -976,7 +981,8 @@ Panel.prototype = {
 
         // PopupMenuManager depends on menus being added in order for
         // keyboard navigation
-        this._menus.addMenu(this._userMenu.menu);
+        if (this._userMenu)
+            this._menus.addMenu(this._userMenu.menu);
     },
 
     startupAnimation: function() {
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index d06220b..21c8401 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -813,6 +813,10 @@ PopupMenuBase.prototype = {
     },
 
     addSettingsAction: function(title, desktopFile) {
+        // Don't allow user settings to get edited unless we're in a user session
+        if (global.session_type != Shell.SessionType.USER)
+            return null;
+
         let app = Shell.AppSystem.get_default().lookup_setting(desktopFile);
 
         if (app) {



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