summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/ppp/pppdata.cpp
authortille <tille>2003-05-25 18:19:04 (UTC)
committer tille <tille>2003-05-25 18:19:04 (UTC)
commit2ec401058a04c15d2725c94d38226d0ac4505496 (patch) (unidiff)
treebbe34da6b452cb01f31e5a08acf114c8c9641c32 /noncore/settings/networksettings/ppp/pppdata.cpp
parent7e1dce1560e45ef7fad91a8da2d0d96c1b166df9 (diff)
downloadopie-2ec401058a04c15d2725c94d38226d0ac4505496.zip
opie-2ec401058a04c15d2725c94d38226d0ac4505496.tar.gz
opie-2ec401058a04c15d2725c94d38226d0ac4505496.tar.bz2
saves configured interfaces now
Diffstat (limited to 'noncore/settings/networksettings/ppp/pppdata.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/pppdata.cpp54
1 files changed, 29 insertions, 25 deletions
diff --git a/noncore/settings/networksettings/ppp/pppdata.cpp b/noncore/settings/networksettings/ppp/pppdata.cpp
index 109e3b7..3f1675c 100644
--- a/noncore/settings/networksettings/ppp/pppdata.cpp
+++ b/noncore/settings/networksettings/ppp/pppdata.cpp
@@ -34,55 +34,54 @@
34#include <qapplication.h> 34#include <qapplication.h>
35// #include <klocale.h> 35// #include <klocale.h>
36// #include <kconfig.h> 36// #include <kconfig.h>
37// #include <kmessagebox.h> 37// #include <kmessagebox.h>
38// #include <kapplication.h> 38// #include <kapplication.h>
39#include <assert.h> 39#include <assert.h>
40 40
41PPPData *PPPData::_data = 0; 41PPPData *PPPData::_data = 0;
42Config *PPPData::config = 0; 42Config *PPPData::config = 0;
43 43
44PPPData* PPPData::data() 44PPPData* PPPData::data()
45{ 45{
46 if (!_data){ 46 if (!_data){
47 qDebug("PPPData::data() creates new Instance"); 47 qDebug("PPPData::data() creates new Instance");
48 _data = new PPPData(); 48 _data = new PPPData();
49 } 49 }
50 if (!_data->config){ 50 if (!_data->config){
51 qDebug("PPPData::data() opens conffile"); 51 qDebug("PPPData::data() opens conffile");
52 _data->open(); 52 _data->open();
53 } 53 }
54 return _data; 54 return _data;
55} 55}
56 56
57PPPData::PPPData() 57PPPData::PPPData()
58 : //config(0L), 58 : modemDeviceGroup(-1),
59 highcount(-1), // start out with no entries 59 highcount(-1), // start out with no entries
60 caccount(-1), // set the current account index also 60 caccount(-1), // set the current account index also
61 suidprocessid(-1), // process ID of setuid child 61 suidprocessid(-1), // process ID of setuid child
62 pppdisrunning(false), 62 pppdisrunning(false),
63 pppderror(0), 63 pppderror(0)
64 modemDeviceGroup(-1)
65{ 64{
66} 65}
67 66
68 67
69// 68//
70// open configuration file 69// open configuration file
71// 70//
72bool PPPData::open() { 71bool PPPData::open() {
73 qDebug("opening configfile NetworkSetupPPP"); 72 qDebug("opening configfile NetworkSetupPPP");
74 if (config) return true; 73 if (config) return true;
75 config = new Config("NetworkSetupPPP"); 74 config = new Config("NetworkSetupPPP");
76 75
77 highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1; 76 highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1;
78 77
79 if (highcount > MAX_ACCOUNTS) 78 if (highcount > MAX_ACCOUNTS)
80 highcount = MAX_ACCOUNTS; 79 highcount = MAX_ACCOUNTS;
81 80
82 if(highcount >= 0 && defaultAccount().isEmpty()) { 81 if(highcount >= 0 && defaultAccount().isEmpty()) {
83 setAccountbyIndex(0); 82 setAccountbyIndex(0);
84 setDefaultAccount(accname()); 83 setDefaultAccount(accname());
85 } else if(!setAccount(defaultAccount())) 84 } else if(!setAccount(defaultAccount()))
86 setDefaultAccount(accname()); 85 setDefaultAccount(accname());
87 86
88 // start out with internal debugging disabled 87 // start out with internal debugging disabled
@@ -308,49 +307,48 @@ QString PPPData::pppdVersion() {
308 307
309bool PPPData::pppdVersionMin(int ver, int mod, int patch) { 308bool PPPData::pppdVersionMin(int ver, int mod, int patch) {
310 // check if pppd version fulfills minimum requirement 309 // check if pppd version fulfills minimum requirement
311 return (pppdVer > ver 310 return (pppdVer > ver
312 || (pppdVer == ver && pppdMod > mod) 311 || (pppdVer == ver && pppdMod > mod)
313 || (pppdVer == ver && pppdMod == mod && pppdPatch >= patch)); 312 || (pppdVer == ver && pppdMod == mod && pppdPatch >= patch));
314} 313}
315 314
316int PPPData::pppdTimeout() { 315int PPPData::pppdTimeout() {
317 return readNumConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, PPPD_TIMEOUT); 316 return readNumConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, PPPD_TIMEOUT);
318} 317}
319 318
320 319
321void PPPData::setpppdTimeout(int n) { 320void PPPData::setpppdTimeout(int n) {
322 writeConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, n); 321 writeConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, n);
323} 322}
324 323
325 324
326const QString PPPData::modemDevice() { 325const QString PPPData::modemDevice() {
327 return readConfig (modemGroup(), MODEMDEV_KEY, devices[DEV_DEFAULT]); 326 return readConfig (modemGroup(), MODEMDEV_KEY, devices[DEV_DEFAULT]);
328} 327}
329 328
330 329
331bool PPPData::setModemDevice(const QString &n) { 330bool PPPData::setModemDevice(const QString &n) {
332 //FIXME: change modem group
333 bool ret = false; 331 bool ret = false;
334 for (int i = 0; devices[i]; i++) 332 for (int i = 0; devices[i]; i++)
335 if (devices[i] == n){ 333 if (devices[i] == n){
336 modemDeviceGroup = i; 334 modemDeviceGroup = i;
337 writeConfig(modemGroup(), MODEMDEV_KEY, n); 335 writeConfig(modemGroup(), MODEMDEV_KEY, n);
338 ret = true; 336 ret = true;
339 } 337 }
340 return ret; 338 return ret;
341} 339}
342 340
343 341
344const QString PPPData::flowcontrol() { 342const QString PPPData::flowcontrol() {
345 return readConfig(modemGroup(), FLOWCONTROL_KEY, "CRTSCTS"); 343 return readConfig(modemGroup(), FLOWCONTROL_KEY, "CRTSCTS");
346} 344}
347 345
348 346
349void PPPData::setFlowcontrol(const QString &n) { 347void PPPData::setFlowcontrol(const QString &n) {
350 writeConfig(modemGroup(), FLOWCONTROL_KEY, n); 348 writeConfig(modemGroup(), FLOWCONTROL_KEY, n);
351} 349}
352 350
353 351
354const QString PPPData::speed() { 352const QString PPPData::speed() {
355 QString s = readConfig(modemGroup(), SPEED_KEY, "57600"); 353 QString s = readConfig(modemGroup(), SPEED_KEY, "57600");
356 // undo the damage of a bug in former versions. It left an empty Speed= 354 // undo the damage of a bug in former versions. It left an empty Speed=
@@ -783,49 +781,49 @@ bool PPPData::deleteAccount(const QString &aname) {
783 if(!setAccount(aname)) 781 if(!setAccount(aname))
784 return false; 782 return false;
785 783
786 deleteAccount(); 784 deleteAccount();
787 785
788 return true; 786 return true;
789} 787}
790 788
791 789
792int PPPData::newaccount() { 790int PPPData::newaccount() {
793 791
794 qDebug("PPPData::newaccount highcount %i/%i",highcount,MAX_ACCOUNTS); 792 qDebug("PPPData::newaccount highcount %i/%i",highcount,MAX_ACCOUNTS);
795 if(!config) open(); 793 if(!config) open();
796 if (highcount >= MAX_ACCOUNTS) return -1; 794 if (highcount >= MAX_ACCOUNTS) return -1;
797 795
798 highcount++; 796 highcount++;
799 setAccountbyIndex(highcount); 797 setAccountbyIndex(highcount);
800 798
801 setpppdArgumentDefaults(); 799 setpppdArgumentDefaults();
802 qDebug("PPPData::newaccount -> %i",caccount); 800 qDebug("PPPData::newaccount -> %i",caccount);
803 return caccount; 801 return caccount;
804} 802}
805 803
806int PPPData::copyaccount(int i) { 804int PPPData::copyaccount(int i) {
807 805// FIXME
808// if(highcount >= MAX_ACCOUNTS) 806// if(highcount >= MAX_ACCOUNTS)
809 return -1; 807 return -1;
810 808
811// setAccountbyIndex(i); 809// setAccountbyIndex(i);
812 810
813// QMap <QString, QString> map = config->entryMap(cgroup); 811// QMap <QString, QString> map = config->entryMap(cgroup);
814// QMap <QString, QString>::ConstIterator it = map.begin(); 812// QMap <QString, QString>::ConstIterator it = map.begin();
815 813
816// QString newname = i18n("%1_copy").arg(accname()); 814// QString newname = i18n("%1_copy").arg(accname());
817 815
818// newaccount(); 816// newaccount();
819 817
820// while (it != map.end()) { 818// while (it != map.end()) {
821// config->writeEntry(it.key(), *it); 819// config->writeEntry(it.key(), *it);
822// it++; 820// it++;
823// } 821// }
824 822
825// setAccname(newname); 823// setAccname(newname);
826 824
827// return caccount; 825// return caccount;
828} 826}
829 827
830 828
831const QString PPPData::accname() { 829const QString PPPData::accname() {
@@ -1200,49 +1198,55 @@ void PPPData::setpppdArgumentDefaults() {
1200 1198
1201 1199
1202// 1200//
1203//functions to change/set the child pppd process info 1201//functions to change/set the child pppd process info
1204// 1202//
1205bool PPPData::pppdRunning() const { 1203bool PPPData::pppdRunning() const {
1206 return pppdisrunning; 1204 return pppdisrunning;
1207} 1205}
1208 1206
1209void PPPData::setpppdRunning(bool set) { 1207void PPPData::setpppdRunning(bool set) {
1210 pppdisrunning = set; 1208 pppdisrunning = set;
1211} 1209}
1212 1210
1213int PPPData::pppdError() const { 1211int PPPData::pppdError() const {
1214 return pppderror; 1212 return pppderror;
1215} 1213}
1216 1214
1217void PPPData::setpppdError(int err) { 1215void PPPData::setpppdError(int err) {
1218 pppderror = err; 1216 pppderror = err;
1219} 1217}
1220 1218
1221QString PPPData::modemGroup() 1219QString PPPData::modemGroup()
1222{ 1220{
1223 if (modemDeviceGroup<0)qFatal("wrong modem %i",modemDeviceGroup); 1221 if (modemDeviceGroup<0)qFatal("wrong modem %i",modemDeviceGroup);
1224 return QString("MODEM_GRP_%1").arg(modemDeviceGroup); 1222 return QString("%1_%1").arg(MODEM_GRP).arg(modemDeviceGroup);
1225} 1223}
1226 1224
1227// //
1228// // window position
1229// //
1230// void PPPData::winPosConWin(int& p_x, int& p_y) {
1231// p_x = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_X, QApplication::desktop()->width()/2-160);
1232// p_y = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_Y, QApplication::desktop()->height()/2-55);
1233// }
1234 1225
1235// void PPPData::setWinPosConWin(int p_x, int p_y) { 1226QMap<QString,QString> PPPData::getConfiguredInterfaces()
1236// writeConfig(WINPOS_GRP, WINPOS_CONWIN_X, p_x); 1227{
1237// writeConfig(WINPOS_GRP, WINPOS_CONWIN_Y, p_y); 1228 QMap<QString,QString> ifaces;
1238// } 1229 int count = readNumConfig( ACCLIST_GRP, ACCOUNTS_COUNT, -1 );
1230 QString accGrp;
1231 for (int i = 0; i < count; i++){
1232 accGrp = QString("%1_%1").arg(ACCLIST_GRP).arg(i);
1233 ifaces.insert( readConfig( accGrp, ACOUNTS_DEV, "error" ),
1234 readConfig( accGrp, ACOUNTS_ACC, "error" ) );
1235 }
1239 1236
1240// void PPPData::winPosStatWin(int& p_x, int& p_y) { 1237 return ifaces;
1241// p_x = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_X, QApplication::desktop()->width()/2-160); 1238}
1242// p_y = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_Y, QApplication::desktop()->height()/2-55);
1243// }
1244 1239
1245// void PPPData::setWinPosStatWin(int p_x, int p_y) { 1240void PPPData::setConfiguredInterfaces( QMap<QString,QString> ifaces )
1246// writeConfig(WINPOS_GRP, WINPOS_STATWIN_X, p_x); 1241{
1247// writeConfig(WINPOS_GRP, WINPOS_STATWIN_Y, p_y); 1242 QMap<QString,QString>::Iterator it;
1248// } 1243 QString accGrp;
1244 int i = 0;
1245 for( it = ifaces.begin(); it != ifaces.end(); ++it, ++i ){
1246 accGrp = QString("%1_%1").arg(ACCLIST_GRP).arg(i);
1247 writeConfig( accGrp, ACOUNTS_DEV, it.key() );
1248 writeConfig( accGrp, ACOUNTS_ACC, it.data() );
1249 }
1250 writeConfig( ACCLIST_GRP, ACCOUNTS_COUNT, i );
1251
1252}