Diffstat (limited to 'noncore/settings/networksettings/ppp/pppdata.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/pppdata.cpp | 371 |
1 files changed, 282 insertions, 89 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 | |||
@@ -23,15 +23,14 @@ | |||
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> |
@@ -39,29 +38,37 @@ | |||
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 | ||
44 | PPPData::PPPData() | 43 | PPPData::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 | 54 | highcountdev = readNumConfig(GENERAL_GRP, NUMDEVICES_KEY, 0) - 1; | |
55 | if (highcount > MAX_ACCOUNTS) | 55 | Config cfg = config(); |
56 | highcount = MAX_ACCOUNTS; | 56 | cfg.setGroup(GENERAL_GRP); |
57 | 57 | accountList = cfg.readListEntry(ACCOUNT_LIST, ',' ); | |
58 | if(highcount >= 0 && defaultAccount().isEmpty()) { | 58 | deviceList = cfg.readListEntry(DEVICESNAMES_LIST, ',' ); |
59 | setAccountbyIndex(0); | 59 | qDebug("PPPData::PPPData has a accountList %s", accountList.join("---").latin1()); |
60 | setDefaultAccount(accname()); | 60 | qDebug("PPPData::PPPData has a deviceList %s", deviceList.join("---").latin1()); |
61 | } else if(!setAccount(defaultAccount())) | 61 | |
62 | // if (highcount > MAX_ACCOUNTS) | ||
63 | // highcount = MAX_ACCOUNTS; | ||
64 | |||
65 | // if(highcount >= 0 && defaultAccount().isEmpty()) { | ||
66 | // setAccountbyIndex(0); | ||
67 | // setDefaultAccount(accname()); | ||
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 | ||
@@ -78,43 +85,47 @@ Config PPPData::config() | |||
78 | // save configuration | 85 | // save configuration |
79 | // | 86 | // |
80 | void PPPData::save() | 87 | void 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 | ||
@@ -341,27 +352,39 @@ int PPPData::pppdTimeout() { | |||
341 | void PPPData::setpppdTimeout(int n) { | 352 | void PPPData::setpppdTimeout(int n) { |
342 | writeConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, n); | 353 | writeConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, n); |
343 | } | 354 | } |
344 | 355 | ||
345 | 356 | ||
346 | const QString PPPData::modemDevice() { | 357 | const 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 | |||
351 | bool PPPData::setModemDevice(const QString &n) { | 381 | bool 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; | ||
354 | for (int i = 0; devices[i]; i++) | ||
355 | if (devices[i] == n){ | ||
356 | modemDeviceGroup = i; | ||
357 | writeConfig(modemGroup(), MODEMDEV_KEY, n); | 383 | writeConfig(modemGroup(), MODEMDEV_KEY, n); |
358 | ret = true; | 384 | return true; //FIXME |
359 | } | ||
360 | qDebug(ret?"SUCCESS":"FAILURE"); | ||
361 | return ret; | ||
362 | } | 385 | } |
363 | 386 | ||
364 | 387 | ||
365 | const QString PPPData::flowcontrol() { | 388 | const QString PPPData::flowcontrol() { |
366 | return readConfig(modemGroup(), FLOWCONTROL_KEY, "CRTSCTS"); | 389 | return readConfig(modemGroup(), FLOWCONTROL_KEY, "CRTSCTS"); |
367 | } | 390 | } |
@@ -714,95 +737,117 @@ int PPPData::count() const { | |||
714 | return highcount + 1; | 737 | return highcount + 1; |
715 | } | 738 | } |
716 | 739 | ||
717 | 740 | ||
718 | bool PPPData::setAccount(const QString &aname) { | 741 | bool 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; |
745 | qDebug("PPPData::setAccount %s", cgroup.latin1()); | ||
746 | qDebug( "iterator %s", (*it).latin1() ); | ||
722 | if(accname() == aname) { | 747 | if(accname() == aname) { |
723 | caccount = i; | ||
724 | qDebug("SUCCESS"); | 748 | qDebug("SUCCESS"); |
725 | return true; | 749 | return true; |
726 | } | 750 | } |
751 | |||
727 | } | 752 | } |
728 | qDebug("FAILURE"); | 753 | qDebug("FAILURE"); |
729 | return false; | 754 | return false; |
730 | } | 755 | } |
731 | 756 | ||
732 | 757 | /* | |
733 | bool PPPData::setAccountbyIndex(int i) { | 758 | bool 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 | ||
743 | bool PPPData::isUniqueAccname(const QString &n) { | 771 | bool 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() ); |
777 | if(accname() == n && cgroup != save_cgroup) { | ||
778 | cgroup = save_cgroup; | ||
779 | qDebug("SUCCESS"); | ||
749 | return false; | 780 | return false; |
750 | } | 781 | } |
782 | |||
751 | } | 783 | } |
752 | setAccountbyIndex(current); | 784 | cgroup = save_cgroup; |
753 | return true; | 785 | return true; |
754 | } | 786 | } |
755 | 787 | ||
756 | 788 | ||
757 | bool PPPData::deleteAccount() { | 789 | bool 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()); |
792 | for ( QStringList::Iterator it = deviceList.begin(); it != deviceList.end(); ++it ) { | ||
793 | _modemName = *it; | ||
794 | qDebug("PPPData::isUniqueDevname %s == %s", n.latin1() , devname().latin1()); | ||
795 | if(devname() == n && _modemName != save_mName) { | ||
796 | _modemName = save_mName; | ||
797 | qDebug("NOT UNIQUE"); | ||
760 | return false; | 798 | return false; |
799 | } | ||
761 | 800 | ||
762 | // QMap <QString, QString> map; | 801 | } |
763 | // QMap <QString, QString>::Iterator it; | 802 | _modemName = save_mName; |
764 | 803 | return true; | |
765 | // // set all entries of the current account to "" | 804 | } |
766 | // map = config->entryMap(cgroup); | ||
767 | // it = map.begin(); | ||
768 | // while (it != map.end()) { | ||
769 | // config->writeEntry(it.key(), ""); | ||
770 | // it++; | ||
771 | // } | ||
772 | |||
773 | // // shift the succeeding accounts | ||
774 | // for(int i = caccount+1; i <= highcount; i++) { | ||
775 | // setAccountbyIndex(i); | ||
776 | // map = config->entryMap(cgroup); | ||
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--; | 807 | bool 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 | ||
806 | bool PPPData::deleteAccount(const QString &aname) { | 851 | bool PPPData::deleteAccount(const QString &aname) { |
807 | if(!setAccount(aname)) | 852 | if(!setAccount(aname)) |
808 | return false; | 853 | return false; |
@@ -814,33 +859,35 @@ bool PPPData::deleteAccount(const QString &aname) { | |||
814 | 859 | ||
815 | 860 | ||
816 | int PPPData::newaccount() { | 861 | int 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 | ||
830 | int PPPData::copyaccount(int i) { | 877 | int 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++; |
@@ -861,12 +908,13 @@ void PPPData::setAccname(const QString &n) { | |||
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 '&' |
871 | QStringList &PPPData::phonenumbers() { | 919 | QStringList &PPPData::phonenumbers() { |
872 | 920 | ||
@@ -1173,12 +1221,13 @@ void PPPData::setpppdArgument(QStringList &args) { | |||
1173 | writeListConfig(cgroup, PPPDARG_KEY, args); | 1221 | writeListConfig(cgroup, PPPDARG_KEY, args); |
1174 | } | 1222 | } |
1175 | 1223 | ||
1176 | 1224 | ||
1177 | void PPPData::setpppdArgumentDefaults() { | 1225 | void 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, |
@@ -1244,17 +1293,15 @@ int PPPData::pppdError() const { | |||
1244 | void PPPData::setpppdError(int err) { | 1293 | void PPPData::setpppdError(int err) { |
1245 | pppderror = err; | 1294 | pppderror = err; |
1246 | } | 1295 | } |
1247 | 1296 | ||
1248 | QString PPPData::modemGroup() | 1297 | QString 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 | ||
1258 | QMap<QString,QString> PPPData::getConfiguredInterfaces() | 1305 | QMap<QString,QString> PPPData::getConfiguredInterfaces() |
1259 | { | 1306 | { |
1260 | QMap<QString,QString> ifaces; | 1307 | QMap<QString,QString> ifaces; |
@@ -1297,6 +1344,152 @@ void PPPData::setConfiguredInterfaces( QMap<QString,QString> ifaces ) | |||
1297 | */ | 1344 | */ |
1298 | QString PPPData::encodeWord(const QString &s) { | 1345 | QString 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 | |||
1351 | QStringList PPPData::getDevicesList() | ||
1352 | { | ||
1353 | Config cfg("NetworkSetupPPP"); | ||
1354 | cfg.setGroup("Devices_General"); | ||
1355 | return cfg.readListEntry(DEVICES_LIST,DEVICES_LIST_SEP); | ||
1356 | } | ||
1357 | |||
1358 | QStringList 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 | |||
1372 | const 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 | |||
1379 | void 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 | |||
1391 | bool 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 | |||
1410 | bool 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 | |||
1455 | bool PPPData::deleteDevice(const QString &dev) | ||
1456 | { | ||
1457 | if(!setDevice(dev)) | ||
1458 | return false; | ||
1459 | |||
1460 | return deleteDevice(); | ||
1461 | } | ||
1462 | |||
1463 | int 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 | |||
1477 | int PPPData::copydevice(const QString&) | ||
1478 | { | ||
1479 | return false; | ||
1480 | } | ||
1481 | |||
1482 | |||
1483 | QStringList 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 | }; | ||