source: trunk/doc/html/session.html@ 190

Last change on this file since 190 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 8.6 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/session.doc:36 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>Session Management</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Session Management</h1>
33
34
35
36<p> <h2> Definitions
37</h2>
38<a name="1"></a><p> A <em>session</em> is a group of running applications, each of which has a
39particular state. The session is controlled by a service called the <em>session</em> <em>manager</em>. The applications participating in the session are
40called <em>session</em> <em>clients</em>.
41<p> The session manager issues commands to its clients on behalf of the
42user. These commands may cause clients to commit unsaved changes (for
43example by saving open files), to preserve their state for future
44sessions, or to terminate gracefully. The set of these operations is
45called <em>session</em> <em>management</em>.
46<p> In the common case, a session consists of all applications that a
47user runs on their desktop at a time. Under Unix/X11, however, a
48session may include applications running on different computers and
49may span multiple displays.
50<p> <h2> Shutting a session down
51</h2>
52<a name="2"></a><p> A session is shut down by the session manager, usually on behalf of
53the user when they want to log out. A system might also perform an
54automatic shutdown in an emergency situation, for example, if power is
55about to be lost. Clearly there is a significant difference between
56these types of shutdown. During the first, the user may want to
57interact with the application, specifying exactly which files should
58be saved and which should be discarded. In the latter case, there's no
59time for interaction. There may not even be a user sitting in front of
60the machine!
61<p> <h2> Protocols and support on different platforms
62</h2>
63<a name="3"></a><p> On Mac OS X and MS-Windows, there is nothing like complete session
64management for applications yet, i.e. no restoring of previous
65sessions. They do support graceful logouts where applications
66have the opportunity to cancel the process after getting confirmation
67from the user. This is the functionality that corresponds to the <a href="qapplication.html#commitData">QApplication::commitData</a>() method.
68<p> X11 has supported complete session management since X11R6.
69<p> <h2> Getting session management to work with Qt
70</h2>
71<a name="4"></a><p> Start by reimplementing <a href="qapplication.html#commitData">QApplication::commitData</a>() to
72enable your application to take part in the graceful logout process. If
73you are only targeting the MS-Windows platform, this is all you can
74and must provide. Ideally, your application should provide a shutdown
75dialog similar to the following:
76<p> <center><img src="session.png" alt="A typical dialog on shutdown"></center>
77<p> Example code to this dialog can be found in the documentation of <a href="qsessionmanager.html#allowsInteraction">QSessionManager::allowsInteraction</a>().
78<p> For complete session management (only supported on X11R6 at present),
79you must also take care of saving the application's state, and
80potentially of restoring the state in the next life cycle of the
81session. This saving is done by reimplementing <a href="qapplication.html#saveState">QApplication::saveState</a>(). All state data you are saving in this
82function, should be marked with the session identifier <a href="qapplication.html#sessionId">QApplication::sessionId</a>(). This application specific identifier is
83globally unique, so no clashes will occur. (See <a href="qsessionmanager.html">QSessionManager</a> for
84information on saving/restoring the state of a particular Qt
85application.)
86<p> Restoration is usually done in the application's main()
87function. Check if <a href="qapplication.html#isSessionRestored">QApplication::isSessionRestored</a>() is <tt>TRUE</tt>. If
88that's the case, use the session identifier <a href="qapplication.html#sessionId">QApplication::sessionId</a>() again to access your state data and restore
89the state of the application.
90<p> <strong>Important:</strong> In order to allow the window manager to
91restore window attributes such as stacking order or geometry
92information, you must identify your top level widgets with
93unique application-wide object names (see <a href="qobject.html#setName">QObject::setName</a>()). When
94restoring the application, you must ensure that all restored
95top level widgets are given the same unique names they had before.
96<p> <h2> Testing and debugging session management
97</h2>
98<a name="5"></a><p> Session management support on Mac OS X and Windows is fairly limited
99due to the lack of this functionality in the operating system
100itself. Simply shut the session down and verify that your application
101behaves as expected. It may be useful to launch another application,
102usually the integrated development environment, before starting your
103application. This other application will get the shutdown message
104afterwards, thus permitting you to cancel the shutdown. Otherwise you
105would have to log in again after each test run, which is not a problem
106per se, but is time consuming.
107<p> On Unix you can either use a desktop environment that supports
108standard X11R6 session management or, the recommended method, use the
109session manager reference implementation provided by the X Consortium.
110This sample manager is called <tt>xsm</tt> and is part of a standard X11R6
111installation. As always with X11, a useful and informative manual page
112is provided. Using <tt>xsm</tt> is straightforward (apart from the clumsy
113Athena-based user interface). Here's a simple approach:
114<p> <ul>
115<li> Run X11R6.
116<li> Create a dot file <tt>.xsmstartup</tt> in your home directory which
117contains the single line
118<pre>
119xterm
120</pre>
121
122This tells <tt>xsm</tt> that the default/failsafe session is just an xterm
123and nothing else. Otherwise <tt>xsm</tt> would try to invoke lots of
124clients including the windowmanager <tt>twm</tt>, which isn't very helpful.
125<li> Now launch <tt>xsm</tt> from another terminal window. Both a session
126manager window and the xterm will appear. The xterm has a nice
127property that sets it apart from all the other shells you are
128currently running: within its shell, the <tt>SESSION_MANAGER</tt>
129environment variable points to the session manager you just started.
130<li> Launch your application from the new xterm window. It will connect
131itself automatically to the session manager. You can check with the <em>ClientList</em> push button whether the connect was successful.<br>
132<strong>Note:</strong> Never keep the <em>ClientList</em> open when you
133start or end session managed clients! Otherwise <tt>xsm</tt> is likely to
134crash.
135<li> Use the session manager's <em>Checkpoint</em> and <em>Shutdown</em> buttons
136with different settings and see how your application behaves. The save
137type <em>local</em> means that the clients should save their state. It
138corresponds to the <a href="qapplication.html#saveState">QApplication::saveState</a>() function. The <em>global</em> save type asks applications to save their unsaved changes in
139permanent, globally accessible storage. It invokes <a href="qapplication.html#commitData">QApplication::commitData</a>().
140<li> Whenever something crashes, blame <tt>xsm</tt> and not Qt. <tt>xsm</tt> is far
141from being a usable session manager on a user's desktop. It is,
142however, stable and useful enough to serve as testing environment.
143</ul>
144<p>
145<!-- eof -->
146<p><address><hr><div align=center>
147<table width=100% cellspacing=0 border=0><tr>
148<td>Copyright &copy; 2007
149<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
150<td align=right><div align=right>Qt 3.3.8</div>
151</table></div></address></body>
152</html>
Note: See TracBrowser for help on using the repository browser.