summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/ppp/pppdata.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings/ppp/pppdata.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/pppdata.cpp211
1 files changed, 108 insertions, 103 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
@@ -35,17 +35,30 @@
// #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)
{
@@ -53,31 +66,15 @@ PPPData::PPPData()
//
// 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;
@@ -101,13 +98,19 @@ bool PPPData::open() {
// 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;
}
}
//
@@ -120,23 +123,24 @@ void PPPData::cancel() {
// 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;
}
@@ -715,20 +719,20 @@ bool PPPData::isUniqueAccname(const QString &n) {
setAccountbyIndex(current);
return true;
}
bool PPPData::deleteAccount() {
- if(caccount < 0)
+ //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++;
// }
@@ -753,19 +757,19 @@ bool PPPData::deleteAccount() {
// 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;
@@ -775,45 +779,46 @@ bool PPPData::deleteAccount(const QString &aname) {
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();
- 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++;
// }
- setAccname(newname);
+// setAccname(newname);
- return caccount;
+// return caccount;
}
const QString PPPData::accname() {
return readConfig(cgroup, NAME_KEY);
}
@@ -826,13 +831,13 @@ void PPPData::setAccname(const QString &n) {
if (def)
setDefaultAccount(n);
}
}
-#define SEPARATOR_CHAR ':'
+#define SEPARATOR_CHAR '&'
QStringList &PPPData::phonenumbers() {
readListConfig(cgroup, PHONENUMBER_KEY, phonelist, SEPARATOR_CHAR);
return phonelist;
}
@@ -1008,13 +1013,13 @@ 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);
}
@@ -1136,55 +1141,55 @@ void PPPData::setpppdArgument(QStringList &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);
- }
-}
+// // 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;
+// 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);
- }
-}
+// 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
//
@@ -1202,28 +1207,28 @@ int PPPData::pppdError() const {
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);
+// }