Eneboo - Documentación para desarrolladores
Tipos públicos | Métodos públicos | Amigas
Referencia de la Clase QSessionManager

The QSessionManager class provides access to the session manager. Más...

#include <qsessionmanager.h>

Diagrama de herencias de QSessionManager
QObject QObject Qt Qt Qt Qt

Lista de todos los miembros.

Tipos públicos

enum  RestartHint {
  RestartIfRunning, RestartAnyway, RestartImmediately, RestartNever,
  RestartIfRunning, RestartAnyway, RestartImmediately, RestartNever
}
enum  RestartHint {
  RestartIfRunning, RestartAnyway, RestartImmediately, RestartNever,
  RestartIfRunning, RestartAnyway, RestartImmediately, RestartNever
}

Métodos públicos

QString sessionId () const
QString sessionKey () const
bool allowsInteraction ()
bool allowsErrorInteraction ()
void release ()
void cancel ()
void setRestartHint (RestartHint)
RestartHint restartHint () const
void setRestartCommand (const QStringList &)
QStringList restartCommand () const
void setDiscardCommand (const QStringList &)
QStringList discardCommand () const
void setManagerProperty (const QString &name, const QString &value)
void setManagerProperty (const QString &name, const QStringList &value)
bool isPhase2 () const
void requestPhase2 ()
QString sessionId () const
QString sessionKey () const
bool allowsInteraction ()
bool allowsErrorInteraction ()
void release ()
void cancel ()
void setRestartHint (RestartHint)
RestartHint restartHint () const
void setRestartCommand (const QStringList &)
QStringList restartCommand () const
void setDiscardCommand (const QStringList &)
QStringList discardCommand () const
void setManagerProperty (const QString &name, const QString &value)
void setManagerProperty (const QString &name, const QStringList &value)
bool isPhase2 () const
void requestPhase2 ()

Amigas

class QApplication
class QBaseApplication

Descripción detallada

The QSessionManager class provides access to the session manager.

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.

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.

During a session management action (i.e. within commitData() and saveState()), no user interaction is possible unless 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.

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 possibilites to fine-tune an application's session management behavior: setRestartCommand(), setDiscardCommand(), setRestartHint(), setProperty(), requestPhase2(). See the respective function descriptions for further details.


Documentación de las enumeraciones miembro de la clase

This enum type defines the circumstances under which this application wants to be restarted by the session manager. The current values are

RestartIfRunning if the application is still running when the session is shut down, it wants to be restarted at the start of the next session.

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

RestartImmediately the application wants to be started immediately whenever it is not running.

RestartNever the application does not want to be restarted automatically.

The default hint is RestartIfRunning.

Valores de enumeraciones:
RestartIfRunning 
RestartAnyway 
RestartImmediately 
RestartNever 
RestartIfRunning 
RestartAnyway 
RestartImmediately 
RestartNever 
Valores de enumeraciones:
RestartIfRunning 
RestartAnyway 
RestartImmediately 
RestartNever 
RestartIfRunning 
RestartAnyway 
RestartImmediately 
RestartNever 

Documentación de las funciones miembro

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.

Ver también:
allowsInteraction(), release(), cancel()
bool QSessionManager::allowsErrorInteraction ( )
bool QSessionManager::allowsInteraction ( )
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:

void MyApplication::commitData( QSessionManager& sm ) {
    if ( sm.allowsInteraction() ) {
  switch ( QMessageBox::warning(
        yourMainWindow,
        tr("Application Name"),
        tr("Save changes to document Foo?"),
        tr("&Yes"),
        tr("&No"),
        tr("Cancel"),
        0, 2) ) {
  case 0: // yes
      sm.release();
      // save document here; if saving fails, call sm.cancel()
      break;
  case 1: // continue without saving
      break;
  default: // cancel
      sm.cancel();
      break;
  }
    } 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.

Ver también:
QApplication::commitData(), release(), cancel()
void QSessionManager::cancel ( )
void QSessionManager::cancel ( )

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

Ver también:
allowsInteraction(), allowsErrorInteraction()
QStringList QSessionManager::discardCommand ( ) const

Returns the currently set discard command.

Note that if you want to iterate over the list, you should iterate over a copy, e.g.

    QStringList list = mySession.discardCommand();
    QStringList::Iterator it = list.begin();
    while( it != list.end() ) {
  myProcessing( *it );
  ++it;
    }
Ver también:
setDiscardCommand(), restartCommand(), setRestartCommand()
QStringList QSessionManager::discardCommand ( ) const
bool QSessionManager::isPhase2 ( ) const

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

Ver también:
requestPhase2()
bool QSessionManager::isPhase2 ( ) const
void QSessionManager::release ( void  )

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

Ver también:
allowsInteraction(), allowsErrorInteraction()
void QSessionManager::release ( )
void QSessionManager::requestPhase2 ( )
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.

Note that if another application has requested a second phase it may get called before, simultaneously with, or after your application's second phase.

Ver también:
isPhase2()
QStringList QSessionManager::restartCommand ( ) const

Returns the currently set restart command.

Note that if you want to iterate over the list, you should iterate over a copy, e.g.

    QStringList list = mySession.restartCommand();
    QStringList::Iterator it = list.begin();
    while( it != list.end() ) {
  myProcessing( *it );
  ++it;
    }
Ver también:
setRestartCommand(), restartHint()
QStringList QSessionManager::restartCommand ( ) const
QSessionManager::RestartHint QSessionManager::restartHint ( ) const

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

Ver también:
setRestartHint()
RestartHint QSessionManager::restartHint ( ) const
QString QSessionManager::sessionId ( ) const
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 that earlier session.

Ver también:
sessionKey(), QApplication::sessionId()
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().

Ver también:
sessionId(), QApplication::sessionKey()
QString QSessionManager::sessionKey ( ) const
void QSessionManager::setDiscardCommand ( const QStringList command)
void QSessionManager::setDiscardCommand ( const QStringList )
void QSessionManager::setManagerProperty ( const QString name,
const QStringList value 
)
void QSessionManager::setManagerProperty ( const QString name,
const QString value 
)
void QSessionManager::setManagerProperty ( const QString name,
const QString 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 )
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

  appname -session id

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, 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.

Ver también:
restartCommand(), setDiscardCommand(), setRestartHint()
void QSessionManager::setRestartHint ( QSessionManager::RestartHint  hint)

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

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.

Ver también:
restartHint()
void QSessionManager::setRestartHint ( RestartHint  )

Documentación de las funciones relacionadas y clases amigas

QApplication [friend]

Reimplementado de QObject.

QBaseApplication [friend]

Reimplementado de QObject.


La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'