summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/ppp/pppdata.cpp
authortille <tille>2003-05-24 16:12:02 (UTC)
committer tille <tille>2003-05-24 16:12:02 (UTC)
commitcc1aa3e178dff65854913bd5667579fc33ce707d (patch) (unidiff)
treed37d7fd8fb3b9832c0825b015af862f2cc62f473 /noncore/settings/networksettings/ppp/pppdata.cpp
parent5667ded1d4583cfb79b2ddfd7aaae0e58ed6d552 (diff)
downloadopie-cc1aa3e178dff65854913bd5667579fc33ce707d.zip
opie-cc1aa3e178dff65854913bd5667579fc33ce707d.tar.gz
opie-cc1aa3e178dff65854913bd5667579fc33ce707d.tar.bz2
saves config (still in the kppp way)
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
@@ -38,11 +38,24 @@
38// #include <kapplication.h> 38// #include <kapplication.h>
39#include <assert.h> 39#include <assert.h>
40 40
41PPPData gpppdata; 41PPPData *PPPData::_data = 0;
42Config *PPPData::config = 0;
42 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}
43 56
44PPPData::PPPData() 57PPPData::PPPData()
45 : config(0L), 58 : //config(0L),
46 highcount(-1), // start out with no entries 59 highcount(-1), // start out with no entries
47 caccount(-1), // set the current account index also 60 caccount(-1), // set the current account index also
48 suidprocessid(-1), // process ID of setuid child 61 suidprocessid(-1), // process ID of setuid child
@@ -56,25 +69,9 @@ PPPData::PPPData()
56// open configuration file 69// open configuration file
57// 70//
58bool PPPData::open() { 71bool PPPData::open() {
59 72 qDebug("opening configfile NetworkSetupPPP");
60 config = new Config("NetworkSetup"); 73 if (config) return true;
61 /* 74 config = new Config("NetworkSetupPPP");
62 config = kapp->config();
63
64 if (config->getConfigState() == KConfig::NoAccess) {
65 KMessageBox::error(0L,
66 i18n("The application-specific config file could not "
67 "be opened in either read-write or read-only mode.\n"
68 "The superuser might have to change its ownership "
69 "by issuing the following command in your home directory:\n"
70 "chown {YourUsername} .kde/share/config/kppprc"),
71 kapp->name());
72 return false;
73 }
74
75 // don't expand shell variables
76 config->setDollarExpansion(false);
77 */
78 75
79 highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1; 76 highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1;
80 77
@@ -104,7 +101,13 @@ void PPPData::save() {
104 101
105 if (config) { 102 if (config) {
106 writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count()); 103 writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count());
107// config->sync(); 104 delete config;
105 config = 0;
106 qDebug("worte confi NetworkSetupPPP");
107 }
108 if (_data){
109 delete _data;
110 _data = 0;
108 } 111 }
109 112
110} 113}
@@ -123,17 +126,18 @@ void PPPData::cancel() {
123} 126}
124 127
125 128
126// currently differentiates between READWRITE and NONE only 129// // currently differentiates between READWRITE and NONE only
127int PPPData::access() const { 130// int PPPData::access() const {
128 131
129 return 0;//config->getConfigState(); 132// return 1;//config->getConfigState();
130} 133// }
131 134
132 135
133// functions to read/write date to configuration file 136// functions to read/write date to configuration file
134QString PPPData::readConfig(const QString &group, const QString &key, 137QString PPPData::readConfig(const QString &group, const QString &key,
135 const QString &defvalue = "") 138 const QString &defvalue = "")
136{ 139{
140// qDebug("PPPData::readConfig key >%s< group >%s<",key.latin1(), group.latin1());
137 if (config) { 141 if (config) {
138 config->setGroup(group); 142 config->setGroup(group);
139 return config->readEntry(key, defvalue); 143 return config->readEntry(key, defvalue);
@@ -718,14 +722,14 @@ bool PPPData::isUniqueAccname(const QString &n) {
718 722
719 723
720bool PPPData::deleteAccount() { 724bool PPPData::deleteAccount() {
721 if(caccount < 0) 725 //FIXME:
726// if(caccount < 0)
722 return false; 727 return false;
723 728
724// QMap <QString, QString> map; 729// QMap <QString, QString> map;
725// QMap <QString, QString>::Iterator it; 730// QMap <QString, QString>::Iterator it;
726 731
727 // set all entries of the current account to "" 732// // set all entries of the current account to ""
728// tille: do not handle the accounts here... (?)
729// map = config->entryMap(cgroup); 733// map = config->entryMap(cgroup);
730// it = map.begin(); 734// it = map.begin();
731// while (it != map.end()) { 735// while (it != map.end()) {
@@ -756,13 +760,13 @@ bool PPPData::deleteAccount() {
756// it++; 760// it++;
757// } 761// }
758 762
759 highcount--; 763// highcount--;
760 if(caccount > highcount) 764// if(caccount > highcount)
761 caccount = highcount; 765// caccount = highcount;
762 766
763 setAccountbyIndex(caccount); 767// setAccountbyIndex(caccount);
764 768
765 return true; 769// return true;
766} 770}
767 771
768 772
@@ -778,39 +782,40 @@ bool PPPData::deleteAccount(const QString &aname) {
778 782
779int PPPData::newaccount() { 783int PPPData::newaccount() {
780 784
781 if(!config || highcount >= MAX_ACCOUNTS) 785 qDebug("PPPData::newaccount highcount %i/%i",highcount,MAX_ACCOUNTS);
782 return -1; 786 if(!config) open();
787 if (highcount >= MAX_ACCOUNTS) return -1;
783 788
784 highcount++; 789 highcount++;
785 setAccountbyIndex(highcount); 790 setAccountbyIndex(highcount);
786 791
787 setpppdArgumentDefaults(); 792 setpppdArgumentDefaults();
788 793 qDebug("PPPData::newaccount -> %i",caccount);
789 return caccount; 794 return caccount;
790} 795}
791 796
792int PPPData::copyaccount(int i) { 797int PPPData::copyaccount(int i) {
793 798
794 if(highcount >= MAX_ACCOUNTS) 799// if(highcount >= MAX_ACCOUNTS)
795 return -1; 800 return -1;
796 801
797 setAccountbyIndex(i); 802// setAccountbyIndex(i);
798 803
799// QMap <QString, QString> map = config->entryMap(cgroup); 804// QMap <QString, QString> map = config->entryMap(cgroup);
800// QMap <QString, QString>::ConstIterator it = map.begin(); 805// QMap <QString, QString>::ConstIterator it = map.begin();
801 806
802 QString newname = i18n("%1_copy").arg(accname()); 807// QString newname = i18n("%1_copy").arg(accname());
803 808
804 newaccount(); 809// newaccount();
805 810
806// while (it != map.end()) { 811// while (it != map.end()) {
807// config->writeEntry(it.key(), *it); 812// config->writeEntry(it.key(), *it);
808// it++; 813// it++;
809// } 814// }
810 815
811 setAccname(newname); 816// setAccname(newname);
812 817
813 return caccount; 818// return caccount;
814} 819}
815 820
816 821
@@ -829,7 +834,7 @@ void PPPData::setAccname(const QString &n) {
829} 834}
830 835
831 836
832#define SEPARATOR_CHAR ':' 837#define SEPARATOR_CHAR '&'
833QStringList &PPPData::phonenumbers() { 838QStringList &PPPData::phonenumbers() {
834 839
835 readListConfig(cgroup, PHONENUMBER_KEY, phonelist, SEPARATOR_CHAR); 840 readListConfig(cgroup, PHONENUMBER_KEY, phonelist, SEPARATOR_CHAR);
@@ -1011,7 +1016,7 @@ void PPPData::setDefaultroute(bool set) {
1011 1016
1012bool PPPData::autoDNS() { 1017bool PPPData::autoDNS() {
1013 bool set = (bool) readNumConfig(cgroup, AUTODNS_KEY, true); 1018 bool set = (bool) readNumConfig(cgroup, AUTODNS_KEY, true);
1014 return (set && gpppdata.pppdVersionMin(2, 3, 7)); 1019 return (set && PPPData::data()->pppdVersionMin(2, 3, 7));
1015} 1020}
1016 1021
1017 1022
@@ -1139,49 +1144,49 @@ void PPPData::setpppdArgumentDefaults() {
1139} 1144}
1140 1145
1141 1146
1142// graphing widget 1147// // graphing widget
1143void PPPData::setGraphingOptions(bool enable, 1148// void PPPData::setGraphingOptions(bool enable,
1144 QColor bg, 1149 // QColor bg,
1145 QColor text, 1150 // QColor text,
1146 QColor in, 1151 // QColor in,
1147 QColor out) 1152 // QColor out)
1148{ 1153// {
1149 if(config) { 1154// if(config) {
1150 config->setGroup(GRAPH_GRP); 1155// config->setGroup(GRAPH_GRP);
1151 config->writeEntry(GENABLED, enable); 1156// config->writeEntry(GENABLED, enable);
1152// config->writeEntry(GCOLOR_BG, bg); 1157// // config->writeEntry(GCOLOR_BG, bg);
1153// config->writeEntry(GCOLOR_TEXT, text); 1158// // config->writeEntry(GCOLOR_TEXT, text);
1154// config->writeEntry(GCOLOR_IN, in); 1159// // config->writeEntry(GCOLOR_IN, in);
1155// config->writeEntry(GCOLOR_OUT, out); 1160// // config->writeEntry(GCOLOR_OUT, out);
1156 } 1161// }
1157} 1162// }
1158 1163
1159void PPPData::graphingOptions(bool &enable, 1164// void PPPData::graphingOptions(bool &enable,
1160 QColor &bg, 1165 // QColor &bg,
1161 QColor &text, 1166 // QColor &text,
1162 QColor &in, 1167 // QColor &in,
1163 QColor &out) 1168 // QColor &out)
1164{ 1169// {
1165 QColor c; 1170// QColor c;
1166 1171
1167 if(config) { 1172// if(config) {
1168 config->setGroup(GRAPH_GRP); 1173// config->setGroup(GRAPH_GRP);
1169 enable = config->readBoolEntry(GENABLED, true); 1174// enable = config->readBoolEntry(GENABLED, true);
1170 bg = Qt::white; 1175// bg = Qt::white;
1171 //bg = config->readColorEntry(GCOLOR_BG, &c); 1176// //bg = config->readColorEntry(GCOLOR_BG, &c);
1172 text = Qt::black; 1177// text = Qt::black;
1173 //text = config->readColorEntry(GCOLOR_TEXT, &c); 1178// //text = config->readColorEntry(GCOLOR_TEXT, &c);
1174 in = Qt::blue; 1179// in = Qt::blue;
1175 //in = config->readColorEntry(GCOLOR_IN, &c); 1180// //in = config->readColorEntry(GCOLOR_IN, &c);
1176 out = Qt::red; 1181// out = Qt::red;
1177 //out = config->readColorEntry(GCOLOR_OUT, &c); 1182// //out = config->readColorEntry(GCOLOR_OUT, &c);
1178 } 1183// }
1179} 1184// }
1180 1185
1181 1186
1182bool PPPData::graphingEnabled() { 1187// bool PPPData::graphingEnabled() {
1183 return (bool) readNumConfig(GRAPH_GRP, GENABLED, true); 1188// return (bool) readNumConfig(GRAPH_GRP, GENABLED, true);
1184} 1189// }
1185 1190
1186 1191
1187 1192
@@ -1205,25 +1210,25 @@ void PPPData::setpppdError(int err) {
1205} 1210}
1206 1211
1207 1212
1208// 1213// //
1209// window position 1214// // window position
1210// 1215// //
1211void PPPData::winPosConWin(int& p_x, int& p_y) { 1216// void PPPData::winPosConWin(int& p_x, int& p_y) {
1212 p_x = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_X, QApplication::desktop()->width()/2-160); 1217// p_x = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_X, QApplication::desktop()->width()/2-160);
1213 p_y = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_Y, QApplication::desktop()->height()/2-55); 1218// p_y = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_Y, QApplication::desktop()->height()/2-55);
1214} 1219// }
1215 1220
1216void PPPData::setWinPosConWin(int p_x, int p_y) { 1221// void PPPData::setWinPosConWin(int p_x, int p_y) {
1217 writeConfig(WINPOS_GRP, WINPOS_CONWIN_X, p_x); 1222// writeConfig(WINPOS_GRP, WINPOS_CONWIN_X, p_x);
1218 writeConfig(WINPOS_GRP, WINPOS_CONWIN_Y, p_y); 1223// writeConfig(WINPOS_GRP, WINPOS_CONWIN_Y, p_y);
1219} 1224// }
1220 1225
1221void PPPData::winPosStatWin(int& p_x, int& p_y) { 1226// void PPPData::winPosStatWin(int& p_x, int& p_y) {
1222 p_x = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_X, QApplication::desktop()->width()/2-160); 1227// p_x = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_X, QApplication::desktop()->width()/2-160);
1223 p_y = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_Y, QApplication::desktop()->height()/2-55); 1228// p_y = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_Y, QApplication::desktop()->height()/2-55);
1224} 1229// }
1225 1230
1226void PPPData::setWinPosStatWin(int p_x, int p_y) { 1231// void PPPData::setWinPosStatWin(int p_x, int p_y) {
1227 writeConfig(WINPOS_GRP, WINPOS_STATWIN_X, p_x); 1232// writeConfig(WINPOS_GRP, WINPOS_STATWIN_X, p_x);
1228 writeConfig(WINPOS_GRP, WINPOS_STATWIN_Y, p_y); 1233// writeConfig(WINPOS_GRP, WINPOS_STATWIN_Y, p_y);
1229} 1234// }