author | tille <tille> | 2003-06-03 14:08:04 (UTC) |
---|---|---|
committer | tille <tille> | 2003-06-03 14:08:04 (UTC) |
commit | 60d9f66d2b31c659ac652c15423ecaca89a5f312 (patch) (unidiff) | |
tree | bfda269b58eb1c72893057d9d7fae5a6a2e45abc /noncore/settings/networksettings/ppp/authwidget.cpp | |
parent | aaf7709f64dda5a6cb81eeb96e421ba4189654d6 (diff) | |
download | opie-60d9f66d2b31c659ac652c15423ecaca89a5f312.zip opie-60d9f66d2b31c659ac652c15423ecaca89a5f312.tar.gz opie-60d9f66d2b31c659ac652c15423ecaca89a5f312.tar.bz2 |
authentication (except when passwd not stored)
and minor things
Diffstat (limited to 'noncore/settings/networksettings/ppp/authwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/authwidget.cpp | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/noncore/settings/networksettings/ppp/authwidget.cpp b/noncore/settings/networksettings/ppp/authwidget.cpp new file mode 100644 index 0000000..86bea98 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/authwidget.cpp | |||
@@ -0,0 +1,195 @@ | |||
1 | |||
2 | #include <qlayout.h> | ||
3 | #include <qmessagebox.h> | ||
4 | #include <qtoolbutton.h> | ||
5 | #include <qwhatsthis.h> | ||
6 | |||
7 | #include "auth.h" | ||
8 | #include "authwidget.h" | ||
9 | #include "edit.h" | ||
10 | #include "pppdata.h" | ||
11 | |||
12 | |||
13 | static const char* const image0_data[] = { | ||
14 | "16 16 2 1", | ||
15 | ". c None", | ||
16 | "# c #000000", | ||
17 | "................", | ||
18 | "...#...###...##.", | ||
19 | "..#.#..#..#.##..", | ||
20 | "..###..###.##...", | ||
21 | ".#...#.#..##....", | ||
22 | ".#...#.#.##.....", | ||
23 | "........##.#..#.", | ||
24 | "..##...##...##..", | ||
25 | ".#..#.###...##..", | ||
26 | ".#...##..#.#..#.", | ||
27 | ".#..##..........", | ||
28 | ".#.##.#..#.#..#.", | ||
29 | "..##...##...##..", | ||
30 | ".##....##...##..", | ||
31 | ".#....#..#.#..#.", | ||
32 | "................"}; | ||
33 | |||
34 | |||
35 | AuthWidget::AuthWidget(PPPData *pd, QWidget *parent, bool isnewaccount, const char *name ) | ||
36 | : QWidget( parent, name), | ||
37 | scriptWidget(0), | ||
38 | _pppdata(pd), | ||
39 | isNewAccount(isnewaccount) | ||
40 | { | ||
41 | layout = new QGridLayout(this); | ||
42 | |||
43 | auth_l = new QLabel(tr("Authentication: "), this); | ||
44 | layout->addWidget(auth_l, 0, 0); | ||
45 | |||
46 | auth = new QComboBox(this); | ||
47 | auth->insertItem(tr("Script-based")); | ||
48 | auth->insertItem(tr("PAP")); | ||
49 | auth->insertItem(tr("Terminal-based")); | ||
50 | auth->insertItem(tr("CHAP")); | ||
51 | auth->insertItem(tr("PAP/CHAP")); | ||
52 | layout->addWidget(auth, 0, 1); | ||
53 | |||
54 | connect( auth, SIGNAL(activated(const QString&)), | ||
55 | SLOT(authChanged(const QString&))); | ||
56 | |||
57 | QString tmp = tr("<p>Specifies the method used to identify yourself to\n" | ||
58 | "the PPP server. Most universities still use\n" | ||
59 | "<b>Terminal</b>- or <b>Script</b>-based authentication,\n" | ||
60 | "while most ISP use <b>PAP</b> and/or <b>CHAP</b>. If\n" | ||
61 | "unsure, contact your ISP.\n" | ||
62 | "\n" | ||
63 | "If you can choose between PAP and CHAP,\n" | ||
64 | "choose CHAP, because it's much safer. If you don't know\n" | ||
65 | "whether PAP or CHAP is right, choose PAP/CHAP."); | ||
66 | |||
67 | QWhatsThis::add(auth_l,tmp); | ||
68 | QWhatsThis::add(auth,tmp); | ||
69 | |||
70 | user_l = new QLabel( tr("Username: "), this); | ||
71 | layout->addWidget( user_l, 1, 0 ); | ||
72 | userName = new QLineEdit( this, "usernameEdit" ); | ||
73 | layout->addWidget( userName, 1, 1 ); | ||
74 | tmp = tr("Enter your username here..."); | ||
75 | QWhatsThis::add( user_l, tmp ); | ||
76 | QWhatsThis::add( userName, tmp ); | ||
77 | |||
78 | pw_l = new QLabel( tr("Password: "), this); | ||
79 | layout->addWidget( pw_l, 2, 0 ); | ||
80 | passWord = new QLineEdit( this, "pw" ); | ||
81 | passWord->setAutoMask( true ); | ||
82 | passWord->setEchoMode( QLineEdit::Password ); | ||
83 | layout->addWidget( passWord, 2, 1 ); | ||
84 | hidePw = new QToolButton( this ); | ||
85 | hidePw->setPixmap( QPixmap( ( const char** ) image0_data ) ); | ||
86 | hidePw->setToggleButton( true ); | ||
87 | layout->addWidget( hidePw, 2, 2 ); | ||
88 | |||
89 | connect(hidePw, SIGNAL(toggled(bool)), SLOT(toggleEchoMode(bool))); | ||
90 | |||
91 | tmp = tr("Enter your password here"); | ||
92 | QWhatsThis::add( pw_l, tmp ); | ||
93 | QWhatsThis::add( passWord, tmp ); | ||
94 | |||
95 | store_password = new QCheckBox(tr("Store password"), this); | ||
96 | layout->addMultiCellWidget(store_password, 3, 3, 0, 1, AlignRight); | ||
97 | QWhatsThis::add(store_password, | ||
98 | tr("<p>When this is turned on, your ISP password\n" | ||
99 | "will be saved in <i>kppp</i>'s config file, so\n" | ||
100 | "you do not need to type it in every time.\n" | ||
101 | "\n" | ||
102 | "<b><font color=\"red\">Warning:</font> your password will be stored as\n" | ||
103 | "plain text in the config file, which is\n" | ||
104 | "readable only to you. Make sure nobody\n" | ||
105 | "gains access to this file!")); | ||
106 | |||
107 | if (isNewAccount){ | ||
108 | // select PAP/CHAP as default | ||
109 | auth->setCurrentItem(AUTH_PAPCHAP); | ||
110 | store_password->setChecked(true); | ||
111 | }else{ | ||
112 | auth->setCurrentItem(_pppdata->authMethod()); | ||
113 | authChanged( auth->currentText() ); | ||
114 | userName->setText( _pppdata->storedUsername() ); | ||
115 | store_password->setChecked(_pppdata->storePassword()); | ||
116 | if (store_password->isChecked()) | ||
117 | passWord->setText( _pppdata->storedPassword() ); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | bool AuthWidget::check() | ||
122 | { | ||
123 | bool ret = true; | ||
124 | if (scriptWidget){ | ||
125 | if (!scriptWidget->check()){ | ||
126 | QMessageBox::critical(this, tr("error"), tr("<qt>Login script has unbalanced loop Start/End<qt>")); | ||
127 | ret = false; | ||
128 | } | ||
129 | } | ||
130 | return ret; | ||
131 | } | ||
132 | |||
133 | void AuthWidget::save() | ||
134 | { | ||
135 | _pppdata->setAuthMethod(auth->currentItem()); | ||
136 | if (scriptWidget) scriptWidget->save(); | ||
137 | _pppdata->setStoredUsername( userName->text() ); | ||
138 | _pppdata->setStorePassword(store_password->isChecked()); | ||
139 | if (store_password->isChecked()) | ||
140 | _pppdata->setStoredPassword( passWord->text() ); | ||
141 | } | ||
142 | |||
143 | void AuthWidget::authChanged( const QString &authStr ) | ||
144 | { | ||
145 | qDebug("AuthWidget::authChanged( %s )", authStr.latin1() ); | ||
146 | if ( authStr.contains( tr("Script-based") ) ){ | ||
147 | showUsernamePassword( false ); | ||
148 | showScriptWindow( true ); | ||
149 | } else if ( authStr.contains( tr("PAP") ) || | ||
150 | authStr.contains( tr("CHAP") ) ){ | ||
151 | showUsernamePassword( true ); | ||
152 | showScriptWindow( false ); | ||
153 | } else { | ||
154 | qDebug("do not really know how to handle"); | ||
155 | showUsernamePassword( false ); | ||
156 | showScriptWindow( false ); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | |||
161 | void AuthWidget::showUsernamePassword( bool show ) | ||
162 | { | ||
163 | if (show){ | ||
164 | user_l->show(); | ||
165 | userName->show(); | ||
166 | pw_l->show(); | ||
167 | passWord->show(); | ||
168 | store_password->show(); | ||
169 | }else{//!show | ||
170 | user_l->hide(); | ||
171 | userName->hide(); | ||
172 | pw_l->hide(); | ||
173 | passWord->hide(); | ||
174 | store_password->hide(); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | void AuthWidget::showScriptWindow( bool show ) | ||
179 | { | ||
180 | if (show){ | ||
181 | if (!scriptWidget){ | ||
182 | scriptWidget = new ScriptWidget( _pppdata, this, isNewAccount, "scriptWid"); | ||
183 | layout->addMultiCellWidget( scriptWidget, 1, 4, 0, 1 ); | ||
184 | } | ||
185 | scriptWidget->show(); | ||
186 | }else{ // !show | ||
187 | if (scriptWidget) scriptWidget->hide(); | ||
188 | } | ||
189 | } | ||
190 | |||
191 | void AuthWidget::toggleEchoMode( bool t ) | ||
192 | { | ||
193 | passWord->setEchoMode( t ? QLineEdit::Normal : QLineEdit::Password ); | ||
194 | } | ||
195 | |||