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"><!--
|
---|
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>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 <<a href="qsessionmanager-h.html">qsessionmanager.h</a>></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 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 QStringList & 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 & )</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 QString & name, const QString & value )</li>
|
---|
56 | <li class=fn>void <a href="#setManagerProperty"><b>setManagerProperty</b></a> ( const QString & name, const QStringList & 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 |
|
---|
63 | The QSessionManager class provides access to the session manager.
|
---|
64 | <p>
|
---|
65 |
|
---|
66 | <p> The session manager is responsible for session management, most
|
---|
67 | importantly for interruption and resumption. A "session" is a kind
|
---|
68 | of record of the state of the system, e.g. which applications were
|
---|
69 | run at start up and which applications are currently running. The
|
---|
70 | session manager is used to save the session, e.g. when the machine
|
---|
71 | is shut down; and to restore a session, e.g. when the machine is
|
---|
72 | started up. Use <a href="qsettings.html">QSettings</a> to save and restore an individual
|
---|
73 | application's settings, e.g. window positions, recently used files,
|
---|
74 | etc.
|
---|
75 | <p> QSessionManager provides an interface between the application and
|
---|
76 | the session manager so that the program can work well with the
|
---|
77 | session manager. In Qt, session management requests for action
|
---|
78 | are handled by the two virtual functions <a href="qapplication.html#commitData">QApplication::commitData</a>()
|
---|
79 | and <a href="qapplication.html#saveState">QApplication::saveState</a>(). Both provide a reference to
|
---|
80 | a session manager object as argument, to allow the application
|
---|
81 | to communicate with the session manager.
|
---|
82 | <p> During a session management action (i.e. within commitData() and
|
---|
83 | saveState()), no user interaction is possible <em>unless</em> the
|
---|
84 | application got explicit permission from the session manager. You
|
---|
85 | ask for permission by calling <a href="#allowsInteraction">allowsInteraction</a>() or, if it's really
|
---|
86 | urgent, <a href="#allowsErrorInteraction">allowsErrorInteraction</a>(). Qt does not enforce this, but the
|
---|
87 | session manager may.
|
---|
88 | <p> You can try to abort the shutdown process by calling <a href="#cancel">cancel</a>(). The
|
---|
89 | default commitData() function does this if some top-level window
|
---|
90 | rejected its closeEvent().
|
---|
91 | <p> For sophisticated session managers provided on Unix/X11, QSessionManager
|
---|
92 | offers further possibilites to fine-tune an application's session
|
---|
93 | management 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
|
---|
95 | function 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
|
---|
101 | application wants to be restarted by the session manager. The
|
---|
102 | current values are
|
---|
103 | <ul>
|
---|
104 | <li><tt>QSessionManager::RestartIfRunning</tt> - if the application is still running when
|
---|
105 | the session is shut down, it wants to be restarted at the start of
|
---|
106 | the next session.
|
---|
107 | <li><tt>QSessionManager::RestartAnyway</tt> - the application wants to be started at the
|
---|
108 | start of the next session, no matter what. (This is useful for
|
---|
109 | utilities that run just after startup and then quit.)
|
---|
110 | <li><tt>QSessionManager::RestartImmediately</tt> - the application wants to be started
|
---|
111 | immediately whenever it is not running.
|
---|
112 | <li><tt>QSessionManager::RestartNever</tt> - the application does not want to be restarted
|
---|
113 | automatically.
|
---|
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
|
---|
121 | manager that an error occurred. Session managers may give error
|
---|
122 | interaction request higher priority, which means that it is more likely
|
---|
123 | that an error interaction is permitted. However, you are still not
|
---|
124 | guaranteed 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
|
---|
131 | user. Returns TRUE if interaction is permitted; otherwise
|
---|
132 | returns FALSE.
|
---|
133 | <p> The rationale behind this mechanism is to make it possible to
|
---|
134 | synchronize user interaction during a shutdown. Advanced session
|
---|
135 | managers may ask all applications simultaneously to commit their
|
---|
136 | data, resulting in a much faster shutdown.
|
---|
137 | <p> When the interaction is completed we strongly recommend releasing the
|
---|
138 | user interaction semaphore with a call to <a href="#release">release</a>(). This way, other
|
---|
139 | applications may get the chance to interact with the user while your
|
---|
140 | application is still busy saving data. (The semaphore is implicitly
|
---|
141 | released when the application exits.)
|
---|
142 | <p> If the user decides to cancel the shutdown process during the
|
---|
143 | interaction phase, you must tell the session manager that this has
|
---|
144 | happened 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>()
|
---|
146 | might be implemented:
|
---|
147 | <p> <pre>
|
---|
148 | void MyApplication::commitData( QSessionManager& 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>("&Yes"),
|
---|
155 | <a href="qobject.html#tr">tr</a>("&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,
|
---|
176 | you 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
|
---|
183 | should 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
|
---|
192 | iterate 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
|
---|
213 | session 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
|
---|
220 | interaction 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
|
---|
227 | application 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,
|
---|
229 | and they will be called again once most or all other applications have
|
---|
230 | finished their session management.
|
---|
231 | <p> The two phases are useful for applications such as the X11 window manager
|
---|
232 | that need to store information about another application's windows
|
---|
233 | and therefore have to wait until these applications have completed their
|
---|
234 | respective session management tasks.
|
---|
235 | <p> Note that if another application has requested a second phase it
|
---|
236 | may get called before, simultaneously with, or after your
|
---|
237 | application'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
|
---|
245 | iterate 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
|
---|
269 | identifier 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
|
---|
277 | key is the same as it was when the previous session ended.
|
---|
278 | <p> The session key changes with every call of commitData() or
|
---|
279 | saveState().
|
---|
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 <a href="qstringlist.html">QStringList</a> & )
|
---|
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 <a href="qstring.html">QString</a> & name, const <a href="qstringlist.html">QStringList</a> & value )
|
---|
288 | </h3>
|
---|
289 |
|
---|
290 | <p> Low-level write access to the application's identification and state
|
---|
291 | record 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 <a href="qstring.html">QString</a> & name, const <a href="qstring.html">QString</a> & value )
|
---|
295 | </h3>
|
---|
296 | This 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
|
---|
298 | records 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 <a href="qstringlist.html">QStringList</a> & command )
|
---|
302 | </h3>
|
---|
303 |
|
---|
304 | <p> If the session manager is capable of restoring sessions it will
|
---|
305 | execute <em>command</em> in order to restore the application. The command
|
---|
306 | defaults 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
|
---|
312 | tell whether it has been restored or what the current session
|
---|
313 | identifier 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
|
---|
316 | entire application state in additional command line options. This
|
---|
317 | is usually a very bad idea because command lines are often limited
|
---|
318 | to a few hundred bytes. Instead, use <a href="qsettings.html">QSettings</a>, or temporary files
|
---|
319 | or 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
|
---|
321 | session.
|
---|
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> hint )
|
---|
325 | </h3>
|
---|
326 |
|
---|
327 | <p> Sets the application's restart hint to <em>hint</em>. On application
|
---|
328 | startup 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
|
---|
330 | not respect them.
|
---|
331 | <p> We recommend setting the restart hint in <a href="qapplication.html#saveState">QApplication::saveState</a>()
|
---|
332 | because most session managers perform a checkpoint shortly after an
|
---|
333 | application's startup.
|
---|
334 | <p> <p>See also <a href="#restartHint">restartHint</a>().
|
---|
335 |
|
---|
336 | <!-- eof -->
|
---|
337 | <hr><p>
|
---|
338 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
339 | Copyright © 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 © 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>
|
---|