GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||
GeezerVison is showing develop.kde.org — Session management Session managementMake your application aware of X sessions About KDE and X11 session managementSince KDE 1.0, KDE supports the legacy X11R4 and ICCCM session management protocols. It will restart with the specified command all legacy applications that define the Since KDE 2.0, KDE also supports the standard X11R6 session management protocol XSMP and uses it. You can download the official documentation of the standard from the X Consortium's FTP server ftp.x.org. Unlike the legacy protocols, the new X11R6 session management gives a chance to save application dependent settings when you log out. A text editor, for instance, would save the names of the loaded files and would reload them when you log in again. Another major advantage of the new protocol is the support for a clean and safe logout procedure even if the users decides not to restore the session next time. The protocol gives applications the possibility to interact with the user if they are in danger to lose some data, and to cancel the shutdown process if necessary. Further ReadingAn introductory overview of session management functionality and the Qt API for it is available from Qt documentation. In KDE, the classes KConfigGui and KMainWindow hide all the ugly details from the programmer. Basically, a KConfigGui manages a KConfig configuration object (available through KConfigGui::sessionConfig()) for you, that your application can use to store session specific data. Please read the class documentation, especially the one of KMainWindow, for a detailed interface description. With the advanced functionality in KMainWindow, it's really just a matter of a few lines to get even a multi-window application to retains its state between different user sessions. Implementing session management in your applicationHere's just a brief overview how you can add session management to your application. Again, see the class documentation for details. Implementing session management in Plasma is easy. If your main window inherits from KMainWindow, you have just 2 things to do:
That's all. Reimplement some virtual functions of KMainWindowKMainWindow will automatically save its position, geometry and positions of toolbars and menu bar on logout - and restore it on the next startup. For every other data that your application needs to restore a session, you have to write the code for saving and restoring yourself. However, KMainWindow makes this task easy. You can just re-implement the following functions:
Furthermore, the function queryClose() could be interesting for you. This function is called always before the window is closed, either by the user or indirectly by the session manager. (Note that this is not the case for a call of QApplication::quit() because this function will exit the event loop without causing a close event for the main windows. It will even not destroy them.) Typically, here you can warn the user that the application or some windows have unsaved data on close or logout (example: show a dialog with the buttons "Save changes" and "Discard changes"). However, for session management it isn't nice to need a user interaction before closing, so you better avoid this. Note that it is not determined if Note To save your application-wide properties (data that is only needed once per application, and not for each main window instance) reimplement saveGlobalProperties() and its counterpart readGlobalProperties(). Normally, you don't need these functions.Add session management support to your main() functionWhile KMainWindow::saveProperties() (and KMainWindow::queryClose() will be called automatically, KMainWindow::readProperties() will not. You have to add some code to your main() function to add session restoring.
kRestoreMainWindows<>() will create (on the heap) as many instances of your main windows as have existed in the last session and call KMainWindow::restore() with the correct arguments. Note that also About With this you can easily restore all top-level windows of your application. It is also possible to restore different types of top-level windows (each derived from KMainWindow, of course) within one application. Imagine you have three classes of main windows: childMW1, childMW2 and childMW3:
Appendix: Architecture of the KDE session managerThe name of the session management server in KDE is Initial Author: Matthias Ettrich | ||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |