Diffstat (limited to 'noncore/settings/networksettings/ppp/pppdata.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/pppdata.cpp | 1229 |
1 files changed, 1229 insertions, 0 deletions
diff --git a/noncore/settings/networksettings/ppp/pppdata.cpp b/noncore/settings/networksettings/ppp/pppdata.cpp new file mode 100644 index 0000000..f2386fc --- a/dev/null +++ b/noncore/settings/networksettings/ppp/pppdata.cpp | |||
@@ -0,0 +1,1229 @@ | |||
1 | /* | ||
2 | * kPPP: A pppd front end for the KDE project | ||
3 | * | ||
4 | * $Id$ | ||
5 | * | ||
6 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
7 | * wuebben@math.cornell.edu | ||
8 | * | ||
9 | * based on EzPPP: | ||
10 | * Copyright (C) 1997 Jay Painter | ||
11 | * | ||
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. | ||
16 | * | ||
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. | ||
21 | * | ||
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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
25 | */ | ||
26 | |||
27 | #include "pppdata.h" | ||
28 | #include "runtests.h" | ||
29 | #include "devices.h" | ||
30 | //#include <klocale.h> | ||
31 | #define i18n QObject::tr | ||
32 | #include <qpe/config.h> | ||
33 | #include <qmessagebox.h> | ||
34 | #include <qapplication.h> | ||
35 | // #include <klocale.h> | ||
36 | // #include <kconfig.h> | ||
37 | // #include <kmessagebox.h> | ||
38 | // #include <kapplication.h> | ||
39 | #include <assert.h> | ||
40 | |||
41 | PPPData gpppdata; | ||
42 | |||
43 | |||
44 | PPPData::PPPData() | ||
45 | : config(0L), | ||
46 | highcount(-1), // start out with no entries | ||
47 | caccount(-1), // set the current account index also | ||
48 | suidprocessid(-1), // process ID of setuid child | ||
49 | pppdisrunning(false), | ||
50 | pppderror(0) | ||
51 | { | ||
52 | } | ||
53 | |||
54 | |||
55 | // | ||
56 | // open configuration file | ||
57 | // | ||
58 | bool PPPData::open() { | ||
59 | |||
60 | config = new Config("NetworkSetup"); | ||
61 | /* | ||
62 | config = kapp->config(); | ||
63 | |||
64 | if (config->getConfigState() == KConfig::NoAccess) { | ||
65 | KMessageBox::error(0L, | ||
66 | i18n("The application-specific config file could not " | ||
67 | "be opened in either read-write or read-only mode.\n" | ||
68 | "The superuser might have to change its ownership " | ||
69 | "by issuing the following command in your home directory:\n" | ||
70 | "chown {YourUsername} .kde/share/config/kppprc"), | ||
71 | kapp->name()); | ||
72 | return false; | ||
73 | } | ||
74 | |||
75 | // don't expand shell variables | ||
76 | config->setDollarExpansion(false); | ||
77 | */ | ||
78 | |||
79 | highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1; | ||
80 | |||
81 | if (highcount > MAX_ACCOUNTS) | ||
82 | highcount = MAX_ACCOUNTS; | ||
83 | |||
84 | if(highcount >= 0 && defaultAccount().isEmpty()) { | ||
85 | setAccountbyIndex(0); | ||
86 | setDefaultAccount(accname()); | ||
87 | } else if(!setAccount(defaultAccount())) | ||
88 | setDefaultAccount(accname()); | ||
89 | |||
90 | // start out with internal debugging disabled | ||
91 | // the user is still free to specify `debug' on his own | ||
92 | setPPPDebug(false); | ||
93 | |||
94 | ::pppdVersion(&pppdVer, &pppdMod, &pppdPatch); | ||
95 | |||
96 | return true; | ||
97 | } | ||
98 | |||
99 | |||
100 | // | ||
101 | // save configuration | ||
102 | // | ||
103 | void PPPData::save() { | ||
104 | |||
105 | if (config) { | ||
106 | writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count()); | ||
107 | // config->sync(); | ||
108 | } | ||
109 | |||
110 | } | ||
111 | |||
112 | |||
113 | // | ||
114 | // cancel changes | ||
115 | // | ||
116 | void PPPData::cancel() { | ||
117 | |||
118 | // if (config) { | ||
119 | // config->rollback(); | ||
120 | // config->reparseConfiguration(); | ||
121 | // } | ||
122 | |||
123 | } | ||
124 | |||
125 | |||
126 | // currently differentiates between READWRITE and NONE only | ||
127 | int PPPData::access() const { | ||
128 | |||
129 | return 0;//config->getConfigState(); | ||
130 | } | ||
131 | |||
132 | |||
133 | // functions to read/write date to configuration file | ||
134 | QString PPPData::readConfig(const QString &group, const QString &key, | ||
135 | const QString &defvalue = "") | ||
136 | { | ||
137 | if (config) { | ||
138 | config->setGroup(group); | ||
139 | return config->readEntry(key, defvalue); | ||
140 | } else | ||
141 | return defvalue; | ||
142 | } | ||
143 | |||
144 | |||
145 | int PPPData::readNumConfig(const QString &group, const QString &key, | ||
146 | int defvalue) { | ||
147 | if (config) { | ||
148 | config->setGroup(group); | ||
149 | return config->readNumEntry(key, defvalue); | ||
150 | } else | ||
151 | return defvalue; | ||
152 | |||
153 | } | ||
154 | |||
155 | |||
156 | bool PPPData::readListConfig(const QString &group, const QString &key, | ||
157 | QStringList &list, char sep) { | ||
158 | list.clear(); | ||
159 | if (config) { | ||
160 | config->setGroup(group); | ||
161 | list = config->readListEntry(key, sep); | ||
162 | return true; | ||
163 | } else | ||
164 | return false; | ||
165 | } | ||
166 | |||
167 | |||
168 | void PPPData::writeConfig(const QString &group, const QString &key, | ||
169 | const QString &value) { | ||
170 | if (config) { | ||
171 | config->setGroup(group); | ||
172 | config->writeEntry(key, value); | ||
173 | } | ||
174 | } | ||
175 | |||
176 | |||
177 | void PPPData::writeConfig(const QString &group, const QString &key, int value) { | ||
178 | if (config) { | ||
179 | config->setGroup(group); | ||
180 | config->writeEntry(key, value); | ||
181 | } | ||
182 | } | ||
183 | |||
184 | |||
185 | void PPPData::writeListConfig(const QString &group, const QString &key, | ||
186 | QStringList &list, char sep) { | ||
187 | if (config) { | ||
188 | config->setGroup(group); | ||
189 | config->writeEntry(key, list, sep); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | |||
194 | // | ||
195 | // functions to set/return general information | ||
196 | // | ||
197 | QString PPPData::password() const { | ||
198 | return passwd; | ||
199 | } | ||
200 | |||
201 | |||
202 | void PPPData::setPassword(const QString &pw) { | ||
203 | passwd = pw; | ||
204 | } | ||
205 | |||
206 | |||
207 | const QString PPPData::defaultAccount() { | ||
208 | return readConfig(GENERAL_GRP, DEFAULTACCOUNT_KEY); | ||
209 | } | ||
210 | |||
211 | |||
212 | void PPPData::setDefaultAccount(const QString &n) { | ||
213 | writeConfig(GENERAL_GRP, DEFAULTACCOUNT_KEY, n); | ||
214 | |||
215 | //now set the current account index to the default account | ||
216 | setAccount(defaultAccount()); | ||
217 | } | ||
218 | |||
219 | |||
220 | bool PPPData::get_show_clock_on_caption() { | ||
221 | return (bool) readNumConfig(GENERAL_GRP, SHOWCLOCK_KEY, true); | ||
222 | } | ||
223 | |||
224 | |||
225 | void PPPData::set_show_clock_on_caption(bool set) { | ||
226 | writeConfig(GENERAL_GRP, SHOWCLOCK_KEY, (int) set); | ||
227 | } | ||
228 | |||
229 | |||
230 | bool PPPData::get_xserver_exit_disconnect() { | ||
231 | return (bool) readNumConfig(GENERAL_GRP, DISCONNECT_KEY, true); | ||
232 | } | ||
233 | |||
234 | |||
235 | void PPPData::setPPPDebug(bool set) { | ||
236 | writeConfig(GENERAL_GRP, PPP_DEBUG_OPTION, (int)set); | ||
237 | } | ||
238 | |||
239 | |||
240 | bool PPPData::getPPPDebug() { | ||
241 | return (bool)readNumConfig(GENERAL_GRP, PPP_DEBUG_OPTION, false); | ||
242 | } | ||
243 | |||
244 | |||
245 | void PPPData::set_xserver_exit_disconnect(bool set) { | ||
246 | writeConfig(GENERAL_GRP, DISCONNECT_KEY, (int) set); | ||
247 | } | ||
248 | |||
249 | |||
250 | bool PPPData::quit_on_disconnect() { | ||
251 | return (bool) readNumConfig(GENERAL_GRP, QUITONDISCONNECT_KEY, false); | ||
252 | } | ||
253 | |||
254 | |||
255 | void PPPData::set_quit_on_disconnect(bool set) { | ||
256 | writeConfig(GENERAL_GRP, QUITONDISCONNECT_KEY, (int) set); | ||
257 | } | ||
258 | |||
259 | |||
260 | bool PPPData::get_show_log_window() { | ||
261 | return (bool) readNumConfig (GENERAL_GRP, SHOWLOGWIN_KEY, false); | ||
262 | } | ||
263 | |||
264 | |||
265 | void PPPData::set_show_log_window(bool set) { | ||
266 | writeConfig(GENERAL_GRP, SHOWLOGWIN_KEY, (int) set); | ||
267 | } | ||
268 | |||
269 | |||
270 | bool PPPData::automatic_redial() { | ||
271 | return (bool) readNumConfig(GENERAL_GRP, AUTOREDIAL_KEY, FALSE); | ||
272 | } | ||
273 | |||
274 | |||
275 | void PPPData::set_automatic_redial(bool set) { | ||
276 | writeConfig(GENERAL_GRP, AUTOREDIAL_KEY, (int) set); | ||
277 | } | ||
278 | |||
279 | |||
280 | bool PPPData::get_iconify_on_connect() { | ||
281 | return (bool) readNumConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, TRUE); | ||
282 | } | ||
283 | |||
284 | |||
285 | void PPPData::set_iconify_on_connect(bool set) { | ||
286 | writeConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, (int) set); | ||
287 | } | ||
288 | |||
289 | |||
290 | bool PPPData::get_dock_into_panel() { | ||
291 | return (bool) readNumConfig(GENERAL_GRP, DOCKING_KEY, false); | ||
292 | } | ||
293 | |||
294 | |||
295 | void PPPData::set_dock_into_panel(bool set) { | ||
296 | writeConfig(GENERAL_GRP, DOCKING_KEY, (int) set); | ||
297 | } | ||
298 | |||
299 | |||
300 | QString PPPData::pppdVersion() { | ||
301 | return QString("%1.%2.%3").arg(pppdVer).arg(pppdMod).arg(pppdPatch); | ||
302 | } | ||
303 | |||
304 | bool PPPData::pppdVersionMin(int ver, int mod, int patch) { | ||
305 | // check if pppd version fulfills minimum requirement | ||
306 | return (pppdVer > ver | ||
307 | || (pppdVer == ver && pppdMod > mod) | ||
308 | || (pppdVer == ver && pppdMod == mod && pppdPatch >= patch)); | ||
309 | } | ||
310 | |||
311 | int PPPData::pppdTimeout() { | ||
312 | return readNumConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, PPPD_TIMEOUT); | ||
313 | } | ||
314 | |||
315 | |||
316 | void PPPData::setpppdTimeout(int n) { | ||
317 | writeConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, n); | ||
318 | } | ||
319 | |||
320 | |||
321 | const QString PPPData::modemDevice() { | ||
322 | return readConfig (MODEM_GRP, MODEMDEV_KEY, devices[DEV_DEFAULT]); | ||
323 | } | ||
324 | |||
325 | |||
326 | void PPPData::setModemDevice(const QString &n) { | ||
327 | writeConfig(MODEM_GRP, MODEMDEV_KEY, n); | ||
328 | } | ||
329 | |||
330 | |||
331 | const QString PPPData::flowcontrol() { | ||
332 | return readConfig(MODEM_GRP, FLOWCONTROL_KEY, "CRTSCTS"); | ||
333 | } | ||
334 | |||
335 | |||
336 | void PPPData::setFlowcontrol(const QString &n) { | ||
337 | writeConfig(MODEM_GRP, FLOWCONTROL_KEY, n); | ||
338 | } | ||
339 | |||
340 | |||
341 | const QString PPPData::speed() { | ||
342 | QString s = readConfig(MODEM_GRP, SPEED_KEY, "57600"); | ||
343 | // undo the damage of a bug in former versions. It left an empty Speed= | ||
344 | // entry in kppprc. kppp did set the serial port to 57600 as default but | ||
345 | // pppd wouldn't receive the speed via the command line. | ||
346 | if(s.toUInt() == 0) | ||
347 | s = "57600"; | ||
348 | return s; | ||
349 | } | ||
350 | |||
351 | |||
352 | void PPPData::setSpeed(const QString &n) { | ||
353 | writeConfig(MODEM_GRP, SPEED_KEY, n); | ||
354 | } | ||
355 | |||
356 | |||
357 | #if 0 | ||
358 | void PPPData::setUseCDLine(const int n) { | ||
359 | writeConfig(MODEM_GRP,USECDLINE_KEY,n); | ||
360 | } | ||
361 | |||
362 | |||
363 | int PPPData::UseCDLine() { | ||
364 | return readNumConfig(MODEM_GRP,USECDLINE_KEY,0); | ||
365 | } | ||
366 | #endif | ||
367 | |||
368 | const QString PPPData::modemEscapeStr() { | ||
369 | return readConfig(MODEM_GRP,ESCAPESTR_KEY,"+++"); | ||
370 | } | ||
371 | |||
372 | |||
373 | void PPPData::setModemEscapeStr(const QString &n) { | ||
374 | writeConfig(MODEM_GRP,ESCAPESTR_KEY,n); | ||
375 | } | ||
376 | |||
377 | |||
378 | const QString PPPData::modemEscapeResp() { | ||
379 | return readConfig(MODEM_GRP,ESCAPERESP_KEY,"OK"); | ||
380 | } | ||
381 | |||
382 | |||
383 | void PPPData::setModemEscapeResp(const QString &n) { | ||
384 | writeConfig(MODEM_GRP,ESCAPERESP_KEY,n); | ||
385 | } | ||
386 | |||
387 | |||
388 | int PPPData::modemEscapeGuardTime() { | ||
389 | return readNumConfig(MODEM_GRP,ESCAPEGUARDTIME_KEY,50); | ||
390 | } | ||
391 | |||
392 | |||
393 | void PPPData::setModemEscapeGuardTime(int n) { | ||
394 | writeConfig(MODEM_GRP,ESCAPEGUARDTIME_KEY,n); | ||
395 | } | ||
396 | |||
397 | |||
398 | bool PPPData::modemLockFile() { | ||
399 | return readNumConfig(MODEM_GRP, LOCKFILE_KEY, 1); | ||
400 | } | ||
401 | |||
402 | |||
403 | void PPPData::setModemLockFile(bool set) { | ||
404 | writeConfig(MODEM_GRP, LOCKFILE_KEY, set); | ||
405 | } | ||
406 | |||
407 | |||
408 | int PPPData::modemTimeout() { | ||
409 | return readNumConfig(MODEM_GRP, TIMEOUT_KEY, MODEM_TIMEOUT); | ||
410 | } | ||
411 | |||
412 | |||
413 | void PPPData::setModemTimeout(int n) { | ||
414 | writeConfig(MODEM_GRP, TIMEOUT_KEY, n); | ||
415 | } | ||
416 | |||
417 | |||
418 | int PPPData::modemToneDuration() { | ||
419 | return readNumConfig(MODEM_GRP, TONEDURATION_KEY,MODEM_TONEDURATION); | ||
420 | } | ||
421 | |||
422 | |||
423 | void PPPData::setModemToneDuration(int n) { | ||
424 | writeConfig(MODEM_GRP, TONEDURATION_KEY, n); | ||
425 | } | ||
426 | |||
427 | |||
428 | int PPPData::busyWait() { | ||
429 | return readNumConfig(MODEM_GRP, BUSYWAIT_KEY, BUSY_WAIT); | ||
430 | } | ||
431 | |||
432 | |||
433 | void PPPData::setbusyWait(int n) { | ||
434 | writeConfig(MODEM_GRP, BUSYWAIT_KEY, n); | ||
435 | } | ||
436 | |||
437 | |||
438 | // | ||
439 | //Advanced "Modem" dialog | ||
440 | // | ||
441 | // defaults: InitString=ATZ, InitString1="" etc. | ||
442 | const QString PPPData::modemInitStr(int i) { | ||
443 | assert(i >= 0 && i < NumInitStrings); | ||
444 | if(i == 0) | ||
445 | return readConfig(MODEM_GRP, INITSTR_KEY, "ATZ"); | ||
446 | else | ||
447 | return readConfig(MODEM_GRP, INITSTR_KEY + QString::number(i), ""); | ||
448 | } | ||
449 | |||
450 | |||
451 | void PPPData::setModemInitStr(int i, const QString &n) { | ||
452 | assert(i >= 0 && i < NumInitStrings); | ||
453 | QString k = INITSTR_KEY + (i > 0 ? QString::number(i) : ""); | ||
454 | writeConfig(MODEM_GRP, k, n); | ||
455 | } | ||
456 | |||
457 | |||
458 | const QString PPPData::modemInitResp() { | ||
459 | return readConfig(MODEM_GRP, INITRESP_KEY, "OK"); | ||
460 | } | ||
461 | |||
462 | |||
463 | void PPPData::setModemInitResp(const QString &n) { | ||
464 | writeConfig(MODEM_GRP, INITRESP_KEY, n); | ||
465 | } | ||
466 | |||
467 | |||
468 | int PPPData::modemPreInitDelay() { | ||
469 | return readNumConfig(MODEM_GRP, PREINITDELAY_KEY, 50); | ||
470 | } | ||
471 | |||
472 | |||
473 | void PPPData::setModemPreInitDelay(int n) { | ||
474 | writeConfig(MODEM_GRP, PREINITDELAY_KEY, n); | ||
475 | } | ||
476 | |||
477 | |||
478 | int PPPData::modemInitDelay() { | ||
479 | return readNumConfig(MODEM_GRP, INITDELAY_KEY, 50); | ||
480 | } | ||
481 | |||
482 | |||
483 | void PPPData::setModemInitDelay(int n) { | ||
484 | writeConfig(MODEM_GRP, INITDELAY_KEY, n); | ||
485 | } | ||
486 | |||
487 | QString PPPData::modemNoDialToneDetectionStr() { | ||
488 | return readConfig(MODEM_GRP, NODTDETECT_KEY, "ATX3"); | ||
489 | } | ||
490 | |||
491 | void PPPData::setModemNoDialToneDetectionStr(const QString &n) { | ||
492 | writeConfig(MODEM_GRP, NODTDETECT_KEY, n); | ||
493 | } | ||
494 | |||
495 | const QString PPPData::modemDialStr() { | ||
496 | return readConfig(MODEM_GRP, DIALSTR_KEY, "ATDT"); | ||
497 | } | ||
498 | |||
499 | |||
500 | void PPPData::setModemDialStr(const QString &n) { | ||
501 | writeConfig(MODEM_GRP, DIALSTR_KEY, n); | ||
502 | } | ||
503 | |||
504 | |||
505 | const QString PPPData::modemConnectResp() { | ||
506 | return readConfig(MODEM_GRP, CONNECTRESP_KEY, "CONNECT"); | ||
507 | } | ||
508 | |||
509 | |||
510 | void PPPData::setModemConnectResp(const QString &n) { | ||
511 | writeConfig(MODEM_GRP, CONNECTRESP_KEY, n); | ||
512 | } | ||
513 | |||
514 | |||
515 | const QString PPPData::modemBusyResp() { | ||
516 | return readConfig(MODEM_GRP, BUSYRESP_KEY, "BUSY"); | ||
517 | } | ||
518 | |||
519 | |||
520 | void PPPData::setModemBusyResp(const QString &n) { | ||
521 | writeConfig(MODEM_GRP, BUSYRESP_KEY, n); | ||
522 | } | ||
523 | |||
524 | |||
525 | const QString PPPData::modemNoCarrierResp() { | ||
526 | return readConfig(MODEM_GRP, NOCARRIERRESP_KEY, "NO CARRIER"); | ||
527 | } | ||
528 | |||
529 | |||
530 | void PPPData::setModemNoCarrierResp(const QString &n) { | ||
531 | writeConfig(MODEM_GRP, NOCARRIERRESP_KEY, n); | ||
532 | } | ||
533 | |||
534 | |||
535 | const QString PPPData::modemNoDialtoneResp() { | ||
536 | return readConfig(MODEM_GRP, NODIALTONERESP_KEY, "NO DIALTONE"); | ||
537 | } | ||
538 | |||
539 | |||
540 | void PPPData::setModemNoDialtoneResp(const QString &n) { | ||
541 | writeConfig(MODEM_GRP, NODIALTONERESP_KEY, n); | ||
542 | } | ||
543 | |||
544 | |||
545 | const QString PPPData::modemHangupStr() { | ||
546 | return readConfig(MODEM_GRP, HANGUPSTR_KEY, "+++ATH"); | ||
547 | } | ||
548 | |||
549 | void PPPData::setModemHangupStr(const QString &n) { | ||
550 | writeConfig(MODEM_GRP, HANGUPSTR_KEY, n); | ||
551 | } | ||
552 | |||
553 | |||
554 | const QString PPPData::modemHangupResp() { | ||
555 | return readConfig(MODEM_GRP, HANGUPRESP_KEY, "OK"); | ||
556 | } | ||
557 | |||
558 | void PPPData::setModemHangupResp(const QString &n) { | ||
559 | writeConfig(MODEM_GRP, HANGUPRESP_KEY, n); | ||
560 | } | ||
561 | |||
562 | |||
563 | const QString PPPData::modemAnswerStr() { | ||
564 | return readConfig(MODEM_GRP, ANSWERSTR_KEY, "ATA"); | ||
565 | } | ||
566 | |||
567 | |||
568 | QString PPPData::volumeOff() { | ||
569 | return readConfig(MODEM_GRP, VOLUME_OFF, "M0L0"); | ||
570 | } | ||
571 | |||
572 | |||
573 | void PPPData::setVolumeOff(const QString &s) { | ||
574 | writeConfig(MODEM_GRP, VOLUME_OFF, s); | ||
575 | } | ||
576 | |||
577 | |||
578 | QString PPPData::volumeMedium() { | ||
579 | return readConfig(MODEM_GRP, VOLUME_MEDIUM, "M1L1"); | ||
580 | } | ||
581 | |||
582 | |||
583 | void PPPData::setVolumeMedium(const QString &s) { | ||
584 | writeConfig(MODEM_GRP, VOLUME_MEDIUM, s); | ||
585 | } | ||
586 | |||
587 | |||
588 | QString PPPData::volumeHigh() { | ||
589 | QString tmp = readConfig(MODEM_GRP, VOLUME_HIGH, "M1L3"); | ||
590 | if(tmp == "M1L4") | ||
591 | tmp = "M1L3"; | ||
592 | return tmp; | ||
593 | } | ||
594 | |||
595 | |||
596 | void PPPData::setVolumeHigh(const QString &s) { | ||
597 | writeConfig(MODEM_GRP, VOLUME_HIGH, s); | ||
598 | } | ||
599 | |||
600 | |||
601 | QString PPPData::volumeInitString() { | ||
602 | QString s; | ||
603 | |||
604 | switch(volume()) { | ||
605 | case 0: | ||
606 | s = volumeOff(); | ||
607 | break; | ||
608 | case 1: | ||
609 | s = volumeMedium(); | ||
610 | break; | ||
611 | case 2: | ||
612 | s = volumeHigh(); | ||
613 | break; | ||
614 | default: | ||
615 | s = volumeMedium(); | ||
616 | } | ||
617 | |||
618 | return s; | ||
619 | } | ||
620 | |||
621 | |||
622 | int PPPData::volume() { | ||
623 | return readNumConfig(MODEM_GRP, VOLUME_KEY, 1); | ||
624 | } | ||
625 | |||
626 | |||
627 | void PPPData::setVolume(int i) { | ||
628 | writeConfig(MODEM_GRP, VOLUME_KEY, i); | ||
629 | } | ||
630 | |||
631 | int PPPData::waitForDialTone() { | ||
632 | return readNumConfig(MODEM_GRP, DIALTONEWAIT_KEY, 1); | ||
633 | } | ||
634 | |||
635 | void PPPData::setWaitForDialTone(int i) { | ||
636 | writeConfig(MODEM_GRP, DIALTONEWAIT_KEY, i); | ||
637 | } | ||
638 | |||
639 | void PPPData::setModemAnswerStr(const QString &n) { | ||
640 | writeConfig(MODEM_GRP, ANSWERSTR_KEY, n); | ||
641 | } | ||
642 | |||
643 | |||
644 | const QString PPPData::modemRingResp() { | ||
645 | return readConfig(MODEM_GRP, RINGRESP_KEY, "RING"); | ||
646 | } | ||
647 | |||
648 | |||
649 | void PPPData::setModemRingResp(const QString &n) { | ||
650 | writeConfig(MODEM_GRP, RINGRESP_KEY, n); | ||
651 | } | ||
652 | |||
653 | |||
654 | const QString PPPData::modemAnswerResp() { | ||
655 | return readConfig(MODEM_GRP, ANSWERRESP_KEY, "CONNECT"); | ||
656 | } | ||
657 | |||
658 | |||
659 | void PPPData::setModemAnswerResp(const QString &n) { | ||
660 | writeConfig(MODEM_GRP, ANSWERRESP_KEY, n); | ||
661 | } | ||
662 | |||
663 | |||
664 | const QString PPPData::enter() { | ||
665 | return readConfig(MODEM_GRP, ENTER_KEY, "CR"); | ||
666 | } | ||
667 | |||
668 | |||
669 | void PPPData::setEnter(const QString &n) { | ||
670 | writeConfig(MODEM_GRP, ENTER_KEY, n); | ||
671 | } | ||
672 | |||
673 | |||
674 | // | ||
675 | // functions to set/return account information | ||
676 | // | ||
677 | |||
678 | //returns number of accounts | ||
679 | int PPPData::count() const { | ||
680 | return highcount + 1; | ||
681 | } | ||
682 | |||
683 | |||
684 | bool PPPData::setAccount(const QString &aname) { | ||
685 | for(int i = 0; i <= highcount; i++) { | ||
686 | setAccountbyIndex(i); | ||
687 | if(accname() == aname) { | ||
688 | caccount = i; | ||
689 | return true; | ||
690 | } | ||
691 | } | ||
692 | return false; | ||
693 | } | ||
694 | |||
695 | |||
696 | bool PPPData::setAccountbyIndex(int i) { | ||
697 | if(i >= 0 && i <= highcount) { | ||
698 | caccount = i; | ||
699 | cgroup.sprintf("%s%i", ACCOUNT_GRP, i); | ||
700 | return true; | ||
701 | } | ||
702 | return false; | ||
703 | } | ||
704 | |||
705 | |||
706 | bool PPPData::isUniqueAccname(const QString &n) { | ||
707 | int current = caccount; | ||
708 | for(int i=0; i <= highcount; i++) { | ||
709 | setAccountbyIndex(i); | ||
710 | if(accname() == n && i != current) { | ||
711 | setAccountbyIndex(current); | ||
712 | return false; | ||
713 | } | ||
714 | } | ||
715 | setAccountbyIndex(current); | ||
716 | return true; | ||
717 | } | ||
718 | |||
719 | |||
720 | bool PPPData::deleteAccount() { | ||
721 | if(caccount < 0) | ||
722 | return false; | ||
723 | |||
724 | // QMap <QString, QString> map; | ||
725 | // QMap <QString, QString>::Iterator it; | ||
726 | |||
727 | // set all entries of the current account to "" | ||
728 | // tille: do not handle the accounts here... (?) | ||
729 | // map = config->entryMap(cgroup); | ||
730 | // it = map.begin(); | ||
731 | // while (it != map.end()) { | ||
732 | // config->writeEntry(it.key(), ""); | ||
733 | // it++; | ||
734 | // } | ||
735 | |||
736 | // // shift the succeeding accounts | ||
737 | // for(int i = caccount+1; i <= highcount; i++) { | ||
738 | // setAccountbyIndex(i); | ||
739 | // map = config->entryMap(cgroup); | ||
740 | // it = map.begin(); | ||
741 | // setAccountbyIndex(i-1); | ||
742 | // config->setGroup(cgroup); | ||
743 | // while (it != map.end()) { | ||
744 | // config->writeEntry(it.key(), *it); | ||
745 | // it++; | ||
746 | // } | ||
747 | // } | ||
748 | |||
749 | // // make sure the top account is cleared | ||
750 | // setAccountbyIndex(highcount); | ||
751 | // map = config->entryMap(cgroup); | ||
752 | // it = map.begin(); | ||
753 | // config->setGroup(cgroup); | ||
754 | // while (it.key() != QString::null) { | ||
755 | // config->writeEntry(it.key(), ""); | ||
756 | // it++; | ||
757 | // } | ||
758 | |||
759 | highcount--; | ||
760 | if(caccount > highcount) | ||
761 | caccount = highcount; | ||
762 | |||
763 | setAccountbyIndex(caccount); | ||
764 | |||
765 | return true; | ||
766 | } | ||
767 | |||
768 | |||
769 | bool PPPData::deleteAccount(const QString &aname) { | ||
770 | if(!setAccount(aname)) | ||
771 | return false; | ||
772 | |||
773 | deleteAccount(); | ||
774 | |||
775 | return true; | ||
776 | } | ||
777 | |||
778 | |||
779 | int PPPData::newaccount() { | ||
780 | |||
781 | if(!config || highcount >= MAX_ACCOUNTS) | ||
782 | return -1; | ||
783 | |||
784 | highcount++; | ||
785 | setAccountbyIndex(highcount); | ||
786 | |||
787 | setpppdArgumentDefaults(); | ||
788 | |||
789 | return caccount; | ||
790 | } | ||
791 | |||
792 | int PPPData::copyaccount(int i) { | ||
793 | |||
794 | if(highcount >= MAX_ACCOUNTS) | ||
795 | return -1; | ||
796 | |||
797 | setAccountbyIndex(i); | ||
798 | |||
799 | // QMap <QString, QString> map = config->entryMap(cgroup); | ||
800 | // QMap <QString, QString>::ConstIterator it = map.begin(); | ||
801 | |||
802 | QString newname = i18n("%1_copy").arg(accname()); | ||
803 | |||
804 | newaccount(); | ||
805 | |||
806 | // while (it != map.end()) { | ||
807 | // config->writeEntry(it.key(), *it); | ||
808 | // it++; | ||
809 | // } | ||
810 | |||
811 | setAccname(newname); | ||
812 | |||
813 | return caccount; | ||
814 | } | ||
815 | |||
816 | |||
817 | const QString PPPData::accname() { | ||
818 | return readConfig(cgroup, NAME_KEY); | ||
819 | } | ||
820 | |||
821 | void PPPData::setAccname(const QString &n) { | ||
822 | if(!cgroup.isNull()) { | ||
823 | // are we manipulating the default account's name ? then change it, too. | ||
824 | bool def = accname() == defaultAccount(); | ||
825 | writeConfig(cgroup, NAME_KEY, n); | ||
826 | if (def) | ||
827 | setDefaultAccount(n); | ||
828 | } | ||
829 | } | ||
830 | |||
831 | |||
832 | #define SEPARATOR_CHAR ':' | ||
833 | QStringList &PPPData::phonenumbers() { | ||
834 | |||
835 | readListConfig(cgroup, PHONENUMBER_KEY, phonelist, SEPARATOR_CHAR); | ||
836 | return phonelist; | ||
837 | |||
838 | } | ||
839 | |||
840 | |||
841 | const QString PPPData::phonenumber() { | ||
842 | return readConfig(cgroup, PHONENUMBER_KEY); | ||
843 | } | ||
844 | |||
845 | |||
846 | void PPPData::setPhonenumber(const QString &n) { | ||
847 | writeConfig(cgroup, PHONENUMBER_KEY, n); | ||
848 | } | ||
849 | |||
850 | |||
851 | const QString PPPData::dialPrefix() { | ||
852 | return readConfig(cgroup, DIAL_PREFIX_KEY, ""); | ||
853 | } | ||
854 | |||
855 | |||
856 | void PPPData::setDialPrefix(const QString &s) { | ||
857 | writeConfig(cgroup, DIAL_PREFIX_KEY, s); | ||
858 | } | ||
859 | |||
860 | |||
861 | int PPPData::authMethod() { | ||
862 | return readNumConfig(cgroup, AUTH_KEY, 0); | ||
863 | } | ||
864 | |||
865 | |||
866 | void PPPData::setAuthMethod(int value) { | ||
867 | writeConfig(cgroup, AUTH_KEY, value); | ||
868 | } | ||
869 | |||
870 | |||
871 | const QString PPPData::storedUsername() { | ||
872 | return readConfig(cgroup, STORED_USERNAME_KEY, ""); | ||
873 | } | ||
874 | |||
875 | |||
876 | void PPPData::setStoredUsername(const QString &b) { | ||
877 | writeConfig(cgroup, STORED_USERNAME_KEY, b); | ||
878 | } | ||
879 | |||
880 | |||
881 | const QString PPPData::storedPassword() { | ||
882 | return readConfig(cgroup, STORED_PASSWORD_KEY, ""); | ||
883 | } | ||
884 | |||
885 | |||
886 | void PPPData::setStoredPassword(const QString &b) { | ||
887 | writeConfig(cgroup, STORED_PASSWORD_KEY, b); | ||
888 | } | ||
889 | |||
890 | |||
891 | bool PPPData::storePassword() { | ||
892 | return (bool)readNumConfig(cgroup, STORE_PASSWORD_KEY, 1); | ||
893 | } | ||
894 | |||
895 | |||
896 | const QString PPPData::command_before_connect() { | ||
897 | return readConfig(cgroup, BEFORE_CONNECT_KEY); | ||
898 | } | ||
899 | |||
900 | |||
901 | void PPPData::setCommand_before_connect(const QString &n) { | ||
902 | writeConfig(cgroup, BEFORE_CONNECT_KEY, n); | ||
903 | } | ||
904 | |||
905 | |||
906 | void PPPData::setStorePassword(bool b) { | ||
907 | writeConfig(cgroup, STORE_PASSWORD_KEY, (int)b); | ||
908 | } | ||
909 | |||
910 | |||
911 | const QString PPPData::command_on_connect() { | ||
912 | return readConfig(cgroup, COMMAND_KEY); | ||
913 | } | ||
914 | |||
915 | |||
916 | void PPPData::setCommand_on_connect(const QString &n) { | ||
917 | writeConfig(cgroup, COMMAND_KEY, n); | ||
918 | } | ||
919 | |||
920 | |||
921 | const QString PPPData::command_on_disconnect() { | ||
922 | return readConfig(cgroup, DISCONNECT_COMMAND_KEY); | ||
923 | } | ||
924 | |||
925 | |||
926 | void PPPData::setCommand_on_disconnect(const QString &n) { | ||
927 | writeConfig(cgroup, DISCONNECT_COMMAND_KEY, n); | ||
928 | } | ||
929 | |||
930 | |||
931 | const QString PPPData::command_before_disconnect() { | ||
932 | return readConfig(cgroup, BEFORE_DISCONNECT_KEY); | ||
933 | } | ||
934 | |||
935 | |||
936 | void PPPData::setCommand_before_disconnect(const QString &n) { | ||
937 | writeConfig(cgroup, BEFORE_DISCONNECT_KEY, n); | ||
938 | } | ||
939 | |||
940 | |||
941 | const QString PPPData::ipaddr() { | ||
942 | return readConfig(cgroup, IPADDR_KEY); | ||
943 | } | ||
944 | |||
945 | |||
946 | void PPPData::setIpaddr(const QString &n) { | ||
947 | writeConfig(cgroup, IPADDR_KEY, n); | ||
948 | } | ||
949 | |||
950 | |||
951 | const QString PPPData::subnetmask() { | ||
952 | return readConfig(cgroup, SUBNETMASK_KEY); | ||
953 | } | ||
954 | |||
955 | |||
956 | void PPPData::setSubnetmask(const QString &n) { | ||
957 | writeConfig(cgroup, SUBNETMASK_KEY, n); | ||
958 | } | ||
959 | |||
960 | |||
961 | bool PPPData::autoname() { | ||
962 | return (bool) readNumConfig(cgroup, AUTONAME_KEY, false); | ||
963 | } | ||
964 | |||
965 | |||
966 | void PPPData::setAutoname(bool set) { | ||
967 | writeConfig(cgroup, AUTONAME_KEY, (int) set); | ||
968 | } | ||
969 | |||
970 | |||
971 | bool PPPData::AcctEnabled() { | ||
972 | return (bool) readNumConfig(cgroup, ACCTENABLED_KEY, false); | ||
973 | } | ||
974 | |||
975 | |||
976 | void PPPData::setAcctEnabled(bool set) { | ||
977 | writeConfig(cgroup, ACCTENABLED_KEY, (int) set); | ||
978 | } | ||
979 | |||
980 | |||
981 | int PPPData::VolAcctEnabled() { | ||
982 | return readNumConfig(cgroup, VOLACCTENABLED_KEY, 0); | ||
983 | } | ||
984 | |||
985 | |||
986 | void PPPData::setVolAcctEnabled(int set) { | ||
987 | writeConfig(cgroup, VOLACCTENABLED_KEY, set); | ||
988 | } | ||
989 | |||
990 | |||
991 | const QString PPPData::gateway() { | ||
992 | return readConfig(cgroup, GATEWAY_KEY); | ||
993 | } | ||
994 | |||
995 | |||
996 | void PPPData::setGateway(const QString &n ) { | ||
997 | writeConfig(cgroup, GATEWAY_KEY, n); | ||
998 | } | ||
999 | |||
1000 | |||
1001 | bool PPPData::defaultroute() { | ||
1002 | // default route is by default 'on'. | ||
1003 | return (bool) readNumConfig(cgroup, DEFAULTROUTE_KEY, true); | ||
1004 | } | ||
1005 | |||
1006 | |||
1007 | void PPPData::setDefaultroute(bool set) { | ||
1008 | writeConfig(cgroup, DEFAULTROUTE_KEY, (int) set); | ||
1009 | } | ||
1010 | |||
1011 | |||
1012 | bool PPPData::autoDNS() { | ||
1013 | bool set = (bool) readNumConfig(cgroup, AUTODNS_KEY, true); | ||
1014 | return (set && gpppdata.pppdVersionMin(2, 3, 7)); | ||
1015 | } | ||
1016 | |||
1017 | |||
1018 | void PPPData::setAutoDNS(bool set) { | ||
1019 | writeConfig(cgroup, AUTODNS_KEY, (int) set); | ||
1020 | } | ||
1021 | |||
1022 | |||
1023 | void PPPData::setExDNSDisabled(bool set) { | ||
1024 | writeConfig(cgroup, EXDNSDISABLED_KEY, (int) set); | ||
1025 | } | ||
1026 | |||
1027 | |||
1028 | bool PPPData::exDNSDisabled() { | ||
1029 | return (bool) readNumConfig(cgroup, EXDNSDISABLED_KEY,0); | ||
1030 | } | ||
1031 | |||
1032 | |||
1033 | QStringList &PPPData::dns() { | ||
1034 | static QStringList dnslist; | ||
1035 | |||
1036 | readListConfig(cgroup, DNS_KEY, dnslist); | ||
1037 | while(dnslist.count() > MAX_DNS_ENTRIES) | ||
1038 | dnslist.remove(dnslist.last()); | ||
1039 | |||
1040 | return dnslist; | ||
1041 | } | ||
1042 | |||
1043 | |||
1044 | void PPPData::setDns(QStringList &list) { | ||
1045 | writeListConfig(cgroup, DNS_KEY, list); | ||
1046 | } | ||
1047 | |||
1048 | |||
1049 | const QString PPPData::domain() { | ||
1050 | return readConfig(cgroup, DOMAIN_KEY); | ||
1051 | } | ||
1052 | |||
1053 | |||
1054 | void PPPData::setDomain(const QString &n ) { | ||
1055 | writeConfig(cgroup, DOMAIN_KEY, n); | ||
1056 | } | ||
1057 | |||
1058 | |||
1059 | QStringList &PPPData::scriptType() { | ||
1060 | static QStringList typelist; | ||
1061 | |||
1062 | readListConfig(cgroup, SCRIPTCOM_KEY, typelist); | ||
1063 | while(typelist.count() > MAX_SCRIPT_ENTRIES) | ||
1064 | typelist.remove(typelist.last()); | ||
1065 | |||
1066 | return typelist; | ||
1067 | } | ||
1068 | |||
1069 | |||
1070 | void PPPData::setScriptType(QStringList &list) { | ||
1071 | writeListConfig(cgroup, SCRIPTCOM_KEY, list); | ||
1072 | } | ||
1073 | |||
1074 | |||
1075 | QStringList &PPPData::script() { | ||
1076 | static QStringList scriptlist; | ||
1077 | |||
1078 | readListConfig(cgroup, SCRIPTARG_KEY, scriptlist); | ||
1079 | while(scriptlist.count() > MAX_SCRIPT_ENTRIES) | ||
1080 | scriptlist.remove(scriptlist.last()); | ||
1081 | |||
1082 | return scriptlist; | ||
1083 | } | ||
1084 | |||
1085 | |||
1086 | void PPPData::setScript(QStringList &list) { | ||
1087 | writeListConfig(cgroup, SCRIPTARG_KEY, list); | ||
1088 | } | ||
1089 | |||
1090 | |||
1091 | const QString PPPData::accountingFile() { | ||
1092 | return readConfig(cgroup, ACCTFILE_KEY); | ||
1093 | } | ||
1094 | |||
1095 | |||
1096 | void PPPData::setAccountingFile(const QString &n) { | ||
1097 | writeConfig(cgroup, ACCTFILE_KEY, n); | ||
1098 | } | ||
1099 | |||
1100 | |||
1101 | const QString PPPData::totalCosts() { | ||
1102 | return readConfig(cgroup, TOTALCOSTS_KEY); | ||
1103 | } | ||
1104 | |||
1105 | |||
1106 | void PPPData::setTotalCosts(const QString &n) { | ||
1107 | writeConfig(cgroup, TOTALCOSTS_KEY, n); | ||
1108 | } | ||
1109 | |||
1110 | |||
1111 | int PPPData::totalBytes() { | ||
1112 | return readNumConfig(cgroup, TOTALBYTES_KEY, 0); | ||
1113 | } | ||
1114 | |||
1115 | void PPPData::setTotalBytes(int n) { | ||
1116 | writeConfig(cgroup, TOTALBYTES_KEY, n); | ||
1117 | } | ||
1118 | |||
1119 | |||
1120 | QStringList &PPPData::pppdArgument() { | ||
1121 | static QStringList arglist; | ||
1122 | |||
1123 | while(arglist.count() > MAX_PPPD_ARGUMENTS) | ||
1124 | arglist.remove(arglist.last()); | ||
1125 | readListConfig(cgroup, PPPDARG_KEY, arglist); | ||
1126 | |||
1127 | return arglist; | ||
1128 | } | ||
1129 | |||
1130 | |||
1131 | void PPPData::setpppdArgument(QStringList &args) { | ||
1132 | writeListConfig(cgroup, PPPDARG_KEY, args); | ||
1133 | } | ||
1134 | |||
1135 | |||
1136 | void PPPData::setpppdArgumentDefaults() { | ||
1137 | QStringList arg; | ||
1138 | setpppdArgument(arg); | ||
1139 | } | ||
1140 | |||
1141 | |||
1142 | // graphing widget | ||
1143 | void PPPData::setGraphingOptions(bool enable, | ||
1144 | QColor bg, | ||
1145 | QColor text, | ||
1146 | QColor in, | ||
1147 | QColor out) | ||
1148 | { | ||
1149 | if(config) { | ||
1150 | config->setGroup(GRAPH_GRP); | ||
1151 | config->writeEntry(GENABLED, enable); | ||
1152 | // config->writeEntry(GCOLOR_BG, bg); | ||
1153 | // config->writeEntry(GCOLOR_TEXT, text); | ||
1154 | // config->writeEntry(GCOLOR_IN, in); | ||
1155 | // config->writeEntry(GCOLOR_OUT, out); | ||
1156 | } | ||
1157 | } | ||
1158 | |||
1159 | void PPPData::graphingOptions(bool &enable, | ||
1160 | QColor &bg, | ||
1161 | QColor &text, | ||
1162 | QColor &in, | ||
1163 | QColor &out) | ||
1164 | { | ||
1165 | QColor c; | ||
1166 | |||
1167 | if(config) { | ||
1168 | config->setGroup(GRAPH_GRP); | ||
1169 | enable = config->readBoolEntry(GENABLED, true); | ||
1170 | bg = Qt::white; | ||
1171 | //bg = config->readColorEntry(GCOLOR_BG, &c); | ||
1172 | text = Qt::black; | ||
1173 | //text = config->readColorEntry(GCOLOR_TEXT, &c); | ||
1174 | in = Qt::blue; | ||
1175 | //in = config->readColorEntry(GCOLOR_IN, &c); | ||
1176 | out = Qt::red; | ||
1177 | //out = config->readColorEntry(GCOLOR_OUT, &c); | ||
1178 | } | ||
1179 | } | ||
1180 | |||
1181 | |||
1182 | bool PPPData::graphingEnabled() { | ||
1183 | return (bool) readNumConfig(GRAPH_GRP, GENABLED, true); | ||
1184 | } | ||
1185 | |||
1186 | |||
1187 | |||
1188 | // | ||
1189 | //functions to change/set the child pppd process info | ||
1190 | // | ||
1191 | bool PPPData::pppdRunning() const { | ||
1192 | return pppdisrunning; | ||
1193 | } | ||
1194 | |||
1195 | void PPPData::setpppdRunning(bool set) { | ||
1196 | pppdisrunning = set; | ||
1197 | } | ||
1198 | |||
1199 | int PPPData::pppdError() const { | ||
1200 | return pppderror; | ||
1201 | } | ||
1202 | |||
1203 | void PPPData::setpppdError(int err) { | ||
1204 | pppderror = err; | ||
1205 | } | ||
1206 | |||
1207 | |||
1208 | // | ||
1209 | // window position | ||
1210 | // | ||
1211 | void PPPData::winPosConWin(int& p_x, int& p_y) { | ||
1212 | p_x = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_X, QApplication::desktop()->width()/2-160); | ||
1213 | p_y = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_Y, QApplication::desktop()->height()/2-55); | ||
1214 | } | ||
1215 | |||
1216 | void PPPData::setWinPosConWin(int p_x, int p_y) { | ||
1217 | writeConfig(WINPOS_GRP, WINPOS_CONWIN_X, p_x); | ||
1218 | writeConfig(WINPOS_GRP, WINPOS_CONWIN_Y, p_y); | ||
1219 | } | ||
1220 | |||
1221 | void PPPData::winPosStatWin(int& p_x, int& p_y) { | ||
1222 | p_x = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_X, QApplication::desktop()->width()/2-160); | ||
1223 | p_y = readNumConfig(WINPOS_GRP, WINPOS_STATWIN_Y, QApplication::desktop()->height()/2-55); | ||
1224 | } | ||
1225 | |||
1226 | void PPPData::setWinPosStatWin(int p_x, int p_y) { | ||
1227 | writeConfig(WINPOS_GRP, WINPOS_STATWIN_X, p_x); | ||
1228 | writeConfig(WINPOS_GRP, WINPOS_STATWIN_Y, p_y); | ||
1229 | } | ||