summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/qsessionmanager.3qt
blob: 5a7eb0e79cafe0e6da0076aa25f486d8fd901e6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
'\" t
.TH QSessionManager 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QSessionManager \- Access to the session manager
.SH SYNOPSIS
\fC#include <qsessionmanager.h>\fR
.PP
Inherits QObject.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "QString \fBsessionId\fR () const"
.br
.ti -1c
.BI "QString \fBsessionKey\fR () const"
.br
.ti -1c
.BI "void * \fBhandle\fR () const"
.br
.ti -1c
.BI "bool \fBallowsInteraction\fR ()"
.br
.ti -1c
.BI "bool \fBallowsErrorInteraction\fR ()"
.br
.ti -1c
.BI "void \fBrelease\fR ()"
.br
.ti -1c
.BI "void \fBcancel\fR ()"
.br
.ti -1c
.BI "enum \fBRestartHint\fR { RestartIfRunning, RestartAnyway, RestartImmediately, RestartNever }"
.br
.ti -1c
.BI "void \fBsetRestartHint\fR ( RestartHint hint )"
.br
.ti -1c
.BI "RestartHint \fBrestartHint\fR () const"
.br
.ti -1c
.BI "void \fBsetRestartCommand\fR ( const QStringList & command )"
.br
.ti -1c
.BI "QStringList \fBrestartCommand\fR () const"
.br
.ti -1c
.BI "void \fBsetDiscardCommand\fR ( const QStringList & )"
.br
.ti -1c
.BI "QStringList \fBdiscardCommand\fR () const"
.br
.ti -1c
.BI "void \fBsetManagerProperty\fR ( const QString & name, const QString & value )"
.br
.ti -1c
.BI "void \fBsetManagerProperty\fR ( const QString & name, const QStringList & value )"
.br
.ti -1c
.BI "bool \fBisPhase2\fR () const"
.br
.ti -1c
.BI "void \fBrequestPhase2\fR ()"
.br
.in -1c
.SH DESCRIPTION
The QSessionManager class provides access to the session manager.
.PP
The session manager is responsible for session management, most importantly for interruption and resumption. A "session" is a kind of record of the state of the system, e.g. which applications were run at start up and which applications are currently running. The session manager is used to save the session, e.g. when the machine is shut down; and to restore a session, e.g. when the machine is started up. Use QSettings to save and restore an individual application's settings, e.g. window positions, recently used files, etc.
.PP
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 QApplication::commitData() and QApplication::saveState(). Both provide a reference to a session manager object as argument, to allow the application to communicate with the session manager.
.PP
During a session management action (i.e. within commitData() and saveState()), no user interaction is possible \fIunless\fR the application got explicit permission from the session manager. You ask for permission by calling allowsInteraction() or, if it's really urgent, allowsErrorInteraction(). Qt does not enforce this, but the session manager may.
.PP
You can try to abort the shutdown process by calling cancel(). The default commitData() function does this if some top-level window rejected its closeEvent().
.PP
For sophisticated session managers provided on Unix/X11, QSessionManager offers further possibilites to fine-tune an application's session management behavior: setRestartCommand(), setDiscardCommand(), setRestartHint(), setProperty(), requestPhase2(). See the respective function descriptions for further details.
.PP
See also Main Window and Related Classes and Environment Classes.
.SS "Member Type Documentation"
.SH "QSessionManager::RestartHint"
This enum type defines the circumstances under which this application wants to be restarted by the session manager. The current values are
.TP
\fCQSessionManager::RestartIfRunning\fR - if the application is still running when the session is shut down, it wants to be restarted at the start of the next session.
.TP
\fCQSessionManager::RestartAnyway\fR - 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.)
.TP
\fCQSessionManager::RestartImmediately\fR - the application wants to be started immediately whenever it is not running.
.TP
\fCQSessionManager::RestartNever\fR - the application does not want to be restarted automatically.
.PP
The default hint is RestartIfRunning.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "bool QSessionManager::allowsErrorInteraction ()"
This is similar to allowsInteraction(), but also tells the session manager that an error occurred. Session managers may give error interaction request 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.
.PP
See also allowsInteraction(), release(), and cancel().
.SH "bool QSessionManager::allowsInteraction ()"
Asks the session manager for permission to interact with the user. Returns TRUE if interaction is permitted; otherwise returns FALSE.
.PP
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.
.PP
When the interaction is completed we strongly recommend releasing the user interaction semaphore with a call to release(). 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.)
.PP
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 cancel().
.PP
Here's an example of how an application's QApplication::commitData() might be implemented:
.PP
.nf
.br
void MyApplication::commitData( QSessionManager& sm ) {
.br
    if ( sm.allowsInteraction() ) {
.br
        switch ( QMessageBox::warning(
.br
                    yourMainWindow,
.br
                    tr("Application Name"),
.br
                    tr("Save changes to document Foo?"),
.br
                    tr("&Yes"),
.br
                    tr("&No"),
.br
                    tr("Cancel"),
.br
                    0, 2) ) {
.br
        case 0: // yes
.br
            sm.release();
.br
            // save document here; if saving fails, call sm.cancel()
.br
            break;
.br
        case 1: // continue without saving
.br
            break;
.br
        default: // cancel
.br
            sm.cancel();
.br
            break;
.br
        }
.br
    } else {
.br
        // we did not get permission to interact, then
.br
        // do something reasonable instead.
.br
    }
.br
}
.fi
.PP
If an error occurred within the application while saving its data, you may want to try allowsErrorInteraction() instead.
.PP
See also QApplication::commitData(), release(), and cancel().
.SH "void QSessionManager::cancel ()"
Tells the session manager to cancel the shutdown process. Applications should not call this function without first asking the user.
.PP
See also allowsInteraction() and allowsErrorInteraction().
.SH "QStringList QSessionManager::discardCommand () const"
Returns the currently set discard command.
.PP
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
.PP
.nf
.br
    QStringList list = mySession.discardCommand();
