add more spacing
[personal-kdebase.git] / workspace / krunner / screensaver / saverengine.h
blobbe36e8b723fc4bf2819457ed23263af0c3a41f54
1 //===========================================================================
2 //
3 // This file is part of the KDE project
4 //
5 // Copyright 1999 Martin R. Jones <mjones@kde.org>
6 //
8 #ifndef SAVERENGINE_H
9 #define SAVERENGINE_H
11 #include <QWidget>
12 #include <kprocess.h>
13 #include <QVector>
14 #include <QDBusContext>
15 #include <QDBusMessage>
17 #include "xautolock.h"
18 #include "xautolock_c.h"
20 class ScreenSaverRequest
22 public:
23 // QString appname;
24 // QString reasongiven;
25 QString dbusid;
26 uint cookie;
27 enum { Inhibit,Throttle } type;
30 //===========================================================================
31 /**
32 * Screen saver engine. Handles screensaver window, starting screensaver
33 * hacks, and password entry.
35 class SaverEngine : public QWidget, protected QDBusContext
37 Q_OBJECT
38 Q_CLASSINFO("D-Bus Interface", "org.freedesktop.ScreenSaver")
40 public:
41 SaverEngine();
42 ~SaverEngine();
44 public Q_SLOTS:
45 /**
46 * Lock the screen now even if the screensaver does not lock by default.
48 void Lock();
50 /**
51 * Save the screen now. If the user has locking enabled, the screen is locked also.
53 bool save();
55 /**
56 * Start the screensaver in plasma-setup mode.
57 * if plasma is not enabled, this just locks the screen.
59 bool setupPlasma();
61 /**
62 * Quit the screensaver if it is running
64 bool quit();
66 /**
67 * Simulate user activity
69 void SimulateUserActivity();
71 /**
72 * Return true if the screensaver is enabled
74 bool isEnabled();
76 /**
77 * Enable/disable the screensaver
78 * @return true if the action succeeded
80 bool enable( bool e, bool force = false );
82 /**
83 * Return true if the screen is currently blanked
85 bool isBlanked();
87 /**
88 * Read and apply configuration.
90 void configure();
92 /**
93 * Called by krunner_lock when locking is in effect.
95 void saverLockReady();
97 /**
98 * Request a change in the state of the screensaver.
99 * Set to TRUE to request that the screensaver activate.
100 * Active means that the screensaver has blanked the
101 * screen and may run a graphical theme. This does
102 * not necessary mean that the screen is locked.
104 bool SetActive( bool state );
106 /// Returns the value of the current state of activity (See setActive)
107 bool GetActive();
110 * Returns the number of seconds that the screensaver has
111 * been active. Returns zero if the screensaver is not active.
113 uint GetActiveTime();
116 * Returns the number of seconds that the session has
117 * been idle. Returns zero if the session is not idle.
119 uint GetSessionIdleTime();
122 * Request that saving the screen due to system idleness
123 * be blocked until UnInhibit is called or the
124 * calling process exits.
125 * The cookie is a random number used to identify the request
127 uint Inhibit(const QString &application_name, const QString &reason_for_inhibit);
128 /// Cancel a previous call to Inhibit() identified by the cookie.
129 void UnInhibit(uint cookie);
132 * Request that running themes while the screensaver is active
133 * be blocked until UnThrottle is called or the
134 * calling process exits.
135 * The cookie is a random number used to identify the request
137 uint Throttle(const QString &application_name, const QString &reason_for_inhibit);
138 /// Cancel a previous call to Throttle() identified by the cookie.
139 void UnThrottle(uint cookie);
141 Q_SIGNALS:
142 // DBus signals
143 void ActiveChanged(bool state);
145 protected Q_SLOTS:
146 void idleTimeout();
147 void lockProcessExited();
148 void serviceOwnerChanged(const QString&, const QString&, const QString&);
150 protected:
151 enum LockType { DontLock, DefaultLock, ForceLock, PlasmaSetup };
152 bool startLockProcess( LockType lock_type );
153 void stopLockProcess();
154 bool handleKeyPress(XKeyEvent *xke);
155 void processLockTransactions();
156 xautolock_corner_t applyManualSettings(int);
158 private:
159 enum State { Waiting, Preparing, Saving };
161 State mState;
162 XAutoLock *mXAutoLock;
163 KProcess mLockProcess;
165 // the original X screensaver parameters
166 int mXTimeout;
167 int mXInterval;
168 int mXBlanking;
169 int mXExposures;
171 time_t m_actived_time;
172 QList<ScreenSaverRequest> m_requests;
173 uint m_next_cookie;
175 int m_nr_throttled;
176 int m_nr_inhibited;
178 QList<QDBusMessage> mLockTransactions;
181 #endif