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 | |||
@@ -37,13 +37,26 @@ | |||
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 | ||
41 | PPPData gpppdata; | 41 | PPPData *PPPData::_data = 0; |
42 | Config *PPPData::config = 0; | ||
42 | 43 | ||
44 | PPPData* 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 | ||
44 | PPPData::PPPData() | 57 | PPPData::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 |
49 | pppdisrunning(false), | 62 | pppdisrunning(false), |
@@ -55,27 +68,11 @@ PPPData::PPPData() | |||
55 | // | 68 | // |
56 | // open configuration file | 69 | // open configuration file |
57 | // | 70 | // |
58 | bool PPPData::open() { | 71 | bool 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 | ||
81 | if (highcount > MAX_ACCOUNTS) | 78 | if (highcount > MAX_ACCOUNTS) |
@@ -103,9 +100,15 @@ bool PPPData::open() { | |||
103 | void PPPData::save() { | 100 | 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 | } |
111 | 114 | ||
@@ -122,19 +125,20 @@ void PPPData::cancel() { | |||
122 | 125 | ||
123 | } | 126 | } |
124 | 127 | ||
125 | 128 | ||
126 | // currently differentiates between READWRITE and NONE only | 129 | // // currently differentiates between READWRITE and NONE only |
127 | int 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 |
134 | QString PPPData::readConfig(const QString &group, const QString &key, | 137 | QString 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); |
140 | } else | 144 | } else |
@@ -717,16 +721,16 @@ bool PPPData::isUniqueAccname(const QString &n) { | |||
717 | } | 721 | } |
718 | 722 | ||
719 | 723 | ||
720 | bool PPPData::deleteAccount() { | 724 | bool PPPData::deleteAccount() { |
721 | if(caccount < 0) | 725 | //FIXME: |
722 | return false; | 726 | // if(caccount < 0) |
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()) { |
732 | // config->writeEntry(it.key(), ""); | 736 | // config->writeEntry(it.key(), ""); |
@@ -755,15 +759,15 @@ bool PPPData::deleteAccount() { | |||
755 | // config->writeEntry(it.key(), ""); | 759 | // config->writeEntry(it.key(), ""); |
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 | ||
769 | bool PPPData::deleteAccount(const QString &aname) { | 773 | bool PPPData::deleteAccount(const QString &aname) { |
@@ -777,41 +781,42 @@ bool PPPData::deleteAccount(const QString &aname) { | |||
777 | 781 | ||
778 | 782 | ||
779 | int PPPData::newaccount() { | 783 | int 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 | ||
792 | int PPPData::copyaccount(int i) { | 797 | int 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 | ||
817 | const QString PPPData::accname() { | 822 | const QString PPPData::accname() { |
@@ -828,9 +833,9 @@ void PPPData::setAccname(const QString &n) { | |||
828 | } | 833 | } |
829 | } | 834 | } |
830 | 835 | ||
831 | 836 | ||
832 | #define SEPARATOR_CHAR ':' | 837 | #define SEPARATOR_CHAR '&' |
833 | QStringList &PPPData::phonenumbers() { | 838 | QStringList &PPPData::phonenumbers() { |
834 | 839 | ||
835 | readListConfig(cgroup, PHONENUMBER_KEY, phonelist, SEPARATOR_CHAR); | 840 | readListConfig(cgroup, PHONENUMBER_KEY, phonelist, SEPARATOR_CHAR); |
836 | return phonelist; | 841 | return phonelist; |
@@ -1010,9 +1015,9 @@ void PPPData::setDefaultroute(bool set) { | |||
1010 | 1015 | ||
1011 | 1016 | ||
1012 | bool PPPData::autoDNS() { | 1017 | bool 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 | ||
1018 | void PPPData::setAutoDNS(bool set) { | 1023 | void PPPData::setAutoDNS(bool set) { |
@@ -1138,51 +1143,51 @@ void PPPData::setpppdArgumentDefaults() { | |||
1138 | setpppdArgument(arg); | 1143 | setpppdArgument(arg); |
1139 | } | 1144 | } |
1140 | 1145 | ||
1141 | 1146 | ||
1142 | // graphing widget | 1147 | // // graphing widget |
1143 | void 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 | ||
1159 | void 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 | ||
1182 | bool 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 | ||
1188 | // | 1193 | // |
@@ -1204,26 +1209,26 @@ void PPPData::setpppdError(int err) { | |||
1204 | pppderror = err; | 1209 | pppderror = err; |
1205 | } | 1210 | } |
1206 | 1211 | ||
1207 | 1212 | ||
1208 | // | 1213 | // // |
1209 | // window position | 1214 | // // window position |
1210 | // | 1215 | // // |
1211 | void 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 | ||
1216 | void 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 | ||
1221 | void 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 | ||
1226 | void 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 | // } |