[][src]Struct qt_gui::QSessionManager

#[repr(C)]pub struct QSessionManager { /* fields omitted */ }

The QSessionManager class provides access to the session manager.

C++ class: QSessionManager.

C++ documentation:

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 platform's session manager. In Qt, session management requests for action are handled by the two signals QGuiApplication::commitDataRequest() and QGuiApplication::saveStateRequest(). Both provide a reference to a QSessionManager object as argument. The session manager can only be accessed in slots invoked by these signals.

Warning: If you use QSessionManager, you should disable fallback session management: QGuiApplication::setFallbackSessionManagementEnabled().

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().

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.

Methods

impl QSessionManager[src]

pub unsafe fn allows_error_interaction(&self) -> bool[src]

Returns true if error interaction is permitted; otherwise returns false.

Calls C++ function: bool QSessionManager::allowsErrorInteraction().

C++ documentation:

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.

See also allowsInteraction(), release(), and cancel().

pub unsafe fn allows_interaction(&self) -> bool[src]

Asks the session manager for permission to interact with the user. Returns true if interaction is permitted; otherwise returns false.

Calls C++ function: bool QSessionManager::allowsInteraction().

C++ documentation:

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 QGuiApplication::commitDataRequest() might be implemented:

MyMainWidget::MyMainWidget(QWidget *parent) :QWidget(parent) { QGuiApplication::setFallbackSessionManagementEnabled(false); connect(qApp, SIGNAL(commitDataRequest(QSessionManager)), SLOT(commitData(QSessionManager))); }

