author | kergoth <kergoth> | 2003-08-09 17:14:54 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2003-08-09 17:14:54 (UTC) |
commit | a7e015198a8c5ad3b6e144a9032b059086253e00 (patch) (side-by-side diff) | |
tree | b712b6f11310d88744fe393a92b3160b741a7efe /noncore/settings/networksettings/ppp | |
parent | beba0e73306815337bf04dee39502233595e9739 (diff) | |
download | opie-a7e015198a8c5ad3b6e144a9032b059086253e00.zip opie-a7e015198a8c5ad3b6e144a9032b059086253e00.tar.gz opie-a7e015198a8c5ad3b6e144a9032b059086253e00.tar.bz2 |
Merge from BRANCH_1_0
Diffstat (limited to 'noncore/settings/networksettings/ppp') (more/less context) (show whitespace changes)
29 files changed, 1541 insertions, 664 deletions
diff --git a/noncore/settings/networksettings/ppp/TODO b/noncore/settings/networksettings/ppp/TODO index 80fc5a6..14a1b3f 100644 --- a/noncore/settings/networksettings/ppp/TODO +++ b/noncore/settings/networksettings/ppp/TODO @@ -1,9 +1,3 @@ -- ask for password is non is set - -- stop pppd, i.e. fix interfaceinformationppp - -- update modem attribute inputs when modem has changed -- impl. PPPData::copyaccount & PPPData::deleteAccount - +- impl. PPPData::copyaccount - check if the same interface device combination allready exists -- fix layout of edit account, i.e. get it shown maximised +- check if a deleted account or device exists in a config and ask the user diff --git a/noncore/settings/networksettings/ppp/accounts.cpp b/noncore/settings/networksettings/ppp/accounts.cpp index fa1c43b..28d8732 100644 --- a/noncore/settings/networksettings/ppp/accounts.cpp +++ b/noncore/settings/networksettings/ppp/accounts.cpp @@ -35,185 +35,151 @@ #include <qapplication.h> #include <qbuttongroup.h> #include <qmessagebox.h> #include <qvgroupbox.h> #include "accounts.h" #include "authwidget.h" #include "pppdata.h" #include "edit.h" void parseargs(char* buf, char** args); -AccountWidget::AccountWidget( PPPData *pd, QWidget *parent, const char *name ) - : QWidget( parent, name )//, _pppdata(pd) + +AccountWidget::AccountWidget( PPPData *pd, QWidget *parent, const char *name, WFlags f ) + : ChooserWidget( pd, parent, name, f ) { - _pppdata = pd; - QVBoxLayout *l1 = new QVBoxLayout(this, 10, 10); - accountlist_l = new QListBox(this); - - connect(accountlist_l, SIGNAL(highlighted(int)), - this, SLOT(slotListBoxSelect(int))); - connect(accountlist_l, SIGNAL(selected(int)), - this, SLOT(editaccount())); - l1->addWidget(accountlist_l, 10); - - edit_b = new QPushButton(tr("&Edit..."), this); - connect(edit_b, SIGNAL(clicked()), SLOT(editaccount())); - QWhatsThis::add(edit_b, tr("Allows you to modify the selected account")); - l1->addWidget(edit_b); - new_b = new QPushButton(tr("&New..."), this); - connect(new_b, SIGNAL(clicked()), SLOT(newaccount())); - l1->addWidget(new_b); + QWhatsThis::add(edit_b, tr("Allows you to modify the selected account")); QWhatsThis::add(new_b, tr("Create a new dialup connection\n" "to the Internet")); - - copy_b = new QPushButton(tr("Co&py"), this); - connect(copy_b, SIGNAL(clicked()), SLOT(copyaccount())); - l1->addWidget(copy_b); QWhatsThis::add(copy_b, tr("Makes a copy of the selected account. All\n" "settings of the selected account are copied\n" "to a new account, that you can modify to fit your\n" "needs")); - - delete_b = new QPushButton(tr("De&lete"), this); - connect(delete_b, SIGNAL(clicked()), SLOT(deleteaccount())); - l1->addWidget(delete_b); QWhatsThis::add(delete_b, tr("<p>Deletes the selected account\n\n" "<font color=\"red\"><b>Use with care!</b></font>")); - QHBoxLayout *l12 = new QHBoxLayout; - l1->addStretch(1); - l1->addLayout(l12); - int currAccId = _pppdata->currentAccountID(); - qDebug("currentAccountID %i", currAccId); - //load up account list from gppdata to the list box - if(_pppdata->count() > 0) { - for(int i=0; i <= _pppdata->count()-1; i++) { - _pppdata->setAccountbyIndex(i); - accountlist_l->insertItem(_pppdata->accname()); - } - } - _pppdata->setAccountbyIndex( currAccId ); + copy_b->setEnabled( false ); //FIXME + // delete_b->setEnabled( false ); //FIXME - qDebug("setting listview index to %i",_pppdata->currentAccountID() ); - accountlist_l->setCurrentItem( _pppdata->currentAccountID() ); - slotListBoxSelect( _pppdata->currentAccountID() ); + listListbox->insertStringList(_pppdata->getAccountList()); - l1->activate(); + for (uint i = 0; i < listListbox->count(); i++){ + if ( listListbox->text(i) == _pppdata->accname() ) + listListbox->setCurrentItem( i ); + } } void AccountWidget::slotListBoxSelect(int idx) { - delete_b->setEnabled((bool)(idx != -1)); - edit_b->setEnabled((bool)(idx != -1)); - copy_b->setEnabled((bool)(idx != -1)); - if(idx!=-1) { - qDebug("setting account to %i", idx); - QString account = _pppdata->accname(); - _pppdata->setAccountbyIndex(accountlist_l->currentItem()); - } + bool ok = _pppdata->setAccount( listListbox->text(idx) ); + ok = (bool)(idx != -1); + delete_b->setEnabled(ok); + edit_b->setEnabled(ok); +//FIXME copy_b->setEnabled(ok); } -void AccountWidget::editaccount() { - _pppdata->setAccount(accountlist_l->text(accountlist_l->currentItem())); +void AccountWidget::edit() { + _pppdata->setAccount(listListbox->text(listListbox->currentItem())); int result = doTab(); if(result == QDialog::Accepted) { - accountlist_l->changeItem(_pppdata->accname(),accountlist_l->currentItem()); + listListbox->changeItem(_pppdata->accname(),listListbox->currentItem()); // emit resetaccounts(); _pppdata->save(); } } -void AccountWidget::newaccount() { +void AccountWidget::create() { - if(accountlist_l->count() == MAX_ACCOUNTS) { - QMessageBox::information(this, "sorry", - tr("Maximum number of accounts reached.")); - return; - } +// if(listListbox->count() == MAX_ACCOUNTS) { +// QMessageBox::information(this, "sorry", +// tr("Maximum number of accounts reached.")); +// return; +// } int result; if (_pppdata->newaccount() == -1){ qDebug("_pppdata->newaccount() == -1"); return; } result = doTab(); if(result == QDialog::Accepted) { - accountlist_l->insertItem(_pppdata->accname()); - accountlist_l->setSelected(accountlist_l->findItem(_pppdata->accname()),true); + listListbox->insertItem(_pppdata->accname()); + listListbox->setSelected(listListbox->findItem(_pppdata->accname()),true); _pppdata->save(); } else _pppdata->deleteAccount(); } -void AccountWidget::copyaccount() { - if(accountlist_l->count() == MAX_ACCOUNTS) { - QMessageBox::information(this, "sorry", tr("Maximum number of accounts reached.")); - return; - } +void AccountWidget::copy() { +// if(listListbox->count() == MAX_ACCOUNTS) { +// QMessageBox::information(this, "sorry", tr("Maximum number of accounts reached.")); +// return; +// } - if(accountlist_l->currentItem()<0) { + if(listListbox->currentItem()<0) { QMessageBox::information(this, "sorry", tr("No account selected.")); return; } - _pppdata->copyaccount(accountlist_l->currentItem()); + _pppdata->copyaccount(listListbox->currentText()); - accountlist_l->insertItem(_pppdata->accname()); + listListbox->insertItem(_pppdata->accname()); // emit resetaccounts(); _pppdata->save(); } -void AccountWidget::deleteaccount() { +void AccountWidget::remove() { QString s = tr("Are you sure you want to delete\nthe account \"%1\"?") - .arg(accountlist_l->text(accountlist_l->currentItem())); + .arg(listListbox->text(listListbox->currentItem())); if(QMessageBox::warning(this,tr("Confirm"),s, QMessageBox::Yes,QMessageBox::No ) != QMessageBox::Yes) return; - if(_pppdata->deleteAccount(accountlist_l->text(accountlist_l->currentItem()))) - accountlist_l->removeItem(accountlist_l->currentItem()); + if(_pppdata->deleteAccount(listListbox->text(listListbox->currentItem()))) + listListbox->removeItem(listListbox->currentItem()); - emit resetaccounts(); - _pppdata->save(); - slotListBoxSelect(accountlist_l->currentItem()); +// emit resetaccounts(); +// _pppdata->save(); + + + slotListBoxSelect(listListbox->currentItem()); } int AccountWidget::doTab(){ - QDialog *dlg = new QDialog( 0, "newAccount", true ); + QDialog *dlg = new QDialog( 0, "newAccount", true, Qt::WStyle_ContextHelp ); QVBoxLayout *layout = new QVBoxLayout( dlg ); layout->setSpacing( 0 ); layout->setMargin( 1 ); - tabWindow = new QTabWidget( dlg, "tabWindow" ); + QTabWidget *tabWindow = new QTabWidget( dlg, "tabWindow" ); layout->addWidget( tabWindow ); bool isnewaccount; if(_pppdata->accname().isEmpty()) { dlg->setCaption(tr("New Account")); isnewaccount = true; } else { QString tit = tr("Edit Account: "); tit += _pppdata->accname(); dlg->setCaption(tit); isnewaccount = false; @@ -264,43 +230,43 @@ int AccountWidget::doTab(){ auth_w->save(); exec_w->save(); } } } delete dlg; return result; } -QString AccountWidget::prettyPrintVolume(unsigned int n) { - int idx = 0; - const QString quant[] = {tr("Byte"), tr("KB"), - tr("MB"), tr("GB"), QString::null}; +// QString AccountWidget::prettyPrintVolume(unsigned int n) { +// int idx = 0; +// const QString quant[] = {tr("Byte"), tr("KB"), +// tr("MB"), tr("GB"), QString::null}; - float n1 = n; - while(n >= 1024 && quant[idx] != QString::null) { - idx++; - n /= 1024; - } +// float n1 = n; +// while(n >= 1024 && quant[idx] != QString::null) { +// idx++; +// n /= 1024; +// } - int i = idx; - while(i--) - n1 = n1 / 1024.0; +// int i = idx; +// while(i--) +// n1 = n1 / 1024.0; - QString s = QString::number( n1, 'f', idx==0 ? 0 : 1 ); - s += " " + quant[idx]; - return s; -} +// QString s = QString::number( n1, 'f', idx==0 ? 0 : 1 ); +// s += " " + quant[idx]; +// return s; +// } ///////////////////////////////////////////////////////////////////////////// // // Queries the user what to reset: costs, volume or both // ///////////////////////////////////////////////////////////////////////////// // QueryReset::QueryReset(QWidget *parent) : QDialog(parent, 0, true) { // // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); // setCaption(tr("Reset Accounting")); // QVBoxLayout *tl = new QVBoxLayout(this, 10, 10); diff --git a/noncore/settings/networksettings/ppp/accounts.h b/noncore/settings/networksettings/ppp/accounts.h index 8c16a7c..7f31513 100644 --- a/noncore/settings/networksettings/ppp/accounts.h +++ b/noncore/settings/networksettings/ppp/accounts.h @@ -18,69 +18,63 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef _ACCOUNTS_H_ #define _ACCOUNTS_H_ -#include <qwidget.h> #include <qdialog.h> #include <qpushbutton.h> #include <qlistbox.h> -//#include "acctselect.h" +#include "chooserwidget.h" -class QDialog; class QCheckBox; class QLineEdit; class QTabWidget; +class ModemWidget; +class ModemWidget2; + + class DialWidget; class AuthWidget; class IPWidget; class DNSWidget; class GatewayWidget; class PPPData; -class AccountWidget : public QWidget { + +class AccountWidget : public ChooserWidget { + Q_OBJECT public: - AccountWidget( PPPData *pd, QWidget *parent=0, const char *name=0 ); + AccountWidget( PPPData *pd, QWidget *parent=0, const char *name=0, WFlags f=0 ); ~AccountWidget() {} -private slots: - void editaccount(); - void copyaccount(); - void newaccount(); - void deleteaccount(); - void slotListBoxSelect(int); -private: +private slots: + virtual void edit(); + virtual void copy(); + virtual void remove(); + virtual void create(); + virtual void slotListBoxSelect(int); int doTab(); signals: void resetaccounts(); private: - QString prettyPrintVolume(unsigned int); - - PPPData *_pppdata; - QTabWidget *tabWindow; DialWidget *dial_w; IPWidget *ip_w; DNSWidget *dns_w; GatewayWidget *gateway_w; AuthWidget *auth_w; - QListBox *accountlist_l; - QPushButton *edit_b; - QPushButton *copy_b; - QPushButton *new_b; - QPushButton *delete_b; }; #endif diff --git a/noncore/settings/networksettings/ppp/chooserwidget.cpp b/noncore/settings/networksettings/ppp/chooserwidget.cpp new file mode 100644 index 0000000..a32b2b8 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/chooserwidget.cpp @@ -0,0 +1,85 @@ +/* + * kPPP: A pppd front end for the KDE project + * + * $Id$ + * + * Copyright (C) 1997 Bernd Johannes Wuebben + * wuebben@math.cornell.edu + * + * based on EzPPP: + * Copyright (C) 1997 Jay Painter + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <qdir.h> +#include <stdlib.h> +#include <qlayout.h> +#include <qtabwidget.h> +#include <qtabdialog.h> +#include <qwhatsthis.h> +#include <qmessagebox.h> + +#include <qapplication.h> +#include <qbuttongroup.h> +#include <qmessagebox.h> +#include <qvgroupbox.h> +#include <qwidget.h> + +#include "accounts.h" +#include "authwidget.h" +#include "pppdata.h" +#include "edit.h" + +void parseargs(char* buf, char** args); + +ChooserWidget::ChooserWidget( PPPData *pd, QWidget *parent, const char *name, WFlags f ) + : QWidget( parent, name, f ) +{ + _pppdata = pd; + QVBoxLayout *l1 = new QVBoxLayout(this, 10, 10); + listListbox = new QListBox(this); + + connect(listListbox, SIGNAL(highlighted(int)), + this, SLOT(slotListBoxSelect(int))); + connect(listListbox, SIGNAL(selected(int)),this, SLOT(edit())); + l1->addWidget(listListbox, 10); + + edit_b = new QPushButton(tr("&Edit..."), this); + connect(edit_b, SIGNAL(clicked()), SLOT(edit())); + l1->addWidget(edit_b); + + new_b = new QPushButton(tr("&New..."), this); + connect(new_b, SIGNAL(clicked()), SLOT(create())); + l1->addWidget(new_b); + + + copy_b = new QPushButton(tr("Co&py"), this); + connect(copy_b, SIGNAL(clicked()), SLOT(copy())); + l1->addWidget(copy_b); + + delete_b = new QPushButton(tr("De&lete"), this); + connect(delete_b, SIGNAL(clicked()), SLOT(remove())); + l1->addWidget(delete_b); + + + QHBoxLayout *l12 = new QHBoxLayout; + l1->addStretch(1); + l1->addLayout(l12); + + l1->activate(); + +} + diff --git a/noncore/settings/networksettings/ppp/chooserwidget.h b/noncore/settings/networksettings/ppp/chooserwidget.h new file mode 100644 index 0000000..ac3f4cb --- a/dev/null +++ b/noncore/settings/networksettings/ppp/chooserwidget.h @@ -0,0 +1,73 @@ +/* -*- C++ -*- + * kPPP: A pppd front end for the KDE project + * + * $Id$ + * + * Copyright (C) 1997 Bernd Johannes Wuebben + * wuebben@math.cornell.edu + * + * based on EzPPP: + * Copyright (C) 1997 Jay Painter + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef _CHOOSERWIDGET_H_ +#define _CHOOSERWIDGET_H_ + +#include <qwidget.h> +#include <qdialog.h> +#include <qpushbutton.h> +#include <qlistbox.h> +//#include "acctselect.h" + +class QDialog; +class QCheckBox; +class QLineEdit; +class QTabWidget; +class DialWidget; +class AuthWidget; +class IPWidget; +class DNSWidget; +class GatewayWidget; +class PPPData; + +class ChooserWidget : public QWidget { + Q_OBJECT +public: + ChooserWidget( PPPData *pd, QWidget *parent=0, const char *name=0, WFlags f=0 ); + ~ChooserWidget() {} + +private slots: + virtual void edit() = 0; + virtual void copy() = 0; + virtual void create()= 0; + virtual void remove()= 0; + virtual void slotListBoxSelect(int) = 0; + + +protected: + PPPData *_pppdata; + + QListBox *listListbox; + QPushButton *edit_b; + QPushButton *copy_b; + QPushButton *new_b; + QPushButton *delete_b; +}; + + +#endif + diff --git a/noncore/settings/networksettings/ppp/connect.cpp b/noncore/settings/networksettings/ppp/connect.cpp index 2400d7b..e3fab24 100644 --- a/noncore/settings/networksettings/ppp/connect.cpp +++ b/noncore/settings/networksettings/ppp/connect.cpp @@ -23,25 +23,24 @@ * License along with this program; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ //#include <config.h> #include <qlayout.h> #include <qregexp.h> #include <qapplication.h> //#include <kdebug.h> //#include <klocale.h> -#define i18n QObject::tr #include <qmessagebox.h> #include <qpushbutton.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <netdb.h> #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netinet/in.h> @@ -90,56 +89,56 @@ ConnectWidget::ConnectWidget(InterfacePPP *ifp, QWidget *parent, const char *nam semaphore(false), expecting(false), readbuffer(""), scanvar(""), scanning(false), pausing(false), dialnumber(0), _ifaceppp(ifp) { modified_hostname = false; QVBoxLayout *tl = new QVBoxLayout(this, 8, 10); - QString tit = i18n("Connecting to: "); + QString tit = QObject::tr("Connecting to: "); setCaption(tit); QHBoxLayout *l0 = new QHBoxLayout(10); tl->addLayout(l0); l0->addSpacing(10); messg = new QLabel(this, "messg"); messg->setFrameStyle(QFrame::Panel|QFrame::Sunken); messg->setAlignment(AlignCenter); - messg->setText(i18n("Unable to create modem lock file.")); + messg->setText(QObject::tr("Unable to create modem lock file.")); messg->setMinimumHeight(messg->sizeHint().height() + 5); // int messw = (messg->sizeHint().width() * 12) / 10; // messw = QMAX(messw,280); // messg->setMinimumWidth(messw); if (_ifaceppp->getStatus()) - messg->setText(i18n("Online")); + messg->setText(QObject::tr("Online")); else - messg->setText(i18n("Offline")); + messg->setText(QObject::tr("Offline")); l0->addSpacing(10); l0->addWidget(messg); l0->addSpacing(10); QHBoxLayout *l1 = new QHBoxLayout(10); tl->addLayout(l1); l1->addStretch(1); - debug = new QPushButton(i18n("Log"), this); + debug = new QPushButton(QObject::tr("Log"), this); debug->setToggleButton(true); debug->setEnabled( false ); // FIXME: disable the log button connect(debug, SIGNAL(clicked()), SIGNAL(toggleDebugWindow())); - cancel = new QPushButton(i18n("Cancel"), this); + cancel = new QPushButton(QObject::tr("Cancel"), this); cancel->setFocus(); connect(cancel, SIGNAL(clicked()), SLOT(cancelbutton())); // int maxw = QMAX(cancel->sizeHint().width(), // debug->sizeHint().width()); // maxw = QMAX(maxw,65); // debug->setFixedWidth(maxw); // cancel->setFixedWidth(maxw); l1->addWidget(debug); l1->addWidget(cancel); // setFixedSize(sizeHint()); @@ -164,25 +163,25 @@ ConnectWidget::ConnectWidget(InterfacePPP *ifp, QWidget *parent, const char *nam if_timer = new QTimer(this); connect(if_timer,SIGNAL(timeout()), SLOT(if_waiting_slot())); } ConnectWidget::~ConnectWidget() { } void ConnectWidget::preinit() { // this is all just to keep the GUI nice and snappy .... // you have to see to believe ... - messg->setText(i18n("Looking for modem...")); + messg->setText(QObject::tr("Looking for modem...")); inittimer->start(100); } void ConnectWidget::init() { _ifaceppp->data()->setpppdError(0); inittimer->stop(); vmain = 0; substate = -1; expecting = false; pausing = false; scriptindex = 0; @@ -192,56 +191,56 @@ void ConnectWidget::init() { firstrunID = true; firstrunPW = true; // stats->totalbytes = 0; dialnumber = 0; // p_kppp->con_speed = ""; // p_kppp->setQuitOnDisconnect (p_kppp->quitOnDisconnect() || _ifaceppp->data()->quit_on_disconnect()); comlist = &_ifaceppp->data()->scriptType(); arglist = &_ifaceppp->data()->script(); - QString tit = i18n("Connecting to: %1").arg(_ifaceppp->data()->accname()); + QString tit = QObject::tr("Connecting to: %1").arg(_ifaceppp->data()->accname()); setCaption(tit); qApp->processEvents(); // run the "before-connect" command if (!_ifaceppp->data()->command_before_connect().isEmpty()) { - messg->setText(i18n("Running pre-startup command...")); - emit debugMessage(i18n("Running pre-startup command...")); + messg->setText(QObject::tr("Running pre-startup command...")); + emit debugMessage(QObject::tr("Running pre-startup command...")); qApp->processEvents(); QApplication::flushX(); pid_t id = execute_command(_ifaceppp->data()->command_before_connect()); // int i, status; // do { // qApp->processEvents(); // i = waitpid(id, &status, WNOHANG); // usleep(100000); // } while (i == 0 && errno == 0); } int lock = _ifaceppp->modem()->lockdevice(); if (lock == 1) { - messg->setText(i18n("Modem device is locked.")); + messg->setText(QObject::tr("Modem device is locked.")); vmain = 20; // wait until cancel is pressed return; } if (lock == -1) { - messg->setText(i18n("Unable to create modem lock file.")); + messg->setText(QObject::tr("Unable to create modem lock file.")); vmain = 20; // wait until cancel is pressed return; } if(_ifaceppp->modem()->opentty()) { messg->setText(_ifaceppp->modem()->modemMessage()); qApp->processEvents(); if(_ifaceppp->modem()->hangup()) { qApp->processEvents(); semaphore = false; @@ -270,26 +269,26 @@ void ConnectWidget::timerEvent(QTimerEvent *) { if (semaphore || pausing) return; if(vmain == 0) { #ifdef DEBUG_WO_DIALING vmain = 10; return; #endif assert(PPPData::NumInitStrings > 0); // first init string ? if(substate == -1) { - messg->setText(i18n("Initializing modem...")); - emit debugMessage(i18n("Initializing modem...")); + messg->setText(QObject::tr("Initializing modem...")); + emit debugMessage(QObject::tr("Initializing modem...")); substate = 0; } QString initStr = _ifaceppp->data()->modemInitStr(substate); if (!initStr.isEmpty()) { // send a carriage return and then wait a bit so that the modem will // let us issue commands. if(_ifaceppp->data()->modemPreInitDelay() > 0) { usleep(_ifaceppp->data()->modemPreInitDelay() * 5000); writeline(""); usleep(_ifaceppp->data()->modemPreInitDelay() * 5000); } @@ -308,85 +307,85 @@ void ConnectWidget::timerEvent(QTimerEvent *) { */ if (MODEM_TONEDURATION != _ifaceppp->data()->modemToneDuration()) vmain = 5; else vmain = 3; return; } if (vmain == 5) { if(!expecting) { QString sToneDuration = "ATS11=" + QString::number(_ifaceppp->data()->modemToneDuration()); - QString msg = i18n("Setting ") + sToneDuration; + QString msg = QObject::tr("Setting ") + sToneDuration; messg->setText(msg); emit debugMessage(msg); setExpect(_ifaceppp->data()->modemInitResp()); writeline(sToneDuration); } vmain = 3; return; } if(vmain == 3) { if(!expecting) { // done with all init strings ? if(substate < PPPData::NumInitStrings) { vmain = 0; return; } substate = -1; // skip setting the volume if command is empty if(_ifaceppp->data()->volumeInitString().isEmpty()) { vmain = 4; return; } - messg->setText(i18n("Setting speaker volume...")); - emit debugMessage(i18n("Setting speaker volume...")); + messg->setText(QObject::tr("Setting speaker volume...")); + emit debugMessage(QObject::tr("Setting speaker volume...")); setExpect(_ifaceppp->data()->modemInitResp()); QString vol("AT"); vol += _ifaceppp->data()->volumeInitString(); writeline(vol); usleep(_ifaceppp->data()->modemInitDelay() * 10000); // 0.01 - 3.0 sec vmain = 4; return; } } if(vmain == 4) { if(!expecting) { if(!_ifaceppp->data()->waitForDialTone()) { - QString msg = i18n("Turning off dial tone waiting..."); + QString msg = QObject::tr("Turning off dial tone waiting..."); messg->setText(msg); emit debugMessage(msg); setExpect(_ifaceppp->data()->modemInitResp()); writeline(_ifaceppp->data()->modemNoDialToneDetectionStr()); } vmain = 1; return; } } // dial the number and wait to connect if(vmain == 1) { if(!expecting) { timeout_timer->stop(); timeout_timer->start(_ifaceppp->data()->modemTimeout()*1000); QStringList &plist = _ifaceppp->data()->phonenumbers(); QString bmarg= _ifaceppp->data()->dialPrefix(); bmarg += *plist.at(dialnumber); - QString bm = i18n("Dialing %1").arg(bmarg); + QString bm = QObject::tr("Dialing %1").arg(bmarg); messg->setText(bm); emit debugMessage(bm); QString pn = _ifaceppp->data()->modemDialStr(); pn += _ifaceppp->data()->dialPrefix(); pn += *plist.at(dialnumber); if(++dialnumber >= plist.count()) dialnumber = 0; writeline(pn); setExpect(_ifaceppp->data()->modemConnectResp()); vmain = 100; @@ -399,58 +398,58 @@ void ConnectWidget::timerEvent(QTimerEvent *) { if(vmain == 100) { if(!expecting) { myreadbuffer = _ifaceppp->data()->modemConnectResp(); setExpect("\n"); vmain = 101; return; } if(readbuffer.contains(_ifaceppp->data()->modemBusyResp())) { timeout_timer->stop(); timeout_timer->start(_ifaceppp->data()->modemTimeout()*1000); - messg->setText(i18n("Line busy. Hanging up...")); + messg->setText(QObject::tr("Line busy. Hanging up...")); emit debugPutChar('\n'); _ifaceppp->modem()->hangup(); if(_ifaceppp->data()->busyWait() > 0) { - QString bm = i18n("Line busy. Waiting: %1 seconds").arg(_ifaceppp->data()->busyWait()); + QString bm = QObject::tr("Line busy. Waiting: %1 seconds").arg(_ifaceppp->data()->busyWait()); messg->setText(bm); emit debugMessage(bm); pausing = true; pausetimer->start(_ifaceppp->data()->busyWait()*1000, true); timeout_timer->stop(); } _ifaceppp->modem()->setDataMode(false); vmain = 0; substate = -1; return; } if(readbuffer.contains(_ifaceppp->data()->modemNoDialtoneResp())) { timeout_timer->stop(); - messg->setText(i18n("No Dialtone")); + messg->setText(QObject::tr("No Dialtone")); vmain = 20; _ifaceppp->modem()->unlockdevice(); return; } if(readbuffer.contains(_ifaceppp->data()->modemNoCarrierResp())) { timeout_timer->stop(); - messg->setText(i18n("No Carrier")); + messg->setText(QObject::tr("No Carrier")); vmain = 20; _ifaceppp->modem()->unlockdevice(); return; } } // wait for newline after CONNECT response (so we get the speed) if(vmain == 101) { if(!expecting) { _ifaceppp->modem()->setDataMode(true); // modem will no longer respond to AT commands emit startAccounting(); @@ -470,144 +469,144 @@ void ConnectWidget::timerEvent(QTimerEvent *) { timeout_timer->start(scriptTimeout); if((unsigned) scriptindex < comlist->count()) { scriptCommand = *(comlist->at(scriptindex)); scriptArgument = *(arglist->at(scriptindex)); } else { qDebug( "End of script" ); vmain = 10; return; } if (scriptCommand == "Scan") { - QString bm = i18n("Scanning %1").arg(scriptArgument); + QString bm = QObject::tr("Scanning %1").arg(scriptArgument); messg->setText(bm); emit debugMessage(bm); setScan(scriptArgument); scriptindex++; return; } if (scriptCommand == "Save") { - QString bm = i18n("Saving %1").arg(scriptArgument); + QString bm = QObject::tr("Saving %1").arg(scriptArgument); messg->setText(bm); emit debugMessage(bm); if (scriptArgument.lower() == "password") { _ifaceppp->data()->setPassword(scanvar); // p_kppp->setPW_Edit(scanvar); if(_ifaceppp->data()->storePassword()) _ifaceppp->data()->setStoredPassword(scanvar); firstrunPW = true; } scriptindex++; return; } if (scriptCommand == "Send" || scriptCommand == "SendNoEcho") { - QString bm = i18n("Sending %1"); + QString bm = QObject::tr("Sending %1"); // replace %USERNAME% and %PASSWORD% QString arg = scriptArgument; QRegExp re1("%USERNAME%"); QRegExp re2("%PASSWORD%"); arg = arg.replace(re1, _ifaceppp->data()->storedUsername()); arg = arg.replace(re2, _ifaceppp->data()->storedPassword()); if (scriptCommand == "Send") bm = bm.arg(scriptArgument); else { for(uint i = 0; i < scriptArgument.length(); i++) bm = bm.arg("*"); } messg->setText(bm); emit debugMessage(bm); writeline(scriptArgument); scriptindex++; return; } if (scriptCommand == "Expect") { - QString bm = i18n("Expecting %1").arg(scriptArgument); + QString bm = QObject::tr("Expecting %1").arg(scriptArgument); messg->setText(bm); emit debugMessage(bm); // The incrementing of the scriptindex MUST be before the // call to setExpect otherwise the expect will miss a string that is // already in the buffer. scriptindex++; setExpect(scriptArgument); return; } if (scriptCommand == "Pause") { - QString bm = i18n("Pause %1 seconds").arg(scriptArgument); + QString bm = QObject::tr("Pause %1 seconds").arg(scriptArgument); messg->setText(bm); emit debugMessage(bm); pausing = true; pausetimer->start(scriptArgument.toInt()*1000, true); timeout_timer->stop(); scriptindex++; return; } if (scriptCommand == "Timeout") { timeout_timer->stop(); - QString bm = i18n("Timeout %1 seconds").arg(scriptArgument); + QString bm = QObject::tr("Timeout %1 seconds").arg(scriptArgument); messg->setText(bm); emit debugMessage(bm); scriptTimeout=scriptArgument.toInt()*1000; timeout_timer->start(scriptTimeout); scriptindex++; return; } if (scriptCommand == "Hangup") { - messg->setText(i18n("Hangup")); - emit debugMessage(i18n("Hangup")); + messg->setText(QObject::tr("Hangup")); + emit debugMessage(QObject::tr("Hangup")); writeline(_ifaceppp->data()->modemHangupStr()); setExpect(_ifaceppp->data()->modemHangupResp()); scriptindex++; return; } if (scriptCommand == "Answer") { timeout_timer->stop(); - messg->setText(i18n("Answer")); - emit debugMessage(i18n("Answer")); + messg->setText(QObject::tr("Answer")); + emit debugMessage(QObject::tr("Answer")); setExpect(_ifaceppp->data()->modemRingResp()); vmain = 150; return; } if (scriptCommand == "ID") { - QString bm = i18n("ID %1").arg(scriptArgument); + QString bm = QObject::tr("ID %1").arg(scriptArgument); messg->setText(bm); emit debugMessage(bm); QString idstring = _ifaceppp->data()->password(); if(!idstring.isEmpty() && firstrunID) { // the user entered an Id on the main kppp dialog writeline(idstring); firstrunID = false; scriptindex++; } else { @@ -625,25 +624,25 @@ void ConnectWidget::timerEvent(QTimerEvent *) { if(!(prompt->isVisible())) { writeline(prompt->text()); prompt->setConsumed(); scriptindex++; return; } /* replace timeout value */ } } } if (scriptCommand == "Password") { - QString bm = i18n("Password %1").arg(scriptArgument); + QString bm = QObject::tr("Password %1").arg(scriptArgument); messg->setText(bm); emit debugMessage(bm); QString pwstring = _ifaceppp->data()->password(); if(!pwstring.isEmpty() && firstrunPW) { // the user entered a password on the main kppp dialog writeline(pwstring); firstrunPW = false; scriptindex++; } else { @@ -662,25 +661,25 @@ void ConnectWidget::timerEvent(QTimerEvent *) { // p_kppp->setPW_Edit(prompt->text()); writeline(prompt->text()); prompt->setConsumed(); scriptindex++; return; } /* replace timeout value */ } } } if (scriptCommand == "Prompt") { - QString bm = i18n("Prompting %1"); + QString bm = QObject::tr("Prompting %1"); // if the scriptindex (aka the prompt text) includes a ## marker // this marker should get substituted with the contents of our stored // variable (from the subsequent scan). QString ts = scriptArgument; int vstart = ts.find( "##" ); if( vstart != -1 ) { ts.remove( vstart, 2 ); ts.insert( vstart, scanvar ); } @@ -699,77 +698,77 @@ void ConnectWidget::timerEvent(QTimerEvent *) { /* if prompt withdrawn ... then, */ if (!(prompt->isVisible())) { writeline(prompt->text()); prompt->setConsumed(); scriptindex++; return; } /* replace timeout value */ } } if (scriptCommand == "PWPrompt") { - QString bm = i18n("PW Prompt %1").arg(scriptArgument); + QString bm = QObject::tr("PW Prompt %1").arg(scriptArgument); messg->setText(bm); emit debugMessage(bm); /* if not around yet, then post window... */ if (prompt->Consumed()) { if (!(prompt->isVisible())) { prompt->setPrompt(scriptArgument); prompt->setEchoModePassword(); prompt->show(); } } else { /* if prompt withdrawn ... then, */ if (!(prompt->isVisible())) { writeline(prompt->text()); prompt->setConsumed(); scriptindex++; return; } /* replace timeout value */ } } if (scriptCommand == "LoopStart") { - QString bm = i18n("Loop Start %1").arg(scriptArgument); + QString bm = QObject::tr("Loop Start %1").arg(scriptArgument); // The incrementing of the scriptindex MUST be before the // call to setExpect otherwise the expect will miss a string that is // already in the buffer. scriptindex++; if ( loopnest > (MAXLOOPNEST-2) ) { - bm += i18n("ERROR: Nested too deep, ignored."); + bm += QObject::tr("ERROR: Nested too deep, ignored."); vmain=20; cancelbutton(); - QMessageBox::critical(0, "error", i18n("Loops nested too deeply!")); + QMessageBox::critical(0, "error", QObject::tr("Loops nested too deeply!")); } else { setExpect(scriptArgument); loopstartindex[loopnest] = scriptindex; loopstr[loopnest] = scriptArgument; loopend = false; loopnest++; } messg->setText(bm); emit debugMessage(bm); } if (scriptCommand == "LoopEnd") { - QString bm = i18n("Loop End %1").arg(scriptArgument); + QString bm = QObject::tr("Loop End %1").arg(scriptArgument); if ( loopnest <= 0 ) { - bm = i18n("LoopEnd without matching Start! Line: %1").arg(bm); + bm = QObject::tr("LoopEnd without matching Start! Line: %1").arg(bm); vmain=20; cancelbutton(); QMessageBox::critical(0, "error", bm); return; } else { // NB! The incrementing of the scriptindex MUST be before the // call to setExpect otherwise the expect will miss a string // that is already in the buffer. scriptindex++; setExpect(scriptArgument); loopnest--; loopend = true; @@ -839,25 +838,25 @@ void ConnectWidget::timerEvent(QTimerEvent *) { killTimer( main_timer_ID ); if_timeout_timer->start(_ifaceppp->data()->pppdTimeout()*1000); qDebug( "started if timeout timer with %i", _ifaceppp->data()->pppdTimeout()*1000); // find out PPP interface and notify the stats module // stats->setUnit(pppInterfaceNumber()); qApp->flushX(); semaphore = true; result = execppp(); - emit debugMessage(i18n("Starting pppd...")); + emit debugMessage(QObject::tr("Starting pppd...")); qDebug("execppp() returned with return-code %i", result ); if(result) { if(!_ifaceppp->data()->autoDNS()) adddns( _ifaceppp ); // O.K we are done here, let's change over to the if_waiting loop // where we wait for the ppp if (interface) to come up. emit if_waiting_signal(); } else { @@ -921,46 +920,46 @@ void ConnectWidget::checkBuffers() { // Let's check if we are finished with scanning: // The scanstring have to be in the buffer and the latest character // was a carriage return or an linefeed (depending on modem setup) if( scanning && scanbuffer.contains(scanstr) && ( scanbuffer.right(1) == "\n" || scanbuffer.right(1) == "\r") ) { scanning = false; int vstart = scanbuffer.find( scanstr ) + scanstr.length(); scanvar = scanbuffer.mid( vstart, scanbuffer.length() - vstart); scanvar = scanvar.stripWhiteSpace(); // Show the Variabel content in the debug window - QString sv = i18n("Scan Var: %1").arg(scanvar); + QString sv = QObject::tr("Scan Var: %1").arg(scanvar); emit debugMessage(sv); } if(expecting) { if(readbuffer.contains(expectstr)) { expecting = false; // keep everything after the expected string readbuffer.remove(0, readbuffer.find(expectstr) + expectstr.length()); - QString ts = i18n("Found: %1").arg(expectstr); + QString ts = QObject::tr("Found: %1").arg(expectstr); emit debugMessage(ts); if (loopend) { loopend=false; } } if (loopend && readbuffer.contains(loopstr[loopnest])) { expecting = false; readbuffer = ""; - QString ts = i18n("Looping: %1").arg(loopstr[loopnest]); + QString ts = QObject::tr("Looping: %1").arg(loopstr[loopnest]); emit debugMessage(ts); scriptindex = loopstartindex[loopnest]; loopend = false; loopnest++; } // notify event loop if expected string was found if(!expecting) timerEvent((QTimerEvent *) 0); } } @@ -975,25 +974,25 @@ void ConnectWidget::cancelbutton() { _ifaceppp->modem()->stop(); killTimer(main_timer_ID); timeout_timer->stop(); if_timer->stop(); if_timeout_timer->stop(); // if (termwindow) { // delete termwindow; // termwindow = 0L; // this->show(); // } - messg->setText(i18n("One moment please...")); + messg->setText(QObject::tr("One moment please...")); // just to be sure _ifaceppp->modem()->removeSecret(AUTH_PAP); _ifaceppp->modem()->removeSecret(AUTH_CHAP); removedns(_ifaceppp); qApp->processEvents(); _ifaceppp->modem()->killPPPDaemon(); _ifaceppp->modem()->hangup(); @@ -1001,65 +1000,68 @@ void ConnectWidget::cancelbutton() { // p_kppp->show(); // emit stopAccounting(); // just to be sure // p_kppp->con_win->stopClock(); _ifaceppp->modem()->closetty(); _ifaceppp->modem()->unlockdevice(); //abort prompt window... if (prompt->isVisible()) { prompt->hide(); } prompt->setConsumed(); - messg->setText(tr("offline")); + _ifaceppp->setStatus( false ); + _ifaceppp->refresh(); +// messg->setText(tr("offline")); + refresh(); } void ConnectWidget::script_timed_out() { if(vmain == 20) { // we are in the 'wait for the user to cancel' state timeout_timer->stop(); emit stopAccounting(); // p_kppp->con_win->stopClock(); return; } if (prompt->isVisible()) prompt->hide(); prompt->setConsumed(); - messg->setText(i18n("Script timed out!")); + messg->setText(QObject::tr("Script timed out!")); _ifaceppp->modem()->hangup(); emit stopAccounting(); // p_kppp->con_win->stopClock(); vmain = 0; // let's try again. substate = -1; } void ConnectWidget::setScan(const QString &n) { scanning = true; scanstr = n; scanbuffer = ""; - QString ts = i18n("Scanning: %1").arg(n); + QString ts = QObject::tr("Scanning: %1").arg(n); emit debugMessage(ts); } void ConnectWidget::setExpect(const QString &n) { expecting = true; expectstr = n; - QString ts = i18n("Expecting: %1").arg(n); + QString ts = QObject::tr("Expecting: %1").arg(n); ts.replace(QRegExp("\n"), "<LF>"); emit debugMessage(ts); // check if the expected string is in the read buffer already. checkBuffers(); } void ConnectWidget::if_waiting_timed_out() { if_timer->stop(); if_timeout_timer->stop(); qDebug("if_waiting_timed_out()"); @@ -1076,25 +1078,25 @@ void ConnectWidget::if_waiting_timed_out() { // killing ppp will generate a SIGCHLD which will be caught in pppdie() // in main.cpp what happens next will depend on the boolean // reconnect_on_disconnect which is set in ConnectWidget::init(); } void ConnectWidget::pppdDied() { if_timer->stop(); if_timeout_timer->stop(); } void ConnectWidget::if_waiting_slot() { - messg->setText(i18n("Logging on to network...")); + messg->setText(QObject::tr("Logging on to network...")); // if(!stats->ifIsUp()) { // if(_ifaceppp->data()->pppdError() != 0) { // // we are here if pppd died immediately after starting it. // pppdDied(); // // error message handled in main.cpp: sigPPPDDied() // return; // } // if_timer->start(100, TRUE); // single shot // return; @@ -1107,44 +1109,49 @@ void ConnectWidget::if_waiting_slot() { usleep(200000); if(_ifaceppp->data()->autoDNS()) addpeerdns( _ifaceppp ); // Close the debugging window. If we are connected, we // are not really interested in debug output emit closeDebugWindow(); // p_kppp->statdlg->take_stats(); // start taking ppp statistics auto_hostname(_ifaceppp); if(!_ifaceppp->data()->command_on_connect().isEmpty()) { - messg->setText(i18n("Running startup command...")); + messg->setText(QObject::tr("Running startup command...")); // make sure that we don't get any async errors qApp->flushX(); execute_command(_ifaceppp->data()->command_on_connect()); - messg->setText(i18n("Done")); + messg->setText(QObject::tr("Done")); } // remove the authentication file _ifaceppp->modem()->removeSecret(AUTH_PAP); _ifaceppp->modem()->removeSecret(AUTH_CHAP); - emit debugMessage(i18n("Done")); + emit debugMessage(QObject::tr("Done")); set_con_speed_string(); // p_kppp->con_win->setConnectionSpeed(p_kppp->con_speed); - this->hide(); - messg->setText(""); +// this->hide(); +// messg->setText(""); _ifaceppp->setStatus( true ); + + m_refreshTimer = new QTimer( this ); + connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); + m_refreshTimer->start( 3000 ); + //_ifaceppp->refresh(); // emit _ifaceppp->updateInterface(_ifaceppp); // prepare the con_win so as to have the right size for // accounting / non-accounting mode // if(p_kppp->acct != 0) // p_kppp->con_win->accounting(p_kppp->acct->running()); // else // p_kppp->con_win->accounting(false); // if (_ifaceppp->data()->get_dock_into_panel()) { // // DockWidget::dock_widget->show(); // // DockWidget::dock_widget->take_stats(); @@ -1152,24 +1159,33 @@ void ConnectWidget::if_waiting_slot() { // } // else { // // p_kppp->con_win->show(); // if(_ifaceppp->data()->get_iconify_on_connect()) { // // p_kppp->con_win->showMinimized(); // } // } _ifaceppp->modem()->closetty(); } +void ConnectWidget::refresh() { + _ifaceppp->refresh(); + if ( _ifaceppp->getStatus() ) { + messg->setText(QObject::tr("Online")); + } else { + messg->setText(QObject::tr("Offline")); + } +} + bool ConnectWidget::execppp() { QString command; command = "pppd"; // as of version 2.3.6 pppd falls back to the real user rights when // opening a device given in a command line. To avoid permission conflicts // we'll simply leave this argument away. pppd will then use the default tty // which is the serial port we connected stdin/stdout to in opener.cpp. // command += " "; // command += _ifaceppp->data()->modemDevice(); @@ -1201,63 +1217,71 @@ bool ConnectWidget::execppp() { if(_ifaceppp->data()->flowcontrol() == "CRTSCTS") command += " crtscts"; else command += " xonxoff"; } if(_ifaceppp->data()->defaultroute()) command += " defaultroute"; if(_ifaceppp->data()->autoDNS()) command += " usepeerdns"; - QStringList &arglist = _ifaceppp->data()->pppdArgument(); - for ( QStringList::Iterator it = arglist.begin(); - it != arglist.end(); - ++it ) - { - command += " " + *it; - } // PAP settings if(_ifaceppp->data()->authMethod() == AUTH_PAP) { command += " -chap user "; - command = command + "\"" + _ifaceppp->data()->storedUsername() + "\""; + command = command + _ifaceppp->data()->storedUsername(); } // CHAP settings if(_ifaceppp->data()->authMethod() == AUTH_CHAP) { command += " -pap user "; - command = command + "\"" + _ifaceppp->data()->storedUsername() + "\""; + command = command + _ifaceppp->data()->storedUsername(); } // PAP/CHAP settings if(_ifaceppp->data()->authMethod() == AUTH_PAPCHAP) { + QString tmpName = _ifaceppp->data()->storedUsername(); + if ( !tmpName.isEmpty() ) { command += " user "; - command = command + "\"" + _ifaceppp->data()->storedUsername() + "\""; + command = command + tmpName; + } } // check for debug if(_ifaceppp->data()->getPPPDebug()) command += " debug"; + QStringList &arglist = _ifaceppp->data()->pppdArgument(); + for ( QStringList::Iterator it = arglist.begin(); + it != arglist.end(); + ++it ) + { + command += " " + *it; + } + + command += " call opie-kppp logfd 11"; + if (command.length() > MAX_CMDLEN) { - QMessageBox::critical(this, "error", i18n( + QMessageBox::critical(this, "error", QObject::tr( "pppd command + command-line arguments exceed " "2024 characters in length." )); return false; // nonsensically long command which would bust my buffer buf. } + qWarning("Command IS: %s",command.latin1() ); + qApp->flushX(); return _ifaceppp->modem()->execPPPDaemon(command); } void ConnectWidget::closeEvent( QCloseEvent *e ) { e->ignore(); emit cancelbutton(); } diff --git a/noncore/settings/networksettings/ppp/connect.h b/noncore/settings/networksettings/ppp/connect.h index e7ae5e0..b225ff5 100644 --- a/noncore/settings/networksettings/ppp/connect.h +++ b/noncore/settings/networksettings/ppp/connect.h @@ -53,24 +53,25 @@ public: void set_con_speed_string(); void setMsg(const QString &); void pppdDied(); protected: void timerEvent(QTimerEvent *); void closeEvent( QCloseEvent *e ); private slots: void readChar(unsigned char); void pause(); void if_waiting_slot(); + void refresh(); public slots: void init(); void preinit(); void script_timed_out(); void if_waiting_timed_out(); void cancelbutton(); signals: void if_waiting_signal(); void debugMessage(const QString &); void toggleDebugWindow(); @@ -118,24 +119,25 @@ private: QString scanstr; QString scanbuffer; bool scanning; bool pausing; PWEntry *prompt; // LoginTerm *termwindow; int scriptTimeout; QTimer *pausetimer; QTimer *if_timer; QTimer *if_timeout_timer; + QTimer *m_refreshTimer; QLabel *messg; QPushButton *cancel; bool firstrunID; bool firstrunPW; unsigned int dialnumber; // the current number to dial InterfacePPP *_ifaceppp; }; diff --git a/noncore/settings/networksettings/ppp/conwindow.cpp b/noncore/settings/networksettings/ppp/conwindow.cpp index 9136ca0..7641bbe 100644 --- a/noncore/settings/networksettings/ppp/conwindow.cpp +++ b/noncore/settings/networksettings/ppp/conwindow.cpp @@ -15,65 +15,60 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <qtooltip.h> #include <qdialog.h> #include "conwindow.h" -//#include "docking.h" #include "pppdata.h" -// #include "pppstats.h" -// #include <klocale.h> -#define i18n QObject::tr -// #include <kglobal.h> ConWindow::ConWindow(PPPData *pd, QWidget *parent, const char *name, QDialog *mainwidget ) : QWidget(parent, name, 0), minutes(0), seconds(0), hours(0), days(0), tl1(0), _pppdata(pd) { - info1 = new QLabel(i18n("Connected at:"), this); + info1 = new QLabel(QObject::tr("Connected at:"), this); info2 = new QLabel("", this); - timelabel1 = new QLabel(i18n("Time connected:"), this); + timelabel1 = new QLabel(QObject::tr("Time connected:"), this); timelabel2 = new QLabel("000:00:00", this); - vollabel = new QLabel(i18n("Volume:"), this); + vollabel = new QLabel(QObject::tr("Volume:"), this); volinfo = new QLabel("", this); // now the stuff for accounting - session_bill_l = new QLabel(i18n("Session Bill:"), this); + session_bill_l = new QLabel(QObject::tr("Session Bill:"), this); session_bill = new QLabel("", this); - total_bill_l = new QLabel(i18n("Total Bill:"), this); + total_bill_l = new QLabel(QObject::tr("Total Bill:"), this); total_bill = new QLabel("", this); this->setCaption("kppp"); cancelbutton = new QPushButton(this); - cancelbutton->setText(i18n("Disconnect")); + cancelbutton->setText(QObject::tr("Disconnect")); connect(cancelbutton, SIGNAL(clicked()), mainwidget, SLOT(disconnect())); // statsbutton = new QPushButton(this); -// statsbutton->setText(i18n("Details")); +// statsbutton->setText(QObject::tr("Details")); // statsbutton->setFocus(); // connect(statsbutton, SIGNAL(clicked()), mainwidget, SLOT(showStats())); clocktimer = new QTimer(this); connect(clocktimer, SIGNAL(timeout()), SLOT(timeclick())); // read window position from config file // int p_x, p_y; // PPPData::data()->winPosConWin(p_x, p_y); // setGeometry(p_x, p_y, 320, 110); } @@ -85,26 +80,26 @@ ConWindow::~ConWindow() { bool ConWindow::event(QEvent *e) { if (e->type() == QEvent::Hide) { // PPPData::data()->setWinPosConWin(x(), y()); return true; } else return QWidget::event(e); } QString ConWindow::prettyPrintVolume(unsigned int n) { int idx = 0; - const QString quant[] = {i18n("Byte"), i18n("KB"), - i18n("MB"), i18n("GB"), QString::null}; + const QString quant[] = {QObject::tr("Byte"), QObject::tr("KB"), + QObject::tr("MB"), QObject::tr("GB"), QString::null}; float n1 = n; while(n >= 1024 && quant[idx] != QString::null) { idx++; n /= 1024; } int i = idx; while(i--) n1 = n1 / 1024.0; QString s = QString::number( n1, 'f', idx==0 ? 0 : 1 ); //KGlobal::locale()->formatNumber( n1, idx==0 ? 0 : 1 ); @@ -250,32 +245,32 @@ void ConWindow::startClock() { void ConWindow::setConnectionSpeed(const QString &speed) { info2->setText(speed); } void ConWindow::stopClock() { clocktimer->stop(); } void ConWindow::timeclick() { -// QString tooltip = i18n("Connection: %1\n" +// QString tooltip = QObject::tr("Connection: %1\n" // "Connected at: %2\n" // "Time connected: %3") // .arg(_pppdata->accname()).arg(info2->text()) // .arg(time_string2); // if(accountingEnabled) -// tooltip += i18n("\nSession Bill: %1\nTotal Bill: %2") +// tooltip += QObject::tr("\nSession Bill: %1\nTotal Bill: %2") // .arg(session_bill->text()).arg(total_bill->text()); // // volume accounting // if(volumeAccountingEnabled) { // volinfo->setEnabled(TRUE); // int bytes = _pppdata->totalBytes(); // volinfo->setText(prettyPrintVolume(bytes)); // } // seconds++; // if(seconds >= 60 ) { diff --git a/noncore/settings/networksettings/ppp/devices.cpp b/noncore/settings/networksettings/ppp/devices.cpp new file mode 100644 index 0000000..e94904b --- a/dev/null +++ b/noncore/settings/networksettings/ppp/devices.cpp @@ -0,0 +1,212 @@ +/* + * kPPP: A pppd front end for the KDE project + * + * $Id$ + * + * Copyright (C) 1997 Bernd Johannes Wuebben + * wuebben@math.cornell.edu + * + * based on EzPPP: + * Copyright (C) 1997 Jay Painter + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <qdir.h> +#include <stdlib.h> +#include <qlayout.h> +#include <qtabwidget.h> +#include <qtabdialog.h> +#include <qwhatsthis.h> +#include <qmessagebox.h> + +#include <qapplication.h> +#include <qbuttongroup.h> +#include <qmessagebox.h> +#include <qvgroupbox.h> + +#include "interfaceppp.h" +#include "devices.h" +#include "authwidget.h" +#include "pppdata.h" +#include "edit.h" +#include "general.h" + +void parseargs(char* buf, char** args); + +DevicesWidget::DevicesWidget( InterfacePPP* ip, QWidget *parent, const char *name, WFlags f ) + : ChooserWidget(ip->data(), parent, name, f) +{ + _ifaceppp = ip; + QWhatsThis::add(edit_b, tr("Allows you to modify the selected device")); + QWhatsThis::add(new_b, tr("Create a new device") ); + + QWhatsThis::add(copy_b, + tr("Makes a copy of the selected device. All\n" + "settings of the selected device are copied\n" + "to a new device, that you can modify to fit your\n" + "needs")); + QWhatsThis::add(delete_b, + tr("<p>Deletes the selected device\n\n" + "<font color=\"red\"><b>Use with care!</b></font>")); + + copy_b->setEnabled( false ); //FIXME +// delete_b->setEnabled( false ); //FIXME + + QStringList tmp = _pppdata->getDevicesNamesList(); + qDebug("DevicesWidget::DevicesWidget got devices %s",tmp.join("--").latin1()); + listListbox->insertStringList(tmp); + + for (uint i = 0; i < listListbox->count(); i++){ + qDebug("listListbox->text(i) %s == _pppdata->devname() %s",listListbox->text(i).latin1(), _pppdata->devname().latin1()); + if ( listListbox->text(i) == _pppdata->devname() ) + listListbox->setCurrentItem( i ); + } +} + + + +void DevicesWidget::slotListBoxSelect(int idx) { + bool ok = _pppdata->setDevice( listListbox->text(idx) ); + delete_b->setEnabled((bool)(idx != -1)); + edit_b->setEnabled((bool)(idx != -1)); +//FIXME copy_b->setEnabled((bool)(idx != -1)); +} + +void DevicesWidget::edit() { + _pppdata->setDevice(listListbox->text(listListbox->currentItem())); + + int result = doTab(); + + if(result == QDialog::Accepted) { + listListbox->changeItem(_pppdata->devname(),listListbox->currentItem()); + _pppdata->save(); + } +} + + +void DevicesWidget::create() { + +// if(listListbox->count() == MAX_ACCOUNTS) { +// QMessageBox::information(this, "sorry", +// tr("Maximum number of accounts reached.")); +// return; +// } + + int result; + if (_pppdata->newdevice() == -1){ + return; + } + result = doTab(); + + if(result == QDialog::Accepted) { + listListbox->insertItem(_pppdata->devname()); + listListbox->setSelected(listListbox->findItem(_pppdata->devname()),true ); + + _pppdata->save(); + } else + _pppdata->deleteDevice(); +} + + +void DevicesWidget::copy() { +// if(listListbox->count() == MAX_ACCOUNTS) { +// QMessageBox::information(this, "sorry", tr("Maximum number of accounts reached.")); +// return; +// } + + if(listListbox->currentItem()<0) { + QMessageBox::information(this, "sorry", tr("No devices selected.")); + return; + } + + _pppdata->copydevice(listListbox->currentText()); + + listListbox->insertItem(_pppdata->devname()); + _pppdata->save(); +} + + +void DevicesWidget::remove() { + + QString s = tr("Are you sure you want to delete\nthe device \"%1\"?") + .arg(listListbox->text(listListbox->currentItem())); + + if(QMessageBox::warning(this,tr("Confirm"),s, + QMessageBox::Yes,QMessageBox::No + ) != QMessageBox::Yes) + return; + + if(_pppdata->deleteDevice(listListbox->text(listListbox->currentItem()))) + listListbox->removeItem(listListbox->currentItem()); + + +// _pppdata->save(); + + + slotListBoxSelect(listListbox->currentItem()); + +} + + +int DevicesWidget::doTab(){ + QDialog *dlg = new QDialog( 0, "newDevice", true, Qt::WStyle_ContextHelp ); + QVBoxLayout *layout = new QVBoxLayout( dlg ); + layout->setSpacing( 0 ); + layout->setMargin( 1 ); + + QTabWidget *tabWindow = new QTabWidget( dlg, "tabWindow" ); + layout->addWidget( tabWindow ); + + bool isnew; + + if(_pppdata->devname().isEmpty()) { + dlg->setCaption(tr("New Device")); + isnew = true; + } else { + QString tit = tr("Edit Device: "); + tit += _pppdata->devname(); + dlg->setCaption(tit); + isnew = false; + } + + modem1 = new ModemWidget( _pppdata, tabWindow, "modem1" ); + tabWindow->addTab( modem1, tr("&Device") ); + modem2 = new ModemWidget2( _pppdata, _ifaceppp, tabWindow, "modem2" ); + tabWindow->addTab( modem2, tr("&Modem") ); + + int result = 0; + bool ok = false; + + while (!ok){ + dlg->showMaximized(); + result = dlg->exec(); + ok = true; + + if(result == QDialog::Accepted) { + if (!modem1->save()){ + QMessageBox::critical(this, "error", tr( "You must enter a unique device name")); + ok = false; + }else{ + modem2->save(); + } + } + } + + delete dlg; + + return result; +} + diff --git a/noncore/settings/networksettings/ppp/devices.h b/noncore/settings/networksettings/ppp/devices.h index d46d5b4..c2679c8 100644 --- a/noncore/settings/networksettings/ppp/devices.h +++ b/noncore/settings/networksettings/ppp/devices.h @@ -1,60 +1,51 @@ #ifndef _DEVICES_H_ #define _DEVICES_H_ #include "kpppconfig.h" -static const char *devices[] = { -#ifdef __FreeBSD__ - "/dev/cuaa0", - "/dev/cuaa1", - "/dev/cuaa2", - "/dev/cuaa3", - "/dev/cuaa4", -#elif defined(__NetBSD__) - "/dev/tty00", /* "normal" modem lines */ - "/dev/tty01", - "/dev/tty02", - "/dev/tty03", - "/dev/dty00", /* Dial out devices */ - "/dev/dty01", - "/dev/dty02", - "/dev/dty03", - "/dev/ttyU0", /* USB stuff modems */ - "/dev/ttyU1", - "/dev/ttyU2", - "/dev/ttyU3", - "/dev/dtyU0", /* USB stuff, too (dial out device) */ - "/dev/dtyU1", - "/dev/dtyU2", - "/dev/dtyU3", -#elif defined (__linux__) - "/dev/modem", - "/dev/ttyS0", - "/dev/ttyS1", - "/dev/ttyS2", - "/dev/ttyS3", -#ifdef ISDNSUPPORT - "/dev/ttyI0", - "/dev/ttyI1", - "/dev/ttyI2", - "/dev/ttyI3", -#endif - "/dev/usb/ttyACM0", /* USB stuff modems */ - "/dev/usb/ttyACM1", - "/dev/usb/ttyACM2", - "/dev/usb/ttyACM3", - "/dev/ircomm0", - "/dev/rfcomm0", - "/dev/rfcomm1", -#elif defined(__svr4__) - "/dev/cua/a", - "/dev/cua/b", - "/dev/ttya", - "/dev/ttyb", -#endif - 0}; +#include <qwidget.h> +#include <qdialog.h> +#include <qpushbutton.h> +#include <qlistbox.h> +#include "chooserwidget.h" + +class QCheckBox; +class QLineEdit; +class QTabWidget; +class DialWidget; +class AuthWidget; +class IPWidget; +class DNSWidget; +class GatewayWidget; +class InterfacePPP; +class PPPData; +class ModemWidget; +class ModemWidget2; + +class DevicesWidget : public ChooserWidget { + Q_OBJECT +public: + DevicesWidget( InterfacePPP* ip, QWidget *parent=0, const char *name=0, WFlags f=0 ); + ~DevicesWidget() {} + + +private slots: + virtual void edit(); + virtual void copy(); + virtual void remove(); + virtual void create(); + virtual void slotListBoxSelect(int); + int doTab(); + +// signals: +// void resetaccounts(); + +private: + ModemWidget *modem1; + ModemWidget2 *modem2; + InterfacePPP *_ifaceppp; + +}; -// default device number from the list above -const int DEV_DEFAULT = 0; #endif diff --git a/noncore/settings/networksettings/ppp/edit.cpp b/noncore/settings/networksettings/ppp/edit.cpp index 0c96253..ceac90c 100644 --- a/noncore/settings/networksettings/ppp/edit.cpp +++ b/noncore/settings/networksettings/ppp/edit.cpp @@ -67,27 +67,27 @@ DialWidget::DialWidget( PPPData *pd, QWidget *parent, bool isnewaccount QHBoxLayout *lpn = new QHBoxLayout(5); tl->addLayout(lpn, 1, 1); numbers = new QListBox(this); // numbers->setMinimumSize(120, 70); lpn->addWidget(numbers); QVBoxLayout *lpn1 = new QVBoxLayout; lpn->addLayout(lpn1); add = new QPushButton(tr("&Add..."), this); del = new QPushButton(tr("&Remove"), this); up = new QPushButton(this); - up->setPixmap( Resource::loadPixmap("inline/up") ); + up->setPixmap( Resource::loadPixmap("up") ); down = new QPushButton(this); - down->setPixmap( Resource::loadPixmap("inline/down") ); + down->setPixmap( Resource::loadPixmap("down") ); lpn1->addWidget(add); lpn1->addWidget(del); lpn1->addStretch(1); lpn1->addWidget(up); lpn1->addWidget(down); connect(add, SIGNAL(clicked()), this, SLOT(addNumber())); connect(del, SIGNAL(clicked()), this, SLOT(delNumber())); connect(up, SIGNAL(clicked()), this, SLOT(upNumber())); connect(down, SIGNAL(clicked()), diff --git a/noncore/settings/networksettings/ppp/general.cpp b/noncore/settings/networksettings/ppp/general.cpp index f735e49..5540946 100644 --- a/noncore/settings/networksettings/ppp/general.cpp +++ b/noncore/settings/networksettings/ppp/general.cpp @@ -26,115 +26,134 @@ #include <termios.h> #include <string.h> #include <qcheckbox.h> #include <qcombobox.h> #include <qlabel.h> #include <qlayout.h> #include <qpushbutton.h> #include <qslider.h> #include <qspinbox.h> #include <qwhatsthis.h> - +#include <qpe/config.h> // #include <qgroupbox.h> + #include "general.h" #include "interfaceppp.h" //#include "miniterm.h" #include "modeminfo.h" #include "modemcmds.h" -#include "devices.h" +//#include "devices.h" #include "pppdata.h" //#include <klocale.h> -#define i18n QObject::tr -ModemWidget::ModemWidget( InterfacePPP *ifppp, QWidget *parent, const char *name ) - : QWidget(parent, name), _ifaceppp(ifppp) + +ModemWidget::ModemWidget( PPPData *pd, QWidget *parent, const char *name ) + : QWidget(parent, name), _pppdata(pd) { int k; QGridLayout *tl = new QGridLayout(this, 8, 2, 0 );//, KDialog::spacingHint()); QLabel *label1; - label1 = new QLabel(i18n("Modem de&vice:"), this); + + label1 = new QLabel(tr("Modem &name:"), this); tl->addWidget(label1, 0, 0); + modemname = new QLineEdit(this, "modemName"); + modemname->setText( _pppdata->devname() ); + label1->setBuddy(modemname); + tl->addWidget(modemname, 0, 1); + + label1 = new QLabel(tr("Modem de&vice:"), this); + tl->addWidget(label1, 1, 0); + modemdevice = new QComboBox(false, this); + modemdevice->setEditable( true ); + modemdevice->setDuplicatesEnabled ( false ); + modemdevice->setInsertionPolicy( QComboBox::AtTop ); label1->setBuddy(modemdevice); - for(k = 0; devices[k]; k++) - modemdevice->insertItem(devices[k]); + Config cfg("NetworkSetupPPP"); + cfg.setGroup("Devices_General"); + QStringList devs = cfg.readListEntry("devices",','); + if (devs.isEmpty()) devs << "/dev/modem" << "/dev/ircomm0" << "/dev/ttyS0"; + modemdevice->insertStringList( devs ); + tl->addWidget(modemdevice, 1, 1); + +// connect(modemdevice, SIGNAL(activated(int)), +// SLOT(setmodemdc(int))); +// connect(modemdevice, SIGNAL(textChanged( const QString & ) ), +// SLOT( setmodemdc( const QString &) ) ); - tl->addWidget(modemdevice, 0, 1); - connect(modemdevice, SIGNAL(activated(int)), - SLOT(setmodemdc(int))); - QString tmp = i18n("This specifies the serial port your modem is attached \n" + QString tmp = tr("This specifies the serial port your modem is attached \n" "to. On Linux/x86, typically this is either /dev/ttyS0 \n" "(COM1 under DOS) or /dev/ttyS1 (COM2 under DOS).\n" "\n" "If you have an internal ISDN card with AT command\n" "emulation (most cards under Linux support this), you\n" "should select one of the /dev/ttyIx devices."); QWhatsThis::add(label1,tmp); QWhatsThis::add(modemdevice,tmp); - label1 = new QLabel(i18n("&Flow control:"), this); - tl->addWidget(label1, 1, 0); + label1 = new QLabel(tr("&Flow control:"), this); + tl->addWidget(label1, 2, 0); flowcontrol = new QComboBox(false, this); label1->setBuddy(flowcontrol); - flowcontrol->insertItem(i18n("Hardware [CRTSCTS]")); - flowcontrol->insertItem(i18n("Software [XON/XOFF]")); - flowcontrol->insertItem(i18n("None")); - tl->addWidget(flowcontrol, 1, 1); - connect(flowcontrol, SIGNAL(activated(int)), - SLOT(setflowcontrol(int))); - - tmp = i18n("<p>Specifies how the serial port and modem\n" + flowcontrol->insertItem(tr("Hardware [CRTSCTS]")); + flowcontrol->insertItem(tr("Software [XON/XOFF]")); + flowcontrol->insertItem(tr("None")); + tl->addWidget(flowcontrol, 2, 1); +// connect(flowcontrol, SIGNAL(activated(int)), +// SLOT(setflowcontrol(int))); + + tmp = tr("<p>Specifies how the serial port and modem\n" "communicate. You should not change this unless\n" "you know what you are doing.\n" "\n" "<b>Default</b>: CRTSCTS"); QWhatsThis::add(label1,tmp); QWhatsThis::add(flowcontrol,tmp); - QLabel *labelenter = new QLabel(i18n("&Line termination:"), this); - tl->addWidget(labelenter, 2, 0); + QLabel *labelenter = new QLabel(tr("&Line termination:"), this); + tl->addWidget(labelenter, 3, 0); enter = new QComboBox(false, this); labelenter->setBuddy(enter); enter->insertItem("CR"); enter->insertItem("LF"); enter->insertItem("CR/LF"); - tl->addWidget(enter, 2, 1); - connect(enter, SIGNAL(activated(int)), SLOT(setenter(int))); - tmp = i18n("<p>Specifies how AT commands are sent to your\n" + tl->addWidget(enter, 3, 1); +// connect(enter, SIGNAL(activated(int)), SLOT(setenter(int))); + tmp = tr("<p>Specifies how AT commands are sent to your\n" "modem. Most modems will work fine with the\n" "default <i>CR/LF</i>. If your modem does not react\n" "to the init string, you should try different\n" "settings here\n" "\n" "<b>Default</b>: CR/LF"); QWhatsThis::add(labelenter,tmp); QWhatsThis::add(enter, tmp); - QLabel *baud_label = new QLabel(i18n("Co&nnection speed:"), this); - tl->addWidget(baud_label, 3, 0); + QLabel *baud_label = new QLabel(tr("Co&nnection speed:"), this); + tl->addWidget(baud_label, 4, 0); baud_c = new QComboBox(this); baud_label->setBuddy(baud_c); static const char *baudrates[] = { #ifdef B460800 "460800", #endif #ifdef B230400 "230400", #endif @@ -148,243 +167,293 @@ ModemWidget::ModemWidget( InterfacePPP *ifppp, QWidget *parent, const char *name #endif "38400", "19200", "9600", "2400", 0}; for(k = 0; baudrates[k]; k++) baud_c->insertItem(baudrates[k]); baud_c->setCurrentItem(3); - connect(baud_c, SIGNAL(activated(int)), - this, SLOT(speed_selection(int))); - tl->addWidget(baud_c, 3, 1); +// connect(baud_c, SIGNAL(activated(int)), +// this, SLOT(speed_selection(int))); + tl->addWidget(baud_c, 4, 1); - tmp = i18n("Specifies the speed your modem and the serial\n" + tmp = tr("Specifies the speed your modem and the serial\n" "port talk to each other. You should begin with\n" "the default of 38400 bits/sec. If everything\n" "works you can try to increase this value, but to\n" "no more than 115200 bits/sec (unless you know\n" "that your serial port supports higher speeds)."); QWhatsThis::add(baud_label,tmp); QWhatsThis::add(baud_c,tmp); for(int i=0; i <= enter->count()-1; i++) { - if(_ifaceppp->data()->enter() == enter->text(i)) + if(_pppdata->enter() == enter->text(i)) enter->setCurrentItem(i); } - tl->addRowSpacing(4, 10); + tl->addRowSpacing(5, 10); //Modem Lock File - modemlockfile = new QCheckBox(i18n("&Use lock file"), this); + modemlockfile = new QCheckBox(tr("&Use lock file"), this); - modemlockfile->setChecked(_ifaceppp->data()->modemLockFile()); - connect(modemlockfile, SIGNAL(toggled(bool)), - SLOT(modemlockfilechanged(bool))); - tl->addMultiCellWidget(modemlockfile, 5, 5, 0, 1); + modemlockfile->setChecked(_pppdata->modemLockFile()); +// connect(modemlockfile, SIGNAL(toggled(bool)), +// SLOT(modemlockfilechanged(bool))); + tl->addMultiCellWidget(modemlockfile, 6, 6, 0, 1); // l12->addStretch(1); QWhatsThis::add(modemlockfile, - i18n("<p>To prevent other programs from accessing the\n" + tr("<p>To prevent other programs from accessing the\n" "modem while a connection is established, a\n" "file can be created to indicate that the modem\n" "is in use. On Linux an example file would be\n" "<tt>/var/lock/LCK..ttyS1</tt>\n" "Here you can select whether this locking will\n" "be done.\n" "\n" "<b>Default</b>: On")); // Modem Timeout Line Edit Box QHBoxLayout *timeoutLayout = new QHBoxLayout( this ); QLabel *timeoutlabel = new QLabel( tr("Modem timeout:") ,this, "timeout" ); modemtimeout = new QSpinBox( 1, 120, 1, this, "modemTimeout" ); // modemtimeout = new KIntNumInput(_pppdata->modemTimeout(), this); -// modemtimeout->setLabel(i18n("Modem &timeout:")); +// modemtimeout->setLabel(tr("Modem &timeout:")); // modemtimeout->setRange(1, 120, 1); - modemtimeout->setSuffix(i18n(" sec")); - modemtimeout->setValue( _ifaceppp->data()->modemTimeout() ); - connect(modemtimeout, SIGNAL(valueChanged(int)), - SLOT(modemtimeoutchanged(int))); + modemtimeout->setSuffix(tr(" sec")); + modemtimeout->setValue( _pppdata->modemTimeout() ); +// connect(modemtimeout, SIGNAL(valueChanged(int)), +// SLOT(modemtimeoutchanged(int))); timeoutLayout->addWidget(timeoutlabel); timeoutLayout->addWidget(modemtimeout); - tl->addMultiCellLayout(timeoutLayout, 6, 6, 0, 1); + tl->addMultiCellLayout(timeoutLayout, 7, 7, 0, 1); QWhatsThis::add(modemtimeout, - i18n("This specifies how long <i>kppp</i> waits for a\n" + tr("This specifies how long <i>kppp</i> waits for a\n" "<i>CONNECT</i> response from your modem. The\n" "recommended value is 30 seconds.")); //set stuff from gpppdata for(int i=0; i <= enter->count()-1; i++) { - if(_ifaceppp->data()->enter() == enter->text(i)) + if(_pppdata->enter() == enter->text(i)) enter->setCurrentItem(i); } for(int i=0; i <= modemdevice->count()-1; i++) { - if(_ifaceppp->data()->modemDevice() == modemdevice->text(i)) + if(_pppdata->modemDevice() == modemdevice->text(i)) modemdevice->setCurrentItem(i); } for(int i=0; i <= flowcontrol->count()-1; i++) { - if(_ifaceppp->data()->flowcontrol() == flowcontrol->text(i)) + if(_pppdata->flowcontrol() == flowcontrol->text(i)) flowcontrol->setCurrentItem(i); } //set the modem speed for(int i=0; i < baud_c->count(); i++) - if(baud_c->text(i) == _ifaceppp->data()->speed()) + if(baud_c->text(i) == _pppdata->speed()) baud_c->setCurrentItem(i); - tl->setRowStretch(7, 1); + tl->setRowStretch(1, 1); } +ModemWidget::~ModemWidget() +{ + QStringList devs; -void ModemWidget::speed_selection(int) { - _ifaceppp->data()->setSpeed(baud_c->text(baud_c->currentItem())); + for (int i=0;i<modemdevice->count();i++) + { + QString s = modemdevice->text(i); + s.simplifyWhiteSpace(); + if (! s.isEmpty() ) devs << s; } -void ModemWidget::setenter(int ) { - _ifaceppp->data()->setEnter(enter->text(enter->currentItem())); + QString edited = modemdevice->currentText(); + if ( !( edited ).isEmpty() ) { + edited.simplifyWhiteSpace(); + if ( devs.contains( edited ) == 0 ) { + devs << edited; } + _pppdata->setModemDevice( edited ); + } + + Config cfg("NetworkSetupPPP"); + cfg.setGroup("Devices_General"); + cfg.writeEntry("devices",devs,','); -void ModemWidget::setmodemdc(int i) { - _ifaceppp->data()->setModemDevice(modemdevice->text(i)); } +// void ModemWidget::speed_selection(int) { +// _pppdata->setSpeed(baud_c->text(baud_c->currentItem())); +// } -void ModemWidget::setflowcontrol(int i) { - _ifaceppp->data()->setFlowcontrol(flowcontrol->text(i)); -} +// void ModemWidget::setenter(int ) { +// _pppdata->setEnter(enter->text(enter->currentItem())); +// } -void ModemWidget::modemlockfilechanged(bool set) { - _ifaceppp->data()->setModemLockFile(set); -} +// void ModemWidget::setmodemdc(int i) { +// _pppdata->setModemDevice(modemdevice->text(i)); +// } -void ModemWidget::modemtimeoutchanged(int n) { - _ifaceppp->data()->setModemTimeout(n); -} +// void ModemWidget::setmodemdc( const QString &string ) { +// _pppdata->setModemDevice( string ); +// } + +// void ModemWidget::setflowcontrol(int i) { +// _pppdata->setFlowcontrol(flowcontrol->text(i)); +// } -ModemWidget2::ModemWidget2( InterfacePPP* ifp, QWidget *parent, +// void ModemWidget::modemlockfilechanged(bool set) { +// _pppdata->setModemLockFile(set); +// } + + +// void ModemWidget::modemtimeoutchanged(int n) { +// _pppdata->setModemTimeout(n); +// } + + + +bool ModemWidget::save() +{ + //first check to make sure that the device name is unique! + if(modemname->text().isEmpty() || + !_pppdata->isUniqueDevname(modemname->text())) + return false; + + qDebug("ModemWidget::save saving modem1 data"); + _pppdata->setDevname( modemname->text() ); + _pppdata->setModemDevice( modemdevice->currentText() ); + _pppdata->setFlowcontrol(flowcontrol->currentText()); + _pppdata->setFlowcontrol(flowcontrol->currentText()); + _pppdata->setSpeed(baud_c->currentText()); + _pppdata->setModemLockFile( modemlockfile->isChecked()); + _pppdata->setModemTimeout( modemtimeout->value() ); + return true; + +} + +ModemWidget2::ModemWidget2( PPPData *pd, InterfacePPP *ip, QWidget *parent, const char *name) - : QWidget(parent, name), _ifaceppp(ifp) + : QWidget(parent, name), _pppdata(pd), _ifaceppp(ip) { QVBoxLayout *l1 = new QVBoxLayout(this, 0 );//, KDialog::spacingHint()); - waitfordt = new QCheckBox(i18n("&Wait for dial tone before dialing"), this); - waitfordt->setChecked(_ifaceppp->data()->waitForDialTone()); - connect(waitfordt, SIGNAL(toggled(bool)), SLOT(waitfordtchanged(bool))); + waitfordt = new QCheckBox(tr("&Wait for dial tone before dialing"), this); + waitfordt->setChecked(_pppdata->waitForDialTone()); +// connect(waitfordt, SIGNAL(toggled(bool)), SLOT(waitfordtchanged(bool))); l1->addWidget(waitfordt); QWhatsThis::add(waitfordt, - i18n("<p>Normally the modem waits for a dial tone\n" + tr("<p>Normally the modem waits for a dial tone\n" "from your phone line, indicating that it can\n" "start to dial a number. If your modem does not\n" "recognize this sound, or your local phone system\n" "does not emit such a tone, uncheck this option\n" "\n" "<b>Default:</b>: On")); QHBoxLayout *waitLayout = new QHBoxLayout( this ); QLabel *waitLabel = new QLabel( tr("Busy wait:"), this, "busyWait" ); busywait = new QSpinBox( 0, 300, 5, this, "busyWait" ); // busywait = new KIntNumInput(_pppdata->busyWait(), this); -// busywait->setLabel(i18n("B&usy wait:")); +// busywait->setLabel(tr("B&usy wait:")); // busywait->setRange(0, 300, 5, true); - busywait->setSuffix(i18n(" sec")); - connect(busywait, SIGNAL(valueChanged(int)), SLOT(busywaitchanged(int))); + busywait->setSuffix(tr(" sec")); +// connect(busywait, SIGNAL(valueChanged(int)), SLOT(busywaitchanged(int))); waitLayout->addWidget(waitLabel); waitLayout->addWidget(busywait); l1->addLayout( waitLayout ); QWhatsThis::add(busywait, - i18n("Specifies the number of seconds to wait before\n" + tr("Specifies the number of seconds to wait before\n" "redial if all dialed numbers are busy. This is\n" "necessary because some modems get stuck if the\n" "same number is busy too often.\n" "\n" "The default is 0 seconds, you should not change\n" "this unless you need to.")); l1->addSpacing(10); QHBoxLayout *hbl = new QHBoxLayout; hbl->setSpacing(2);//KDialog::spacingHint()); - QLabel *volumeLabel = new QLabel(i18n("Modem &volume:"), this); + QLabel *volumeLabel = new QLabel(tr("Modem &volume:"), this); hbl->addWidget(volumeLabel); - volume = new QSlider(0, 2, 1, _ifaceppp->data()->volume(), + volume = new QSlider(0, 2, 1, _pppdata->volume(), QSlider::Horizontal, this); volumeLabel->setBuddy(volume); volume->setTickmarks(QSlider::Below); hbl->addWidget(volume); l1->addLayout(hbl); - connect(volume, SIGNAL(valueChanged(int)), - this, SLOT(volumeChanged(int))); - QString tmp = i18n("Most modems have a speaker which makes\n" +// connect(volume, SIGNAL(valueChanged(int)), +// this, SLOT(volumeChanged(int))); + QString tmp = tr("Most modems have a speaker which makes\n" "a lot of noise when dialing. Here you can\n" "either turn this completely off or select a\n" "lower volume.\n" "\n" "If this does not work for your modem,\n" "you must modify the modem volume command."); QWhatsThis::add(volumeLabel,tmp); QWhatsThis::add(volume, tmp); l1->addSpacing(20); #if 0 - chkbox1 = new QCheckBox(i18n("Modem asserts CD line"), this); - chkbox1->setChecked(_ifaceppp->data()->UseCDLine()); + chkbox1 = new QCheckBox(tr("Modem asserts CD line"), this); + chkbox1->setChecked(_pppdata->UseCDLine()); connect(chkbox1,SIGNAL(toggled(bool)), this,SLOT(use_cdline_toggled(bool))); l12->addWidget(chkbox1); l12->addStretch(1); l1->addStretch(1); QWhatsThis::add(chkbox1, - i18n("This controls how <i>kppp</i> detects that the modem\n" + tr("This controls how <i>kppp</i> detects that the modem\n" "is not responding. Unless you are having\n" "problems with this, do not modify this setting.\n" "\n" "<b>Default</b>: Off")); #endif - modemcmds = new QPushButton(i18n("Mod&em Commands..."), this); + modemcmds = new QPushButton(tr("Mod&em Commands..."), this); QWhatsThis::add(modemcmds, - i18n("Allows you to change the AT command for\n" + tr("Allows you to change the AT command for\n" "your modem.")); - modeminfo_button = new QPushButton(i18n("&Query Modem..."), this); + modeminfo_button = new QPushButton(tr("&Query Modem..."), this); QWhatsThis::add(modeminfo_button, - i18n("Most modems support the ATI command set to\n" + tr("Most modems support the ATI command set to\n" "find out vendor and revision of your modem.\n" "\n" "Press this button to query your modem for\n" "this information. It can be useful to help\n" "you setup the modem")); -// terminal_button = new QPushButton(i18n("&Terminal..."), this); +// terminal_button = new QPushButton(tr("&Terminal..."), this); // QWhatsThis::add(terminal_button, -// i18n("Opens the built-in terminal program. You\n" +// tr("Opens the built-in terminal program. You\n" // "can use this if you want to play around\n" // "with your modem's AT command set")); QHBoxLayout *hbox = new QHBoxLayout(); l1->addLayout(hbox); hbox->addStretch(1); QVBoxLayout *vbox = new QVBoxLayout(); hbox->addLayout(vbox); vbox->addWidget(modemcmds); vbox->addWidget(modeminfo_button); // vbox->addWidget(terminal_button); @@ -393,49 +462,57 @@ ModemWidget2::ModemWidget2( InterfacePPP* ifp, QWidget *parent, l1->addStretch(1); connect(modemcmds, SIGNAL(clicked()), SLOT(modemcmdsbutton())); connect(modeminfo_button, SIGNAL(clicked()), SLOT(query_modem())); // connect(terminal_button, SIGNAL(clicked()), // SLOT(terminal())); } void ModemWidget2::modemcmdsbutton() { - ModemCommands mc(_ifaceppp->data(), this); + ModemCommands mc(_ifaceppp->data(), this, "commands" , true, Qt::WStyle_ContextHelp); mc.showMaximized(); mc.exec(); } void ModemWidget2::query_modem() { ModemTransfer mt(_ifaceppp->modem(), this); mt.exec(); } // void ModemWidget2::terminal() { // MiniTerm terminal(NULL,NULL); // terminal.exec(); // } -#if 0 -void ModemWidget2::use_cdline_toggled(bool on) { - _ifaceppp->data()->setUseCDLine(on); -} -#endif +// #if 0 +// void ModemWidget2::use_cdline_toggled(bool on) { +// _pppdata->setUseCDLine(on); +// } +// #endif -void ModemWidget2::waitfordtchanged(bool b) { - _ifaceppp->data()->setWaitForDialTone((int)b); -} +// void ModemWidget2::waitfordtchanged(bool b) { +// _pppdata->setWaitForDialTone((int)b); +// } -void ModemWidget2::busywaitchanged(int n) { - _ifaceppp->data()->setbusyWait(n); -} +// void ModemWidget2::busywaitchanged(int n) { +// _pppdata->setbusyWait(n); +// } -void ModemWidget2::volumeChanged(int v) { - _ifaceppp->data()->setVolume(v); +// void ModemWidget2::volumeChanged(int v) { +// _pppdata->setVolume(v); +// } + +bool ModemWidget2::save() +{ + _pppdata->setWaitForDialTone(waitfordt->isChecked()); + _pppdata->setbusyWait(busywait->value()); + _pppdata->setVolume(volume->value()); + return true; } diff --git a/noncore/settings/networksettings/ppp/general.h b/noncore/settings/networksettings/ppp/general.h index 3e59b46..f43f241 100644 --- a/noncore/settings/networksettings/ppp/general.h +++ b/noncore/settings/networksettings/ppp/general.h @@ -27,74 +27,82 @@ #define _GENERAL_H_ #include <qwidget.h> class QSlider; class QSpinBox; class QCombobox; class QLabel; class QCheckBox; class QComboBox; class PPPData; class InterfacePPP; +class QLineEdit; class ModemWidget : public QWidget { Q_OBJECT public: - ModemWidget( InterfacePPP*, QWidget *parent=0, const char *name=0 ); + ModemWidget(PPPData*, QWidget *parent=0, const char *name=0 ); + ~ModemWidget(); -private slots: - void setmodemdc(int); - void setflowcontrol(int); - void modemtimeoutchanged(int); - void modemlockfilechanged(bool); - void setenter(int); - void speed_selection(int); + bool save(); + +/* private slots: */ +/* void setmodemdc(int); */ +/* void setmodemdc(const QString &); */ +/* void setflowcontrol(int); */ +/* void modemtimeoutchanged(int); */ +/* void modemlockfilechanged(bool); */ +/* void setenter(int); */ +/* void speed_selection(int); */ private: QComboBox *enter; /* QLabel *label1; */ /* QLabel *label2; */ /* QLabel *labeltmp; */ /* QLabel *labelenter; */ + QLineEdit *modemname; QComboBox *modemdevice; QComboBox *flowcontrol; QComboBox *baud_c; QLabel *baud_label; QSpinBox *modemtimeout; QCheckBox *modemlockfile; - InterfacePPP *_ifaceppp; + PPPData *_pppdata; }; class ModemWidget2 : public QWidget { Q_OBJECT public: - ModemWidget2( InterfacePPP*, QWidget *parent=0, const char *name=0 ); + ModemWidget2( PPPData*, InterfacePPP*, QWidget *parent=0, const char *name=0 ); + bool save(); private slots: - void waitfordtchanged(bool); - void busywaitchanged(int); +/* void waitfordtchanged(bool); */ +/* void busywaitchanged(int); */ // void use_cdline_toggled(bool); void modemcmdsbutton(); // void terminal(); void query_modem(); - void volumeChanged(int); + // void volumeChanged(int); private: QLabel *labeltmp; QPushButton *modemcmds; QPushButton *modeminfo_button; // QPushButton *terminal_button; // QFrame *fline; QCheckBox *waitfordt; QSpinBox *busywait; QCheckBox *chkbox1; QSlider *volume; + PPPData *_pppdata; InterfacePPP *_ifaceppp; }; #endif diff --git a/noncore/settings/networksettings/ppp/interfaceinformationppp.cpp b/noncore/settings/networksettings/ppp/interfaceinformationppp.cpp index 553daa2..6b158b9 100644 --- a/noncore/settings/networksettings/ppp/interfaceinformationppp.cpp +++ b/noncore/settings/networksettings/ppp/interfaceinformationppp.cpp @@ -1,37 +1,41 @@ #include "interfaceinformationppp.h" - #include <qpushbutton.h> #include <qlabel.h> -//#include <qgroupbox.h> #include <qmessagebox.h> #include <qabstractlayout.h> #include "connect.h" #include "conwindow.h" #ifdef QWS #else #define showMaximized show #endif /** * Constructor for the InterfaceInformationImp class. This class pretty much * just display's information about the interface that is passed to it. */ InterfaceInformationPPP::InterfaceInformationPPP(QWidget *parent, const char *name, Interface *i, WFlags f) - :InterfaceInformationImp(parent, name, i, f) + :InterfaceInformationImp(parent, name, i, Qt::WStyle_ContextHelp) { - qDebug("InterfaceInformationPPP::InterfaceInformationPPP"); + qDebug("InterfaceInformationPPP::InterfaceInformationPPP %s", name); con = new ConnectWidget( (InterfacePPP*)i, this, "con" ); con->setSizePolicy( QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed) ); - QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); - InterfaceInformationLayout->addItem( spacer, 7, 0 ); - InterfaceInformationLayout->addMultiCellWidget( con, 8, 8, 0, 1 ); - // InterfaceInformationLayout->addWidget( con, 7, 0 ); + + macAddressLabel->hide(); + subnetMaskLabel->hide(); + broadcastLabel->hide(); + TextLabel23->hide(); + TextLabel21->hide(); + TextLabel24->hide(); + + InterfaceInformationLayout->addWidget( con, 1, 0 ); connect(i, SIGNAL(begin_connect()),con, SLOT(preinit())); + connect(i, SIGNAL(hangup_now() ), con, SLOT(cancelbutton() ) ); } diff --git a/noncore/settings/networksettings/ppp/interfaceppp.cpp b/noncore/settings/networksettings/ppp/interfaceppp.cpp index 9ec30bc..f443f3c 100644 --- a/noncore/settings/networksettings/ppp/interfaceppp.cpp +++ b/noncore/settings/networksettings/ppp/interfaceppp.cpp @@ -1,142 +1,174 @@ #include <qmessagebox.h> -#define i18n QObject::tr +#include <qlayout.h> +#include <qlineedit.h> +#include <qlabel.h> #include "auth.h" #include "interfaceppp.h" #include "modem.h" #include "pppdata.h" InterfacePPP::InterfacePPP(QObject *parent, const char *name, bool status) : Interface(parent, name, status), _modemPtr(0), _dataPtr(0) { qDebug("InterfacePPP::InterfacePPP("); } -PPPData* InterfacePPP::data() +PPPData* InterfacePPP::data()const { if (!_dataPtr){ qDebug("creating new Data obj"); _dataPtr = new PPPData(); - _dataPtr->setModemDevice( getInterfaceName() ); + _dataPtr->setDevice( getInterfaceName() ); _dataPtr->setAccount( getHardwareName() ); } return _dataPtr; } -Modem* InterfacePPP::modem() +Modem* InterfacePPP::modem()const { if (!_modemPtr){ qDebug("creating new modem obj"); _modemPtr = new Modem( data() ); } return _modemPtr; } bool InterfacePPP::refresh() { qDebug("InterfacePPP::refresh()"); - updateInterface(this); - QMessageBox::information(0,"Not Implemented","This feature is not yet implemneted... ;-("); - return false; + QString old = getInterfaceName(); + setInterfaceName( modem()->pppDevice() ); + + (void)Interface::refresh(); + + setInterfaceName( old ); + emit updateInterface(this); + + return true; } void InterfacePPP::start() { qDebug("InterfacePPP::start"); -// should work... -// if (data()->password().isEmpty() ){ -// //FIXME: ask for password -// qDebug("using dummy password"); -// QMessageBox::critical( 0, "no password", "you should be prompted for a password, but you are not! ;-)"); -// } + if (data()->password().isEmpty() && !data()->storedUsername().isEmpty() ) { + + QDialog mb( 0, "Dialog", true ); + mb.setCaption( tr( "No password" ) ); + QVBoxLayout layout( &mb ); + QLabel text ( &mb ); + text.setText( tr("Username defined but no password\n Please enter a password") ); + QLineEdit lineedit( &mb ); + lineedit.setEchoMode( QLineEdit::Password ); + layout.addWidget( &text ); + layout.addWidget( &lineedit ); + if ( mb.exec() == QDialog::Accepted ) { + data()->setPassword( lineedit.text() ); + } + } QFileInfo info(pppdPath()); if(!info.exists()){ QMessageBox::warning(0, tr("Error"), - i18n("<qt>Cannot find the PPP daemon!<br>" + QObject::tr("<qt>Cannot find the PPP daemon!<br>" "Make sure that pppd is installed and " "that you have entered the correct path.</qt>")); return; } //#if 0 if(!info.isExecutable()){ QString string; - string = i18n( "<qt>Cannot execute:<br> %1<br>" + string = QObject::tr( "<qt>Cannot execute:<br> %1<br>" "Please make sure that you have given " "setuid permission and that " "pppd is executable.<br>").arg(pppdPath()); QMessageBox::warning(0, tr("Error"), string); return; } //#endif QFileInfo info2(data()->modemDevice()); if(!info2.exists()){ QString string; - string = i18n( "<qt>Cannot find:<br> %1<br>" + string = QObject::tr( "<qt>Cannot find:<br> %1<br>" "Please make sure you have setup " "your modem device properly " "and/or adjust the location of the modem device on " "the modem tab of " "the setup dialog.</qt>").arg(data()->modemDevice()); QMessageBox::warning(0, tr("Error"), string); return; } // if this is a PAP or CHAP account, ensure that username is // supplied if(data()->authMethod() == AUTH_PAP || data()->authMethod() == AUTH_CHAP || data()->authMethod() == AUTH_PAPCHAP ) { if(false){ //FIXME: ID_Edit->text().isEmpty()) { QMessageBox::warning(0,tr("Error"), - i18n("<qt>You have selected the authentication method PAP or CHAP. This requires that you supply a username and a password!</qt>")); + QObject::tr("<qt>You have selected the authentication method PAP or CHAP. This requires that you supply a username and a password!</qt>")); // FIXME: return; } else { if(!modem()->setSecret(data()->authMethod(), PPPData::encodeWord(data()->storedUsername()), PPPData::encodeWord(data()->password())) ) { QString s; - s = i18n("<qt>Cannot create PAP/CHAP authentication<br>" + s = QObject::tr("<qt>Cannot create PAP/CHAP authentication<br>" "file \"%1\"</qt>").arg(PAP_AUTH_FILE); QMessageBox::warning(0, tr("Error"), s); return; } } } if (data()->phonenumber().isEmpty()) { - QString s = i18n("You must specify a telephone number!"); + QString s = QObject::tr("You must specify a telephone number!"); QMessageBox::warning(0, tr("Error"), s); return; } // SEGFAULTS: // setStatus( true ); // emit updateInterface((Interface*) this); emit begin_connect(); qDebug("InterfacePPP::start END"); } void InterfacePPP::stop() { qDebug("InterfacePPP::stop"); + // emit hangup_now(); + status = false; // not connected + setStatus( false ); + emit hangup_now(); + refresh(); } void InterfacePPP::save() { data()->save(); emit updateInterface((Interface*) this); } +QString InterfacePPP::pppDev()const { + return modem()->pppDevice(); +} +pid_t InterfacePPP::pppPID()const{ + return modem()->pppPID(); +} +void InterfacePPP::setPPPDpid( pid_t pid) { + setStatus( true ); + modem()->setPPPDPid( pid ); +} diff --git a/noncore/settings/networksettings/ppp/interfaceppp.h b/noncore/settings/networksettings/ppp/interfaceppp.h index 6eb6a69..39495c2 100644 --- a/noncore/settings/networksettings/ppp/interfaceppp.h +++ b/noncore/settings/networksettings/ppp/interfaceppp.h @@ -1,34 +1,40 @@ #ifndef INTERFACEPPP_H #define INTERFACEPPP_H +#include <sys/types.h> + #include "interface.h" class PPPData; class Modem; class InterfacePPP : public Interface { Q_OBJECT public: InterfacePPP(QObject *parent=0, const char *name="PPP", bool status=false); - PPPData* data(); - Modem* modem(); + PPPData* data()const; + Modem* modem()const; + QString pppDev()const; // returns the ppp device.... /dev/ppp0... + pid_t pppPID()const; signals: void begin_connect(); + void hangup_now(); public slots: virtual bool refresh(); virtual void start(); virtual void stop(); void save(); + void setPPPDpid( pid_t ); // sets the pppd pid for modem... private: - Modem *_modemPtr; - PPPData *_dataPtr; + mutable Modem *_modemPtr; + mutable PPPData *_dataPtr; }; #endif diff --git a/noncore/settings/networksettings/ppp/kpppwidget.cpp b/noncore/settings/networksettings/ppp/kpppwidget.cpp index 7b5c74d..e466358 100644 --- a/noncore/settings/networksettings/ppp/kpppwidget.cpp +++ b/noncore/settings/networksettings/ppp/kpppwidget.cpp @@ -33,61 +33,50 @@ #include <qdialog.h> #include <qlabel.h> #include <qpushbutton.h> #include <qregexp.h> #include <qtabwidget.h> #include <qdialog.h> #include <qwhatsthis.h> #include <qcheckbox.h> // #include <kaboutdata.h> // #include <kapplication.h> #include <qbuttongroup.h> -//#include <kcmdlineargs.h> -//#include <kconfig.h> -//#include <kdebug.h> -#define i18n QObject::tr -//#include <kiconloader.h> // For BarIcon -//#include <klocale.h> #include <qmessagebox.h> -// #include <kseparator.h> -// #include <kstandarddirs.h> -// #include <kwin.h> -// #include <khelpmenu.h> #include <qpushbutton.h> -//#include <kguiitem.h> #include <stdlib.h> #include <errno.h> #include <signal.h> #include "runtests.h" //#include "main.h" #include "auth.h" #include "modem.h" //#include "ppplog.h" //#include "opener.h" //#include "requester.h" //#include "pppstats.h" #include "pppdata.h" #include "general.h" #include "interface.h" #define execute_command system KPPPWidget *p_kppp = 0; KPPPWidget::KPPPWidget(PPPData*pd, Interface *i, QWidget *parent, const char *name, bool modal, WFlags fl ) - : QDialog(parent, name, modal, fl), _pppdata(pd) + : QDialog(parent, name, modal, Qt::WStyle_ContextHelp ), _pppdata(pd) { // tabWindow = 0; p_kppp = this; // before doing anything else, run a few tests if (!_pppdata->setModemDevice( i->getInterfaceName() )) _pppdata->setModemDevice("/dev/modem"); qDebug("PPPConfigWidget::PPPConfigWidget"); qDebug(" interface->getHardwareName >%s<", i->getHardwareName().latin1()); if (!_pppdata->setAccount( i->getHardwareName() )) _pppdata->setAccount( 0 ); qDebug(" _pppdata->accname >%s<",_pppdata->accname().latin1()); @@ -99,130 +88,130 @@ KPPPWidget::KPPPWidget(PPPData*pd, Interface *i, QWidget *parent, const char *na // installEventFilter(this); QVBoxLayout *tl = new QVBoxLayout(this, 10, 10); QGridLayout *l1 = new QGridLayout(3, 4); tl->addLayout(l1); l1->addColSpacing(0, 10); l1->addColSpacing(3, 10); l1->setColStretch(1, 3); l1->setColStretch(2, 4); - label1 = new QLabel(i18n("C&onnect to: "), this); + label1 = new QLabel(QObject::tr("C&onnect to: "), this); l1->addWidget(label1, 0, 1); connectto_c = new QComboBox(false, this); label1->setBuddy(connectto_c); connect(connectto_c, SIGNAL(activated(int)), SLOT(newdefaultaccount(int))); l1->addWidget(connectto_c, 0, 2); - ID_Label = new QLabel(i18n("&Login ID:"), this); + ID_Label = new QLabel(QObject::tr("&Login ID:"), this); l1->addWidget(ID_Label, 1, 1); // the entry line for usernames ID_Edit = new QLineEdit(this); ID_Label->setBuddy(ID_Edit); l1->addWidget(ID_Edit, 1, 2); connect(ID_Edit, SIGNAL(returnPressed()), this, SLOT(enterPressedInID())); - QString tmp = i18n("<p>Type in the username that you got from your\n" + QString tmp = QObject::tr("<p>Type in the username that you got from your\n" "ISP. This is especially important for PAP\n" "and CHAP. You may omit this when you use\n" "terminal-based or script-based authentication.\n" "\n" "<b>Important</b>: case is important here:\n" "<i>myusername</i> is not the same as <i>MyUserName</i>!"); QWhatsThis::add(ID_Label,tmp); QWhatsThis::add(ID_Edit,tmp); - PW_Label = new QLabel(i18n("&Password:"), this); + PW_Label = new QLabel(QObject::tr("&Password:"), this); l1->addWidget(PW_Label, 2, 1); PW_Edit= new QLineEdit(this); PW_Label->setBuddy(PW_Edit); PW_Edit->setEchoMode(QLineEdit::Password); l1->addWidget(PW_Edit, 2, 2); connect(PW_Edit, SIGNAL(returnPressed()), this, SLOT(enterPressedInPW())); - tmp = i18n("<p>Type in the password that you got from your\n" + tmp = QObject::tr("<p>Type in the password that you got from your\n" "ISP. This is especially important for PAP\n" "and CHAP. You may omit this when you use\n" "terminal-based or script-based authentication.\n" "\n" "<b>Important</b>: case is important here:\n" "<i>mypassword</i> is not the same as <i>MyPassword</i>!"); QWhatsThis::add(PW_Label,tmp); QWhatsThis::add(PW_Edit,tmp); QHBoxLayout *l3 = new QHBoxLayout; tl->addSpacing(5); tl->addLayout(l3); tl->addSpacing(5); l3->addSpacing(10); - log = new QCheckBox(i18n("Show lo&g window"), this); + log = new QCheckBox(QObject::tr("Show lo&g window"), this); connect(log, SIGNAL(toggled(bool)), this, SLOT(log_window_toggled(bool))); log->setChecked(_pppdata->get_show_log_window()); l3->addWidget(log); QWhatsThis::add(log, - i18n("<p>This controls whether a log window is shown.\n" + QObject::tr("<p>This controls whether a log window is shown.\n" "A log window shows the communication between\n" "<i>kppp</i> and your modem. This will help you\n" "in tracking down problems.\n" "\n" "Turn it off if <i>kppp</i> routinely connects without\n" "problems")); // fline = new QSeparator( KSeparator::HLine, this); // tl->addWidget(fline); QHBoxLayout *l2 = new QHBoxLayout(this); tl->addLayout(l2); int minw = 0; - quit_b = new QPushButton(i18n("&Quit"), this); - // quit_b-> setGuiItem (KGuiItem(i18n("&Quit"), "exit" ) ); + quit_b = new QPushButton(QObject::tr("&Quit"), this); + // quit_b-> setGuiItem (KGuiItem(QObject::tr("&Quit"), "exit" ) ); connect( quit_b, SIGNAL(clicked()), SLOT(quitbutton())); if(quit_b->sizeHint().width() > minw) minw = quit_b->sizeHint().width(); - setup_b = new QPushButton(i18n("&Setup..."), this); -// setup_b->setGuiItem (KGuiItem(i18n("&Setup...")) ); + setup_b = new QPushButton(QObject::tr("&Setup..."), this); +// setup_b->setGuiItem (KGuiItem(QObject::tr("&Setup...")) ); connect( setup_b, SIGNAL(clicked()), SLOT(expandbutton())); if(setup_b->sizeHint().width() > minw) minw = setup_b->sizeHint().width(); // if(_pppdata->access() != KConfig::ReadWrite) // setup_b->setEnabled(false); -// help_b = new QPushButton(i18n("&Help"), this); +// help_b = new QPushButton(QObject::tr("&Help"), this); // connect( help_b, SIGNAL(clicked()), SLOT(helpbutton())); // KHelpMenu *helpMenu = new KHelpMenu(this, KGlobal::instance()->aboutData(), true); // help_b->setPopup((QPopupMenu*)helpMenu->menu()); -// help_b->setGuiItem (KGuiItem(i18n("&Help"), "help" ) ); +// help_b->setGuiItem (KGuiItem(QObject::tr("&Help"), "help" ) ); // if(help_b->sizeHint().width() > minw) // minw = help_b->sizeHint().width(); - connect_b = new QPushButton(i18n("&Connect"), this); + connect_b = new QPushButton(QObject::tr("&Connect"), this); connect_b->setDefault(true); connect_b->setFocus(); connect(connect_b, SIGNAL(clicked()), SLOT(beginConnect())); if(connect_b->sizeHint().width() > minw) minw = connect_b->sizeHint().width(); quit_b->setFixedWidth(minw); setup_b->setFixedWidth(minw); // help_b->setFixedWidth(help_b->sizeHint().width()); connect_b->setFixedWidth(minw); l2->addWidget(quit_b); @@ -277,25 +266,25 @@ KPPPWidget::KPPPWidget(PPPData*pd, Interface *i, QWidget *parent, const char *na // m_strCmdlAccount = args->getOption("c"); // m_bQuitOnDisconnect = args->isSet("q"); // if(!m_strCmdlAccount.isEmpty()) { // m_bCmdlAccount = true; // kdDebug(5002) << "cmdl_account: " << m_bCmdlAccount << endl; // } // if(m_bCmdlAccount){ // bool result = _pppdata->setAccount(m_strCmdlAccount); // if (!result){ // QString string; -// string = i18n("No such Account:\n%1").arg(m_strCmdlAccount); +// string = QObject::tr("No such Account:\n%1").arg(m_strCmdlAccount); // KMessageBox::error(this, string); // m_bCmdlAccount = false; // this->show(); // } else { // beginConnect(); // } // } else // expandbutton(); // show(); //#define KPPP_SHOW_NEWS @@ -473,39 +462,39 @@ void KPPPWidget::sigPPPDDied() { if(!_pppdata->automatic_redial()) { quit_b->setFocus(); show(); con_win->stopClock(); // stopAccounting(); con_win->hide(); con->hide(); _pppdata->setpppdRunning(false); // // not in a signal handler !!! KNotifyClient::beep(); QString msg; if (_pppdata->pppdError() == E_IF_TIMEOUT) - msg = i18n("Timeout expired while waiting for the PPP interface " + msg = QObject::tr("Timeout expired while waiting for the PPP interface " "to come up!"); else { - msg = i18n("<p>The pppd daemon died unexpectedly!</p>"); + msg = QObject::tr("<p>The pppd daemon died unexpectedly!</p>"); Modem::modem->pppdExitStatus(); if (Modem::modem->lastStatus != 99) { // more recent pppds only - msg += i18n("<p>Exit status: %1").arg(Modem::modem->lastStatus); - msg += i18n("</p><p>See 'man pppd' for an explanation of the error " + msg += QObject::tr("<p>Exit status: %1").arg(Modem::modem->lastStatus); + msg += QObject::tr("</p><p>See 'man pppd' for an explanation of the error " "codes or take a look at the kppp FAQ on " " <a href=http://devel-home.kde.org/~kppp/index.html>" "http://devel-home.kde.org/~kppp/index.html</a></p>"); } } -// if(QMessageBox::warning(0, msg, i18n("Error"), i18n("&OK"), i18n("&Details...")) == QMessageBox::No) +// if(QMessageBox::warning(0, msg, QObject::tr("Error"), QObject::tr("&OK"), QObject::tr("&Details...")) == QMessageBox::No) // // PPPL_ShowLog(); // } else { /* reconnect on disconnect */ if (false){ qDebug( "Trying to reconnect... " ); if(_pppdata->authMethod() == AUTH_PAP || _pppdata->authMethod() == AUTH_CHAP || _pppdata->authMethod() == AUTH_PAPCHAP) Modem::modem->setSecret(_pppdata->authMethod(), encodeWord(_pppdata->storedUsername()), encodeWord(_pppdata->password())); @@ -518,25 +507,25 @@ void KPPPWidget::sigPPPDDied() { } } _pppdata->setpppdError(0); } } // void KPPPWidget::sigChld() { // qDebug( "sigchld()" ); // // pid_t id = wait(0L); // // if(id == helperPid && helperPid != -1) { // // kdDebug(5002) << "It was the setuid child that died" << endl; // // helperPid = -1; -// QString msg = i18n("kppp's helper process just died.\n" +// QString msg = QObject::tr("kppp's helper process just died.\n" // "Since a further execution would be pointless, " // "kppp will shut down now."); // QMessageBox::warning(0L,"error", msg); // //remove_pidfile(); // exit(1); // // } // } void KPPPWidget::newdefaultaccount(int i) { _pppdata->setDefaultAccount(connectto_c->text(i)); _pppdata->save(); @@ -551,102 +540,102 @@ void KPPPWidget::beginConnect() { // make sure to connect to the account that is selected in the combo box // (exeption: an account given by a command line argument) // if(!m_bCmdlAccount) { // _pppdata->setAccount(connectto_c->currentText()); // _pppdata->setPassword(PW_Edit->text()); // } else { _pppdata->setPassword(_pppdata->storedPassword()); // } QFileInfo info(pppdPath()); if(!info.exists()){ - QMessageBox::warning(this, "error", i18n("Cannot find the PPP daemon!\n" + QMessageBox::warning(this, "error", QObject::tr("Cannot find the PPP daemon!\n" "Make sure that pppd is installed and " "that you have entered the correct path.")); return; } #if 0 if(!info.isExecutable()){ QString string; - string = i18n("kppp cannot execute:\n %1\n" + string = QObject::tr("kppp cannot execute:\n %1\n" "Please make sure that you have given kppp " "setuid permission and that " "pppd is executable.").arg(_pppdata->pppdPath()); KMessageBox::error(this, string); return; } #endif QFileInfo info2(_pppdata->modemDevice()); if(!info2.exists()){ QString string; - string = i18n("kppp can not find:\n %1\nPlease make sure you have setup " + string = QObject::tr("kppp can not find:\n %1\nPlease make sure you have setup " "your modem device properly " "and/or adjust the location of the modem device on " "the modem tab of " "the setup dialog.").arg(_pppdata->modemDevice()); QMessageBox::warning(this, "error", string); return; } // if this is a PAP or CHAP account, ensure that username is // supplied if(_pppdata->authMethod() == AUTH_PAP || _pppdata->authMethod() == AUTH_CHAP || _pppdata->authMethod() == AUTH_PAPCHAP ) { if(ID_Edit->text().isEmpty()) { QMessageBox::warning(this,"error", - i18n("You have selected the authentication method PAP or CHAP. This requires that you supply a username and a password!")); + QObject::tr("You have selected the authentication method PAP or CHAP. This requires that you supply a username and a password!")); return; } else { if(!Modem::modem->setSecret(_pppdata->authMethod(), encodeWord(_pppdata->storedUsername()), encodeWord(_pppdata->password()))) { QString s; - s = i18n("Cannot create PAP/CHAP authentication\n" + s = QObject::tr("Cannot create PAP/CHAP authentication\n" "file \"%1\"").arg(PAP_AUTH_FILE); QMessageBox::warning(this, "error", s); return; } } } if (_pppdata->phonenumber().isEmpty()) { - QString s = i18n("You must specify a telephone number!"); + QString s = QObject::tr("You must specify a telephone number!"); QMessageBox::warning(this, "error", s); return; } this->hide(); - QString tit = i18n("Connecting to: %1").arg(_pppdata->accname()); + QString tit = QObject::tr("Connecting to: %1").arg(_pppdata->accname()); // con->setCaption(tit); // con->show(); emit begin_connect(); } void KPPPWidget::disconnect() { if (!_pppdata->command_before_disconnect().isEmpty()) { con_win->hide(); con->show(); - con->setCaption(i18n("Disconnecting...")); - con->setMsg(i18n("Executing command before disconnection.")); + con->setCaption(QObject::tr("Disconnecting...")); + con->setMsg(QObject::tr("Executing command before disconnection.")); qApp->processEvents(); QApplication::flushX(); // pid_t id = execute_command(_pppdata->command_before_disconnect()); // int i, status; // do { // kapp->processEvents(); // i = waitpid(id, &status, WNOHANG); // usleep(500000); // } while (i == 0 && errno == 0); @@ -683,26 +672,26 @@ void KPPPWidget::disconnect() { // } } // void KPPPWidget::helpbutton() { // kapp->invokeHelp(); // } void KPPPWidget::quitbutton() { if(_pppdata->pppdRunning()) { int ok = QMessageBox::warning(this, - i18n("Exiting kPPP will close your PPP Session."), - i18n("Quit kPPP?")); + QObject::tr("Exiting kPPP will close your PPP Session."), + QObject::tr("Quit kPPP?")); if(ok == QMessageBox::Yes) { Modem::modem->killPPPDaemon(); QApplication::flushX(); execute_command(_pppdata->command_on_disconnect()); removedns(); Modem::modem->unlockdevice(); } } else { if (!_pppdata->accname().isEmpty() && !_pppdata->storePassword()) _pppdata->setStoredPassword(""); } _pppdata->save(); @@ -727,25 +716,25 @@ void KPPPWidget::quitbutton() { // QString d = AccountingBase::getAccountingFile(_pppdata->accountingFile()); // // if(::access(d.data(), X_OK) != 0) // acct = new Accounting(this, stats); // // else // // acct = new ExecutableAccounting(this); // // connect to the accounting object // connect(acct, SIGNAL(changed(QString, QString)), // con_win, SLOT(slotAccounting(QString, QString))); // // if(!acct->loadRuleSet(_pppdata->accountingFile())) { -// // QString s= i18n("Can not load the accounting " +// // QString s= QObject::tr("Can not load the accounting " // // "ruleset \"%1\"!").arg(_pppdata->accountingFile()); // // starting the messagebox with a timer will prevent us // // from blocking the calling function ConnectWidget::timerEvent // ruleset_load_errmsg = s; // QTimer::singleShot(0, this, SLOT(rulesetLoadError())); // return; // } // //else // // acct->slotStart(); // } @@ -817,66 +806,66 @@ QString KPPPWidget::encodeWord(const QString &s) { // { // m_bQuitOnDisconnect = b; // } void KPPPWidget::showNews() { #ifdef KPPP_SHOW_NEWS /* * Introduce the QuickHelp feature to new users of this version */ #define QUICKHELP_HINT "Hint_QuickHelp" if(_pppdata->readNumConfig(GENERAL_GRP, QUICKHELP_HINT, 0) == 0) { QDialog dlg(0, 0, true); - dlg.setCaption(i18n("Recent Changes in KPPP")); + dlg.setCaption(QObject::tr("Recent Changes in KPPP")); QVBoxLayout *tl = new QVBoxLayout(&dlg, 10, 10); QHBoxLayout *l1 = new QHBoxLayout(10); QVBoxLayout *l2 = new QVBoxLayout(10); tl->addLayout(l1); QLabel *icon = new QLabel(&dlg); icon->setPixmap(BarIcon("exclamation")); icon->setFixedSize(icon->sizeHint()); l1->addWidget(icon); l1->addLayout(l2); - QLabel *l = new QLabel(i18n("From version 1.4.8 on, kppp has a new feature\n" + QLabel *l = new QLabel(QObject::tr("From version 1.4.8 on, kppp has a new feature\n" "called \"Quickhelp\". It's similar to a tooltip,\n" "but you can activate it whenever you want.\n" "\n" "To activate it, simply click on a control like\n" "a button or a label with the right mouse button.\n" "If the item supports Quickhelp, a popup menu\n" "will appear leading to Quickhelp.\n" "\n" "To test it, right-click somewhere in this text."), &dlg); - QCheckBox *cb = new QCheckBox(i18n("Don't show this hint again"), &dlg); + QCheckBox *cb = new QCheckBox(QObject::tr("Don't show this hint again"), &dlg); cb->setFixedSize(cb->sizeHint()); KButtonBox *bbox = new KButtonBox(&dlg); bbox->addStretch(1); - QPushButton *ok = bbox->addButton(i18n("OK")); + QPushButton *ok = bbox->addButton(QObject::tr("OK")); ok->setDefault(true); dlg.connect(ok, SIGNAL(clicked()), &dlg, SLOT(accept())); bbox->addStretch(1); bbox->layout(); l2->addWidget(l); l2->addWidget(cb); tl->addWidget(bbox); - QString tmp = i18n("This is an example of <b>QuickHelp</b>.\n" + QString tmp = QObject::tr("This is an example of <b>QuickHelp</b>.\n" "This window will stay open until you\n" "click a mouse button or a press a key.\n"); QWhatsThis::add(cb,tmp); QWhatsThis::add(l, tmp); dlg.exec(); if(cb->isChecked()) { _pppdata->writeConfig(GENERAL_GRP, QUICKHELP_HINT, 1); _pppdata->save(); } } diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp index d23fee4..3dbc8c3 100644 --- a/noncore/settings/networksettings/ppp/modem.cpp +++ b/noncore/settings/networksettings/ppp/modem.cpp @@ -42,29 +42,26 @@ # include <arpa/nameser.h> # include <resolv.h> #endif #ifndef _PATH_RESCONF #define _PATH_RESCONF "/etc/resolv.conf" #endif #define strlcpy strcpy #include "auth.h" #include "modem.h" #include "pppdata.h" -//#include <klocale.h> -#define i18n QObject::tr #define qError qDebug -//#include <kdebug.h> -//#include <config.h> + #define MY_ASSERT(x) if (!(x)) { \ qFatal( "ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__); \ exit(1); } static sigjmp_buf jmp_buffer; //Modem *Modem::modem = 0; const char* pppdPath() { @@ -90,25 +87,25 @@ const char* pppdPath() { } return pppdPath; } Modem::Modem( PPPData* pd ) { _pppdata = pd; modemfd = -1; _pppdExitStatus = -1; pppdPid = -1; - sn = 0L; + sn = m_modemDebug = 0L; data_mode = false; modem_is_locked = false; lockfile[0] = '\0'; device = "/dev/modem"; } Modem::~Modem() { } @@ -160,56 +157,56 @@ speed_t Modem::modemspeed() { break; } } bool Modem::opentty() { // int flags; //begin if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { close(modemfd); device = _pppdata->modemDevice(); if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) { qDebug("error opening modem device !"); - errmsg = i18n("Unable to open modem."); + errmsg = QObject::tr("Unable to open modem."); return false; } //bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { //} #if 0 if(_pppdata->UseCDLine()) { if(ioctl(modemfd, TIOCMGET, &flags) == -1) { - errmsg = i18n("Unable to detect state of CD line."); + errmsg = QObject::tr("Unable to detect state of CD line."); ::close(modemfd); modemfd = -1; return false; } if ((flags&TIOCM_CD) == 0) { - errmsg = i18n("The modem is not ready."); + errmsg = QObject::tr("The modem is not ready."); ::close(modemfd); modemfd = -1; return false; } } #endif tcdrain (modemfd); tcflush (modemfd, TCIOFLUSH); if(tcgetattr(modemfd, &tty) < 0){ // this helps in some cases tcsendbreak(modemfd, 0); sleep(1); if(tcgetattr(modemfd, &tty) < 0){ - errmsg = i18n("The modem is busy."); + errmsg = QObject::tr("The modem is busy."); ::close(modemfd); modemfd = -1; return false; } } memset(&initial_tty,'\0',sizeof(initial_tty)); initial_tty = tty; tty.c_cc[VMIN] = 0; // nonblocking tty.c_cc[VTIME] = 0; @@ -236,43 +233,43 @@ bool Modem::opentty() { } else { tty.c_cflag &= ~CRTSCTS; tty.c_iflag &= ~(IXON | IXOFF); } cfsetospeed(&tty, modemspeed()); cfsetispeed(&tty, modemspeed()); tcdrain(modemfd); if(tcsetattr(modemfd, TCSANOW, &tty) < 0){ - errmsg = i18n("The modem is busy."); + errmsg = QObject::tr("The modem is busy."); ::close(modemfd); modemfd=-1; return false; } - errmsg = i18n("Modem Ready."); + errmsg = QObject::tr("Modem Ready."); return true; } bool Modem::closetty() { if(modemfd >=0 ) { stop(); /* discard data not read or transmitted */ tcflush(modemfd, TCIOFLUSH); if(tcsetattr(modemfd, TCSANOW, &initial_tty) < 0){ - errmsg = i18n("Can't restore tty settings: tcsetattr()\n"); + errmsg = QObject::tr("Can't restore tty settings: tcsetattr()\n"); ::close(modemfd); modemfd = -1; return false; } ::close(modemfd); modemfd = -1; } return true; } @@ -404,25 +401,25 @@ bool Modem::hangup() { signal(SIGALRM, alarm_handler); alarm(2); tcsendbreak(modemfd, 0); alarm(0); signal(SIGALRM, SIG_IGN); } else { // we reach this point if the alarm handler got called closetty(); close(modemfd); modemfd = -1; - errmsg = i18n("The modem does not respond."); + errmsg = QObject::tr("The modem does not respond."); return false; } #ifndef __svr4__ // drops DTR but doesn't set it afterwards again. not good for init. tcgetattr(modemfd, &temptty); cfsetospeed(&temptty, B0); cfsetispeed(&temptty, B0); tcsetattr(modemfd, TCSAFLUSH, &temptty); #else int modemstat; ioctl(modemfd, TIOCMGET, &modemstat); modemstat &= ~TIOCM_DTR; @@ -546,25 +543,25 @@ QString Modem::parseModemSpeed(const QString &s) { // len = rrx[RXMAX-1].matchedLength(); sub = sub.mid(idx, len); result = sub.toInt(); if(result > 0) { tx = result; break; } } } } if(rx == -1 && tx == -1) - result = i18n("Unknown speed"); + result = QObject::tr("Unknown speed"); else if(tx == -1) result.setNum(rx); else if(rx == -1) // should not happen result.setNum(tx); else result.sprintf("%d/%d", rx, tx); qDebug( "The parsed result is: %s", result.latin1()); return result; } @@ -868,80 +865,108 @@ int checkForInterface() } bool Modem::execpppd(const char *arguments) { char buf[MAX_CMDLEN]; char *args[MaxArgs]; pid_t pgrpid; if(modemfd<0) return false; _pppdExitStatus = -1; + (void)::pipe( m_pppdLOG ); + switch(pppdPid = fork()) { case -1: fprintf(stderr,"In parent: fork() failed\n"); + ::close( m_pppdLOG[0] ); + ::close( m_pppdLOG[1] ); return false; break; case 0: // let's parse the arguments the user supplied into UNIX suitable form // that is a list of pointers each pointing to exactly one word strlcpy(buf, arguments); parseargs(buf, args); // become a session leader and let /dev/ttySx // be the controlling terminal. pgrpid = setsid(); #ifdef TIOCSCTTY if(ioctl(modemfd, TIOCSCTTY, 0)<0) fprintf(stderr, "ioctl() failed.\n"); #elif defined (TIOCSPGRP) if(ioctl(modemfd, TIOCSPGRP, &pgrpid)<0) fprintf(stderr, "ioctl() failed.\n"); #endif if(tcsetpgrp(modemfd, pgrpid)<0) fprintf(stderr, "tcsetpgrp() failed.\n"); + ::close( m_pppdLOG[0] ); + ::setenv( "LANG", "C", 1 ); // overwrite + dup2(m_pppdLOG[1], 11 ); // for logfd 11 dup2(modemfd, 0); dup2(modemfd, 1); + switch (checkForInterface()) { case 1: fprintf(stderr, "Cannot determine if kernel supports ppp.\n"); break; case -1: fprintf(stderr, "Kernel does not support ppp, oops.\n"); break; case 0: fprintf(stderr, "Kernel supports ppp alright.\n"); break; } execve(pppdPath(), args, 0L); _exit(0); break; default: qDebug("In parent: pppd pid %d\n",pppdPid); close(modemfd); + + ::close( m_pppdLOG[1] ); + // set it to nonblocking io + int flag = ::fcntl( m_pppdLOG[0], F_GETFL ); + + if ( !(flag & O_NONBLOCK) ) { + qDebug("Setting nonblocking io"); + flag |= O_NONBLOCK; + ::fcntl(m_pppdLOG[0], F_SETFL, flag ); + } + + delete m_modemDebug; + m_modemDebug = new QSocketNotifier(m_pppdLOG[0], QSocketNotifier::Read, this ); + connect(m_modemDebug, SIGNAL(activated(int) ), + this, SLOT(slotModemDebug(int) ) ); + modemfd = -1; + m_pppdDev = QString::fromLatin1("ppp0"); return true; break; } } bool Modem::killpppd() { + qDebug("In killpppd and pid is %d", pppdPid ); if(pppdPid > 0) { + delete m_modemDebug; + m_modemDebug = 0; qDebug("In killpppd(): Sending SIGTERM to %d\n", pppdPid); if(kill(pppdPid, SIGTERM) < 0) { qDebug("Error terminating %d. Sending SIGKILL\n", pppdPid); if(kill(pppdPid, SIGKILL) < 0) { qDebug("Error killing %d\n", pppdPid); return false; } } } return true; } @@ -1012,12 +1037,44 @@ int Modem::openResolv(int flags) if ((fd = open(_PATH_RESCONF, flags)) == -1) { qDebug("error opening resolv.conf!"); fd = open(DEVNULL, O_RDONLY); } return fd; } bool Modem::setHostname(const QString & name) { return sethostname(name, name.length()) == 0; } +QString Modem::pppDevice()const { + return m_pppdDev; +} +void Modem::setPPPDevice( const QString& dev ) { + m_pppdDev = dev; +} +pid_t Modem::pppPID()const { + return pppdPid; +} +void Modem::setPPPDPid( pid_t pid ) { + qDebug("Modem setting pid"); + _pppdExitStatus = -1; + pppdPid = pid; + modemfd = -1; +} +void Modem::slotModemDebug(int fd) { + char buf[2049]; + int len; + + // read in pppd data look for Using interface + // then read the interface + // we limit to 10 device now 0-9 + if((len = ::read(fd, buf, 2048)) > 0) { + buf[len+1] = '\0'; + char *found; + if ( (found = ::strstr(buf, "Using interface ") ) ) { + found += 16; + m_pppdDev = QString::fromLatin1(found, 5 ); + m_pppdDev = m_pppdDev.simplifyWhiteSpace(); + } + } +} diff --git a/noncore/settings/networksettings/ppp/modem.h b/noncore/settings/networksettings/ppp/modem.h index 103cbeb..8ecc354 100644 --- a/noncore/settings/networksettings/ppp/modem.h +++ b/noncore/settings/networksettings/ppp/modem.h @@ -40,24 +40,26 @@ class PPPData; void alarm_handler(int); const char *pppdPath(); class Modem : public QObject { Q_OBJECT public: Modem(PPPData*); ~Modem(); const QString getDevice() {return device;}; void setDevice(const QString dev) {device = dev;}; + void save(); + bool opentty(); bool closetty(); bool hangup(); bool writeChar(unsigned char); bool writeLine(const char *); bool dataMode() const { return data_mode; } void setDataMode(bool set) { data_mode = set; } const QString modemMessage(); speed_t modemspeed(); static QString parseModemSpeed(const QString &); void notify(const QObject *, const char *); void stop(); @@ -65,56 +67,65 @@ public: int lockdevice(); void unlockdevice(); bool setSecret(int,const char*,const char*); bool removeSecret(int); void killPPPDaemon(); int pppdExitStatus(); bool execPPPDaemon(const QString & arguments); int openResolv(int flags); bool setHostname(const QString & name); + QString pppDevice()const; + void setPPPDevice( const QString& ); + pid_t pppPID()const; + void setPPPDPid( pid_t ); + public: enum Auth { PAP = 1, CHAP }; // static Modem *modem; int lastStatus; signals: void charWaiting(unsigned char); private slots: void startNotifier(); void stopNotifier(); void readtty(int); + void slotModemDebug(int); private: enum { MaxPathLen = 30, MaxStrLen = 40, MaxArgs = 100 }; enum { Original=0x100, New=0x200, Old=0x400 } Version; const char* authFile(Auth method, int version = Original ); bool createAuthFile(Auth method,const char *username,const char *password); bool removeAuthFile(Auth method); bool execpppd(const char *arguments); bool killpppd(); void parseargs(char* buf, char** args); void escape_to_command_mode(); int openLockfile(QString,int); private: QString device; QString lockfile; int modemfd; int pppdPid; int _pppdExitStatus; QSocketNotifier *sn; + QSocketNotifier *m_modemDebug; bool data_mode; QString errmsg; struct termios initial_tty; struct termios tty; bool modem_is_locked; PPPData *_pppdata; + int m_pppdLOG[2]; + QString m_pppdDev; }; #endif diff --git a/noncore/settings/networksettings/ppp/modemcmds.cpp b/noncore/settings/networksettings/ppp/modemcmds.cpp index 1d9db6e..e797795 100644 --- a/noncore/settings/networksettings/ppp/modemcmds.cpp +++ b/noncore/settings/networksettings/ppp/modemcmds.cpp @@ -18,223 +18,233 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with dummyWidget program; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <qlayout.h> #include <qslider.h> #include <qbuttongroup.h> +#include <qscrollview.h> +#include <qapplication.h> #include <stdlib.h> -//#include <kapplication.h> // for getMiniIcon() -//#include <klocale.h> -#define i18n QObject::tr #include "modemcmds.h" #include "pppdata.h" -//#include <kwin.h> #define ADJUSTEDIT(e) //e->setText("XXXXXXXXqy"); e->setMinimumSize(e->sizeHint()); /*e->setFixedHeight(e->sizeHint().height());*/ e->setText(""); e->setMaxLength(MODEMSTR_SIZE); // a little trick to make the label look like a disabled lineedit #define FORMATSLIDERLABEL(l) //l->setFixedWidth(l->sizeHint().width()); l->setFixedHeight(QLineEdit(dummyWidget).sizeHint().height()); l->setAlignment(AlignCenter); l->setFrameStyle(QFrame::WinPanel|QFrame::Sunken); l->setLineWidth(2); -ModemCommands::ModemCommands(PPPData *pd, QWidget *parent, const char *name) - : QDialog(parent, name, true ), _pppdata(pd) +ModemCommands::ModemCommands(PPPData *pd, QWidget *parent, const char *name , bool modal, WFlags f) + : QDialog( parent, name, modal, f ), _pppdata(pd) { - setCaption(i18n("Edit Modem Commands")); + setCaption(QObject::tr("Edit Modem Commands")); const int GRIDROWS = 22; int row = 0; + QVBoxLayout *main = new QVBoxLayout( this ); + QScrollView *sv = new QScrollView( this ); + QWidget *mainW = new QWidget( sv->viewport() ); + sv->setResizePolicy( QScrollView::AutoOneFit ); + sv->setHScrollBarMode( QScrollView::AlwaysOff ); + sv->setFrameShape( QFrame::NoFrame ); + sv->addChild( mainW ); + main->addWidget( sv ); + // evil hack + mainW->setMaximumWidth( QApplication::desktop()->width() - 10 ); + // toplevel layout - QVBoxLayout *tl = new QVBoxLayout(this, 10, 4); + QVBoxLayout *tl = new QVBoxLayout( mainW, 10, 4); // add grid + frame QGridLayout *l1 = new QGridLayout(GRIDROWS, 4); tl->addLayout(l1); - box = new QGroupBox(this, "box"); + box = new QGroupBox(mainW, "box"); + box->setMargin( 0 ); l1->addMultiCellWidget(box, row++, GRIDROWS, 0, 3); // put slider and label into a separate H-Box QHBoxLayout *l2 = new QHBoxLayout; l1->addLayout(l2, row, 2); - lpreinitslider = new QLabel("MMMM", this); + lpreinitslider = new QLabel("MMMM", mainW); FORMATSLIDERLABEL(lpreinitslider); QSlider *preinitslider = new QSlider(0, 300, 1, 0, - QSlider::Horizontal, this); + QSlider::Horizontal, mainW); // preinitslider->setFixedHeight(preinitslider->sizeHint().height()); connect(preinitslider, SIGNAL(valueChanged(int)), lpreinitslider, SLOT(setNum(int))); l2->addWidget(lpreinitslider, 0); l2->addWidget(preinitslider, 1); - lpreinit = new QLabel(i18n("Pre-init delay (sec/100):"), this); + lpreinit = new QLabel(QObject::tr("Pre-init delay (sec/100):"), mainW); l1->addWidget(lpreinit, row++, 1); for(int i = 0; i < PPPData::NumInitStrings; i++) { - initstr[i] = new QLineEdit(this); - QLabel *initLabel = new QLabel(i18n("Initialization string %1:").arg(i + 1), - this); + initstr[i] = new QLineEdit(mainW); + QLabel *initLabel = new QLabel(QObject::tr("Initialization string %1:").arg(i + 1), + mainW); ADJUSTEDIT(initstr[i]); l1->addWidget(initLabel, row, 1); l1->addWidget(initstr[i], row++, 2); } QHBoxLayout *l3 = new QHBoxLayout; l1->addLayout(l3, row, 2); - linitslider = new QLabel("MMMM", this); + linitslider = new QLabel("MMMM", mainW); FORMATSLIDERLABEL(linitslider); QSlider *initslider = new QSlider(1, 300, 1, 0, - QSlider::Horizontal, this); + QSlider::Horizontal, mainW); // initslider->setFixedHeight(initslider->sizeHint().height()); connect(initslider, SIGNAL(valueChanged(int)), linitslider, SLOT(setNum(int))); l3->addWidget(linitslider, 0); l3->addWidget(initslider, 1); - label3 = new QLabel(i18n("Post-init delay (sec/100):"), this); + label3 = new QLabel(QObject::tr("Post-init delay (sec/100):"), mainW); l1->addWidget(label3, row++, 1); /* Set ATS11 (Dial tone duration) between 0-255 (Default ~ 70) */ QHBoxLayout *l4 = new QHBoxLayout; l1->addLayout(l4, row, 2); - ldurationslider = new QLabel("MMMM", this); + ldurationslider = new QLabel("MMMM", mainW); FORMATSLIDERLABEL(ldurationslider); QSlider *durationslider = new QSlider(1, 255, 1, 0, - QSlider::Horizontal, this); + QSlider::Horizontal, mainW); // durationslider->setFixedHeight(durationslider->sizeHint().height()); connect(durationslider, SIGNAL(valueChanged(int)), ldurationslider, SLOT(setNum(int))); l4->addWidget(ldurationslider, 0); l4->addWidget(durationslider, 1); - lduration = new QLabel(i18n("Dialing speed (sec/100):"), this); + lduration = new QLabel(QObject::tr("Dialing speed (sec/100):"), mainW); l1->addWidget(lduration, row++, 1); - initresp = new QLineEdit(this); - label2 = new QLabel(i18n("Init response:"), this); + initresp = new QLineEdit(mainW); + label2 = new QLabel(QObject::tr("Init response:"), mainW); ADJUSTEDIT(initresp); l1->addWidget(label2, row, 1); l1->addWidget(initresp, row++, 2); - nodetectdialtone = new QLineEdit(this); - lnodetectdialtone = new QLabel(i18n("No dial tone detection:"), this); + nodetectdialtone = new QLineEdit(mainW); + lnodetectdialtone = new QLabel(QObject::tr("No dial tone detection:"), mainW); ADJUSTEDIT(nodetectdialtone); l1->addWidget(lnodetectdialtone, row, 1); l1->addWidget(nodetectdialtone, row++, 2); - dialstr = new QLineEdit(this); - label4 = new QLabel(i18n("Dial string:"),this); + dialstr = new QLineEdit(mainW); + label4 = new QLabel(QObject::tr("Dial string:"),mainW); ADJUSTEDIT(dialstr); l1->addWidget(label4, row, 1); l1->addWidget(dialstr, row++, 2); - connectresp = new QLineEdit(this); - label5 = new QLabel(i18n("Connect response:"), this); + connectresp = new QLineEdit(mainW); + label5 = new QLabel(QObject::tr("Connect response:"), mainW); ADJUSTEDIT(connectresp); l1->addWidget(label5, row, 1); l1->addWidget(connectresp, row++, 2); - busyresp = new QLineEdit(this); - label6 = new QLabel(i18n("Busy response:"), this); + busyresp = new QLineEdit(mainW); + label6 = new QLabel(QObject::tr("Busy response:"), mainW); ADJUSTEDIT(busyresp); l1->addWidget(label6, row, 1); l1->addWidget(busyresp, row++, 2); - nocarrierresp = new QLineEdit(this); - label7 = new QLabel(i18n("No carrier response:"), this); + nocarrierresp = new QLineEdit(mainW); + label7 = new QLabel(QObject::tr("No carrier response:"), mainW); ADJUSTEDIT(nocarrierresp); l1->addWidget(label7, row, 1); l1->addWidget(nocarrierresp, row++, 2); - nodialtoneresp = new QLineEdit(this); - label8 = new QLabel(i18n("No dial tone response:"), this); + nodialtoneresp = new QLineEdit(mainW); + label8 = new QLabel(QObject::tr("No dial tone response:"), mainW); ADJUSTEDIT(nodialtoneresp); l1->addWidget(label8, row, 1); l1->addWidget(nodialtoneresp, row++, 2); - hangupstr = new QLineEdit(this); - label9 = new QLabel(i18n("Hangup string:"), this); + hangupstr = new QLineEdit(mainW); + label9 = new QLabel(QObject::tr("Hangup string:"), mainW); ADJUSTEDIT(hangupstr); l1->addWidget(label9, row, 1); l1->addWidget(hangupstr, row++, 2); - hangupresp = new QLineEdit(this); - label10 = new QLabel(i18n("Hangup response:"), this); + hangupresp = new QLineEdit(mainW); + label10 = new QLabel(QObject::tr("Hangup response:"), mainW); ADJUSTEDIT(hangupresp); l1->addWidget(label10, row, 1); l1->addWidget(hangupresp, row++, 2); - answerstr = new QLineEdit(this); - label11 = new QLabel(i18n("Answer string:"), this); + answerstr = new QLineEdit(mainW); + label11 = new QLabel(QObject::tr("Answer string:"), mainW); ADJUSTEDIT(answerstr); l1->addWidget(label11, row, 1); l1->addWidget(answerstr, row++, 2); - ringresp = new QLineEdit(this); - label12 = new QLabel(i18n("Ring response:"), this); + ringresp = new QLineEdit(mainW); + label12 = new QLabel(QObject::tr("Ring response:"), mainW); ADJUSTEDIT(ringresp); l1->addWidget(label12, row, 1); l1->addWidget(ringresp, row++, 2); - answerresp = new QLineEdit(this); - label13 = new QLabel(i18n("Answer response:"), this); + answerresp = new QLineEdit(mainW); + label13 = new QLabel(QObject::tr("Answer response:"), mainW); ADJUSTEDIT(answerresp); l1->addWidget(label13, row, 1); l1->addWidget(answerresp, row++, 2); - escapestr = new QLineEdit(this); - label14 = new QLabel(i18n("Escape string:"), this); + escapestr = new QLineEdit(mainW); + label14 = new QLabel(QObject::tr("Escape string:"), mainW); ADJUSTEDIT(escapestr); l1->addWidget(label14, row, 1); l1->addWidget(escapestr, row++, 2); - escaperesp = new QLineEdit(this); - label15 = new QLabel(i18n("Escape response:"), this); + escaperesp = new QLineEdit(mainW); + label15 = new QLabel(QObject::tr("Escape response:"), mainW); ADJUSTEDIT(escaperesp); l1->addWidget(label15, row, 1); l1->addWidget(escaperesp, row++, 2); QHBoxLayout *l5 = new QHBoxLayout; l1->addLayout(l5, row, 2); - lslider = new QLabel("MMMM", this); + lslider = new QLabel("MMMM", mainW); FORMATSLIDERLABEL(lslider); QSlider *slider = new QSlider(0, 255, 1, 0, - QSlider::Horizontal, this); + QSlider::Horizontal, mainW); // slider->setFixedHeight(slider->sizeHint().height()); connect(slider, SIGNAL(valueChanged(int)), lslider, SLOT(setNum(int))); l5->addWidget(lslider, 0); l5->addWidget(slider, 1); - label16 = new QLabel(i18n("Guard time (sec/50):"), this); + label16 = new QLabel(QObject::tr("Guard time (sec/50):"), mainW); l1->addWidget(label16, row++, 1); - QLabel *l = new QLabel(i18n("Volume off/low/high:"), this); + QLabel *l = new QLabel(QObject::tr("Volume off/low/high:"), mainW); l1->addWidget(l, row, 1); QHBoxLayout *l6 = new QHBoxLayout; l1->addLayout(l6, row++, 2); - volume_off = new QLineEdit(this); + volume_off = new QLineEdit(mainW); // volume_off->setFixedHeight(volume_off->sizeHint().height()); // volume_off->setMinimumWidth((int)(volume_off->sizeHint().width() / 2)); - volume_medium = new QLineEdit(this); + volume_medium = new QLineEdit(mainW); // volume_medium->setFixedHeight(volume_medium->sizeHint().height()); // volume_medium->setMinimumWidth((int)(volume_medium->sizeHint().width() / 2)); - volume_high = new QLineEdit(this); + volume_high = new QLineEdit(mainW); // volume_high->setFixedHeight(volume_high->sizeHint().height()); // volume_high->setMinimumWidth((int)(volume_high->sizeHint().width() / 2)); l6->addWidget(volume_off); l6->addWidget(volume_medium); l6->addWidget(volume_high); initstr[0]->setFocus(); l1->addColSpacing(0, 10); l1->addColSpacing(3, 10); l1->addRowSpacing(0, 5); l1->addRowSpacing(GRIDROWS, 5); @@ -298,21 +308,26 @@ void ModemCommands::slotOk() { _pppdata->setModemHangupStr(hangupstr->text()); _pppdata->setModemHangupResp(hangupresp->text()); _pppdata->setModemAnswerStr(answerstr->text()); _pppdata->setModemRingResp(ringresp->text()); _pppdata->setModemAnswerResp(answerresp->text()); _pppdata->setVolumeHigh(volume_high->text()); _pppdata->setVolumeMedium(volume_medium->text()); _pppdata->setVolumeOff(volume_off->text()); _pppdata->save(); - accept(); + QDialog::accept(); +} + +void ModemCommands::accept() +{ + slotOk(); } void ModemCommands::slotCancel() { reject(); } //#include "modemcmds.moc" diff --git a/noncore/settings/networksettings/ppp/modemcmds.h b/noncore/settings/networksettings/ppp/modemcmds.h index ef69fec..81d67f4 100644 --- a/noncore/settings/networksettings/ppp/modemcmds.h +++ b/noncore/settings/networksettings/ppp/modemcmds.h @@ -35,28 +35,29 @@ #include <qdialog.h> #include <qlineedit.h> #include <qpushbutton.h> #include <qlabel.h> #include "pppdata.h" class ModemCommands : public QDialog { Q_OBJECT public: - ModemCommands(PPPData*, QWidget *parent=0, const char *name=0); + ModemCommands(PPPData*, QWidget *parent=0, const char *name=0, bool modal=0, WFlags f = 0); ~ModemCommands() {} private slots: + virtual void accept(); void slotCancel(); void slotOk(); private: PPPData *_pppdata; QGroupBox *box; QLineEdit *initstr[int(PPPData::NumInitStrings)]; QLineEdit *initresp; QLabel *label2; diff --git a/noncore/settings/networksettings/ppp/modeminfo.cpp b/noncore/settings/networksettings/ppp/modeminfo.cpp index 0bec186..dbb26db 100644 --- a/noncore/settings/networksettings/ppp/modeminfo.cpp +++ b/noncore/settings/networksettings/ppp/modeminfo.cpp @@ -25,59 +25,57 @@ */ #include <unistd.h> #include <qregexp.h> #include <qlayout.h> // #include <kwin.h> // #include <kmessagebox.h> // #include <kapplication.h> #include <qmessagebox.h> #include <qapplication.h> #include "modeminfo.h" #include "modem.h" -//#include <klocale.h> -#define i18n QObject::tr ModemTransfer::ModemTransfer(Modem *mo, QWidget *parent, const char *name) : QDialog(parent, name,TRUE, WStyle_Customize|WStyle_NormalBorder), _modem(mo) { - setCaption(i18n("ATI Query")); + setCaption(QObject::tr("ATI Query")); // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); QVBoxLayout *tl = new QVBoxLayout(this, 10, 10); progressBar = new QProgressBar(this, "bar"); progressBar->setTotalSteps(8); statusBar = new QLabel(this,"sBar"); statusBar->setFrameStyle(QFrame::Panel|QFrame::Sunken); statusBar->setAlignment(AlignCenter); // This is a rather complicated case. Since we do not know which // message is the widest in the national language, we'd to // search all these messages. This is a little overkill, so I take // the longest english message, translate it and give it additional // 20 percent space. Hope this is enough. - statusBar->setText(i18n("Unable to create modem lock file.")); + statusBar->setText(QObject::tr("Unable to create modem lock file.")); statusBar->setFixedWidth((statusBar->sizeHint().width() * 12) / 10); statusBar->setFixedHeight(statusBar->sizeHint().height() + 4); // set original text - statusBar->setText(i18n("Looking for modem...")); + statusBar->setText(QObject::tr("Looking for modem...")); progressBar->setFixedHeight(statusBar->minimumSize().height()); tl->addWidget(progressBar); tl->addWidget(statusBar); - cancel = new QPushButton(i18n("Cancel"), this); + cancel = new QPushButton(QObject::tr("Cancel"), this); cancel->setFocus(); connect(cancel, SIGNAL(clicked()), SLOT(cancelbutton())); QHBoxLayout *l1 = new QHBoxLayout; tl->addLayout(l1); l1->addStretch(1); l1->addWidget(cancel); setFixedSize(sizeHint()); step = 0; @@ -109,53 +107,53 @@ void ModemTransfer::ati_done() { mi->showMaximized(); mi->exec(); delete mi; accept(); } void ModemTransfer::time_out_slot() { timeout_timer->stop(); scripttimer->stop(); - QMessageBox::warning(this, tr("Error"), i18n("Modem Query timed out.")); + QMessageBox::warning(this, tr("Error"), QObject::tr("Modem Query timed out.")); reject(); } void ModemTransfer::init() { qApp->processEvents(); int lock = _modem->lockdevice(); if (lock == 1) { - statusBar->setText(i18n("Modem device is locked.")); + statusBar->setText(QObject::tr("Modem device is locked.")); return; } if (lock == -1) { - statusBar->setText(i18n("Unable to create modem lock file.")); + statusBar->setText(QObject::tr("Unable to create modem lock file.")); return; } if(_modem->opentty()) { if(_modem->hangup()) { usleep(100000); // wait 0.1 secs _modem->writeLine("ATE0Q1V1"); // E0 don't echo the commands I send ... - statusBar->setText(i18n("Modem Ready")); + statusBar->setText(QObject::tr("Modem Ready")); qApp->processEvents(); usleep(100000); // wait 0.1 secs qApp->processEvents(); scripttimer->start(1000); // this one does the ati query // clear modem buffer _modem->flush(); _modem->notify(this, SLOT(readChar(unsigned char))); return; } } @@ -218,72 +216,72 @@ void ModemTransfer::readtty() { if(step <= NUM_OF_ATI) ati_query_strings[step-1] = readbuffer.copy(); readbuffer = ""; } void ModemTransfer::cancelbutton() { scripttimer->stop(); _modem->stop(); timeout_timer->stop(); - statusBar->setText(i18n("One moment please...")); + statusBar->setText(QObject::tr("One moment please...")); qApp->processEvents(); _modem->hangup(); _modem->closetty(); _modem->unlockdevice(); reject(); } void ModemTransfer::closeEvent( QCloseEvent *e ) { cancelbutton(); e->accept(); } ModemInfo::ModemInfo(QWidget *parent, const char* name) : QDialog(parent, name, TRUE, WStyle_Customize|WStyle_NormalBorder) { QString label_text; - setCaption(i18n("Modem Query Results")); + setCaption(QObject::tr("Modem Query Results")); // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); QVBoxLayout *tl = new QVBoxLayout(this, 10, 10); QGridLayout *l1 = new QGridLayout(NUM_OF_ATI, 2, 5); tl->addLayout(l1, 1); for(int i = 0 ; i < NUM_OF_ATI ; i++) { label_text = ""; if ( i == 0) label_text.sprintf("ATI :"); else label_text.sprintf("ATI %d:", i ); ati_label[i] = new QLabel(label_text, this); l1->addWidget(ati_label[i], i, 0); ati_label_result[i] = new QLineEdit(this); ati_label_result[i]->setMinimumWidth(fontMetrics().width('H') * 24); l1->addWidget(ati_label_result[i], i, 1); } //tl->addSpacing(1); QHBoxLayout *l2 = new QHBoxLayout; - QPushButton *ok = new QPushButton(i18n("Close"), this); + QPushButton *ok = new QPushButton(QObject::tr("Close"), this); ok->setDefault(TRUE); ok->setFocus(); tl->addLayout(l2); l2->addStretch(1); connect(ok, SIGNAL(clicked()), SLOT(accept())); l2->addWidget(ok); setMinimumSize(sizeHint()); } diff --git a/noncore/settings/networksettings/ppp/ppp.pro b/noncore/settings/networksettings/ppp/ppp.pro index fc89f35..84acd0e 100644 --- a/noncore/settings/networksettings/ppp/ppp.pro +++ b/noncore/settings/networksettings/ppp/ppp.pro @@ -1,18 +1,17 @@ #TEMPLATE = app # TEMPLATE = lib #CONFIG += qt warn_on release CONFIG += qt warn_on debug DESTDIR = $(OPIEDIR)/plugins/networksettings -HEADERS = pppmodule.h devices.h modem.h modeminfo.h pppdata.h kpppconfig.h pppdata.h runtests.h general.h modemcmds.h conwindow.h accounts.h connect.h edit.h scriptedit.h pppdargs.h iplined.h pwentry.h pppconfig.h interfaceinformationppp.h interfaceppp.h authwidget.h -SOURCES = pppmodule.cpp modem.cpp modeminfo.cpp pppdata.cpp runtests.cpp general.cpp modemcmds.cpp conwindow.cpp accounts.cpp connect.cpp edit.cpp scriptedit.cpp pppdargs.cpp iplined.cpp pwentry.cpp pppconfig.cpp interfaceinformationppp.cpp interfaceppp.cpp authwidget.cpp +HEADERS = pppmodule.h modem.h modeminfo.h pppdata.h kpppconfig.h pppdata.h runtests.h general.h modemcmds.h conwindow.h accounts.h connect.h edit.h scriptedit.h pppdargs.h iplined.h pwentry.h pppconfig.h interfaceinformationppp.h interfaceppp.h authwidget.h chooserwidget.h devices.h +SOURCES = pppmodule.cpp modem.cpp modeminfo.cpp pppdata.cpp runtests.cpp general.cpp modemcmds.cpp conwindow.cpp accounts.cpp connect.cpp edit.cpp scriptedit.cpp pppdargs.cpp iplined.cpp pwentry.cpp pppconfig.cpp interfaceinformationppp.cpp interfaceppp.cpp authwidget.cpp chooserwidget.cpp devices.cpp INCLUDEPATH += $(OPIEDIR)/include ../ ../interfaces/ DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe -L../interfaces/ -linterfaces -INTERFACES = TARGET = kppp VERSION = 1.0.0 include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings/ppp/pppconfig.cpp b/noncore/settings/networksettings/ppp/pppconfig.cpp index 5fa7d3f..97baf31 100644 --- a/noncore/settings/networksettings/ppp/pppconfig.cpp +++ b/noncore/settings/networksettings/ppp/pppconfig.cpp @@ -1,70 +1,75 @@ #include <qlayout.h> #include <qmessagebox.h> #include <qtabwidget.h> #include "accounts.h" +#include "devices.h" #include "general.h" #include "interfaceppp.h" #include "modem.h" #include "pppconfig.h" #include "pppdata.h" #include "runtests.h" PPPConfigWidget::PPPConfigWidget( InterfacePPP* iface, QWidget *parent, const char *name, bool modal, WFlags fl ) : QDialog(parent, name, modal, fl) { setCaption(tr("Configure Modem")); int result = runTests(); if(result == TEST_CRITICAL){ QMessageBox::critical(0, tr("Modem failure"), tr("A critical failure appeard while testing the modem") ); return; } interface = iface; qDebug("PPPConfigWidget::PPPConfigWidget"); qDebug(" interface->getHardwareName >%s<", interface->getHardwareName().latin1()); qDebug(" _pppdata->accname >%s<",interface->data()->accname().latin1()); - qDebug(" _pppdata->currentAccountID() >%i<",interface->data()->currentAccountID()); + QVBoxLayout *layout = new QVBoxLayout( this ); layout->setSpacing( 0 ); layout->setMargin( 1 ); tabWindow = new QTabWidget( this, "tabWidget" ); layout->addWidget( tabWindow ); - accounts = new AccountWidget( interface->data(), tabWindow, "accounts" ); + accounts = new AccountWidget( interface->data(), tabWindow, "accounts", Qt::WStyle_ContextHelp ); tabWindow->addTab( accounts, tr("&Accounts") ); - modem1 = new ModemWidget( interface, tabWindow, "modem1" ); - tabWindow->addTab( modem1, tr("&Device") ); - modem2 = new ModemWidget2( interface, tabWindow, "modem2" ); - tabWindow->addTab( modem2, tr("&Modem") ); + devices = new DevicesWidget( interface, tabWindow, "devices", Qt::WStyle_ContextHelp ); + tabWindow->addTab( devices, tr("&Devices") ); + +//OLD: +// modem1 = new ModemWidget( interface, tabWindow, "modem1" ); +// tabWindow->addTab( modem1, tr("&Device") ); +// modem2 = new ModemWidget2( interface, tabWindow, "modem2" ); +// tabWindow->addTab( modem2, tr("&Modem") ); } PPPConfigWidget::~PPPConfigWidget() { } void PPPConfigWidget::accept() { qDebug("PPPConfigWidget::accept"); qDebug(" _pppdata->accname >%s<",interface->data()->accname().latin1()); qDebug(" interface->getHardwareName >%s<", interface->getHardwareName().latin1()); - interface->setInterfaceName( interface->data()->modemDevice() ); + interface->setInterfaceName( interface->data()->devname() ); interface->setHardwareName( interface->data()->accname() ); interface->save(); QDialog::accept(); } void PPPConfigWidget::reject() { interface->data()->cancel(); QDialog::reject(); } diff --git a/noncore/settings/networksettings/ppp/pppconfig.h b/noncore/settings/networksettings/ppp/pppconfig.h index 9bab6fe..4d7912f 100644 --- a/noncore/settings/networksettings/ppp/pppconfig.h +++ b/noncore/settings/networksettings/ppp/pppconfig.h @@ -1,37 +1,43 @@ #ifndef _PPPCONFIG_H_ #define _PPPCONFIG_H_ #include <qdialog.h> class QTabWidget; //class Interface; class InterfacePPP; class AccountWidget; class GeneralWidget; +class DevicesWidget; + +//OLD: class ModemWidget; class ModemWidget2; class PPPConfigWidget : public QDialog { Q_OBJECT public: PPPConfigWidget( InterfacePPP*, QWidget *parent=0, const char *name=0, bool modal = false, WFlags fl = 0 ); ~PPPConfigWidget(); protected slots: virtual void accept(); virtual void reject(); private: InterfacePPP *interface; QTabWidget *tabWindow; AccountWidget *accounts; GeneralWidget *general; + DevicesWidget* devices; + + //OLD: ModemWidget *modem1; ModemWidget2 *modem2; }; #endif diff --git a/noncore/settings/networksettings/ppp/pppdata.cpp b/noncore/settings/networksettings/ppp/pppdata.cpp index 8f45e54..f4727c1 100644 --- a/noncore/settings/networksettings/ppp/pppdata.cpp +++ b/noncore/settings/networksettings/ppp/pppdata.cpp @@ -17,110 +17,121 @@ * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "pppdata.h" #include "runtests.h" -#include "devices.h" +//#include "devices.h" //#include <klocale.h> -#define i18n QObject::tr #include <qpe/config.h> #include <qmessagebox.h> #include <qapplication.h> // #include <klocale.h> // #include <kconfig.h> // #include <kmessagebox.h> // #include <kapplication.h> #include <assert.h> #define SEPARATOR -sseepp- #define SEP QString("%1SEPARATOR%1") PPPData::PPPData() - : modemDeviceGroup(-1), - passwd(""), + : passwd(""), + _modemName(""), highcount(-1), // start out with no entries - caccount(-1), // set the current account index also + highcountdev(-1), // start out with no entries +// caccount(-1), // set the current account index also suidprocessid(-1), // process ID of setuid child pppdisrunning(false), pppderror(0) { highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1; - - if (highcount > MAX_ACCOUNTS) - highcount = MAX_ACCOUNTS; - - if(highcount >= 0 && defaultAccount().isEmpty()) { - setAccountbyIndex(0); - setDefaultAccount(accname()); - } else if(!setAccount(defaultAccount())) + highcountdev = readNumConfig(GENERAL_GRP, NUMDEVICES_KEY, 0) - 1; + Config cfg = config(); + cfg.setGroup(GENERAL_GRP); + accountList = cfg.readListEntry(ACCOUNT_LIST, ',' ); + deviceList = cfg.readListEntry(DEVICESNAMES_LIST, ',' ); + qDebug("PPPData::PPPData has a accountList %s", accountList.join("---").latin1()); + qDebug("PPPData::PPPData has a deviceList %s", deviceList.join("---").latin1()); + +// if (highcount > MAX_ACCOUNTS) +// highcount = MAX_ACCOUNTS; + + // if(highcount >= 0 && defaultAccount().isEmpty()) { +// setAccountbyIndex(0); +// setDefaultAccount(accname()); +// } else if(!setAccount(defaultAccount())) setDefaultAccount(accname()); // start out with internal debugging disabled // the user is still free to specify `debug' on his own setPPPDebug(false); ::pppdVersion(&pppdVer, &pppdMod, &pppdPatch); } Config PPPData::config() { return Config("NetworkSetupPPP"); } // // save configuration // void PPPData::save() { qDebug("PPPData saving data"); writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count()); + writeConfig(GENERAL_GRP, NUMDEVICES_KEY, highcountdev + 1); QString key; QStringList keys; Config cfg = config(); + cfg.setGroup(GENERAL_GRP); + cfg.writeEntry(ACCOUNT_LIST, accountList, ',' ); + cfg.writeEntry(DEVICESNAMES_LIST, deviceList, ',' ); + for( QMap<QString,QString>::Iterator it = stringEntries.begin(); it != stringEntries.end(); ++it ){ QString val = it.data(); key = it.key(); // qDebug("saving %s -> %s", key.latin1(), val.latin1() ); keys = QStringList::split( "SEPARATOR", key ); - qDebug("group >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.latin1() ); + //qDebug("group >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.latin1() ); cfg.setGroup(keys[0]); cfg.writeEntry(keys[1], val); } for( QMap<QString,int>::Iterator it = intEntries.begin(); it != intEntries.end(); ++it ){ int val = it.data(); key = it.key(); // qDebug("saving %s -> %i", key.latin1(), val ); keys = QStringList::split( "SEPARATOR", key ); - qDebug("group >%s< key >%s< val %i", keys[0].latin1(), keys[1].latin1(), val ); + //qDebug("group >%s< key >%s< val %i", keys[0].latin1(), keys[1].latin1(), val ); cfg.setGroup(keys[0]); cfg.writeEntry(keys[1], val); } for( QMap<QString,QStringList>::Iterator it = listEntries.begin(); it != listEntries.end(); ++it ){ QStringList val = it.data(); key = it.key(); QChar sep = sepEntries[key]; // qDebug("saving %s -> %s", key.latin1(), val.join(sep).latin1() ); keys = QStringList::split( "SEPARATOR", key ); - qDebug("group >%s< key >%s<values >%s<", keys[0].latin1(), keys[1].latin1(), val.join(sep).latin1() ); cfg.setGroup(keys[0]); cfg.writeEntry(keys[1], val, sep); } } // // cancel changes // void PPPData::cancel() { stringEntries.clear(); intEntries.clear(); @@ -335,39 +346,51 @@ bool PPPData::pppdVersionMin(int ver, int mod, int patch) { int PPPData::pppdTimeout() { return readNumConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, PPPD_TIMEOUT); } void PPPData::setpppdTimeout(int n) { writeConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, n); } const QString PPPData::modemDevice() { - return readConfig (modemGroup(), MODEMDEV_KEY, devices[DEV_DEFAULT]); + return readConfig (modemGroup(), MODEMDEV_KEY, "/dev/modem" ); } +// const QString PPPData::modemName() +// { +// return readConfig(modemGroup(), MODEMNAME_KEY); +// } + +// bool PPPData::setModemName(const QString &n) { +// qDebug("Setting modem name to >%s<", n.latin1()); +// _modemName = n; +// writeConfig(cgroup, MODEMNAME_KEY, n); +// return true; //FIXME +// } + +// bool PPPData::changeModemName(const QString &n) { +// qDebug("Setting modem name to >%s<", n.latin1()); +// _modemName = n; +// writeConfig(modemGroup(), MODEMNAME_KEY, n); +// return true; //FIXME +// } + bool PPPData::setModemDevice(const QString &n) { qDebug("Setting modem dev to >%s<", n.latin1()); - bool ret = false; - for (int i = 0; devices[i]; i++) - if (devices[i] == n){ - modemDeviceGroup = i; writeConfig(modemGroup(), MODEMDEV_KEY, n); - ret = true; - } - qDebug(ret?"SUCCESS":"FAILURE"); - return ret; + return true; //FIXME } const QString PPPData::flowcontrol() { return readConfig(modemGroup(), FLOWCONTROL_KEY, "CRTSCTS"); } void PPPData::setFlowcontrol(const QString &n) { writeConfig(modemGroup(), FLOWCONTROL_KEY, n); } @@ -708,145 +731,169 @@ void PPPData::setEnter(const QString &n) { // // functions to set/return account information // //returns number of accounts int PPPData::count() const { return highcount + 1; } bool PPPData::setAccount(const QString &aname) { qDebug("setting account to >%s<", aname.latin1()); - for(int i = 0; i <= highcount; i++) { - setAccountbyIndex(i); + for ( QStringList::Iterator it = accountList.begin(); it != accountList.end(); ++it ) { + cgroup = *it; + qDebug("PPPData::setAccount %s", cgroup.latin1()); + qDebug( "iterator %s", (*it).latin1() ); if(accname() == aname) { - caccount = i; qDebug("SUCCESS"); return true; } + } qDebug("FAILURE"); return false; } - +/* bool PPPData::setAccountbyIndex(int i) { if(i >= 0 && i <= highcount) { + QString tmp; + tmp.sprintf("%s%i", ACCOUNT_GRP, i); + if (_deleted.find(tmp)!=_deleted.end()) return false; caccount = i; - cgroup.sprintf("%s%i", ACCOUNT_GRP, i); + cgroup = tmp; return true; } return false; } - +*/ bool PPPData::isUniqueAccname(const QString &n) { - int current = caccount; - for(int i=0; i <= highcount; i++) { - setAccountbyIndex(i); - if(accname() == n && i != current) { - setAccountbyIndex(current); + QString save_cgroup = cgroup; + for ( QStringList::Iterator it = accountList.begin(); it != accountList.end(); ++it ) { + cgroup = *it; + qDebug("PPPData::setAccount %s", cgroup.latin1()); + qDebug( "%s \n", (*it).latin1() ); + if(accname() == n && cgroup != save_cgroup) { + cgroup = save_cgroup; + qDebug("SUCCESS"); return false; } + } - setAccountbyIndex(current); + cgroup = save_cgroup; return true; } -bool PPPData::deleteAccount() { - //FIXME: PPPData::deleteAccount -// if(caccount < 0) +bool PPPData::isUniqueDevname(const QString &n) { + QString save_mName = _modemName; + qDebug("PPPData::isUniqueDevname checking if %s is unique", n.latin1()); + for ( QStringList::Iterator it = deviceList.begin(); it != deviceList.end(); ++it ) { + _modemName = *it; + qDebug("PPPData::isUniqueDevname %s == %s", n.latin1() , devname().latin1()); + if(devname() == n && _modemName != save_mName) { + _modemName = save_mName; + qDebug("NOT UNIQUE"); return false; + } -// QMap <QString, QString> map; -// QMap <QString, QString>::Iterator it; - -// // set all entries of the current account to "" -// map = config->entryMap(cgroup); -// it = map.begin(); -// while (it != map.end()) { -// config->writeEntry(it.key(), ""); -// it++; -// } - -// // shift the succeeding accounts -// for(int i = caccount+1; i <= highcount; i++) { -// setAccountbyIndex(i); -// map = config->entryMap(cgroup); -// it = map.begin(); -// setAccountbyIndex(i-1); -// config->setGroup(cgroup); -// while (it != map.end()) { -// config->writeEntry(it.key(), *it); -// it++; -// } -// } + } + _modemName = save_mName; + return true; +} -// // make sure the top account is cleared -// setAccountbyIndex(highcount); -// map = config->entryMap(cgroup); -// it = map.begin(); -// config->setGroup(cgroup); -// while (it.key() != QString::null) { -// config->writeEntry(it.key(), ""); -// it++; -// } -// highcount--; -// if(caccount > highcount) -// caccount = highcount; +bool PPPData::deleteAccount() { + // FIXME: check if this account exists in a config... + Config cfg = PPPData::config(); + cfg.setGroup(cgroup); + cfg.clearGroup(); + accountList.remove(cgroup); -// setAccountbyIndex(caccount); + QString key; + QStringList keys; + for( QMap<QString,QString>::Iterator it = stringEntries.begin(); + it != stringEntries.end(); ++it ){ + QString val = it.data(); + key = it.key(); + keys = QStringList::split( "SEPARATOR", key ); + if(keys[0]==cgroup){ + stringEntries.remove( it ); + qDebug("deleting >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.latin1() ); + } + } + for( QMap<QString,int>::Iterator it = intEntries.begin(); + it != intEntries.end(); ++it ){ + int val = it.data(); + key = it.key(); + keys = QStringList::split( "SEPARATOR", key ); + if(keys[0]==cgroup){ + intEntries.remove( it ); + qDebug("deleting >%s< key >%s< value >%i<", keys[0].latin1(), keys[1].latin1(), val ); + } + } + for( QMap<QString,QStringList>::Iterator it = listEntries.begin(); + it != listEntries.end(); ++it ){ + QStringList val = it.data(); + key = it.key(); + if(keys[0]==cgroup){ + listEntries.remove( it ); + sepEntries.remove( key ); + qDebug("deleting >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.join("").latin1() ); + } + } -// return true; + return true; } bool PPPData::deleteAccount(const QString &aname) { if(!setAccount(aname)) return false; deleteAccount(); return true; } int PPPData::newaccount() { qDebug("PPPData::newaccount highcount %i/%i",highcount,MAX_ACCOUNTS); // if(!config) open(); - if (highcount >= MAX_ACCOUNTS) return -1; +// if (highcount >= MAX_ACCOUNTS) return -1; - highcount++; - setAccountbyIndex(highcount); + QString tmp; + tmp.sprintf("%s%i", ACCOUNT_GRP, ++highcount); + cgroup = QString(tmp); + accountList << tmp; + qDebug("PPPData::newaccount() Group: >%s<",cgroup.latin1()); setpppdArgumentDefaults(); - qDebug("PPPData::newaccount -> %i",caccount); - return caccount; + return highcount; } -int PPPData::copyaccount(int i) { +int PPPData::copyaccount(const QString&) { // FIXME: PPPData::copyaccount // if(highcount >= MAX_ACCOUNTS) return -1; // setAccountbyIndex(i); // QMap <QString, QString> map = config->entryMap(cgroup); // QMap <QString, QString>::ConstIterator it = map.begin(); -// QString newname = i18n("%1_copy").arg(accname()); +// QString newname = QObject::tr("%1_copy").arg(accname()); // newaccount(); // while (it != map.end()) { // config->writeEntry(it.key(), *it); // it++; // } // setAccname(newname); // return caccount; } @@ -855,24 +902,25 @@ int PPPData::copyaccount(int i) { const QString PPPData::accname() { return readConfig(cgroup, NAME_KEY); } void PPPData::setAccname(const QString &n) { if(!cgroup.isNull()) { // are we manipulating the default account's name ? then change it, too. bool def = accname() == defaultAccount(); writeConfig(cgroup, NAME_KEY, n); if (def) setDefaultAccount(n); } + writeConfig(cgroup, NAME_KEY, n); } #define SEPARATOR_CHAR '&' QStringList &PPPData::phonenumbers() { readListConfig(cgroup, PHONENUMBER_KEY, phonelist, SEPARATOR_CHAR); return phonelist; } @@ -1167,24 +1215,25 @@ QStringList &PPPData::pppdArgument() { return arglist; } void PPPData::setpppdArgument(QStringList &args) { writeListConfig(cgroup, PPPDARG_KEY, args); } void PPPData::setpppdArgumentDefaults() { QStringList arg; + arg << "lcp-echo-failure 0"; setpppdArgument(arg); } // // graphing widget // void PPPData::setGraphingOptions(bool enable, // QColor bg, // QColor text, // QColor in, // QColor out) // { // if(config) { @@ -1238,29 +1287,27 @@ void PPPData::setpppdRunning(bool set) { } int PPPData::pppdError() const { return pppderror; } void PPPData::setpppdError(int err) { pppderror = err; } QString PPPData::modemGroup() { - if (modemDeviceGroup<0){ - qDebug("wrong modem %i\n using 0",modemDeviceGroup); - modemDeviceGroup = 0; //FIXME! - } - return QString("%1_%1").arg(MODEM_GRP).arg(modemDeviceGroup); + if (_modemName.isEmpty()) + _modemName = deviceList[0]; + return _modemName; } QMap<QString,QString> PPPData::getConfiguredInterfaces() { QMap<QString,QString> ifaces; Config config = PPPData::config(); config.setGroup(ACCLIST_GRP); int count = config.readNumEntry( ACCOUNTS_COUNT, -1 ); QString accGrp, dev, acc; for (int i = 0; i < count; i++){ accGrp = QString("%1_%1").arg(ACCLIST_GRP).arg(i); @@ -1291,12 +1338,158 @@ void PPPData::setConfiguredInterfaces( QMap<QString,QString> ifaces ) } /** * pppd's getword() function knows about escape characters. * If we write the username and password to the secrets file * we'll therefore have to escape back slashes. */ QString PPPData::encodeWord(const QString &s) { QString r = s; r.replace(QRegExp("\\"), "\\\\"); return r; } + +QStringList PPPData::getDevicesList() +{ + Config cfg("NetworkSetupPPP"); + cfg.setGroup("Devices_General"); + return cfg.readListEntry(DEVICES_LIST,DEVICES_LIST_SEP); +} + +QStringList PPPData::getAccountList() +{ + QStringList list; + QString save_cgroup; + save_cgroup = cgroup; + for ( QStringList::Iterator it = accountList.begin(); it != accountList.end(); ++it ) { + cgroup = *it; + list << accname(); + } + cgroup = save_cgroup; + return list; +}; + + +const QString PPPData::devname() +{ + QString tmp = readConfig(modemGroup(), MODEMNAME_KEY ); + qDebug("PPPData::devname() of %s is %s", modemGroup().latin1(), tmp.latin1()); + return tmp; +} + +void PPPData::setDevname(const QString &n) { + // if(!cgroup.isNull()) { +// // are we manipulating the default account's name ? then change it, too. +// bool def = accname() == defaultAccount(); +// writeConfig(cgroup, NAME_KEY, n); +// if (def) +// setDefaultAccount(n); +// } + writeConfig(modemGroup(), MODEMNAME_KEY, n ); +} + + +bool PPPData::setDevice(const QString &dev ) +{ + qDebug("setting device to >%s<", dev.latin1()); + QString save_mName = _modemName; + for ( QStringList::Iterator it = deviceList.begin(); it != deviceList.end(); ++it ) { + _modemName = *it; + qDebug("PPPData::setDevice %s is named %s", _modemName.latin1(), devname().latin1() ); + qDebug( "iterator %s", (*it).latin1() ); + if(devname() == dev) { + qDebug("SUCCESS"); + return true; + } + + } + _modemName = save_mName; + qDebug("FAILURE"); + return false; +} + +bool PPPData::deleteDevice() +{ + // FIXME: check if this account exists in a config... + Config cfg = PPPData::config(); + cfg.setGroup(modemGroup()); + cfg.clearGroup(); + deviceList.remove(modemGroup()); + + QString key; + QStringList keys; + for( QMap<QString,QString>::Iterator it = stringEntries.begin(); + it != stringEntries.end(); ++it ){ + QString val = it.data(); + key = it.key(); + keys = QStringList::split( "SEPARATOR", key ); + if(keys[0]==modemGroup()){ + stringEntries.remove( it ); + qDebug("deleting >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.latin1() ); + } + } + for( QMap<QString,int>::Iterator it = intEntries.begin(); + it != intEntries.end(); ++it ){ + int val = it.data(); + key = it.key(); + keys = QStringList::split( "SEPARATOR", key ); + if(keys[0]==modemGroup()){ + intEntries.remove( it ); + qDebug("deleting >%s< key >%s< value >%i<", keys[0].latin1(), keys[1].latin1(), val ); + } + } + for( QMap<QString,QStringList>::Iterator it = listEntries.begin(); + it != listEntries.end(); ++it ){ + QStringList val = it.data(); + key = it.key(); + if(keys[0]==modemGroup()){ + listEntries.remove( it ); + sepEntries.remove( key ); + qDebug("deleting >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.join("").latin1() ); + } + } + + return true; + +} + +bool PPPData::deleteDevice(const QString &dev) +{ + if(!setDevice(dev)) + return false; + + return deleteDevice(); +} + +int PPPData::newdevice() +{ + + qDebug("PPPData::newdevice highcount %i",highcountdev); + + + QString tmp; + tmp.sprintf("%s%i", MODEM_GRP, ++highcountdev); + _modemName = QString(tmp); + deviceList << tmp; + qDebug("PPPData::newdevice() Group: >%s<",cgroup.latin1()); + return highcountdev; +} + +int PPPData::copydevice(const QString&) +{ + return false; +} + + +QStringList PPPData::getDevicesNamesList() +{ + QStringList list; + QString save_mName = _modemName; + qDebug("PPPData::getDevicesNamesList has %s", deviceList.join("---").latin1()); + for ( QStringList::Iterator it = deviceList.begin(); it != deviceList.end(); ++it ) { + _modemName = *it; + qDebug("PPPData::getDevicesNamesList adding %s as %s",_modemName.latin1(), devname().latin1()); + list << devname(); + } + _modemName = save_mName; + return list; +}; diff --git a/noncore/settings/networksettings/ppp/pppdata.h b/noncore/settings/networksettings/ppp/pppdata.h index 6e1379d..d1cbeb5 100644 --- a/noncore/settings/networksettings/ppp/pppdata.h +++ b/noncore/settings/networksettings/ppp/pppdata.h @@ -55,36 +55,40 @@ class Config; // keys for config file // // groups #define GENERAL_GRP "PPP_General" #define MODEM_GRP "PPP_Modem" #define ACCOUNT_GRP "PPP_Account" #define ACCLIST_GRP "PPP_Accounts_List" //#define GRAPH_GRP "Graph" //#define WINPOS_GRP "WindowPosition" // general +#define ACCOUNT_LIST "AccountList" +#define DEVICE_LIST "DeviceList" #define DEFAULTACCOUNT_KEY "DefaultAccount" #define PPPDVERSION_KEY "pppdVersion" #define PPPDTIMEOUT_KEY "pppdTimeout" #define SHOWCLOCK_KEY "ShowClock" #define SHOWLOGWIN_KEY "ShowLogWindow" #define AUTOREDIAL_KEY "AutomaticRedial" #define DISCONNECT_KEY "DisconnectOnXServerExit" #define QUITONDISCONNECT_KEY "QuitOnDisconnect" -#define NUMACCOUNTS_KEY "NumberOfAccounts" +#define NUMACCOUNTS_KEY "HighcountAccounts" +#define NUMDEVICES_KEY "HighcountDevices" #define ID_KEY "ID" // modem +#define MODEMNAME_KEY "Modem_Name" #define MODEMDEV_KEY "Device" #define LOCKFILE_KEY "UseLockFile" #define FLOWCONTROL_KEY "FlowControl" #define SPEED_KEY "Speed" #define TIMEOUT_KEY "Timeout" #define TONEDURATION_KEY "ToneDuration" #define BUSYWAIT_KEY "BusyWait" #define INITSTR_KEY "InitString" #define INITRESP_KEY "InitResponse" #define PREINITDELAY_KEY "PreInitDelay" #define INITDELAY_KEY "InitDelay" #define NODTDETECT_KEY "NoDialToneDetection" @@ -142,58 +146,64 @@ class Config; #define TOTALCOSTS_KEY "TotalCosts" #define TOTALBYTES_KEY "TotalBytes" // pppd errors #define E_IF_TIMEOUT 1 #define E_PPPD_DIED 2 // account list #define ACCOUNTS_COUNT "Accounts_Count" #define ACOUNTS_DEV "Accounts_Modem" #define ACOUNTS_ACC "Accounts_Account" +#define DEVICESNAMES_LIST "DevicesNames_List" +#define DEVICES_LIST "Devices_List" +#define DEVICES_LIST_SEP ',' + class PPPData { public: PPPData(); ~PPPData() {}; enum { NumInitStrings = 2 }; // general functions void save(); void cancel(); + QStringList getAccountList(); + static QMap<QString,QString> getConfiguredInterfaces(); static void setConfiguredInterfaces( QMap<QString,QString> ); // function to read/write date to configuration file static Config config(); QString readConfig(const QString &, const QString &, const QString &); int readNumConfig(const QString &, const QString &, int); bool readListConfig(const QString &, const QString &, QStringList &, char sep = ','); void writeConfig(const QString &, const QString &, const QString &); void writeConfig(const QString &, const QString &, int); void writeListConfig(const QString &, const QString &, QStringList &, char sep = ','); // return the current account group QString currentGroup() { return cgroup; } QString modemGroup(); // functions to set/get general kppp info QString password(); void setPassword(const QString &); - int currentAccountID() { return caccount; }; +// int currentAccountID() { return caccount; }; const QString defaultAccount(); void setDefaultAccount(const QString &); void set_xserver_exit_disconnect(bool set); bool get_xserver_exit_disconnect(); void setPPPDebug(bool set); bool getPPPDebug(); void set_quit_on_disconnect(bool); bool quit_on_disconnect(); @@ -227,24 +237,28 @@ public: bool modemLockFile(); void setModemLockFile(bool set); int modemEscapeGuardTime(); void setModemEscapeGuardTime(int i); void setModemEscapeStr(const QString &); const QString modemEscapeStr(); void setModemEscapeResp(const QString &); const QString modemEscapeResp(); +// const QString modemName(); +// bool setModemName(const QString &); +// bool changeModemName(const QString &); + const QString modemDevice(); bool setModemDevice(const QString &); const QString flowcontrol(); void setFlowcontrol(const QString &); int modemTimeout(); void setModemTimeout(int); int modemToneDuration(); void setModemToneDuration(int); @@ -304,32 +318,33 @@ public: QString volumeOff(); void setVolumeOff(const QString &); QString volumeMedium(); void setVolumeMedium(const QString &); QString volumeHigh(); void setVolumeHigh(const QString &); // functions to set/get account information int count() const; bool setAccount(const QString &); - bool setAccountbyIndex(int); +// bool setAccountbyIndex(int); bool isUniqueAccname(const QString &); + bool isUniqueDevname(const QString &); bool deleteAccount(); bool deleteAccount(const QString &); int newaccount(); - int copyaccount(int i); + int copyaccount(const QString&); const QString accname(); void setAccname(const QString &); QStringList &phonenumbers(); const QString phonenumber(); void setPhonenumber(const QString &); const QString dialPrefix(); void setDialPrefix(const QString &); int authMethod(); @@ -400,39 +415,53 @@ public: QStringList &pppdArgument(); void setpppdArgumentDefaults(); void setpppdArgument(QStringList &); //functions to change/set the child pppd process info bool pppdRunning() const; void setpppdRunning(bool set); int pppdError() const; void setpppdError(int err); + QStringList getDevicesList(); static QString encodeWord(const QString &s); + const QString devname(); + void setDevname(const QString &); + bool setDevice(const QString& ); + bool deleteDevice(); + bool deleteDevice(const QString &); + int newdevice(); + int copydevice(const QString&); + QStringList getDevicesNamesList(); + private: //static PPPData *_data; - int modemDeviceGroup; +// int modemDeviceGroup; QString passwd; - // static Config* config; // configuration object + QString _modemName; int highcount; // index of highest account - int caccount; // index of the current account + int highcountdev; // index of highest device +// int caccount; // index of the current account QString cgroup; // name of current config group pid_t suidprocessid; // process ID of setuid child bool pppdisrunning; // pppd process // daemon int pppderror; // error encounterd running pppd int pppdVer, pppdMod, pppdPatch; // pppd version + QStringList phonelist; + QStringList accountList; + QStringList deviceList; QMap<QString,QString> stringEntries; QMap<QString,int> intEntries; QMap<QString,QStringList> listEntries; QMap<QString,QChar> sepEntries; }; #endif diff --git a/noncore/settings/networksettings/ppp/pppmodule.cpp b/noncore/settings/networksettings/ppp/pppmodule.cpp index d4c137b..af05eb7 100644 --- a/noncore/settings/networksettings/ppp/pppmodule.cpp +++ b/noncore/settings/networksettings/ppp/pppmodule.cpp @@ -1,44 +1,102 @@ +#include <errno.h> +#include <signal.h> + +#include <qpe/config.h> + +#include "modem.h" #include "pppconfig.h" #include "pppmodule.h" #include "pppdata.h" #include "interfaceinformationppp.h" #include "interfaceppp.h" +// don't polute global namespace +namespace { + /* + * If network settings is qutting and we've ppp + * devices open we need to save the pid_t the PPData + * and the interface number + */ + struct Connection { + pid_t pid; + QString device; + QString name; + }; + class InterfaceKeeper { + public: + InterfaceKeeper(); + ~InterfaceKeeper(); + + void addInterface( pid_t, const QString& pppDev, const QString& name ); + QMap<QString, Connection> interfaces()const; // will check if still available + private: + bool isAvailable( pid_t )const; + QMap<QString, Connection> m_interfaces; + }; +} + /** * Constructor, find all of the possible interfaces + * We also need to restore the state.. it could be that + * an interface was up while closing the application + * we need to be able to shut it down... */ PPPModule::PPPModule() : Module() { + InterfaceKeeper inFace; + QMap<QString,Connection> running = inFace.interfaces(); + QStringList handledInterfaceNames; + QMap<QString,QString> ifaces = PPPData::getConfiguredInterfaces(); QMap<QString,QString>::Iterator it; InterfacePPP *iface; qDebug("getting interfaces"); for( it = ifaces.begin(); it != ifaces.end(); ++it ){ - qDebug("ifaces %s", it.key().latin1()); + qDebug("ifaces %s %s", it.key().latin1(), it.data().latin1() ); iface = new InterfacePPP( 0, it.key() ); iface->setHardwareName( it.data() ); list.append( (Interface*)iface ); + + // check if (*it) is one of the running ifaces + if ( running.contains( it.data() ) ) { + qDebug("iface is running %s", it.key().latin1() ); + handledInterfaceNames << running[it.data()].device; + iface->setStatus( true ); + iface->setPPPDpid( running[it.data()].pid ); + iface->modem()->setPPPDevice( running[it.data()].device ); + iface->refresh(); + } } + + setHandledInterfaceNames( handledInterfaceNames ); } /** * Delete any interfaces that we own. */ PPPModule::~PPPModule(){ + qDebug("PPPModule::~PPPModule() " ); QMap<QString,QString> ifaces; + InterfaceKeeper keeper; Interface *i; for ( i=list.first(); i != 0; i=list.next() ){ + /* if online save the state */ + if ( i->getStatus() ) { + qDebug("Iface %s is still up", i->getHardwareName().latin1() ); + InterfacePPP* ppp = static_cast<InterfacePPP*>(i); + keeper.addInterface( ppp->pppPID(), ppp->pppDev(), ppp->getHardwareName() ); + } ifaces.insert( i->getInterfaceName(), i->getHardwareName() ); delete i; } PPPData::setConfiguredInterfaces( ifaces ); } /** * Change the current profile */ void PPPModule::setProfile(const QString &newProfile){ profile = newProfile; } @@ -60,25 +118,25 @@ QString PPPModule::getPixmapName(Interface* ){ bool PPPModule::isOwner(Interface *i){ return list.find( i ) != -1; } /** * Create, and return the WLANConfigure Module * @return QWidget* pointer to this modules configure. */ QWidget *PPPModule::configure(Interface *i){ qDebug("return ModemWidget"); PPPConfigWidget *pppconfig = new PPPConfigWidget( (InterfacePPP*)i, 0, "PPPConfig", false, - Qt::WDestructiveClose ); + Qt::WDestructiveClose | Qt::WStyle_ContextHelp); return pppconfig; } /** * Create, and return the Information Module * @return QWidget* pointer to this modules info. */ QWidget *PPPModule::information(Interface *i){ // We don't have any advanced pppd information widget yet :-D // TODO ^ return new InterfaceInformationPPP( 0, "InterfaceInformationPPP", i ); @@ -126,12 +184,67 @@ Interface *PPPModule::addNewInterface(const QString &newInterface){ */ bool PPPModule::remove(Interface *i){ return list.remove(i); } void PPPModule::possibleNewInterfaces(QMap<QString, QString> &newIfaces) { newIfaces.insert(QObject::tr("PPP") , QObject::tr("generic ppp device")); } + +namespace { + InterfaceKeeper::InterfaceKeeper( ) { + } + InterfaceKeeper::~InterfaceKeeper() { + Config cfg("ppp_plugin_keeper"); + QStringList lst = cfg.groupList(); + for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { + Connection con; + cfg.setGroup( (*it) ); + cfg.clearGroup(); + } + + for (QMap<QString, Connection>::Iterator it = m_interfaces.begin(); it != m_interfaces.end(); ++it ) { + Connection con = it.data(); + cfg.setGroup( con.name ); + cfg.writeEntry( "pid", con.pid ); + cfg.writeEntry( "device", con.device ); + } + } + void InterfaceKeeper::addInterface(pid_t pid, const QString& dev, const QString& name ) { + Connection con; + con.pid = pid; + con.device = dev; + con.name = name; + m_interfaces.insert( name, con ); + } + QMap<QString, Connection> InterfaceKeeper::interfaces()const { + Config cfg("ppp_plugin_keeper"); + QMap<QString, Connection> ifaces; + QStringList lst = cfg.groupList(); + for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { + Connection con; + cfg.setGroup( (*it) ); + con.name = (*it); + con.pid = cfg.readNumEntry("pid"); + con.device = cfg.readEntry("device"); + qDebug(" %s %s %d", con.name.latin1(), con.device.latin1(), con.pid ); + + if ( con.pid != -1 && isAvailable( con.pid ) ) + ifaces.insert( con.name, con ); + } + return ifaces; + } + bool InterfaceKeeper::isAvailable( pid_t p)const { + if (::kill(p, 0 ) == 0 || errno != ESRCH ) { + qDebug("isAvailable %d", p); + return true; + } + + qDebug("notAvailable %d", p); + return false; + } + +} diff --git a/noncore/settings/networksettings/ppp/runtests.cpp b/noncore/settings/networksettings/ppp/runtests.cpp index 83ef2ea..5548601 100644 --- a/noncore/settings/networksettings/ppp/runtests.cpp +++ b/noncore/settings/networksettings/ppp/runtests.cpp @@ -35,26 +35,24 @@ #include <pwd.h> #include <netinet/in.h> #ifdef HAVE_RESOLV_H #include <arpa/nameser.h> #include <resolv.h> #endif #ifndef _PATH_RESCONF #define _PATH_RESCONF "/etc/resolv.conf" #endif -//#include <klocale.h> -#define i18n QObject::tr #include "pppdata.h" // initial effective uid (main.cpp) extern uid_t euid; // secure pppd location (opener.cpp) extern const char* pppdPath(); // shamelessly stolen from pppd-2.3.5 /******************************************************************** * * Internal routine to decode the version.modification.patch level @@ -208,71 +206,71 @@ int runTests() { access = TRUE; fclose(f); f = NULL; } } } if(f) fclose(f); } if(!access) { QMessageBox::warning(0,"error", - i18n("You're not allowed to dial out with " + QObject::tr("You're not allowed to dial out with " "kppp.\nContact your system administrator.")); return TEST_CRITICAL; } } // Test 1: search the pppd binary const char *f = pppdPath(); if(!f) { QMessageBox::warning(0,"error", - i18n("Cannot find the PPP daemon!\n" + QObject::tr("Cannot find the PPP daemon!\n" "Make sure that pppd is installed.")); warning++; } // Test 2: check access to the pppd binary if(f) { #if 0 if(access(f, X_OK) != 0 /* && geteuid() != 0 */) { KMessageBox::warning(0, - i18n("You do not have the permission " + QObject::tr("You do not have the permission " "to start pppd!\n" "Contact your system administrator " "and ask to get access to pppd.")); return TEST_CRITICAL; } #endif if(geteuid() != 0) { struct stat st; stat(f, &st); if(st.st_uid != 0 || (st.st_mode & S_ISUID) == 0) { QMessageBox::warning(0,"error", - i18n("You don't have sufficient permission to run\n" + QObject::tr("You don't have sufficient permission to run\n" "%1\n" "Please make sure that kppp is owned by root " "and has the SUID bit set.").arg(f)); warning++; } } } // Test 5: check for existence of /etc/resolv.conf if (access(_PATH_RESCONF, R_OK) != 0) { QString file = _PATH_RESCONF" "; - QString msgstr = i18n("%1 is missing or can't be read!\n" + QString msgstr = QObject::tr("%1 is missing or can't be read!\n" "Ask your system administrator to create " "this file (can be empty) with appropriate " "read and write permissions.").arg(file); QMessageBox::warning(0, "errror", msgstr); warning ++; } if(warning == 0) return TEST_OK; else return TEST_WARNING; } |