2 * kPPP: A pppd front end for the KDE project
6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
10 * Copyright (C) 1997 Jay Painter
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
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
24 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 #include <kconfiggroup.h>
33 #include <kmessagebox.h>
34 #include <kapplication.h>
35 #include <kglobalsettings.h>
44 accounthighcount(-1), // start out with no account entries
45 caccount(-1), // set the current account index also
46 modemhighcount(-1), // start out with no modem entries
47 cmodem(-1), // set the current modem index also
48 suidprocessid(-1), // process ID of setuid child
57 // open configuration file
59 bool PPPData::open() {
61 config
= KGlobal::config();
63 if (config
->accessMode() == KConfig::NoAccess
) {
64 KMessageBox::error(0L,
65 i18n("The application-specific config file could not "
66 "be opened in either read-write or read-only mode.\n"
67 "The superuser might have to change its ownership "
68 "by issuing the following command in your home directory:\n"
69 "chown {YourUsername} .kde/share/config/kppprc"),
74 // don't expand shell variables
75 accounthighcount
= readNumConfig(GENERAL_GRP
, NUMACCOUNTS_KEY
, 0) - 1;
77 if (accounthighcount
> MAX_ACCOUNTS
)
78 accounthighcount
= MAX_ACCOUNTS
;
80 if(accounthighcount
>= 0 && defaultAccount().isEmpty()) {
82 setDefaultAccount(accname());
83 } else if(!setAccount(defaultAccount()))
84 setDefaultAccount(accname());
86 modemhighcount
= readNumConfig(GENERAL_GRP
, NUMMODEMS_KEY
, 0) - 1;
88 if (modemhighcount
> MAX_MODEMS
)
89 modemhighcount
= MAX_MODEMS
;
91 // if there aren't any ModemX set and exists the [Modem] group,
92 // probably it's the first time we are using this new version
93 // with multiple modem profiles.
94 // So we copy the old [Modem] to the new [Modem0]
95 if(modemhighcount
< 0 && defaultModem().isEmpty() && config
->hasGroup("Modem"))
97 KConfigGroup
cg( config
, "Modem");
99 QMap
<QString
, QString
> map
= config
->entryMap("Modem");
100 QMap
<QString
, QString
>::ConstIterator it
= map
.begin();
104 while (it
!= map
.end()) {
105 KConfigGroup
cg2( config
, cmodemgroup
);
106 cg2
.writeEntry(it
.key(), *it
);
110 QString
newname("Modem0");
114 if(modemhighcount
>= 0 && defaultModem().isEmpty()) {
116 setDefaultModem(modname());
117 } else if(!setModem(defaultModem()))
118 setDefaultModem(modname());
121 // start out with internal debugging disabled
122 // the user is still free to specify `debug' on his own
125 ::pppdVersion(&pppdVer
, &pppdMod
, &pppdPatch
);
132 // save configuration
134 void PPPData::save() {
137 writeConfig(GENERAL_GRP
, NUMACCOUNTS_KEY
, accountCount());
138 writeConfig(GENERAL_GRP
, NUMMODEMS_KEY
, modemCount());
148 void PPPData::cancel() {
151 config
->markAsClean();
152 config
->reparseConfiguration();
158 // currently differentiates between READWRITE and NONE only
159 int PPPData::access() const {
161 return config
->accessMode();
165 // functions to read/write date to configuration file
166 QString
PPPData::readConfig(const QString
&group
, const QString
&key
,
167 const QString
&defvalue
= "")
170 return config
->group(group
).readEntry(key
, defvalue
);
176 int PPPData::readNumConfig(const QString
&group
, const QString
&key
,
179 return config
->group(group
).readEntry(key
, defvalue
);
186 bool PPPData::readListConfig(const QString
&group
, const QString
&key
,
190 list
= config
->group(group
).readEntry(key
, QStringList());
197 void PPPData::writeConfig(const QString
&group
, const QString
&key
,
198 const QString
&value
) {
200 config
->group(group
).writeEntry(key
, value
);
205 void PPPData::writeConfig(const QString
&group
, const QString
&key
, int value
) {
207 config
->group(group
).writeEntry(key
, value
);
212 void PPPData::writeListConfig(const QString
&group
, const QString
&key
,
215 config
->group(group
).writeEntry(key
, list
);
221 // functions to set/return general information
223 QString
PPPData::password() const {
228 void PPPData::setPassword(const QString
&pw
) {
233 const QString
PPPData::defaultAccount() {
234 return readConfig(GENERAL_GRP
, DEFAULTACCOUNT_KEY
);
238 void PPPData::setDefaultAccount(const QString
&n
) {
239 writeConfig(GENERAL_GRP
, DEFAULTACCOUNT_KEY
, n
);
241 //now set the current account index to the default account
242 setAccount(defaultAccount());
246 const QString
PPPData::defaultModem() {
247 return readConfig(GENERAL_GRP
, DEFAULTMODEM_KEY
);
251 void PPPData::setDefaultModem(const QString
&n
) {
252 writeConfig(GENERAL_GRP
, DEFAULTMODEM_KEY
, n
);
254 //now set the current modem index to the default modem
255 setModem(defaultModem());
258 bool PPPData::get_show_clock_on_caption() {
259 return (bool) readNumConfig(GENERAL_GRP
, SHOWCLOCK_KEY
, true);
263 void PPPData::set_show_clock_on_caption(bool set
) {
264 writeConfig(GENERAL_GRP
, SHOWCLOCK_KEY
, (int) set
);
268 bool PPPData::get_xserver_exit_disconnect() {
269 return (bool) readNumConfig(GENERAL_GRP
, DISCONNECT_KEY
, true);
272 bool PPPData::get_redial_on_nocarrier() {
273 return (bool) readNumConfig(GENERAL_GRP
, REDIALONNOCARR_KEY
, false);
277 void PPPData::setPPPDebug(bool set
) {
278 writeConfig(GENERAL_GRP
, PPP_DEBUG_OPTION
, (int)set
);
282 bool PPPData::getPPPDebug() {
283 return (bool)readNumConfig(GENERAL_GRP
, PPP_DEBUG_OPTION
, false);
287 void PPPData::set_xserver_exit_disconnect(bool set
) {
288 writeConfig(GENERAL_GRP
, DISCONNECT_KEY
, (int) set
);
291 void PPPData::set_redial_on_nocarrier(bool set
) {
292 writeConfig(GENERAL_GRP
, REDIALONNOCARR_KEY
, (int) set
);
296 bool PPPData::quit_on_disconnect() {
297 return (bool) readNumConfig(GENERAL_GRP
, QUITONDISCONNECT_KEY
, false);
301 void PPPData::set_quit_on_disconnect(bool set
) {
302 writeConfig(GENERAL_GRP
, QUITONDISCONNECT_KEY
, (int) set
);
306 bool PPPData::get_show_log_window() {
307 return (bool) readNumConfig (GENERAL_GRP
, SHOWLOGWIN_KEY
, false);
311 void PPPData::set_show_log_window(bool set
) {
312 writeConfig(GENERAL_GRP
, SHOWLOGWIN_KEY
, (int) set
);
316 bool PPPData::automatic_redial() {
317 return (bool) readNumConfig(GENERAL_GRP
, AUTOREDIAL_KEY
, false);
321 void PPPData::set_automatic_redial(bool set
) {
322 writeConfig(GENERAL_GRP
, AUTOREDIAL_KEY
, (int) set
);
326 bool PPPData::get_iconify_on_connect() {
327 return (bool) readNumConfig(GENERAL_GRP
, ICONIFY_ON_CONNECT_KEY
, true);
331 void PPPData::set_iconify_on_connect(bool set
) {
332 writeConfig(GENERAL_GRP
, ICONIFY_ON_CONNECT_KEY
, (int) set
);
336 bool PPPData::get_dock_into_panel() {
337 return (bool) readNumConfig(GENERAL_GRP
, DOCKING_KEY
, false);
341 void PPPData::set_dock_into_panel(bool set
) {
342 writeConfig(GENERAL_GRP
, DOCKING_KEY
, (int) set
);
346 QString
PPPData::pppdVersion() {
347 return QString("%1.%2.%3").arg(pppdVer
).arg(pppdMod
).arg(pppdPatch
);
350 bool PPPData::pppdVersionMin(int ver
, int mod
, int patch
) {
351 // check if pppd version fulfills minimum requirement
352 return (pppdVer
> ver
353 || (pppdVer
== ver
&& pppdMod
> mod
)
354 || (pppdVer
== ver
&& pppdMod
== mod
&& pppdPatch
>= patch
));
357 int PPPData::pppdTimeout() {
358 return readNumConfig(GENERAL_GRP
, PPPDTIMEOUT_KEY
, PPPD_TIMEOUT
);
362 void PPPData::setpppdTimeout(int n
) {
363 writeConfig(GENERAL_GRP
, PPPDTIMEOUT_KEY
, n
);
367 // functions to set/return modem information
371 //returns number of modems
372 int PPPData::modemCount() const {
373 return modemhighcount
+ 1;
377 bool PPPData::setModem(const QString
&mname
) {
378 for(int i
= 0; i
<= modemhighcount
; i
++) {
380 if(modname() == mname
) {
389 bool PPPData::setModemByIndex(int i
) {
390 if(i
>= 0 && i
<= modemhighcount
) {
392 cmodemgroup
.sprintf("%s%i", MODEM_GRP
, i
);
399 bool PPPData::isUniqueModname(const QString
&n
) {
400 int current
= cmodem
;
401 for(int i
=0; i
<= modemhighcount
; i
++) {
403 if(modname() == n
&& i
!= current
) {
404 setModemByIndex(current
);
408 setModemByIndex(current
);
413 bool PPPData::deleteModem() {
417 QMap
<QString
, QString
> map
;
418 QMap
<QString
, QString
>::Iterator it
;
420 // set all entries of the current modem to ""
421 map
= config
->entryMap(cmodemgroup
);
423 while (it
!= map
.end()) {
424 config
->group(cmodemgroup
).writeEntry(it
.key(), "");
428 // shift the succeeding modems
429 for(int i
= cmodem
+1; i
<= modemhighcount
; i
++) {
431 map
= config
->entryMap(cmodemgroup
);
433 setModemByIndex(i
-1);
434 KConfigGroup
cg(config
, cmodemgroup
);
435 while (it
!= map
.end()) {
436 cg
.writeEntry(it
.key(), *it
);
441 // make sure the top modem is cleared
442 setModemByIndex(modemhighcount
);
443 map
= config
->entryMap(cmodemgroup
);
445 KConfigGroup
cg2(config
, cmodemgroup
);
446 while (!it
.key().isNull()) {
447 cg2
.writeEntry(it
.key(), "");
452 if(cmodem
> modemhighcount
)
453 cmodem
= modemhighcount
;
455 setModemByIndex(cmodem
);
460 bool PPPData::deleteModem(const QString
&mname
) {
470 int PPPData::newmodem() {
472 if(!config
|| modemhighcount
>= MAX_MODEMS
)
476 setModemByIndex(modemhighcount
);
478 setpppdArgumentDefaults();
483 int PPPData::copymodem(int i
) {
485 KConfigGroup group
= config
->group(cmodemgroup
);
487 if(modemhighcount
>= MAX_MODEMS
)
492 QMap
<QString
, QString
> map
= group
.entryMap();
493 QMap
<QString
, QString
>::ConstIterator it
= map
.begin();
495 QString newname
= i18n("%1_copy", modname());
499 while (it
!= map
.end()) {
500 group
= config
->group(cmodemgroup
);
501 group
.writeEntry(it
.key(), *it
);
511 const QString
PPPData::modname() {
512 return readConfig(cmodemgroup
, MOD_NAME_KEY
);
515 void PPPData::setModname(const QString
&n
) {
516 if(!cmodemgroup
.isNull()) {
517 // are we manipulating the default modem's name ? then change it, too.
518 bool def
= modname() == defaultModem();
519 writeConfig(cmodemgroup
, MOD_NAME_KEY
, n
);
528 const QString
PPPData::modemDevice() {
529 return readConfig (cmodemgroup
, MODEMDEV_KEY
, devices
[DEV_DEFAULT
]);
533 void PPPData::setModemDevice(const QString
&n
) {
534 writeConfig(cmodemgroup
, MODEMDEV_KEY
, n
);
538 QString
PPPData::flowcontrol() {
539 // keep default value in sync with general.cpp
540 return readConfig(cmodemgroup
, FLOWCONTROL_KEY
, i18n("Hardware [CRTSCTS]"));
544 void PPPData::setFlowcontrol(const QString
&n
) {
545 writeConfig(cmodemgroup
, FLOWCONTROL_KEY
, n
);
549 const QString
PPPData::speed() {
550 QString s
= readConfig(cmodemgroup
, SPEED_KEY
, "57600");
551 // undo the damage of a bug in former versions. It left an empty Speed=
552 // entry in kppprc. kppp did set the serial port to 57600 as default but
553 // pppd wouldn't receive the speed via the command line.
560 void PPPData::setSpeed(const QString
&n
) {
561 writeConfig(cmodemgroup
, SPEED_KEY
, n
);
566 void PPPData::setUseCDLine(const int n
) {
567 writeConfig(cmodemgroup
,USECDLINE_KEY
,n
);
571 int PPPData::UseCDLine() {
572 return readNumConfig(cmodemgroup
,USECDLINE_KEY
,0);
576 const QString
PPPData::modemEscapeStr() {
577 return readConfig(cmodemgroup
,ESCAPESTR_KEY
,"+++");
581 void PPPData::setModemEscapeStr(const QString
&n
) {
582 writeConfig(cmodemgroup
,ESCAPESTR_KEY
,n
);
586 const QString
PPPData::modemEscapeResp() {
587 return readConfig(cmodemgroup
,ESCAPERESP_KEY
,"OK");
591 void PPPData::setModemEscapeResp(const QString
&n
) {
592 writeConfig(cmodemgroup
,ESCAPERESP_KEY
,n
);
596 int PPPData::modemEscapeGuardTime() {
597 return readNumConfig(cmodemgroup
,ESCAPEGUARDTIME_KEY
,50);
601 void PPPData::setModemEscapeGuardTime(int n
) {
602 writeConfig(cmodemgroup
,ESCAPEGUARDTIME_KEY
,n
);
606 bool PPPData::modemLockFile() {
607 return readNumConfig(cmodemgroup
, LOCKFILE_KEY
, 1);
611 void PPPData::setModemLockFile(bool set
) {
612 writeConfig(cmodemgroup
, LOCKFILE_KEY
, set
);
616 int PPPData::modemTimeout() {
617 return readNumConfig(cmodemgroup
, TIMEOUT_KEY
, MODEM_TIMEOUT
);
621 void PPPData::setModemTimeout(int n
) {
622 writeConfig(cmodemgroup
, TIMEOUT_KEY
, n
);
626 int PPPData::modemToneDuration() {
627 return readNumConfig(cmodemgroup
, TONEDURATION_KEY
,MODEM_TONEDURATION
);
631 void PPPData::setModemToneDuration(int n
) {
632 writeConfig(cmodemgroup
, TONEDURATION_KEY
, n
);
636 int PPPData::busyWait() {
637 return readNumConfig(cmodemgroup
, BUSYWAIT_KEY
, BUSY_WAIT
);
641 void PPPData::setbusyWait(int n
) {
642 writeConfig(cmodemgroup
, BUSYWAIT_KEY
, n
);
647 //Advanced "Modem" dialog
649 // defaults: InitString=ATZ, InitString1="" etc.
650 const QString
PPPData::modemInitStr(int i
) {
651 assert(i
>= 0 && i
< NumInitStrings
);
653 return readConfig(cmodemgroup
, INITSTR_KEY
, "ATZ");
655 return readConfig(cmodemgroup
, INITSTR_KEY
+ QString::number(i
), "");
659 void PPPData::setModemInitStr(int i
, const QString
&n
) {
660 assert(i
>= 0 && i
< NumInitStrings
);
661 QString k
= INITSTR_KEY
+ (i
> 0 ? QString::number(i
) : "");
662 writeConfig(cmodemgroup
, k
, n
);
666 const QString
PPPData::modemInitResp() {
667 return readConfig(cmodemgroup
, INITRESP_KEY
, "OK");
671 void PPPData::setModemInitResp(const QString
&n
) {
672 writeConfig(cmodemgroup
, INITRESP_KEY
, n
);
676 int PPPData::modemPreInitDelay() {
677 return readNumConfig(cmodemgroup
, PREINITDELAY_KEY
, 50);
681 void PPPData::setModemPreInitDelay(int n
) {
682 writeConfig(cmodemgroup
, PREINITDELAY_KEY
, n
);
686 int PPPData::modemInitDelay() {
687 return readNumConfig(cmodemgroup
, INITDELAY_KEY
, 50);
691 void PPPData::setModemInitDelay(int n
) {
692 writeConfig(cmodemgroup
, INITDELAY_KEY
, n
);
695 QString
PPPData::modemNoDialToneDetectionStr() {
696 return readConfig(cmodemgroup
, NODTDETECT_KEY
, "ATX3");
699 void PPPData::setModemNoDialToneDetectionStr(const QString
&n
) {
700 writeConfig(cmodemgroup
, NODTDETECT_KEY
, n
);
703 const QString
PPPData::modemDialStr() {
704 return readConfig(cmodemgroup
, DIALSTR_KEY
, "ATDT");
708 void PPPData::setModemDialStr(const QString
&n
) {
709 writeConfig(cmodemgroup
, DIALSTR_KEY
, n
);
713 const QString
PPPData::modemConnectResp() {
714 return readConfig(cmodemgroup
, CONNECTRESP_KEY
, "CONNECT");
718 void PPPData::setModemConnectResp(const QString
&n
) {
719 writeConfig(cmodemgroup
, CONNECTRESP_KEY
, n
);
723 const QString
PPPData::modemBusyResp() {
724 return readConfig(cmodemgroup
, BUSYRESP_KEY
, "BUSY");
728 void PPPData::setModemBusyResp(const QString
&n
) {
729 writeConfig(cmodemgroup
, BUSYRESP_KEY
, n
);
733 const QString
PPPData::modemNoCarrierResp() {
734 return readConfig(cmodemgroup
, NOCARRIERRESP_KEY
, "NO CARRIER");
738 void PPPData::setModemNoCarrierResp(const QString
&n
) {
739 writeConfig(cmodemgroup
, NOCARRIERRESP_KEY
, n
);
743 const QString
PPPData::modemNoDialtoneResp() {
744 return readConfig(cmodemgroup
, NODIALTONERESP_KEY
, "NO DIALTONE");
748 void PPPData::setModemNoDialtoneResp(const QString
&n
) {
749 writeConfig(cmodemgroup
, NODIALTONERESP_KEY
, n
);
753 const QString
PPPData::modemHangupStr() {
754 return readConfig(cmodemgroup
, HANGUPSTR_KEY
, "+++ATH");
757 void PPPData::setModemHangupStr(const QString
&n
) {
758 writeConfig(cmodemgroup
, HANGUPSTR_KEY
, n
);
762 const QString
PPPData::modemHangupResp() {
763 return readConfig(cmodemgroup
, HANGUPRESP_KEY
, "OK");
766 void PPPData::setModemHangupResp(const QString
&n
) {
767 writeConfig(cmodemgroup
, HANGUPRESP_KEY
, n
);
771 QString
PPPData::modemDLPResp() {
772 return readConfig(cmodemgroup
, DLPRESP_KEY
, "DIGITAL LINE DETECTED");
775 void PPPData::setModemDLPResp(const QString
&n
) {
776 writeConfig(cmodemgroup
, DLPRESP_KEY
, n
);
782 const QString
PPPData::modemAnswerStr() {
783 return readConfig(cmodemgroup
, ANSWERSTR_KEY
, "ATA");
787 QString
PPPData::volumeOff() {
788 return readConfig(cmodemgroup
, VOLUME_OFF
, "M0L0");
792 void PPPData::setVolumeOff(const QString
&s
) {
793 writeConfig(cmodemgroup
, VOLUME_OFF
, s
);
797 QString
PPPData::volumeMedium() {
798 return readConfig(cmodemgroup
, VOLUME_MEDIUM
, "M1L1");
802 void PPPData::setVolumeMedium(const QString
&s
) {
803 writeConfig(cmodemgroup
, VOLUME_MEDIUM
, s
);
807 QString
PPPData::volumeHigh() {
808 QString tmp
= readConfig(cmodemgroup
, VOLUME_HIGH
, "M1L3");
815 void PPPData::setVolumeHigh(const QString
&s
) {
816 writeConfig(cmodemgroup
, VOLUME_HIGH
, s
);
820 QString
PPPData::volumeInitString() {
841 int PPPData::volume() {
842 return readNumConfig(cmodemgroup
, VOLUME_KEY
, 1);
846 void PPPData::setVolume(int i
) {
847 writeConfig(cmodemgroup
, VOLUME_KEY
, i
);
850 int PPPData::waitForDialTone() {
851 return readNumConfig(cmodemgroup
, DIALTONEWAIT_KEY
, 1);
854 void PPPData::setWaitForDialTone(int i
) {
855 writeConfig(cmodemgroup
, DIALTONEWAIT_KEY
, i
);
858 void PPPData::setModemAnswerStr(const QString
&n
) {
859 writeConfig(cmodemgroup
, ANSWERSTR_KEY
, n
);
863 const QString
PPPData::modemRingResp() {
864 return readConfig(cmodemgroup
, RINGRESP_KEY
, "RING");
868 void PPPData::setModemRingResp(const QString
&n
) {
869 writeConfig(cmodemgroup
, RINGRESP_KEY
, n
);
873 const QString
PPPData::modemAnswerResp() {
874 return readConfig(cmodemgroup
, ANSWERRESP_KEY
, "CONNECT");
878 void PPPData::setModemAnswerResp(const QString
&n
) {
879 writeConfig(cmodemgroup
, ANSWERRESP_KEY
, n
);
883 const QString
PPPData::enter() {
884 return readConfig(cmodemgroup
, ENTER_KEY
, "CR");
888 void PPPData::setEnter(const QString
&n
) {
889 writeConfig(cmodemgroup
, ENTER_KEY
, n
);
894 // functions to set/return account information
897 //returns number of accounts
898 int PPPData::accountCount() const {
899 return accounthighcount
+ 1;
903 bool PPPData::setAccount(const QString
&aname
) {
904 for(int i
= 0; i
<= accounthighcount
; i
++) {
905 setAccountByIndex(i
);
906 if(accname() == aname
) {
915 bool PPPData::setAccountByIndex(int i
) {
916 if(i
>= 0 && i
<= accounthighcount
) {
918 caccountgroup
.sprintf("%s%i", ACCOUNT_GRP
, i
);
925 bool PPPData::isUniqueAccname(const QString
&n
) {
928 int current
= caccount
;
929 for(int i
=0; i
<= accounthighcount
; i
++) {
930 setAccountByIndex(i
);
931 if(accname() == n
&& i
!= current
) {
932 setAccountByIndex(current
);
936 setAccountByIndex(current
);
941 bool PPPData::deleteAccount() {
945 QMap
<QString
, QString
> map
;
946 QMap
<QString
, QString
>::Iterator it
;
948 // set all entries of the current account to ""
949 map
= config
->entryMap(caccountgroup
);
951 KConfigGroup
cg(config
,caccountgroup
);
952 while (it
!= map
.end()) {
953 cg
.writeEntry(it
.key(), "");
957 // shift the succeeding accounts
958 for(int i
= caccount
+1; i
<= accounthighcount
; i
++) {
959 setAccountByIndex(i
);
960 map
= config
->entryMap(caccountgroup
);
962 setAccountByIndex(i
-1);
963 KConfigGroup
cg2(config
,caccountgroup
);
964 while (it
!= map
.end()) {
965 cg2
.writeEntry(it
.key(), *it
);
970 // make sure the top account is cleared
971 setAccountByIndex(accounthighcount
);
972 map
= config
->entryMap(caccountgroup
);
974 KConfigGroup
cg3(config
,caccountgroup
);
975 while (it
!= map
.end() && !it
.key().isNull()) {
976 cg3
.writeEntry(it
.key(), "");
981 if(caccount
> accounthighcount
)
982 caccount
= accounthighcount
;
984 setAccountByIndex(caccount
);
989 bool PPPData::deleteAccount(const QString
&aname
) {
990 if(!setAccount(aname
))
999 int PPPData::newaccount() {
1001 if(!config
|| accounthighcount
>= MAX_ACCOUNTS
)
1005 setAccountByIndex(accounthighcount
);
1007 setpppdArgumentDefaults();
1012 int PPPData::copyaccount(int i
) {
1014 if(accounthighcount
>= MAX_ACCOUNTS
)
1017 setAccountByIndex(i
);
1019 QMap
<QString
, QString
> map
= config
->entryMap(caccountgroup
);
1020 QMap
<QString
, QString
>::ConstIterator it
= map
.begin();
1022 QString newname
= i18n("%1_copy", accname());
1026 while (it
!= map
.end()) {
1027 KConfigGroup
cg2 ( config
, caccountgroup
);
1028 cg2
.writeEntry(it
.key(), *it
);
1032 setAccname(newname
);
1038 const QString
PPPData::accname() {
1039 return readConfig(caccountgroup
, ACC_NAME_KEY
);
1042 void PPPData::setAccname(const QString
&n
) {
1043 if(!caccountgroup
.isNull()) {
1044 // are we manipulating the default account's name ? then change it, too.
1045 bool def
= accname() == defaultAccount();
1046 writeConfig(caccountgroup
, ACC_NAME_KEY
, n
);
1048 setDefaultAccount(n
);
1053 #define SEPARATOR_CHAR ':'
1054 QStringList
&PPPData::phonenumbers() {
1055 phonelist
= readConfig(caccountgroup
, PHONENUMBER_KEY
).split(SEPARATOR_CHAR
);
1060 const QString
PPPData::phonenumber() {
1061 return readConfig(caccountgroup
, PHONENUMBER_KEY
);
1065 void PPPData::setPhonenumber(const QString
&n
) {
1066 writeConfig(caccountgroup
, PHONENUMBER_KEY
, n
);
1070 const QString
PPPData::dialPrefix() {
1071 return readConfig(caccountgroup
, DIAL_PREFIX_KEY
, "");
1075 void PPPData::setDialPrefix(const QString
&s
) {
1076 writeConfig(caccountgroup
, DIAL_PREFIX_KEY
, s
);
1080 int PPPData::authMethod() {
1081 return readNumConfig(caccountgroup
, AUTH_KEY
, 0);
1085 void PPPData::setAuthMethod(int value
) {
1086 writeConfig(caccountgroup
, AUTH_KEY
, value
);
1090 const QString
PPPData::storedUsername() {
1091 return readConfig(caccountgroup
, STORED_USERNAME_KEY
, "");
1095 void PPPData::setStoredUsername(const QString
&b
) {
1096 writeConfig(caccountgroup
, STORED_USERNAME_KEY
, b
);
1100 const QString
PPPData::storedPassword() {
1101 return readConfig(caccountgroup
, STORED_PASSWORD_KEY
, "");
1105 void PPPData::setStoredPassword(const QString
&b
) {
1106 writeConfig(caccountgroup
, STORED_PASSWORD_KEY
, b
);
1110 bool PPPData::storePassword() {
1111 return (bool)readNumConfig(caccountgroup
, STORE_PASSWORD_KEY
, 1);
1114 int PPPData::callbackType() {
1115 return readNumConfig(caccountgroup
, CALLBACK_TYPE_KEY
, 0);
1118 void PPPData::setCallbackType(int value
) {
1119 writeConfig(caccountgroup
, CALLBACK_TYPE_KEY
, value
);
1122 QString
PPPData::callbackPhone() {
1123 return readConfig(caccountgroup
, CALLBACK_PHONE_KEY
, "");
1126 void PPPData::setCallbackPhone(const QString
&b
) {
1127 writeConfig(caccountgroup
, CALLBACK_PHONE_KEY
, b
);
1130 bool PPPData::waitCallback() {
1131 return waitcallback
;
1134 void PPPData::setWaitCallback(bool value
) {
1135 waitcallback
= value
;
1138 const QString
PPPData::command_before_connect() {
1139 return readConfig(caccountgroup
, BEFORE_CONNECT_KEY
);
1143 void PPPData::setCommand_before_connect(const QString
&n
) {
1144 writeConfig(caccountgroup
, BEFORE_CONNECT_KEY
, n
);
1148 void PPPData::setStorePassword(bool b
) {
1149 writeConfig(caccountgroup
, STORE_PASSWORD_KEY
, (int)b
);
1153 const QString
PPPData::command_on_connect() {
1154 return readConfig(caccountgroup
, COMMAND_KEY
);
1158 void PPPData::setCommand_on_connect(const QString
&n
) {
1159 writeConfig(caccountgroup
, COMMAND_KEY
, n
);
1163 const QString
PPPData::command_on_disconnect() {
1164 return readConfig(caccountgroup
, DISCONNECT_COMMAND_KEY
);
1168 void PPPData::setCommand_on_disconnect(const QString
&n
) {
1169 writeConfig(caccountgroup
, DISCONNECT_COMMAND_KEY
, n
);
1173 const QString
PPPData::command_before_disconnect() {
1174 return readConfig(caccountgroup
, BEFORE_DISCONNECT_KEY
);
1178 void PPPData::setCommand_before_disconnect(const QString
&n
) {
1179 writeConfig(caccountgroup
, BEFORE_DISCONNECT_KEY
, n
);
1183 const QString
PPPData::ipaddr() {
1184 return readConfig(caccountgroup
, IPADDR_KEY
);
1188 void PPPData::setIpaddr(const QString
&n
) {
1189 writeConfig(caccountgroup
, IPADDR_KEY
, n
);
1193 const QString
PPPData::subnetmask() {
1194 return readConfig(caccountgroup
, SUBNETMASK_KEY
);
1198 void PPPData::setSubnetmask(const QString
&n
) {
1199 writeConfig(caccountgroup
, SUBNETMASK_KEY
, n
);
1203 bool PPPData::autoname() {
1204 return (bool) readNumConfig(caccountgroup
, AUTONAME_KEY
, false);
1208 void PPPData::setAutoname(bool set
) {
1209 writeConfig(caccountgroup
, AUTONAME_KEY
, (int) set
);
1213 bool PPPData::AcctEnabled() {
1214 return (bool) readNumConfig(caccountgroup
, ACCTENABLED_KEY
, false);
1218 void PPPData::setAcctEnabled(bool set
) {
1219 writeConfig(caccountgroup
, ACCTENABLED_KEY
, (int) set
);
1223 int PPPData::VolAcctEnabled() {
1224 return readNumConfig(caccountgroup
, VOLACCTENABLED_KEY
, 0);
1228 void PPPData::setVolAcctEnabled(int set
) {
1229 writeConfig(caccountgroup
, VOLACCTENABLED_KEY
, set
);
1233 const QString
PPPData::gateway() {
1234 return readConfig(caccountgroup
, GATEWAY_KEY
);
1238 void PPPData::setGateway(const QString
&n
) {
1239 writeConfig(caccountgroup
, GATEWAY_KEY
, n
);
1243 bool PPPData::defaultroute() {
1244 // default route is by default 'on'.
1245 return (bool) readNumConfig(caccountgroup
, DEFAULTROUTE_KEY
, true);
1249 void PPPData::setDefaultroute(bool set
) {
1250 writeConfig(caccountgroup
, DEFAULTROUTE_KEY
, (int) set
);
1254 bool PPPData::autoDNS() {
1255 bool set
= (bool) readNumConfig(caccountgroup
, AUTODNS_KEY
, true);
1256 return (set
&& gpppdata
.pppdVersionMin(2, 3, 7));
1260 void PPPData::setAutoDNS(bool set
) {
1261 writeConfig(caccountgroup
, AUTODNS_KEY
, (int) set
);
1265 void PPPData::setExDNSDisabled(bool set
) {
1266 writeConfig(caccountgroup
, EXDNSDISABLED_KEY
, (int) set
);
1270 bool PPPData::exDNSDisabled() {
1271 return (bool) readNumConfig(caccountgroup
, EXDNSDISABLED_KEY
,0);
1275 QStringList
&PPPData::dns() {
1276 static QStringList dnslist
;
1278 readListConfig(caccountgroup
, DNS_KEY
, dnslist
);
1279 while(dnslist
.count() > MAX_DNS_ENTRIES
)
1280 dnslist
.removeAll(dnslist
.last());
1286 void PPPData::setDns(QStringList
&list
) {
1287 writeListConfig(caccountgroup
, DNS_KEY
, list
);
1291 const QString
PPPData::domain() {
1292 return readConfig(caccountgroup
, DOMAIN_KEY
);
1296 void PPPData::setDomain(const QString
&n
) {
1297 writeConfig(caccountgroup
, DOMAIN_KEY
, n
);
1301 QStringList
&PPPData::scriptType() {
1302 static QStringList typelist
;
1304 readListConfig(caccountgroup
, SCRIPTCOM_KEY
, typelist
);
1305 while(typelist
.count() > MAX_SCRIPT_ENTRIES
)
1306 typelist
.removeAll(typelist
.last());
1312 void PPPData::setScriptType(QStringList
&list
) {
1313 writeListConfig(caccountgroup
, SCRIPTCOM_KEY
, list
);
1317 QStringList
&PPPData::script() {
1318 static QStringList scriptlist
;
1320 readListConfig(caccountgroup
, SCRIPTARG_KEY
, scriptlist
);
1321 while(scriptlist
.count() > MAX_SCRIPT_ENTRIES
)
1322 scriptlist
.removeAll(scriptlist
.last());
1328 void PPPData::setScript(QStringList
&list
) {
1329 writeListConfig(caccountgroup
, SCRIPTARG_KEY
, list
);
1333 const QString
PPPData::accountingFile() {
1334 return readConfig(caccountgroup
, ACCTFILE_KEY
);
1338 void PPPData::setAccountingFile(const QString
&n
) {
1339 writeConfig(caccountgroup
, ACCTFILE_KEY
, n
);
1343 const QString
PPPData::totalCosts() {
1344 return readConfig(caccountgroup
, TOTALCOSTS_KEY
);
1348 void PPPData::setTotalCosts(const QString
&n
) {
1349 writeConfig(caccountgroup
, TOTALCOSTS_KEY
, n
);
1353 int PPPData::totalBytes() {
1354 return readNumConfig(caccountgroup
, TOTALBYTES_KEY
, 0);
1357 void PPPData::setTotalBytes(int n
) {
1358 writeConfig(caccountgroup
, TOTALBYTES_KEY
, n
);
1362 QStringList
&PPPData::pppdArgument() {
1363 static QStringList arglist
;
1365 while(arglist
.count() > MAX_PPPD_ARGUMENTS
)
1366 arglist
.removeAll(arglist
.last());
1367 readListConfig(caccountgroup
, PPPDARG_KEY
, arglist
);
1373 void PPPData::setpppdArgument(QStringList
&args
) {
1374 writeListConfig(caccountgroup
, PPPDARG_KEY
, args
);
1378 void PPPData::setpppdArgumentDefaults() {
1380 setpppdArgument(arg
);
1385 void PPPData::setGraphingOptions(bool enable
,
1392 KConfigGroup group
= config
->group(GRAPH_GRP
);
1393 group
.writeEntry(GENABLED
, enable
);
1394 group
.writeEntry(GCOLOR_BG
, bg
);
1395 group
.writeEntry(GCOLOR_TEXT
, text
);
1396 group
.writeEntry(GCOLOR_IN
, in
);
1397 group
.writeEntry(GCOLOR_OUT
, out
);
1401 void PPPData::graphingOptions(bool &enable
,
1410 KConfigGroup group
= config
->group(GRAPH_GRP
);
1411 enable
= group
.readEntry(GENABLED
,true);
1413 bg
= group
.readEntry(GCOLOR_BG
, c
);
1415 text
= group
.readEntry(GCOLOR_TEXT
, c
);
1417 in
= group
.readEntry(GCOLOR_IN
, c
);
1419 out
= group
.readEntry(GCOLOR_OUT
, c
);
1424 bool PPPData::graphingEnabled() {
1426 return config
->group(GRAPH_GRP
).readEntry(GENABLED
, true);
1434 //functions to change/set the child pppd process info
1436 bool PPPData::pppdRunning() const {
1437 return pppdisrunning
;
1440 void PPPData::setpppdRunning(bool set
) {
1441 pppdisrunning
= set
;
1444 int PPPData::pppdError() const {
1448 void PPPData::setpppdError(int err
) {
1456 void PPPData::winPosConWin(int& p_x
, int& p_y
) {
1457 QRect desk
= KGlobalSettings::splashScreenDesktopGeometry();
1458 p_x
= readNumConfig(WINPOS_GRP
, WINPOS_CONWIN_X
, desk
.center().x()-160);
1459 p_y
= readNumConfig(WINPOS_GRP
, WINPOS_CONWIN_Y
, desk
.center().y()-55);
1462 void PPPData::setWinPosConWin(int p_x
, int p_y
) {
1463 writeConfig(WINPOS_GRP
, WINPOS_CONWIN_X
, p_x
);
1464 writeConfig(WINPOS_GRP
, WINPOS_CONWIN_Y
, p_y
);
1467 void PPPData::winPosStatWin(int& p_x
, int& p_y
) {
1468 QRect desk
= KGlobalSettings::splashScreenDesktopGeometry();
1469 p_x
= readNumConfig(WINPOS_GRP
, WINPOS_STATWIN_X
, desk
.center().x()-160);
1470 p_y
= readNumConfig(WINPOS_GRP
, WINPOS_STATWIN_Y
, desk
.center().y()-55);
1473 void PPPData::setWinPosStatWin(int p_x
, int p_y
) {
1474 writeConfig(WINPOS_GRP
, WINPOS_STATWIN_X
, p_x
);
1475 writeConfig(WINPOS_GRP
, WINPOS_STATWIN_Y
, p_y
);