|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QSessionManager
public final class QSessionManager
The QSessionManager
class provides access to the session manager. 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.
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. We recommend that you use QSettings
to save an individual application's settings, e.g. window positions, recently used files, etc. When the application is restarted by the session manager, you can restore the settings.
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. The session manager can only be accessed through these functions.
No user interaction is possible unless the application gets 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.
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().
For sophisticated session managers provided on Unix/X11, QSessionManager
offers further possibilities to fine-tune an application's session management behavior: setRestartCommand()
, setDiscardCommand()
, setRestartHint()
, setProperty()
, requestPhase2()
. See the respective function descriptions for further details.
QApplication
, and Session Management.
Nested Class Summary | |
---|---|
static class |
QSessionManager.RestartHint
This enum type defines the circumstances under which this application wants to be restarted by the session manager. |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary |
---|
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Method Summary | |
---|---|
boolean |
allowsErrorInteraction()
Returns true if error interaction is permitted; otherwise returns false. |
boolean |
allowsInteraction()
Asks the session manager for permission to interact with the user. |
void |
cancel()
Tells the session manager to cancel the shutdown process. |
java.util.List |
discardCommand()
Returns the currently set discard command. |
boolean |
isPhase2()
Returns true if the session manager is currently performing a second session management phase; otherwise returns false. |
void |
release()
Releases the session manager's interaction semaphore after an interaction phase. |
void |
requestPhase2()
Requests a second session management phase for the application. |
java.util.List |
restartCommand()
Returns the currently set restart command. |
QSessionManager.RestartHint |
restartHint()
Returns the application's current restart hint. |
java.lang.String |
sessionId()
Returns the identifier of the current session. |
java.lang.String |
sessionKey()
Returns the session key in the current session. |
void |
setDiscardCommand(java.util.List arg__1)
Sets the discard command to the given list. |
void |
setManagerProperty(java.lang.String name,
java.util.List value)
Low-level write access to the application's identification and state record are kept in the session manager. |
void |
setManagerProperty(java.lang.String name,
java.lang.String value)
Low-level write access to the application's identification and state records are kept in the session manager. |
void |
setRestartCommand(java.util.List arg__1)
If the session manager is capable of restoring sessions it will execute command in order to restore the application. |
void |
setRestartHint(QSessionManager.RestartHint arg__1)
Sets the application's restart hint to hint. |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Method Detail |
---|
public final boolean allowsErrorInteraction()
This is similar to allowsInteraction()
, 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.
allowsInteraction()
, release()
, and cancel()
.
public final boolean allowsInteraction()
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.
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.)
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()
.
Here's an example of how an application's QApplication::commitData()
might be implemented:
public final void commitData(QSessionManager manager) { if (manager.allowsInteraction()) { QMessageBox.StandardButton ret = QMessageBox.warning( mainWindow, tr("My Application"), tr("Save changes to document?"), QMessageBox.StandardButton.createQFlags( QMessageBox.StandardButton.Save, QMessageBox.StandardButton.Discard, QMessageBox.StandardButton.Cancel) ); switch (ret) { case Save: manager.release(); if (!saveDocument()) manager.cancel(); break; case Discard: break; case Cancel: default: manager.cancel(); } } else { // we did not get permission to interact, then // do something reasonable instead } }If an error occurred within the application while saving its data, you may want to try
allowsErrorInteraction()
instead. QApplication::commitData()
, release()
, and cancel()
.
public final void cancel()
allowsInteraction()
, and allowsErrorInteraction()
.
public final java.util.List discardCommand()
To iterate over the list, you can use the foreach pseudo-keyword:
for (String command : mySession.discardCommand()) do_something(command);
setDiscardCommand()
, restartCommand()
, and setRestartCommand()
.
public final boolean isPhase2()
requestPhase2()
.
public final void release()
allowsInteraction()
, and allowsErrorInteraction()
.
public final void requestPhase2()
QApplication::commitData()
or QApplication::saveState()
function, and they will be called again once most or all other applications have finished their session management. 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.
Note that if another application has requested a second phase it may get called before, simultaneously with, or after your application's second phase.
isPhase2()
.
public final java.util.List restartCommand()
To iterate over the list, you can use the foreach pseudo-keyword:
for (String command : mySession.restartCommand()) do_something(command);
setRestartCommand()
, and restartHint()
.
public final QSessionManager.RestartHint restartHint()
setRestartHint()
.
public final java.lang.String sessionId()
If the application has been restored from an earlier session, this identifier is the same as it was in that earlier session.
sessionKey()
, and QApplication::sessionId()
.
public final java.lang.String sessionKey()
If the application has been restored from an earlier session, this key is the same as it was when the previous session ended.
The session key changes with every call of commitData() or saveState().
sessionId()
, and QApplication::sessionKey()
.
public final void setDiscardCommand(java.util.List arg__1)
discardCommand()
, and setRestartCommand()
.
public final void setManagerProperty(java.lang.String name, java.lang.String value)
The property called name has its value set to the string value.
public final void setManagerProperty(java.lang.String name, java.util.List value)
The property called name has its value set to the string list value.
public final void setRestartCommand(java.util.List arg__1)
appname -session idThe -session 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. 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.
restartCommand()
, setDiscardCommand()
, and setRestartHint()
.
public final void setRestartHint(QSessionManager.RestartHint arg__1)
Note that these flags are only hints, a session manager may or may not respect them.
We recommend setting the restart hint in QApplication::saveState()
because most session managers perform a checkpoint shortly after an application's startup.
restartHint()
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |