~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to krunner/lock/lockprocess.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===========================================================================
 
2
//
 
3
// This file is part of the KDE project
 
4
//
 
5
// Copyright 1999 Martin R. Jones <mjones@kde.org>
 
6
// Copyright 2003 Oswald Buddenhagen <ossi@kde.org>
 
7
// Copyright 2008 Chani Armitage <chanika@gmail.com>
 
8
//
 
9
 
 
10
#ifndef LOCKPROCESS_H
 
11
#define LOCKPROCESS_H
 
12
 
 
13
#include <KProcess>
 
14
 
 
15
#include <QWidget>
 
16
#include <QTimer>
 
17
#include <QStack>
 
18
#include <QList>
 
19
#include <QHash>
 
20
#include <QMessageBox>
 
21
#include <QPixmap>
 
22
 
 
23
#include <X11/Xlib.h>
 
24
#include <fixx11h.h>
 
25
 
 
26
#include "plasmaapp_interface.h"
 
27
 
 
28
class KLibrary;
 
29
 
 
30
struct KGreeterPluginInfo;
 
31
 
 
32
struct GreeterPluginHandle {
 
33
    KLibrary *library;
 
34
    KGreeterPluginInfo *info;
 
35
};
 
36
 
 
37
const int TIMEOUT_CODE = 2; //from PasswordDlg
 
38
 
 
39
class QDBusServiceWatcher;
 
40
 
 
41
//===========================================================================
 
42
//
 
43
// Screen saver handling process.  Handles screensaver window,
 
44
// starting screensaver hacks, and password entry.
 
45
//
 
46
class LockProcess
 
47
    : public QWidget
 
