1 //---------------------------------------------------------------------------
3 // kPPP: A pppd front end for the KDE project
5 //---------------------------------------------------------------------------
7 // (c) 1997-1998 Bernd Johannes Wuebben <wuebben@kde.org>
8 // (c) 1997-1999 Mario Weilguni <mweilguni@kde.org>
9 // (c) 1998-1999 Harri Porten <porten@kde.org>
11 // derived from Jay Painters "ezppp"
13 //---------------------------------------------------------------------------
15 // This program is free software; you can redistribute it and-or
16 // modify it under the terms of the GNU Library General Public
17 // License as published by the Free Software Foundation; either
18 // version 2 of the License, or (at your option) any later version.
20 // This program is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 // Library General Public License for more details.
25 // You should have received a copy of the GNU Library General Public
26 // License along with this program; if not, write to the Free
27 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 //---------------------------------------------------------------------------
37 #include <QGridLayout>
38 #include <QHBoxLayout>
39 #include <QVBoxLayout>
41 #include <kstandarddirs.h>
43 #include "providerdb.h"
44 #include "newwidget.h"
46 #include <q3listbox.h>
47 #include <qlineedit.h>
49 #include <kdesktopfile.h>
51 #define UNENCODED_CHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"
53 Q3Wizard
* ProviderDB::wiz
= 0L;
55 ProviderDB::ProviderDB(QWidget
*parent
) :
56 K3Wizard(parent
, "", true),
59 setWindowTitle(i18n("Create New Account"));
63 page1
= new PDB_Intro(this);
65 setHelpEnabled(page1
, false);
66 // TODO p1->w->setFocusPolicy(StrongFocus);
68 page2
= new PDB_Country(this);
70 setHelpEnabled(page2
, false);
72 page3
= new PDB_Provider(this);
74 setHelpEnabled(page3
, false);
76 page4
= new PDB_UserInfo(this);
78 setHelpEnabled(page4
, false);
80 page5
= new PDB_DialPrefix(this);
82 setHelpEnabled(page5
, false);
84 page9
= new PDB_Finished(this);
86 setHelpEnabled(page9
, false);
87 setFinish(page9
, true);
88 setFinishEnabled(page9
, true);
90 connect((const QObject
*)nextButton(), SIGNAL(clicked()),
91 this, SLOT(pageSelected()));
92 connect((const QObject
*)backButton(), SIGNAL(clicked()),
93 this, SLOT(pageSelected()));
95 // resize(minimumSize());
100 ProviderDB::~ProviderDB() {
105 void ProviderDB::pageSelected() {
109 QWidget
*page
= currentPage();
111 next
= page2
->lb
->currentItem() != -1;
112 } else if(page
== page3
) {
113 page3
->setDir(page2
->list
->at(page2
->lb
->currentItem()));
114 next
= page3
->lb
->currentItem() != -1;
115 } else if(page
== page4
) {
117 next
= !page4
->username().isEmpty() &&
118 !page4
->password().isEmpty();
121 setBackEnabled(page
, prev
);
122 setNextEnabled(page
, next
);
126 void ProviderDB::loadProviderInfo() {
129 QString loc
= page2
->list
->at(page2
->lb
->currentItem());
130 QString provider
= page3
->lb
->text(page3
->lb
->currentItem());
132 QString prov
= "Provider/" + loc
;
133 prov
+= '/' + provider
;
134 QString fname
= KStandardDirs::locate("appdata", prov
);
135 kDebug(5002) << "Providerfile=" << fname
;
137 cfg
= new KConfig(fname
, KConfig::SimpleConfig
);
141 void ProviderDB::accept() {
142 QString usernamePlaceholder
="%USERNAME%";
143 QString passwordPlaceholder
="%PASSWORD%";
144 QString username
=page4
->username();
145 QString password
=page4
->password();
147 QMap
<QString
, QString
> map
=cfg
->entryMap("<default>");
148 QMap
<QString
, QString
>::Iterator it
=map
.begin();
149 while(it
!= map
.end()) {
150 QString key
= it
.key();
152 value
.replace(usernamePlaceholder
,username
);
153 value
.replace(passwordPlaceholder
,password
);
155 gpppdata
.writeConfig(gpppdata
.currentAccountGroup(), key
, value
);
158 gpppdata
.setAccname(value
);
162 map
=cfg
->entryMap(MODEM_GRP
);
163 for(it
=map
.begin(); it
!=map
.end(); ++it
) {
164 gpppdata
.writeConfig(gpppdata
.currentModemGroup(), it
.key(), *it
);
167 gpppdata
.writeConfig(gpppdata
.currentAccountGroup(), "DialPrefix", page5
->prefix());
172 /////////////////////////////////////////////////////////////////////////////
174 /////////////////////////////////////////////////////////////////////////////
175 PDB_Intro::PDB_Intro(QWidget
*parent
) : QWidget(parent
) {
176 QLabel
*l
= new QLabel(i18n("You will be asked a few questions on information\n"
177 "which is needed to establish an Internet connection\n"
178 "with your Internet Service Provider (ISP).\n\n"
179 "Make sure you have the registration form from your\n"
180 "ISP handy. If you have any problems, try the online\n"
181 "help first. If any information is missing, contact\n"
184 QVBoxLayout
*tl
= new QVBoxLayout(this);
192 /////////////////////////////////////////////////////////////////////////////
194 /////////////////////////////////////////////////////////////////////////////
195 PDB_Country::PDB_Country(QWidget
*parent
) : QWidget(parent
) {
196 //TODO when ported to MVC -- preselect country
198 QLabel
*l
= new QLabel(i18n("Select the location where you plan to use this\n"
199 "account from the list below. If your country or\n"
200 "location is not listed, you have to create the\n"
201 "account with the normal, dialog based setup.\n\n"
202 "If you click \"Cancel\", the dialog based setup\n"
205 QVBoxLayout
*tl
= new QVBoxLayout(this);
210 QHBoxLayout
*l1
= new QHBoxLayout
;
214 lb
= new Q3ListBox(this);
215 connect(lb
, SIGNAL(highlighted(int)),
216 this, SLOT(selectionChanged(int)));
217 lb
->setMinimumSize(220, 100);
218 l1
->addWidget(lb
, 2);
221 list
= new QStringList
;
225 QDir
d(KGlobal::dirs()->findDirs("appdata", "Provider").first());
226 d
.setFilter(QDir::Dirs
);
227 d
.setSorting(QDir::Name
);
229 // read the list of files
230 const QFileInfoList flist
= d
.entryInfoList();
232 QFileInfoList::const_iterator it
= flist
.begin();
233 QFileInfoList::const_iterator itEnd
= flist
.end();
235 // traverse the flist and insert into a map for sorting
236 QMap
<QString
, QString
> countries
;
237 for(; it
!= itEnd
; ++it
) {
239 if(fi
.fileName() != "." && fi
.fileName() != "..") {
240 QString
dirFile(fi
.absoluteFilePath()+"/.directory");
242 if(QFile::exists(dirFile
)){
243 KDesktopFile
config(dirFile
);
244 entryName
= config
.readName();
246 if (entryName
.isNull()) entryName
= fi
.fileName();
247 countries
.insert(entryName
, fi
.fileName());
250 // insert sorted entries into list box and string list
251 QMap
<QString
, QString
>::const_iterator mit
= countries
.begin();
252 QMap
<QString
, QString
>::const_iterator mend
= countries
.end();
254 lb
->insertItem(mit
.key());
263 PDB_Country::~PDB_Country()
268 void PDB_Country::selectionChanged(int idx
) {
269 // QWizard *wizard = (QWizard *)parent(); Why doesn't this work ?
270 ProviderDB::wiz
->setNextEnabled(this, (idx
!= -1));
274 /////////////////////////////////////////////////////////////////////////////
276 /////////////////////////////////////////////////////////////////////////////
277 PDB_Provider::PDB_Provider(QWidget
*parent
) : QWidget(parent
) {
278 QVBoxLayout
*tl
= new QVBoxLayout(this);
281 QLabel
*l
= new QLabel(i18n("Select your Internet Service Provider (ISP) from\n"
282 "the list below. If the ISP is not in this list,\n"
283 "you have to click on \"Cancel\" and create this\n"
284 "account using the normal, dialog-based setup.\n\n"
285 "Click on \"Next\" when you have finished your\n"
286 "selection."), this);
289 QHBoxLayout
*l1
= new QHBoxLayout
;
293 lb
= new Q3ListBox(this);
294 connect(lb
, SIGNAL(highlighted(int)),
295 this, SLOT(selectionChanged(int)));
296 lb
->setMinimumSize(220, 100);
297 l1
->addWidget(lb
, 2);
301 void PDB_Provider::selectionChanged(int idx
) {
302 ProviderDB::wiz
->setNextEnabled(this, idx
!= -1);
306 void PDB_Provider::setDir(const QString
&_dir
) {
314 QString dir1
= KGlobal::dirs()->findDirs("appdata", "Provider").first();
315 dir
= dir
.replace(' ', "_");
319 d
.setFilter(QDir::Files
);
320 d
.setSorting(QDir::Name
);
322 // read the list of files
323 const QFileInfoList list
= d
.entryInfoList();
324 QFileInfoList::const_iterator it
= list
.begin();
325 QFileInfoList::const_iterator itEnd
= list
.end();
328 // traverse the list and insert into the widget
331 QString fname
= fi
.fileName();
332 if(fname
.length() && fname
[0] != '.') {
334 lb
->insertItem(fname
);
339 // TODO: Qt 1.x needs this if list is empty
345 QString
PDB_Provider::getDir() {
351 /////////////////////////////////////////////////////////////////////////////
353 /////////////////////////////////////////////////////////////////////////////
354 PDB_UserInfo::PDB_UserInfo(QWidget
*parent
) : QWidget(parent
) {
355 QVBoxLayout
*tl
= new QVBoxLayout(this);
358 QLabel
*l
= new QLabel(i18n("To log on to your ISP, kppp needs the username\n"
359 "and the password you got from your ISP. Type\n"
360 "in this information in the fields below.\n\n"
361 "Word case is important here."),
365 QGridLayout
*l1
= new QGridLayout();
367 l
= new QLabel(i18n("Username:"), this);
368 l1
->addWidget(l
, 0, 0);
369 l
= new QLabel(i18n("Password:"), this);
370 l1
->addWidget(l
, 1, 0);
371 _username
= newLineEdit(24, this);
372 connect(_username
, SIGNAL(textChanged(const QString
&)),
373 this, SLOT(textChanged(const QString
&)));
374 l1
->addWidget(_username
, 0, 1);
375 _password
= newLineEdit(24, this);
376 _password
->setEchoMode(QLineEdit::Password
);
377 connect(_password
, SIGNAL(textChanged(const QString
&)),
378 this, SLOT(textChanged(const QString
&)));
379 l1
->addWidget(_password
, 1, 1);
384 void PDB_UserInfo::textChanged(const QString
&) {
385 ProviderDB::wiz
->setNextEnabled(this, !_password
->text().isEmpty() &&
386 !_username
->text().isEmpty());
390 QString
PDB_UserInfo::username() {
391 QString s
= _username
->text();
396 QString
PDB_UserInfo::password() {
397 QString s
= _password
->text();
402 void PDB_UserInfo::activate() {
403 _username
->setFocus();
407 /////////////////////////////////////////////////////////////////////////////
409 /////////////////////////////////////////////////////////////////////////////
410 PDB_DialPrefix::PDB_DialPrefix(QWidget
*parent
) : QWidget(parent
) {
411 QVBoxLayout
*tl
= new QVBoxLayout(this);
414 QLabel
*l
= new QLabel(i18n("If you need a special dial prefix (e.g. if you\n"
415 "are using a telephone switch) you can specify\n"
416 "it here. This prefix is dialed just before the\n"
418 "If you have a telephone switch, you probably need\n"
419 "to write \"0\" or \"0,\" here."),
423 QGridLayout
*l1
= new QGridLayout();
425 l
= new QLabel(i18n("Dial prefix:"), this);
426 l1
->addWidget(l
, 0, 0);
427 _prefix
= newLineEdit(24, this);
428 l1
->addWidget(_prefix
, 0, 1);
433 QString
PDB_DialPrefix::prefix() {
434 QString s
= _prefix
->text();
440 void PDB_DialPrefix::activate() {
445 /////////////////////////////////////////////////////////////////////////////
447 /////////////////////////////////////////////////////////////////////////////
448 PDB_Finished::PDB_Finished(QWidget
*parent
) : QWidget(parent
) {
449 QVBoxLayout
*tl
= new QVBoxLayout(this);
452 QLabel
*l
= new QLabel(i18n("Finished!\n\n"
453 "A new account has been created. Click \"Finish\" to\n"
454 "go back to the setup dialog. If you want to\n"
455 "check the settings of the newly created account,\n"
456 "you can use \"Edit\" in the setup dialog."),
462 //BEGIN pseudo percentencoding routines
463 void urlDecode(QString
&s
) {
466 for(int i
= 0; i
< s
.length(); i
++) {
468 s1
+= 100*s
[i
+1].digitValue() + 10*s
[i
+2].digitValue()
469 + s
[i
+3].digitValue();
480 void urlEncode(QString
&s
) {
483 for(int i
= 0; i
< s
.length(); i
++) {
484 if(QString(UNENCODED_CHARS
).indexOf(s
[i
]) >= 0)
487 tmp
.sprintf("%%%03i", s
[i
].unicode());
493 //END pseudo percentencoding routines
495 #include "providerdb.moc"