.br
    QStringList::Iterator it = list.begin();
.br
    while( it != list.end() ) {
.br
        myProcessing( *it );
.br
        ++it;
.br
    }
.br
.fi
.PP
See also setDiscardCommand(), restartCommand(), and setRestartCommand().
.SH "void * QSessionManager::handle () const"
X11 only: returns a handle to the current \fCSmcConnection\fR.
.SH "bool QSessionManager::isPhase2 () const"
Returns TRUE if the session manager is currently performing a second session management phase; otherwise returns FALSE.
.PP
See also requestPhase2().
.SH "void QSessionManager::release ()"
Releases the session manager's interaction semaphore after an interaction phase.
.PP
See also allowsInteraction() and allowsErrorInteraction().
.SH "void QSessionManager::requestPhase2 ()"
Requests a second session management phase for the application. The application may then return immediately from the QApplication::commitData() or QApplication::saveState() function, and they will be called again once most or all other applications have finished their session management.
.PP
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.
.PP
Note that if another application has requested a second phase it may get called before, simultaneously with, or after your application's second phase.
.PP
See also isPhase2().
.SH "QStringList QSessionManager::restartCommand () const"
Returns the currently set restart command.
.PP
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
.PP
.nf
.br
    QStringList list = mySession.restartCommand();
.br
    QStringList::Iterator it = list.begin();
.br
    while( it != list.end() ) {
.br
        myProcessing( *it );
.br
        ++it;
.br
    }
.br
.fi
.PP
See also setRestartCommand() and restartHint().
.SH "RestartHint QSessionManager::restartHint () const"
Returns the application's current restart hint. The default is RestartIfRunning.
.PP
See also setRestartHint().
.SH "QString QSessionManager::sessionId () const"
Returns the identifier of the current session.
.PP
If the application has been restored from an earlier session, this identifier is the same as it was in that earlier session.
.PP
See also sessionKey() and QApplication::sessionId().
.SH "QString QSessionManager::sessionKey () const"
Returns the session key in the current session.
.PP
If the application has been restored from an earlier session, this key is the same as it was when the previous session ended.
.PP
The session key changes with every call of commitData() or saveState().
.PP
See also sessionId() and QApplication::sessionKey().
.SH "void QSessionManager::setDiscardCommand ( const QStringList & )"
See also discardCommand() and setRestartCommand().
.SH "void QSessionManager::setManagerProperty ( const QString & name, const QStringList & value )"
Low-level write access to the application's identification and state record are kept in the session manager.
.PP
The property called \fIname\fR has its value set to the string list \fIvalue\fR.
.SH "void QSessionManager::setManagerProperty ( const QString & name, const QString & value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Low-level write access to the application's identification and state records are kept in the session manager.
.PP
The property called \fIname\fR has its value set to the string \fIvalue\fR.
.SH "void QSessionManager::setRestartCommand ( const QStringList & command )"
If the session manager is capable of restoring sessions it will execute \fIcommand\fR in order to restore the application. The command defaults to
.PP
.nf
.br
        appname -session id
.br
.fi
.PP
The \fC-session\fR option is mandatory; otherwise QApplication cannot tell whether it has been restored or what the current session identifier is. See QApplication::isSessionRestored() and QApplication::sessionId() for details.
.PP
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 QSettings, or temporary files or a database for this purpose. By marking the data with the unique sessionId(), you will be able to restore the application in a future session.
.PP
See also restartCommand(), setDiscardCommand(), and setRestartHint().
.SH "void QSessionManager::setRestartHint ( RestartHint hint )"
Sets the application's restart hint to \fIhint\fR. On application startup the hint is set to RestartIfRunning.
.PP
Note that these flags are only hints, a session manager may or may not respect them.
.PP
We recommend setting the restart hint in QApplication::saveState() because most session managers perform a checkpoint shortly after an application's startup.
.PP
See also restartHint().

.SH "SEE ALSO"
.BR http://doc.trolltech.com/qsessionmanager.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech. 
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (qsessionmanager.3qt) and the Qt
version (3.3.8).