48
{
 
49
    Q_OBJECT
 
50
    Q_CLASSINFO("D-Bus Interface", "org.kde.screenlocker.LockProcess")
 
51
public:
 
52
    explicit LockProcess(bool child_saver = false, bool useBlankOnly = false);
 
53
    ~LockProcess();
 
54
 
 
55
    /**
 
56
     * start the screensaver locked
 
57
     */
 
58
    bool lock(bool initial = false);
 
59
 
 
60
    /**
 
61
     * start the screensaver unlocked
 
62
     */
 
63
    bool defaultSave();
 
64
 
 
65
    /**
 
66
     * start the screensaver in plasma setup mode
 
67
     * if plasma is disabled this just acts like defaultSave
 
68
     */
 
69
    bool startSetup();
 
70
 
 
71
    /**
 
72
     * start the screensaver unlocked, and *never* automatically lock it
 
73
     */
 
74
    bool dontLock();
 
75
 
 
76
    void setChildren(QList<int> children) { child_sockets = children; }
 
77
    void setParent(int fd) { mParent = fd; }
 
78
 
 
79
    void msgBox( QWidget *parent, QMessageBox::Icon type, const QString &txt );
 
80
    int execDialog( QDialog* dlg );
 
81
 
 
82
public Q_SLOTS:
 
83
    void quitSaver();
 
84
    //dbus methods
 
85
    /**
 
86
     * bring up the password dialog with @param reason displayed instead of the usual "this session
 
87
     * is locked" message.
 
88
     * @return true if the password was entered correctly
 
89
     * if this returns true, it will also unlock the screensaver without quitting.
 
90
     * it will re-lock after the lock timeout in the settings
 
91
     */
 
92
    Q_SCRIPTABLE bool checkPass(const QString &reason);
 
93
    /**
 
94
     * this will unlock and quit the screensaver, asking for a password first if necessary
 
95
     */
 
96
    Q_SCRIPTABLE void quit();
 
97
    /**
 
98
     * immediately lock the screen; it will now require a password to unlock.
 
99
     */
 
100
    Q_SCRIPTABLE bool startLock();
 
101
 
 
102
protected:
 
103
    virtual bool x11Event(XEvent *);
 
104
    virtual void timerEvent(QTimerEvent *);
 
105
    virtual bool eventFilter(QObject *o, QEvent *e);
 
106
 
 
107
private Q_SLOTS:
 
108
    void hackExited();
 
109
    void signalPipeSignal();
 
110
    void suspend();
 
111
    void checkDPMSActive();
 
112
    void slotDeadTimePassed();
 
113
    /**
 
114
     * check that plasma started properly (used for timeout)
 
115
     * and disable it if it failed
 
116
     */
 
117
    void checkPlasma();
 
118
    /**
 
119
     * a new dbus service has come in
 
120
     */
 
121
    void newService(QString name, QString oldOwner, QString newOwner);
 
122
    /**
 
123
     * tell plasma we're in idle mode
 
124
     */
 
125
    void deactivatePlasma();
 
126
    void lockPlasma();
 
127
    /**
 
128
     * immediately un-suppress the password dialog
 
129
     * FIXME need a better name
 
130
     */
 
131
    void unSuppressUnlock();
 
132
 
 
133
private:
 
134
    void configure();
 
135
    void readSaver();
 
136
    void createSaverWindow();
 
137
    void hideSaverWindow();
 
138
    void saveVRoot();
 
139
    void setVRoot(Window win, Window rw);
 
140
    void removeVRoot(Window win);
 
141
    bool grabKeyboard();
 
142
    bool grabMouse();
 
143
    bool grabInput();
 
144
    void ungrabInput();
 
145
    void cantLock(const QString &reason);
 
146
    bool startSaver();
 
147
    void stopSaver();
 
148
    bool startHack();
 
149
    void stopHack();
 
150
    bool startPlasma();
 
151
    void stopPlasma();
 
152
    void setupSignals();
 
153
    /**
 
154
     * exec the password dialog
 
155
     * @return true iff the password was checked and is valid
 
156
     */
 
157
    bool checkPass();
 
158
    /**
 
159
     * returns true if plasma is up and the dbus interface is valid
 
160
     */
 
161
    bool isPlasmaValid();
 
162
    /**
 
163
     * give up on plasma, probably because it crashed.
 
164
     * this does *not* tell plasma to quit. it just stops using it.
 
165
     */
 
166
    void disablePlasma();
 
167
    /**
 
168
     * give a fakefocusin to the right window
 
169
     */
 
170
    void updateFocus();
 
171
    void stayOnTop();
 
172
    int findWindowInfo( Window window ); // returns index in windowInfo or -1
 
173
    void lockXF86();
 
174
    void unlockXF86();
 
175
    void resume( bool force );
 
176
    enum WindowType { IgnoreWindow = 0 /** regular window to be left below the saver */,
 
177
                      SimpleWindow = 1 /** simple popup that can't handle direct input */,
 
178
                      InputWindow = 2  /** annoying dialog that needs direct input */,
 
179
                      DefaultWindow = 6/** input window that's also the plasma view */
 
180
    };
 
181
    /**
 
182
     * @return the type of window, based on its X property
 
183
     */
 
184
    WindowType windowType(WId id);
 
185
 
 
186
    static QVariant getConf(void *ctx, const char *key, const QVariant &dflt);
 
187
    bool loadGreetPlugin();
 
188
 
 
189
    bool        mInitialLock;
 
190
    bool        mLocked;
 
191
    int         mLockGrace;
 
192
    int         mPriority;
 
193
    bool        mBusy;
 
194
    KProcess    mHackProc;
 
195
    org::kde::plasmaoverlay::App *mPlasmaDBus;
 
196
    QDBusServiceWatcher *mServiceWatcher;
 
197
    bool        mPlasmaEnabled;
 
198
    bool        mSetupMode;
 
199
    QString     mSaverExec;
 
200
    QString     mSaver;
 
201
    bool        mOpenGLVisual;
 
202
    bool        child_saver;
 
203
    QList<int> child_sockets;
 
204
    int         mParent;
 
205
    bool        mUseBlankOnly;
 
206
    bool        mSuspended;
 
207
    QTimer      mSuspendTimer;
 
208
    bool        mVisibility;
 
209
    bool        mDPMSDepend;
 
210
    QTimer      mCheckDPMS;
 
211
    QStack< QWidget* > mDialogs;
 
212
    QHash< QWidget*, QWidget* > mFrames;
 
213
    QList<WId>  mVisibleDialogs;
 
214
    QQueue<XEvent> mEventQueue;
 
215
    bool        mEventRecursed;
 
216
    bool        mRestoreXF86Lock;
 
217
    bool        mForbidden;
 
218
    QStringList mPlugins, mPluginOptions;
 
219
    QString     mMethod;
 
220
    GreeterPluginHandle greetPlugin;
 
221
    QPixmap     mSavedScreen;
 
222
    QTimer      mSnapshotTimer;
 
223
    int         mAutoLogoutTimerId;
 
224
    int         mAutoLogoutTimeout;
 
225
    QTimer      mSuppressUnlock;
 
226
    int         mSuppressUnlockTimeout;
 
227
    QList<WId>  mForeignWindows;
 
228
    QList<WId>  mForeignInputWindows;
 
229
    struct WindowInfo
 
230
    {
 
231
        Window window;
 
232
        bool viewable;
 
233
    };
 
234
    QList<WindowInfo> windowInfo;
 
235
};
 
236
 
 
237
#endif
 
238