Merge branch 'central-widget'
[krunner.git] / saverengine.h
blobf5c03e78fad66931531a72d9998df63a4453f917
1 //===========================================================================
2 //
3 // This file is part of the KDE project
4 //
5 // Copyright (c) 1999 Martin R. Jones <mjones@kde.org>
6 //
8 #ifndef __SAVERENGINE_H__
9 #define __SAVERENGINE_H__
11 #include <QWidget>
12 #include <k3process.h>
13 #include <QVector>
14 #include <QDBusConnection>
16 #include "xautolock.h"
17 #include "xautolock_c.h"
19 class ScreenSaverRequest
21 public:
22 QString appname;
23 QString reasongiven;
24 QString dbusid;
25 uint cookie;
26 enum { Inhibit,Throttle } type;
29 //===========================================================================
30 /**
31 * Screen saver engine. Handles screensaver window, starting screensaver
32 * hacks, and password entry.
34 class SaverEngine : public QWidget
36 Q_OBJECT
37 Q_CLASSINFO("D-Bus Interface", "org.freedesktop.ScreenSaver")
39 public:
40 SaverEngine();
41 ~SaverEngine();
43 public Q_SLOTS:
44 /**
45 * Lock the screen now even if the screensaver does not lock by default.
47 void Lock();
49 /**
50 * Save the screen now. If the user has locking enabled, the screen is locked also.
52 bool save();
54 /**
55 * Quit the screensaver if it is running
57 bool quit();
59 /**
60 * Simulate user activity
62 void SimulateUserActivity();
64 /**
65 * Return true if the screensaver is enabled
67 bool isEnabled();
69 /**
70 * Enable/disable the screensaver
71 * @return true if the action succeeded
73 bool enable( bool e );
75 /**
76 * Return true if the screen is currently blanked
78 bool isBlanked();
80 /**
81 * Read and apply configuration.
83 void configure();
85 /**
86 * Called by krunner_lock when locking is in effect.
88 void saverLockReady();
90 /**
91 * Request a change in the state of the screensaver.
92 * Set to TRUE to request that the screensaver activate.
93 * Active means that the screensaver has blanked the
94 * screen and may run a graphical theme. This does
95 * not necessary mean that the screen is locked.
97 bool SetActive( bool state );
99 /// Returns the value of the current state of activity (See setActive)
100 bool GetActive();
103 * Returns the number of seconds that the screensaver has
104 * been active. Returns zero if the screensaver is not active.
106 uint GetActiveTime();
108 /// Returns the value of the current state of session idleness.
109 bool GetSessionIdle();
112 * Returns the number of seconds that the session has
113 * been idle. Returns zero if the session is not idle.
115 uint GetSessionIdleTime();
118 * Request that saving the screen due to system idleness
119 * be blocked until UnInhibit is called or the
120 * calling process exits.
121 * The cookie is a random number used to identify the request
123 uint Inhibit(const QString &application_name, const QString &reason_for_inhibit);
124 /// Cancel a previous call to Inhibit() identified by the cookie.
125 void UnInhibit(uint cookie);
128 * Request that running themes while the screensaver is active
129 * be blocked until UnThrottle is called or the
130 * calling process exits.
131 * The cookie is a random number used to identify the request
133 uint Throttle(const QString &application_name, const QString &reason_for_inhibit);
134 /// Cancel a previous call to Throttle() identified by the cookie.
135 void UnThrottle(uint cookie);
137 Q_SIGNALS:
138 // DBus signals
139 void ActiveChanged(bool state);
141 protected Q_SLOTS:
142 void idleTimeout();
143 void lockProcessExited();
144 void serviceOwnerChanged(const QString&,const QString&,const QString&);
146 protected:
147 enum LockType { DontLock, DefaultLock, ForceLock };
148 bool startLockProcess( LockType lock_type );
149 void stopLockProcess();
150 bool handleKeyPress(XKeyEvent *xke);
151 void processLockTransactions();
152 xautolock_corner_t applyManualSettings(int);
154 private:
155 enum State { Waiting, Preparing, Saving };
156 bool mEnabled;
157 bool mDPMS;
159 State mState;
160 XAutoLock *mXAutoLock;
161 K3Process mLockProcess;
162 int mTimeout;
164 // the original X screensaver parameters
165 int mXTimeout;
166 int mXInterval;
167 int mXBlanking;
168 int mXExposures;
170 time_t m_actived_time;
171 QDBusConnection screensaverService;
172 QList<ScreenSaverRequest> m_requests;
173 uint m_next_cookie;
175 int m_nr_throttled;
176 int m_nr_inhibited;
178 // QVector< DCOPClientTransaction* > mLockTransactions;
181 #endif