void MyMainWidget::commitData(QSessionManager& manager) { if (manager.allowsInteraction()) { int ret = QMessageBox::warning( mainWindow, tr("My Application"), tr("Save changes to document?"), 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 { // 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.

See also QGuiApplication::commitDataRequest(), release(), and cancel().

pub unsafe fn cancel(&self)[src]

Tells the session manager to cancel the shutdown process. Applications should not call this function without asking the user first.

Calls C++ function: void QSessionManager::cancel().

C++ documentation:

Tells the session manager to cancel the shutdown process. Applications should not call this function without asking the user first.

See also allowsInteraction() and allowsErrorInteraction().

pub unsafe fn discard_command(&self) -> CppBox<QStringList>[src]

Returns the currently set discard command.

Calls C++ function: QStringList QSessionManager::discardCommand() const.

C++ documentation:

Returns the currently set discard command.

To iterate over the list, you can use the foreach pseudo-keyword:

foreach (const QString &command, mySession.discardCommand()) do_something(command);

See also setDiscardCommand(), restartCommand(), and setRestartCommand().

pub unsafe fn is_phase2(&self) -> bool[src]

Returns true if the session manager is currently performing a second session management phase; otherwise returns false.

Calls C++ function: bool QSessionManager::isPhase2() const.

C++ documentation:

Returns true if the session manager is currently performing a second session management phase; otherwise returns false.

See also requestPhase2().

pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>[src]

Calls C++ function: virtual const QMetaObject* QSessionManager::metaObject() const.

pub unsafe fn qt_metacall(
    &self,
    arg1: Call,
    arg2: c_int,
    arg3: *mut *mut c_void
) -> c_int
[src]

Calls C++ function: virtual int QSessionManager::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3).

pub unsafe fn qt_metacast(&self, arg1: *const c_char) -> *mut c_void[src]

Calls C++ function: virtual void* QSessionManager::qt_metacast(const char* arg1).

pub unsafe fn release(&self)[src]

Releases the session manager's interaction semaphore after an interaction phase.

Calls C++ function: void QSessionManager::release().

C++ documentation:

Releases the session manager's interaction semaphore after an interaction phase.

See also allowsInteraction() and allowsErrorInteraction().

pub unsafe fn request_phase2(&self)[src]

Requests a second session management phase for the application. The application may then return immediately from the QGuiApplication::commitDataRequest() or QApplication::saveStateRequest() function, and they will be called again once most or all other applications have finished their session management.

Calls C++ function: void QSessionManager::requestPhase2().

C++ documentation:

Requests a second session management phase for the application. The application may then return immediately from the QGuiApplication::commitDataRequest() or QApplication::saveStateRequest() 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: If another application has requested a second phase it may get called before, simultaneously with, or after your application's second phase.

See also isPhase2().

pub unsafe fn restart_command(&self) -> CppBox<QStringList>[src]

Returns the currently set restart command.

Calls C++ function: QStringList QSessionManager::restartCommand() const.

C++ documentation:

Returns the currently set restart command.

To iterate over the list, you can use the foreach pseudo-keyword:

foreach (const QString &command, mySession.restartCommand()) do_something(command);

See also setRestartCommand() and restartHint().

pub unsafe fn restart_hint(&self) -> RestartHint[src]

Returns the application's current restart hint. The default is RestartIfRunning.

Calls C++ function: QSessionManager::RestartHint QSessionManager::restartHint() const.

C++ documentation:

Returns the application's current restart hint. The default is RestartIfRunning.

See also setRestartHint().

pub unsafe fn session_id(&self) -> CppBox<QString>[src]

Returns the identifier of the current session.

Calls C++ function: QString QSessionManager::sessionId() const.

C++ documentation:

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.

See also sessionKey() and QGuiApplication::sessionId().

pub unsafe fn session_key(&self) -> CppBox<QString>[src]

Returns the session key in the current session.

Calls C++ function: QString QSessionManager::sessionKey() const.

C++ documentation:

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().

See also sessionId() and QGuiApplication::sessionKey().

pub unsafe fn set_discard_command(&self, arg1: impl CastInto<Ref<QStringList>>)[src]

Sets the discard command to the given command.

Calls C++ function: void QSessionManager::setDiscardCommand(const QStringList& arg1).

C++ documentation:

Sets the discard command to the given command.

See also discardCommand() and setRestartCommand().

pub unsafe fn set_manager_property_2_q_string(
    &self,
    name: impl CastInto<Ref<QString>>,
    value: impl CastInto<Ref<QString>>
)
[src]

This is an overloaded function.

Calls C++ function: void QSessionManager::setManagerProperty(const QString& name, const QString& value).

C++ documentation:

This is an overloaded function.

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.

pub unsafe fn set_manager_property_q_string_q_string_list(
    &self,
    name: impl CastInto<Ref<QString>>,
    value: impl CastInto<Ref<QStringList>>
)
[src]

Low-level write access to the application's identification and state record are kept in the session manager.

Calls C++ function: void QSessionManager::setManagerProperty(const QString& name, const QStringList& value).

C++ documentation:

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.

pub unsafe fn set_restart_command(&self, arg1: impl CastInto<Ref<QStringList>>)[src]

If the session manager is capable of restoring sessions it will execute command in order to restore the application. The command defaults to

Calls C++ function: void QSessionManager::setRestartCommand(const QStringList& arg1).

C++ documentation:

If the session manager is capable of restoring sessions it will execute command in order to restore the application. The command defaults to


  appname -session id

The -session option is mandatory; otherwise QGuiApplication cannot tell whether it has been restored or what the current session identifier is. See QGuiApplication::isSessionRestored() and QGuiApplication::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.

See also restartCommand(), setDiscardCommand(), and setRestartHint().

pub unsafe fn set_restart_hint(&self, arg1: RestartHint)[src]

Sets the application's restart hint to hint. On application startup, the hint is set to RestartIfRunning.

Calls C++ function: void QSessionManager::setRestartHint(QSessionManager::RestartHint arg1).

C++ documentation:

Sets the application's restart hint to hint. On application startup, the hint is set to RestartIfRunning.

Note: These flags are only hints, a session manager may or may not respect them.

We recommend setting the restart hint in QGuiApplication::saveStateRequest() because most session managers perform a checkpoint shortly after an application's startup.

See also restartHint().

pub unsafe fn static_meta_object() -> Ref<QMetaObject>[src]

Returns a reference to the staticMetaObject field.

pub unsafe fn tr(
    s: *const c_char,
    c: *const c_char,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QSessionManager::tr(const char* s, const char* c, int n).

pub unsafe fn tr_utf8(
    s: *const c_char,
    c: *const c_char,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QSessionManager::trUtf8(const char* s, const char* c, int n).

Trait Implementations

impl Deref for QSessionManager[src]

type Target = QObject

The resulting type after dereferencing.

fn deref(&self) -> &QObject[src]

Calls C++ function: QObject* static_cast<QObject*>(QSessionManager* ptr).

impl DynamicCast<QSessionManager> for QObject[src]

unsafe fn dynamic_cast(ptr: Ptr<QObject>) -> Ptr<QSessionManager>[src]

Calls C++ function: QSessionManager* dynamic_cast<QSessionManager*>(QObject* ptr).

impl StaticDowncast<QSessionManager> for QObject[src]

unsafe fn static_downcast(ptr: Ptr<QObject>) -> Ptr<QSessionManager>[src]

Calls C++ function: QSessionManager* static_cast<QSessionManager*>(QObject* ptr).

impl StaticUpcast<QObject> for QSessionManager[src]

unsafe fn static_upcast(ptr: Ptr<QSessionManager>) -> Ptr<QObject>[src]

Calls C++ function: QObject* static_cast<QObject*>(QSessionManager* ptr).

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.