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

pppdata.cpp

Go to the documentation of this file.
00001 /*
00002  *            kPPP: A pppd front end for the KDE project
00003  *
00004  * $Id: pppdata.cpp,v 1.15 2004/10/14 01:44:27 zecke Exp $
00005  *
00006  *            Copyright (C) 1997 Bernd Johannes Wuebben
00007  *                   wuebben@math.cornell.edu
00008  *
00009  * based on EzPPP:
00010  * Copyright (C) 1997  Jay Painter
00011  *
00012  * This program is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU Library General Public
00014  * License as published by the Free Software Foundation; either
00015  * version 2 of the License, or (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Library General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU Library General Public
00023  * License along with this program; if not, write to the Free
00024  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00025  */
00026 
00027 #include "pppdata.h"
00028 #include "runtests.h"
00029 
00030 /* OPIE */
00031 #include <opie2/odebug.h>
00032 #include <qpe/config.h>
00033 using namespace Opie::Core;
00034 
00035 /* QT */
00036 #include <qmessagebox.h>
00037 #include <qapplication.h>
00038 
00039 /* STD */
00040 #include <assert.h>
00041 
00042 #define SEPARATOR -sseepp-
00043 #define SEP QString("%1SEPARATOR%1")
00044 
00045 PPPData::PPPData()
00046     : passwd(""),
00047       _modemName(""),
00048       highcount(-1),        // start out with no entries
00049       highcountdev(-1),        // start out with no entries
00050 //      caccount(-1),         // set the current account index also
00051       suidprocessid(-1),    // process ID of setuid child
00052       pppdisrunning(false),
00053       pppderror(0)
00054 {
00055   highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1;
00056   highcountdev = readNumConfig(GENERAL_GRP, NUMDEVICES_KEY, 0) - 1;
00057   Config cfg = config();
00058   cfg.setGroup(GENERAL_GRP);
00059   accountList = cfg.readListEntry(ACCOUNT_LIST, ',' );
00060   deviceList = cfg.readListEntry(DEVICESNAMES_LIST, ',' );
00061   odebug << "PPPData::PPPData has a accountList " << accountList.join("---").latin1() << "" << oendl; 
00062   odebug << "PPPData::PPPData has a deviceList " << deviceList.join("---").latin1() << "" << oendl; 
00063 
00064 //   if (highcount > MAX_ACCOUNTS)
00065 //     highcount = MAX_ACCOUNTS;
00066 
00067  //  if(highcount >= 0 && defaultAccount().isEmpty()) {
00068 //     setAccountbyIndex(0);
00069 //     setDefaultAccount(accname());
00070 //   } else if(!setAccount(defaultAccount()))
00071   setDefaultAccount(accname());
00072 
00073   // start out with internal debugging disabled
00074   // the user is still free to specify `debug' on his own
00075   setPPPDebug(false);
00076 
00077   ::pppdVersion(&pppdVer, &pppdMod, &pppdPatch);
00078 
00079 }
00080 
00081 Config PPPData::config()
00082 {
00083     return Config("NetworkSetupPPP");
00084 }
00085 
00086 //
00087 // save configuration
00088 //
00089 void PPPData::save()
00090 {
00091     odebug << "PPPData saving data" << oendl; 
00092     writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count());
00093     writeConfig(GENERAL_GRP, NUMDEVICES_KEY, highcountdev + 1);
00094     QString key;
00095     QStringList keys;
00096     Config cfg = config();
00097     cfg.setGroup(GENERAL_GRP);
00098     cfg.writeEntry(ACCOUNT_LIST, accountList, ',' );
00099     cfg.writeEntry(DEVICESNAMES_LIST, deviceList, ',' );
00100 
00101     for( QMap<QString,QString>::Iterator it = stringEntries.begin();
00102          it != stringEntries.end(); ++it ){
00103         QString val = it.data();
00104         key = it.key();
00105 //        odebug << "saving " << key.latin1() << " -> " << val.latin1() << "" << oendl; 
00106         keys = QStringList::split( "SEPARATOR", key );
00107         //odebug << "group >" << keys[0].latin1() << "< key >" << keys[1].latin1() << "< value >" << val.latin1() << "<" << oendl; 
00108         cfg.setGroup(keys[0]);
00109         cfg.writeEntry(keys[1], val);
00110      }
00111     for( QMap<QString,int>::Iterator it = intEntries.begin();
00112          it != intEntries.end(); ++it ){
00113         int val = it.data();
00114         key = it.key();
00115 //        odebug << "saving " << key.latin1() << " -> " << val << "" << oendl; 
00116         keys = QStringList::split( "SEPARATOR", key );
00117         //odebug << "group >" << keys[0].latin1() << "< key >" << keys[1].latin1() << "< val " << val << "" << oendl; 
00118         cfg.setGroup(keys[0]);
00119         cfg.writeEntry(keys[1], val);
00120      }
00121     for( QMap<QString,QStringList>::Iterator it = listEntries.begin();
00122          it != listEntries.end(); ++it ){
00123         QStringList val = it.data();
00124         key = it.key();
00125         QChar sep = sepEntries[key];
00126 //        odebug << "saving " << key.latin1() << " -> " << val.join(sep).latin1() << "" << oendl; 
00127         keys = QStringList::split( "SEPARATOR", key );
00128         cfg.setGroup(keys[0]);
00129         cfg.writeEntry(keys[1], val, sep);
00130      }
00131 }
00132 
00133 
00134 //
00135 // cancel changes
00136 //
00137 void PPPData::cancel() {
00138     stringEntries.clear();
00139     intEntries.clear();
00140     listEntries.clear();
00141 }
00142 
00143 // functions to read/write date to configuration file
00144 QString PPPData::readConfig(const QString &group, const QString &key,
00145                             const QString &defvalue = "")
00146 {
00147 //    odebug << "PPPData::readConfig key >" << key.latin1() << "< group >" << group.latin1() << "<" << oendl; 
00148     QString idx = SEP.arg(group).arg(key);
00149     if (stringEntries.find(idx) != stringEntries.end())
00150         return stringEntries[idx];
00151     Config cfg = config();
00152     cfg.setGroup(group);
00153     return cfg.readEntry(key, defvalue);
00154 }
00155 
00156 
00157 int PPPData::readNumConfig(const QString &group, const QString &key,
00158                            int defvalue)
00159 {
00160     QString idx = SEP.arg(group).arg(key);
00161     if (intEntries.find(idx) != intEntries.end())
00162         return intEntries[idx];
00163     Config cfg = config();
00164     cfg.setGroup(group);
00165     return cfg.readNumEntry(key, defvalue);
00166 
00167 //   if (config) {
00168 //     config->setGroup(group);
00169 //     return config->readNumEntry(key, defvalue);
00170 //   } else
00171 //     return defvalue;
00172 
00173 }
00174 
00175 
00176 bool PPPData::readListConfig(const QString &group, const QString &key,
00177                              QStringList &list, char sep) {
00178   list.clear();
00179   QString idx = SEP.arg(group).arg(key);
00180   if (listEntries.find(idx) != listEntries.end()){
00181       list = listEntries[idx];
00182       return true;
00183   }
00184   Config cfg = config();
00185   cfg.setGroup(group);
00186   list = cfg.readListEntry(key, sep);
00187   if (list.count() > 0) return true;
00188   return false;
00189 
00190 //   if (config) {
00191 //     config->setGroup(group);
00192 //     list = config->readListEntry(key, sep);
00193 //     return true;
00194 //   } else
00195 //     return false;
00196 }
00197 
00198 
00199 void PPPData::writeConfig(const QString &group, const QString &key,
00200                           const QString &value) {
00201     stringEntries.insert( SEP.arg(group).arg(key), value );
00202 //   if (config) {
00203 //     config->setGroup(group);
00204 //     config->writeEntry(key, value);
00205 //   }
00206 }
00207 
00208 
00209 void PPPData::writeConfig(const QString &group, const QString &key, int value)
00210 {
00211     intEntries.insert( SEP.arg(group).arg(key), value );
00212 //   if (config) {
00213 //     config->setGroup(group);
00214 //     config->writeEntry(key, value);
00215 //   }
00216 }
00217 
00218 
00219 void PPPData::writeListConfig(const QString &group, const QString &key,
00220                               QStringList &list, char sep)
00221 {
00222     listEntries.insert( SEP.arg(group).arg(key), list );
00223     sepEntries.insert( SEP.arg(group).arg(key), sep );
00224 //   if (config) {
00225 //     config->setGroup(group);
00226 //     config->writeEntry(key, list, sep);
00227 //   }
00228 }
00229 
00230 
00231 //
00232 // functions to set/return general information
00233 //
00234 QString PPPData::password(){
00235     if ( storePassword() ) return storedPassword();
00236     else return passwd;
00237 }
00238 
00239 
00240 void PPPData::setPassword(const QString &pw) {
00241   passwd = pw;
00242 }
00243 
00244 
00245 const QString PPPData::defaultAccount() {
00246   return readConfig(GENERAL_GRP, DEFAULTACCOUNT_KEY);
00247 }
00248 
00249 
00250 void PPPData::setDefaultAccount(const QString &n) {
00251   writeConfig(GENERAL_GRP, DEFAULTACCOUNT_KEY, n);
00252 
00253   //now set the current account index to the default account
00254   setAccount(defaultAccount());
00255 }
00256 
00257 
00258 bool PPPData::get_show_clock_on_caption() {
00259   return (bool) readNumConfig(GENERAL_GRP, SHOWCLOCK_KEY, true);
00260 }
00261 
00262 
00263 void PPPData::set_show_clock_on_caption(bool set) {
00264   writeConfig(GENERAL_GRP, SHOWCLOCK_KEY, (int) set);
00265 }
00266 
00267 
00268 bool PPPData::get_xserver_exit_disconnect() {
00269   return (bool) readNumConfig(GENERAL_GRP, DISCONNECT_KEY, true);
00270 }
00271 
00272 
00273 void PPPData::setPPPDebug(bool set) {
00274   writeConfig(GENERAL_GRP, PPP_DEBUG_OPTION, (int)set);
00275 }
00276 
00277 
00278 bool PPPData::getPPPDebug() {
00279   return (bool)readNumConfig(GENERAL_GRP, PPP_DEBUG_OPTION, false);
00280 }
00281 
00282 
00283 void PPPData::set_xserver_exit_disconnect(bool set) {
00284   writeConfig(GENERAL_GRP, DISCONNECT_KEY, (int) set);
00285 }
00286 
00287 
00288 bool PPPData::quit_on_disconnect() {
00289   return (bool) readNumConfig(GENERAL_GRP, QUITONDISCONNECT_KEY, false);
00290 }
00291 
00292 
00293 void PPPData::set_quit_on_disconnect(bool set) {
00294   writeConfig(GENERAL_GRP, QUITONDISCONNECT_KEY, (int) set);
00295 }
00296 
00297 
00298 bool PPPData::get_show_log_window() {
00299   return (bool) readNumConfig (GENERAL_GRP, SHOWLOGWIN_KEY, false);
00300 }
00301 
00302 
00303 void PPPData::set_show_log_window(bool set) {
00304   writeConfig(GENERAL_GRP, SHOWLOGWIN_KEY, (int) set);
00305 }
00306 
00307 
00308 bool PPPData::automatic_redial() {
00309   return (bool) readNumConfig(GENERAL_GRP, AUTOREDIAL_KEY, FALSE);
00310 }
00311 
00312 
00313 void PPPData::set_automatic_redial(bool set) {
00314   writeConfig(GENERAL_GRP, AUTOREDIAL_KEY, (int) set);
00315 }
00316 
00317 
00318 // bool PPPData::get_iconify_on_connect() {
00319 //   return (bool) readNumConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, TRUE);
00320 // }
00321 
00322 
00323 // void PPPData::set_iconify_on_connect(bool set) {
00324 //   writeConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, (int) set);
00325 // }
00326 
00327 
00328 // bool PPPData::get_dock_into_panel() {
00329 //   return (bool) readNumConfig(GENERAL_GRP, DOCKING_KEY, false);
00330 // }
00331 
00332 
00333 // void PPPData::set_dock_into_panel(bool set) {
00334 //   writeConfig(GENERAL_GRP, DOCKING_KEY, (int) set);
00335 // }
00336 
00337 
00338 QString PPPData::pppdVersion() {
00339   return QString("%1.%2.%3").arg(pppdVer).arg(pppdMod).arg(pppdPatch);
00340 }
00341 
00342 bool PPPData::pppdVersionMin(int ver, int mod, int patch) {
00343   // check if pppd version fulfills minimum requirement
00344   return (pppdVer > ver
00345           || (pppdVer == ver && pppdMod > mod)
00346           || (pppdVer == ver && pppdMod == mod && pppdPatch >= patch));
00347 }
00348 
00349 int PPPData::pppdTimeout() {
00350   return readNumConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, PPPD_TIMEOUT);
00351 }
00352 
00353 
00354 void PPPData::setpppdTimeout(int n) {
00355   writeConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, n);
00356 }
00357 
00358 
00359 const QString PPPData::modemDevice() {
00360   return readConfig (modemGroup(), MODEMDEV_KEY, "/dev/modem" );
00361 }
00362 
00363 
00364 // const QString PPPData::modemName()
00365 // {
00366 //     return readConfig(modemGroup(), MODEMNAME_KEY);
00367 // }
00368 
00369 // bool PPPData::setModemName(const QString &n) {
00370 //     odebug << "Setting modem name to >" << n.latin1() << "<" << oendl; 
00371 //     _modemName = n;
00372 //     writeConfig(cgroup, MODEMNAME_KEY, n);
00373 //     return true; //FIXME
00374 // }
00375 
00376 // bool PPPData::changeModemName(const QString &n) {
00377 //     odebug << "Setting modem name to >" << n.latin1() << "<" << oendl; 
00378 //     _modemName = n;
00379 //     writeConfig(modemGroup(), MODEMNAME_KEY, n);
00380 //     return true; //FIXME
00381 // }
00382 
00383 bool PPPData::setModemDevice(const QString &n) {
00384     odebug << "Setting modem dev to >" << n.latin1() << "<" << oendl; 
00385     writeConfig(modemGroup(), MODEMDEV_KEY, n);
00386     return true; //FIXME
00387 }
00388 
00389 
00390 enum PPPData::FlowControl PPPData::flowcontrol() {
00391   return static_cast<FlowControl>(readNumConfig(modemGroup(), FLOWCONTROL_KEY, FlowHardware));
00392 }
00393 
00394 
00395 void PPPData::setFlowcontrol(enum FlowControl n) {
00396   writeConfig(modemGroup(), FLOWCONTROL_KEY, n);
00397 }
00398 
00399 
00400 const QString PPPData::speed() {
00401   QString s = readConfig(modemGroup(), SPEED_KEY, "57600");
00402   // undo the damage of a bug in former versions. It left an empty Speed=
00403   // entry in kppprc. kppp did set the serial port to 57600 as default but
00404   // pppd wouldn't receive the speed via the command line.
00405   if(s.toUInt() == 0)
00406     s = "57600";
00407   return s;
00408 }
00409 
00410 
00411 void PPPData::setSpeed(const QString &n) {
00412   writeConfig(modemGroup(), SPEED_KEY, n);
00413 }
00414 
00415 
00416 #if 0
00417 void PPPData::setUseCDLine(const int n) {
00418   writeConfig(modemGroup(),USECDLINE_KEY,n);
00419 }
00420 
00421 
00422 int PPPData::UseCDLine() {
00423   return  readNumConfig(modemGroup(),USECDLINE_KEY,0);
00424 }
00425 #endif
00426 
00427 const QString  PPPData::modemEscapeStr() {
00428   return readConfig(modemGroup(),ESCAPESTR_KEY,"+++");
00429 }
00430 
00431 
00432 void PPPData::setModemEscapeStr(const QString &n) {
00433   writeConfig(modemGroup(),ESCAPESTR_KEY,n);
00434 }
00435 
00436 
00437 const QString  PPPData::modemEscapeResp() {
00438   return readConfig(modemGroup(),ESCAPERESP_KEY,"OK");
00439 }
00440 
00441 
00442 void PPPData::setModemEscapeResp(const QString &n) {
00443   writeConfig(modemGroup(),ESCAPERESP_KEY,n);
00444 }
00445 
00446 
00447 int  PPPData::modemEscapeGuardTime() {
00448   return readNumConfig(modemGroup(),ESCAPEGUARDTIME_KEY,50);
00449 }
00450 
00451 
00452 void PPPData::setModemEscapeGuardTime(int n) {
00453   writeConfig(modemGroup(),ESCAPEGUARDTIME_KEY,n);
00454 }
00455 
00456 
00457 bool PPPData::modemLockFile() {
00458   return readNumConfig(modemGroup(), LOCKFILE_KEY, 1);
00459 }
00460 
00461 
00462 void PPPData::setModemLockFile(bool set) {
00463   writeConfig(modemGroup(), LOCKFILE_KEY, set);
00464 }
00465 
00466 
00467 int PPPData::modemTimeout() {
00468   return readNumConfig(modemGroup(), TIMEOUT_KEY, MODEM_TIMEOUT);
00469 }
00470 
00471 
00472 void PPPData::setModemTimeout(int n) {
00473   writeConfig(modemGroup(), TIMEOUT_KEY, n);
00474 }
00475 
00476 
00477 int PPPData::modemToneDuration() {
00478   return readNumConfig(modemGroup(), TONEDURATION_KEY,MODEM_TONEDURATION);
00479 }
00480 
00481 
00482 void PPPData::setModemToneDuration(int n) {
00483   writeConfig(modemGroup(), TONEDURATION_KEY, n);
00484 }
00485 
00486 
00487 int PPPData::busyWait() {
00488   return readNumConfig(modemGroup(), BUSYWAIT_KEY, BUSY_WAIT);
00489 }
00490 
00491 
00492 void PPPData::setbusyWait(int n) {
00493   writeConfig(modemGroup(), BUSYWAIT_KEY, n);
00494 }
00495 
00496 
00497 //
00498 //Advanced "Modem" dialog
00499 //
00500 // defaults: InitString=ATZ, InitString1="" etc.
00501 const QString PPPData::modemInitStr(int i) {
00502   assert(i >= 0 && i < NumInitStrings);
00503   if(i == 0)
00504     return readConfig(modemGroup(), INITSTR_KEY, "ATZ");
00505   else
00506     return readConfig(modemGroup(), INITSTR_KEY + QString::number(i), "");
00507 }
00508 
00509 
00510 void PPPData::setModemInitStr(int i, const QString &n) {
00511   assert(i >= 0 && i < NumInitStrings);
00512   QString k = INITSTR_KEY + (i > 0 ? QString::number(i) : QString(""));
00513   writeConfig(modemGroup(), k, n);
00514 }
00515 
00516 
00517 const QString PPPData::modemInitResp() {
00518   return readConfig(modemGroup(), INITRESP_KEY, "OK");
00519 }
00520 
00521 
00522 void PPPData::setModemInitResp(const QString &n) {
00523   writeConfig(modemGroup(), INITRESP_KEY, n);
00524 }
00525 
00526 
00527 int PPPData::modemPreInitDelay() {
00528   return readNumConfig(modemGroup(), PREINITDELAY_KEY, 50);
00529 }
00530 
00531 
00532 void PPPData::setModemPreInitDelay(int n) {
00533   writeConfig(modemGroup(), PREINITDELAY_KEY, n);
00534 }
00535 
00536 
00537 int PPPData::modemInitDelay() {
00538   return readNumConfig(modemGroup(), INITDELAY_KEY, 50);
00539 }
00540 
00541 
00542 void PPPData::setModemInitDelay(int n) {
00543   writeConfig(modemGroup(), INITDELAY_KEY, n);
00544 }
00545 
00546 QString PPPData::modemNoDialToneDetectionStr() {
00547   return readConfig(modemGroup(), NODTDETECT_KEY, "ATX3");
00548 }
00549 
00550 void PPPData::setModemNoDialToneDetectionStr(const QString &n) {
00551   writeConfig(modemGroup(), NODTDETECT_KEY, n);
00552 }
00553 
00554 const QString PPPData::modemDialStr() {
00555   return readConfig(modemGroup(), DIALSTR_KEY, "ATDT");
00556 }
00557 
00558 
00559 void PPPData::setModemDialStr(const QString &n) {
00560   writeConfig(modemGroup(), DIALSTR_KEY, n);
00561 }
00562 
00563 
00564 const QString PPPData::modemConnectResp() {
00565   return readConfig(modemGroup(), CONNECTRESP_KEY, "CONNECT");
00566 }
00567 
00568 
00569 void PPPData::setModemConnectResp(const QString &n) {
00570   writeConfig(modemGroup(), CONNECTRESP_KEY, n);
00571 }
00572 
00573 
00574 const QString PPPData::modemBusyResp() {
00575   return readConfig(modemGroup(), BUSYRESP_KEY, "BUSY");
00576 }
00577 
00578 
00579 void PPPData::setModemBusyResp(const QString &n) {
00580   writeConfig(modemGroup(), BUSYRESP_KEY, n);
00581 }
00582 
00583 
00584 const QString PPPData::modemNoCarrierResp() {
00585   return readConfig(modemGroup(), NOCARRIERRESP_KEY, "NO CARRIER");
00586 }
00587 
00588 
00589 void PPPData::setModemNoCarrierResp(const QString &n) {
00590   writeConfig(modemGroup(), NOCARRIERRESP_KEY, n);
00591 }
00592 
00593 
00594 const QString PPPData::modemNoDialtoneResp() {
00595   return readConfig(modemGroup(), NODIALTONERESP_KEY, "NO DIALTONE");
00596 }
00597 
00598 
00599 void PPPData::setModemNoDialtoneResp(const QString &n) {
00600   writeConfig(modemGroup(), NODIALTONERESP_KEY, n);
00601 }
00602 
00603 
00604 const QString PPPData::modemHangupStr() {
00605   return readConfig(modemGroup(), HANGUPSTR_KEY, "+++ATH");
00606 }
00607 
00608 void PPPData::setModemHangupStr(const QString &n) {
00609   writeConfig(modemGroup(), HANGUPSTR_KEY, n);
00610 }
00611 
00612 
00613 const QString PPPData::modemHangupResp() {
00614   return readConfig(modemGroup(), HANGUPRESP_KEY, "OK");
00615 }
00616 
00617 void PPPData::setModemHangupResp(const QString &n) {
00618   writeConfig(modemGroup(), HANGUPRESP_KEY, n);
00619 }
00620 
00621 
00622 const QString PPPData::modemAnswerStr() {
00623   return readConfig(modemGroup(), ANSWERSTR_KEY, "ATA");
00624 }
00625 
00626 
00627 QString PPPData::volumeOff() {
00628   return readConfig(modemGroup(), VOLUME_OFF, "M0L0");
00629 }
00630 
00631 
00632 void PPPData::setVolumeOff(const QString &s) {
00633   writeConfig(modemGroup(), VOLUME_OFF, s);
00634 }
00635 
00636 
00637 QString PPPData::volumeMedium() {
00638  return readConfig(modemGroup(), VOLUME_MEDIUM, "M1L1");
00639 }
00640 
00641 
00642 void PPPData::setVolumeMedium(const QString &s) {
00643   writeConfig(modemGroup(), VOLUME_MEDIUM, s);
00644 }
00645 
00646 
00647 QString PPPData::volumeHigh() {
00648   QString tmp = readConfig(modemGroup(), VOLUME_HIGH, "M1L3");
00649   if(tmp == "M1L4")
00650     tmp = "M1L3";
00651   return tmp;
00652 }
00653 
00654 
00655 void PPPData::setVolumeHigh(const QString &s) {
00656  writeConfig(modemGroup(), VOLUME_HIGH, s);
00657 }
00658 
00659 
00660 QString PPPData::volumeInitString() {
00661   QString s;
00662 
00663   switch(volume()) {
00664   case 0:
00665     s = volumeOff();
00666     break;
00667   case 1:
00668     s = volumeMedium();
00669     break;
00670   case 2:
00671     s = volumeHigh();
00672     break;
00673   default:
00674     s = volumeMedium();
00675   }
00676 
00677   return s;
00678 }
00679 
00680 
00681 int PPPData::volume() {
00682   return readNumConfig(modemGroup(), VOLUME_KEY, 1);
00683 }
00684 
00685 
00686 void PPPData::setVolume(int i) {
00687   writeConfig(modemGroup(), VOLUME_KEY, i);
00688 }
00689 
00690 int PPPData::waitForDialTone() {
00691   return readNumConfig(modemGroup(), DIALTONEWAIT_KEY, 1);
00692 }
00693 
00694 void PPPData::setWaitForDialTone(int i) {
00695   writeConfig(modemGroup(), DIALTONEWAIT_KEY, i);
00696 }
00697 
00698 void PPPData::setModemAnswerStr(const QString &n) {
00699   writeConfig(modemGroup(), ANSWERSTR_KEY, n);
00700 }
00701 
00702 
00703 const QString PPPData::modemRingResp() {
00704   return readConfig(modemGroup(), RINGRESP_KEY, "RING");
00705 }
00706 
00707 
00708 void PPPData::setModemRingResp(const QString &n) {
00709   writeConfig(modemGroup(), RINGRESP_KEY, n);
00710 }
00711 
00712 
00713 const QString PPPData::modemAnswerResp() {
00714   return readConfig(modemGroup(), ANSWERRESP_KEY, "CONNECT");
00715 }
00716 
00717 
00718 void PPPData::setModemAnswerResp(const QString &n) {
00719   writeConfig(modemGroup(), ANSWERRESP_KEY, n);
00720 }
00721 
00722 
00723 enum PPPData::LineTermination PPPData::enter(){
00724     return static_cast<PPPData::LineTermination>(readNumConfig(modemGroup(), ENTER_KEY, EndCR));
00725 }
00726 
00727 
00728 void PPPData::setEnter(enum PPPData::LineTermination n) {
00729   writeConfig(modemGroup(), ENTER_KEY, n);
00730 }
00731 
00732 
00733 //
00734 // functions to set/return account information
00735 //
00736 
00737 //returns number of accounts
00738 int PPPData::count() const {
00739   return highcount + 1;
00740 }
00741 
00742 
00743 bool PPPData::setAccount(const QString &aname) {
00744     odebug << "setting account to >" << aname.latin1() << "<" << oendl; 
00745     for ( QStringList::Iterator it = accountList.begin(); it != accountList.end(); ++it ) {
00746         cgroup = *it;
00747         odebug << "PPPData::setAccount " << cgroup.latin1() << "" << oendl; 
00748         odebug << "iterator " << (*it).latin1() << "" << oendl; 
00749         if(accname() == aname) {
00750             odebug << "SUCCESS" << oendl; 
00751             return true;
00752         }
00753 
00754     }
00755     odebug << "FAILURE" << oendl; 
00756     return false;
00757 }
00758 
00759 /*
00760 bool PPPData::setAccountbyIndex(int i) {
00761   if(i >= 0 && i <= highcount) {
00762     QString tmp;
00763     tmp.sprintf("%s%i", ACCOUNT_GRP, i);
00764     if (_deleted.find(tmp)!=_deleted.end()) return false;
00765     caccount = i;
00766     cgroup = tmp;
00767     return true;
00768   }
00769   return false;
00770 }
00771 */
00772 
00773 bool PPPData::isUniqueAccname(const QString &n) {
00774   QString save_cgroup = cgroup;
00775   for ( QStringList::Iterator it = accountList.begin(); it != accountList.end(); ++it ) {
00776       cgroup = *it;
00777       odebug << "PPPData::setAccount " << cgroup.latin1() << "" << oendl; 
00778       odebug << "" << (*it).latin1() << " \n" << oendl; 
00779       if(accname() == n && cgroup != save_cgroup) {
00780           cgroup = save_cgroup;
00781           odebug << "SUCCESS" << oendl; 
00782           return false;
00783       }
00784 
00785   }
00786   cgroup = save_cgroup;
00787   return true;
00788 }
00789 
00790 
00791 bool PPPData::isUniqueDevname(const QString &n) {
00792     QString save_mName = _modemName;
00793     odebug << "PPPData::isUniqueDevname checking if " << n.latin1() << " is unique" << oendl; 
00794     for ( QStringList::Iterator it = deviceList.begin(); it != deviceList.end(); ++it ) {
00795         _modemName = *it;
00796         odebug << "PPPData::isUniqueDevname " << n.latin1() << " == " << devname().latin1() << "" << oendl; 
00797         if(devname() == n && _modemName != save_mName) {
00798             _modemName = save_mName;
00799             odebug << "NOT UNIQUE" << oendl; 
00800             return false;
00801         }
00802 
00803     }
00804     _modemName = save_mName;
00805     return true;
00806 }
00807 
00808 
00809 bool PPPData::deleteAccount() {
00810     // FIXME: check if this account exists in a config...
00811     Config cfg = PPPData::config();
00812     cfg.setGroup(cgroup);
00813     cfg.clearGroup();
00814     accountList.remove(cgroup);
00815 
00816     QString key;
00817     QStringList keys;
00818     for( QMap<QString,QString>::Iterator it = stringEntries.begin();
00819          it != stringEntries.end(); ++it ){
00820         QString val = it.data();
00821         key = it.key();
00822         keys = QStringList::split( "SEPARATOR", key );
00823         if(keys[0]==cgroup){
00824             stringEntries.remove( it );
00825             odebug << "deleting >" << keys[0].latin1() << "< key >" << keys[1].latin1() << "< value >" << val.latin1() << "<" << oendl; 
00826         }
00827     }
00828     for( QMap<QString,int>::Iterator it = intEntries.begin();
00829          it != intEntries.end(); ++it ){
00830         int val = it.data();
00831         key = it.key();
00832         keys = QStringList::split( "SEPARATOR", key );
00833         if(keys[0]==cgroup){
00834             intEntries.remove( it );
00835             odebug << "deleting >" << keys[0].latin1() << "< key >" << keys[1].latin1() << "< value >" << val << "<" << oendl; 
00836         }
00837     }
00838     for( QMap<QString,QStringList>::Iterator it = listEntries.begin();
00839          it != listEntries.end(); ++it ){
00840         QStringList val = it.data();
00841         key = it.key();
00842         if(keys[0]==cgroup){
00843             listEntries.remove( it );
00844             sepEntries.remove( key );
00845             odebug << "deleting >" << keys[0].latin1() << "< key >" << keys[1].latin1() << "< value >" << val.join("").latin1() << "<" << oendl; 
00846         }
00847     }
00848 
00849     return true;
00850 }
00851 
00852 
00853 bool PPPData::deleteAccount(const QString &aname) {
00854   if(!setAccount(aname))
00855     return false;
00856 
00857   deleteAccount();
00858 
00859   return true;
00860 }
00861 
00862 
00863 int PPPData::newaccount() {
00864 
00865     odebug << "PPPData::newaccount highcount " << highcount << "/" << MAX_ACCOUNTS << "" << oendl; 
00866 //  if(!config) open();
00867 //  if (highcount >= MAX_ACCOUNTS) return -1;
00868 
00869 
00870   QString tmp;
00871   tmp.sprintf("%s%i", ACCOUNT_GRP, ++highcount);
00872   cgroup = QString(tmp);
00873   accountList << tmp;
00874   odebug << "PPPData::newaccount() Group: >" << cgroup.latin1() << "<" << oendl; 
00875   setpppdArgumentDefaults();
00876   return highcount;
00877 }
00878 
00879 int PPPData::copyaccount(const QString&) {
00880 // FIXME: PPPData::copyaccount
00881 //  if(highcount >= MAX_ACCOUNTS)
00882     return -1;
00883 
00884 //   setAccountbyIndex(i);
00885 
00886 //    QMap <QString, QString> map = config->entryMap(cgroup);
00887 //    QMap <QString, QString>::ConstIterator it = map.begin();
00888 
00889 //    QString newname = QObject::tr("%1_copy").arg(accname());
00890 
00891 //    newaccount();
00892 
00893 //    while (it != map.end()) {
00894 //      config->writeEntry(it.key(), *it);
00895 //      it++;
00896 //    }
00897 
00898 //   setAccname(newname);
00899 
00900 //   return caccount;
00901 }
00902 
00903 
00904 const QString PPPData::accname() {
00905   return readConfig(cgroup, NAME_KEY);
00906 }
00907 
00908 void PPPData::setAccname(const QString &n) {
00909   if(!cgroup.isNull()) {
00910     // are we manipulating the default account's name ? then change it, too.
00911     bool def = accname() == defaultAccount();
00912     writeConfig(cgroup, NAME_KEY, n);
00913     if (def)
00914       setDefaultAccount(n);
00915   }
00916   writeConfig(cgroup, NAME_KEY, n);
00917 }
00918 
00919 
00920 #define SEPARATOR_CHAR '&'
00921 QStringList &PPPData::phonenumbers() {
00922 
00923   readListConfig(cgroup, PHONENUMBER_KEY, phonelist, SEPARATOR_CHAR);
00924   return phonelist;
00925 
00926 }
00927 
00928 
00929 const QString PPPData::phonenumber() {
00930   return readConfig(cgroup, PHONENUMBER_KEY);
00931 }
00932 
00933 
00934 void PPPData::setPhonenumber(const QString &n) {
00935   writeConfig(cgroup, PHONENUMBER_KEY, n);
00936 }
00937 
00938 
00939 const QString PPPData::dialPrefix() {
00940   return readConfig(cgroup, DIAL_PREFIX_KEY, "");
00941 }
00942 
00943 
00944 void PPPData::setDialPrefix(const QString &s) {
00945   writeConfig(cgroup, DIAL_PREFIX_KEY, s);
00946 }
00947 
00948 
00949 int PPPData::authMethod() {
00950     return readNumConfig(cgroup, AUTH_KEY, 0);
00951 }
00952 
00953 
00954 void PPPData::setAuthMethod(int value) {
00955   writeConfig(cgroup, AUTH_KEY, value);
00956 }
00957 
00958 
00959 const QString  PPPData::storedUsername() {
00960   return readConfig(cgroup, STORED_USERNAME_KEY, "");
00961 }
00962 
00963 
00964 void PPPData::setStoredUsername(const QString &b) {
00965   writeConfig(cgroup, STORED_USERNAME_KEY, b);
00966 }
00967 
00968 
00969 const QString  PPPData::storedPassword() {
00970     odebug << "getting stored pw" << oendl; 
00971     odebug << "g " << cgroup.latin1() << "" << oendl; 
00972     odebug << "k " << STORED_PASSWORD_KEY << "" << oendl; 
00973   return readConfig(cgroup, STORED_PASSWORD_KEY, "");
00974 }
00975 
00976 
00977 void PPPData::setStoredPassword(const QString &b) {
00978   writeConfig(cgroup, STORED_PASSWORD_KEY, b);
00979 }
00980 
00981 
00982 bool PPPData::storePassword() {
00983   return (bool)readNumConfig(cgroup, STORE_PASSWORD_KEY, 1);
00984 }
00985 
00986 
00987 const QString PPPData::command_before_connect() {
00988   return readConfig(cgroup, BEFORE_CONNECT_KEY);
00989 }
00990 
00991 
00992 void PPPData::setCommand_before_connect(const QString &n) {
00993   writeConfig(cgroup, BEFORE_CONNECT_KEY, n);
00994 }
00995 
00996 
00997 void PPPData::setStorePassword(bool b) {
00998   writeConfig(cgroup, STORE_PASSWORD_KEY, (int)b);
00999 }
01000 
01001 
01002 const QString PPPData::command_on_connect() {
01003   return readConfig(cgroup, COMMAND_KEY);
01004 }
01005 
01006 
01007 void PPPData::setCommand_on_connect(const QString &n) {
01008   writeConfig(cgroup, COMMAND_KEY, n);
01009 }
01010 
01011 
01012 const QString PPPData::command_on_disconnect() {
01013   return readConfig(cgroup, DISCONNECT_COMMAND_KEY);
01014 }
01015 
01016 
01017 void PPPData::setCommand_on_disconnect(const QString &n) {
01018   writeConfig(cgroup, DISCONNECT_COMMAND_KEY, n);
01019 }
01020 
01021 
01022 const QString PPPData::command_before_disconnect() {
01023   return readConfig(cgroup, BEFORE_DISCONNECT_KEY);
01024 }
01025 
01026 
01027 void PPPData::setCommand_before_disconnect(const QString &n) {
01028   writeConfig(cgroup, BEFORE_DISCONNECT_KEY, n);
01029 }
01030 
01031 
01032 const QString PPPData::ipaddr() {
01033   return readConfig(cgroup, IPADDR_KEY);
01034 }
01035 
01036 
01037 void PPPData::setIpaddr(const QString &n) {
01038   writeConfig(cgroup, IPADDR_KEY, n);
01039 }
01040 
01041 
01042 const QString PPPData::subnetmask() {
01043   return readConfig(cgroup, SUBNETMASK_KEY);
01044 }
01045 
01046 
01047 void PPPData::setSubnetmask(const QString &n) {
01048   writeConfig(cgroup, SUBNETMASK_KEY, n);
01049 }
01050 
01051 
01052 bool PPPData::autoname() {
01053   return (bool) readNumConfig(cgroup, AUTONAME_KEY, false);
01054 }
01055 
01056 
01057 void PPPData::setAutoname(bool set) {
01058   writeConfig(cgroup, AUTONAME_KEY, (int) set);
01059 }
01060 
01061 
01062 bool PPPData::AcctEnabled() {
01063   return (bool) readNumConfig(cgroup, ACCTENABLED_KEY, false);
01064 }
01065 
01066 
01067 void PPPData::setAcctEnabled(bool set) {
01068   writeConfig(cgroup, ACCTENABLED_KEY, (int) set);
01069 }
01070 
01071 
01072 // int PPPData::VolAcctEnabled() {
01073 //   return readNumConfig(cgroup, VOLACCTENABLED_KEY, 0);
01074 // }
01075 
01076 
01077 // void PPPData::setVolAcctEnabled(int set) {
01078 //   writeConfig(cgroup, VOLACCTENABLED_KEY, set);
01079 // }
01080 
01081 
01082 const QString PPPData::gateway() {
01083   return readConfig(cgroup, GATEWAY_KEY);
01084 }
01085 
01086 
01087 void PPPData::setGateway(const QString &n ) {
01088   writeConfig(cgroup, GATEWAY_KEY, n);
01089 }
01090 
01091 
01092 bool PPPData::defaultroute() {
01093   // default route is by default 'on'.
01094   return (bool) readNumConfig(cgroup, DEFAULTROUTE_KEY, true);
01095 }
01096 
01097 
01098 void PPPData::setDefaultroute(bool set) {
01099   writeConfig(cgroup, DEFAULTROUTE_KEY, (int) set);
01100 }
01101 
01102 
01103 bool PPPData::autoDNS() {
01104   bool set = (bool) readNumConfig(cgroup, AUTODNS_KEY, true);
01105   return (set && pppdVersionMin(2, 3, 7));
01106 }
01107 
01108 
01109 void PPPData::setAutoDNS(bool set) {
01110   writeConfig(cgroup, AUTODNS_KEY, (int) set);
01111 }
01112 
01113 
01114 void PPPData::setExDNSDisabled(bool set) {
01115   writeConfig(cgroup, EXDNSDISABLED_KEY, (int) set);
01116 }
01117 
01118 
01119 bool PPPData::exDNSDisabled() {
01120   return (bool) readNumConfig(cgroup, EXDNSDISABLED_KEY,0);
01121 }
01122 
01123 
01124 QStringList &PPPData::dns() {
01125   static QStringList dnslist;
01126 
01127   readListConfig(cgroup, DNS_KEY, dnslist);
01128   while(dnslist.count() > MAX_DNS_ENTRIES)
01129     dnslist.remove(dnslist.last());
01130 
01131   return dnslist;
01132 }
01133 
01134 
01135 void PPPData::setDns(QStringList &list) {
01136   writeListConfig(cgroup, DNS_KEY, list);
01137 }
01138 
01139 
01140 const QString PPPData::domain() {
01141   return readConfig(cgroup, DOMAIN_KEY);
01142 }
01143 
01144 
01145 void PPPData::setDomain(const QString &n ) {
01146   writeConfig(cgroup, DOMAIN_KEY, n);
01147 }
01148 
01149 
01150 QStringList &PPPData::scriptType() {
01151   static QStringList typelist;
01152 
01153   readListConfig(cgroup, SCRIPTCOM_KEY, typelist);
01154   while(typelist.count() > MAX_SCRIPT_ENTRIES)
01155     typelist.remove(typelist.last());
01156 
01157   return typelist;
01158 }
01159 
01160 
01161 void PPPData::setScriptType(QStringList &list) {
01162   writeListConfig(cgroup, SCRIPTCOM_KEY, list);
01163 }
01164 
01165 
01166 QStringList &PPPData::script() {
01167   static QStringList scriptlist;
01168 
01169   readListConfig(cgroup, SCRIPTARG_KEY, scriptlist);
01170   while(scriptlist.count() > MAX_SCRIPT_ENTRIES)
01171     scriptlist.remove(scriptlist.last());
01172 
01173   return scriptlist;
01174 }
01175 
01176 
01177 void PPPData::setScript(QStringList &list) {
01178   writeListConfig(cgroup, SCRIPTARG_KEY, list);
01179 }
01180 
01181 
01182 // const QString PPPData::accountingFile() {
01183 //   return readConfig(cgroup, ACCTFILE_KEY);
01184 // }
01185 
01186 
01187 // void PPPData::setAccountingFile(const QString &n) {
01188 //   writeConfig(cgroup, ACCTFILE_KEY, n);
01189 // }
01190 
01191 
01192 // const QString PPPData::totalCosts() {
01193 //   return readConfig(cgroup, TOTALCOSTS_KEY);
01194 // }
01195 
01196 
01197 // void PPPData::setTotalCosts(const QString &n) {
01198 //   writeConfig(cgroup, TOTALCOSTS_KEY, n);
01199 // }
01200 
01201 
01202 // int PPPData::totalBytes() {
01203 //   return readNumConfig(cgroup, TOTALBYTES_KEY, 0);
01204 // }
01205 
01206 // void PPPData::setTotalBytes(int n) {
01207 //   writeConfig(cgroup, TOTALBYTES_KEY, n);
01208 // }
01209 
01210 
01211 QStringList &PPPData::pppdArgument() {
01212   static QStringList arglist;
01213 
01214   while(arglist.count() > MAX_PPPD_ARGUMENTS)
01215     arglist.remove(arglist.last());
01216   readListConfig(cgroup, PPPDARG_KEY, arglist);
01217 
01218   return arglist;
01219 }
01220 
01221 
01222 void PPPData::setpppdArgument(QStringList &args) {
01223   writeListConfig(cgroup, PPPDARG_KEY, args);
01224 }
01225 
01226 
01227 void PPPData::setpppdArgumentDefaults() {
01228   QStringList arg;
01229   arg << "lcp-echo-failure 0";
01230   setpppdArgument(arg);
01231 }
01232 
01233 
01234 // // graphing widget
01235 // void PPPData::setGraphingOptions(bool enable,
01236 //                               QColor bg,
01237 //                               QColor text,
01238 //                               QColor in,
01239 //                               QColor out)
01240 // {
01241 //   if(config) {
01242 //     config->setGroup(GRAPH_GRP);
01243 //     config->writeEntry(GENABLED, enable);
01244 // //     config->writeEntry(GCOLOR_BG, bg);
01245 // //     config->writeEntry(GCOLOR_TEXT, text);
01246 // //     config->writeEntry(GCOLOR_IN, in);
01247 // //     config->writeEntry(GCOLOR_OUT, out);
01248 //   }
01249 // }
01250 
01251 // void PPPData::graphingOptions(bool &enable,
01252 //                            QColor &bg,
01253 //                            QColor &text,
01254 //                            QColor &in,
01255 //                            QColor &out)
01256 // {
01257 //   QColor c;
01258 
01259 //   if(config) {
01260 //     config->setGroup(GRAPH_GRP);
01261 //     enable = config->readBoolEntry(GENABLED, true);
01262 //     bg = Qt::white;
01263 //     //bg = config->readColorEntry(GCOLOR_BG, &c);
01264 //     text = Qt::black;
01265 //     //text = config->readColorEntry(GCOLOR_TEXT, &c);
01266 //     in = Qt::blue;
01267 //     //in = config->readColorEntry(GCOLOR_IN, &c);
01268 //     out = Qt::red;
01269 //     //out = config->readColorEntry(GCOLOR_OUT, &c);
01270 //   }
01271 // }
01272 
01273 
01274 // bool PPPData::graphingEnabled() {
01275 //   return (bool) readNumConfig(GRAPH_GRP, GENABLED, true);
01276 // }
01277 
01278 
01279 
01280 //
01281 //functions to change/set the child pppd process info
01282 //
01283 bool PPPData::pppdRunning() const {
01284   return pppdisrunning;
01285 }
01286 
01287 void PPPData::setpppdRunning(bool set) {
01288   pppdisrunning = set;
01289 }
01290 
01291 int PPPData::pppdError() const {
01292   return pppderror;
01293 }
01294 
01295 void PPPData::setpppdError(int err) {
01296   pppderror = err;
01297 }
01298 
01299 QString PPPData::modemGroup()
01300 {
01301     if (_modemName.isEmpty())
01302         _modemName = deviceList[0];
01303    return _modemName;
01304 }
01305 
01306 
01307 QMap<QString,QString> PPPData::getConfiguredInterfaces()
01308 {
01309     QMap<QString,QString> ifaces;
01310     Config config = PPPData::config();
01311     config.setGroup(ACCLIST_GRP);
01312     int count = config.readNumEntry( ACCOUNTS_COUNT, -1 );
01313     QString accGrp, dev, acc;
01314     for (int i = 0; i < count; i++){
01315         accGrp = QString("%1_%1").arg(ACCLIST_GRP).arg(i);
01316         config.setGroup(accGrp);
01317         dev = config.readEntry( ACOUNTS_DEV, "error" );
01318         acc = config.readEntry( ACOUNTS_ACC, "error" );
01319         ifaces.insert( dev, acc );
01320     }
01321 
01322     return ifaces;
01323 }
01324 
01325 void PPPData::setConfiguredInterfaces( QMap<QString,QString> ifaces )
01326 {
01327     QMap<QString,QString>::Iterator it;
01328     int i = 0;
01329     Config cfg = config();
01330     for( it = ifaces.begin(); it != ifaces.end(); ++it ){
01331         cfg.setGroup(QString("%1_%1").arg(ACCLIST_GRP).arg(i++));
01332         cfg.writeEntry( ACOUNTS_DEV, it.key() );
01333         cfg.writeEntry( ACOUNTS_ACC, it.data() );
01334         odebug << "I " << i << "" << oendl; 
01335     }
01336     cfg.setGroup( ACCLIST_GRP );
01337     odebug << "saved " << i << " account settings" << oendl; 
01338     cfg.writeEntry( ACCOUNTS_COUNT, i );
01339 
01340 }
01341 
01347 QString PPPData::encodeWord(const QString &s) {
01348     QString r = s;
01349     r.replace(QRegExp("\\"), "\\\\");
01350     return r;
01351 }
01352 
01353 QStringList PPPData::getDevicesList()
01354 {
01355      Config cfg("NetworkSetupPPP");
01356      cfg.setGroup("Devices_General");
01357      return cfg.readListEntry(DEVICES_LIST,DEVICES_LIST_SEP);
01358 }
01359 
01360 QStringList PPPData::getAccountList()
01361 {
01362     QStringList list;
01363     QString save_cgroup;
01364     save_cgroup = cgroup;
01365     for ( QStringList::Iterator it = accountList.begin(); it != accountList.end(); ++it ) {
01366         cgroup = *it;
01367         list << accname();
01368     }
01369     cgroup = save_cgroup;
01370     return list;
01371 };
01372 
01373 
01374 const QString PPPData::devname()
01375 {
01376     QString tmp = readConfig(modemGroup(), MODEMNAME_KEY );
01377     odebug << "PPPData::devname() of " << modemGroup().latin1() << " is " << tmp.latin1() << "" << oendl; 
01378     return tmp;
01379 }
01380 
01381 void PPPData::setDevname(const QString &n) {
01382   // if(!cgroup.isNull()) {
01383 //     // are we manipulating the default account's name ? then change it, too.
01384 //     bool def = accname() == defaultAccount();
01385 //     writeConfig(cgroup, NAME_KEY, n);
01386 //     if (def)
01387 //       setDefaultAccount(n);
01388 //   }
01389     writeConfig(modemGroup(), MODEMNAME_KEY, n );
01390 }
01391 
01392 
01393 bool PPPData::setDevice(const QString &dev )
01394 {
01395     odebug << "setting device to >" << dev.latin1() << "<" << oendl; 
01396     QString save_mName = _modemName;
01397     for ( QStringList::Iterator it = deviceList.begin(); it != deviceList.end(); ++it ) {
01398         _modemName = *it;
01399         odebug << "PPPData::setDevice " << _modemName.latin1() << " is named " << devname().latin1() << "" << oendl; 
01400         odebug << "iterator " << (*it).latin1() << "" << oendl; 
01401         if(devname() == dev) {
01402             odebug << "SUCCESS" << oendl; 
01403             return true;
01404         }
01405 
01406     }
01407     _modemName = save_mName;
01408     odebug << "FAILURE" << oendl; 
01409     return false;
01410 }
01411 
01412 bool PPPData::deleteDevice()
01413 {
01414     // FIXME: check if this account exists in a config...
01415     Config cfg = PPPData::config();
01416     cfg.setGroup(modemGroup());
01417     cfg.clearGroup();
01418     deviceList.remove(modemGroup());
01419 
01420     QString key;
01421     QStringList keys;
01422     for( QMap<QString,QString>::Iterator it = stringEntries.begin();
01423          it != stringEntries.end(); ++it ){
01424         QString val = it.data();
01425         key = it.key();
01426         keys = QStringList::split( "SEPARATOR", key );
01427         if(keys[0]==modemGroup()){
01428             stringEntries.remove( it );
01429             odebug << "deleting >" << keys[0].latin1() << "< key >" << keys[1].latin1() << "< value >" << val.latin1() << "<" << oendl; 
01430         }
01431     }
01432     for( QMap<QString,int>::Iterator it = intEntries.begin();
01433          it != intEntries.end(); ++it ){
01434         int val = it.data();
01435         key = it.key();
01436         keys = QStringList::split( "SEPARATOR", key );
01437         if(keys[0]==modemGroup()){
01438             intEntries.remove( it );
01439             odebug << "deleting >" << keys[0].latin1() << "< key >" << keys[1].latin1() << "< value >" << val << "<" << oendl; 
01440         }
01441     }
01442     for( QMap<QString,QStringList>::Iterator it = listEntries.begin();
01443          it != listEntries.end(); ++it ){
01444         QStringList val = it.data();
01445         key = it.key();
01446         if(keys[0]==modemGroup()){
01447             listEntries.remove( it );
01448             sepEntries.remove( key );
01449             odebug << "deleting >" << keys[0].latin1() << "< key >" << keys[1].latin1() << "< value >" << val.join("").latin1() << "<" << oendl; 
01450         }
01451     }
01452 
01453     return true;
01454 
01455 }
01456 
01457 bool PPPData::deleteDevice(const QString &dev)
01458 {
01459   if(!setDevice(dev))
01460     return false;
01461 
01462   return deleteDevice();
01463 }
01464 
01465 int PPPData::newdevice()
01466 {
01467 
01468     odebug << "PPPData::newdevice highcount " << highcountdev << "" << oendl; 
01469 
01470 
01471   QString tmp;
01472   tmp.sprintf("%s%i", MODEM_GRP, ++highcountdev);
01473   _modemName = QString(tmp);
01474   deviceList << tmp;
01475   odebug << "PPPData::newdevice() Group: >" << cgroup.latin1() << "<" << oendl; 
01476   return highcountdev;
01477 }
01478 
01479 int PPPData::copydevice(const QString&)
01480 {
01481     return false;
01482 }
01483 
01484 
01485 QStringList PPPData::getDevicesNamesList()
01486 {
01487     QStringList list;
01488     QString save_mName = _modemName;
01489     odebug << "PPPData::getDevicesNamesList has  " << deviceList.join("---").latin1() << "" << oendl; 
01490     for ( QStringList::Iterator it = deviceList.begin(); it != deviceList.end(); ++it ) {
01491         _modemName = *it;
01492         odebug << "PPPData::getDevicesNamesList adding " << _modemName.latin1() << " as " << devname().latin1() << "" << oendl; 
01493         list << devname();
01494     }
01495     _modemName = save_mName;
01496     return list;
01497 };

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