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

kpppwidget.cpp

Go to the documentation of this file.
00001 /*
00002  *
00003  *            kPPP: A pppd front end for the KDE project
00004  *
00005  * $Id: kpppwidget.cpp,v 1.8 2004/04/04 13:55:01 mickeyl Exp $
00006  *
00007  *            Copyright (C) 1997 Bernd Johannes Wuebben
00008  *                   wuebben@math.cornell.edu
00009  *
00010  *            Copyright (C) 1998-2002 Harri Porten <porten@kde.org>
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 "kpppwidget.h"
00028 
00029 #include <qapplication.h>
00030 #include <qcombobox.h>
00031 #include <qdir.h>
00032 #include <qevent.h>
00033 #include <qdialog.h>
00034 #include <qlabel.h>
00035 #include <qpushbutton.h>
00036 #include <qregexp.h>
00037 #include <qtabwidget.h>
00038 #include <qdialog.h>
00039 #include <qwhatsthis.h>
00040 #include <qcheckbox.h>
00041 
00042 // #include <kaboutdata.h>
00043 // #include <kapplication.h>
00044 #include <qbuttongroup.h>
00045 #include <qmessagebox.h>
00046 #include <qpushbutton.h>
00047 
00048 #include <stdlib.h>
00049 #include <errno.h>
00050 #include <signal.h>
00051 
00052 #include "runtests.h"
00053 
00054 //#include "main.h"
00055 #include "auth.h"
00056 #include "modem.h"
00057 //#include "ppplog.h"
00058 //#include "opener.h"
00059 //#include "requester.h"
00060 //#include "pppstats.h"
00061 #include "pppdata.h"
00062 #include "general.h"
00063 #include "interface.h"
00064 
00065 #define execute_command system
00066 
00067 KPPPWidget *p_kppp = 0;
00068 
00069 KPPPWidget::KPPPWidget(PPPData*pd, Interface *i, QWidget *parent, const char *name, bool modal, WFlags fl )
00070     : QDialog(parent, name, modal, Qt::WStyle_ContextHelp ), _pppdata(pd)
00071 {
00072 //  tabWindow = 0;
00073   p_kppp = this;
00074   // before doing anything else, run a few tests
00075     if (!_pppdata->setModemDevice( i->getInterfaceName() ))
00076         _pppdata->setModemDevice("/dev/modem");
00077     odebug << "PPPConfigWidget::PPPConfigWidget" << oendl; 
00078     odebug << " interface->getHardwareName >" << i->getHardwareName().latin1() << "<" << oendl; 
00079     if (!_pppdata->setAccount( i->getHardwareName() ))
00080         _pppdata->setAccount( 0 );
00081 
00082     odebug << " _pppdata->accname >" << _pppdata->accname().latin1() << "<" << oendl; 
00083     odebug << " _pppdata->currentAccountID() >" << _pppdata->currentAccountID() << "<" << oendl; 
00084 
00085   int result = runTests();
00086   if(result == TEST_CRITICAL)
00087     exit(4);
00088 
00089 //   installEventFilter(this);
00090 
00091   QVBoxLayout *tl = new QVBoxLayout(this, 10, 10);
00092 
00093   QGridLayout *l1 = new QGridLayout(3, 4);
00094   tl->addLayout(l1);
00095   l1->addColSpacing(0, 10);
00096   l1->addColSpacing(3, 10);
00097   l1->setColStretch(1, 3);
00098   l1->setColStretch(2, 4);
00099 
00100   label1 = new QLabel(QObject::tr("C&onnect to: "), this);
00101   l1->addWidget(label1, 0, 1);
00102 
00103   connectto_c = new QComboBox(false, this);
00104   label1->setBuddy(connectto_c);
00105 
00106   connect(connectto_c, SIGNAL(activated(int)),
00107           SLOT(newdefaultaccount(int)));
00108   l1->addWidget(connectto_c, 0, 2);
00109 
00110   ID_Label = new QLabel(QObject::tr("&Login ID:"), this);
00111   l1->addWidget(ID_Label, 1, 1);
00112 
00113   // the entry line for usernames
00114   ID_Edit = new QLineEdit(this);
00115   ID_Label->setBuddy(ID_Edit);
00116   l1->addWidget(ID_Edit, 1, 2);
00117   connect(ID_Edit, SIGNAL(returnPressed()),
00118           this, SLOT(enterPressedInID()));
00119   QString tmp = QObject::tr("<p>Type in the username that you got from your\n"
00120                      "ISP. This is especially important for PAP\n"
00121                      "and CHAP. You may omit this when you use\n"
00122                      "terminal-based or script-based authentication.\n"
00123                      "\n"
00124                      "<b>Important</b>: case is important here:\n"
00125                      "<i>myusername</i> is not the same as <i>MyUserName</i>!");
00126 
00127   QWhatsThis::add(ID_Label,tmp);
00128   QWhatsThis::add(ID_Edit,tmp);
00129 
00130   PW_Label = new QLabel(QObject::tr("&Password:"), this);
00131   l1->addWidget(PW_Label, 2, 1);
00132 
00133   PW_Edit= new QLineEdit(this);
00134   PW_Label->setBuddy(PW_Edit);
00135   PW_Edit->setEchoMode(QLineEdit::Password);
00136   l1->addWidget(PW_Edit, 2, 2);
00137   connect(PW_Edit, SIGNAL(returnPressed()),
00138           this, SLOT(enterPressedInPW()));
00139 
00140   tmp = QObject::tr("<p>Type in the password that you got from your\n"
00141              "ISP. This is especially important for PAP\n"
00142              "and CHAP. You may omit this when you use\n"
00143              "terminal-based or script-based authentication.\n"
00144              "\n"
00145              "<b>Important</b>: case is important here:\n"
00146              "<i>mypassword</i> is not the same as <i>MyPassword</i>!");
00147 
00148   QWhatsThis::add(PW_Label,tmp);
00149   QWhatsThis::add(PW_Edit,tmp);
00150 
00151    QHBoxLayout *l3 = new QHBoxLayout;
00152    tl->addSpacing(5);
00153    tl->addLayout(l3);
00154    tl->addSpacing(5);
00155    l3->addSpacing(10);
00156    log = new QCheckBox(QObject::tr("Show lo&g window"), this);
00157    connect(log, SIGNAL(toggled(bool)),
00158           this, SLOT(log_window_toggled(bool)));
00159    log->setChecked(_pppdata->get_show_log_window());
00160    l3->addWidget(log);
00161 
00162    QWhatsThis::add(log,
00163                   QObject::tr("<p>This controls whether a log window is shown.\n"
00164                        "A log window shows the communication between\n"
00165                        "<i>kppp</i> and your modem. This will help you\n"
00166                        "in tracking down problems.\n"
00167                        "\n"
00168                        "Turn it off if <i>kppp</i> routinely connects without\n"
00169                        "problems"));
00170 
00171 //  fline = new QSeparator( KSeparator::HLine, this);
00172 //  tl->addWidget(fline);
00173 
00174   QHBoxLayout *l2 = new QHBoxLayout(this);
00175   tl->addLayout(l2);
00176 
00177  int minw = 0;
00178   quit_b = new QPushButton(QObject::tr("&Quit"), this);
00179   // quit_b-> setGuiItem (KGuiItem(QObject::tr("&Quit"), "exit" ) );
00180   connect( quit_b, SIGNAL(clicked()), SLOT(quitbutton()));
00181   if(quit_b->sizeHint().width() > minw)
00182       minw = quit_b->sizeHint().width();
00183 
00184   setup_b = new QPushButton(QObject::tr("&Setup..."), this);
00185 // setup_b->setGuiItem (KGuiItem(QObject::tr("&Setup...")) );
00186   connect( setup_b, SIGNAL(clicked()), SLOT(expandbutton()));
00187   if(setup_b->sizeHint().width() > minw)
00188       minw = setup_b->sizeHint().width();
00189 
00190 
00191 
00192 //  if(_pppdata->access() != KConfig::ReadWrite)
00193   //  setup_b->setEnabled(false);
00194 
00195 //   help_b = new QPushButton(QObject::tr("&Help"), this);
00196 //   connect( help_b, SIGNAL(clicked()), SLOT(helpbutton()));
00197 
00198 //   KHelpMenu *helpMenu = new KHelpMenu(this, KGlobal::instance()->aboutData(), true);
00199 //   help_b->setPopup((QPopupMenu*)helpMenu->menu());
00200 //   help_b->setGuiItem (KGuiItem(QObject::tr("&Help"), "help" ) );
00201 
00202 //    if(help_b->sizeHint().width() > minw)
00203 //        minw = help_b->sizeHint().width();
00204 
00205   connect_b = new QPushButton(QObject::tr("&Connect"), this);
00206   connect_b->setDefault(true);
00207   connect_b->setFocus();
00208   connect(connect_b, SIGNAL(clicked()), SLOT(beginConnect()));
00209    if(connect_b->sizeHint().width() > minw)
00210        minw = connect_b->sizeHint().width();
00211 
00212   quit_b->setFixedWidth(minw);
00213   setup_b->setFixedWidth(minw);
00214 // help_b->setFixedWidth(help_b->sizeHint().width());
00215   connect_b->setFixedWidth(minw);
00216 
00217   l2->addWidget(quit_b);
00218   l2->addWidget(setup_b);
00219 // l2->addWidget(help_b);
00220   l2->addSpacing(20);
00221   l2->addWidget(connect_b);
00222 
00223   setFixedSize(sizeHint());
00224 
00225   (void)new Modem(_pppdata);
00226 
00227   // we also connect cmld_start to the beginConnect so that I can run
00228   // the dialer through a command line argument
00229   connect(this,SIGNAL(cmdl_start()),this,SLOT(beginConnect()));
00230 
00231 //  stats = new PPPStats;
00232 
00233   // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon());
00234 
00235   // constructor of con_win reads position from config file
00236   con_win = new ConWindow(_pppdata, 0, "conw", this);
00237   // KWin::setIcons(con_win->winId(), kapp->icon(), kapp->miniIcon());
00238 
00239 //  statdlg = new PPPStatsDlg(0, "stats", this, stats);
00240 //  statdlg->hide();
00241 
00242   // load up the accounts combo box
00243 
00244 //  resetaccounts();
00245   con = new ConnectWidget(_pppdata, 0, "con");
00246   //KWin::setIcons(con->winId(), kapp->icon(), kapp->miniIcon() );
00247  connect(this, SIGNAL(begin_connect()),con, SLOT(preinit()));
00248   // Is this the best we can do here?  it's not right.
00249 //   QRect desk = QApplication::desktop()->screenGeometry(
00250 //                QApplication::desktop()->screenNumber(topLevelWidget()));
00251 //   con->setGeometry(desk.center().x()-175, desk.center().y()-55, 350,110);
00252 
00253   // connect the ConnectWidgets various signals
00254   connect(con, SIGNAL(startAccounting()),
00255           this, SLOT(startAccounting()));
00256   connect(con, SIGNAL(stopAccounting()),
00257           this, SLOT(stopAccounting()));
00258   connect(qApp, SIGNAL(saveYourself()),
00259           this, SLOT(saveMyself()));
00260   connect(qApp, SIGNAL(shutDown()),
00261           this, SLOT(shutDown()));
00262 
00263 
00264 //   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00265 
00266 //   m_strCmdlAccount = args->getOption("c");
00267 //   m_bQuitOnDisconnect = args->isSet("q");
00268 
00269 //   if(!m_strCmdlAccount.isEmpty()) {
00270 //     m_bCmdlAccount = true;
00271 //     kdDebug(5002) << "cmdl_account: " << m_bCmdlAccount << endl;
00272 //   }
00273 
00274 //   if(m_bCmdlAccount){
00275 //     bool result = _pppdata->setAccount(m_strCmdlAccount);
00276 //     if (!result){
00277 //       QString string;
00278 //       string = QObject::tr("No such Account:\n%1").arg(m_strCmdlAccount);
00279 //       KMessageBox::error(this, string);
00280 //       m_bCmdlAccount = false;
00281 //       this->show();
00282 //     } else {
00283 //       beginConnect();
00284 //     }
00285 //   } else
00286 //    expandbutton();
00287 //    show();
00288 
00289 
00290 //#define KPPP_SHOW_NEWS
00291 #ifdef KPPP_SHOW_NEWS
00292   // keep user informed about recent changes
00293   if(!m_bCmdlAccount)
00294     showNews();
00295 #endif
00296 }
00297 
00298 KPPPWidget::~KPPPWidget()
00299 {
00300     p_kppp = 0;
00301 //  delete stats;
00302 }
00303 
00304 // bool KPPPWidget::eventFilter(QObject *o, QEvent *e) {
00305 //   if(e->type() == QEvent::User) {
00306 //     switch(((SignalEvent*)e)->sigType()) {
00307 //     case SIGINT:
00308 //       odebug << "Received a SIGINT" << oendl; 
00309 //       interruptConnection();
00310 //       break;
00311 //     case SIGCHLD:
00312 //       sigChld();
00313 //       break;
00314 //     case SIGUSR1:
00315 //       sigPPPDDied();
00316 //       break;
00317 //     }
00318 //     return true;
00319 //   }
00320 
00321 //     if(o == connect_b) {
00322 //       if(e->type() == QEvent::KeyPress) {
00323 //         if(connect_b->hasFocus() && ((QKeyEvent *)e)->key() == Qt::Key_Return) {
00324 //           beginConnect();
00325 //           return true;
00326 //         }
00327 //       }
00328 //     }
00329 
00330 //     return false;
00331 // }
00332 
00333 
00334 
00335 
00336 void KPPPWidget::enterPressedInID() {
00337   PW_Edit->setFocus();
00338 }
00339 
00340 
00341 void KPPPWidget::enterPressedInPW() {
00342   connect_b->setFocus();
00343 }
00344 
00345 // triggered by the session manager
00346 void KPPPWidget::saveMyself() {
00347     _pppdata->save();
00348 }
00349 
00350 void KPPPWidget::shutDown() {
00351     interruptConnection();
00352     saveMyself();
00353 }
00354 
00355 void KPPPWidget::log_window_toggled(bool on) {
00356   _pppdata->set_show_log_window(on);
00357 }
00358 
00359 
00360 
00361 
00362 // void KPPPWidget::resetaccounts() {
00363 //   connectto_c->clear();
00364 
00365 //   int count = _pppdata->count();
00366 
00367 //   // enable/disable controls
00368 //   connectto_c->setEnabled(count > 0);
00369 //   connect_b->setEnabled(count > 0);
00370 //   log->setEnabled(count > 0);
00371 //   ID_Edit->setEnabled(count > 0);
00372 //   PW_Edit->setEnabled(count > 0);
00373 
00374 //   //load the accounts
00375 //   for(int i=0; i < count; i++) {
00376 //     _pppdata->setAccountbyIndex(i);
00377 //      connectto_c->insertItem(_pppdata->accname());
00378 //   }
00379 
00380 //   //set the default account
00381 //   if(!_pppdata->defaultAccount().isEmpty()) {
00382 //     for(int i=0; i < count; i++)
00383 //        if(_pppdata->defaultAccount() == connectto_c->text(i)) {
00384 //      connectto_c->setCurrentItem(i);
00385 //      _pppdata->setAccountbyIndex(i);
00386 
00387 //      ID_Edit->setText(_pppdata->storedUsername());
00388 //      PW_Edit->setText(_pppdata->storedPassword());
00389 //     }
00390 //   }
00391 //   else
00392 //     if(count > 0) {
00393 //        _pppdata->setDefaultAccount(connectto_c->text(0));
00394 //         _pppdata->save();
00395 //      ID_Edit->setText(_pppdata->storedUsername());
00396 //      PW_Edit->setText(_pppdata->storedPassword());
00397 //     }
00398 
00399 //   connect(ID_Edit, SIGNAL(textChanged(const QString&)),
00400 //        this, SLOT(usernameChanged(const QString&)));
00401 
00402 //   connect(PW_Edit, SIGNAL(textChanged(const QString&)),
00403 //        this, SLOT(passwordChanged(const QString&)));
00404 
00405 //   if (ID_Edit->text().isEmpty())
00406 //       ID_Edit->setFocus();
00407 //   else if (PW_Edit->text().isEmpty())
00408 //       PW_Edit->setFocus();
00409 // }
00410 
00411 
00412 void KPPPWidget::interruptConnection() {
00413   // interrupt dial up
00414 //
00415 
00416     if (con->isVisible())
00417      emit con->cancelbutton();
00418 
00419   // disconnect if online
00420   if (_pppdata->pppdRunning())
00421     emit disconnect();
00422 }
00423 
00424 
00425 void KPPPWidget::sigPPPDDied() {
00426     odebug << "Received a SIGUSR1" << oendl; 
00427 
00428     // if we are not connected pppdpid is -1 so have have to check for that
00429     // in the followin line to make sure that we don't raise a false alarm
00430     // such as would be the case when the log file viewer exits.
00431     if(_pppdata->pppdRunning() || _pppdata->pppdError()) {
00432         odebug << "It was pppd that died" << oendl; 
00433 
00434         // when we killpppd() on Cancel in ConnectWidget
00435         // we set pppid to -1 so we won't
00436         // enter this block
00437 
00438         // just to be sure
00439 
00440         Modem::modem->removeSecret(AUTH_PAP);
00441         Modem::modem->removeSecret(AUTH_CHAP);
00442 
00443         _pppdata->setpppdRunning(false);
00444 
00445         odebug << "Executing command on disconnect since pppd has died." << oendl; 
00446         QApplication::flushX();
00447         execute_command(_pppdata->command_on_disconnect());
00448 
00449 //      stopAccounting();
00450 
00451         con_win->stopClock();
00452 //       DockWidget::dock_widget->stop_stats();
00453 //       DockWidget::dock_widget->hide();
00454 
00455         if(!_pppdata->pppdError())
00456             _pppdata->setpppdError(E_PPPD_DIED);
00457         removedns();
00458         Modem::modem->unlockdevice();
00459         //
00460         con->pppdDied();
00461 
00462         if(!_pppdata->automatic_redial()) {
00463             quit_b->setFocus();
00464             show();
00465             con_win->stopClock();
00466 //      stopAccounting();
00467             con_win->hide();
00468             con->hide();
00469 
00470             _pppdata->setpppdRunning(false);
00471             // // not in a signal handler !!!  KNotifyClient::beep();
00472             QString msg;
00473             if (_pppdata->pppdError() == E_IF_TIMEOUT)
00474                 msg = QObject::tr("Timeout expired while waiting for the PPP interface "
00475                            "to come up!");
00476             else {
00477                 msg = QObject::tr("<p>The pppd daemon died unexpectedly!</p>");
00478                 Modem::modem->pppdExitStatus();
00479                 if (Modem::modem->lastStatus != 99) {   // more recent pppds only
00480                     msg += QObject::tr("<p>Exit status: %1").arg(Modem::modem->lastStatus);
00481                     msg += QObject::tr("</p><p>See 'man pppd' for an explanation of the error "
00482                                 "codes or take a look at the kppp FAQ on "
00483                                 "  <a href=http://devel-home.kde.org/~kppp/index.html>"
00484                                 "http://devel-home.kde.org/~kppp/index.html</a></p>");
00485                 }
00486             }
00487 
00488 //      if(QMessageBox::warning(0, msg, QObject::tr("Error"), QObject::tr("&OK"), QObject::tr("&Details...")) == QMessageBox::No)
00489 // //     PPPL_ShowLog();
00490 //       } else { /* reconnect on disconnect */
00491             if (false){
00492                 odebug << "Trying to reconnect... " << oendl; 
00493 
00494                 if(_pppdata->authMethod() == AUTH_PAP ||
00495                    _pppdata->authMethod() == AUTH_CHAP ||
00496                    _pppdata->authMethod() == AUTH_PAPCHAP)
00497                     Modem::modem->setSecret(_pppdata->authMethod(),
00498                                             encodeWord(_pppdata->storedUsername()),
00499                                             encodeWord(_pppdata->password()));
00500 
00501                 con_win->hide();
00502                                con_win->stopClock();
00503 //      stopAccounting();
00504                 _pppdata->setpppdRunning(false);
00505                 // not in a signal handler !!!  KNotifyClient::beep();
00506                 emit cmdl_start();
00507             }
00508         }
00509         _pppdata->setpppdError(0);
00510     }
00511 }
00512 
00513 // void KPPPWidget::sigChld() {
00514 //   odebug << "sigchld()" << oendl; 
00515 //   //  pid_t id = wait(0L);
00516 //   //  if(id == helperPid && helperPid != -1) {
00517 //   //    kdDebug(5002) << "It was the setuid child that died" << endl;
00518 //  // helperPid = -1;
00519 //     QString msg = QObject::tr("kppp's helper process just died.\n"
00520 //                        "Since a further execution would be pointless, "
00521 //                        "kppp will shut down now.");
00522 //     QMessageBox::warning(0L,"error", msg);
00523 //     //remove_pidfile();
00524 //     exit(1);
00525 //     //  }
00526 // }
00527 
00528 
00529 void KPPPWidget::newdefaultaccount(int i) {
00530   _pppdata->setDefaultAccount(connectto_c->text(i));
00531   _pppdata->save();
00532   ID_Edit->setText(_pppdata->storedUsername());
00533   PW_Edit->setText(_pppdata->storedPassword());
00534 }
00535 
00536 
00537 
00538 
00539 void KPPPWidget::beginConnect() {
00540   // make sure to connect to the account that is selected in the combo box
00541   // (exeption: an account given by a command line argument)
00542  //  if(!m_bCmdlAccount) {
00543 //     _pppdata->setAccount(connectto_c->currentText());
00544 //     _pppdata->setPassword(PW_Edit->text());
00545 //   } else {
00546     _pppdata->setPassword(_pppdata->storedPassword());
00547 //  }
00548 
00549   QFileInfo info(pppdPath());
00550 
00551   if(!info.exists()){
00552     QMessageBox::warning(this, "error", QObject::tr("Cannot find the PPP daemon!\n"
00553                               "Make sure that pppd is installed and "
00554                               "that you have entered the correct path."));
00555     return;
00556   }
00557 #if 0
00558   if(!info.isExecutable()){
00559 
00560     QString string;
00561     string = QObject::tr("kppp cannot execute:\n %1\n"
00562                    "Please make sure that you have given kppp "
00563                    "setuid permission and that "
00564                    "pppd is executable.").arg(_pppdata->pppdPath());
00565     KMessageBox::error(this, string);
00566     return;
00567 
00568   }
00569 #endif
00570 
00571   QFileInfo info2(_pppdata->modemDevice());
00572 
00573   if(!info2.exists()){
00574     QString string;
00575     string = QObject::tr("kppp can not find:\n %1\nPlease make sure you have setup "
00576                    "your modem device properly "
00577                    "and/or adjust the location of the modem device on "
00578                    "the modem tab of "
00579                    "the setup dialog.").arg(_pppdata->modemDevice());
00580     QMessageBox::warning(this, "error", string);
00581     return;
00582   }
00583 
00584   // if this is a PAP or CHAP account, ensure that username is
00585   // supplied
00586   if(_pppdata->authMethod() == AUTH_PAP ||
00587      _pppdata->authMethod() == AUTH_CHAP ||
00588      _pppdata->authMethod() == AUTH_PAPCHAP ) {
00589     if(ID_Edit->text().isEmpty()) {
00590         QMessageBox::warning(this,"error",
00591                            QObject::tr("You have selected the authentication method PAP or CHAP. This requires that you supply a username and a password!"));
00592       return;
00593     } else {
00594       if(!Modem::modem->setSecret(_pppdata->authMethod(),
00595                                    encodeWord(_pppdata->storedUsername()),
00596                                    encodeWord(_pppdata->password()))) {
00597         QString s;
00598         s = QObject::tr("Cannot create PAP/CHAP authentication\n"
00599                                      "file \"%1\"").arg(PAP_AUTH_FILE);
00600         QMessageBox::warning(this, "error", s);
00601         return;
00602       }
00603     }
00604   }
00605 
00606   if (_pppdata->phonenumber().isEmpty()) {
00607     QString s = QObject::tr("You must specify a telephone number!");
00608     QMessageBox::warning(this, "error", s);
00609     return;
00610   }
00611 
00612   this->hide();
00613 
00614   QString tit = QObject::tr("Connecting to: %1").arg(_pppdata->accname());
00615 //   con->setCaption(tit);
00616 
00617 //   con->show();
00618 
00619 
00620   emit begin_connect();
00621 }
00622 
00623 
00624 void KPPPWidget::disconnect() {
00625   if (!_pppdata->command_before_disconnect().isEmpty()) {
00626      con_win->hide();
00627      con->show();
00628      con->setCaption(QObject::tr("Disconnecting..."));
00629      con->setMsg(QObject::tr("Executing command before disconnection."));
00630 
00631     qApp->processEvents();
00632     QApplication::flushX();
00633 //    pid_t id =
00634         execute_command(_pppdata->command_before_disconnect());
00635 //    int i, status;
00636 
00637 //     do {
00638 //       kapp->processEvents();
00639 //       i = waitpid(id, &status, WNOHANG);
00640 //       usleep(500000);
00641 //     } while (i == 0 && errno == 0);
00642 
00643     con->hide();
00644   }
00645 
00646   qApp->processEvents();
00647 
00648 //  statdlg->stop_stats();
00649   Modem::modem->killPPPDaemon();
00650 
00651   QApplication::flushX();
00652   execute_command(_pppdata->command_on_disconnect());
00653 
00654   Modem::modem->removeSecret(AUTH_PAP);
00655   Modem::modem->removeSecret(AUTH_CHAP);
00656 
00657   removedns();
00658   Modem::modem->unlockdevice();
00659 
00660   con_win->stopClock();
00661 //  p_kppp->stopAccounting();
00662   con_win->hide();
00663 
00664 //   DockWidget::dock_widget->stop_stats();
00665 //   DockWidget::dock_widget->hide();
00666 
00667 //   if(m_bQuitOnDisconnect)
00668 //     kapp->exit(0);
00669 //   else {
00670     this->quit_b->setFocus();
00671     this->show();
00672 //  }
00673 }
00674 
00675 
00676 // void KPPPWidget::helpbutton() {
00677 //   kapp->invokeHelp();
00678 // }
00679 
00680 
00681 void KPPPWidget::quitbutton() {
00682   if(_pppdata->pppdRunning()) {
00683     int ok = QMessageBox::warning(this,
00684                             QObject::tr("Exiting kPPP will close your PPP Session."),
00685                             QObject::tr("Quit kPPP?"));
00686     if(ok == QMessageBox::Yes) {
00687       Modem::modem->killPPPDaemon();
00688       QApplication::flushX();
00689       execute_command(_pppdata->command_on_disconnect());
00690       removedns();
00691       Modem::modem->unlockdevice();
00692     }
00693   } else {
00694     if (!_pppdata->accname().isEmpty() && !_pppdata->storePassword())
00695       _pppdata->setStoredPassword("");
00696   }
00697   _pppdata->save();
00698   qApp->quit();
00699 }
00700 
00701 
00702 // void KPPPWidget::rulesetLoadError() {
00703 //   QMessageBox::warning(this,"error", ruleset_load_errmsg);
00704 // }
00705 
00706 
00707 // void KPPPWidget::startAccounting() {
00708 //   // volume accounting
00709 //   stats->totalbytes = 0;
00710 
00711 //   kdDebug() << "AcctEnabled: " << _pppdata->AcctEnabled() << endl;
00712 
00713 //   // load the ruleset
00714 //   if(!_pppdata->AcctEnabled())
00715 //     return;
00716 
00717 //   QString d = AccountingBase::getAccountingFile(_pppdata->accountingFile());
00718 //   //  if(::access(d.data(), X_OK) != 0)
00719 //     acct = new Accounting(this, stats);
00720 //     //  else
00721 //     //    acct = new ExecutableAccounting(this);
00722 
00723 //   // connect to the accounting object
00724 //   connect(acct, SIGNAL(changed(QString,QString)),
00725 //        con_win, SLOT(slotAccounting(QString,QString)));
00726 
00727 // //   if(!acct->loadRuleSet(_pppdata->accountingFile())) {
00728 // //     QString s= QObject::tr("Can not load the accounting "
00729 // //                       "ruleset \"%1\"!").arg(_pppdata->accountingFile());
00730 
00731 //     // starting the messagebox with a timer will prevent us
00732 //     // from blocking the calling function ConnectWidget::timerEvent
00733 //     ruleset_load_errmsg = s;
00734 //     QTimer::singleShot(0, this, SLOT(rulesetLoadError()));
00735 //     return;
00736 //   }
00737 // //else
00738 // //    acct->slotStart();
00739 // }
00740 
00741 // void KPPPWidget::stopAccounting() {
00742 //   // store volume accounting
00743 // //   if(stats->totalbytes != 0)
00744 // //     _pppdata->setTotalBytes(stats->totalbytes);
00745 
00746 //   if(!_pppdata->AcctEnabled())
00747 //     return;
00748 
00749 // //   if(acct != 0) {
00750 // //     acct->slotStop();
00751 // //     delete acct;
00752 // //     acct = 0;
00753 // //   }
00754 // }
00755 
00756 
00757 // void KPPPWidget::showStats() {
00758 //   if(statdlg) {
00759 //     statdlg->show();
00760 //     statdlg->raise();
00761 //   }
00762 // }
00763 
00764 
00765 void KPPPWidget::usernameChanged(const QString &) {
00766   // store username for later use
00767   _pppdata->setStoredUsername(ID_Edit->text());
00768 }
00769 
00770 
00771 void KPPPWidget::passwordChanged(const QString &) {
00772     // store the password if so requested
00773   if(_pppdata->storePassword())
00774     _pppdata->setStoredPassword(PW_Edit->text());
00775   else
00776     _pppdata->setStoredPassword("");
00777 }
00778 
00779 
00780 void KPPPWidget::setPW_Edit(const QString &pw) {
00781   PW_Edit->setText(pw);
00782 }
00783 
00784 
00785 // void KPPPWidget::resetCosts(const QString &s) {
00786 //   AccountingBase::resetCosts(s);
00787 // }
00788 
00789 
00790 // void KPPPWidget::resetVolume(const QString &s) {
00791 //   AccountingBase::resetVolume(s);
00792 // }
00793 
00799 QString KPPPWidget::encodeWord(const QString &s) {
00800     QString r = s;
00801     r.replace(QRegExp("\\"), "\\\\");
00802     return r;
00803 }
00804 
00805 // void KPPPWidget::setQuitOnDisconnect (bool b)
00806 // {
00807 //     m_bQuitOnDisconnect = b;
00808 // }
00809 
00810 void KPPPWidget::showNews() {
00811 #ifdef KPPP_SHOW_NEWS
00812   /*
00813    * Introduce the QuickHelp feature to new users of this version
00814    */
00815   #define QUICKHELP_HINT "Hint_QuickHelp"
00816   if(_pppdata->readNumConfig(GENERAL_GRP, QUICKHELP_HINT, 0) == 0) {
00817     QDialog dlg(0, 0, true);
00818     dlg.setCaption(QObject::tr("Recent Changes in KPPP"));
00819 
00820     QVBoxLayout *tl = new QVBoxLayout(&dlg, 10, 10);
00821     QHBoxLayout *l1 = new QHBoxLayout(10);
00822     QVBoxLayout *l2 = new QVBoxLayout(10);
00823     tl->addLayout(l1);
00824 
00825     QLabel *icon = new QLabel(&dlg);
00826     icon->setPixmap(BarIcon("exclamation"));
00827     icon->setFixedSize(icon->sizeHint());
00828     l1->addWidget(icon);
00829     l1->addLayout(l2);
00830 
00831     QLabel *l = new QLabel(QObject::tr("From version 1.4.8 on, kppp has a new feature\n"
00832                               "called \"Quickhelp\". It's similar to a tooltip,\n"
00833                               "but you can activate it whenever you want.\n"
00834                               "\n"
00835                               "To activate it, simply click on a control like\n"
00836                               "a button or a label with the right mouse button.\n"
00837                               "If the item supports Quickhelp, a popup menu\n"
00838                               "will appear leading to Quickhelp.\n"
00839                               "\n"
00840                               "To test it, right-click somewhere in this text."),
00841                          &dlg);
00842 
00843     QCheckBox *cb = new QCheckBox(QObject::tr("Don't show this hint again"), &dlg);
00844     cb->setFixedSize(cb->sizeHint());
00845 
00846     KButtonBox *bbox = new KButtonBox(&dlg);
00847     bbox->addStretch(1);
00848     QPushButton *ok = bbox->addButton(QObject::tr("OK"));
00849     ok->setDefault(true);
00850     dlg.connect(ok, SIGNAL(clicked()),
00851                 &dlg, SLOT(accept()));
00852     bbox->addStretch(1);
00853     bbox->layout();
00854 
00855     l2->addWidget(l);
00856     l2->addWidget(cb);
00857     tl->addWidget(bbox);
00858 
00859     QString tmp = QObject::tr("This is an example of <b>QuickHelp</b>.\n"
00860                        "This window will stay open until you\n"
00861                        "click a mouse button or a press a key.\n");
00862 
00863     QWhatsThis::add(cb,tmp);
00864     QWhatsThis::add(l, tmp);
00865 
00866     dlg.exec();
00867     if(cb->isChecked()) {
00868       _pppdata->writeConfig(GENERAL_GRP, QUICKHELP_HINT, 1);
00869       _pppdata->save();
00870     }
00871   }
00872 #endif
00873 }
00874 
00875 
00876 //#include "kpppwidget.moc"
00877 

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