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

general.cpp

Go to the documentation of this file.
00001 /*
00002  *            kPPP: A pppd front end for the KDE project
00003  *
00004  * $Id: general.cpp,v 1.11 2004/10/14 01:44:27 zecke 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 "general.h"
00028 #include "interfaceppp.h"
00029 #include "modeminfo.h"
00030 #include "modemcmds.h"
00031 #include "pppdata.h"
00032 
00033 /* OPIE */
00034 #include <opie2/odebug.h>
00035 #include <qpe/config.h>
00036 #include <qpe/qpeapplication.h>
00037 using namespace Opie::Core;
00038 
00039 /* QT */
00040 #include <qcheckbox.h>
00041 #include <qcombobox.h>
00042 #include <qlabel.h>
00043 #include <qlayout.h>
00044 #include <qpushbutton.h>
00045 #include <qslider.h>
00046 #include <qspinbox.h>
00047 #include <qwhatsthis.h>
00048 
00049 /* STD */
00050 #include <termios.h>
00051 #include <string.h>
00052 
00053 
00054 ModemWidget::ModemWidget( PPPData *pd, QWidget *parent, const char *name )
00055         : QWidget(parent, name), _pppdata(pd)
00056 {
00057     int k;
00058 
00059     QGridLayout *tl = new QGridLayout(this, 8, 2, 0 );//, KDialog::spacingHint());
00060 
00061     QLabel *label1;
00062 
00063     label1 = new QLabel(tr("Modem &name:"), this);
00064     tl->addWidget(label1, 0, 0);
00065 
00066     modemname = new QLineEdit(this, "modemName");
00067     modemname->setText( _pppdata->devname() );
00068     label1->setBuddy(modemname);
00069     tl->addWidget(modemname, 0, 1);
00070 
00071     label1 = new QLabel(tr("Modem de&vice:"), this);
00072     tl->addWidget(label1, 1, 0);
00073 
00074     modemdevice = new QComboBox(false, this);
00075     modemdevice->setEditable( true );
00076     modemdevice->setDuplicatesEnabled ( false );
00077     modemdevice->setInsertionPolicy( QComboBox::AtTop );
00078     label1->setBuddy(modemdevice);
00079 
00080     Config cfg("NetworkSetupPPP");
00081     cfg.setGroup("Devices_General");
00082     QStringList devs = cfg.readListEntry("devices",',');
00083     if (devs.isEmpty()) devs << "/dev/modem" << "/dev/ircomm0" << "/dev/ttyS0";
00084     modemdevice->insertStringList( devs );
00085     tl->addWidget(modemdevice, 1, 1);
00086 
00087     //   connect(modemdevice, SIGNAL(activated(int)),
00088     //    SLOT(setmodemdc(int)));
00089     //   connect(modemdevice, SIGNAL(textChanged(const QString&) ),
00090     //           SLOT( setmodemdc(const QString&) ) );
00091 
00092     QString tmp = tr("This specifies the serial port your modem is attached \n"
00093                      "to. On Linux/x86, typically this is either /dev/ttyS0 \n"
00094                      "(COM1 under DOS) or /dev/ttyS1 (COM2 under DOS).\n"
00095                      "\n"
00096                      "If you have an internal ISDN card with AT command\n"
00097                      "emulation (most cards under Linux support this), you\n"
00098                      "should select one of the /dev/ttyIx devices.");
00099 
00100     QWhatsThis::add(label1,tmp);
00101     QWhatsThis::add(modemdevice,tmp);
00102 
00103 
00104     label1 = new QLabel(tr("&Flow control:"), this);
00105     tl->addWidget(label1, 2, 0);
00106 
00107     flowcontrol = new QComboBox(false, this);
00108     label1->setBuddy(flowcontrol);
00109     flowcontrol->insertItem(tr("Hardware [CRTSCTS]"));
00110     flowcontrol->insertItem(tr("Software [XON/XOFF]"));
00111     flowcontrol->insertItem(tr("None"));
00112     tl->addWidget(flowcontrol, 2, 1);
00113     //   connect(flowcontrol, SIGNAL(activated(int)),
00114     //    SLOT(setflowcontrol(int)));
00115 
00116     tmp = tr("<p>Specifies how the serial port and modem\n"
00117              "communicate. You should not change this unless\n"
00118              "you know what you are doing.\n"
00119              "\n"
00120              "<b>Default</b>: CRTSCTS");
00121 
00122     QWhatsThis::add(label1,tmp);
00123     QWhatsThis::add(flowcontrol,tmp);
00124 
00125     QLabel *labelenter = new QLabel(tr("&Line termination:"), this);
00126     tl->addWidget(labelenter, 3, 0);
00127 
00128     enter = new QComboBox(false, this);
00129     labelenter->setBuddy(enter);
00130     enter->insertItem("CR");
00131     enter->insertItem("LF");
00132     enter->insertItem("CR/LF");
00133     tl->addWidget(enter, 3, 1);
00134     //  connect(enter, SIGNAL(activated(int)), SLOT(setenter(int)));
00135     tmp = tr("<p>Specifies how AT commands are sent to your\n"
00136              "modem. Most modems will work fine with the\n"
00137              "default <i>CR/LF</i>. If your modem does not react\n"
00138              "to the init string, you should try different\n"
00139              "settings here\n"
00140              "\n"
00141              "<b>Default</b>: CR/LF");
00142 
00143     QWhatsThis::add(labelenter,tmp);
00144     QWhatsThis::add(enter, tmp);
00145 
00146     QLabel *baud_label = new QLabel(tr("Co&nnection speed:"), this);
00147     tl->addWidget(baud_label, 4, 0);
00148     baud_c = new QComboBox(this);
00149     baud_label->setBuddy(baud_c);
00150 
00151     static const char *baudrates[] =
00152         {
00153 
00154 #ifdef B460800
00155             "460800",
00156 #endif
00157 
00158 #ifdef B230400
00159             "230400",
00160 #endif
00161 
00162 #ifdef B115200
00163             "115200",
00164 #endif
00165 
00166 #ifdef B57600
00167             "57600",
00168 #endif
00169 
00170             "38400",
00171             "19200",
00172             "9600",
00173             "2400",
00174             0
00175         };
00176 
00177     for(k = 0; baudrates[k]; k++)
00178         baud_c->insertItem(baudrates[k]);
00179 
00180     baud_c->setCurrentItem(3);
00181     //   connect(baud_c, SIGNAL(activated(int)),
00182     //    this, SLOT(speed_selection(int)));
00183     tl->addWidget(baud_c, 4, 1);
00184 
00185     tmp = tr("Specifies the speed your modem and the serial\n"
00186              "port talk to each other. You should begin with\n"
00187              "the default of 38400 bits/sec. If everything\n"
00188              "works you can try to increase this value, but to\n"
00189              "no more than 115200 bits/sec (unless you know\n"
00190              "that your serial port supports higher speeds).");
00191 
00192     QWhatsThis::add(baud_label,tmp);
00193     QWhatsThis::add(baud_c,tmp);
00194 
00195     tl->addRowSpacing(5, 10);
00196 
00197     //Modem Lock File
00198     modemlockfile = new QCheckBox(tr("&Use lock file"), this);
00199     modemlockfile->setChecked(_pppdata->modemLockFile());
00200     //   connect(modemlockfile, SIGNAL(toggled(bool)),
00201     //           SLOT(modemlockfilechanged(bool)));
00202     tl->addMultiCellWidget(modemlockfile, 6, 6, 0, 1);
00203     //  l12->addStretch(1);
00204     QWhatsThis::add(modemlockfile,
00205                         tr("<p>To prevent other programs from accessing the\n"
00206                            "modem while a connection is established, a\n"
00207                            "file can be created to indicate that the modem\n"
00208                            "is in use. On Linux an example file would be\n"
00209                            "<tt>/var/lock/LCK..ttyS1</tt>\n"
00210                            "Here you can select whether this locking will\n"
00211                            "be done.\n"
00212                            "\n"
00213                            "<b>Default</b>: On"));
00214 
00215     // Modem Timeout Line Edit Box
00216     QHBoxLayout *timeoutLayout = new QHBoxLayout( this );
00217     QLabel *timeoutlabel = new QLabel( tr("Modem timeout:") ,this, "timeout" );
00218     modemtimeout = new QSpinBox( 1, 120, 1, this, "modemTimeout" );
00219     //   modemtimeout = new KIntNumInput(_pppdata->modemTimeout(), this);
00220     //   modemtimeout->setLabel(tr("Modem &timeout:"));
00221     //  modemtimeout->setRange(1, 120, 1);
00222     modemtimeout->setSuffix(tr(" sec"));
00223     modemtimeout->setValue( _pppdata->modemTimeout() );
00224     //   connect(modemtimeout, SIGNAL(valueChanged(int)),
00225     //    SLOT(modemtimeoutchanged(int)));
00226     timeoutLayout->addWidget(timeoutlabel);
00227     timeoutLayout->addWidget(modemtimeout);
00228     tl->addMultiCellLayout(timeoutLayout, 7, 7, 0, 1);
00229 
00230     QWhatsThis::add(modemtimeout,
00231                         tr("This specifies how long <i>kppp</i> waits for a\n"
00232                            "<i>CONNECT</i> response from your modem. The\n"
00233                            "recommended value is 30 seconds."));
00234 
00235     //set stuff from gpppdata
00236     enter->setCurrentItem( static_cast<int>(_pppdata->enter()) );
00237     flowcontrol->setCurrentItem( static_cast<int>( _pppdata->flowcontrol() ) );
00238 
00239     for(int i=0; i <= modemdevice->count()-1; i++)
00240     {
00241         if(_pppdata->modemDevice() == modemdevice->text(i))
00242             modemdevice->setCurrentItem(i);
00243     }
00244 
00245     //set the modem speed
00246     for(int i=0; i < baud_c->count(); i++)
00247         if(baud_c->text(i) == _pppdata->speed())
00248             baud_c->setCurrentItem(i);
00249 
00250     tl->setRowStretch(1, 1);
00251 }
00252 
00253 ModemWidget::~ModemWidget()
00254 {
00255     QStringList devs;
00256 
00257     for (int i=0;i<modemdevice->count();i++)
00258     {
00259         QString s = modemdevice->text(i);
00260         s.simplifyWhiteSpace();
00261         if (! s.isEmpty() ) devs << s;
00262     }
00263 
00264 
00265     QString edited = modemdevice->currentText();
00266     if ( !( edited ).isEmpty() )
00267     {
00268         edited.simplifyWhiteSpace();
00269         if ( devs.contains( edited ) == 0 )
00270         {
00271             devs << edited;
00272         }
00273     }
00274 
00275 
00276     Config cfg("NetworkSetupPPP");
00277     cfg.setGroup("Devices_General");
00278     cfg.writeEntry("devices",devs,',');
00279 
00280 }
00281 
00282 // void ModemWidget::speed_selection(int) {
00283 //   _pppdata->setSpeed(baud_c->text(baud_c->currentItem()));
00284 // }
00285 
00286 
00287 // void ModemWidget::setenter(int ) {
00288 //   _pppdata->setEnter(enter->text(enter->currentItem()));
00289 // }
00290 
00291 
00292 // void ModemWidget::setmodemdc(int i) {
00293 //   _pppdata->setModemDevice(modemdevice->text(i));
00294 // }
00295 
00296 // void ModemWidget::setmodemdc( const QString &string )  {
00297 //     _pppdata->setModemDevice( string );
00298 // }
00299 
00300 // void ModemWidget::setflowcontrol(int i) {
00301 //   _pppdata->setFlowcontrol(flowcontrol->text(i));
00302 // }
00303 
00304 
00305 // void ModemWidget::modemlockfilechanged(bool set) {
00306 //   _pppdata->setModemLockFile(set);
00307 // }
00308 
00309 
00310 // void ModemWidget::modemtimeoutchanged(int n) {
00311 //   _pppdata->setModemTimeout(n);
00312 // }
00313 
00314 
00315 
00316 bool ModemWidget::save()
00317 {
00318     //first check to make sure that the device name is unique!
00319     if(modemname->text().isEmpty() ||
00320             !_pppdata->isUniqueDevname(modemname->text()))
00321         return false;
00322 
00323     _pppdata->setDevname( modemname->text() );
00324     _pppdata->setModemDevice( modemdevice->currentText() );
00325     _pppdata->setFlowcontrol(static_cast<PPPData::FlowControl>(flowcontrol->currentItem()));
00326     _pppdata->setEnter( static_cast<PPPData::LineTermination>(enter->currentItem()));
00327     _pppdata->setSpeed(baud_c->currentText());
00328     _pppdata->setModemLockFile( modemlockfile->isChecked());
00329     _pppdata->setModemTimeout( modemtimeout->value() );
00330     return true;
00331 
00332 }
00333 
00334 void ModemWidget::slotBeforeModemQuery()
00335 {
00336     m_oldModemDev     = _pppdata->modemDevice();
00337     m_oldFlowControl  = static_cast<int>( _pppdata->flowcontrol() );
00338     m_oldSpeed        = _pppdata->speed();
00339     m_oldModemLock    = _pppdata->modemLockFile();
00340     m_oldModemTimeout = _pppdata->modemTimeout();
00341     m_oldLineEnd      = static_cast<int>( _pppdata->enter() );
00342 
00343 
00344     _pppdata->setModemDevice( modemdevice->currentText() );
00345     _pppdata->setFlowcontrol(static_cast<PPPData::FlowControl>(flowcontrol->currentItem()));
00346     _pppdata->setEnter(static_cast<PPPData::LineTermination>(enter->currentItem()));
00347     _pppdata->setSpeed(baud_c->currentText());
00348     _pppdata->setModemLockFile( modemlockfile->isChecked());
00349     _pppdata->setModemTimeout( modemtimeout->value() );
00350 }
00351 
00352 
00353 void ModemWidget::slotAfterModemQuery()
00354 {
00355     _pppdata->setModemDevice( m_oldModemDev );
00356     _pppdata->setFlowcontrol( static_cast<PPPData::FlowControl>(m_oldFlowControl) );
00357     _pppdata->setEnter( static_cast<PPPData::LineTermination>(m_oldLineEnd) );
00358     _pppdata->setSpeed( m_oldSpeed );
00359     _pppdata->setModemLockFile( m_oldModemLock );
00360     _pppdata->setModemTimeout( m_oldModemTimeout );
00361 }
00362 
00363 
00364 ModemWidget2::ModemWidget2( PPPData *pd, InterfacePPP *ip, QWidget *parent,
00365                             const char *name)
00366         : QWidget(parent, name), _pppdata(pd), _ifaceppp(ip)
00367 {
00368     QVBoxLayout *l1 = new QVBoxLayout(this, 0 );//, KDialog::spacingHint());
00369 
00370 
00371     waitfordt = new QCheckBox(tr("&Wait for dial tone before dialing"), this);
00372     waitfordt->setChecked(_pppdata->waitForDialTone());
00373     //  connect(waitfordt, SIGNAL(toggled(bool)), SLOT(waitfordtchanged(bool)));
00374     l1->addWidget(waitfordt);
00375     QWhatsThis::add(waitfordt,
00376                         tr("<p>Normally the modem waits for a dial tone\n"
00377                            "from your phone line, indicating that it can\n"
00378                            "start to dial a number. If your modem does not\n"
00379                            "recognize this sound, or your local phone system\n"
00380                            "does not emit such a tone, uncheck this option\n"
00381                            "\n"
00382                            "<b>Default:</b>: On"));
00383 
00384     QHBoxLayout *waitLayout = new QHBoxLayout( this );
00385     QLabel *waitLabel = new QLabel( tr("Busy wait:"), this, "busyWait" );
00386     busywait = new QSpinBox( 0, 300, 5, this, "busyWait" );
00387     //   busywait = new KIntNumInput(_pppdata->busyWait(), this);
00388     //   busywait->setLabel(tr("B&usy wait:"));
00389     //   busywait->setRange(0, 300, 5, true);
00390     busywait->setSuffix(tr(" sec"));
00391     //  connect(busywait, SIGNAL(valueChanged(int)), SLOT(busywaitchanged(int)));
00392     waitLayout->addWidget(waitLabel);
00393     waitLayout->addWidget(busywait);
00394     l1->addLayout( waitLayout );
00395 
00396     QWhatsThis::add(busywait,
00397                         tr("Specifies the number of seconds to wait before\n"
00398                            "redial if all dialed numbers are busy. This is\n"
00399                            "necessary because some modems get stuck if the\n"
00400                            "same number is busy too often.\n"
00401                            "\n"
00402                            "The default is 0 seconds, you should not change\n"
00403                            "this unless you need to."));
00404 
00405     l1->addSpacing(10);
00406 
00407     QHBoxLayout *hbl = new QHBoxLayout;
00408     hbl->setSpacing(2);//KDialog::spacingHint());
00409 
00410     QLabel *volumeLabel = new QLabel(tr("Modem &volume:"), this);
00411     hbl->addWidget(volumeLabel);
00412     volume = new QSlider(0, 2, 1, _pppdata->volume(),
00413                          QSlider::Horizontal, this);
00414     volumeLabel->setBuddy(volume);
00415     volume->setTickmarks(QSlider::Below);
00416     hbl->addWidget(volume);
00417 
00418     l1->addLayout(hbl);
00419 
00420     //   connect(volume, SIGNAL(valueChanged(int)),
00421     //    this, SLOT(volumeChanged(int)));
00422     QString tmp = tr("Most modems have a speaker which makes\n"
00423                      "a lot of noise when dialing. Here you can\n"
00424                      "either turn this completely off or select a\n"
00425                      "lower volume.\n"
00426                      "\n"
00427                      "If this does not work for your modem,\n"
00428                      "you must modify the modem volume command.");
00429 
00430     QWhatsThis::add(volumeLabel,tmp);
00431     QWhatsThis::add(volume, tmp);
00432 
00433     l1->addSpacing(20);
00434 
00435 #if 0
00436     chkbox1 = new QCheckBox(tr("Modem asserts CD line"), this);
00437     chkbox1->setChecked(_pppdata->UseCDLine());
00438     connect(chkbox1,SIGNAL(toggled(bool)),
00439             this,SLOT(use_cdline_toggled(bool)));
00440     l12->addWidget(chkbox1);
00441     l12->addStretch(1);
00442     l1->addStretch(1);
00443     QWhatsThis::add(chkbox1,
00444                         tr("This controls how <i>kppp</i> detects that the modem\n"
00445                            "is not responding. Unless you are having\n"
00446                            "problems with this, do not modify this setting.\n"
00447                            "\n"
00448                            "<b>Default</b>: Off"));
00449 #endif
00450 
00451     modemcmds = new QPushButton(tr("Mod&em Commands..."), this);
00452     QWhatsThis::add(modemcmds,
00453                         tr("Allows you to change the AT command for\n"
00454                            "your modem."));
00455 
00456     modeminfo_button = new QPushButton(tr("&Query Modem..."), this);
00457     QWhatsThis::add(modeminfo_button,
00458                         tr("Most modems support the ATI command set to\n"
00459                            "find out vendor and revision of your modem.\n"
00460                            "\n"
00461                            "Press this button to query your modem for\n"
00462                            "this information. It can be useful to help\n"
00463                            "you setup the modem"));
00464 
00465     //   terminal_button = new QPushButton(tr("&Terminal..."), this);
00466     //   QWhatsThis::add(terminal_button,
00467     //            tr("Opens the built-in terminal program. You\n"
00468     //                 "can use this if you want to play around\n"
00469     //                 "with your modem's AT command set"));
00470 
00471     QHBoxLayout *hbox = new QHBoxLayout();
00472     l1->addLayout(hbox);
00473     hbox->addStretch(1);
00474     QVBoxLayout *vbox = new QVBoxLayout();
00475     hbox->addLayout(vbox);
00476 
00477     vbox->addWidget(modemcmds);
00478     vbox->addWidget(modeminfo_button);
00479     //  vbox->addWidget(terminal_button);
00480 
00481     hbox->addStretch(1);
00482     l1->addStretch(1);
00483 
00484     connect(modemcmds, SIGNAL(clicked()),
00485             SLOT(modemcmdsbutton()));
00486     connect(modeminfo_button, SIGNAL(clicked()),
00487             SLOT(query_modem()));
00488     //   connect(terminal_button, SIGNAL(clicked()),
00489     //    SLOT(terminal()));
00490 }
00491 
00492 
00493 void ModemWidget2::modemcmdsbutton()
00494 {
00495     ModemCommands mc(_ifaceppp->data(), this, "commands" , true, Qt::WStyle_ContextHelp);
00496 
00497     QPEApplication::execDialog( &mc );
00498 }
00499 
00500 
00501 void ModemWidget2::query_modem()
00502 {
00503     emit sig_beforeQueryModem();
00504 
00505     ModemTransfer mt(_ifaceppp->modem(), this);
00506     mt.exec();
00507 
00508     emit sig_afterQueryModem();
00509 }
00510 
00511 
00512 // void ModemWidget2::terminal() {
00513 //   MiniTerm terminal(NULL,NULL);
00514 //   terminal.exec();
00515 // }
00516 
00517 
00518 // #if 0
00519 // void ModemWidget2::use_cdline_toggled(bool on) {
00520 //     _pppdata->setUseCDLine(on);
00521 // }
00522 // #endif
00523 
00524 // void ModemWidget2::waitfordtchanged(bool b) {
00525 //   _pppdata->setWaitForDialTone((int)b);
00526 // }
00527 
00528 // void ModemWidget2::busywaitchanged(int n) {
00529 //   _pppdata->setbusyWait(n);
00530 // }
00531 
00532 
00533 // void ModemWidget2::volumeChanged(int v) {
00534 //   _pppdata->setVolume(v);
00535 // }
00536 
00537 bool ModemWidget2::save()
00538 {
00539     _pppdata->setWaitForDialTone(waitfordt->isChecked());
00540     _pppdata->setbusyWait(busywait->value());
00541     _pppdata->setVolume(volume->value());
00542     return true;
00543 }
00544 

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