source: trunk/doc/html/qsessionmanager.html@ 208

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

reference documentation added

File size: 18.4 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/src/kernel/qapplication.cpp:4067 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QSessionManager Class</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>QSessionManager Class Reference</h1>
33
34<p>The QSessionManager class provides access to the session manager.
35<a href="#details">More...</a>
36<p><tt>#include &lt;<a href="qsessionmanager-h.html">qsessionmanager.h</a>&gt;</tt>
37<p>Inherits <a href="qobject.html">QObject</a>.
38<p><a href="qsessionmanager-members.html">List of all member functions.</a>
39<h2>Public Members</h2>
40<ul>
41<li class=fn>QString <a href="#sessionId"><b>sessionId</b></a> () const</li>
42<li class=fn>QString <a href="#sessionKey"><b>sessionKey</b></a> () const</li>
43<li class=fn>void * <a href="#handle"><b>handle</b></a> () const</li>
44<li class=fn>bool <a href="#allowsInteraction"><b>allowsInteraction</b></a> ()</li>
45<li class=fn>bool <a href="#allowsErrorInteraction"><b>allowsErrorInteraction</b></a> ()</li>
46<li class=fn>void <a href="#release"><b>release</b></a> ()</li>
47<li class=fn>void <a href="#cancel"><b>cancel</b></a> ()</li>
48<li class=fn>enum <a href="#RestartHint-enum"><b>RestartHint</b></a> { RestartIfRunning, RestartAnyway, RestartImmediately, RestartNever }</li>
49<li class=fn>void <a href="#setRestartHint"><b>setRestartHint</b></a> ( RestartHint&nbsp;hint )</li>
50<li class=fn>RestartHint <a href="#restartHint"><b>restartHint</b></a> () const</li>
51<li class=fn>void <a href="#setRestartCommand"><b>setRestartCommand</b></a> ( const&nbsp;QStringList&nbsp;&amp;&nbsp;command )</li>
52<li class=fn>QStringList <a href="#restartCommand"><b>restartCommand</b></a> () const</li>
53<li class=fn>void <a href="#setDiscardCommand"><b>setDiscardCommand</b></a> ( const QStringList &amp; )</li>
54<li class=fn>QStringList <a href="#discardCommand"><b>discardCommand</b></a> () const</li>
55<li class=fn>void <a href="#setManagerProperty-2"><b>setManagerProperty</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name, const&nbsp;QString&nbsp;&amp;&nbsp;value )</li>
56<li class=fn>void <a href="#setManagerProperty"><b>setManagerProperty</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name, const&nbsp;QStringList&nbsp;&amp;&nbsp;value )</li>
57<li class=fn>bool <a href="#isPhase2"><b>isPhase2</b></a> () const</li>
58<li class=fn>void <a href="#requestPhase2"><b>requestPhase2</b></a> ()</li>
59</ul>
60<hr><a name="details"></a><h2>Detailed Description</h2>
61
62
63The QSessionManager class provides access to the session manager.
64<p>
65
66<p> The session manager is responsible for session management, most
67importantly for interruption and resumption. A "session" is a kind
68of record of the state of the system, e.g. which applications were
69run at start up and which applications are currently running. The
70session manager is used to save the session, e.g. when the machine
71is shut down; and to restore a session, e.g. when the machine is
72started up. Use <a href="qsettings.html">QSettings</a> to save and restore an individual
73application's settings, e.g. window positions, recently used files,
74etc.
75<p> QSessionManager provides an interface between the application and
76the session manager so that the program can work well with the
77session manager. In Qt, session management requests for action
78are handled by the two virtual functions <a href="qapplication.html#commitData">QApplication::commitData</a>()
79and <a href="qapplication.html#saveState">QApplication::saveState</a>(). Both provide a reference to
80a session manager object as argument, to allow the application
81to communicate with the session manager.
82<p> During a session management action (i.e. within commitData() and
83saveState()), no user interaction is possible <em>unless</em> the
84application got explicit permission from the session manager. You
85ask for permission by calling <a href="#allowsInteraction">allowsInteraction</a>() or, if it's really
86urgent, <a href="#allowsErrorInteraction">allowsErrorInteraction</a>(). Qt does not enforce this, but the
87session manager may.
88<p> You can try to abort the shutdown process by calling <a href="#cancel">cancel</a>(). The
89default commitData() function does this if some top-level window
90rejected its closeEvent().
91<p> For sophisticated session managers provided on Unix/X11, QSessionManager
92offers further possibilites to fine-tune an application's session
93management behavior: <a href="#setRestartCommand">setRestartCommand</a>(), <a href="#setDiscardCommand">setDiscardCommand</a>(),
94<a href="#setRestartHint">setRestartHint</a>(), <a href="qobject.html#setProperty">setProperty</a>(), <a href="#requestPhase2">requestPhase2</a>(). See the respective
95function descriptions for further details.
96<p>See also <a href="application.html">Main Window and Related Classes</a> and <a href="environment.html">Environment Classes</a>.
97
98<hr><h2>Member Type Documentation</h2>
99<h3 class=fn><a name="RestartHint-enum"></a>QSessionManager::RestartHint</h3>
100<p> This enum type defines the circumstances under which this
101application wants to be restarted by the session manager. The
102current values are
103<ul>
104<li><tt>QSessionManager::RestartIfRunning</tt> - if the application is still running when
105the session is shut down, it wants to be restarted at the start of
106the next session.
107<li><tt>QSessionManager::RestartAnyway</tt> - the application wants to be started at the
108start of the next session, no matter what. (This is useful for
109utilities that run just after startup and then quit.)
110<li><tt>QSessionManager::RestartImmediately</tt> - the application wants to be started
111immediately whenever it is not running.
112<li><tt>QSessionManager::RestartNever</tt> - the application does not want to be restarted
113automatically.
114</ul><p> The default hint is <a href="#RestartHint-enum">RestartIfRunning</a>.
115
116<hr><h2>Member Function Documentation</h2>
117<h3 class=fn>bool <a name="allowsErrorInteraction"></a>QSessionManager::allowsErrorInteraction ()
118</h3>
119
120<p> This is similar to <a href="#allowsInteraction">allowsInteraction</a>(), but also tells the session
121manager that an error occurred. Session managers may give error
122interaction request higher priority, which means that it is more likely
123that an error interaction is permitted. However, you are still not
124guaranteed that the session manager will allow interaction.
125<p> <p>See also <a href="#allowsInteraction">allowsInteraction</a>(), <a href="#release">release</a>(), and <a href="#cancel">cancel</a>().
126
127<h3 class=fn>bool <a name="allowsInteraction"></a>QSessionManager::allowsInteraction ()
128</h3>
129
130<p> Asks the session manager for permission to interact with the
131user. Returns TRUE if interaction is permitted; otherwise
132returns FALSE.
133<p> The rationale behind this mechanism is to make it possible to
134synchronize user interaction during a shutdown. Advanced session
135managers may ask all applications simultaneously to commit their
136data, resulting in a much faster shutdown.
137<p> When the interaction is completed we strongly recommend releasing the
138user interaction semaphore with a call to <a href="#release">release</a>(). This way, other
139applications may get the chance to interact with the user while your
140application is still busy saving data. (The semaphore is implicitly
141released when the application exits.)
142<p> If the user decides to cancel the shutdown process during the
143interaction phase, you must tell the session manager that this has
144happened by calling <a href="#cancel">cancel</a>().
145<p> Here's an example of how an application's <a href="qapplication.html#commitData">QApplication::commitData</a>()
146might be implemented:
147<p> <pre>
148void MyApplication::commitData( QSessionManager&amp; sm ) {
149 if ( sm.<a href="#allowsInteraction">allowsInteraction</a>() ) {
150 switch ( QMessageBox::<a href="qmessagebox.html#warning">warning</a>(
151 yourMainWindow,
152 <a href="qobject.html#tr">tr</a>("Application Name"),
153 <a href="qobject.html#tr">tr</a>("Save changes to document Foo?"),
154 <a href="qobject.html#tr">tr</a>("&amp;Yes"),
155 <a href="qobject.html#tr">tr</a>("&amp;No"),
156 <a href="qobject.html#tr">tr</a>("Cancel"),
157 0, 2) ) {
158 case 0: // yes
159 sm.<a href="#release">release</a>();
160 // save document here; if saving fails, call sm.<a href="#cancel">cancel</a>()
161 break;
162 case 1: // continue without saving
163 break;
164 default: // cancel
165 sm.<a href="#cancel">cancel</a>();
166 break;
167 }
168 } else {
169 // we did not get permission to interact, then
170 // do something reasonable instead.
171 }
172}
173</pre>
174
175<p> If an error occurred within the application while saving its data,
176you may want to try <a href="#allowsErrorInteraction">allowsErrorInteraction</a>() instead.
177<p> <p>See also <a href="qapplication.html#commitData">QApplication::commitData</a>(), <a href="#release">release</a>(), and <a href="#cancel">cancel</a>().
178
179<h3 class=fn>void <a name="cancel"></a>QSessionManager::cancel ()
180</h3>
181
182<p> Tells the session manager to cancel the shutdown process. Applications
183should not call this function without first asking the user.
184<p> <p>See also <a href="#allowsInteraction">allowsInteraction</a>() and <a href="#allowsErrorInteraction">allowsErrorInteraction</a>().
185
186<p>
187<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="discardCommand"></a>QSessionManager::discardCommand () const
188</h3>
189
190<p> Returns the currently set discard command.
191<p> Note that if you want to iterate over the list, you should
192iterate over a copy, e.g.
193<pre>
194 <a href="qstringlist.html">QStringList</a> list = mySession.discardCommand();
195 QStringList::Iterator it = list.<a href="qvaluelist.html#begin">begin</a>();
196 while( it != list.<a href="qvaluelist.html#end">end</a>() ) {
197 myProcessing( *it );
198 ++it;
199 }
200 </pre>
201
202<p> <p>See also <a href="#setDiscardCommand">setDiscardCommand</a>(), <a href="#restartCommand">restartCommand</a>(), and <a href="#setRestartCommand">setRestartCommand</a>().
203
204<h3 class=fn>void * <a name="handle"></a>QSessionManager::handle () const
205</h3>
206
207<p> X11 only: returns a handle to the current <tt>SmcConnection</tt>.
208
209<h3 class=fn>bool <a name="isPhase2"></a>QSessionManager::isPhase2 () const
210</h3>
211
212<p> Returns TRUE if the session manager is currently performing a second
213session management phase; otherwise returns FALSE.
214<p> <p>See also <a href="#requestPhase2">requestPhase2</a>().
215
216<h3 class=fn>void <a name="release"></a>QSessionManager::release ()
217</h3>
218
219<p> Releases the session manager's interaction semaphore after an
220interaction phase.
221<p> <p>See also <a href="#allowsInteraction">allowsInteraction</a>() and <a href="#allowsErrorInteraction">allowsErrorInteraction</a>().
222
223<h3 class=fn>void <a name="requestPhase2"></a>QSessionManager::requestPhase2 ()
224</h3>
225
226<p> Requests a second session management phase for the application. The
227application may then return immediately from the
228<a href="qapplication.html#commitData">QApplication::commitData</a>() or <a href="qapplication.html#saveState">QApplication::saveState</a>() function,
229and they will be called again once most or all other applications have
230finished their session management.
231<p> The two phases are useful for applications such as the X11 window manager
232that need to store information about another application's windows
233and therefore have to wait until these applications have completed their
234respective session management tasks.
235<p> Note that if another application has requested a second phase it
236may get called before, simultaneously with, or after your
237application's second phase.
238<p> <p>See also <a href="#isPhase2">isPhase2</a>().
239
240<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="restartCommand"></a>QSessionManager::restartCommand () const
241</h3>
242
243<p> Returns the currently set restart command.
244<p> Note that if you want to iterate over the list, you should
245iterate over a copy, e.g.
246<pre>
247 <a href="qstringlist.html">QStringList</a> list = mySession.restartCommand();
248 QStringList::Iterator it = list.<a href="qvaluelist.html#begin">begin</a>();
249 while( it != list.<a href="qvaluelist.html#end">end</a>() ) {
250 myProcessing( *it );
251 ++it;
252 }
253 </pre>
254
255<p> <p>See also <a href="#setRestartCommand">setRestartCommand</a>() and <a href="#restartHint">restartHint</a>().
256
257<h3 class=fn><a href="qsessionmanager.html#RestartHint-enum">RestartHint</a> <a name="restartHint"></a>QSessionManager::restartHint () const
258</h3>
259
260<p> Returns the application's current restart hint. The default is
261<a href="#RestartHint-enum">RestartIfRunning</a>.
262<p> <p>See also <a href="#setRestartHint">setRestartHint</a>().
263
264<h3 class=fn><a href="qstring.html">QString</a> <a name="sessionId"></a>QSessionManager::sessionId () const
265</h3>
266
267<p> Returns the identifier of the current session.
268<p> If the application has been restored from an earlier session, this
269identifier is the same as it was in that earlier session.
270<p> <p>See also <a href="#sessionKey">sessionKey</a>() and <a href="qapplication.html#sessionId">QApplication::sessionId</a>().
271
272<h3 class=fn><a href="qstring.html">QString</a> <a name="sessionKey"></a>QSessionManager::sessionKey () const
273</h3>
274
275<p> Returns the session key in the current session.
276<p> If the application has been restored from an earlier session, this
277key is the same as it was when the previous session ended.
278<p> The session key changes with every call of commitData() or
279saveState().
280<p> <p>See also <a href="#sessionId">sessionId</a>() and <a href="qapplication.html#sessionKey">QApplication::sessionKey</a>().
281
282<h3 class=fn>void <a name="setDiscardCommand"></a>QSessionManager::setDiscardCommand ( const&nbsp;<a href="qstringlist.html">QStringList</a>&nbsp;&amp; )
283</h3>
284
285<p> <p>See also <a href="#discardCommand">discardCommand</a>() and <a href="#setRestartCommand">setRestartCommand</a>().
286
287<h3 class=fn>void <a name="setManagerProperty"></a>QSessionManager::setManagerProperty ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name, const&nbsp;<a href="qstringlist.html">QStringList</a>&nbsp;&amp;&nbsp;value )
288</h3>
289
290<p> Low-level write access to the application's identification and state
291record are kept in the session manager.
292<p> The property called <em>name</em> has its value set to the string list <em>value</em>.
293
294<h3 class=fn>void <a name="setManagerProperty-2"></a>QSessionManager::setManagerProperty ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;value )
295</h3>
296This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
297<p> Low-level write access to the application's identification and state
298records are kept in the session manager.
299<p> The property called <em>name</em> has its value set to the string <em>value</em>.
300
301<h3 class=fn>void <a name="setRestartCommand"></a>QSessionManager::setRestartCommand ( const&nbsp;<a href="qstringlist.html">QStringList</a>&nbsp;&amp;&nbsp;command )
302</h3>
303
304<p> If the session manager is capable of restoring sessions it will
305execute <em>command</em> in order to restore the application. The command
306defaults to
307<p> <pre>
308 appname -session id
309 </pre>
310
311<p> The <tt>-session</tt> option is mandatory; otherwise <a href="qapplication.html">QApplication</a> cannot
312tell whether it has been restored or what the current session
313identifier is. See <a href="qapplication.html#isSessionRestored">QApplication::isSessionRestored</a>() and
314<a href="qapplication.html#sessionId">QApplication::sessionId</a>() for details.
315<p> If your application is very simple, it may be possible to store the
316entire application state in additional command line options. This
317is usually a very bad idea because command lines are often limited
318to a few hundred bytes. Instead, use <a href="qsettings.html">QSettings</a>, or temporary files
319or a database for this purpose. By marking the data with the unique
320<a href="#sessionId">sessionId</a>(), you will be able to restore the application in a future
321session.
322<p> <p>See also <a href="#restartCommand">restartCommand</a>(), <a href="#setDiscardCommand">setDiscardCommand</a>(), and <a href="#setRestartHint">setRestartHint</a>().
323
324<h3 class=fn>void <a name="setRestartHint"></a>QSessionManager::setRestartHint ( <a href="qsessionmanager.html#RestartHint-enum">RestartHint</a>&nbsp;hint )
325</h3>
326
327<p> Sets the application's restart hint to <em>hint</em>. On application
328startup the hint is set to <a href="#RestartHint-enum">RestartIfRunning</a>.
329<p> Note that these flags are only hints, a session manager may or may
330not respect them.
331<p> We recommend setting the restart hint in <a href="qapplication.html#saveState">QApplication::saveState</a>()
332because most session managers perform a checkpoint shortly after an
333application's startup.
334<p> <p>See also <a href="#restartHint">restartHint</a>().
335
336<!-- eof -->
337<hr><p>
338This file is part of the <a href="index.html">Qt toolkit</a>.
339Copyright &copy; 1995-2007
340<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
341<table width=100% cellspacing=0 border=0><tr>
342<td>Copyright &copy; 2007
343<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
344<td align=right><div align=right>Qt 3.3.8</div>
345</table></div></address></body>
346</html>
Note: See TracBrowser for help on using the repository browser.