00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "accounts.h"
00028 #include "authwidget.h"
00029 #include "pppdata.h"
00030 #include "edit.h"
00031
00032
00033 #include <opie2/odebug.h>
00034 #include <qpe/qpeapplication.h>
00035 using namespace Opie::Core;
00036
00037
00038 #include <qdir.h>
00039 #include <qlayout.h>
00040 #include <qtabwidget.h>
00041 #include <qtabdialog.h>
00042 #include <qwhatsthis.h>
00043 #include <qmessagebox.h>
00044 #include <qapplication.h>
00045 #include <qbuttongroup.h>
00046 #include <qmessagebox.h>
00047 #include <qvgroupbox.h>
00048
00049
00050 #include <stdlib.h>
00051
00052 void parseargs(char* buf, char** args);
00053
00054
00055 AccountWidget::AccountWidget( PPPData *pd, QWidget *parent, const char *name, WFlags f )
00056 : ChooserWidget( pd, parent, name, f )
00057 {
00058
00059 QWhatsThis::add(edit_b, tr("Allows you to modify the selected account"));
00060 QWhatsThis::add(new_b, tr("Create a new dialup connection\n"
00061 "to the Internet"));
00062 QWhatsThis::add(copy_b,
00063 tr("Makes a copy of the selected account. All\n"
00064 "settings of the selected account are copied\n"
00065 "to a new account, that you can modify to fit your\n"
00066 "needs"));
00067 QWhatsThis::add(delete_b,
00068 tr("<p>Deletes the selected account\n\n"
00069 "<font color=\"red\"><b>Use with care!</b></font>"));
00070
00071
00072
00073 copy_b->setEnabled( false );
00074
00075
00076 listListbox->insertStringList(_pppdata->getAccountList());
00077
00078 for (uint i = 0; i < listListbox->count(); i++)
00079 {
00080 if ( listListbox->text(i) == _pppdata->accname() )
00081 listListbox->setCurrentItem( i );
00082 }
00083 }
00084
00085
00086
00087 void AccountWidget::slotListBoxSelect(int idx)
00088 {
00089 bool ok = _pppdata->setAccount( listListbox->text(idx) );
00090 ok = (bool)(idx != -1);
00091 delete_b->setEnabled(ok);
00092 edit_b->setEnabled(ok);
00093
00094 }
00095
00096 void AccountWidget::edit()
00097 {
00098 _pppdata->setAccount(listListbox->text(listListbox->currentItem()));
00099
00100 int result = doTab();
00101
00102 if(result == QDialog::Accepted)
00103 {
00104 listListbox->changeItem(_pppdata->accname(),listListbox->currentItem());
00105
00106 _pppdata->save();
00107 }
00108 }
00109
00110
00111 void AccountWidget::create()
00112 {
00113
00114
00115
00116
00117
00118
00119
00120 int result;
00121 if (_pppdata->newaccount() == -1)
00122 {
00123 odebug << "_pppdata->newaccount() == -1" << oendl;
00124 return;
00125 }
00126 result = doTab();
00127
00128 if(result == QDialog::Accepted)
00129 {
00130 listListbox->insertItem(_pppdata->accname());
00131 listListbox->setSelected(listListbox->findItem(_pppdata->accname()),true);
00132
00133 _pppdata->save();
00134 }
00135 else
00136 _pppdata->deleteAccount();
00137 }
00138
00139
00140 void AccountWidget::copy()
00141 {
00142
00143
00144
00145
00146
00147 if(listListbox->currentItem()<0)
00148 {
00149 QMessageBox::information(this, "sorry", tr("No account selected."));
00150 return;
00151 }
00152
00153 _pppdata->copyaccount(listListbox->currentText());
00154
00155 listListbox->insertItem(_pppdata->accname());
00156
00157 _pppdata->save();
00158 }
00159
00160
00161 void AccountWidget::remove()
00162 {
00163
00164 QString s = tr("Are you sure you want to delete\nthe account \"%1\"?")
00165 .arg(listListbox->text(listListbox->currentItem()));
00166
00167 if(QMessageBox::warning(this,tr("Confirm"),s,
00168 QMessageBox::Yes,QMessageBox::No
00169 ) != QMessageBox::Yes)
00170 return;
00171
00172 if(_pppdata->deleteAccount(listListbox->text(listListbox->currentItem())))
00173 listListbox->removeItem(listListbox->currentItem());
00174
00175
00176
00177
00178
00179
00180 slotListBoxSelect(listListbox->currentItem());
00181
00182 }
00183
00184
00185 int AccountWidget::doTab()
00186 {
00187 QDialog *dlg = new QDialog( 0, "newAccount", true, Qt::WStyle_ContextHelp );
00188 QVBoxLayout *layout = new QVBoxLayout( dlg );
00189 layout->setSpacing( 0 );
00190 layout->setMargin( 1 );
00191
00192 QTabWidget *tabWindow = new QTabWidget( dlg, "tabWindow" );
00193 layout->addWidget( tabWindow );
00194
00195 bool isnewaccount;
00196
00197 if(_pppdata->accname().isEmpty())
00198 {
00199 dlg->setCaption(tr("New Account"));
00200 isnewaccount = true;
00201 }
00202 else
00203 {
00204 QString tit = tr("Edit Account: ");
00205 tit += _pppdata->accname();
00206 dlg->setCaption(tit);
00207 isnewaccount = false;
00208 }
00209
00210
00211 dial_w = new DialWidget( _pppdata, tabWindow, isnewaccount, "Dial Setup");
00212 tabWindow->addTab( dial_w, tr("Dial") );
00213
00214
00215 auth_w = new AuthWidget( _pppdata, tabWindow, isnewaccount, tr("Edit Login Script"));
00216 tabWindow->addTab( auth_w, tr("Authentication") );
00217
00218
00219 ip_w = new IPWidget( _pppdata, tabWindow, isnewaccount, tr("IP Setup"));
00220 tabWindow->addTab( ip_w, tr("IP") );
00221
00222
00223 gateway_w = new GatewayWidget( _pppdata, tabWindow, isnewaccount, tr("Gateway Setup"));
00224 tabWindow->addTab( gateway_w, tr("Gateway") );
00225
00226
00227 dns_w = new DNSWidget( _pppdata, tabWindow, isnewaccount, tr("DNS Servers") );
00228 tabWindow->addTab( dns_w, tr("DNS") );
00229
00230
00231 ExecWidget *exec_w = new ExecWidget( _pppdata, tabWindow, isnewaccount, tr("Execute Programs"));
00232 tabWindow->addTab( exec_w, tr("Execute") );
00233
00234 int result = 0;
00235 bool ok = false;
00236
00237 while (!ok)
00238 {
00239 result = QPEApplication::execDialog( dlg );
00240 ok = true;
00241
00242 if(result == QDialog::Accepted)
00243 {
00244 if (!auth_w->check())
00245 {
00246 ok = false;
00247 }
00248 else if(!dial_w->save())
00249 {
00250 QMessageBox::critical(this, "error", tr( "You must enter a unique account name"));
00251 ok = false;
00252 }
00253 else
00254 {
00255 ip_w->save();
00256 dns_w->save();
00257 gateway_w->save();
00258 auth_w->save();
00259 exec_w->save();
00260 }
00261 }
00262 }
00263
00264 delete dlg;
00265
00266 return result;
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00292
00293
00294
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351