summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/ppp/pppdata.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/ppp/pppdata.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/pppdata.cpp250
1 files changed, 137 insertions, 113 deletions
diff --git a/noncore/settings/networksettings/ppp/pppdata.cpp b/noncore/settings/networksettings/ppp/pppdata.cpp
index 3f1675c..59d68c9 100644
--- a/noncore/settings/networksettings/ppp/pppdata.cpp
+++ b/noncore/settings/networksettings/ppp/pppdata.cpp
@@ -38,21 +38,8 @@
38// #include <kapplication.h> 38// #include <kapplication.h>
39#include <assert.h> 39#include <assert.h>
40 40
41PPPData *PPPData::_data = 0; 41#define SEPARATOR -sseepp-
42Config *PPPData::config = 0; 42#define SEP QString("%1SEPARATOR%1")
43
44PPPData* PPPData::data()
45{
46 if (!_data){
47 qDebug("PPPData::data() creates new Instance");
48 _data = new PPPData();
49 }
50 if (!_data->config){
51 qDebug("PPPData::data() opens conffile");
52 _data->open();
53 }
54 return _data;
55}
56 43
57PPPData::PPPData() 44PPPData::PPPData()
58 : modemDeviceGroup(-1), 45 : modemDeviceGroup(-1),
@@ -62,17 +49,6 @@ PPPData::PPPData()
62 pppdisrunning(false), 49 pppdisrunning(false),
63 pppderror(0) 50 pppderror(0)
64{ 51{
65}
66
67
68//
69// open configuration file
70//
71bool PPPData::open() {
72 qDebug("opening configfile NetworkSetupPPP");
73 if (config) return true;
74 config = new Config("NetworkSetupPPP");
75
76 highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1; 52 highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1;
77 53
78 if (highcount > MAX_ACCOUNTS) 54 if (highcount > MAX_ACCOUNTS)
@@ -90,26 +66,54 @@ bool PPPData::open() {
90 66
91 ::pppdVersion(&pppdVer, &pppdMod, &pppdPatch); 67 ::pppdVersion(&pppdVer, &pppdMod, &pppdPatch);
92 68
93 return true;
94} 69}
95 70
71Config PPPData::config()
72{
73 return Config("NetworkSetupPPP");
74}
96 75
97// 76//
98// save configuration 77// save configuration
99// 78//
100void PPPData::save() { 79void PPPData::save()
101 80{
102 if (config) { 81 qDebug("PPPData saving data");
103 writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count()); 82 writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count());
104 delete config; 83 QString key;
105 config = 0; 84 QStringList keys;
106 qDebug("worte confi NetworkSetupPPP"); 85 Config cfg = config();
107 } 86 for( QMap<QString,QString>::Iterator it = stringEntries.begin();
108 if (_data){ 87 it != stringEntries.end(); ++it ){
109 delete _data; 88 QString val = it.data();
110 _data = 0; 89 key = it.key();
111 } 90// qDebug("saving %s -> %s", key.latin1(), val.latin1() );
112 91 keys = QStringList::split( "SEPARATOR", key );
92 qDebug("group >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.latin1() );
93 cfg.setGroup(keys[0]);
94 cfg.writeEntry(keys[1], val);
95 }
96 for( QMap<QString,int>::Iterator it = intEntries.begin();
97 it != intEntries.end(); ++it ){
98 int val = it.data();
99 key = it.key();
100// qDebug("saving %s -> %i", key.latin1(), val );
101 keys = QStringList::split( "SEPARATOR", key );
102 qDebug("group >%s< key >%s< val %i", keys[0].latin1(), keys[1].latin1(), val );
103 cfg.setGroup(keys[0]);
104 cfg.writeEntry(keys[1], val);
105 }
106 for( QMap<QString,QStringList>::Iterator it = listEntries.begin();
107 it != listEntries.end(); ++it ){
108 QStringList val = it.data();
109 key = it.key();
110 QChar sep = sepEntries[key];
111// qDebug("saving %s -> %s", key.latin1(), val.join(sep).latin1() );
112 keys = QStringList::split( "SEPARATOR", key );
113 qDebug("group >%s< key >%s<values >%s<", keys[0].latin1(), keys[1].latin1(), val.join(sep).latin1() );
114 cfg.setGroup(keys[0]);
115 cfg.writeEntry(keys[1], val, sep);
116 }
113} 117}
114 118
115 119
@@ -117,42 +121,40 @@ void PPPData::save() {
117// cancel changes 121// cancel changes
118// 122//
119void PPPData::cancel() { 123void PPPData::cancel() {
120 124 stringEntries.clear();
121// if (config) { 125 intEntries.clear();
122// config->rollback(); 126 listEntries.clear();
123// config->reparseConfiguration();
124// }
125
126} 127}
127 128
128
129// // currently differentiates between READWRITE and NONE only
130// int PPPData::access() const {
131
132// return 1;//config->getConfigState();
133// }
134
135
136// functions to read/write date to configuration file 129// functions to read/write date to configuration file
137QString PPPData::readConfig(const QString &group, const QString &key, 130QString PPPData::readConfig(const QString &group, const QString &key,
138 const QString &defvalue = "") 131 const QString &defvalue = "")
139{ 132{
140// qDebug("PPPData::readConfig key >%s< group >%s<",key.latin1(), group.latin1()); 133// qDebug("PPPData::readConfig key >%s< group >%s<",key.latin1(), group.latin1());
141 if (config) { 134 QString idx = SEP.arg(group).arg(key);
142 config->setGroup(group); 135 if (stringEntries.find(idx) != stringEntries.end())
143 return config->readEntry(key, defvalue); 136 return stringEntries[idx];
144 } else 137 Config cfg = config();
145 return defvalue; 138 cfg.setGroup(group);
139 return cfg.readEntry(key, defvalue);
146} 140}
147 141
148 142
149int PPPData::readNumConfig(const QString &group, const QString &key, 143int PPPData::readNumConfig(const QString &group, const QString &key,
150 int defvalue) { 144 int defvalue)
151 if (config) { 145{
152 config->setGroup(group); 146 QString idx = SEP.arg(group).arg(key);
153 return config->readNumEntry(key, defvalue); 147 if (intEntries.find(idx) != intEntries.end())
154 } else 148 return intEntries[idx];
155 return defvalue; 149 Config cfg = config();
150 cfg.setGroup(group);
151 return cfg.readNumEntry(key, defvalue);
152
153// if (config) {
154// config->setGroup(group);
155// return config->readNumEntry(key, defvalue);
156// } else
157// return defvalue;
156 158
157} 159}
158 160
@@ -160,38 +162,55 @@ int PPPData::readNumConfig(const QString &group, const QString &key,
160bool PPPData::readListConfig(const QString &group, const QString &key, 162bool PPPData::readListConfig(const QString &group, const QString &key,
161 QStringList &list, char sep) { 163 QStringList &list, char sep) {
162 list.clear(); 164 list.clear();
163 if (config) { 165 QString idx = SEP.arg(group).arg(key);
164 config->setGroup(group); 166 if (listEntries.find(idx) != listEntries.end()){
165 list = config->readListEntry(key, sep); 167 list = listEntries[idx];
166 return true; 168 return true;
167 } else 169 }
168 return false; 170 Config cfg = config();
171 cfg.setGroup(group);
172 list = cfg.readListEntry(key, sep);
173 if (list.count() > 0) return true;
174 return false;
175
176// if (config) {
177// config->setGroup(group);
178// list = config->readListEntry(key, sep);
179// return true;
180// } else
181// return false;
169} 182}
170 183
171 184
172void PPPData::writeConfig(const QString &group, const QString &key, 185void PPPData::writeConfig(const QString &group, const QString &key,
173 const QString &value) { 186 const QString &value) {
174 if (config) { 187 stringEntries.insert( SEP.arg(group).arg(key), value );
175 config->setGroup(group); 188// if (config) {
176 config->writeEntry(key, value); 189// config->setGroup(group);
177 } 190// config->writeEntry(key, value);
191// }
178} 192}
179 193
180 194
181void PPPData::writeConfig(const QString &group, const QString &key, int value) { 195void PPPData::writeConfig(const QString &group, const QString &key, int value)
182 if (config) { 196{
183 config->setGroup(group); 197 intEntries.insert( SEP.arg(group).arg(key), value );
184 config->writeEntry(key, value); 198// if (config) {
185 } 199// config->setGroup(group);
200// config->writeEntry(key, value);
201// }
186} 202}
187 203
188 204
189void PPPData::writeListConfig(const QString &group, const QString &key, 205void PPPData::writeListConfig(const QString &group, const QString &key,
190 QStringList &list, char sep) { 206 QStringList &list, char sep)
191 if (config) { 207{
192 config->setGroup(group); 208 listEntries.insert( SEP.arg(group).arg(key), list );
193 config->writeEntry(key, list, sep); 209 sepEntries.insert( SEP.arg(group).arg(key), sep );
194 } 210// if (config) {
211// config->setGroup(group);
212// config->writeEntry(key, list, sep);
213// }
195} 214}
196 215
197 216
@@ -281,24 +300,24 @@ void PPPData::set_automatic_redial(bool set) {
281} 300}
282 301
283 302
284bool PPPData::get_iconify_on_connect() { 303// bool PPPData::get_iconify_on_connect() {
285 return (bool) readNumConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, TRUE); 304// return (bool) readNumConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, TRUE);
286} 305// }
287 306
288 307
289void PPPData::set_iconify_on_connect(bool set) { 308// void PPPData::set_iconify_on_connect(bool set) {
290 writeConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, (int) set); 309// writeConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, (int) set);
291} 310// }
292 311
293 312
294bool PPPData::get_dock_into_panel() { 313// bool PPPData::get_dock_into_panel() {
295 return (bool) readNumConfig(GENERAL_GRP, DOCKING_KEY, false); 314// return (bool) readNumConfig(GENERAL_GRP, DOCKING_KEY, false);
296} 315// }
297 316
298 317
299void PPPData::set_dock_into_panel(bool set) { 318// void PPPData::set_dock_into_panel(bool set) {
300 writeConfig(GENERAL_GRP, DOCKING_KEY, (int) set); 319// writeConfig(GENERAL_GRP, DOCKING_KEY, (int) set);
301} 320// }
302 321
303 322
304QString PPPData::pppdVersion() { 323QString PPPData::pppdVersion() {
@@ -790,7 +809,7 @@ bool PPPData::deleteAccount(const QString &aname) {
790int PPPData::newaccount() { 809int PPPData::newaccount() {
791 810
792 qDebug("PPPData::newaccount highcount %i/%i",highcount,MAX_ACCOUNTS); 811 qDebug("PPPData::newaccount highcount %i/%i",highcount,MAX_ACCOUNTS);
793 if(!config) open(); 812// if(!config) open();
794 if (highcount >= MAX_ACCOUNTS) return -1; 813 if (highcount >= MAX_ACCOUNTS) return -1;
795 814
796 highcount++; 815 highcount++;
@@ -990,14 +1009,14 @@ void PPPData::setAcctEnabled(bool set) {
990} 1009}
991 1010
992 1011
993int PPPData::VolAcctEnabled() { 1012// int PPPData::VolAcctEnabled() {
994 return readNumConfig(cgroup, VOLACCTENABLED_KEY, 0); 1013// return readNumConfig(cgroup, VOLACCTENABLED_KEY, 0);
995} 1014// }
996 1015
997 1016
998void PPPData::setVolAcctEnabled(int set) { 1017// void PPPData::setVolAcctEnabled(int set) {
999 writeConfig(cgroup, VOLACCTENABLED_KEY, set); 1018// writeConfig(cgroup, VOLACCTENABLED_KEY, set);
1000} 1019// }
1001 1020
1002 1021
1003const QString PPPData::gateway() { 1022const QString PPPData::gateway() {
@@ -1023,7 +1042,7 @@ void PPPData::setDefaultroute(bool set) {
1023 1042
1024bool PPPData::autoDNS() { 1043bool PPPData::autoDNS() {
1025 bool set = (bool) readNumConfig(cgroup, AUTODNS_KEY, true); 1044 bool set = (bool) readNumConfig(cgroup, AUTODNS_KEY, true);
1026 return (set && PPPData::data()->pppdVersionMin(2, 3, 7)); 1045 return (set && pppdVersionMin(2, 3, 7));
1027} 1046}
1028 1047
1029 1048
@@ -1226,12 +1245,16 @@ QString PPPData::modemGroup()
1226QMap<QString,QString> PPPData::getConfiguredInterfaces() 1245QMap<QString,QString> PPPData::getConfiguredInterfaces()
1227{ 1246{
1228 QMap<QString,QString> ifaces; 1247 QMap<QString,QString> ifaces;
1229 int count = readNumConfig( ACCLIST_GRP, ACCOUNTS_COUNT, -1 ); 1248 Config config = PPPData::config();
1230 QString accGrp; 1249 config.setGroup(ACCLIST_GRP);
1250 int count = config.readNumEntry( ACCOUNTS_COUNT, -1 );
1251 QString accGrp, dev, acc;
1231 for (int i = 0; i < count; i++){ 1252 for (int i = 0; i < count; i++){
1232 accGrp = QString("%1_%1").arg(ACCLIST_GRP).arg(i); 1253 accGrp = QString("%1_%1").arg(ACCLIST_GRP).arg(i);
1233 ifaces.insert( readConfig( accGrp, ACOUNTS_DEV, "error" ), 1254 config.setGroup(accGrp);
1234 readConfig( accGrp, ACOUNTS_ACC, "error" ) ); 1255 dev = config.readEntry( ACOUNTS_DEV, "error" );
1256 acc = config.readEntry( ACOUNTS_ACC, "error" );
1257 ifaces.insert( dev, acc );
1235 } 1258 }
1236 1259
1237 return ifaces; 1260 return ifaces;
@@ -1240,13 +1263,14 @@ QMap<QString,QString> PPPData::getConfiguredInterfaces()
1240void PPPData::setConfiguredInterfaces( QMap<QString,QString> ifaces ) 1263void PPPData::setConfiguredInterfaces( QMap<QString,QString> ifaces )
1241{ 1264{
1242 QMap<QString,QString>::Iterator it; 1265 QMap<QString,QString>::Iterator it;
1243 QString accGrp;
1244 int i = 0; 1266 int i = 0;
1267 Config cfg = config();
1245 for( it = ifaces.begin(); it != ifaces.end(); ++it, ++i ){ 1268 for( it = ifaces.begin(); it != ifaces.end(); ++it, ++i ){
1246 accGrp = QString("%1_%1").arg(ACCLIST_GRP).arg(i); 1269 cfg.setGroup(QString("%1_%1").arg(ACCLIST_GRP).arg(i));
1247 writeConfig( accGrp, ACOUNTS_DEV, it.key() ); 1270 cfg.writeEntry( ACOUNTS_DEV, it.key() );
1248 writeConfig( accGrp, ACOUNTS_ACC, it.data() ); 1271 cfg.writeEntry( ACOUNTS_ACC, it.data() );
1249 } 1272 }
1250 writeConfig( ACCLIST_GRP, ACCOUNTS_COUNT, i ); 1273 cfg.setGroup( ACCLIST_GRP );
1274 cfg.writeEntry( ACCOUNTS_COUNT, i );
1251 1275
1252} 1276}