CopperSpice API
1.9.2
|
The QSessionManager class provides access to the session manager. More...
Public Types | |
enum | RestartHint |
Public Methods | |
bool | allowsErrorInteraction () |
bool | allowsInteraction () |
void | cancel () |
QStringList | discardCommand () const |
bool | isPhase2 () const |
void | release () |
void | requestPhase2 () |
QStringList | restartCommand () const |
RestartHint | restartHint () const |
QString | sessionId () const |
QString | sessionKey () const |
void | setDiscardCommand (const QStringList &list) |
void | setManagerProperty (const QString &name, const QString &value) |
void | setManagerProperty (const QString &name, const QStringList &value) |
void | setRestartCommand (const QStringList &list) |
void | setRestartHint (RestartHint hint) |
Public Methods inherited from QObject | |
QObject (QObject *parent=nullptr) | |
~QObject () | |
bool | blockSignals (bool block) |
const QList< QObject * > & | children () const |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QString > | dynamicPropertyNames () const |
virtual bool | event (QEvent *event) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
template<class T > | |
QList< T > | findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
bool | inherits (const QString &className) const |
void | installEventFilter (QObject *filterObj) |
bool | isWidgetType () const |
bool | isWindowType () const |
void | killTimer (int id) |
const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | property (const QString &name) const |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const QString &name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
QThread * | thread () const |
Friends | |
class | QApplication |
Additional Inherited Members | |
Public Signals inherited from QObject | |
void | destroyed (QObject *obj=nullptr) |
void | objectNameChanged (const QString &objectName) |
Public Slots inherited from QObject | |
void | deleteLater () |
Static Public Methods inherited from QObject | |
static bool | connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ()) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...)) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod) |
static QMetaObject & | staticMetaObject () |
static QString | tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) |
Protected Methods inherited from QObject | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signalMethod) const |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signalMethod) const |
bool | isSignalConnected (const QMetaMethod &signalMethod) const |
int | receivers (const QString &signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Properties inherited from QObject | |
objectName | |
Related Functions inherited from QObject | |
T | qobject_cast (QObject *object) |
QObjectList | |
The QSessionManager class provides access to the session manager.
A session manager in a desktop environment (in which CopperSpice 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. 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(). CopperSpice 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.
This enum type defines the circumstances under which this application wants to be restarted by the session manager. The current values are:
Constant | Value | Description |
---|---|---|
QSessionManager::RestartIfRunning | 0 | If the application is still running when the session is shut down, it wants to be restarted at the start of the next session. |
QSessionManager::RestartAnyway | 1 | 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.) |
QSessionManager::RestartImmediately | 2 | The application wants to be started immediately whenever it is not running. |
QSessionManager::RestartNever | 3 | The application does not want to be restarted automatically. |
The default hint is RestartIfRunning
.
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.
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 is 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.
void QSessionManager::cancel | ( | ) |
Tells the session manager to cancel the shutdown process. Applications should not call this function without asking the user first.
QStringList QSessionManager::discardCommand | ( | ) | const |
Returns the currently set discard command. To navigate through a list you can use a range based for loop.
bool QSessionManager::isPhase2 | ( | ) | const |
Returns true if the session manager is currently performing a second session management phase, otherwise returns false.
void QSessionManager::release | ( | ) |
Releases the session manager's interaction semaphore after an interaction phase.
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.
QStringList QSessionManager::restartCommand | ( | ) | const |
Returns the currently set restart command. To navigate through a list you can use a range based for loop.
RestartHint QSessionManager::restartHint | ( | ) | const |
Returns the application's current restart hint. The default is RestartIfRunning
.
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.
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().
void QSessionManager::setDiscardCommand | ( | const QStringList & | list | ) |
Sets the discard command to the given list.
Low-level write access to the application's identification and state records are kept in the session manager. The property called name has its value set to the string value.
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.
void QSessionManager::setRestartCommand | ( | const QStringList & | list | ) |
If the session manager is capable of restoring sessions it will execute the command specified in list in order to restore the application. If this method is not called the default is equivalent to the code shown below.
The -session
option is mandatory, otherwise QApplication can not tell whether it has been restored or what the current session identifier is. Refer 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.
void QSessionManager::setRestartHint | ( | RestartHint | hint | ) |
Sets the application's restart hint to hint. On application startup, the hint is set to RestartIfRunning
. This method should be called from QApplication::saveState() because most session managers perform a checkpoint shortly after an application's startup.