Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > 8e6051afcdb111a0317a58fb64c2abf5 > files > 4806

qt4-doc-4.6.3-0.2mdv2010.2.i586.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- qapplication.cpp -->
<head>
  <title>Qt 4.6: QSessionManager Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<a name="//apple_ref/cpp/cl//QSessionManager"></a>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">All&nbsp;Functions</font></a>&nbsp;&middot; <a href="overviews.html"><font color="#004faf">Overviews</font></a></td></tr></table><h1 class="title">QSessionManager Class Reference<br /><span class="small-subtitle">[<a href="qtgui.html">QtGui</a> module]</span>
</h1>
<p>The QSessionManager class provides access to the session manager. <a href="#details">More...</a></p>
<pre> #include &lt;QSessionManager&gt;</pre><p>Inherits <a href="qobject.html">QObject</a>.</p>
<ul>
<li><a href="qsessionmanager-members.html">List of all members, including inherited members</a></li>
</ul>
<hr />
<a name="public-types"></a>
<h2>Public Types</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top">enum </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#RestartHint-enum">RestartHint</a></b> { RestartIfRunning, RestartAnyway, RestartImmediately, RestartNever }</td></tr>
</table>
<hr />
<a name="public-functions"></a>
<h2>Public Functions</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#allowsErrorInteraction">allowsErrorInteraction</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#allowsInteraction">allowsInteraction</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#cancel">cancel</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QStringList </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#discardCommand">discardCommand</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#isPhase2">isPhase2</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#release">release</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#requestPhase2">requestPhase2</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QStringList </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#restartCommand">restartCommand</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">RestartHint </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#restartHint">restartHint</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QString </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#sessionId">sessionId</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QString </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#sessionKey">sessionKey</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#setDiscardCommand">setDiscardCommand</a></b> ( const QStringList &amp; <i>list</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#setManagerProperty">setManagerProperty</a></b> ( const QString &amp; <i>name</i>, const QStringList &amp; <i>value</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#setManagerProperty-2">setManagerProperty</a></b> ( const QString &amp; <i>name</i>, const QString &amp; <i>value</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#setRestartCommand">setRestartCommand</a></b> ( const QStringList &amp; <i>command</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qsessionmanager.html#setRestartHint">setRestartHint</a></b> ( RestartHint <i>hint</i> )</td></tr>
</table>
<ul>
<li><div bar="2" class="fn"></div>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li><div class="fn"></div>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
<li><div class="fn"></div>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li><div class="fn"></div>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
<li><div class="fn"></div>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
<li><div class="fn"></div>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QSessionManager class provides access to the session manager.</p>
<p>A session manager in a desktop environment (in which Qt GUI applications live) keeps track of a session, which is a group of running applications, each of which has a particular state. The state of an application contains (most notably) the documents the application has open and the position and size of its windows.</p>
<p>The session manager is used to save the session, e.g&#x2e;, when the machine is shut down, and to restore a session, e.g&#x2e;, when the machine is started up. We recommend that you use <a href="qsettings.html">QSettings</a> to save an application's settings, for example, window positions, recently used files, etc. When the application is restarted by the session manager, you can restore the settings.</p>
<p>QSessionManager provides an interface between the application and the session manager so that the program can work well with the session manager. In Qt, session management requests for action are handled by the two virtual functions <a href="qapplication.html#commitData">QApplication::commitData</a>() and <a href="qapplication.html#saveState">QApplication::saveState</a>(). Both provide a reference to a session manager object as argument, to allow the application to communicate with the session manager. The session manager can only be accessed through these functions.</p>
<p>No user interaction is possible <i>unless</i> the application gets explicit permission from the session manager. You ask for permission by calling <a href="qsessionmanager.html#allowsInteraction">allowsInteraction</a>() or, if it is really urgent, <a href="qsessionmanager.html#allowsErrorInteraction">allowsErrorInteraction</a>(). Qt does not enforce this, but the session manager may.</p>
<p>You can try to abort the shutdown process by calling <a href="qsessionmanager.html#cancel">cancel</a>(). The default commitData() function does this if some top-level window rejected its closeEvent().</p>
<p>For sophisticated session managers provided on Unix/X11, QSessionManager offers further possibilities to fine-tune an application's session management behavior: <a href="qsessionmanager.html#setRestartCommand">setRestartCommand</a>(), <a href="qsessionmanager.html#setDiscardCommand">setDiscardCommand</a>(), <a href="qsessionmanager.html#setRestartHint">setRestartHint</a>(), <a href="qobject.html#setProperty">setProperty</a>(), <a href="qsessionmanager.html#requestPhase2">requestPhase2</a>(). See the respective function descriptions for further details.</p>
<p>See also <a href="qapplication.html">QApplication</a> and <a href="session.html">Session Management</a>.</p>
<hr />
<h2>Member Type Documentation</h2>
<a name="//apple_ref/cpp/tag/QSessionManager/RestartHint"></a>
<a name="//apple_ref/cpp/econst/QSessionManager/RestartIfRunning"></a>
<a name="//apple_ref/cpp/econst/QSessionManager/RestartAnyway"></a>
<a name="//apple_ref/cpp/econst/QSessionManager/RestartImmediately"></a>
<a name="//apple_ref/cpp/econst/QSessionManager/RestartNever"></a>
<h3 class="fn"><a name="RestartHint-enum"></a>enum QSessionManager::RestartHint</h3>
<p>This enum type defines the circumstances under which this application wants to be restarted by the session manager. The current values are:</p>
<p><table class="valuelist" border="1" cellpadding="2" cellspacing="1" width="100%">
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
<tr><td valign="top"><tt>QSessionManager::RestartIfRunning</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">If the application is still running when the session is shut down, it wants to be restarted at the start of the next session.</td></tr>
<tr><td valign="top"><tt>QSessionManager::RestartAnyway</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">The application wants to be started at the start of the next session, no matter what. (This is useful for utilities that run just after startup and then quit.)</td></tr>
<tr><td valign="top"><tt>QSessionManager::RestartImmediately</tt></td><td align="center" valign="top"><tt>2</tt></td><td valign="top">The application wants to be started immediately whenever it is not running.</td></tr>
<tr><td valign="top"><tt>QSessionManager::RestartNever</tt></td><td align="center" valign="top"><tt>3</tt></td><td valign="top">The application does not want to be restarted automatically.</td></tr>
</table></p>
<p>The default hint is <tt>RestartIfRunning</tt>.</p>
<hr />
<h2>Member Function Documentation</h2>
<a name="//apple_ref/cpp/instm/QSessionManager/allowsErrorInteraction"></a>
<h3 class="fn"><a name="allowsErrorInteraction"></a>bool QSessionManager::allowsErrorInteraction ()</h3>
<p>Returns true if error interaction is permitted; otherwise returns false.</p>
<p>This is similar to <a href="qsessionmanager.html#allowsInteraction">allowsInteraction</a>(), but also enables the application to tell the user about any errors that occur. Session managers may give error interaction requests higher priority, which means that it is more likely that an error interaction is permitted. However, you are still not guaranteed that the session manager will allow interaction.</p>
<p>See also <a href="qsessionmanager.html#allowsInteraction">allowsInteraction</a>(), <a href="qsessionmanager.html#release">release</a>(), and <a href="qsessionmanager.html#cancel">cancel</a>().</p>
<a name="//apple_ref/cpp/instm/QSessionManager/allowsInteraction"></a>
<h3 class="fn"><a name="allowsInteraction"></a>bool QSessionManager::allowsInteraction ()</h3>
<p>Asks the session manager for permission to interact with the user. Returns true if interaction is permitted; otherwise returns false.</p>
<p>The rationale behind this mechanism is to make it possible to synchronize user interaction during a shutdown. Advanced session managers may ask all applications simultaneously to commit their data, resulting in a much faster shutdown.</p>
<p>When the interaction is completed we strongly recommend releasing the user interaction semaphore with a call to <a href="qsessionmanager.html#release">release</a>(). This way, other applications may get the chance to interact with the user while your application is still busy saving data. (The semaphore is implicitly released when the application exits.)</p>
<p>If the user decides to cancel the shutdown process during the interaction phase, you must tell the session manager that this has happened by calling <a href="qsessionmanager.html#cancel">cancel</a>().</p>
<p>Here's an example of how an application's <a href="qapplication.html#commitData">QApplication::commitData</a>() might be implemented:</p>
<pre> void MyApplication::commitData(QSessionManager&amp; manager)
 {
     if (manager.allowsInteraction()) {
         int ret = QMessageBox::warning(
                     mainWindow,
                     tr(&quot;My Application&quot;),
                     tr(&quot;Save changes to document?&quot;),
                     QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);

         switch (ret) {
         case QMessageBox::Save:
             manager.release();
             if (!saveDocument())
                 manager.cancel();
             break;
         case QMessageBox::Discard:
             break;
         case QMessageBox::Cancel:
         default:
             manager.cancel();
         }
     } else {
         <span class="comment">// we did not get permission to interact, then</span>
         <span class="comment">// do something reasonable instead</span>
     }
 }</pre>
