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"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { 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 Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main 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 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
|
---|
39 | particular state. The session is controlled by a service called the <em>session</em> <em>manager</em>. The applications participating in the session are
|
---|
40 | called <em>session</em> <em>clients</em>.
|
---|
41 | <p> The session manager issues commands to its clients on behalf of the
|
---|
42 | user. These commands may cause clients to commit unsaved changes (for
|
---|
43 | example by saving open files), to preserve their state for future
|
---|
44 | sessions, or to terminate gracefully. The set of these operations is
|
---|
45 | called <em>session</em> <em>management</em>.
|
---|
46 | <p> In the common case, a session consists of all applications that a
|
---|
47 | user runs on their desktop at a time. Under Unix/X11, however, a
|
---|
48 | session may include applications running on different computers and
|
---|
49 | may 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
|
---|
53 | the user when they want to log out. A system might also perform an
|
---|
54 | automatic shutdown in an emergency situation, for example, if power is
|
---|
55 | about to be lost. Clearly there is a significant difference between
|
---|
56 | these types of shutdown. During the first, the user may want to
|
---|
57 | interact with the application, specifying exactly which files should
|
---|
58 | be saved and which should be discarded. In the latter case, there's no
|
---|
59 | time for interaction. There may not even be a user sitting in front of
|
---|
60 | the 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
|
---|
64 | management for applications yet, i.e. no restoring of previous
|
---|
65 | sessions. They do support graceful logouts where applications
|
---|
66 | have the opportunity to cancel the process after getting confirmation
|
---|
67 | from 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
|
---|
72 | enable your application to take part in the graceful logout process. If
|
---|
73 | you are only targeting the MS-Windows platform, this is all you can
|
---|
74 | and must provide. Ideally, your application should provide a shutdown
|
---|
75 | dialog 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),
|
---|
79 | you must also take care of saving the application's state, and
|
---|
80 | potentially of restoring the state in the next life cycle of the
|
---|
81 | session. This saving is done by reimplementing <a href="qapplication.html#saveState">QApplication::saveState</a>(). All state data you are saving in this
|
---|
82 | function, should be marked with the session identifier <a href="qapplication.html#sessionId">QApplication::sessionId</a>(). This application specific identifier is
|
---|
83 | globally unique, so no clashes will occur. (See <a href="qsessionmanager.html">QSessionManager</a> for
|
---|
84 | information on saving/restoring the state of a particular Qt
|
---|
85 | application.)
|
---|
86 | <p> Restoration is usually done in the application's main()
|
---|
87 | function. Check if <a href="qapplication.html#isSessionRestored">QApplication::isSessionRestored</a>() is <tt>TRUE</tt>. If
|
---|
88 | that's the case, use the session identifier <a href="qapplication.html#sessionId">QApplication::sessionId</a>() again to access your state data and restore
|
---|
89 | the state of the application.
|
---|
90 | <p> <strong>Important:</strong> In order to allow the window manager to
|
---|
91 | restore window attributes such as stacking order or geometry
|
---|
92 | information, you must identify your top level widgets with
|
---|
93 | unique application-wide object names (see <a href="qobject.html#setName">QObject::setName</a>()). When
|
---|
94 | restoring the application, you must ensure that all restored
|
---|
95 | top 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
|
---|
99 | due to the lack of this functionality in the operating system
|
---|
100 | itself. Simply shut the session down and verify that your application
|
---|
101 | behaves as expected. It may be useful to launch another application,
|
---|
102 | usually the integrated development environment, before starting your
|
---|
103 | application. This other application will get the shutdown message
|
---|
104 | afterwards, thus permitting you to cancel the shutdown. Otherwise you
|
---|
105 | would have to log in again after each test run, which is not a problem
|
---|
106 | per se, but is time consuming.
|
---|
107 | <p> On Unix you can either use a desktop environment that supports
|
---|
108 | standard X11R6 session management or, the recommended method, use the
|
---|
109 | session manager reference implementation provided by the X Consortium.
|
---|
110 | This sample manager is called <tt>xsm</tt> and is part of a standard X11R6
|
---|
111 | installation. As always with X11, a useful and informative manual page
|
---|
112 | is provided. Using <tt>xsm</tt> is straightforward (apart from the clumsy
|
---|
113 | Athena-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
|
---|
117 | contains the single line
|
---|
118 | <pre>
|
---|
119 | xterm
|
---|
120 | </pre>
|
---|
121 |
|
---|
122 | This tells <tt>xsm</tt> that the default/failsafe session is just an xterm
|
---|
123 | and nothing else. Otherwise <tt>xsm</tt> would try to invoke lots of
|
---|
124 | clients 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
|
---|
126 | manager window and the xterm will appear. The xterm has a nice
|
---|
127 | property that sets it apart from all the other shells you are
|
---|
128 | currently running: within its shell, the <tt>SESSION_MANAGER</tt>
|
---|
129 | environment variable points to the session manager you just started.
|
---|
130 | <li> Launch your application from the new xterm window. It will connect
|
---|
131 | itself 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
|
---|
133 | start or end session managed clients! Otherwise <tt>xsm</tt> is likely to
|
---|
134 | crash.
|
---|
135 | <li> Use the session manager's <em>Checkpoint</em> and <em>Shutdown</em> buttons
|
---|
136 | with different settings and see how your application behaves. The save
|
---|
137 | type <em>local</em> means that the clients should save their state. It
|
---|
138 | corresponds 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
|
---|
139 | permanent, 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
|
---|
141 | from being a usable session manager on a user's desktop. It is,
|
---|
142 | however, 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 © 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>
|
---|