summaryrefslogtreecommitdiff
path: root/libopie2/opiesecurity/multiauthmainwindow.cpp
Unidiff
Diffstat (limited to 'libopie2/opiesecurity/multiauthmainwindow.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiesecurity/multiauthmainwindow.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/libopie2/opiesecurity/multiauthmainwindow.cpp b/libopie2/opiesecurity/multiauthmainwindow.cpp
new file mode 100644
index 0000000..2be3473
--- a/dev/null
+++ b/libopie2/opiesecurity/multiauthmainwindow.cpp
@@ -0,0 +1,129 @@
1#include "multiauthmainwindow.h"
2
3#include "multiauthcommon.h"
4#include <qpe/config.h>
5
6/// Initializes widgets according to allowBypass and explanScreens config
7MultiauthMainWindow::MultiauthMainWindow()
8 : QDialog(0, "main Opie multiauth modal dialog", TRUE,
9 Qt::WStyle_NoBorder | Qt::WStyle_Customize | Qt::WStyle_StaysOnTop)
10
11{
12 alreadyDone = false;
13 // initializes widget pointers which not always point to an object
14 quit = 0;
15 message2 = 0;
16
17 Config *pcfg = new Config("Security");
18 pcfg->setGroup("Misc");
19 explanScreens = pcfg->readBoolEntry("explanScreens", true);
20 allowBypass = pcfg->readBoolEntry("allowBypass", true);
21 delete pcfg;
22
23 layout = new QVBoxLayout(this);
24 layout->setSpacing(11);
25 layout->setMargin(11);
26 layout->setAlignment( Qt::AlignTop );
27
28 // if explanScreens is false, we don't show any text in the QDialog,
29 // and we proceed directly
30 if ( explanScreens == true )
31 {
32 title = new QLabel("<center><h1>" + tr("Welcome to Opie Multi-authentication Framework") + "</h1></center>", this);
33 message = new QLabel("<center><h3>" + tr("Launching authentication plugins...") + "</h3></center>", this);
34 } else {
35 title = new QLabel("", this);
36 message = new QLabel("", this);
37 }
38
39 layout->addWidget(title);
40 layout->addWidget(message);
41 proceedButton = new QPushButton(tr("Proceed..."), this);
42 layout->addWidget(proceedButton, 0, Qt::AlignHCenter);
43
44 QObject::connect(proceedButton, SIGNAL(clicked()), this, SLOT(proceed()));
45
46 if ( explanScreens == true )
47 {
48 quit = new QPushButton("Exit", this);
49 layout->addWidget(quit, 0, Qt::AlignHCenter);
50 if ( allowBypass == true )
51 {
52 // very important: we can close the widget through the quit button, and bypass authentication, only if allowBypass is set!
53 message2 = new QLabel("<center><i>" + tr("Note: the 'exit' button should be removed for real protection, through Security config dialog") + ".</i></center>", this);
54 layout->addWidget(message2);
55 QObject::connect(quit, SIGNAL(clicked()), this, SLOT(close()));
56 }
57 else
58 {
59 quit->hide();
60 }
61
62 }
63 else
64 {
65 // we will need this button only if runPlugins() fails in proceed()
66 proceedButton->hide();
67 // let's proceed now
68 proceed();
69 }
70}
71
72/// nothing to do
73MultiauthMainWindow::~MultiauthMainWindow() {
74}
75
76/// launch the authentication
77void MultiauthMainWindow::proceed() {
78 int result = runPlugins();
79
80
81 if ( (result == 0) && !explanScreens )
82 {
83 // the authentication has succeeded, we can exit directly
84 // this will work if we haven't been called by the constructor of MultiauthMainWindow
85 close();
86 // and if we've been called by this constructor, we use this variable to tell our
87 // caller we're already done
88 alreadyDone = true;
89 return;
90 }
91 else
92 {
93
94 proceedButton->setText("Another try?");
95 QString resultMessage;
96
97 if (result == 0)
98 {
99 // authentication has succeeded, adapt interface then
100 message->setText( "<center><h3>" + tr("Congratulations! Your authentication has been successful.") + "</h3></center>" );
101 quit->setText("Enter Opie");
102 if ( quit->isHidden() )
103 {
104 // that means we don't allow to bypass, but now we can show and connect this button
105 QObject::connect(quit, SIGNAL(clicked()), this, SLOT(close()));
106 quit->show();
107 } else {
108 if ( message2 != 0 ) message2->hide();
109 }
110 }
111 else
112 {
113 // authentication has failed, explain that according to allowBypass
114 message->setText( "<center><h3>" + tr("You have not succeeded enough authentication steps!") + "</h3></center>" );
115 proceedButton->show();
116 if ( allowBypass == true )
117 message2->setText( "<center><p>" + tr("Note: if 'allow to bypass' was uncheck in Security config, you would have to go back through all the steps now.") + "</p></center>" );
118 }
119 }
120}
121
122/** When we don't show explanatory screens and we succeed authentication,
123 * as early as during the proceed() call of the constructor, the caller must know
124 * (through this function) authentication has already been succeeded..
125 * \todo try to avoid this hack?
126 */
127bool MultiauthMainWindow::isAlreadyDone() {
128 return alreadyDone;
129}