<p>If an error occurred within the application while saving its data, you may want to try <a href="qsessionmanager.html#allowsErrorInteraction">allowsErrorInteraction</a>() instead.</p>
<p>See also <a href="qapplication.html#commitData">QApplication::commitData</a>(), <a href="qsessionmanager.html#release">release</a>(), and <a href="qsessionmanager.html#cancel">cancel</a>().</p>
<a name="//apple_ref/cpp/instm/QSessionManager/cancel"></a>
<h3 class="fn"><a name="cancel"></a>void QSessionManager::cancel ()</h3>
<p>Tells the session manager to cancel the shutdown process. Applications should not call this function without asking the user first.</p>
<p>See also <a href="qsessionmanager.html#allowsInteraction">allowsInteraction</a>() and <a href="qsessionmanager.html#allowsErrorInteraction">allowsErrorInteraction</a>().</p>
<a name="//apple_ref/cpp/instm/QSessionManager/discardCommand"></a>
<h3 class="fn"><a name="discardCommand"></a><a href="qstringlist.html">QStringList</a> QSessionManager::discardCommand () const</h3>
<p>Returns the currently set discard command.</p>
<p>To iterate over the list, you can use the <a href="containers.html#foreach">foreach</a> pseudo-keyword:</p>
<pre> foreach (QString command, mySession.discardCommand())
     do_something(command);</pre>
