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

interfaceppp.cpp

Go to the documentation of this file.
00001 #include "auth.h"
00002 #include "interfaceppp.h"
00003 #include "modem.h"
00004 #include "pppdata.h"
00005 
00006 /* OPIE */
00007 #include <opie2/odebug.h>
00008 using namespace Opie::Core;
00009 
00010 /* QT */
00011 #include <qmessagebox.h>
00012 #include <qlayout.h>
00013 #include <qlineedit.h>
00014 #include <qlabel.h>
00015 
00016 InterfacePPP::InterfacePPP(QObject *parent, const char *name, bool status)
00017     : Interface(parent, name, status),
00018       _modemPtr(0),
00019       _dataPtr(0)
00020 {
00021     odebug << "InterfacePPP::InterfacePPP(" << oendl; 
00022 }
00023 
00024 PPPData* InterfacePPP::data()const
00025 {
00026     if (!_dataPtr){
00027         odebug << "creating new Data obj" << oendl; 
00028         _dataPtr = new PPPData();
00029         _dataPtr->setDevice( getInterfaceName() );
00030         _dataPtr->setAccount( getHardwareName() );
00031     }
00032     return _dataPtr;
00033 }
00034 
00035 Modem* InterfacePPP::modem()const
00036 {
00037     if (!_modemPtr){
00038         odebug << "creating new modem obj" << oendl; 
00039         _modemPtr = new Modem( data() );
00040     }
00041     return _modemPtr;
00042 }
00043 
00044 bool InterfacePPP::refresh()
00045 {
00046     odebug << "InterfacePPP::refresh()" << oendl; 
00047     QString old = getInterfaceName();
00048     setInterfaceName( modem()->pppDevice() );
00049 
00050     (void)Interface::refresh();
00051 
00052     setInterfaceName( old );
00053     emit updateInterface(this);
00054 
00055     return true;
00056 }
00057 
00058 void InterfacePPP::start()
00059 {
00060     odebug << "InterfacePPP::start" << oendl; 
00061 
00062     if (data()->password().isEmpty() && !data()->storedUsername().isEmpty() ) {
00063 
00064         QDialog mb( 0, "Dialog", true );
00065         mb.setCaption( tr( "No password" ) );
00066         QVBoxLayout layout( &mb );
00067         QLabel text ( &mb  );
00068         text.setText( tr("Username defined but no password\n Please enter a password") );
00069         QLineEdit lineedit( &mb );
00070         lineedit.setEchoMode( QLineEdit::Password );
00071         layout.addWidget( &text );
00072         layout.addWidget( &lineedit );
00073         if ( mb.exec() == QDialog::Accepted )  {
00074             data()->setPassword( lineedit.text() );
00075         }
00076     }
00077 
00078   QFileInfo info(pppdPath());
00079 
00080   if(!info.exists()){
00081     QMessageBox::warning(0, tr("Error"),
00082                          QObject::tr("<qt>Cannot find the PPP daemon!<br>"
00083                               "Make sure that pppd is installed and "
00084                               "that you have entered the correct path.</qt>"));
00085     return;
00086   }
00087 //#if 0
00088   if(!info.isExecutable()){
00089 
00090     QString string;
00091     string = QObject::tr( "<qt>Cannot execute:<br> %1<br>"
00092                    "Please make sure that you have given "
00093                    "setuid permission and that "
00094                    "pppd is executable.<br>").arg(pppdPath());
00095     QMessageBox::warning(0, tr("Error"), string);
00096     return;
00097 
00098   }
00099 //#endif
00100 
00101   QFileInfo info2(data()->modemDevice());
00102 
00103   if(!info2.exists()){
00104     QString string;
00105     string = QObject::tr( "<qt>Cannot find:<br> %1<br>"
00106                    "Please make sure you have setup "
00107                    "your modem device properly "
00108                    "and/or adjust the location of the modem device on "
00109                    "the modem tab of "
00110                    "the setup dialog.</qt>").arg(data()->modemDevice());
00111     QMessageBox::warning(0, tr("Error"), string);
00112     return;
00113   }
00114 
00115   // if this is a PAP or CHAP account, ensure that username is
00116   // supplied
00117   if(data()->authMethod() == AUTH_PAP ||
00118      data()->authMethod() == AUTH_CHAP ||
00119      data()->authMethod() == AUTH_PAPCHAP ) {
00120       if(false){ //FIXME: ID_Edit->text().isEmpty()) {
00121         QMessageBox::warning(0,tr("Error"),
00122                            QObject::tr("<qt>You have selected the authentication method PAP or CHAP. This requires that you supply a username and a password!</qt>"));
00123 // FIXME:      return;
00124     } else {
00125       if(!modem()->setSecret(data()->authMethod(),
00126                              PPPData::encodeWord(data()->storedUsername()),
00127                              PPPData::encodeWord(data()->password()))
00128           ) {
00129         QString s;
00130         s = QObject::tr("<qt>Cannot create PAP/CHAP authentication<br>"
00131                                      "file \"%1\"</qt>").arg(PAP_AUTH_FILE);
00132         QMessageBox::warning(0, tr("Error"), s);
00133         return;
00134       }
00135     }
00136   }
00137 
00138   if (data()->phonenumber().isEmpty()) {
00139     QString s = QObject::tr("You must specify a telephone number!");
00140     QMessageBox::warning(0, tr("Error"), s);
00141     return;
00142   }
00143 
00144   // SEGFAULTS:
00145 //   setStatus( true );
00146 //   emit updateInterface((Interface*) this);
00147 
00148   emit begin_connect();
00149 
00150   odebug << "InterfacePPP::start END" << oendl; 
00151 }
00152 
00153 void InterfacePPP::stop()
00154 {
00155     odebug << "InterfacePPP::stop" << oendl; 
00156     // emit hangup_now();
00157     status = false; // not connected
00158     setStatus( false );
00159     emit hangup_now();
00160     refresh();
00161 
00162 }
00163 
00164 void InterfacePPP::save()
00165 {
00166     data()->save();
00167     emit updateInterface((Interface*) this);
00168 }
00169 QString InterfacePPP::pppDev()const {
00170     return modem()->pppDevice();
00171 }
00172 pid_t InterfacePPP::pppPID()const{
00173     return modem()->pppPID();
00174 }
00175 void InterfacePPP::setPPPDpid( pid_t pid) {
00176     setStatus( true );
00177     modem()->setPPPDPid( pid );
00178 }

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