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.cpp397
1 files changed, 295 insertions, 102 deletions
diff --git a/noncore/settings/networksettings/ppp/pppdata.cpp b/noncore/settings/networksettings/ppp/pppdata.cpp
index 8f45e54..f4727c1 100644
--- a/noncore/settings/networksettings/ppp/pppdata.cpp
+++ b/noncore/settings/networksettings/ppp/pppdata.cpp
@@ -17,113 +17,124 @@
17 * This program is distributed in the hope that it will be useful, 17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details. 20 * Library General Public License for more details.
21 * 21 *
22 * You should have received a copy of the GNU Library General Public 22 * You should have received a copy of the GNU Library General Public
23 * License along with this program; if not, write to the Free 23 * License along with this program; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */ 25 */
26 26
27#include "pppdata.h" 27#include "pppdata.h"
28#include "runtests.h" 28#include "runtests.h"
29#include "devices.h" 29//#include "devices.h"
30//#include <klocale.h> 30//#include <klocale.h>
31#define i18n QObject::tr
32#include <qpe/config.h> 31#include <qpe/config.h>
33#include <qmessagebox.h> 32#include <qmessagebox.h>
34#include <qapplication.h> 33#include <qapplication.h>
35// #include <klocale.h> 34// #include <klocale.h>
36// #include <kconfig.h> 35// #include <kconfig.h>
37// #include <kmessagebox.h> 36// #include <kmessagebox.h>
38// #include <kapplication.h> 37// #include <kapplication.h>
39#include <assert.h> 38#include <assert.h>
40 39
41#define SEPARATOR -sseepp- 40#define SEPARATOR -sseepp-
42#define SEP QString("%1SEPARATOR%1") 41#define SEP QString("%1SEPARATOR%1")
43 42
44PPPData::PPPData() 43PPPData::PPPData()
45 : modemDeviceGroup(-1), 44 : passwd(""),
46 passwd(""), 45 _modemName(""),
47 highcount(-1), // start out with no entries 46 highcount(-1), // start out with no entries
48 caccount(-1), // set the current account index also 47 highcountdev(-1), // start out with no entries
48// caccount(-1), // set the current account index also
49 suidprocessid(-1), // process ID of setuid child 49 suidprocessid(-1), // process ID of setuid child
50 pppdisrunning(false), 50 pppdisrunning(false),
51 pppderror(0) 51 pppderror(0)
52{ 52{
53 highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1; 53 highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1;
54 highcountdev = readNumConfig(GENERAL_GRP, NUMDEVICES_KEY, 0) - 1;
55 Config cfg = config();
56 cfg.setGroup(GENERAL_GRP);
57 accountList = cfg.readListEntry(ACCOUNT_LIST, ',' );
58 deviceList = cfg.readListEntry(DEVICESNAMES_LIST, ',' );
59 qDebug("PPPData::PPPData has a accountList %s", accountList.join("---").latin1());
60 qDebug("PPPData::PPPData has a deviceList %s", deviceList.join("---").latin1());
54 61
55 if (highcount > MAX_ACCOUNTS) 62// if (highcount > MAX_ACCOUNTS)
56 highcount = MAX_ACCOUNTS; 63// highcount = MAX_ACCOUNTS;
57 64
58 if(highcount >= 0 && defaultAccount().isEmpty()) { 65 // if(highcount >= 0 && defaultAccount().isEmpty()) {
59 setAccountbyIndex(0); 66// setAccountbyIndex(0);
60 setDefaultAccount(accname()); 67// setDefaultAccount(accname());
61 } else if(!setAccount(defaultAccount())) 68// } else if(!setAccount(defaultAccount()))
62 setDefaultAccount(accname()); 69 setDefaultAccount(accname());
63 70
64 // start out with internal debugging disabled 71 // start out with internal debugging disabled
65 // the user is still free to specify `debug' on his own 72 // the user is still free to specify `debug' on his own
66 setPPPDebug(false); 73 setPPPDebug(false);
67 74
68 ::pppdVersion(&pppdVer, &pppdMod, &pppdPatch); 75 ::pppdVersion(&pppdVer, &pppdMod, &pppdPatch);
69 76
70} 77}
71 78
72Config PPPData::config() 79Config PPPData::config()
73{ 80{
74 return Config("NetworkSetupPPP"); 81 return Config("NetworkSetupPPP");
75} 82}
76 83
77// 84//
78// save configuration 85// save configuration
79// 86//
80void PPPData::save() 87void PPPData::save()
81{ 88{
82 qDebug("PPPData saving data"); 89 qDebug("PPPData saving data");
83 writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count()); 90 writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count());
91 writeConfig(GENERAL_GRP, NUMDEVICES_KEY, highcountdev + 1);
84 QString key; 92 QString key;
85 QStringList keys; 93 QStringList keys;
86 Config cfg = config(); 94 Config cfg = config();
95 cfg.setGroup(GENERAL_GRP);
96 cfg.writeEntry(ACCOUNT_LIST, accountList, ',' );
97 cfg.writeEntry(DEVICESNAMES_LIST, deviceList, ',' );
98
87 for( QMap<QString,QString>::Iterator it = stringEntries.begin(); 99 for( QMap<QString,QString>::Iterator it = stringEntries.begin();
88 it != stringEntries.end(); ++it ){ 100 it != stringEntries.end(); ++it ){
89 QString val = it.data(); 101 QString val = it.data();
90 key = it.key(); 102 key = it.key();
91// qDebug("saving %s -> %s", key.latin1(), val.latin1() ); 103// qDebug("saving %s -> %s", key.latin1(), val.latin1() );
92 keys = QStringList::split( "SEPARATOR", key ); 104 keys = QStringList::split( "SEPARATOR", key );
93 qDebug("group >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.latin1() ); 105 //qDebug("group >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.latin1() );
94 cfg.setGroup(keys[0]); 106 cfg.setGroup(keys[0]);
95 cfg.writeEntry(keys[1], val); 107 cfg.writeEntry(keys[1], val);
96 } 108 }
97 for( QMap<QString,int>::Iterator it = intEntries.begin(); 109 for( QMap<QString,int>::Iterator it = intEntries.begin();
98 it != intEntries.end(); ++it ){ 110 it != intEntries.end(); ++it ){
99 int val = it.data(); 111 int val = it.data();
100 key = it.key(); 112 key = it.key();
101// qDebug("saving %s -> %i", key.latin1(), val ); 113// qDebug("saving %s -> %i", key.latin1(), val );
102 keys = QStringList::split( "SEPARATOR", key ); 114 keys = QStringList::split( "SEPARATOR", key );
103 qDebug("group >%s< key >%s< val %i", keys[0].latin1(), keys[1].latin1(), val ); 115 //qDebug("group >%s< key >%s< val %i", keys[0].latin1(), keys[1].latin1(), val );
104 cfg.setGroup(keys[0]); 116 cfg.setGroup(keys[0]);
105 cfg.writeEntry(keys[1], val); 117 cfg.writeEntry(keys[1], val);
106 } 118 }
107 for( QMap<QString,QStringList>::Iterator it = listEntries.begin(); 119 for( QMap<QString,QStringList>::Iterator it = listEntries.begin();
108 it != listEntries.end(); ++it ){ 120 it != listEntries.end(); ++it ){
109 QStringList val = it.data(); 121 QStringList val = it.data();
110 key = it.key(); 122 key = it.key();
111 QChar sep = sepEntries[key]; 123 QChar sep = sepEntries[key];
112// qDebug("saving %s -> %s", key.latin1(), val.join(sep).latin1() ); 124// qDebug("saving %s -> %s", key.latin1(), val.join(sep).latin1() );
113 keys = QStringList::split( "SEPARATOR", key ); 125 keys = QStringList::split( "SEPARATOR", key );
114 qDebug("group >%s< key >%s<values >%s<", keys[0].latin1(), keys[1].latin1(), val.join(sep).latin1() );
115 cfg.setGroup(keys[0]); 126 cfg.setGroup(keys[0]);
116 cfg.writeEntry(keys[1], val, sep); 127 cfg.writeEntry(keys[1], val, sep);
117 } 128 }
118} 129}
119 130
120 131
121// 132//
122// cancel changes 133// cancel changes
123// 134//
124void PPPData::cancel() { 135void PPPData::cancel() {
125 stringEntries.clear(); 136 stringEntries.clear();
126 intEntries.clear(); 137 intEntries.clear();
127 listEntries.clear(); 138 listEntries.clear();
128} 139}
129 140
@@ -335,39 +346,51 @@ bool PPPData::pppdVersionMin(int ver, int mod, int patch) {
335 346
336int PPPData::pppdTimeout() { 347int PPPData::pppdTimeout() {
337 return readNumConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, PPPD_TIMEOUT); 348 return readNumConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, PPPD_TIMEOUT);
338} 349}
339 350
340 351
341void PPPData::setpppdTimeout(int n) { 352void PPPData::setpppdTimeout(int n) {
342 writeConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, n); 353 writeConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, n);
343} 354}
344 355
345 356
346const QString PPPData::modemDevice() { 357const QString PPPData::modemDevice() {
347 return readConfig (modemGroup(), MODEMDEV_KEY, devices[DEV_DEFAULT]); 358 return readConfig (modemGroup(), MODEMDEV_KEY, "/dev/modem" );
348} 359}
349 360
350 361
362// const QString PPPData::modemName()
363// {
364// return readConfig(modemGroup(), MODEMNAME_KEY);
365// }
366
367// bool PPPData::setModemName(const QString &n) {
368// qDebug("Setting modem name to >%s<", n.latin1());
369// _modemName = n;
370// writeConfig(cgroup, MODEMNAME_KEY, n);
371// return true; //FIXME
372// }
373
374// bool PPPData::changeModemName(const QString &n) {
375// qDebug("Setting modem name to >%s<", n.latin1());
376// _modemName = n;
377// writeConfig(modemGroup(), MODEMNAME_KEY, n);
378// return true; //FIXME
379// }
380
351bool PPPData::setModemDevice(const QString &n) { 381bool PPPData::setModemDevice(const QString &n) {
352 qDebug("Setting modem dev to >%s<", n.latin1()); 382 qDebug("Setting modem dev to >%s<", n.latin1());
353 bool ret = false; 383 writeConfig(modemGroup(), MODEMDEV_KEY, n);
354 for (int i = 0; devices[i]; i++) 384 return true; //FIXME
355 if (devices[i] == n){
356 modemDeviceGroup = i;
357 writeConfig(modemGroup(), MODEMDEV_KEY, n);
358 ret = true;
359 }
360 qDebug(ret?"SUCCESS":"FAILURE");
361 return ret;
362} 385}
363 386
364 387
365const QString PPPData::flowcontrol() { 388const QString PPPData::flowcontrol() {
366 return readConfig(modemGroup(), FLOWCONTROL_KEY, "CRTSCTS"); 389 return readConfig(modemGroup(), FLOWCONTROL_KEY, "CRTSCTS");
367} 390}
368 391
369 392
370void PPPData::setFlowcontrol(const QString &n) { 393void PPPData::setFlowcontrol(const QString &n) {
371 writeConfig(modemGroup(), FLOWCONTROL_KEY, n); 394 writeConfig(modemGroup(), FLOWCONTROL_KEY, n);
372} 395}
373 396
@@ -708,145 +731,169 @@ void PPPData::setEnter(const QString &n) {
708// 731//
709// functions to set/return account information 732// functions to set/return account information
710// 733//
711 734
712//returns number of accounts 735//returns number of accounts
713int PPPData::count() const { 736int PPPData::count() const {
714 return highcount + 1; 737 return highcount + 1;
715} 738}
716 739
717 740
718bool PPPData::setAccount(const QString &aname) { 741bool PPPData::setAccount(const QString &aname) {
719 qDebug("setting account to >%s<", aname.latin1()); 742 qDebug("setting account to >%s<", aname.latin1());
720 for(int i = 0; i <= highcount; i++) { 743 for ( QStringList::Iterator it = accountList.begin(); it != accountList.end(); ++it ) {
721 setAccountbyIndex(i); 744 cgroup = *it;
722 if(accname() == aname) { 745 qDebug("PPPData::setAccount %s", cgroup.latin1());
723 caccount = i; 746 qDebug( "iterator %s", (*it).latin1() );
724 qDebug("SUCCESS"); 747 if(accname() == aname) {
725 return true; 748 qDebug("SUCCESS");
749 return true;
750 }
751
726 } 752 }
727 } 753 qDebug("FAILURE");
728 qDebug("FAILURE"); 754 return false;
729 return false;
730} 755}
731 756
732 757/*
733bool PPPData::setAccountbyIndex(int i) { 758bool PPPData::setAccountbyIndex(int i) {
734 if(i >= 0 && i <= highcount) { 759 if(i >= 0 && i <= highcount) {
760 QString tmp;
761 tmp.sprintf("%s%i", ACCOUNT_GRP, i);
762 if (_deleted.find(tmp)!=_deleted.end()) return false;
735 caccount = i; 763 caccount = i;
736 cgroup.sprintf("%s%i", ACCOUNT_GRP, i); 764 cgroup = tmp;
737 return true; 765 return true;
738 } 766 }
739 return false; 767 return false;
740} 768}
741 769*/
742 770
743bool PPPData::isUniqueAccname(const QString &n) { 771bool PPPData::isUniqueAccname(const QString &n) {
744 int current = caccount; 772 QString save_cgroup = cgroup;
745 for(int i=0; i <= highcount; i++) { 773 for ( QStringList::Iterator it = accountList.begin(); it != accountList.end(); ++it ) {
746 setAccountbyIndex(i); 774 cgroup = *it;
747 if(accname() == n && i != current) { 775 qDebug("PPPData::setAccount %s", cgroup.latin1());
748 setAccountbyIndex(current); 776 qDebug( "%s \n", (*it).latin1() );
749 return false; 777 if(accname() == n && cgroup != save_cgroup) {
750 } 778 cgroup = save_cgroup;
779 qDebug("SUCCESS");
780 return false;
781 }
782
751 } 783 }
752 setAccountbyIndex(current); 784 cgroup = save_cgroup;
753 return true; 785 return true;
754} 786}
755 787
756 788
757bool PPPData::deleteAccount() { 789bool PPPData::isUniqueDevname(const QString &n) {
758 //FIXME: PPPData::deleteAccount 790 QString save_mName = _modemName;
759// if(caccount < 0) 791 qDebug("PPPData::isUniqueDevname checking if %s is unique", n.latin1());
760 return false; 792 for ( QStringList::Iterator it = deviceList.begin(); it != deviceList.end(); ++it ) {
761 793 _modemName = *it;
762// QMap <QString, QString> map; 794 qDebug("PPPData::isUniqueDevname %s == %s", n.latin1() , devname().latin1());
763// QMap <QString, QString>::Iterator it; 795 if(devname() == n && _modemName != save_mName) {
764 796 _modemName = save_mName;
765// // set all entries of the current account to "" 797 qDebug("NOT UNIQUE");
766// map = config->entryMap(cgroup); 798 return false;
767// it = map.begin(); 799 }
768// while (it != map.end()) {
769// config->writeEntry(it.key(), "");
770// it++;
771// }
772 800
773// // shift the succeeding accounts 801 }
774// for(int i = caccount+1; i <= highcount; i++) { 802 _modemName = save_mName;
775// setAccountbyIndex(i); 803 return true;
776// map = config->entryMap(cgroup); 804}
777// it = map.begin();
778// setAccountbyIndex(i-1);
779// config->setGroup(cgroup);
780// while (it != map.end()) {
781// config->writeEntry(it.key(), *it);
782// it++;
783// }
784// }
785 805
786// // make sure the top account is cleared
787// setAccountbyIndex(highcount);
788// map = config->entryMap(cgroup);
789// it = map.begin();
790// config->setGroup(cgroup);
791// while (it.key() != QString::null) {
792// config->writeEntry(it.key(), "");
793// it++;
794// }
795 806
796// highcount--; 807bool PPPData::deleteAccount() {
797// if(caccount > highcount) 808 // FIXME: check if this account exists in a config...
798// caccount = highcount; 809 Config cfg = PPPData::config();
810 cfg.setGroup(cgroup);
811 cfg.clearGroup();
812 accountList.remove(cgroup);
799 813
800// setAccountbyIndex(caccount); 814 QString key;
815 QStringList keys;
816 for( QMap<QString,QString>::Iterator it = stringEntries.begin();
817 it != stringEntries.end(); ++it ){
818 QString val = it.data();
819 key = it.key();
820 keys = QStringList::split( "SEPARATOR", key );
821 if(keys[0]==cgroup){
822 stringEntries.remove( it );
823 qDebug("deleting >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.latin1() );
824 }
825 }
826 for( QMap<QString,int>::Iterator it = intEntries.begin();
827 it != intEntries.end(); ++it ){
828 int val = it.data();
829 key = it.key();
830 keys = QStringList::split( "SEPARATOR", key );
831 if(keys[0]==cgroup){
832 intEntries.remove( it );
833 qDebug("deleting >%s< key >%s< value >%i<", keys[0].latin1(), keys[1].latin1(), val );
834 }
835 }
836 for( QMap<QString,QStringList>::Iterator it = listEntries.begin();
837 it != listEntries.end(); ++it ){
838 QStringList val = it.data();
839 key = it.key();
840 if(keys[0]==cgroup){
841 listEntries.remove( it );
842 sepEntries.remove( key );
843 qDebug("deleting >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.join("").latin1() );
844 }
845 }
801 846
802// return true; 847 return true;
803} 848}
804 849
805 850
806bool PPPData::deleteAccount(const QString &aname) { 851bool PPPData::deleteAccount(const QString &aname) {
807 if(!setAccount(aname)) 852 if(!setAccount(aname))
808 return false; 853 return false;
809 854
810 deleteAccount(); 855 deleteAccount();
811 856
812 return true; 857 return true;
813} 858}
814 859
815 860
816int PPPData::newaccount() { 861int PPPData::newaccount() {
817 862
818 qDebug("PPPData::newaccount highcount %i/%i",highcount,MAX_ACCOUNTS); 863 qDebug("PPPData::newaccount highcount %i/%i",highcount,MAX_ACCOUNTS);
819// if(!config) open(); 864// if(!config) open();
820 if (highcount >= MAX_ACCOUNTS) return -1; 865// if (highcount >= MAX_ACCOUNTS) return -1;
821 866
822 highcount++;
823 setAccountbyIndex(highcount);
824 867
868 QString tmp;
869 tmp.sprintf("%s%i", ACCOUNT_GRP, ++highcount);
870 cgroup = QString(tmp);
871 accountList << tmp;
872 qDebug("PPPData::newaccount() Group: >%s<",cgroup.latin1());
825 setpppdArgumentDefaults(); 873 setpppdArgumentDefaults();
826 qDebug("PPPData::newaccount -> %i",caccount); 874 return highcount;
827 return caccount;
828} 875}
829 876
830int PPPData::copyaccount(int i) { 877int PPPData::copyaccount(const QString&) {
831// FIXME: PPPData::copyaccount 878// FIXME: PPPData::copyaccount
832// if(highcount >= MAX_ACCOUNTS) 879// if(highcount >= MAX_ACCOUNTS)
833 return -1; 880 return -1;
834 881
835// setAccountbyIndex(i); 882// setAccountbyIndex(i);
836 883
837// QMap <QString, QString> map = config->entryMap(cgroup); 884// QMap <QString, QString> map = config->entryMap(cgroup);
838// QMap <QString, QString>::ConstIterator it = map.begin(); 885// QMap <QString, QString>::ConstIterator it = map.begin();
839 886
840// QString newname = i18n("%1_copy").arg(accname()); 887// QString newname = QObject::tr("%1_copy").arg(accname());
841 888
842// newaccount(); 889// newaccount();
843 890
844// while (it != map.end()) { 891// while (it != map.end()) {
845// config->writeEntry(it.key(), *it); 892// config->writeEntry(it.key(), *it);
846// it++; 893// it++;
847// } 894// }
848 895
849// setAccname(newname); 896// setAccname(newname);
850 897
851// return caccount; 898// return caccount;
852} 899}
@@ -855,24 +902,25 @@ int PPPData::copyaccount(int i) {
855const QString PPPData::accname() { 902const QString PPPData::accname() {
856 return readConfig(cgroup, NAME_KEY); 903 return readConfig(cgroup, NAME_KEY);
857} 904}
858 905
859void PPPData::setAccname(const QString &n) { 906void PPPData::setAccname(const QString &n) {
860 if(!cgroup.isNull()) { 907 if(!cgroup.isNull()) {
861 // are we manipulating the default account's name ? then change it, too. 908 // are we manipulating the default account's name ? then change it, too.
862 bool def = accname() == defaultAccount(); 909 bool def = accname() == defaultAccount();
863 writeConfig(cgroup, NAME_KEY, n); 910 writeConfig(cgroup, NAME_KEY, n);
864 if (def) 911 if (def)
865 setDefaultAccount(n); 912 setDefaultAccount(n);
866 } 913 }
914 writeConfig(cgroup, NAME_KEY, n);
867} 915}
868 916
869 917
870#define SEPARATOR_CHAR '&' 918#define SEPARATOR_CHAR '&'
871QStringList &PPPData::phonenumbers() { 919QStringList &PPPData::phonenumbers() {
872 920
873 readListConfig(cgroup, PHONENUMBER_KEY, phonelist, SEPARATOR_CHAR); 921 readListConfig(cgroup, PHONENUMBER_KEY, phonelist, SEPARATOR_CHAR);
874 return phonelist; 922 return phonelist;
875 923
876} 924}
877 925
878 926
@@ -1167,24 +1215,25 @@ QStringList &PPPData::pppdArgument() {
1167 1215
1168 return arglist; 1216 return arglist;
1169} 1217}
1170 1218
1171 1219
1172void PPPData::setpppdArgument(QStringList &args) { 1220void PPPData::setpppdArgument(QStringList &args) {
1173 writeListConfig(cgroup, PPPDARG_KEY, args); 1221 writeListConfig(cgroup, PPPDARG_KEY, args);
1174} 1222}
1175 1223
1176 1224
1177void PPPData::setpppdArgumentDefaults() { 1225void PPPData::setpppdArgumentDefaults() {
1178 QStringList arg; 1226 QStringList arg;
1227 arg << "lcp-echo-failure 0";
1179 setpppdArgument(arg); 1228 setpppdArgument(arg);
1180} 1229}
1181 1230
1182 1231
1183// // graphing widget 1232// // graphing widget
1184// void PPPData::setGraphingOptions(bool enable, 1233// void PPPData::setGraphingOptions(bool enable,
1185 // QColor bg, 1234 // QColor bg,
1186 // QColor text, 1235 // QColor text,
1187 // QColor in, 1236 // QColor in,
1188 // QColor out) 1237 // QColor out)
1189// { 1238// {
1190// if(config) { 1239// if(config) {
@@ -1238,29 +1287,27 @@ void PPPData::setpppdRunning(bool set) {
1238} 1287}
1239 1288
1240int PPPData::pppdError() const { 1289int PPPData::pppdError() const {
1241 return pppderror; 1290 return pppderror;
1242} 1291}
1243 1292
1244void PPPData::setpppdError(int err) { 1293void PPPData::setpppdError(int err) {
1245 pppderror = err; 1294 pppderror = err;
1246} 1295}
1247 1296
1248QString PPPData::modemGroup() 1297QString PPPData::modemGroup()
1249{ 1298{
1250 if (modemDeviceGroup<0){ 1299 if (_modemName.isEmpty())
1251 qDebug("wrong modem %i\n using 0",modemDeviceGroup); 1300 _modemName = deviceList[0];
1252 modemDeviceGroup = 0; //FIXME! 1301 return _modemName;
1253 }
1254 return QString("%1_%1").arg(MODEM_GRP).arg(modemDeviceGroup);
1255} 1302}
1256 1303
1257 1304
1258QMap<QString,QString> PPPData::getConfiguredInterfaces() 1305QMap<QString,QString> PPPData::getConfiguredInterfaces()
1259{ 1306{
1260 QMap<QString,QString> ifaces; 1307 QMap<QString,QString> ifaces;
1261 Config config = PPPData::config(); 1308 Config config = PPPData::config();
1262 config.setGroup(ACCLIST_GRP); 1309 config.setGroup(ACCLIST_GRP);
1263 int count = config.readNumEntry( ACCOUNTS_COUNT, -1 ); 1310 int count = config.readNumEntry( ACCOUNTS_COUNT, -1 );
1264 QString accGrp, dev, acc; 1311 QString accGrp, dev, acc;
1265 for (int i = 0; i < count; i++){ 1312 for (int i = 0; i < count; i++){
1266 accGrp = QString("%1_%1").arg(ACCLIST_GRP).arg(i); 1313 accGrp = QString("%1_%1").arg(ACCLIST_GRP).arg(i);
@@ -1291,12 +1338,158 @@ void PPPData::setConfiguredInterfaces( QMap<QString,QString> ifaces )
1291} 1338}
1292 1339
1293/** 1340/**
1294 * pppd's getword() function knows about escape characters. 1341 * pppd's getword() function knows about escape characters.
1295 * If we write the username and password to the secrets file 1342 * If we write the username and password to the secrets file
1296 * we'll therefore have to escape back slashes. 1343 * we'll therefore have to escape back slashes.
1297 */ 1344 */
1298QString PPPData::encodeWord(const QString &s) { 1345QString PPPData::encodeWord(const QString &s) {
1299 QString r = s; 1346 QString r = s;
1300 r.replace(QRegExp("\\"), "\\\\"); 1347 r.replace(QRegExp("\\"), "\\\\");
1301 return r; 1348 return r;
1302} 1349}
1350
1351QStringList PPPData::getDevicesList()
1352{
1353 Config cfg("NetworkSetupPPP");
1354 cfg.setGroup("Devices_General");
1355 return cfg.readListEntry(DEVICES_LIST,DEVICES_LIST_SEP);
1356}
1357
1358QStringList PPPData::getAccountList()
1359{
1360 QStringList list;
1361 QString save_cgroup;
1362 save_cgroup = cgroup;
1363 for ( QStringList::Iterator it = accountList.begin(); it != accountList.end(); ++it ) {
1364 cgroup = *it;
1365 list << accname();
1366 }
1367 cgroup = save_cgroup;
1368 return list;
1369};
1370
1371
1372const QString PPPData::devname()
1373{
1374 QString tmp = readConfig(modemGroup(), MODEMNAME_KEY );
1375 qDebug("PPPData::devname() of %s is %s", modemGroup().latin1(), tmp.latin1());
1376 return tmp;
1377}
1378
1379void PPPData::setDevname(const QString &n) {
1380 // if(!cgroup.isNull()) {
1381// // are we manipulating the default account's name ? then change it, too.
1382// bool def = accname() == defaultAccount();
1383// writeConfig(cgroup, NAME_KEY, n);
1384// if (def)
1385// setDefaultAccount(n);
1386// }
1387 writeConfig(modemGroup(), MODEMNAME_KEY, n );
1388}
1389
1390
1391bool PPPData::setDevice(const QString &dev )
1392{
1393 qDebug("setting device to >%s<", dev.latin1());
1394 QString save_mName = _modemName;
1395 for ( QStringList::Iterator it = deviceList.begin(); it != deviceList.end(); ++it ) {
1396 _modemName = *it;
1397 qDebug("PPPData::setDevice %s is named %s", _modemName.latin1(), devname().latin1() );
1398 qDebug( "iterator %s", (*it).latin1() );
1399 if(devname() == dev) {
1400 qDebug("SUCCESS");
1401 return true;
1402 }
1403
1404 }
1405 _modemName = save_mName;
1406 qDebug("FAILURE");
1407 return false;
1408}
1409
1410bool PPPData::deleteDevice()
1411{
1412 // FIXME: check if this account exists in a config...
1413 Config cfg = PPPData::config();
1414 cfg.setGroup(modemGroup());
1415 cfg.clearGroup();
1416 deviceList.remove(modemGroup());
1417
1418 QString key;
1419 QStringList keys;
1420 for( QMap<QString,QString>::Iterator it = stringEntries.begin();
1421 it != stringEntries.end(); ++it ){
1422 QString val = it.data();
1423 key = it.key();
1424 keys = QStringList::split( "SEPARATOR", key );
1425 if(keys[0]==modemGroup()){
1426 stringEntries.remove( it );
1427 qDebug("deleting >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.latin1() );
1428 }
1429 }
1430 for( QMap<QString,int>::Iterator it = intEntries.begin();
1431 it != intEntries.end(); ++it ){
1432 int val = it.data();
1433 key = it.key();
1434 keys = QStringList::split( "SEPARATOR", key );
1435 if(keys[0]==modemGroup()){
1436 intEntries.remove( it );
1437 qDebug("deleting >%s< key >%s< value >%i<", keys[0].latin1(), keys[1].latin1(), val );
1438 }
1439 }
1440 for( QMap<QString,QStringList>::Iterator it = listEntries.begin();
1441 it != listEntries.end(); ++it ){
1442 QStringList val = it.data();
1443 key = it.key();
1444 if(keys[0]==modemGroup()){
1445 listEntries.remove( it );
1446 sepEntries.remove( key );
1447 qDebug("deleting >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.join("").latin1() );
1448 }
1449 }
1450
1451 return true;
1452
1453}
1454
1455bool PPPData::deleteDevice(const QString &dev)
1456{
1457 if(!setDevice(dev))
1458 return false;
1459
1460 return deleteDevice();
1461}
1462
1463int PPPData::newdevice()
1464{
1465
1466 qDebug("PPPData::newdevice highcount %i",highcountdev);
1467
1468
1469 QString tmp;
1470 tmp.sprintf("%s%i", MODEM_GRP, ++highcountdev);
1471 _modemName = QString(tmp);
1472 deviceList << tmp;
1473 qDebug("PPPData::newdevice() Group: >%s<",cgroup.latin1());
1474 return highcountdev;
1475}
1476
1477int PPPData::copydevice(const QString&)
1478{
1479 return false;
1480}
1481
1482
1483QStringList PPPData::getDevicesNamesList()
1484{
1485 QStringList list;
1486 QString save_mName = _modemName;
1487 qDebug("PPPData::getDevicesNamesList has %s", deviceList.join("---").latin1());
1488 for ( QStringList::Iterator it = deviceList.begin(); it != deviceList.end(); ++it ) {
1489 _modemName = *it;
1490 qDebug("PPPData::getDevicesNamesList adding %s as %s",_modemName.latin1(), devname().latin1());
1491 list << devname();
1492 }
1493 _modemName = save_mName;
1494 return list;
1495};