<p>See also <a href="qsessionmanager.html#setDiscardCommand">setDiscardCommand</a>(), <a href="qsessionmanager.html#restartCommand">restartCommand</a>(), and <a href="qsessionmanager.html#setRestartCommand">setRestartCommand</a>().</p>
<a name="//apple_ref/cpp/instm/QSessionManager/isPhase2"></a>
<h3 class="fn"><a name="isPhase2"></a>bool QSessionManager::isPhase2 () const</h3>
<p>Returns true if the session manager is currently performing a second session management phase; otherwise returns false.</p>
<p>See also <a href="qsessionmanager.html#requestPhase2">requestPhase2</a>().</p>
<a name="//apple_ref/cpp/instm/QSessionManager/release"></a>
<h3 class="fn"><a name="release"></a>void QSessionManager::release ()</h3>
<p>Releases the session manager's interaction semaphore after an interaction phase.</p>
<p>See also <a href="qsessionmanager.html#allowsInteraction">allowsInteraction</a>() and <a href="qsessionmanager.html#allowsErrorInteraction">allowsErrorInteraction</a>().</p>
<a name="//apple_ref/cpp/instm/QSessionManager/requestPhase2"></a>
<h3 class="fn"><a name="requestPhase2"></a>void QSessionManager::requestPhase2 ()</h3>
<p>Requests a second session management phase for the application. The application may then return immediately from the <a href="qapplication.html#commitData">QApplication::commitData</a>() or <a href="qapplication.html#saveState">QApplication::saveState</a>() function, and they will be called again once most or all other applications have finished their session management.</p>
<p>The two phases are useful for applications such as the X11 window manager that need to store information about another application's windows and therefore have to wait until these applications have completed their respective session management tasks.</p>
<p><b>Note:</b> If another application has requested a second phase it may get called before, simultaneously with, or after your application's second phase.</p>
<p>See also <a href="qsessionmanager.html#isPhase2">isPhase2</a>().</p>
<a name="//apple_ref/cpp/instm/QSessionManager/restartCommand"></a>
<h3 class="fn"><a name="restartCommand"></a><a href="qstringlist.html">QStringList</a> QSessionManager::restartCommand () const</h3>
<p>Returns the currently set restart command.</p>
<p>To iterate over the list, you can use the <a href="containers.html#foreach">foreach</a> pseudo-keyword:</p>
<pre> foreach (QString command, mySession.restartCommand())
     do_something(command);</pre>
