Diffstat (limited to 'noncore/settings/networksettings/ppp/pppdata.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/pppdata.cpp | 229 |
1 files changed, 117 insertions, 112 deletions
diff --git a/noncore/settings/networksettings/ppp/pppdata.cpp b/noncore/settings/networksettings/ppp/pppdata.cpp index f2386fc..646facd 100644 --- a/noncore/settings/networksettings/ppp/pppdata.cpp +++ b/noncore/settings/networksettings/ppp/pppdata.cpp @@ -29,61 +29,58 @@ #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> -PPPData gpppdata; +PPPData *PPPData::_data = 0; +Config *PPPData::config = 0; +PPPData* PPPData::data() +{ + if (!_data){ + qDebug("PPPData::data() creates new Instance"); + _data = new PPPData(); + } + if (!_data->config){ + qDebug("PPPData::data() opens conffile"); + _data->open(); + } + return _data; +} PPPData::PPPData() - : config(0L), + : //config(0L), highcount(-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) { } // // open configuration file // bool PPPData::open() { - - config = new Config("NetworkSetup"); - /* - config = kapp->config(); - - if (config->getConfigState() == KConfig::NoAccess) { - KMessageBox::error(0L, - i18n("The application-specific config file could not " - "be opened in either read-write or read-only mode.\n" - "The superuser might have to change its ownership " - "by issuing the following command in your home directory:\n" - "chown {YourUsername} .kde/share/config/kppprc"), - kapp->name()); - return false; - } - - // don't expand shell variables - config->setDollarExpansion(false); - */ + qDebug("opening configfile NetworkSetupPPP"); + if (config) return true; + config = new Config("NetworkSetupPPP"); 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())) setDefaultAccount(accname()); @@ -95,54 +92,61 @@ bool PPPData::open() { return true; } // // save configuration // void PPPData::save() { if (config) { writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count()); -// config->sync(); + delete config; + config = 0; + qDebug("worte confi NetworkSetupPPP"); + } + if (_data){ + delete _data; + _data = 0; } } // // cancel changes // void PPPData::cancel() { // if (config) { // config->rollback(); // config->reparseConfiguration(); // } } -// currently differentiates between READWRITE and NONE only -int PPPData::access() const { +// // currently differentiates between READWRITE and NONE only +// int PPPData::access() const { - return 0;//config->getConfigState(); -} +// return 1;//config->getConfigState(); +// } // functions to read/write date to configuration file QString PPPData::readConfig(const QString &group, const QString &key, const QString &defvalue = "") { +// qDebug("PPPData::readConfig key >%s< group >%s<",key.latin1(), group.latin1()); if (config) { config->setGroup(group); return config->readEntry(key, defvalue); } else return defvalue; } int PPPData::readNumConfig(const QString &group, const QString &key, int defvalue) { if (config) { config->setGroup(group); @@ -709,32 +713,32 @@ bool PPPData::isUniqueAccname(const QString &n) { setAccountbyIndex(i); if(accname() == n && i != current) { setAccountbyIndex(current); return false; } } setAccountbyIndex(current); return true; } bool PPPData::deleteAccount() { - if(caccount < 0) - return false; + //FIXME: +// if(caccount < 0) + return false; // QMap <QString, QString> map; // QMap <QString, QString>::Iterator it; - // set all entries of the current account to "" -// tille: do not handle the accounts here... (?) +// // 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(); @@ -747,98 +751,99 @@ bool PPPData::deleteAccount() { // } // // 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; +// highcount--; +// if(caccount > highcount) +// caccount = highcount; - setAccountbyIndex(caccount); +// setAccountbyIndex(caccount); - return true; +// return true; } bool PPPData::deleteAccount(const QString &aname) { if(!setAccount(aname)) return false; deleteAccount(); return true; } int PPPData::newaccount() { - if(!config || highcount >= MAX_ACCOUNTS) - return -1; + qDebug("PPPData::newaccount highcount %i/%i",highcount,MAX_ACCOUNTS); + if(!config) open(); + if (highcount >= MAX_ACCOUNTS) return -1; highcount++; setAccountbyIndex(highcount); setpppdArgumentDefaults(); - + qDebug("PPPData::newaccount -> %i",caccount); return caccount; } int PPPData::copyaccount(int i) { - if(highcount >= MAX_ACCOUNTS) +// if(highcount >= MAX_ACCOUNTS) return -1; - setAccountbyIndex(i); +// setAccountbyIndex(i); -// QMap <QString, QString> map = config->entryMap(cgroup); -// QMap <QString, QString>::ConstIterator it = map.begin(); +// QMap <QString, QString> map = config->entryMap(cgroup); +// QMap <QString, QString>::ConstIterator it = map.begin(); - QString newname = i18n("%1_copy").arg(accname()); +// QString newname = i18n("%1_copy").arg(accname()); - newaccount(); +// newaccount(); -// while (it != map.end()) { -// config->writeEntry(it.key(), *it); -// it++; -// } +// while (it != map.end()) { +// config->writeEntry(it.key(), *it); +// it++; +// } - setAccname(newname); +// setAccname(newname); - return caccount; +// return caccount; } 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); } } -#define SEPARATOR_CHAR ':' +#define SEPARATOR_CHAR '&' QStringList &PPPData::phonenumbers() { readListConfig(cgroup, PHONENUMBER_KEY, phonelist, SEPARATOR_CHAR); return phonelist; } const QString PPPData::phonenumber() { return readConfig(cgroup, PHONENUMBER_KEY); } @@ -1002,25 +1007,25 @@ bool PPPData::defaultroute() { // default route is by default 'on'. return (bool) readNumConfig(cgroup, DEFAULTROUTE_KEY, true); } void PPPData::setDefaultroute(bool set) { writeConfig(cgroup, DEFAULTROUTE_KEY, (int) set); } bool PPPData::autoDNS() { bool set = (bool) readNumConfig(cgroup, AUTODNS_KEY, true); - return (set && gpppdata.pppdVersionMin(2, 3, 7)); + return (set && PPPData::data()->pppdVersionMin(2, 3, 7)); } void PPPData::setAutoDNS(bool set) { writeConfig(cgroup, AUTODNS_KEY, (int) set); } void PPPData::setExDNSDisabled(bool set) { writeConfig(cgroup, EXDNSDISABLED_KEY, (int) set); } @@ -1130,100 +1135,100 @@ QStringList &PPPData::pppdArgument() { void PPPData::setpppdArgument(QStringList &args) { writeListConfig(cgroup, PPPDARG_KEY, args); } void PPPData::setpppdArgumentDefaults() { QStringList arg; setpppdArgument(arg); } -// graphing widget -void PPPData::setGraphingOptions(bool enable, - QColor bg, - QColor text, - QColor in, - QColor out) -{ - if(config) { - config->setGroup(GRAPH_GRP); - config->writeEntry(GENABLED, enable); -// config->writeEntry(GCOLOR_BG, bg); -// config->writeEntry(GCOLOR_TEXT, text); -// config->writeEntry(GCOLOR_IN, in); -// config->writeEntry(GCOLOR_OUT, out); - } -} - -void PPPData::graphingOptions(bool &enable, - QColor &bg, - QColor &text, - QColor &in, - QColor &out) -{ - QColor c; - - if(config) { - config->setGroup(GRAPH_GRP); - enable = config->readBoolEntry(GENABLED, true); - bg = Qt::white; - //bg = config->readColorEntry(GCOLOR_BG, &c); - text = Qt::black; - //text = config->readColorEntry(GCOLOR_TEXT, &c); - in = Qt::blue; - //in = config->readColorEntry(GCOLOR_IN, &c); - out = Qt::red; - //out = config->readColorEntry(GCOLOR_OUT, &c); - } -} +// // graphing widget +// void PPPData::setGraphingOptions(bool enable, +// QColor bg, +// QColor text, +// QColor in, +// QColor out) +// { +// if(config) { +// config->setGroup(GRAPH_GRP); +// config->writeEntry(GENABLED, enable); +// // config->writeEntry(GCOLOR_BG, bg); +// // config->writeEntry(GCOLOR_TEXT, text); +// // config->writeEntry(GCOLOR_IN, in); +// // config->writeEntry(GCOLOR_OUT, out); +// } +// } + +// void PPPData::graphingOptions(bool &enable, +// QColor &bg, +// QColor &text, +// QColor &in, +// QColor &out) +// { +// QColor c; + +// if(config) { +// config->setGroup(GRAPH_GRP); +// enable = config->readBoolEntry(GENABLED, true); +// bg = Qt::white; +// //bg = config->readColorEntry(GCOLOR_BG, &c); +// text = Qt::black; +// //text = config->readColorEntry(GCOLOR_TEXT, &c); +// in = Qt::blue; +// //in = config->readColorEntry(GCOLOR_IN, &c); +// out = Qt::red; +// //out = config->readColorEntry(GCOLOR_OUT, &c); +// } +// } -bool PPPData::graphingEnabled() { - return (bool) readNumConfig(GRAPH_GRP, GENABLED, true); -} +// bool PPPData::graphingEnabled() { +// return (bool) readNumConfig(GRAPH_GRP, GENABLED, true); +// } // //functions to change/set the child pppd process info // bool PPPData::pppdRunning() const { return pppdisrunning; } void PPPData::setpppdRunning(bool set) { pppdisrunning = set; } int PPPData::pppdError() const { return pppderror; } void PPPData::setpppdError(int err) { pppderror = err; } -// -// window position -// -void PPPData::winPosConWin(int& p_x, int& p_y) { - p_x = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_X, QApplication::desktop()->width()/2-160); - p_y = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_Y, QApplication::desktop()->height()/2-55); -} +// // +// // window position +// // +// void PPPData::winPosConWin(int& p_x, int& p_y) { +// p_x = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_X, QApplication::desktop()->width()/2-160); +// p_y = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_Y, QApplication::desktop()->height()/2-55); +// } -void PPPData::setWinPosConWin(int p_x, int p_y) { - writeConfig(WINPOS_GRP, WINPOS_CONWIN_X, p_x); - writeConfig(WINPOS_GRP, WINPOS_CONWIN_Y, p_y); -} +// void PPPData::setWinPosConWin(int p_x, int p_y) { +// writeConfig(WINPOS_GRP, WINPOS_CONWIN_X, p_x); +// writeConfig(WINPOS_GRP, WINPOS_CONWIN_Y, p_y); +// } -void PPPData::winPosStatWin(int& p_x, int& p_y) { - p_x = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_X, QApplication::desktop()->width()/2-160); - p_y = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_Y, QApplication::desktop()->height()/2-55); -} +// void PPPData::winPosStatWin(int& p_x, int& p_y) { +// p_x = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_X, QApplication::desktop()->width()/2-160); +// p_y = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_Y, QApplication::desktop()->height()/2-55); +// } -void PPPData::setWinPosStatWin(int p_x, int p_y) { - writeConfig(WINPOS_GRP, WINPOS_STATWIN_X, p_x); - writeConfig(WINPOS_GRP, WINPOS_STATWIN_Y, p_y); -} +// void PPPData::setWinPosStatWin(int p_x, int p_y) { +// writeConfig(WINPOS_GRP, WINPOS_STATWIN_X, p_x); +// writeConfig(WINPOS_GRP, WINPOS_STATWIN_Y, p_y); +// } |