1/*
2
3Shell for kdm conversation plugins
4
5Copyright (C) 1997, 1998 Steffen Hansen <hansen@kde.org>
6Copyright (C) 2000-2004 Oswald Buddenhagen <ossi@kde.org>
7
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
23*/
24
25
26#ifndef KGVERIFY_H
27#define KGVERIFY_H
28
29#include "kgreeterplugin.h"
30#include "kfdialog.h"
31
32#include <QGridLayout>
33#include <QSet>
34#include <QTimer>
35
36#include <sys/time.h>
37#include <time.h>
38
39class KdmThemer;
40
41class KLibrary;
42class KPushButton;
43class QMenu;
44class QSocketNotifier;
45
46// helper class, nuke when qt supports suspend()/resume()
47class QXTimer : public QObject {
48 Q_OBJECT
49 typedef QObject inherited;
50
51 public:
52 QXTimer();
53 void start(int msec);
54 void stop();
55 void suspend();
56 void resume();
57
58 Q_SIGNALS:
59 void timeout();
60
61 private Q_SLOTS:
62 void slotTimeout();
63
64 private:
65 QTimer timer;
66 struct timeval stv;
67 long left;
68};
69
70class KGVerifyHandler {
71 public:
72 virtual ~KGVerifyHandler() {}
73 virtual void verifyPluginChanged(int id) = 0;
74 virtual void verifyClear();
75 virtual void verifyOk() = 0;
76 virtual void verifyFailed() = 0;
77 virtual void verifyRetry() = 0;
78 virtual void verifySetUser(const QString &user) = 0;
79 virtual void updateStatus(bool fail, bool caps, int left); // for themed only
80};
81
82struct GreeterPluginHandle {
83 KLibrary *library;
84 KGreeterPluginInfo *info;
85 QAction *action;
86};
87
88typedef QVector<int> PluginList;
89
90class KGVerify : public QObject, public KGreeterPluginHandler {
91 Q_OBJECT
92 typedef QObject inherited;
93
94 public:
95 KGVerify(KGVerifyHandler *handler,
96 QWidget *parent, QWidget *predecessor,
97 const QString &fixedEntity, const PluginList &pluginList,
98 KGreeterPlugin::Function func, KGreeterPlugin::Context ctx);
99 virtual ~KGVerify();
100 QMenu *getPlugMenu();
101 void loadUsers(const QStringList &users);
102 void presetEntity(const QString &entity, int field);
103 QString getEntity() const;
104 void setUser(const QString &user);
105 virtual void selectPlugin(int id);
106 bool entitiesLocal() const;
107 bool entitiesFielded() const;
108 bool entityPresettable() const;
109 bool isClassic() const;
110 QString pluginName() const;
111 void setEnabled(bool on);
112 void abort();
113 void suspend();
114 void resume();
115 void accept();
116 void reject();
117
118 enum { CoreIdle, CorePrompting, CoreBusy } coreState;
119
120 static bool handleFailVerify(QWidget *parent, bool showUser);
121 static PluginList init(const QStringList &plugins);
122 static void done();
123
124 public Q_SLOTS:
125 void start();
126
127 protected:
128 bool eventFilter(QObject *, QEvent *);
129 void msgBox(QMessageBox::Icon typ, const QString &msg);
130 void setTimer();
131 void updateLockStatus();
132 virtual void updateStatus() = 0;
133
134 QXTimer timer;
135 QString fixedEntity, presEnt, curUser, pamUser;
136 PluginList pluginList;
137 KGVerifyHandler *handler;
138 QSocketNotifier *sockNot;
139 QWidget *parent, *predecessor;
140 KGreeterPlugin *greet;
141 QMenu *plugMenu;
142 int curPlugin, presFld, timedLeft, deadTicks;
143 QByteArray pName;
144 KGreeterPlugin::Function func;
145 KGreeterPlugin::Context ctx;
146 bool capsLocked;
147 bool enabled, running, suspended, failed, delayed;
148 bool authTok, isClear, timeable;
149
150 static void vrfMsgBox(QWidget *parent, const QString &user, QMessageBox::Icon type, const QString &mesg);
151 static void vrfErrBox(QWidget *parent, const QString &user, const char *msg);
152 static void vrfInfoBox(QWidget *parent, const QString &user, const char *msg);
153
154 static QVector<GreeterPluginHandle> greetPlugins;
155
156 private:
157 bool applyPreset();
158 void performAutoLogin();
159 bool scheduleAutoLogin(bool initial);
160 void doReject(bool initial);
161 void talkerEdits();
162
163 private Q_SLOTS:
164 void slotPluginSelected(QAction *);
165 void slotTimeout();
166 void slotActivity();
167 void handleVerify();
168
169 public: // from KGreetPluginHandler
170 virtual void gplugReturnText(const char *text, int tag);
171 virtual void gplugReturnBinary(const char *data);
172 virtual void gplugSetUser(const QString &user);
173 virtual void gplugStart();
174 virtual void gplugChanged();
175 virtual void gplugActivity();
176 virtual void gplugMsgBox(QMessageBox::Icon type, const QString &text);
177
178 static QVariant getConf(void *ctx, const char *key, const QVariant &dflt);
179};
180
181class KGStdVerify : public KGVerify {
182 Q_OBJECT
183 typedef KGVerify inherited;
184
185 public:
186 KGStdVerify(KGVerifyHandler *handler, QWidget *parent,
187 QWidget *predecessor, const QString &fixedEntity,
188 const PluginList &pluginList,
189 KGreeterPlugin::Function func, KGreeterPlugin::Context ctx);
190 virtual ~KGStdVerify();
191 QLayout *getLayout() const { return grid; }
192 void selectPlugin(int id);
193
194 protected:
195 void updateStatus();
196
197 private:
198 QGridLayout *grid;
199 QLabel *failedLabel;
200 int failedLabelState;
201
202 public: // from KGreetPluginHandler
203 virtual bool gplugHasNode(const QString &id);
204};
205
206class KGThemedVerify : public KGVerify {
207 Q_OBJECT
208 typedef KGVerify inherited;
209
210 public:
211 KGThemedVerify(KGVerifyHandler *handler, KdmThemer *themer,
212 QWidget *parent, QWidget *predecessor,
213 const QString &fixedEntity,
214 const PluginList &pluginList,
215 KGreeterPlugin::Function func,
216 KGreeterPlugin::Context ctx);
217 virtual ~KGThemedVerify();
218 void selectPlugin(int id);
219
220 protected:
221 void updateStatus();
222
223 private:
224 KdmThemer *themer;
225 QSet<QString> showTypes;
226
227 public: // from KGreetPluginHandler
228 virtual bool gplugHasNode(const QString &id);
229};
230
231class KGChTok : public FDialog, public KGVerifyHandler {
232 Q_OBJECT
233 typedef FDialog inherited;
234
235 public:
236 KGChTok(QWidget *parent, const QString &user,
237 const PluginList &pluginList, int curPlugin,
238 KGreeterPlugin::Function func, KGreeterPlugin::Context ctx);
239 ~KGChTok();
240
241 public Q_SLOTS:
242 void accept();
243
244 private:
245 KPushButton *okButton, *cancelButton;
246 KGStdVerify *verify;
247
248 public: // from KGVerifyHandler
249 virtual void verifyPluginChanged(int id);
250 virtual void verifyOk();
251 virtual void verifyFailed();
252 virtual void verifyRetry();
253 virtual void verifySetUser(const QString &user);
254};
255
256#endif /* KGVERIFY_H */
257