<p>See also <a href="qsessionmanager.html#setRestartCommand">setRestartCommand</a>() and <a href="qsessionmanager.html#restartHint">restartHint</a>().</p>
<a name="//apple_ref/cpp/instm/QSessionManager/restartHint"></a>
<h3 class="fn"><a name="restartHint"></a><a href="qsessionmanager.html#RestartHint-enum">RestartHint</a> QSessionManager::restartHint () const</h3>
<p>Returns the application's current restart hint. The default is <tt>RestartIfRunning</tt>.</p>
<p>See also <a href="qsessionmanager.html#setRestartHint">setRestartHint</a>().</p>
<a name="//apple_ref/cpp/instm/QSessionManager/sessionId"></a>
<h3 class="fn"><a name="sessionId"></a><a href="qstring.html">QString</a> QSessionManager::sessionId () const</h3>
<p>Returns the identifier of the current session.</p>
<p>If the application has been restored from an earlier session, this identifier is the same as it was in the earlier session.</p>
<p>See also <a href="qsessionmanager.html#sessionKey">sessionKey</a>() and <a href="qapplication.html#sessionId">QApplication::sessionId</a>().</p>
<a name="//apple_ref/cpp/instm/QSessionManager/sessionKey"></a>
<h3 class="fn"><a name="sessionKey"></a><a href="qstring.html">QString</a> QSessionManager::sessionKey () const</h3>
<p>Returns the session key in the current session.</p>
<p>If the application has been restored from an earlier session, this key is the same as it was when the previous session ended.</p>
<p>The session key changes with every call of commitData() or saveState().</p>
<p>See also <a href="qsessionmanager.html#sessionId">sessionId</a>() and <a href="qapplication.html#sessionKey">QApplication::sessionKey</a>().</p>
<a name="//apple_ref/cpp/instm/QSessionManager/setDiscardCommand"></a>
<h3 class="fn"><a name="setDiscardCommand"></a>void QSessionManager::setDiscardCommand ( const <a href="qstringlist.html">QStringList</a> &amp; <i>list</i> )</h3>
<p>Sets the discard command to the given <i>list</i>.</p>
<p>See also <a href="qsessionmanager.html#discardCommand">discardCommand</a>() and <a href="qsessionmanager.html#setRestartCommand">setRestartCommand</a>().</p>
<a name="//apple_ref/cpp/instm/QSessionManager/setManagerProperty"></a>
<h3 class="fn"><a name="setManagerProperty"></a>void QSessionManager::setManagerProperty ( const <a href="qstring.html">QString</a> &amp; <i>name</i>, const <a href="qstringlist.html">QStringList</a> &amp; <i>value</i> )</h3>
<p>Low-level write access to the application's identification and state record are kept in the session manager.</p>
<p>The property called <i>name</i> has its value set to the string list <i>value</i>.</p>
<h3 class="fn"><a name="setManagerProperty-2"></a>void QSessionManager::setManagerProperty ( const <a href="qstring.html">QString</a> &amp; <i>name</i>, const <a href="qstring.html">QString</a> &amp; <i>value</i> )</h3>
<p>This is an overloaded function.</p>
<p>Low-level write access to the application's identification and state records are kept in the session manager.</p>
<p>The property called <i>name</i> has its value set to the string <i>value</i>.</p>
<a name="//apple_ref/cpp/instm/QSessionManager/setRestartCommand"></a>
<h3 class="fn"><a name="setRestartCommand"></a>void QSessionManager::setRestartCommand ( const <a href="qstringlist.html">QStringList</a> &amp; <i>command</i> )</h3>
<p>If the session manager is capable of restoring sessions it will execute <i>command</i> in order to restore the application. The command defaults to</p>
<pre> appname -session id</pre>
<p>The <tt>-session</tt> option is mandatory; otherwise <a href="qapplication.html">QApplication</a> cannot tell whether it has been restored or what the current session identifier is. See <a href="qapplication.html#isSessionRestored">QApplication::isSessionRestored</a>() and <a href="qapplication.html#sessionId">QApplication::sessionId</a>() for details.</p>
<p>If your application is very simple, it may be possible to store the entire application state in additional command line options. This is usually a very bad idea because command lines are often limited to a few hundred bytes. Instead, use <a href="qsettings.html">QSettings</a>, temporary files, or a database for this purpose. By marking the data with the unique <a href="qsessionmanager.html#sessionId">sessionId</a>(), you will be able to restore the application in a future session.</p>
<p>See also <a href="qsessionmanager.html#restartCommand">restartCommand</a>(), <a href="qsessionmanager.html#setDiscardCommand">setDiscardCommand</a>(), and <a href="qsessionmanager.html#setRestartHint">setRestartHint</a>().</p>
<a name="//apple_ref/cpp/instm/QSessionManager/setRestartHint"></a>
<h3 class="fn"><a name="setRestartHint"></a>void QSessionManager::setRestartHint ( <a href="qsessionmanager.html#RestartHint-enum">RestartHint</a> <i>hint</i> )</h3>
<p>Sets the application's restart hint to <i>hint</i>. On application startup, the hint is set to <tt>RestartIfRunning</tt>.</p>
<p><b>Note:</b> These flags are only hints, a session manager may or may not respect them.</p>
<p>We recommend setting the restart hint in <a href="qapplication.html#saveState">QApplication::saveState</a>() because most session managers perform a checkpoint shortly after an application's startup.</p>
<p>See also <a href="qsessionmanager.html#restartHint">restartHint</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="40%" align="left">Copyright &copy; 2010 Nokia Corporation and/or its subsidiary(-ies)</td>
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="40%" align="right"><div align="right">Qt 4.6.3</div></td>
</tr></table></div></address></body>
</html>