Qt 4.8
|
The QSessionManager class provides access to the session manager. More...
#include <qsessionmanager.h>
Public Types | |
enum | RestartHint { RestartIfRunning, RestartAnyway, RestartImmediately, RestartNever } |
This enum type defines the circumstances under which this application wants to be restarted by the session manager. More... | |
Public Functions | |
bool | allowsErrorInteraction () |
Returns true if error interaction is permitted; otherwise returns false. More... | |
bool | allowsInteraction () |
Asks the session manager for permission to interact with the user. More... | |
void | cancel () |
Tells the session manager to cancel the shutdown process. More... | |
QStringList | discardCommand () const |
Returns the currently set discard command. More... | |
void * | handle () const |
bool | isPhase2 () const |
Returns true if the session manager is currently performing a second session management phase; otherwise returns false. More... | |
void | release () |
Releases the session manager's interaction semaphore after an interaction phase. More... | |
void | requestPhase2 () |
Requests a second session management phase for the application. More... | |
QStringList | restartCommand () const |
Returns the currently set restart command. More... | |
RestartHint | restartHint () const |
Returns the application's current restart hint. More... | |
QString | sessionId () const |
Returns the identifier of the current session. More... | |
QString | sessionKey () const |
Returns the session key in the current session. More... | |
void | setDiscardCommand (const QStringList &) |
Sets the discard command to the given list. More... | |
void | setManagerProperty (const QString &name, const QString &value) |
Low-level write access to the application's identification and state records are kept in the session manager. More... | |
void | 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. More... | |
void | setRestartCommand (const QStringList &) |
If the session manager is capable of restoring sessions it will execute command in order to restore the application. More... | |
void | setRestartHint (RestartHint) |
Sets the application's restart hint to hint. More... | |
Public Functions inherited from QObject | |
bool | blockSignals (bool b) |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More... | |
const QObjectList & | children () const |
Returns a list of child objects. More... | |
bool | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0) |
bool | disconnect (const QObject *receiver, const char *member=0) |
void | dumpObjectInfo () |
Dumps information about signal connections, etc. More... | |
void | dumpObjectTree () |
Dumps a tree of children to the debug output. More... | |
QList< QByteArray > | dynamicPropertyNames () const |
Returns the names of all properties that were dynamically added to the object using setProperty(). More... | |
virtual bool | event (QEvent *) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. More... | |
virtual bool | eventFilter (QObject *, QEvent *) |
Filters events if this object has been installed as an event filter for the watched object. More... | |
template<typename T > | |
T | findChild (const QString &aName=QString()) const |
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More... | |
template<typename T > | |
QList< T > | findChildren (const QString &aName=QString()) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More... | |
template<typename T > | |
QList< T > | findChildren (const QRegExp &re) const |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More... | |
void | installEventFilter (QObject *) |
Installs an event filter filterObj on this object. More... | |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false. More... | |
void | killTimer (int id) |
Kills the timer with timer identifier, id. More... | |
virtual const QMetaObject * | metaObject () const |
Returns a pointer to the meta-object of this object. More... | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. More... | |
QString | objectName () const |
QObject * | parent () const |
Returns a pointer to the parent object. More... | |
QVariant | property (const char *name) const |
Returns the value of the object's name property. More... | |
Q_INVOKABLE | QObject (QObject *parent=0) |
Constructs an object with parent object parent. More... | |
void | removeEventFilter (QObject *) |
Removes an event filter object obj from this object. More... | |
void | setObjectName (const QString &name) |
void | setParent (QObject *) |
Makes the object a child of parent. More... | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. More... | |
void | setUserData (uint id, QObjectUserData *data) |
bool | signalsBlocked () const |
Returns true if signals are blocked; otherwise returns false. More... | |
int | startTimer (int interval) |
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More... | |
QThread * | thread () const |
Returns the thread in which the object lives. More... | |
QObjectUserData * | userData (uint id) const |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. More... | |
Private Functions | |
QSessionManager (QApplication *app, QString &id, QString &key) | |
~QSessionManager () | |
Friends | |
class | QApplication |
class | QApplicationPrivate |
class | QBaseApplication |
Additional Inherited Members | |
Public Slots inherited from QObject | |
void | deleteLater () |
Schedules this object for deletion. More... | |
Signals inherited from QObject | |
void | destroyed (QObject *=0) |
This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More... | |
Static Public Functions inherited from QObject | |
static bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More... | |
static bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
Disconnects signal in object sender from method in object receiver. More... | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static uint | registerUserData () |
static QString | tr (const char *sourceText, const char *comment=0, int n=-1) |
static QString | trUtf8 (const char *sourceText, const char *comment=0, int n=-1) |
Static Public Variables inherited from QObject | |
static const QMetaObject | staticMetaObject |
This variable stores the meta-object for the class. More... | |
Protected Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *) |
This event handler can be reimplemented in a subclass to receive child events. More... | |
virtual void | connectNotify (const char *signal) |
This virtual function is called when something has been connected to signal in this object. More... | |
virtual void | customEvent (QEvent *) |
This event handler can be reimplemented in a subclass to receive custom events. More... | |
virtual void | disconnectNotify (const char *signal) |
This virtual function is called when something has been disconnected from signal in this object. More... | |
QObject (QObjectPrivate &dd, QObject *parent=0) | |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. More... | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More... | |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *) |
This event handler can be reimplemented in a subclass to receive timer events for the object. More... | |
Protected Variables inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Static Protected Variables inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
Related Functions inherited from QObject | |
T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QRegExp ®Exp)() |
T * | qobject_cast (QObject *object) |
QObjectList | |
void * | qt_find_obj_child (QObject *parent, const char *type, const QString &name) |
Returns a pointer to the object named name that inherits type and with a given parent. More... | |
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 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.
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 is 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.
Definition at line 60 of file qsessionmanager.h.
This enum type defines the circumstances under which this application wants to be restarted by the session manager.
The current values are:
The default hint is RestartIfRunning
.
Enumerator | |
---|---|
RestartIfRunning | |
RestartAnyway | |
RestartImmediately | |
RestartNever |
Definition at line 79 of file qsessionmanager.h.
|
private |
Definition at line 5054 of file qapplication.cpp.
Referenced by QSessionManagerPrivate::QSessionManagerPrivate(), and QSmSocketReceiver::socketActivated().
|
private |
Definition at line 5075 of file qapplication.cpp.
Referenced by QSessionManagerPrivate::QSessionManagerPrivate(), and QSmSocketReceiver::socketActivated().
bool QSessionManager::allowsErrorInteraction | ( | ) |
Returns true if error interaction is permitted; otherwise returns false.
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.
Definition at line 4170 of file qapplication_win.cpp.
Referenced by handle(), QSessionManagerPrivate::QSessionManagerPrivate(), and sm_performSaveYourself().
bool QSessionManager::allowsInteraction | ( | ) |
Asks the session manager for permission to interact with the user.
Returns true if interaction is permitted; otherwise returns false.
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:
If an error occurred within the application while saving its data, you may want to try allowsErrorInteraction() instead.
Definition at line 4164 of file qapplication_win.cpp.
Referenced by QApplication::commitData(), handle(), QSessionManagerPrivate::QSessionManagerPrivate(), and QSmSocketReceiver::socketActivated().
void QSessionManager::cancel | ( | ) |
Tells the session manager to cancel the shutdown process.
Applications should not call this function without asking the user first.
Definition at line 4182 of file qapplication_win.cpp.
Referenced by QApplication::commitData(), handle(), and QSessionManagerPrivate::QSessionManagerPrivate().
QStringList QSessionManager::discardCommand | ( | ) | const |
Returns the currently set discard command.
To iterate over the list, you can use the foreach pseudo-keyword:
Definition at line 5150 of file qapplication.cpp.
Referenced by QSessionManagerPrivate::QSessionManagerPrivate(), and sm_performSaveYourself().
void * QSessionManager::handle | ( | ) | const |
Definition at line 5094 of file qapplication.cpp.
Referenced by QSmSocketReceiver::socketActivated().
bool QSessionManager::isPhase2 | ( | ) | const |
Returns true if the session manager is currently performing a second session management phase; otherwise returns false.
Definition at line 5164 of file qapplication.cpp.
Referenced by QSessionManagerPrivate::QSessionManagerPrivate().
void QSessionManager::release | ( | ) |
Releases the session manager's interaction semaphore after an interaction phase.
Definition at line 4176 of file qapplication_win.cpp.
Referenced by handle(), and QSessionManagerPrivate::QSessionManagerPrivate().
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.
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.
Definition at line 5169 of file qapplication.cpp.
Referenced by QSessionManagerPrivate::QSessionManagerPrivate().
QStringList QSessionManager::restartCommand | ( | ) | const |
Returns the currently set restart command.
To iterate over the list, you can use the foreach pseudo-keyword:
Definition at line 5138 of file qapplication.cpp.
Referenced by QSessionManagerPrivate::QSessionManagerPrivate(), and sm_performSaveYourself().
QSessionManager::RestartHint QSessionManager::restartHint | ( | ) | const |
Returns the application's current restart hint.
The default is RestartIfRunning
.
Definition at line 5126 of file qapplication.cpp.
Referenced by QSessionManagerPrivate::QSessionManagerPrivate(), and sm_performSaveYourself().
QString QSessionManager::sessionId | ( | ) | const |
Returns the identifier of the current session.
If the application has been restored from an earlier session, this identifier is the same as it was in the earlier session.
Definition at line 5080 of file qapplication.cpp.
Referenced by QSessionManagerPrivate::QSessionManagerPrivate(), and QSmSocketReceiver::socketActivated().
QString QSessionManager::sessionKey | ( | ) | const |
Returns the session key in the current session.
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().
Definition at line 5086 of file qapplication.cpp.
Referenced by QSessionManagerPrivate::QSessionManagerPrivate(), and QSmSocketReceiver::socketActivated().
void QSessionManager::setDiscardCommand | ( | const QStringList & | list | ) |
Sets the discard command to the given list.
Definition at line 5144 of file qapplication.cpp.
Referenced by QSessionManagerPrivate::QSessionManagerPrivate(), and sm_performSaveYourself().
Low-level write access to the application's identification and state records are kept in the session manager.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
The property called name has its value set to the string value.
Definition at line 5156 of file qapplication.cpp.
Referenced by QSessionManagerPrivate::QSessionManagerPrivate().
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.
The property called name has its value set to the string list value.
Definition at line 5160 of file qapplication.cpp.
void QSessionManager::setRestartCommand | ( | const QStringList & | command | ) |
If the session manager is capable of restoring sessions it will execute command in order to restore the application.
The command defaults to
The -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, 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.
Definition at line 5132 of file qapplication.cpp.
Referenced by QSessionManagerPrivate::QSessionManagerPrivate(), and sm_performSaveYourself().
void QSessionManager::setRestartHint | ( | QSessionManager::RestartHint | hint | ) |
Sets the application's restart hint to hint.
On application startup, the hint is set to RestartIfRunning
.
We recommend setting the restart hint in QApplication::saveState() because most session managers perform a checkpoint shortly after an application's startup.
Definition at line 5120 of file qapplication.cpp.
Referenced by QSessionManagerPrivate::QSessionManagerPrivate().
|
friend |
Definition at line 100 of file qsessionmanager.h.
|
friend |
Definition at line 101 of file qsessionmanager.h.
|
friend |
Definition at line 102 of file qsessionmanager.h.