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

devices.cpp

Go to the documentation of this file.
00001 /*
00002  *           kPPP: A pppd front end for the KDE project
00003  *
00004  * $Id: devices.cpp,v 1.7 2004/10/14 00:39:47 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 "interfaceppp.h"
00028 #include "devices.h"
00029 #include "authwidget.h"
00030 #include "pppdata.h"
00031 #include "edit.h"
00032 #include "general.h"
00033 
00034 /* OPIE */
00035 #include <opie2/odebug.h>
00036 #include <qpe/qpeapplication.h>
00037 using namespace Opie::Core;
00038 
00039 /* QT */
00040 #include <qdir.h>
00041 #include <qlayout.h>
00042 #include <qtabwidget.h>
00043 #include <qtabdialog.h>
00044 #include <qwhatsthis.h>
00045 #include <qmessagebox.h>
00046 #include <qapplication.h>
00047 #include <qbuttongroup.h>
00048 #include <qmessagebox.h>
00049 #include <qvgroupbox.h>
00050 
00051 /* STD */
00052 #include <stdlib.h>
00053 
00054 
00055 void parseargs(char* buf, char** args);
00056 
00057 DevicesWidget::DevicesWidget( InterfacePPP* ip, QWidget *parent, const char *name, WFlags f )
00058     : ChooserWidget(ip->data(), parent, name, f)
00059 {
00060   _ifaceppp = ip;
00061   QWhatsThis::add(edit_b, tr("Allows you to modify the selected device"));
00062   QWhatsThis::add(new_b, tr("Create a new device") );
00063 
00064   QWhatsThis::add(copy_b,
00065                   tr("Makes a copy of the selected device. All\n"
00066                        "settings of the selected device are copied\n"
00067                        "to a new device, that you can modify to fit your\n"
00068                        "needs"));
00069   QWhatsThis::add(delete_b,
00070                   tr("<p>Deletes the selected device\n\n"
00071                        "<font color=\"red\"><b>Use with care!</b></font>"));
00072 
00073   copy_b->setEnabled( false ); //FIXME
00074 //  delete_b->setEnabled( false ); //FIXME
00075 
00076   QStringList tmp = _pppdata->getDevicesNamesList();
00077   odebug << "DevicesWidget::DevicesWidget got devices " << tmp.join("--").latin1() << "" << oendl;
00078   listListbox->insertStringList(tmp);
00079 
00080   for (uint i = 0; i < listListbox->count(); i++){
00081       odebug << "listListbox->text(i) " << listListbox->text(i).latin1() << " == _pppdata->devname() " << _pppdata->devname().latin1() << "" << oendl;
00082       if ( listListbox->text(i) == _pppdata->devname() )
00083           listListbox->setCurrentItem( i );
00084   }
00085 }
00086 
00087 
00088 
00089 void DevicesWidget::slotListBoxSelect(int idx) {
00090     _pppdata->setDevice( listListbox->text(idx) );
00091     delete_b->setEnabled((bool)(idx != -1));
00092     edit_b->setEnabled((bool)(idx != -1));
00093 //FIXME  copy_b->setEnabled((bool)(idx != -1));
00094 }
00095 
00096 void DevicesWidget::edit() {
00097   _pppdata->setDevice(listListbox->text(listListbox->currentItem()));
00098 
00099   int result = doTab();
00100 
00101   if(result == QDialog::Accepted) {
00102       listListbox->changeItem(_pppdata->devname(),listListbox->currentItem());
00103       _pppdata->save();
00104   }
00105 }
00106 
00107 
00108 void DevicesWidget::create() {
00109 
00110 //     if(listListbox->count() == MAX_ACCOUNTS) {
00111 //         QMessageBox::information(this, "sorry",
00112 //                                  tr("Maximum number of accounts reached."));
00113 //         return;
00114 //     }
00115 
00116     int result;
00117     if (_pppdata->newdevice() == -1){
00118         return;
00119     }
00120     result = doTab();
00121 
00122     if(result == QDialog::Accepted) {
00123         listListbox->insertItem(_pppdata->devname());
00124         listListbox->setSelected(listListbox->findItem(_pppdata->devname()),true );
00125 
00126         _pppdata->save();
00127     } else
00128         _pppdata->deleteDevice();
00129 }
00130 
00131 
00132 void DevicesWidget::copy() {
00133 //   if(listListbox->count() == MAX_ACCOUNTS) {
00134 //     QMessageBox::information(this, "sorry", tr("Maximum number of accounts reached."));
00135 //     return;
00136 //   }
00137 
00138   if(listListbox->currentItem()<0) {
00139     QMessageBox::information(this, "sorry", tr("No devices selected."));
00140     return;
00141   }
00142 
00143   _pppdata->copydevice(listListbox->currentText());
00144 
00145   listListbox->insertItem(_pppdata->devname());
00146   _pppdata->save();
00147 }
00148 
00149 
00150 void DevicesWidget::remove() {
00151 
00152   QString s = tr("Are you sure you want to delete\nthe device \"%1\"?")
00153     .arg(listListbox->text(listListbox->currentItem()));
00154 
00155   if(QMessageBox::warning(this,tr("Confirm"),s,
00156                           QMessageBox::Yes,QMessageBox::No
00157                           ) != QMessageBox::Yes)
00158     return;
00159 
00160   if(_pppdata->deleteDevice(listListbox->text(listListbox->currentItem())))
00161     listListbox->removeItem(listListbox->currentItem());
00162 
00163 
00164 //  _pppdata->save();
00165 
00166 
00167   slotListBoxSelect(listListbox->currentItem());
00168 
00169 }
00170 
00171 
00172 int DevicesWidget::doTab(){
00173     QDialog *dlg = new QDialog( 0, "newDevice", true, Qt::WStyle_ContextHelp );
00174     QVBoxLayout *layout = new QVBoxLayout( dlg );
00175     layout->setSpacing( 0 );
00176     layout->setMargin( 1 );
00177 
00178     QTabWidget *tabWindow = new QTabWidget( dlg, "tabWindow" );
00179     layout->addWidget( tabWindow );
00180 
00181     bool isnew;
00182 
00183     if(_pppdata->devname().isEmpty()) {
00184         dlg->setCaption(tr("New Device"));
00185         isnew = true;
00186     } else {
00187         QString tit = tr("Edit Device: ");
00188         tit += _pppdata->devname();
00189         dlg->setCaption(tit);
00190         isnew = false;
00191     }
00192 
00193    modem1 = new ModemWidget( _pppdata, tabWindow, "modem1" );
00194    tabWindow->addTab( modem1, tr("&Device") );
00195    modem2 = new ModemWidget2( _pppdata, _ifaceppp, tabWindow, "modem2" );
00196    tabWindow->addTab( modem2, tr("&Modem") );
00197 
00198    connect(modem2, SIGNAL(sig_beforeQueryModem()),
00199            modem1, SLOT(slotBeforeModemQuery()));
00200    connect(modem2, SIGNAL(sig_afterQueryModem()),
00201            modem1, SLOT(slotAfterModemQuery()));
00202 
00203     int result = 0;
00204     bool ok = false;
00205 
00206     while (!ok){
00207         result = QPEApplication::execDialog( dlg );
00208         ok = true;
00209 
00210         if(result == QDialog::Accepted) {
00211             if (!modem1->save()){
00212                 QMessageBox::critical(this, tr("Error"), tr( "You must enter a unique device name"));
00213                 ok = false;
00214             }else{
00215                  modem2->save();
00216             }
00217         }
00218     }
00219 
00220     delete dlg;
00221 
00222     return result;
00223 }
00224 

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