Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

accounts.cpp

Go to the documentation of this file.
00001 /*
00002  *           kPPP: A pppd front end for the KDE project
00003  *
00004  * $Id: accounts.cpp,v 1.13 2004/04/09 15:00:07 mickeyl Exp $
00005  *
00006  *            Copyright (C) 1997 Bernd Johannes Wuebben
00007  *                   wuebben@math.cornell.edu
00008  *
00009  * based on EzPPP:
00010  * Copyright (C) 1997  Jay Painter
00011  *
00012  * This program is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU Library General Public
00014  * License as published by the Free Software Foundation; either
00015  * version 2 of the License, or (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Library General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU Library General Public
00023  * License along with this program; if not, write to the Free
00024  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00025  */
00026 
00027 #include "accounts.h"
00028 #include "authwidget.h"
00029 #include "pppdata.h"
00030 #include "edit.h"
00031 
00032 /* OPIE */
00033 #include <opie2/odebug.h>
00034 #include <qpe/qpeapplication.h>
00035 using namespace Opie::Core;
00036 
00037 /* QT */
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 /* STD */
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 ); //FIXME
00074     //  delete_b->setEnabled( false ); //FIXME
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     //FIXME  copy_b->setEnabled(ok);
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         //    emit resetaccounts();
00106         _pppdata->save();
00107     }
00108 }
00109 
00110 
00111 void AccountWidget::create()
00112 {
00113 
00114     //     if(listListbox->count() == MAX_ACCOUNTS) {
00115     //         QMessageBox::information(this, "sorry",
00116     //                                  tr("Maximum number of accounts reached."));
00117     //         return;
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     //   if(listListbox->count() == MAX_ACCOUNTS) {
00143     //     QMessageBox::information(this, "sorry", tr("Maximum number of accounts reached."));
00144     //     return;
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     //  emit resetaccounts();
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     //  emit resetaccounts();
00177     //  _pppdata->save();
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     //   // DIAL WIDGET
00211     dial_w = new DialWidget( _pppdata, tabWindow, isnewaccount, "Dial Setup");
00212     tabWindow->addTab( dial_w, tr("Dial") );
00213 
00214     //   // AUTH WIDGET
00215     auth_w = new AuthWidget( _pppdata, tabWindow, isnewaccount, tr("Edit Login Script"));
00216     tabWindow->addTab( auth_w, tr("Authentication") );
00217 
00218     //   // IP WIDGET
00219     ip_w = new IPWidget( _pppdata, tabWindow, isnewaccount, tr("IP Setup"));
00220     tabWindow->addTab( ip_w, tr("IP") );
00221 
00222     //   // GATEWAY WIDGET
00223     gateway_w = new GatewayWidget( _pppdata, tabWindow, isnewaccount, tr("Gateway Setup"));
00224     tabWindow->addTab( gateway_w, tr("Gateway") );
00225 
00226     //   // DNS WIDGET
00227     dns_w = new DNSWidget( _pppdata, tabWindow, isnewaccount, tr("DNS Servers") );
00228     tabWindow->addTab( dns_w, tr("DNS") );
00229 
00230     //   // EXECUTE WIDGET
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 // QString AccountWidget::prettyPrintVolume(unsigned int n) {
00271 //   int idx = 0;
00272 //   const QString quant[] = {tr("Byte"), tr("KB"),
00273 //                 tr("MB"), tr("GB"), QString::null};
00274 
00275 //   float n1 = n;
00276 //   while(n >= 1024 && quant[idx] != QString::null) {
00277 //     idx++;
00278 //     n /= 1024;
00279 //   }
00280 
00281 //   int i = idx;
00282 //   while(i--)
00283 //     n1 = n1 / 1024.0;
00284 
00285 //   QString s = QString::number( n1, 'f', idx==0 ? 0 : 1 );
00286 //   s += " " + quant[idx];
00287 //   return s;
00288 // }
00289 
00290 
00292 //
00293 // Queries the user what to reset: costs, volume or both
00294 //
00296 // QueryReset::QueryReset(QWidget *parent) : QDialog(parent, 0, true) {
00297 // //  KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon());
00298 //   setCaption(tr("Reset Accounting"));
00299 
00300 //   QVBoxLayout *tl = new QVBoxLayout(this, 10, 10);
00301 //   QVGroupBox *f = new QVGroupBox(tr("What to Reset"), this);
00302 
00303 //   QVBoxLayout *l1 = new QVBoxLayout(this, 10, 10);
00304 // //   costs = new QCheckBox(tr("Reset the accumulated phone costs"), f);
00305 // //   costs->setChecked(true);
00306 // //   l1->addWidget(costs);
00307 // //   QWhatsThis::add(costs, tr("Check this to set the phone costs\n"
00308 // //                         "to zero. Typically you'll want to\n"
00309 // //                         "do this once a month."));
00310 
00311 // //   volume = new QCheckBox(tr("Reset volume accounting"), f);
00312 // //   volume->setChecked(true);
00313 // //   l1->addWidget(volume);
00314 // //   QWhatsThis::add(volume, tr("Check this to set the volume accounting\n"
00315 // //                          "to zero. Typically you'll want to do this\n"
00316 // //                          "once a month."));
00317 
00318 //   l1->activate();
00319 
00320 //   // this activates the f-layout and sets minimumSize()
00321 //   f->show();
00322 
00323 //   tl->addWidget(f);
00324 
00325 //   QButtonGroup *bbox = new QButtonGroup(this);
00326 // //  bbox->addStretch(1);
00327 //   QPushButton *ok = new QPushButton( bbox, tr("OK") );
00328 //   bbox->insert(ok);
00329 //   ok->setDefault(true);
00330 //   QPushButton *cancel = new QPushButton( bbox, tr("Cancel") );
00331 //   bbox->insert(cancel);
00332 
00333 //   connect(ok, SIGNAL(clicked()),
00334 //        this, SLOT(accepted()));
00335 //   connect(cancel, SIGNAL(clicked()),
00336 //        this, SLOT(reject()));
00337 
00338 //   bbox->layout();
00339 //   tl->addWidget(bbox);
00340 
00341 // }
00342 
00343 
00344 // void QueryReset::accepted() {
00345 //   int result = costs->isChecked() ? COSTS : 0;
00346 //   result += volume->isChecked() ? VOLUME : 0;
00347 
00348 //   done(result);
00349 // }
00350 
00351 

Generated on Sat Nov 5 16:17:49 2005 for OPIE by  doxygen 1.4.2