2 * kPPP: A pppd Front End for the KDE project
5 * Copyright (C) 1997 Bernd Johannes Wuebben
6 * wuebben@math.cornell.edu
9 * Copyright (C) 1997 Jay Painter
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this program; if not, write to the Free
23 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <QGridLayout>
31 #include <QHBoxLayout>
33 #include <QVBoxLayout>
34 #include <QApplication>
35 #include <kmessagebox.h>
38 #include <kiconloader.h>
39 #include <kdialogbuttonbox.h>
42 #include <kwindowsystem.h>
46 #include "newwidget.h"
50 DialWidget::DialWidget( QWidget
*parent
, bool isnewaccount
)
53 parent
->setMinimumWidth(440);
54 QVBoxLayout
*topLayout
= new QVBoxLayout(parent
);
55 topLayout
->setSpacing(KDialog::spacingHint());
56 topLayout
->addWidget(this);
58 QGridLayout
*tl
= new QGridLayout(this );
59 tl
->setSpacing( KDialog::spacingHint() );
61 connect_label
= new QLabel(i18n("Connection &name:"), this);
62 tl
->addWidget(connect_label
, 0, 0);
64 connectname_l
= new QLineEdit(this);
65 connectname_l
->setMaxLength(ACCNAME_SIZE
);
66 connect_label
->setBuddy(connectname_l
);
68 tl
->addWidget(connectname_l
, 0, 1);
69 QString tmp
= i18n("Type in a unique name for this connection");
71 connect_label
->setWhatsThis(tmp
);
72 connectname_l
->setWhatsThis(tmp
);
75 number_label
= new QLabel(i18n("P&hone number:"), this);
76 number_label
->setAlignment(Qt::AlignTop
|Qt::AlignLeft
);
77 tl
->addWidget(number_label
, 1, 0);
79 QHBoxLayout
*lpn
= new QHBoxLayout();
81 tl
->addLayout(lpn
, 1, 1);
82 numbers
= new Q3ListBox(this);
83 number_label
->setBuddy(numbers
);
84 numbers
->setMinimumSize(120, 70);
85 lpn
->addWidget(numbers
);
86 QVBoxLayout
*lpn1
= new QVBoxLayout
;
88 add
= new QPushButton(i18n("&Add..."), this);
89 del
= new QPushButton(i18n("&Remove"), this);
91 up
= new QPushButton(this);
92 up
->setIcon(KIcon("go-up"));
93 down
= new QPushButton(this);
94 down
->setIcon(KIcon("go-down"));
99 lpn1
->addWidget(down
);
100 connect(add
, SIGNAL(clicked()),
101 this, SLOT(addNumber()));
102 connect(del
, SIGNAL(clicked()),
103 this, SLOT(delNumber()));
104 connect(up
, SIGNAL(clicked()),
105 this, SLOT(upNumber()));
106 connect(down
, SIGNAL(clicked()),
107 this, SLOT(downNumber()));
108 connect(numbers
, SIGNAL(highlighted(int)),
109 this, SLOT(selectionChanged(int)));
112 tmp
= i18n("<p>Specifies the phone numbers to dial. You\n"
113 "can supply multiple numbers here, simply\n"
114 "click on \"Add\". You can arrange the\n"
115 "order the numbers are tried by using the\n"
117 "When a number is busy or fails, <i>kppp</i> will \n"
118 "try the next number and so on");
120 number_label
->setWhatsThis(tmp
);
121 numbers
->setWhatsThis(tmp
);
123 auth_l
= new QLabel(i18n("A&uthentication:"), this);
124 tl
->addWidget(auth_l
, 3, 0);
126 auth
= new QComboBox(this);
127 auth_l
->setBuddy(auth
);
128 auth
->addItem(i18n("Script-based"));
129 auth
->addItem(i18n("PAP"));
130 auth
->addItem(i18n("Terminal-based"));
131 auth
->addItem(i18n("CHAP"));
132 auth
->addItem(i18n("PAP/CHAP"));
133 tl
->addWidget(auth
, 3, 1);
134 tmp
= i18n("<p>Specifies the method used to identify yourself to\n"
135 "the PPP server. Most universities still use\n"
136 "<b>Terminal</b>- or <b>Script</b>-based authentication,\n"
137 "while most ISP use <b>PAP</b> and/or <b>CHAP</b>. If\n"
138 "unsure, contact your ISP.\n"
140 "If you can choose between PAP and CHAP,\n"
141 "choose CHAP, because it's much safer. If you don't know\n"
142 "whether PAP or CHAP is right, choose PAP/CHAP.");
144 auth_l
->setWhatsThis(tmp
);
145 auth
->setWhatsThis(tmp
);
147 store_password
= new QCheckBox(i18n("Store &password"), this);
148 store_password
->setChecked(true);
149 tl
->addWidget(store_password
, 4, 0, 1, 2, Qt::AlignRight
);
150 store_password
->setWhatsThis(
151 i18n("<p>When this is turned on, your ISP password\n"
152 "will be saved in <i>kppp</i>'s config file, so\n"
153 "you do not need to type it in every time.\n"
155 "<b><font color=\"red\">Warning:</font> your password will be stored as\n"
156 "plain text in the config file, which is\n"
157 "readable only to you. Make sure nobody\n"
158 "gains access to this file!"));
160 cbtype_l
= new QLabel(i18n("&Callback type:"), this);
161 tl
->addWidget(cbtype_l
, 5, 0);
163 cbtype
= new QComboBox(this);
164 cbtype_l
->setBuddy(cbtype
);
165 cbtype
->addItem(i18n("None"));
166 cbtype
->addItem(i18n("Administrator-defined"));
167 cbtype
->addItem(i18n("User-defined"));
168 connect(cbtype
, SIGNAL(highlighted(int)),
169 this, SLOT(cbtypeChanged(int)));
170 tl
->addWidget(cbtype
, 5, 1);
171 tmp
= i18n("Callback type");
173 cbtype_l
->setWhatsThis(tmp
);
174 cbtype
->setWhatsThis(tmp
);
176 cbphone_l
= new QLabel(i18n("Call&back number:"), this);
177 tl
->addWidget(cbphone_l
, 6, 0);
179 cbphone
= new QLineEdit(this);
180 cbphone_l
->setBuddy(cbphone
);
181 cbphone
->setMaxLength(140);
182 tl
->addWidget(cbphone
, 6, 1);
183 tmp
= i18n("Callback phone number");
185 cbphone_l
->setWhatsThis(tmp
);
186 cbphone
->setWhatsThis(tmp
);
188 pppdargs
= new QPushButton(i18n("Customize &pppd Arguments..."), this);
189 connect(pppdargs
, SIGNAL(clicked()), SLOT(pppdargsbutton()));
190 tl
->addWidget(pppdargs
, 7, 0, 1, 2, Qt::AlignCenter
);
192 // Set defaults if editing an existing connection
194 connectname_l
->setText(gpppdata
.accname());
196 // insert the phone numbers into the listbox
197 QString n
= gpppdata
.phonenumber();
200 while(idx
!= n
.length()) {
203 numbers
->insertItem(tmp
);
210 numbers
->insertItem(tmp
);
212 auth
->setCurrentIndex(gpppdata
.authMethod());
213 store_password
->setChecked(gpppdata
.storePassword());
214 cbtype
->setCurrentIndex(gpppdata
.callbackType());
215 cbphone
->setText(gpppdata
.callbackPhone());
217 // select PAP/CHAP as default
218 auth
->setCurrentIndex(AUTH_PAPCHAP
);
219 // select NONE as default
220 cbtype
->setCurrentIndex(CBTYPE_NONE
);
223 emit
cbtypeChanged(cbtype
->currentIndex());
229 bool DialWidget::save() {
230 //first check to make sure that the account name is unique!
231 if(connectname_l
->text().isEmpty() ||
232 !gpppdata
.isUniqueAccname(connectname_l
->text())) {
235 gpppdata
.setAccname(connectname_l
->text());
238 for(uint i
= 0; i
< numbers
->count(); i
++) {
241 number
+= numbers
->text(i
);
244 gpppdata
.setPhonenumber(number
);
245 gpppdata
.setAuthMethod(auth
->currentIndex());
246 gpppdata
.setStorePassword(store_password
->isChecked());
247 gpppdata
.setCallbackType(cbtype
->currentIndex());
248 gpppdata
.setCallbackPhone(cbphone
->text());
254 void DialWidget::numbersChanged() {
255 int sel
= numbers
->currentItem();
257 del
->setEnabled(sel
!= -1);
258 up
->setEnabled(sel
!= -1 && sel
!= 0);
259 down
->setEnabled(sel
!= -1 && sel
!= (int)numbers
->count()-1);
262 void DialWidget::cbtypeChanged(int value
) {
263 cbphone_l
->setEnabled(value
== CBTYPE_USER
);
264 cbphone
->setEnabled(value
== CBTYPE_USER
);
267 void DialWidget::selectionChanged(int) {
272 void DialWidget::addNumber() {
273 PhoneNumberDialog
dlg(this);
275 numbers
->insertItem(dlg
.phoneNumber());
281 void DialWidget::delNumber() {
282 if(numbers
->currentItem() != -1) {
283 numbers
->removeItem(numbers
->currentItem());
289 void DialWidget::upNumber() {
290 int idx
= numbers
->currentItem();
292 QString item
= numbers
->text(idx
);
293 numbers
->removeItem(idx
);
294 numbers
->insertItem(item
, idx
-1);
295 numbers
->setCurrentItem(idx
-1);
301 void DialWidget::downNumber() {
302 int idx
= numbers
->currentItem();
304 QString item
= numbers
->text(idx
);
305 numbers
->removeItem(idx
);
306 numbers
->insertItem(item
, idx
+1);
307 numbers
->setCurrentItem(idx
+1);
313 void DialWidget::pppdargsbutton() {
314 PPPdArguments
pa(this);
320 /////////////////////////////////////////////////////////////////////////////
322 /////////////////////////////////////////////////////////////////////////////
323 ExecWidget::ExecWidget(QWidget
*parent
, bool isnewaccount
) :
326 QVBoxLayout
*tl
= new QVBoxLayout(parent
);
327 tl
->setSpacing(KDialog::spacingHint());
330 QLabel
*l
= new QLabel(\
331 i18n("Here you can select commands to run at certain stages of the\n"
332 "connection. The commands are run with your real user id, so\n"
333 "you cannot run any commands here requiring root permissions\n"
334 "(unless, of course, you are root).\n\n"
335 "Be sure to supply the whole path to the program otherwise\n"
336 "kppp might be unable to find it."), parent
);
337 l
->setMinimumHeight(l
->sizeHint().height());
341 QGridLayout
*l1
= new QGridLayout( );
344 l1
->setColumnStretch(0, 0);
345 l1
->setColumnStretch(1, 1);
347 before_connect_l
= new QLabel(i18n("&Before connect:"), parent
);
348 before_connect_l
->setAlignment(Qt::AlignVCenter
);
349 l1
->addWidget(before_connect_l
, 0, 0);
350 before_connect
= new QLineEdit(parent
);
351 before_connect_l
->setBuddy(before_connect
);
352 before_connect
->setMaxLength(COMMAND_SIZE
);
353 l1
->addWidget(before_connect
, 0, 1);
354 QString tmp
= i18n("Allows you to run a program <b>before</b> a connection\n"
355 "is established. It is called immediately before\n"
356 "dialing has begun.\n\n"
357 "This might be useful, e.g. to stop HylaFAX blocking the\n"
360 before_connect_l
->setWhatsThis(tmp
);
361 before_connect
->setWhatsThis(tmp
);
363 command_label
= new QLabel(i18n("&Upon connect:"), parent
);
364 command_label
->setAlignment(Qt::AlignVCenter
);
365 l1
->addWidget(command_label
, 1, 0);
366 command
= new QLineEdit(parent
);
367 command_label
->setBuddy(command
);
368 command
->setMaxLength(COMMAND_SIZE
);
369 l1
->addWidget(command
, 1, 1);
370 tmp
= i18n("Allows you to run a program <b>after</b> a connection\n"
371 "is established. When your program is called, all\n"
372 "preparations for an Internet connection are finished.\n"
374 "Very useful for fetching mail and news");
376 command_label
->setWhatsThis(tmp
);
377 command
->setWhatsThis(tmp
);
379 predisconnect_label
= new QLabel(i18n("Before &disconnect:"),
381 predisconnect_label
->setAlignment(Qt::AlignVCenter
);
382 l1
->addWidget(predisconnect_label
, 2, 0);
383 predisconnect
= new QLineEdit(parent
);
384 predisconnect_label
->setBuddy(predisconnect
);
385 predisconnect
->setMaxLength(COMMAND_SIZE
);
386 l1
->addWidget(predisconnect
, 2, 1);
387 tmp
= i18n("Allows you to run a program <b>before</b> a connection\n"
388 "is closed. The connection will stay open until\n"
389 "the program exits.");
391 predisconnect_label
->setWhatsThis(tmp
);
392 predisconnect
->setWhatsThis(tmp
);
394 discommand_label
= new QLabel(i18n("U&pon disconnect:"),
396 discommand_label
->setAlignment(Qt::AlignVCenter
);
397 l1
->addWidget(discommand_label
, 3, 0);
399 discommand
= new QLineEdit(parent
);
400 discommand_label
->setBuddy(discommand
);
401 discommand
->setMaxLength(COMMAND_SIZE
);
402 l1
->addWidget(discommand
, 3, 1);
403 tmp
= i18n("Allows you to run a program <b>after</b> a connection\n"
406 discommand_label
->setWhatsThis(tmp
);
407 discommand
->setWhatsThis(tmp
);
409 // extra space between entries
410 l1
->addItem(new QSpacerItem(0, 5), 1, 0);
411 l1
->addItem(new QSpacerItem(0, 5), 3, 0);
416 // Set defaults if editing an existing connection
418 before_connect
->setText(gpppdata
.command_before_connect());
419 command
->setText(gpppdata
.command_on_connect());
420 discommand
->setText(gpppdata
.command_on_disconnect());
421 predisconnect
->setText(gpppdata
.command_before_disconnect());
426 bool ExecWidget::save() {
427 gpppdata
.setCommand_before_connect(before_connect
->text());
428 gpppdata
.setCommand_on_connect(command
->text());
429 gpppdata
.setCommand_before_disconnect(predisconnect
->text());
430 gpppdata
.setCommand_on_disconnect(discommand
->text());
436 /////////////////////////////////////////////////////////////////////////////
440 /////////////////////////////////////////////////////////////////////////////
441 IPWidget::IPWidget( QWidget
*parent
, bool isnewaccount
, const char *name
)
445 QVBoxLayout
*topLayout
= new QVBoxLayout(parent
);
446 topLayout
->setSpacing(KDialog::spacingHint());
448 box
= new Q3GroupBox(1, Qt::Horizontal
,i18n("C&onfiguration"), parent
);
449 box
->setInsideSpacing(KDialog::spacingHint());
451 rb
= new Q3ButtonGroup(parent
);
453 connect(rb
, SIGNAL(clicked(int)),
454 SLOT(hitIPSelect(int)));
456 dynamicadd_rb
= new QRadioButton(box
);
457 dynamicadd_rb
->setText(i18n("Dynamic IP address"));
458 dynamicadd_rb
->setWhatsThis(
459 i18n("Select this option when your computer gets an\n"
460 "internet address (IP) every time a\n"
461 "connection is made.\n"
463 "Almost every Internet Service Provider uses\n"
464 "this method, so this should be turned on."));
466 staticadd_rb
= new QRadioButton(box
);
467 staticadd_rb
->setText(i18n("Static IP address"));
468 rb
->insert(dynamicadd_rb
, 0);
469 rb
->insert(staticadd_rb
, 1);
470 staticadd_rb
->setWhatsThis(
471 i18n("Select this option when your computer has a\n"
472 "fixed internet address (IP). Most computers\n"
473 "don't have this, so you should probably select\n"
474 "dynamic IP addressing unless you know what you\n"
477 QWidget
*ipWidget
= new QWidget(box
);
478 QGridLayout
*ipLayout
= new QGridLayout(ipWidget
);
479 ipLayout
->setSpacing(KDialog::spacingHint());
481 ipaddress_label
= new QLabel(i18n("&IP address:"), ipWidget
);
482 QString tmp
= i18n("If your computer has a permanent internet\n"
483 "address, you must supply your IP address here.");
484 ipLayout
->addWidget(ipaddress_label
, 0, 0);
486 ipaddress_l
= new IPLineEdit(ipWidget
);
487 ipaddress_label
->setBuddy(ipaddress_l
);
488 ipLayout
->addWidget(ipaddress_l
, 0, 1);
490 ipaddress_label
->setWhatsThis(tmp
);
491 ipaddress_l
->setWhatsThis(tmp
);
493 sub_label
= new QLabel(i18n("&Subnet mask:"), ipWidget
);
494 tmp
= i18n("<p>If your computer has a static Internet address,\n"
495 "you must supply a network mask here. In almost\n"
496 "all cases this netmask will be <b>255.255.255.0</b>,\n"
497 "but your mileage may vary.\n"
499 "If unsure, contact your Internet Service Provider");
500 ipLayout
->addWidget(sub_label
, 1, 0);
502 subnetmask_l
= new IPLineEdit(ipWidget
);
503 sub_label
->setBuddy(subnetmask_l
);
504 ipLayout
->addWidget(subnetmask_l
, 1, 1);
506 sub_label
->setWhatsThis(tmp
);
507 subnetmask_l
->setWhatsThis(tmp
);
509 autoname
= new QCheckBox(i18n("&Auto-configure hostname from this IP"), parent
);
510 autoname
->setChecked(gpppdata
.autoname());
511 connect(autoname
,SIGNAL(toggled(bool)),
512 this,SLOT(autoname_t(bool)));
514 autoname
->setWhatsThis(
515 i18n("<p>Whenever you connect, this reconfigures\n"
516 "your hostname to match the IP address you\n"
517 "got from the PPP server. This may be useful\n"
518 "if you need to use a protocol which depends\n"
519 "on this information, but it can also cause several\n"
520 "<a href=\"kppp-7.html#autohostname\">problems</a>.\n"
522 "Do not enable this unless you really need it."));
524 topLayout
->addWidget(box
);
525 topLayout
->addWidget(autoname
);
526 topLayout
->addStretch();
528 //load info from gpppdata
530 if(gpppdata
.ipaddr() == "0.0.0.0" &&
531 gpppdata
.subnetmask() == "0.0.0.0") {
532 dynamicadd_rb
->setChecked(true);
534 autoname
->setChecked(gpppdata
.autoname());
537 ipaddress_l
->setText(gpppdata
.ipaddr());
538 subnetmask_l
->setText(gpppdata
.subnetmask());
539 staticadd_rb
->setChecked(true);
540 autoname
->setChecked(false);
544 dynamicadd_rb
->setChecked(true);
550 void IPWidget::autoname_t(bool on
) {
551 static bool was_warned
= false;
553 // big-fat warning when selecting the auto configure hostname option
554 if(on
&& !was_warned
) {
555 KMessageBox::information(this,
556 i18n("Selecting this option might cause some weird "
557 "problems with the X-server and applications "
558 "while kppp is connected. Don't use it until "
559 "you know what you are doing!\n"
560 "For more information take a look at the "
561 "handbook (or help) in the section \"Frequently "
562 "asked questions\"."),
569 void IPWidget::save() {
570 if(dynamicadd_rb
->isChecked()) {
571 gpppdata
.setIpaddr("0.0.0.0");
572 gpppdata
.setSubnetmask("0.0.0.0");
574 gpppdata
.setIpaddr(ipaddress_l
->text());
575 gpppdata
.setSubnetmask(subnetmask_l
->text());
577 gpppdata
.setAutoname(autoname
->isChecked());
581 void IPWidget::hitIPSelect( int i
) {
583 ipaddress_label
->setEnabled(false);
584 sub_label
->setEnabled(false);
585 ipaddress_l
->setEnabled(false);
586 subnetmask_l
->setEnabled(false);
589 ipaddress_label
->setEnabled(true);
590 sub_label
->setEnabled(true);
591 ipaddress_l
->setEnabled(true);
592 subnetmask_l
->setEnabled(true);
598 DNSWidget::DNSWidget( QWidget
*parent
, bool isnewaccount
)
601 QVBoxLayout
*topLayout
= new QVBoxLayout(parent
);
602 topLayout
->setSpacing(KDialog::spacingHint());
603 topLayout
->addWidget(this);
605 // box = new QGroupBox(this);
606 QGridLayout
*tl
= new QGridLayout(this );
607 tl
->setSpacing( KDialog::spacingHint() );
609 dnsdomain_label
= new QLabel(i18n("Domain &name:"), this);
610 tl
->addWidget(dnsdomain_label
, 0, 0);
612 dnsdomain
= new QLineEdit(this);
613 dnsdomain_label
->setBuddy(dnsdomain
);
614 dnsdomain
->setMaxLength(DOMAIN_SIZE
);
615 tl
->addWidget(dnsdomain
, 0, 1);
616 QString tmp
= i18n("If you enter a domain name here, this domain\n"
617 "name is used for your computer while you are\n"
618 "connected. When the connection is closed, the\n"
619 "original domain name of your computer is\n"
622 "If you leave this field blank, no changes are\n"
623 "made to the domain name.");
625 dnsdomain_label
->setWhatsThis(tmp
);
626 dnsdomain
->setWhatsThis(tmp
);
628 conf_label
= new QLabel(i18n("C&onfiguration:"), this);
629 tl
->addWidget(conf_label
, 1, 0);
631 bg
= new Q3ButtonGroup("Group", this);
632 conf_label
->setBuddy(bg
);
633 connect(bg
, SIGNAL(clicked(int)), SLOT(DNS_Mode_Selected(int)));
636 autodns
= new QRadioButton(i18n("Automatic"), this);
637 bg
->insert(autodns
, 0);
638 tl
->addWidget(autodns
, 1, 1);
639 // no automatic DNS detection for pppd < 2.3.7
640 if(!gpppdata
.pppdVersionMin(2, 3, 7))
641 autodns
->setEnabled(false);
643 mandns
= new QRadioButton(i18n("Manual"), this);
644 bg
->insert(mandns
, 1);
645 tl
->addWidget(mandns
, 2, 1);
647 dns_label
= new QLabel(i18n("DNS &IP address:"), this);
648 tl
->addWidget(dns_label
, 3, 0);
650 QHBoxLayout
*l2
= new QHBoxLayout
;
651 tl
->addLayout(l2
, 3, 1);
652 dnsipaddr
= new IPLineEdit(this);
653 dns_label
->setBuddy(dnsipaddr
);
654 connect(dnsipaddr
, SIGNAL(returnPressed()),
656 connect(dnsipaddr
, SIGNAL(textChanged(const QString
&)),
657 SLOT(DNS_Edit_Changed(const QString
&)));
658 l2
->addWidget(dnsipaddr
, 1);
660 tmp
= i18n("<p>Allows you to specify a new DNS server to be\n"
661 "used while you are connected. When the\n"
662 "connection is closed, this DNS entry will be\n"
665 "To add a DNS server, type in the IP address of\n"
666 "the DNS server here and click on <b>Add</b>");
668 dns_label
->setWhatsThis( tmp
);
669 dnsipaddr
->setWhatsThis( tmp
);
671 QHBoxLayout
*l1
= new QHBoxLayout
;
672 tl
->addLayout(l1
, 4, 1);
673 add
= new QPushButton(i18n("&Add"), this);
674 connect(add
, SIGNAL(clicked()), SLOT(adddns()));
675 int width
= add
->sizeHint().width();
676 width
= qMax(width
,60);
677 add
->setMinimumWidth(width
);
681 i18n("Click this button to add the DNS server\n"
682 "specified in the field above. The entry\n"
683 "will then be added to the list below"));
685 remove
= new QPushButton(i18n("&Remove"), this);
686 connect(remove
, SIGNAL(clicked()), SLOT(removedns()));
687 width
= remove
->sizeHint().width();
688 width
= qMax(width
,60);
689 remove
->setMinimumWidth(width
);
690 l1
->addWidget(remove
);
691 remove
->setWhatsThis(
692 i18n("Click this button to remove the selected DNS\n"
693 "server entry from the list below"));
695 servers_label
= new QLabel(i18n("DNS address &list:"), this);
696 servers_label
->setAlignment(Qt::AlignTop
|Qt::AlignLeft
);
697 tl
->addWidget(servers_label
, 5, 0);
699 dnsservers
= new Q3ListBox(this);
700 servers_label
->setBuddy(dnsservers
);
701 dnsservers
->setMinimumSize(150, 80);
702 connect(dnsservers
, SIGNAL(highlighted(int)),
703 SLOT(DNS_Entry_Selected(int)));
704 tl
->addWidget(dnsservers
, 5, 1);
705 tmp
= i18n("<p>This shows all defined DNS servers to use\n"
706 "while you are connected. Use the <b>Add</b> and\n"
707 "<b>Remove</b> buttons to modify the list");
709 servers_label
->setWhatsThis(tmp
);
710 dnsservers
->setWhatsThis(tmp
);
712 exdnsdisabled_toggle
= new QCheckBox(i18n( \
713 "&Disable existing DNS servers during connection"),
715 exdnsdisabled_toggle
->setChecked(gpppdata
.exDNSDisabled());
716 tl
->addWidget(exdnsdisabled_toggle
, 6, 0, 1, 2, Qt::AlignCenter
);
717 exdnsdisabled_toggle
->setWhatsThis(
718 i18n("<p>When this option is selected, all DNS\n"
719 "servers specified in <tt>/etc/resolv.conf</tt> are\n"
720 "temporary disabled while the dialup connection\n"
721 "is established. After the connection is\n"
722 "closed, the servers will be re-enabled\n"
724 "Typically, there is no reason to use this\n"
725 "option, but it may become useful under \n"
726 "some circumstances."));
729 // restore data if editing
731 dnsservers
->insertStringList(gpppdata
.dns());
732 dnsdomain
->setText(gpppdata
.domain());
735 int mode
= gpppdata
.autoDNS() ? 0 : 1;
737 DNS_Mode_Selected(mode
);
742 void DNSWidget::DNS_Edit_Changed(const QString
&text
) {
743 QRegExp
r("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+");
744 add
->setEnabled(text
.contains(r
));
747 void DNSWidget::DNS_Entry_Selected(int) {
748 remove
->setEnabled(true);
751 void DNSWidget::DNS_Mode_Selected(int mode
) {
752 bool on
= (mode
== 1);
753 dns_label
->setEnabled(on
);
754 servers_label
->setEnabled(on
);
755 dnsipaddr
->setText("");
756 dnsipaddr
->setEnabled(on
);
757 add
->setEnabled(false);
758 remove
->setEnabled(dnsservers
->count()>0 && on
);
759 dnsservers
->clearSelection();
760 dnsservers
->setEnabled(on
);
761 dnsservers
->triggerUpdate(false);
764 void DNSWidget::save() {
765 gpppdata
.setAutoDNS(bg
->id(bg
->selected()) == 0);
766 QStringList serverlist
;
767 for(uint i
=0; i
< dnsservers
->count(); i
++)
768 serverlist
.append(dnsservers
->text(i
));
769 gpppdata
.setDns(serverlist
);
772 QString
s(dnsdomain
->text());
774 gpppdata
.setDomain(s
.mid(1));
776 gpppdata
.setDomain(dnsdomain
->text());
778 gpppdata
.setExDNSDisabled(exdnsdisabled_toggle
->isChecked());
782 void DNSWidget::adddns() {
783 if(dnsservers
->count() < MAX_DNS_ENTRIES
) {
784 dnsservers
->insertItem(dnsipaddr
->text());
785 dnsipaddr
->setText("");
790 void DNSWidget::removedns() {
792 i
= dnsservers
->currentItem();
794 dnsservers
->removeItem(i
);
795 remove
->setEnabled(dnsservers
->count()>0);
802 GatewayWidget::GatewayWidget( QWidget
*parent
, bool isnewaccount
)
805 QVBoxLayout
*topLayout
= new QVBoxLayout(parent
);
806 topLayout
->setSpacing(KDialog::spacingHint());
808 box
= new Q3GroupBox (1, Qt::Horizontal
,i18n("C&onfiguration"), parent
);
809 box
->setInsideSpacing(KDialog::spacingHint());
811 rb
= new Q3ButtonGroup(parent
);
813 connect(rb
, SIGNAL(clicked(int)), SLOT(hitGatewaySelect(int)));
815 defaultgateway
= new QRadioButton(box
);
816 defaultgateway
->setText(i18n("Default gateway"));
817 rb
->insert(defaultgateway
, 0);
818 defaultgateway
->setWhatsThis(
819 i18n("This makes the PPP peer computer (the computer\n"
820 "you are connected to with your modem) to act as\n"
821 "a gateway. Your computer will send all packets not\n"
822 "going to a computer inside your local net to this\n"
823 "computer, which will route these packets.\n"
825 "This is the default for most ISPs, so you should\n"
826 "probably leave this option on."));
829 staticgateway
= new QRadioButton(box
);
830 staticgateway
->setText(i18n("Static gateway"));
831 rb
->insert(staticgateway
, 1);
832 staticgateway
->setWhatsThis(
833 i18n("<p>Allows you to specify which computer you want\n"
834 "to use as gateway (see <i>Default Gateway</i> above)"));
836 QWidget
*gateBox
= new QWidget(box
);
837 QHBoxLayout
*hboxLayout1
= new QHBoxLayout(gateBox
);
838 gate_label
= new QLabel(i18n("Gateway &IP address:"), gateBox
);
839 hboxLayout1
->addWidget(gate_label
);
840 gatewayaddr
= new IPLineEdit(gateBox
);
841 hboxLayout1
->addWidget(gatewayaddr
);
842 gate_label
->setBuddy(gatewayaddr
);
844 defaultroute
= new QCheckBox(i18n("&Assign the default route to this gateway"),
846 defaultroute
->setWhatsThis(
847 i18n("If this option is enabled, all packets not\n"
848 "going to the local net are routed through\n"
849 "the PPP connection.\n"
851 "Normally, you should turn this on"));
853 topLayout
->addWidget(box
);
854 topLayout
->addWidget(defaultroute
);
855 topLayout
->addStretch();
857 //load info from gpppdata
859 if(gpppdata
.gateway() == "0.0.0.0") {
860 defaultgateway
->setChecked(true);
864 gatewayaddr
->setText(gpppdata
.gateway());
865 staticgateway
->setChecked(true);
867 defaultroute
->setChecked(gpppdata
.defaultroute());
870 defaultgateway
->setChecked(true);
872 defaultroute
->setChecked(true);
876 void GatewayWidget::save() {
877 gpppdata
.setGateway(gatewayaddr
->text());
878 gpppdata
.setDefaultroute(defaultroute
->isChecked());
882 void GatewayWidget::hitGatewaySelect( int i
) {
884 gatewayaddr
->setText("0.0.0.0");
885 gatewayaddr
->setEnabled(false);
886 gate_label
->setEnabled(false);
889 gatewayaddr
->setEnabled(true);
890 gatewayaddr
->setText("");
891 gate_label
->setEnabled(true);
897 ScriptWidget::ScriptWidget( QWidget
*parent
, bool isnewaccount
, const char *name
)
901 QVBoxLayout
*tl
= new QVBoxLayout(parent
);
902 tl
->setSpacing(KDialog::spacingHint());
904 se
= new ScriptEdit(parent
);
905 connect(se
, SIGNAL(returnPressed()), SLOT(addButton()));
908 // insert equal-sized buttons
909 KDialogButtonBox
*bbox
= new KDialogButtonBox(parent
);
910 add
= bbox
->addButton(i18n("&Add"),QDialogButtonBox::ActionRole
);
911 connect(add
, SIGNAL(clicked()), SLOT(addButton()));
912 insert
= bbox
->addButton(i18n("&Insert"),QDialogButtonBox::ActionRole
);
913 connect(insert
, SIGNAL(clicked()), SLOT(insertButton()));
914 remove
= bbox
->addButton(i18n("&Remove"),QDialogButtonBox::ActionRole
);
915 connect(remove
, SIGNAL(clicked()), SLOT(removeButton()));
918 QHBoxLayout
*l12
= new QHBoxLayout
;
920 stl
= new Q3ListBox(parent
);
921 stl
->setVScrollBarMode( Q3ScrollView::AlwaysOff
);
922 connect(stl
, SIGNAL(highlighted(int)), SLOT(stlhighlighted(int)));
923 stl
->setMinimumSize(QSize(70, 140));
925 sl
= new Q3ListBox(parent
);
926 sl
->setVScrollBarMode( Q3ScrollView::AlwaysOff
);
927 connect(sl
, SIGNAL(highlighted(int)), SLOT(slhighlighted(int)));
928 sl
->setMinimumSize(QSize(150, 140));
930 slb
= new QScrollBar(parent
);
931 slb
->setFixedWidth(slb
->sizeHint().width());
932 connect(slb
, SIGNAL(valueChanged(int)), SLOT(scrolling(int)));
934 l12
->addWidget(stl
, 1);
935 l12
->addWidget(sl
, 3);
936 l12
->addWidget(slb
, 0);
938 //load data from gpppdata
940 QStringList
&comlist
= gpppdata
.scriptType();
941 QStringList
&arglist
= gpppdata
.script();
942 QStringList::Iterator itcom
= comlist
.begin();
943 QStringList::Iterator itarg
= arglist
.begin();
946 itcom
!= comlist
.end() && itarg
!= arglist
.end();
949 stl
->insertItem(*itcom
);
950 sl
->insertItem(*itarg
);
954 insert
->setEnabled(false);
955 remove
->setEnabled(false);
960 bool ScriptWidget::check() {
965 if(sl
->count() > 0) {
966 for( uint i
=0; i
<= sl
->count()-1; i
++) {
967 if(stl
->text(i
) == "LoopStart") {
970 if (stl
->text(i
) == "LoopEnd") {
973 if ( lend
> lstart
) errcnt
++;
975 return ( (errcnt
== 0 ) && (lstart
== lend
) );
981 void ScriptWidget::save() {
982 QStringList typelist
, arglist
;
983 for(uint i
=0; i
< sl
->count(); i
++) {
984 typelist
.append(stl
->text(i
));
985 arglist
.append(sl
->text(i
));
987 gpppdata
.setScriptType(typelist
);
988 gpppdata
.setScript(arglist
);
993 void ScriptWidget::adjustScrollBar() {
994 if((int)sl
->count() <= sl
->numItemsVisible())
997 slb
->setRange(0, (sl
->count() - sl
->numItemsVisible())+1);
1001 void ScriptWidget::scrolling(int i
) {
1007 void ScriptWidget::slhighlighted(int i
) {
1008 insert
->setEnabled(true);
1009 remove
->setEnabled(true);
1010 stl
->setCurrentItem(i
);
1014 void ScriptWidget::stlhighlighted(int i
) {
1015 insert
->setEnabled(true);
1016 remove
->setEnabled(true);
1017 sl
->setCurrentItem(i
);
1021 void ScriptWidget::addButton() {
1022 //don't allow more than the maximum script entries
1023 if(sl
->count() == MAX_SCRIPT_ENTRIES
-1)
1026 switch(se
->type()) {
1027 case ScriptEdit::Expect
:
1028 stl
->insertItem("Expect");
1029 sl
->insertItem(se
->text());
1032 case ScriptEdit::Send
:
1033 stl
->insertItem("Send");
1034 sl
->insertItem(se
->text());
1037 case ScriptEdit::SendNoEcho
:
1038 stl
->insertItem("SendNoEcho");
1039 sl
->insertItem(se
->text());
1042 case ScriptEdit::Pause
:
1043 stl
->insertItem("Pause");
1044 sl
->insertItem(se
->text());
1047 case ScriptEdit::Hangup
:
1048 stl
->insertItem("Hangup");
1052 case ScriptEdit::Answer
:
1053 stl
->insertItem("Answer");
1057 case ScriptEdit::Timeout
:
1058 stl
->insertItem("Timeout");
1059 sl
->insertItem(se
->text());
1062 case ScriptEdit::Password
:
1063 stl
->insertItem("Password");
1064 sl
->insertItem(se
->text());
1067 case ScriptEdit::ID
:
1068 stl
->insertItem("ID");
1069 sl
->insertItem(se
->text());
1072 case ScriptEdit::Prompt
:
1073 stl
->insertItem("Prompt");
1074 sl
->insertItem(se
->text());
1077 case ScriptEdit::PWPrompt
:
1078 stl
->insertItem("PWPrompt");
1079 sl
->insertItem(se
->text());
1082 case ScriptEdit::LoopStart
:
1083 stl
->insertItem("LoopStart");
1084 sl
->insertItem(se
->text());
1087 case ScriptEdit::LoopEnd
:
1088 stl
->insertItem("LoopEnd");
1089 sl
->insertItem(se
->text());
1092 case ScriptEdit::Scan
:
1093 stl
->insertItem("Scan");
1094 sl
->insertItem(se
->text());
1097 case ScriptEdit::Save
:
1098 stl
->insertItem("Save");
1099 sl
->insertItem(se
->text());
1106 //get the scrollbar adjusted, and scroll the list so we can see what
1109 slb
->setValue(slb
->maximum());
1111 //clear the text in the entry box
1116 void ScriptWidget::insertButton() {
1117 //exit if there is no highlighted item, or we've reached the
1118 //maximum entries in the script list
1119 if(sl
->currentItem() < 0 || (sl
->count() == MAX_SCRIPT_ENTRIES
-1))
1122 switch(se
->type()) {
1123 case ScriptEdit::Expect
:
1124 stl
->insertItem("Expect", stl
->currentItem());
1125 sl
->insertItem(se
->text(), sl
->currentItem());
1128 case ScriptEdit::Send
:
1129 stl
->insertItem("Send", stl
->currentItem());
1130 sl
->insertItem(se
->text(), sl
->currentItem());
1133 case ScriptEdit::SendNoEcho
:
1134 stl
->insertItem("SendNoEcho", stl
->currentItem());
1135 sl
->insertItem(se
->text(), sl
->currentItem());
1138 case ScriptEdit::Pause
:
1139 stl
->insertItem("Pause", stl
->currentItem());
1140 sl
->insertItem(se
->text(), sl
->currentItem());
1143 case ScriptEdit::Hangup
:
1144 stl
->insertItem("Hangup", stl
->currentItem());
1145 sl
->insertItem("", sl
->currentItem());
1148 case ScriptEdit::Answer
:
1149 stl
->insertItem("Answer", stl
->currentItem());
1150 sl
->insertItem("", sl
->currentItem());
1153 case ScriptEdit::Timeout
:
1154 stl
->insertItem("Timeout", stl
->currentItem());
1155 sl
->insertItem(se
->text(), sl
->currentItem());
1158 case ScriptEdit::Password
:
1159 stl
->insertItem("Password", stl
->currentItem());
1160 sl
->insertItem(se
->text(), sl
->currentItem());
1163 case ScriptEdit::ID
:
1164 stl
->insertItem("ID", stl
->currentItem());
1165 sl
->insertItem(se
->text(), sl
->currentItem());
1168 case ScriptEdit::Prompt
:
1169 stl
->insertItem("Prompt", stl
->currentItem());
1170 sl
->insertItem(se
->text(), sl
->currentItem());
1173 case ScriptEdit::PWPrompt
:
1174 stl
->insertItem("PWPrompt", stl
->currentItem());
1175 sl
->insertItem(se
->text(), sl
->currentItem());
1178 case ScriptEdit::LoopStart
:
1179 stl
->insertItem("LoopStart", stl
->currentItem());
1180 sl
->insertItem(se
->text(), sl
->currentItem());
1183 case ScriptEdit::LoopEnd
:
1184 stl
->insertItem("LoopEnd", stl
->currentItem());
1185 sl
->insertItem(se
->text(), sl
->currentItem());
1188 case ScriptEdit::Scan
:
1189 stl
->insertItem("Scan", stl
->currentItem());
1190 sl
->insertItem(se
->text(), sl
->currentItem());
1193 case ScriptEdit::Save
:
1194 stl
->insertItem("Save", stl
->currentItem());
1195 sl
->insertItem(se
->text(), sl
->currentItem());
1206 void ScriptWidget::removeButton() {
1207 if(sl
->currentItem() >= 0) {
1208 int stlc
= stl
->currentItem();
1209 sl
->removeItem(sl
->currentItem());
1210 stl
->removeItem(stlc
);
1212 insert
->setEnabled(sl
->currentItem() != -1);
1213 remove
->setEnabled(sl
->currentItem() != -1);
1219 /////////////////////////////////////////////////////////////////////////////
1221 // Used to specify a new phone number
1223 /////////////////////////////////////////////////////////////////////////////
1224 PhoneNumberDialog::PhoneNumberDialog(QWidget
*parent
)
1226 setCaption( i18n("Add Phone Number") );
1227 setButtons( Ok
|Cancel
);
1228 setDefaultButton( Ok
);
1230 KWindowSystem::setIcons(winId(), qApp
->windowIcon().pixmap(IconSize(KIconLoader::Desktop
),IconSize(KIconLoader::Desktop
)), qApp
->windowIcon().pixmap(IconSize(KIconLoader::Small
),IconSize(KIconLoader::Small
)));
1232 QWidget
*hbox
= new QWidget(this);
1233 QHBoxLayout
*hboxLayout2
= new QHBoxLayout(hbox
);
1234 hbox
->setLayout(hboxLayout2
);
1235 setMainWidget(hbox
);
1237 hboxLayout2
->setSpacing(KDialog::spacingHint());
1239 QLabel
*lbl_le
= new QLabel(i18n("Enter a phone number:"));
1240 hboxLayout2
->addWidget(lbl_le
);
1242 QLineEdit
*le
= new QLineEdit
;
1243 le
->setMinimumWidth(125);
1244 hboxLayout2
->addWidget(le
);
1246 connect(le
, SIGNAL(textChanged(const QString
&)),
1247 this, SLOT(textChanged(const QString
&)));
1252 showButtonSeparator(true);
1256 QString
PhoneNumberDialog::phoneNumber() {
1257 QString s
= le
->text();
1263 void PhoneNumberDialog::textChanged(const QString
&s
) {
1264 enableButtonOk(s
.length() > 0);