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
.constBegin();
104 while (it
!= map
.constEnd()) {
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
);
412 bool PPPData::deleteModem() {
416 QMap
<QString
, QString
> map
;
417 QMap
<QString
, QString
>::Iterator it
;
419 // set all entries of the current modem to ""
420 map
= config
->entryMap(cmodemgroup
);
422 while (it
!= map
.end()) {
423 config
->group(cmodemgroup
).writeEntry(it
.key(), "");
427 // shift the succeeding modems
428 for(int i
= cmodem
+1; i
<= modemhighcount
; i
++) {
430 map
= config
->entryMap(cmodemgroup
);
432 setModemByIndex(i
-1);
433 KConfigGroup
cg(config
, cmodemgroup
);
434 while (it
!= map
.end()) {
435 cg
.writeEntry(it
.key(), *it
);
440 // make sure the top modem is cleared
441 setModemByIndex(modemhighcount
);
442 map
= config
->entryMap(cmodemgroup
);
446 KConfigGroup
cg2(config
, cmodemgroup
);
447 while (!it
.key().isEmpty()) {
448 if(!it
.key().isEmpty())
449 cg2
.writeEntry(it
.key(), "");
454 if(cmodem
> modemhighcount
)
455 cmodem
= modemhighcount
;
457 setModemByIndex(cmodem
);
462 bool PPPData::deleteModem(const QString
&mname
) {
472 int PPPData::newmodem() {
474 if(!config
|| modemhighcount
>= MAX_MODEMS
)
478 setModemByIndex(modemhighcount
);
480 setpppdArgumentDefaults();
485 int PPPData::copymodem(int i
) {
487 KConfigGroup group
= config
->group(cmodemgroup
);
489 if(modemhighcount
>= MAX_MODEMS
)
494 QMap
<QString
, QString
> map
= group
.entryMap();
495 QMap
<QString
, QString
>::ConstIterator it
= map
.constBegin();
497 QString newname
= i18n("%1_copy", modname());
501 while (it
!= map
.constEnd()) {
502 group
= config
->group(cmodemgroup
);
503 group
.writeEntry(it
.key(), *it
);
513 const QString
PPPData::modname() {
514 return readConfig(cmodemgroup
, MOD_NAME_KEY
);
517 void PPPData::setModname(const QString
&n
) {
518 if(!cmodemgroup
.isNull()) {
519 // are we manipulating the default modem's name ? then change it, too.
520 bool def
= modname() == defaultModem();
521 writeConfig(cmodemgroup
, MOD_NAME_KEY
, n
);
530 const QString
PPPData::modemDevice() {
531 return readConfig (cmodemgroup
, MODEMDEV_KEY
, devices
[DEV_DEFAULT
]);
535 void PPPData::setModemDevice(const QString
&n
) {
536 writeConfig(cmodemgroup
, MODEMDEV_KEY
, n
);
540 QString
PPPData::flowcontrol() {
541 // keep default value in sync with general.cpp
542 return readConfig(cmodemgroup
, FLOWCONTROL_KEY
, i18n("Hardware [CRTSCTS]"));
546 void PPPData::setFlowcontrol(const QString
&n
) {
547 writeConfig(cmodemgroup
, FLOWCONTROL_KEY
, n
);
551 const QString
PPPData::speed() {
552 QString s
= readConfig(cmodemgroup
, SPEED_KEY
, "57600");
553 // undo the damage of a bug in former versions. It left an empty Speed=
554 // entry in kppprc. kppp did set the serial port to 57600 as default but
555 // pppd wouldn't receive the speed via the command line.
562 void PPPData::setSpeed(const QString
&n
) {
563 writeConfig(cmodemgroup
, SPEED_KEY
, n
);
568 void PPPData::setUseCDLine(const int n
) {
569 writeConfig(cmodemgroup
,USECDLINE_KEY
,n
);
573 int PPPData::UseCDLine() {
574 return readNumConfig(cmodemgroup
,USECDLINE_KEY
,0);
578 const QString
PPPData::modemEscapeStr() {
579 return readConfig(cmodemgroup
,ESCAPESTR_KEY
,"+++");
583 void PPPData::setModemEscapeStr(const QString
&n
) {
584 writeConfig(cmodemgroup
,ESCAPESTR_KEY
,n
);
588 const QString
PPPData::modemEscapeResp() {
589 return readConfig(cmodemgroup
,ESCAPERESP_KEY
,"OK");
593 void PPPData::setModemEscapeResp(const QString
&n
) {
594 writeConfig(cmodemgroup
,ESCAPERESP_KEY
,n
);
598 int PPPData::modemEscapeGuardTime() {
599 return readNumConfig(cmodemgroup
,ESCAPEGUARDTIME_KEY
,50);
603 void PPPData::setModemEscapeGuardTime(int n
) {
604 writeConfig(cmodemgroup
,ESCAPEGUARDTIME_KEY
,n
);
608 bool PPPData::modemLockFile() {
609 return readNumConfig(cmodemgroup
, LOCKFILE_KEY
, 1);
613 void PPPData::setModemLockFile(bool set
) {
614 writeConfig(cmodemgroup
, LOCKFILE_KEY
, set
);
618 int PPPData::modemTimeout() {
619 return readNumConfig(cmodemgroup
, TIMEOUT_KEY
, MODEM_TIMEOUT
);
623 void PPPData::setModemTimeout(int n
) {
624 writeConfig(cmodemgroup
, TIMEOUT_KEY
, n
);
628 int PPPData::modemToneDuration() {
629 return readNumConfig(cmodemgroup
, TONEDURATION_KEY
,MODEM_TONEDURATION
);
633 void PPPData::setModemToneDuration(int n
) {
634 writeConfig(cmodemgroup
, TONEDURATION_KEY
, n
);
638 int PPPData::busyWait() {
639 return readNumConfig(cmodemgroup
, BUSYWAIT_KEY
, BUSY_WAIT
);
643 void PPPData::setbusyWait(int n
) {
644 writeConfig(cmodemgroup
, BUSYWAIT_KEY
, n
);
649 //Advanced "Modem" dialog
651 // defaults: InitString=ATZ, InitString1="" etc.
652 const QString
PPPData::modemInitStr(int i
) {
653 assert(i
>= 0 && i
< NumInitStrings
);
655 return readConfig(cmodemgroup
, INITSTR_KEY
, "ATZ");
657 return readConfig(cmodemgroup
, INITSTR_KEY
+ QString::number(i
), "");
661 void PPPData::setModemInitStr(int i
, const QString
&n
) {
662 assert(i
>= 0 && i
< NumInitStrings
);
663 QString k
= INITSTR_KEY
+ (i
> 0 ? QString::number(i
) : "");
664 writeConfig(cmodemgroup
, k
, n
);
668 const QString
PPPData::modemInitResp() {
669 return readConfig(cmodemgroup
, INITRESP_KEY
, "OK");
673 void PPPData::setModemInitResp(const QString
&n
) {
674 writeConfig(cmodemgroup
, INITRESP_KEY
, n
);
678 int PPPData::modemPreInitDelay() {
679 return readNumConfig(cmodemgroup
, PREINITDELAY_KEY
, 50);
683 void PPPData::setModemPreInitDelay(int n
) {
684 writeConfig(cmodemgroup
, PREINITDELAY_KEY
, n
);
688 int PPPData::modemInitDelay() {
689 return readNumConfig(cmodemgroup
, INITDELAY_KEY
, 50);
693 void PPPData::setModemInitDelay(int n
) {
694 writeConfig(cmodemgroup
, INITDELAY_KEY
, n
);
697 QString
PPPData::modemNoDialToneDetectionStr() {
698 return readConfig(cmodemgroup
, NODTDETECT_KEY
, "ATX3");
701 void PPPData::setModemNoDialToneDetectionStr(const QString
&n
) {
702 writeConfig(cmodemgroup
, NODTDETECT_KEY
, n
);
705 const QString
PPPData::modemDialStr() {
706 return readConfig(cmodemgroup
, DIALSTR_KEY
, "ATDT");
710 void PPPData::setModemDialStr(const QString
&n
) {
711 writeConfig(cmodemgroup
, DIALSTR_KEY
, n
);
715 const QString
PPPData::modemConnectResp() {
716 return readConfig(cmodemgroup
, CONNECTRESP_KEY
, "CONNECT");
720 void PPPData::setModemConnectResp(const QString
&n
) {
721 writeConfig(cmodemgroup
, CONNECTRESP_KEY
, n
);
725 const QString
PPPData::modemBusyResp() {
726 return readConfig(cmodemgroup
, BUSYRESP_KEY
, "BUSY");
730 void PPPData::setModemBusyResp(const QString
&n
) {
731 writeConfig(cmodemgroup
, BUSYRESP_KEY
, n
);
735 const QString
PPPData::modemNoCarrierResp() {
736 return readConfig(cmodemgroup
, NOCARRIERRESP_KEY
, "NO CARRIER");
740 void PPPData::setModemNoCarrierResp(const QString
&n
) {
741 writeConfig(cmodemgroup
, NOCARRIERRESP_KEY
, n
);
745 const QString
PPPData::modemNoDialtoneResp() {
746 return readConfig(cmodemgroup
, NODIALTONERESP_KEY
, "NO DIALTONE");
750 void PPPData::setModemNoDialtoneResp(const QString
&n
) {
751 writeConfig(cmodemgroup
, NODIALTONERESP_KEY
, n
);
755 const QString
PPPData::modemHangupStr() {
756 return readConfig(cmodemgroup
, HANGUPSTR_KEY
, "+++ATH");
759 void PPPData::setModemHangupStr(const QString
&n
) {
760 writeConfig(cmodemgroup
, HANGUPSTR_KEY
, n
);
764 const QString
PPPData::modemHangupResp() {
765 return readConfig(cmodemgroup
, HANGUPRESP_KEY
, "OK");
768 void PPPData::setModemHangupResp(const QString
&n
) {
769 writeConfig(cmodemgroup
, HANGUPRESP_KEY
, n
);
773 QString
PPPData::modemDLPResp() {
774 return readConfig(cmodemgroup
, DLPRESP_KEY
, "DIGITAL LINE DETECTED");
777 void PPPData::setModemDLPResp(const QString
&n
) {
778 writeConfig(cmodemgroup
, DLPRESP_KEY
, n
);
784 const QString
PPPData::modemAnswerStr() {
785 return readConfig(cmodemgroup
, ANSWERSTR_KEY
, "ATA");
789 QString
PPPData::volumeOff() {
790 return readConfig(cmodemgroup
, VOLUME_OFF
, "M0L0");
794 void PPPData::setVolumeOff(const QString
&s
) {
795 writeConfig(cmodemgroup
, VOLUME_OFF
, s
);
799 QString
PPPData::volumeMedium() {
800 return readConfig(cmodemgroup
, VOLUME_MEDIUM
, "M1L1");
804 void PPPData::setVolumeMedium(const QString
&s
) {
805 writeConfig(cmodemgroup
, VOLUME_MEDIUM
, s
);
809 QString
PPPData::volumeHigh() {
810 QString tmp
= readConfig(cmodemgroup
, VOLUME_HIGH
, "M1L3");
817 void PPPData::setVolumeHigh(const QString
&s
) {
818 writeConfig(cmodemgroup
, VOLUME_HIGH
, s
);
822 QString
PPPData::volumeInitString() {
843 int PPPData::volume() {
844 return readNumConfig(cmodemgroup
, VOLUME_KEY
, 1);
848 void PPPData::setVolume(int i
) {
849 writeConfig(cmodemgroup
, VOLUME_KEY
, i
);
852 int PPPData::waitForDialTone() {
853 return readNumConfig(cmodemgroup
, DIALTONEWAIT_KEY
, 1);
856 void PPPData::setWaitForDialTone(int i
) {
857 writeConfig(cmodemgroup
, DIALTONEWAIT_KEY
, i
);
860 void PPPData::setModemAnswerStr(const QString
&n
) {
861 writeConfig(cmodemgroup
, ANSWERSTR_KEY
, n
);
865 const QString
PPPData::modemRingResp() {
866 return readConfig(cmodemgroup
, RINGRESP_KEY
, "RING");
870 void PPPData::setModemRingResp(const QString
&n
) {
871 writeConfig(cmodemgroup
, RINGRESP_KEY
, n
);
875 const QString
PPPData::modemAnswerResp() {
876 return readConfig(cmodemgroup
, ANSWERRESP_KEY
, "CONNECT");
880 void PPPData::setModemAnswerResp(const QString
&n
) {
881 writeConfig(cmodemgroup
, ANSWERRESP_KEY
, n
);
885 const QString
PPPData::enter() {
886 return readConfig(cmodemgroup
, ENTER_KEY
, "CR");
890 void PPPData::setEnter(const QString
&n
) {
891 writeConfig(cmodemgroup
, ENTER_KEY
, n
);
896 // functions to set/return account information
899 //returns number of accounts
900 int PPPData::accountCount() const {
901 return accounthighcount
+ 1;
905 bool PPPData::setAccount(const QString
&aname
) {
906 for(int i
= 0; i
<= accounthighcount
; i
++) {
907 setAccountByIndex(i
);
908 if(accname() == aname
) {
917 bool PPPData::setAccountByIndex(int i
) {
918 if(i
>= 0 && i
<= accounthighcount
) {
920 caccountgroup
.sprintf("%s%i", ACCOUNT_GRP
, i
);
927 bool PPPData::isUniqueAccname(const QString
&n
) {
930 int current
= caccount
;
931 for(int i
=0; i
<= accounthighcount
; i
++) {
932 setAccountByIndex(i
);
933 if(accname() == n
&& i
!= current
) {
934 setAccountByIndex(current
);
938 setAccountByIndex(current
);
943 bool PPPData::deleteAccount() {
947 QMap
<QString
, QString
> map
;
948 QMap
<QString
, QString
>::Iterator it
;
950 // set all entries of the current account to ""
951 map
= config
->entryMap(caccountgroup
);
953 KConfigGroup
cg(config
,caccountgroup
);
954 while (it
!= map
.end()) {
955 cg
.writeEntry(it
.key(), "");
959 // shift the succeeding accounts
960 for(int i
= caccount
+1; i
<= accounthighcount
; i
++) {
961 setAccountByIndex(i
);
962 map
= config
->entryMap(caccountgroup
);
964 setAccountByIndex(i
-1);
965 KConfigGroup
cg2(config
,caccountgroup
);
966 while (it
!= map
.end()) {
967 cg2
.writeEntry(it
.key(), *it
);
972 // make sure the top account is cleared
973 setAccountByIndex(accounthighcount
);
974 map
= config
->entryMap(caccountgroup
);
976 KConfigGroup
cg3(config
,caccountgroup
);
977 while (it
!= map
.end() && !it
.key().isNull()) {
978 cg3
.writeEntry(it
.key(), "");
983 if(caccount
> accounthighcount
)
984 caccount
= accounthighcount
;
986 setAccountByIndex(caccount
);
991 bool PPPData::deleteAccount(const QString
&aname
) {
992 if(!setAccount(aname
))
1001 int PPPData::newaccount() {
1003 if(!config
|| accounthighcount
>= MAX_ACCOUNTS
)
1007 setAccountByIndex(accounthighcount
);
1009 setpppdArgumentDefaults();
1014 int PPPData::copyaccount(int i
) {
1016 if(accounthighcount
>= MAX_ACCOUNTS
)
1019 setAccountByIndex(i
);
1021 QMap
<QString
, QString
> map
= config
->entryMap(caccountgroup
);
1022 QMap
<QString
, QString
>::ConstIterator it
= map
.constBegin();
1024 QString newname
= i18n("%1_copy", accname());
1028 while (it
!= map
.constEnd()) {
1029 KConfigGroup
cg2 ( config
, caccountgroup
);
1030 cg2
.writeEntry(it
.key(), *it
);
1034 setAccname(newname
);
1040 const QString
PPPData::accname() {
1041 return readConfig(caccountgroup
, ACC_NAME_KEY
);
1044 void PPPData::setAccname(const QString
&n
) {
1045 if(!caccountgroup
.isNull()) {
1046 // are we manipulating the default account's name ? then change it, too.
1047 bool def
= accname() == defaultAccount();
1048 writeConfig(caccountgroup
, ACC_NAME_KEY
, n
);
1050 setDefaultAccount(n
);
1055 #define SEPARATOR_CHAR ':'
1056 QStringList
&PPPData::phonenumbers() {
1057 phonelist
= readConfig(caccountgroup
, PHONENUMBER_KEY
).split(SEPARATOR_CHAR
);
1062 const QString
PPPData::phonenumber() {
1063 return readConfig(caccountgroup
, PHONENUMBER_KEY
);
1067 void PPPData::setPhonenumber(const QString
&n
) {
1068 writeConfig(caccountgroup
, PHONENUMBER_KEY
, n
);
1072 const QString
PPPData::dialPrefix() {
1073 return readConfig(caccountgroup
, DIAL_PREFIX_KEY
, "");
1077 void PPPData::setDialPrefix(const QString
&s
) {
1078 writeConfig(caccountgroup
, DIAL_PREFIX_KEY
, s
);
1082 int PPPData::authMethod() {
1083 return readNumConfig(caccountgroup
, AUTH_KEY
, 0);
1087 void PPPData::setAuthMethod(int value
) {
1088 writeConfig(caccountgroup
, AUTH_KEY
, value
);
1092 const QString
PPPData::storedUsername() {
1093 return readConfig(caccountgroup
, STORED_USERNAME_KEY
, "");
1097 void PPPData::setStoredUsername(const QString
&b
) {
1098 writeConfig(caccountgroup
, STORED_USERNAME_KEY
, b
);
1102 const QString
PPPData::storedPassword() {
1103 return readConfig(caccountgroup
, STORED_PASSWORD_KEY
, "");
1107 void PPPData::setStoredPassword(const QString
&b
) {
1108 writeConfig(caccountgroup
, STORED_PASSWORD_KEY
, b
);
1112 bool PPPData::storePassword() {
1113 return (bool)readNumConfig(caccountgroup
, STORE_PASSWORD_KEY
, 1);
1116 int PPPData::callbackType() {
1117 return readNumConfig(caccountgroup
, CALLBACK_TYPE_KEY
, 0);
1120 void PPPData::setCallbackType(int value
) {
1121 writeConfig(caccountgroup
, CALLBACK_TYPE_KEY
, value
);
1124 QString
PPPData::callbackPhone() {
1125 return readConfig(caccountgroup
, CALLBACK_PHONE_KEY
, "");
1128 void PPPData::setCallbackPhone(const QString
&b
) {
1129 writeConfig(caccountgroup
, CALLBACK_PHONE_KEY
, b
);
1132 bool PPPData::waitCallback() {
1133 return waitcallback
;
1136 void PPPData::setWaitCallback(bool value
) {
1137 waitcallback
= value
;
1140 const QString
PPPData::command_before_connect() {
1141 return readConfig(caccountgroup
, BEFORE_CONNECT_KEY
);
1145 void PPPData::setCommand_before_connect(const QString
&n
) {
1146 writeConfig(caccountgroup
, BEFORE_CONNECT_KEY
, n
);
1150 void PPPData::setStorePassword(bool b
) {
1151 writeConfig(caccountgroup
, STORE_PASSWORD_KEY
, (int)b
);
1155 const QString
PPPData::command_on_connect() {
1156 return readConfig(caccountgroup
, COMMAND_KEY
);
1160 void PPPData::setCommand_on_connect(const QString
&n
) {
1161 writeConfig(caccountgroup
, COMMAND_KEY
, n
);
1165 const QString
PPPData::command_on_disconnect() {
1166 return readConfig(caccountgroup
, DISCONNECT_COMMAND_KEY
);
1170 void PPPData::setCommand_on_disconnect(const QString
&n
) {
1171 writeConfig(caccountgroup
, DISCONNECT_COMMAND_KEY
, n
);
1175 const QString
PPPData::command_before_disconnect() {
1176 return readConfig(caccountgroup
, BEFORE_DISCONNECT_KEY
);
1180 void PPPData::setCommand_before_disconnect(const QString
&n
) {
1181 writeConfig(caccountgroup
, BEFORE_DISCONNECT_KEY
, n
);
1185 const QString
PPPData::ipaddr() {
1186 return readConfig(caccountgroup
, IPADDR_KEY
);
1190 void PPPData::setIpaddr(const QString
&n
) {
1191 writeConfig(caccountgroup
, IPADDR_KEY
, n
);
1195 const QString
PPPData::subnetmask() {
1196 return readConfig(caccountgroup
, SUBNETMASK_KEY
);
1200 void PPPData::setSubnetmask(const QString
&n
) {
1201 writeConfig(caccountgroup
, SUBNETMASK_KEY
, n
);
1205 bool PPPData::autoname() {
1206 return (bool) readNumConfig(caccountgroup
, AUTONAME_KEY
, false);
1210 void PPPData::setAutoname(bool set
) {
1211 writeConfig(caccountgroup
, AUTONAME_KEY
, (int) set
);
1215 bool PPPData::AcctEnabled() {
1216 return (bool) readNumConfig(caccountgroup
, ACCTENABLED_KEY
, false);
1220 void PPPData::setAcctEnabled(bool set
) {
1221 writeConfig(caccountgroup
, ACCTENABLED_KEY
, (int) set
);
1225 int PPPData::VolAcctEnabled() {
1226 return readNumConfig(caccountgroup
, VOLACCTENABLED_KEY
, 0);
1230 void PPPData::setVolAcctEnabled(int set
) {
1231 writeConfig(caccountgroup
, VOLACCTENABLED_KEY
, set
);
1235 const QString
PPPData::gateway() {
1236 return readConfig(caccountgroup
, GATEWAY_KEY
);
1240 void PPPData::setGateway(const QString
&n
) {
1241 writeConfig(caccountgroup
, GATEWAY_KEY
, n
);
1245 bool PPPData::defaultroute() {
1246 // default route is by default 'on'.
1247 return (bool) readNumConfig(caccountgroup
, DEFAULTROUTE_KEY
, true);
1251 void PPPData::setDefaultroute(bool set
) {
1252 writeConfig(caccountgroup
, DEFAULTROUTE_KEY
, (int) set
);
1256 bool PPPData::autoDNS() {
1257 bool set
= (bool) readNumConfig(caccountgroup
, AUTODNS_KEY
, true);
1258 return (set
&& gpppdata
.pppdVersionMin(2, 3, 7));
1262 void PPPData::setAutoDNS(bool set
) {
1263 writeConfig(caccountgroup
, AUTODNS_KEY
, (int) set
);
1267 void PPPData::setExDNSDisabled(bool set
) {
1268 writeConfig(caccountgroup
, EXDNSDISABLED_KEY
, (int) set
);
1272 bool PPPData::exDNSDisabled() {
1273 return (bool) readNumConfig(caccountgroup
, EXDNSDISABLED_KEY
,0);
1277 QStringList
&PPPData::dns() {
1278 static QStringList dnslist
;
1280 readListConfig(caccountgroup
, DNS_KEY
, dnslist
);
1281 while(dnslist
.count() > MAX_DNS_ENTRIES
)
1282 dnslist
.removeAll(dnslist
.last());
1288 void PPPData::setDns(QStringList
&list
) {
1289 writeListConfig(caccountgroup
, DNS_KEY
, list
);
1293 const QString
PPPData::domain() {
1294 return readConfig(caccountgroup
, DOMAIN_KEY
);
1298 void PPPData::setDomain(const QString
&n
) {
1299 writeConfig(caccountgroup
, DOMAIN_KEY
, n
);
1303 QStringList
&PPPData::scriptType() {
1304 static QStringList typelist
;
1306 readListConfig(caccountgroup
, SCRIPTCOM_KEY
, typelist
);
1307 while(typelist
.count() > MAX_SCRIPT_ENTRIES
)
1308 typelist
.removeAll(typelist
.last());
1314 void PPPData::setScriptType(QStringList
&list
) {
1315 writeListConfig(caccountgroup
, SCRIPTCOM_KEY
, list
);
1319 QStringList
&PPPData::script() {
1320 static QStringList scriptlist
;
1322 readListConfig(caccountgroup
, SCRIPTARG_KEY
, scriptlist
);
1323 while(scriptlist
.count() > MAX_SCRIPT_ENTRIES
)
1324 scriptlist
.removeAll(scriptlist
.last());
1330 void PPPData::setScript(QStringList
&list
) {
1331 writeListConfig(caccountgroup
, SCRIPTARG_KEY
, list
);
1335 const QString
PPPData::accountingFile() {
1336 return readConfig(caccountgroup
, ACCTFILE_KEY
);
1340 void PPPData::setAccountingFile(const QString
&n
) {
1341 writeConfig(caccountgroup
, ACCTFILE_KEY
, n
);
1345 const QString
PPPData::totalCosts() {
1346 return readConfig(caccountgroup
, TOTALCOSTS_KEY
);
1350 void PPPData::setTotalCosts(const QString
&n
) {
1351 writeConfig(caccountgroup
, TOTALCOSTS_KEY
, n
);
1355 int PPPData::totalBytes() {
1356 return readNumConfig(caccountgroup
, TOTALBYTES_KEY
, 0);
1359 void PPPData::setTotalBytes(int n
) {
1360 writeConfig(caccountgroup
, TOTALBYTES_KEY
, n
);
1364 QStringList
&PPPData::pppdArgument() {
1365 static QStringList arglist
;
1367 while(arglist
.count() > MAX_PPPD_ARGUMENTS
)
1368 arglist
.removeAll(arglist
.last());
1369 readListConfig(caccountgroup
, PPPDARG_KEY
, arglist
);
1375 void PPPData::setpppdArgument(QStringList
&args
) {
1376 writeListConfig(caccountgroup
, PPPDARG_KEY
, args
);
1380 void PPPData::setpppdArgumentDefaults() {
1382 setpppdArgument(arg
);
1387 void PPPData::setGraphingOptions(bool enable
,
1394 KConfigGroup group
= config
->group(GRAPH_GRP
);
1395 group
.writeEntry(GENABLED
, enable
);
1396 group
.writeEntry(GCOLOR_BG
, bg
);
1397 group
.writeEntry(GCOLOR_TEXT
, text
);
1398 group
.writeEntry(GCOLOR_IN
, in
);
1399 group
.writeEntry(GCOLOR_OUT
, out
);
1403 void PPPData::graphingOptions(bool &enable
,
1412 KConfigGroup group
= config
->group(GRAPH_GRP
);
1413 enable
= group
.readEntry(GENABLED
,true);
1415 bg
= group
.readEntry(GCOLOR_BG
, c
);
1417 text
= group
.readEntry(GCOLOR_TEXT
, c
);
1419 in
= group
.readEntry(GCOLOR_IN
, c
);
1421 out
= group
.readEntry(GCOLOR_OUT
, c
);
1426 bool PPPData::graphingEnabled() {
1428 return config
->group(GRAPH_GRP
).readEntry(GENABLED
, true);
1436 //functions to change/set the child pppd process info
1438 bool PPPData::pppdRunning() const {
1439 return pppdisrunning
;
1442 void PPPData::setpppdRunning(bool set
) {
1443 pppdisrunning
= set
;
1446 int PPPData::pppdError() const {
1450 void PPPData::setpppdError(int err
) {
1458 void PPPData::winPosConWin(int& p_x
, int& p_y
) {
1459 QRect desk
= KGlobalSettings::splashScreenDesktopGeometry();
1460 p_x
= readNumConfig(WINPOS_GRP
, WINPOS_CONWIN_X
, desk
.center().x()-160);
1461 p_y
= readNumConfig(WINPOS_GRP
, WINPOS_CONWIN_Y
, desk
.center().y()-55);
1464 void PPPData::setWinPosConWin(int p_x
, int p_y
) {
1465 writeConfig(WINPOS_GRP
, WINPOS_CONWIN_X
, p_x
);
1466 writeConfig(WINPOS_GRP
, WINPOS_CONWIN_Y
, p_y
);
1469 void PPPData::winPosStatWin(int& p_x
, int& p_y
) {
1470 QRect desk
= KGlobalSettings::splashScreenDesktopGeometry();
1471 p_x
= readNumConfig(WINPOS_GRP
, WINPOS_STATWIN_X
, desk
.center().x()-160);
1472 p_y
= readNumConfig(WINPOS_GRP
, WINPOS_STATWIN_Y
, desk
.center().y()-55);
1475 void PPPData::setWinPosStatWin(int p_x
, int p_y
) {
1476 writeConfig(WINPOS_GRP
, WINPOS_STATWIN_X
, p_x
);
1477 writeConfig(WINPOS_GRP
, WINPOS_STATWIN_Y
, p_y
);