author | tille <tille> | 2003-05-23 19:43:46 (UTC) |
---|---|---|
committer | tille <tille> | 2003-05-23 19:43:46 (UTC) |
commit | 9b6b21112f38181f49b07e973bfe00c0d83a6900 (patch) (unidiff) | |
tree | c2fa45a93ac5c26fe98558f28bb0a166b14ad065 | |
parent | 34b9974063032242e5de65fa56d4c2cb5e1ce565 (diff) | |
download | opie-9b6b21112f38181f49b07e973bfe00c0d83a6900.zip opie-9b6b21112f38181f49b07e973bfe00c0d83a6900.tar.gz opie-9b6b21112f38181f49b07e973bfe00c0d83a6900.tar.bz2 |
configure dialog basicly working
more kppp stuff... ;)
39 files changed, 10083 insertions, 47 deletions
diff --git a/noncore/settings/networksettings/main.cpp b/noncore/settings/networksettings/main.cpp index a9d1a87..1b74d62 100644 --- a/noncore/settings/networksettings/main.cpp +++ b/noncore/settings/networksettings/main.cpp | |||
@@ -1,13 +1,13 @@ | |||
1 | #include "mainwindowimp.h" | 1 | #include "mainwindowimp.h" |
2 | #include <qpe/qpeapplication.h> | 2 | #include <qpe/qpeapplication.h> |
3 | 3 | ||
4 | int main(int argc, char **argv) | 4 | int main(int argc, char **argv) |
5 | { | 5 | { |
6 | QPEApplication app(argc, argv); | 6 | QPEApplication app(argc, argv); |
7 | MainWindowImp window; | 7 | MainWindowImp window; |
8 | app.showMainWidget(&window); | 8 | app.showMainWidget(&window); |
9 | return app.exec(); | 9 | return app.exec(); |
10 | } | 10 | } |
11 | 11 | ||
12 | // main.cpp | 12 | // main.cpp |
13 | 13 | ||
diff --git a/noncore/settings/networksettings/ppp/accounts.cpp b/noncore/settings/networksettings/ppp/accounts.cpp new file mode 100644 index 0000000..d902517 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/accounts.cpp | |||
@@ -0,0 +1,491 @@ | |||
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 <qdir.h> | ||
28 | #include <stdlib.h> | ||
29 | #include <qlayout.h> | ||
30 | #include <qtabwidget.h> | ||
31 | #include <qtabdialog.h> | ||
32 | #include <qwhatsthis.h> | ||
33 | #include <qmessagebox.h> | ||
34 | |||
35 | #include <qapplication.h> | ||
36 | #include <qbuttongroup.h> | ||
37 | #include <qmessagebox.h> | ||
38 | //#include <klocale.h> | ||
39 | #define i18n QObject::tr | ||
40 | //#include <kglobal.h> | ||
41 | //#include <kwin.h> | ||
42 | //#include <kdialogbase.h> | ||
43 | #include <qvgroupbox.h> | ||
44 | |||
45 | #include "pppdata.h" | ||
46 | #include "accounts.h" | ||
47 | //#include "accounting.h" | ||
48 | //#include "providerdb.h" | ||
49 | #include "edit.h" | ||
50 | |||
51 | void parseargs(char* buf, char** args); | ||
52 | |||
53 | AccountWidget::AccountWidget( QWidget *parent, const char *name ) | ||
54 | : QWidget( parent, name ) | ||
55 | { | ||
56 | int min = 0; | ||
57 | QVBoxLayout *l1 = new QVBoxLayout(this, 10, 10); | ||
58 | |||
59 | // add a hbox | ||
60 | // QHBoxLayout *l11 = new QHBoxLayout; | ||
61 | // l1->addLayout(l11); | ||
62 | |||
63 | accountlist_l = new QListBox(this); | ||
64 | accountlist_l->setMinimumSize(160, 128); | ||
65 | connect(accountlist_l, SIGNAL(highlighted(int)), | ||
66 | this, SLOT(slotListBoxSelect(int))); | ||
67 | connect(accountlist_l, SIGNAL(selected(int)), | ||
68 | this, SLOT(editaccount())); | ||
69 | l1->addWidget(accountlist_l, 10); | ||
70 | |||
71 | // QVBoxLayout *l111 = new QVBoxLayout(this); | ||
72 | // l11->addLayout(l111, 1); | ||
73 | edit_b = new QPushButton(i18n("&Edit..."), this); | ||
74 | connect(edit_b, SIGNAL(clicked()), SLOT(editaccount())); | ||
75 | QWhatsThis::add(edit_b, i18n("Allows you to modify the selected account")); | ||
76 | |||
77 | min = edit_b->sizeHint().width(); | ||
78 | min = QMAX(70,min); | ||
79 | edit_b->setMinimumWidth(min); | ||
80 | |||
81 | l1->addWidget(edit_b); | ||
82 | |||
83 | new_b = new QPushButton(i18n("&New..."), this); | ||
84 | connect(new_b, SIGNAL(clicked()), SLOT(newaccount())); | ||
85 | l1->addWidget(new_b); | ||
86 | QWhatsThis::add(new_b, i18n("Create a new dialup connection\n" | ||
87 | "to the Internet")); | ||
88 | |||
89 | copy_b = new QPushButton(i18n("Co&py"), this); | ||
90 | connect(copy_b, SIGNAL(clicked()), SLOT(copyaccount())); | ||
91 | l1->addWidget(copy_b); | ||
92 | QWhatsThis::add(copy_b, | ||
93 | i18n("Makes a copy of the selected account. All\n" | ||
94 | "settings of the selected account are copied\n" | ||
95 | "to a new account, that you can modify to fit your\n" | ||
96 | "needs")); | ||
97 | |||
98 | delete_b = new QPushButton(i18n("De&lete"), this); | ||
99 | connect(delete_b, SIGNAL(clicked()), SLOT(deleteaccount())); | ||
100 | l1->addWidget(delete_b); | ||
101 | QWhatsThis::add(delete_b, | ||
102 | i18n("<p>Deletes the selected account\n\n" | ||
103 | "<font color=\"red\"><b>Use with care!</b></font>")); | ||
104 | |||
105 | QHBoxLayout *l12 = new QHBoxLayout; | ||
106 | l1->addStretch(1); | ||
107 | l1->addLayout(l12); | ||
108 | |||
109 | // QVBoxLayout *l121 = new QVBoxLayout; | ||
110 | // l12->addLayout(l121); | ||
111 | // l121->addStretch(1); | ||
112 | // costlabel = new QLabel(i18n("Phone costs:"), parent); | ||
113 | // costlabel->setEnabled(FALSE); | ||
114 | // l121->addWidget(costlabel); | ||
115 | |||
116 | // costedit = new QLineEdit(parent); | ||
117 | // costedit->setFocusPolicy(QWidget::NoFocus); | ||
118 | // costedit->setFixedHeight(costedit->sizeHint().height()); | ||
119 | // costedit->setEnabled(FALSE); | ||
120 | // l121->addWidget(costedit); | ||
121 | // l121->addStretch(1); | ||
122 | // QString tmp = i18n("<p>This shows the accumulated phone costs\n" | ||
123 | // "for the selected account.\n" | ||
124 | // "\n" | ||
125 | // "<b>Important</b>: If you have more than one \n" | ||
126 | // "account - beware, this is <b>NOT</b> the sum \n" | ||
127 | // "of the phone costs of all your accounts!"); | ||
128 | // QWhatsThis::add(costlabel, tmp); | ||
129 | // QWhatsThis::add(costedit, tmp); | ||
130 | |||
131 | // vollabel = new QLabel(i18n("Volume:"), parent); | ||
132 | // vollabel->setEnabled(FALSE); | ||
133 | // l121->addWidget(vollabel); | ||
134 | |||
135 | // voledit = new QLineEdit(parent,"voledit"); | ||
136 | // voledit->setFocusPolicy(QWidget::NoFocus); | ||
137 | // voledit->setFixedHeight(voledit->sizeHint().height()); | ||
138 | // voledit->setEnabled(FALSE); | ||
139 | // l121->addWidget(voledit); | ||
140 | // tmp = i18n("<p>This shows the number of bytes transferred\n" | ||
141 | // "for the selected account (not for all of your\n" | ||
142 | // "accounts. You can select what to display in\n" | ||
143 | // "the accounting dialog.\n" | ||
144 | // "\n" | ||
145 | // "<a href=\"#volaccounting\">More on volume accounting</a>"); | ||
146 | |||
147 | // QWhatsThis::add(vollabel,tmp); | ||
148 | // QWhatsThis::add(voledit, tmp); | ||
149 | |||
150 | // QVBoxLayout *l122 = new QVBoxLayout; | ||
151 | // l12->addStretch(1); | ||
152 | // l12->addLayout(l122); | ||
153 | |||
154 | // l122->addStretch(1); | ||
155 | // reset = new QPushButton(i18n("&Reset..."), parent); | ||
156 | // reset->setEnabled(FALSE); | ||
157 | // connect(reset, SIGNAL(clicked()), | ||
158 | // this, SLOT(resetClicked())); | ||
159 | // l122->addWidget(reset); | ||
160 | |||
161 | // log = new QPushButton(i18n("&View Logs"), this); | ||
162 | // connect(log, SIGNAL(clicked()), | ||
163 | // this, SLOT(viewLogClicked())); | ||
164 | // l122->addWidget(log); | ||
165 | // l122->addStretch(1); | ||
166 | |||
167 | //load up account list from gppdata to the list box | ||
168 | if(gpppdata.count() > 0) { | ||
169 | for(int i=0; i <= gpppdata.count()-1; i++) { | ||
170 | gpppdata.setAccountbyIndex(i); | ||
171 | accountlist_l->insertItem(gpppdata.accname()); | ||
172 | } | ||
173 | } | ||
174 | |||
175 | slotListBoxSelect(accountlist_l->currentItem()); | ||
176 | |||
177 | l1->activate(); | ||
178 | } | ||
179 | |||
180 | |||
181 | |||
182 | void AccountWidget::slotListBoxSelect(int idx) { | ||
183 | delete_b->setEnabled((bool)(idx != -1)); | ||
184 | edit_b->setEnabled((bool)(idx != -1)); | ||
185 | copy_b->setEnabled((bool)(idx != -1)); | ||
186 | if(idx!=-1) { | ||
187 | QString account = gpppdata.accname(); | ||
188 | gpppdata.setAccountbyIndex(accountlist_l->currentItem()); | ||
189 | // reset->setEnabled(TRUE); | ||
190 | // costlabel->setEnabled(TRUE); | ||
191 | // costedit->setEnabled(TRUE); | ||
192 | // costedit->setText(AccountingBase::getCosts(accountlist_l->text(accountlist_l->currentItem()))); | ||
193 | |||
194 | // vollabel->setEnabled(TRUE); | ||
195 | // voledit->setEnabled(TRUE); | ||
196 | int bytes = gpppdata.totalBytes(); | ||
197 | // voledit->setText(prettyPrintVolume(bytes)); | ||
198 | gpppdata.setAccount(account); | ||
199 | } else{ | ||
200 | // reset->setEnabled(FALSE); | ||
201 | // costlabel->setEnabled(FALSE); | ||
202 | // costedit->setText(""); | ||
203 | // costedit->setEnabled(FALSE); | ||
204 | // vollabel->setEnabled(FALSE); | ||
205 | // voledit->setText(""); | ||
206 | // voledit->setEnabled(FALSE); | ||
207 | } | ||
208 | } | ||
209 | |||
210 | |||
211 | // void AccountWidget::viewLogClicked(){ | ||
212 | |||
213 | // QApplication::flushX(); | ||
214 | // if(fork() == 0) { | ||
215 | // setgid(getgid()); | ||
216 | // setuid(getuid()); | ||
217 | // system("kppplogview -kppp"); | ||
218 | // _exit(0); | ||
219 | // } | ||
220 | // } | ||
221 | |||
222 | |||
223 | // void AccountWidget::resetClicked(){ | ||
224 | // if(accountlist_l->currentItem() == -1) | ||
225 | // return; | ||
226 | |||
227 | // // QueryReset dlg(this); | ||
228 | // // int what = dlg.exec(); | ||
229 | |||
230 | // // if(what && QueryReset::COSTS) { | ||
231 | // // emit resetCosts(accountlist_l->text(accountlist_l->currentItem())); | ||
232 | // // costedit->setText("0"); | ||
233 | // // } | ||
234 | |||
235 | // // if(what && QueryReset::VOLUME) { | ||
236 | // // emit resetVolume(accountlist_l->text(accountlist_l->currentItem())); | ||
237 | // // voledit->setText(prettyPrintVolume(0)); | ||
238 | // // } | ||
239 | // } | ||
240 | |||
241 | |||
242 | void AccountWidget::editaccount() { | ||
243 | gpppdata.setAccount(accountlist_l->text(accountlist_l->currentItem())); | ||
244 | |||
245 | int result = doTab(); | ||
246 | |||
247 | if(result == QDialog::Accepted) { | ||
248 | accountlist_l->changeItem(gpppdata.accname(),accountlist_l->currentItem()); | ||
249 | // emit resetaccounts(); | ||
250 | gpppdata.save(); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | |||
255 | void AccountWidget::newaccount() { | ||
256 | if(accountlist_l->count() == MAX_ACCOUNTS) { | ||
257 | QMessageBox::information(this, "sorry", i18n("Maximum number of accounts reached.")); | ||
258 | return; | ||
259 | } | ||
260 | |||
261 | int result; | ||
262 | // int query = QMessageBox::information(this, | ||
263 | // i18n("Do you want to use the wizard to create the new account or the " | ||
264 | // "standard, dialog-based setup?\n" | ||
265 | // "The wizard is easier and sufficient in most cases. If you need " | ||
266 | // "very special settings, you might want to try the standard, " | ||
267 | // "dialog-based setup."), | ||
268 | // i18n("Create New Account"), | ||
269 | // i18n("Wizard"), i18n("Dialog Setup"), i18n("Cancel")); | ||
270 | |||
271 | // switch(query) { | ||
272 | // case QMessageBox::Yes: | ||
273 | // { | ||
274 | // if (gpppdata.newaccount() == -1) | ||
275 | // return; | ||
276 | // // ProviderDB pdb(this); | ||
277 | // // result = pdb.exec(); | ||
278 | // break; | ||
279 | // } | ||
280 | // case QMessageBox::No: | ||
281 | if (gpppdata.newaccount() == -1){ | ||
282 | qDebug("gpppdata.newaccount() == -1"); | ||
283 | return; | ||
284 | } | ||
285 | result = doTab(); | ||
286 | // break; | ||
287 | // default: | ||
288 | // return; | ||
289 | // } | ||
290 | |||
291 | if(result == QDialog::Accepted) { | ||
292 | accountlist_l->insertItem(gpppdata.accname()); | ||
293 | accountlist_l->setSelected(accountlist_l->findItem(gpppdata.accname()), | ||
294 | true); | ||
295 | // emit resetaccounts(); | ||
296 | gpppdata.save(); | ||
297 | } else | ||
298 | gpppdata.deleteAccount(); | ||
299 | } | ||
300 | |||
301 | |||
302 | void AccountWidget::copyaccount() { | ||
303 | if(accountlist_l->count() == MAX_ACCOUNTS) { | ||
304 | QMessageBox::information(this, "sorry", i18n("Maximum number of accounts reached.")); | ||
305 | return; | ||
306 | } | ||
307 | |||
308 | if(accountlist_l->currentItem()<0) { | ||
309 | QMessageBox::information(this, "sorry", i18n("No account selected.")); | ||
310 | return; | ||
311 | } | ||
312 | |||
313 | gpppdata.copyaccount(accountlist_l->currentItem()); | ||
314 | |||
315 | accountlist_l->insertItem(gpppdata.accname()); | ||
316 | // emit resetaccounts(); | ||
317 | gpppdata.save(); | ||
318 | } | ||
319 | |||
320 | |||
321 | void AccountWidget::deleteaccount() { | ||
322 | |||
323 | QString s = i18n("Are you sure you want to delete\nthe account \"%1\"?") | ||
324 | .arg(accountlist_l->text(accountlist_l->currentItem())); | ||
325 | |||
326 | if(QMessageBox::warning(this, s, i18n("Confirm")) != QMessageBox::Yes) | ||
327 | return; | ||
328 | |||
329 | if(gpppdata.deleteAccount(accountlist_l->text(accountlist_l->currentItem()))) | ||
330 | accountlist_l->removeItem(accountlist_l->currentItem()); | ||
331 | |||
332 | emit resetaccounts(); | ||
333 | gpppdata.save(); | ||
334 | |||
335 | slotListBoxSelect(accountlist_l->currentItem()); | ||
336 | |||
337 | } | ||
338 | |||
339 | |||
340 | int AccountWidget::doTab(){ | ||
341 | QDialog *dlg = new QDialog( this ); | ||
342 | tabWindow = new QTabWidget( dlg ); | ||
343 | // tabWindow = new KDialogBase( KDialogBase::Tabbed, QString::null, | ||
344 | // KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, | ||
345 | // 0, 0, true); | ||
346 | // KWin::setIcons(tabWindow->winId(), kapp->icon(), kapp->miniIcon()); | ||
347 | bool isnewaccount; | ||
348 | |||
349 | if(gpppdata.accname().isEmpty()) { | ||
350 | tabWindow->setCaption(i18n("New Account")); | ||
351 | isnewaccount = true; | ||
352 | } else { | ||
353 | QString tit = i18n("Edit Account: "); | ||
354 | tit += gpppdata.accname(); | ||
355 | tabWindow->setCaption(tit); | ||
356 | isnewaccount = false; | ||
357 | } | ||
358 | |||
359 | dial_w = new DialWidget( tabWindow ); | ||
360 | tabWindow->addTab( dial_w, i18n("Dial") );//, i18n("Dial Setup")), isnewaccount); | ||
361 | ip_w = new IPWidget( tabWindow ); | ||
362 | tabWindow->addTab( ip_w, i18n("IP") );//, i18n("IP Setup")), isnewaccount); | ||
363 | gateway_w = new GatewayWidget( tabWindow ); | ||
364 | tabWindow->addTab( gateway_w, i18n("Gateway") );//, i18n("Gateway Setup")), isnewaccount); | ||
365 | dns_w = new DNSWidget( tabWindow ); | ||
366 | tabWindow->addTab( dns_w, i18n("DNS") );//, i18n("DNS Servers")), isnewaccount); | ||
367 | script_w = new ScriptWidget( tabWindow ); | ||
368 | tabWindow->addTab( script_w, i18n("Login Script") ); //, i18n("Edit Login Script")), isnewaccount); | ||
369 | ExecWidget *exec_w = new ExecWidget( tabWindow ); | ||
370 | tabWindow->addTab( exec_w, i18n("Execute") );//, i18n("Execute Programs")), isnewaccount); | ||
371 | // acct = new AccountingSelector( tabWindow, isnewaccount ); | ||
372 | // tabWindow->addTab( acct, i18n("Accounting")); | ||
373 | |||
374 | int result = 0; | ||
375 | bool ok = false; | ||
376 | while (!ok){ | ||
377 | |||
378 | result = dlg->exec(); | ||
379 | ok = true; | ||
380 | |||
381 | if(result == QDialog::Accepted) { | ||
382 | if (script_w->check()) { | ||
383 | if(dial_w->save()) { | ||
384 | ip_w->save(); | ||
385 | dns_w->save(); | ||
386 | gateway_w->save(); | ||
387 | script_w->save(); | ||
388 | exec_w->save(); | ||
389 | // acct->save(); | ||
390 | } else { | ||
391 | QMessageBox::critical(this, "error", i18n( "You must enter a unique\n" | ||
392 | "account name")); | ||
393 | ok = false; | ||
394 | } | ||
395 | } else { | ||
396 | QMessageBox::critical(this, "error", i18n("Login script has unbalanced " | ||
397 | "loop Start/End")); | ||
398 | ok = false; | ||
399 | } | ||
400 | } | ||
401 | } | ||
402 | |||
403 | delete tabWindow; | ||
404 | return result; | ||
405 | } | ||
406 | |||
407 | |||
408 | QString AccountWidget::prettyPrintVolume(unsigned int n) { | ||
409 | int idx = 0; | ||
410 | const QString quant[] = {i18n("Byte"), i18n("KB"), | ||
411 | i18n("MB"), i18n("GB"), QString::null}; | ||
412 | |||
413 | float n1 = n; | ||
414 | while(n >= 1024 && quant[idx] != QString::null) { | ||
415 | idx++; | ||
416 | n /= 1024; | ||
417 | } | ||
418 | |||
419 | int i = idx; | ||
420 | while(i--) | ||
421 | n1 = n1 / 1024.0; | ||
422 | |||
423 | QString s = QString::number( n1, 'f', idx==0 ? 0 : 1 ); | ||
424 | s += " " + quant[idx]; | ||
425 | return s; | ||
426 | } | ||
427 | |||
428 | |||
429 | ///////////////////////////////////////////////////////////////////////////// | ||
430 | // | ||
431 | // Queries the user what to reset: costs, volume or both | ||
432 | // | ||
433 | ///////////////////////////////////////////////////////////////////////////// | ||
434 | QueryReset::QueryReset(QWidget *parent) : QDialog(parent, 0, true) { | ||
435 | // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); | ||
436 | setCaption(i18n("Reset Accounting")); | ||
437 | |||
438 | QVBoxLayout *tl = new QVBoxLayout(this, 10, 10); | ||
439 | QVGroupBox *f = new QVGroupBox(i18n("What to Reset"), this); | ||
440 | |||
441 | QVBoxLayout *l1 = new QVBoxLayout(this, 10, 10); | ||
442 | // costs = new QCheckBox(i18n("Reset the accumulated phone costs"), f); | ||
443 | // costs->setChecked(true); | ||
444 | // l1->addWidget(costs); | ||
445 | // QWhatsThis::add(costs, i18n("Check this to set the phone costs\n" | ||
446 | // "to zero. Typically you'll want to\n" | ||
447 | // "do this once a month.")); | ||
448 | |||
449 | // volume = new QCheckBox(i18n("Reset volume accounting"), f); | ||
450 | // volume->setChecked(true); | ||
451 | // l1->addWidget(volume); | ||
452 | // QWhatsThis::add(volume, i18n("Check this to set the volume accounting\n" | ||
453 | // "to zero. Typically you'll want to do this\n" | ||
454 | // "once a month.")); | ||
455 | |||
456 | l1->activate(); | ||
457 | |||
458 | // this activates the f-layout and sets minimumSize() | ||
459 | f->show(); | ||
460 | |||
461 | tl->addWidget(f); | ||
462 | |||
463 | QButtonGroup *bbox = new QButtonGroup(this); | ||
464 | // bbox->addStretch(1); | ||
465 | QPushButton *ok = new QPushButton( bbox, i18n("OK") ); | ||
466 | bbox->insert(ok); | ||
467 | ok->setDefault(true); | ||
468 | QPushButton *cancel = new QPushButton( bbox, i18n("Cancel") ); | ||
469 | bbox->insert(cancel); | ||
470 | |||
471 | connect(ok, SIGNAL(clicked()), | ||
472 | this, SLOT(accepted())); | ||
473 | connect(cancel, SIGNAL(clicked()), | ||
474 | this, SLOT(reject())); | ||
475 | |||
476 | bbox->layout(); | ||
477 | tl->addWidget(bbox); | ||
478 | |||
479 | // TODO: activate if KGroupBox is fixed | ||
480 | // setFixedSize(sizeHint()); | ||
481 | } | ||
482 | |||
483 | |||
484 | void QueryReset::accepted() { | ||
485 | int result = costs->isChecked() ? COSTS : 0; | ||
486 | result += volume->isChecked() ? VOLUME : 0; | ||
487 | |||
488 | done(result); | ||
489 | } | ||
490 | |||
491 | |||
diff --git a/noncore/settings/networksettings/ppp/accounts.h b/noncore/settings/networksettings/ppp/accounts.h new file mode 100644 index 0000000..751a414 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/accounts.h | |||
@@ -0,0 +1,110 @@ | |||
1 | /* -*- C++ -*- | ||
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 | #ifndef _ACCOUNTS_H_ | ||
28 | #define _ACCOUNTS_H_ | ||
29 | |||
30 | #include <qwidget.h> | ||
31 | #include <qdialog.h> | ||
32 | #include <qpushbutton.h> | ||
33 | #include <qlistbox.h> | ||
34 | //#include "acctselect.h" | ||
35 | |||
36 | class QDialog; | ||
37 | class QCheckBox; | ||
38 | class QLineEdit; | ||
39 | class QTabWidget; | ||
40 | class DialWidget; | ||
41 | class ScriptWidget; | ||
42 | class IPWidget; | ||
43 | class DNSWidget; | ||
44 | class GatewayWidget; | ||
45 | |||
46 | class AccountWidget : public QWidget { | ||
47 | Q_OBJECT | ||
48 | public: | ||
49 | AccountWidget( QWidget *parent=0, const char *name=0 ); | ||
50 | ~AccountWidget() {} | ||
51 | |||
52 | private slots: | ||
53 | void editaccount(); | ||
54 | void copyaccount(); | ||
55 | void newaccount(); | ||
56 | void deleteaccount(); | ||
57 | void slotListBoxSelect(int); | ||
58 | // void resetClicked(); | ||
59 | // void viewLogClicked(); | ||
60 | |||
61 | private: | ||
62 | int doTab(); | ||
63 | |||
64 | signals: | ||
65 | void resetaccounts(); | ||
66 | // void resetCosts(const QString &); | ||
67 | // void resetVolume(const QString &); | ||
68 | |||
69 | private: | ||
70 | QString prettyPrintVolume(unsigned int); | ||
71 | |||
72 | QTabWidget *tabWindow; | ||
73 | DialWidget *dial_w; | ||
74 | // AccountingSelector *acct; | ||
75 | IPWidget *ip_w; | ||
76 | DNSWidget *dns_w; | ||
77 | GatewayWidget *gateway_w; | ||
78 | ScriptWidget *script_w; | ||
79 | |||
80 | // QPushButton *reset; | ||
81 | // QPushButton *log; | ||
82 | // QLabel *costlabel; | ||
83 | // QLineEdit *costedit; | ||
84 | // QLabel *vollabel; | ||
85 | // QLineEdit *voledit; | ||
86 | |||
87 | QListBox *accountlist_l; | ||
88 | QPushButton *edit_b; | ||
89 | QPushButton *copy_b; | ||
90 | QPushButton *new_b; | ||
91 | QPushButton *delete_b; | ||
92 | }; | ||
93 | |||
94 | |||
95 | class QueryReset : public QDialog { | ||
96 | Q_OBJECT | ||
97 | public: | ||
98 | QueryReset(QWidget *parent); | ||
99 | |||
100 | enum {COSTS=1, VOLUME=2}; | ||
101 | |||
102 | private slots: | ||
103 | void accepted(); | ||
104 | |||
105 | private: | ||
106 | QCheckBox *costs, *volume; | ||
107 | }; | ||
108 | |||
109 | #endif | ||
110 | |||
diff --git a/noncore/settings/networksettings/ppp/auth.h b/noncore/settings/networksettings/ppp/auth.h new file mode 100644 index 0000000..d497b10 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/auth.h | |||
@@ -0,0 +1,36 @@ | |||
1 | /* | ||
2 | * | ||
3 | * kPPP: A pppd Front End for the KDE project | ||
4 | * | ||
5 | * $Id$ | ||
6 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
7 | * wuebben@math.cornell.edu | ||
8 | * | ||
9 | * This file was contributed by Mario Weilguni <mweilguni@sime.com> | ||
10 | * Thanks Mario! | ||
11 | * | ||
12 | * This library 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 library 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 | #ifndef __AUTH__H__ | ||
28 | #define __AUTH__H__ | ||
29 | |||
30 | #define AUTH_SCRIPT 0 | ||
31 | #define AUTH_PAP 1 | ||
32 | #define AUTH_TERMINAL 2 | ||
33 | #define AUTH_CHAP 3 | ||
34 | #define AUTH_PAPCHAP 4 | ||
35 | |||
36 | #endif | ||
diff --git a/noncore/settings/networksettings/ppp/connect.cpp b/noncore/settings/networksettings/ppp/connect.cpp new file mode 100644 index 0000000..b7e229e --- a/dev/null +++ b/noncore/settings/networksettings/ppp/connect.cpp | |||
@@ -0,0 +1,1438 @@ | |||
1 | /* | ||
2 | * kPPP: A pppd front end for the KDE project | ||
3 | * | ||
4 | * | ||
5 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
6 | * wuebben@math.cornell.edu | ||
7 | * Copyright (C) 1998-2001 Harri Porten <porten@kde.org> | ||
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 <config.h> | ||
28 | |||
29 | #include <qlayout.h> | ||
30 | #include <qregexp.h> | ||
31 | |||
32 | #include <qapplication.h> | ||
33 | //#include <kdebug.h> | ||
34 | //#include <klocale.h> | ||
35 | #define i18n QObject::tr | ||
36 | #include <qmessagebox.h> | ||
37 | #include <qpushbutton.h> | ||
38 | |||
39 | #include <unistd.h> | ||
40 | #include <stdlib.h> | ||
41 | #include <string.h> | ||
42 | #include <fcntl.h> | ||
43 | #include <netdb.h> | ||
44 | #include <sys/types.h> | ||
45 | #include <sys/socket.h> | ||
46 | #include <arpa/inet.h> | ||
47 | #include <netinet/in.h> | ||
48 | #include <sys/ioctl.h> | ||
49 | #include <assert.h> | ||
50 | |||
51 | #ifdef _XPG4_2 | ||
52 | #define __xnet_connectconnect | ||
53 | #endif | ||
54 | |||
55 | #include <errno.h> | ||
56 | |||
57 | #ifdef HAVE_SYS_PARAM_H | ||
58 | #include <sys/param.h> | ||
59 | #endif | ||
60 | |||
61 | #ifdef __linux__ | ||
62 | #include "runtests.h" | ||
63 | #endif | ||
64 | |||
65 | #include "auth.h" | ||
66 | #include "connect.h" | ||
67 | //#include "docking.h" | ||
68 | //#include "main.h" | ||
69 | #include "modem.h" | ||
70 | #include "kpppconfig.h" | ||
71 | #include "pppdata.h" | ||
72 | #include "kpppwidget.h" | ||
73 | //#include "requester.h" | ||
74 | //#include "utils.h" | ||
75 | #define execute_command system | ||
76 | |||
77 | extern KPPPWidget *p_kppp; | ||
78 | |||
79 | QString old_hostname; | ||
80 | bool modified_hostname; | ||
81 | |||
82 | |||
83 | ConnectWidget::ConnectWidget(QWidget *parent, const char *name) | ||
84 | : QWidget(parent, name), | ||
85 | // initialize some important variables | ||
86 | myreadbuffer(""), | ||
87 | main_timer_ID(0), | ||
88 | vmain(0), | ||
89 | substate(-1), | ||
90 | scriptindex(0), | ||
91 | loopnest(0), | ||
92 | loopend(false), | ||
93 | semaphore(false), | ||
94 | expecting(false), | ||
95 | readbuffer(""), | ||
96 | scanvar(""), | ||
97 | scanning(false), | ||
98 | pausing(false), | ||
99 | // termwindow(0), | ||
100 | // stats(st), | ||
101 | dialnumber(0) | ||
102 | { | ||
103 | modified_hostname = false; | ||
104 | |||
105 | QVBoxLayout *tl = new QVBoxLayout(this, 8, 10); | ||
106 | QString tit = i18n("Connecting to: "); | ||
107 | setCaption(tit); | ||
108 | |||
109 | QHBoxLayout *l0 = new QHBoxLayout(10); | ||
110 | tl->addLayout(l0); | ||
111 | l0->addSpacing(10); | ||
112 | messg = new QLabel(this, "messg"); | ||
113 | messg->setFrameStyle(QFrame::Panel|QFrame::Sunken); | ||
114 | messg->setAlignment(AlignCenter); | ||
115 | messg->setText(i18n("Unable to create modem lock file.")); | ||
116 | messg->setMinimumHeight(messg->sizeHint().height() + 5); | ||
117 | int messw = (messg->sizeHint().width() * 12) / 10; | ||
118 | messw = QMAX(messw,280); | ||
119 | messg->setMinimumWidth(messw); | ||
120 | messg->setText(i18n("Looking for modem...")); | ||
121 | l0->addSpacing(10); | ||
122 | l0->addWidget(messg); | ||
123 | l0->addSpacing(10); | ||
124 | |||
125 | QHBoxLayout *l1 = new QHBoxLayout(10); | ||
126 | tl->addLayout(l1); | ||
127 | l1->addStretch(1); | ||
128 | |||
129 | debug = new QPushButton(i18n("Log"), this); | ||
130 | debug->setToggleButton(true); | ||
131 | connect(debug, SIGNAL(clicked()), SIGNAL(toggleDebugWindow())); | ||
132 | |||
133 | cancel = new QPushButton(i18n("Cancel"), this); | ||
134 | cancel->setFocus(); | ||
135 | connect(cancel, SIGNAL(clicked()), SLOT(cancelbutton())); | ||
136 | |||
137 | int maxw = QMAX(cancel->sizeHint().width(), | ||
138 | debug->sizeHint().width()); | ||
139 | maxw = QMAX(maxw,65); | ||
140 | debug->setFixedWidth(maxw); | ||
141 | cancel->setFixedWidth(maxw); | ||
142 | l1->addWidget(debug); | ||
143 | l1->addWidget(cancel); | ||
144 | |||
145 | setFixedSize(sizeHint()); | ||
146 | |||
147 | pausetimer = new QTimer(this); | ||
148 | connect(pausetimer, SIGNAL(timeout()), SLOT(pause())); | ||
149 | |||
150 | qApp->processEvents(); | ||
151 | |||
152 | timeout_timer = new QTimer(this); | ||
153 | connect(timeout_timer, SIGNAL(timeout()), SLOT(script_timed_out())); | ||
154 | |||
155 | inittimer = new QTimer(this); | ||
156 | connect(inittimer, SIGNAL(timeout()), SLOT(init())); | ||
157 | |||
158 | if_timeout_timer = new QTimer(this); | ||
159 | connect(if_timeout_timer, SIGNAL(timeout()), SLOT(if_waiting_timed_out())); | ||
160 | |||
161 | connect(this,SIGNAL(if_waiting_signal()),this,SLOT(if_waiting_slot())); | ||
162 | |||
163 | prompt = new PWEntry( this, "pw" ); | ||
164 | if_timer = new QTimer(this); | ||
165 | connect(if_timer,SIGNAL(timeout()), SLOT(if_waiting_slot())); | ||
166 | } | ||
167 | |||
168 | |||
169 | ConnectWidget::~ConnectWidget() { | ||
170 | } | ||
171 | |||
172 | |||
173 | void ConnectWidget::preinit() { | ||
174 | // this is all just to keep the GUI nice and snappy .... | ||
175 | // you have to see to believe ... | ||
176 | messg->setText(i18n("Looking for modem...")); | ||
177 | inittimer->start(100); | ||
178 | } | ||
179 | |||
180 | |||
181 | void ConnectWidget::init() { | ||
182 | gpppdata.setpppdError(0); | ||
183 | inittimer->stop(); | ||
184 | vmain = 0; | ||
185 | substate = -1; | ||
186 | expecting = false; | ||
187 | pausing = false; | ||
188 | scriptindex = 0; | ||
189 | myreadbuffer = ""; | ||
190 | scanning = false; | ||
191 | scanvar = ""; | ||
192 | firstrunID = true; | ||
193 | firstrunPW = true; | ||
194 | // stats->totalbytes = 0; | ||
195 | dialnumber = 0; | ||
196 | |||
197 | p_kppp->con_speed = ""; | ||
198 | |||
199 | // p_kppp->setQuitOnDisconnect (p_kppp->quitOnDisconnect() || gpppdata.quit_on_disconnect()); | ||
200 | |||
201 | comlist = &gpppdata.scriptType(); | ||
202 | arglist = &gpppdata.script(); | ||
203 | |||
204 | QString tit = i18n("Connecting to: %1").arg(gpppdata.accname()); | ||
205 | setCaption(tit); | ||
206 | |||
207 | qApp->processEvents(); | ||
208 | |||
209 | // run the "before-connect" command | ||
210 | if (!gpppdata.command_before_connect().isEmpty()) { | ||
211 | messg->setText(i18n("Running pre-startup command...")); | ||
212 | emit debugMessage(i18n("Running pre-startup command...")); | ||
213 | |||
214 | qApp->processEvents(); | ||
215 | QApplication::flushX(); | ||
216 | pid_t id = execute_command(gpppdata.command_before_connect()); | ||
217 | // int i, status; | ||
218 | |||
219 | // do { | ||
220 | // qApp->processEvents(); | ||
221 | // i = waitpid(id, &status, WNOHANG); | ||
222 | // usleep(100000); | ||
223 | // } while (i == 0 && errno == 0); | ||
224 | } | ||
225 | |||
226 | int lock = Modem::modem->lockdevice(); | ||
227 | |||
228 | if (lock == 1) { | ||
229 | messg->setText(i18n("Modem device is locked.")); | ||
230 | vmain = 20; // wait until cancel is pressed | ||
231 | return; | ||
232 | } | ||
233 | |||
234 | if (lock == -1) { | ||
235 | messg->setText(i18n("Unable to create modem lock file.")); | ||
236 | vmain = 20; // wait until cancel is pressed | ||
237 | return; | ||
238 | } | ||
239 | |||
240 | if(Modem::modem->opentty()) { | ||
241 | messg->setText(Modem::modem->modemMessage()); | ||
242 | qApp->processEvents(); | ||
243 | if(Modem::modem->hangup()) { | ||
244 | |||
245 | qApp->processEvents(); | ||
246 | |||
247 | semaphore = false; | ||
248 | |||
249 | Modem::modem->stop(); | ||
250 | Modem::modem->notify(this, SLOT(readChar(unsigned char))); | ||
251 | |||
252 | // if we are stuck anywhere we will time out | ||
253 | timeout_timer->start(gpppdata.modemTimeout()*1000); | ||
254 | |||
255 | // this timer will run the script etc. | ||
256 | main_timer_ID = startTimer(10); | ||
257 | |||
258 | return; | ||
259 | } | ||
260 | } | ||
261 | |||
262 | // initialization failed | ||
263 | messg->setText(Modem::modem->modemMessage()); | ||
264 | vmain = 20; // wait until cancel is pressed | ||
265 | Modem::modem->unlockdevice(); | ||
266 | } | ||
267 | |||
268 | |||
269 | void ConnectWidget::timerEvent(QTimerEvent *) { | ||
270 | if (semaphore || pausing) | ||
271 | return; | ||
272 | |||
273 | if(vmain == 0) { | ||
274 | #ifdef DEBUG_WO_DIALING | ||
275 | vmain = 10; | ||
276 | return; | ||
277 | #endif | ||
278 | |||
279 | assert(PPPData::NumInitStrings > 0); | ||
280 | // first init string ? | ||
281 | if(substate == -1) { | ||
282 | messg->setText(i18n("Initializing modem...")); | ||
283 | emit debugMessage(i18n("Initializing modem...")); | ||
284 | substate = 0; | ||
285 | } | ||
286 | |||
287 | QString initStr = gpppdata.modemInitStr(substate); | ||
288 | if (!initStr.isEmpty()) { | ||
289 | // send a carriage return and then wait a bit so that the modem will | ||
290 | // let us issue commands. | ||
291 | if(gpppdata.modemPreInitDelay() > 0) { | ||
292 | usleep(gpppdata.modemPreInitDelay() * 5000); | ||
293 | writeline(""); | ||
294 | usleep(gpppdata.modemPreInitDelay() * 5000); | ||
295 | } | ||
296 | setExpect(gpppdata.modemInitResp()); | ||
297 | writeline(initStr); | ||
298 | usleep(gpppdata.modemInitDelay() * 10000); // 0.01 - 3.0 sec | ||
299 | } | ||
300 | |||
301 | substate++; | ||
302 | |||
303 | /* | ||
304 | * FIXME after 3.0: Make it possible to disable ATS11 since it | ||
305 | * seems to be incompatible with some ISDN adapters (e.g. DataBox | ||
306 | * Speed Dragon). Even better would be to detect this when doing | ||
307 | * a "Modem Query" | ||
308 | */ | ||
309 | if (MODEM_TONEDURATION != gpppdata.modemToneDuration()) | ||
310 | vmain = 5; | ||
311 | else | ||
312 | vmain = 3; | ||
313 | |||
314 | return; | ||
315 | } | ||
316 | |||
317 | if (vmain == 5) { | ||
318 | if(!expecting) { | ||
319 | QString sToneDuration = "ATS11=" + QString::number(gpppdata.modemToneDuration()); | ||
320 | QString msg = i18n("Setting ") + sToneDuration; | ||
321 | messg->setText(msg); | ||
322 | emit debugMessage(msg); | ||
323 | setExpect(gpppdata.modemInitResp()); | ||
324 | writeline(sToneDuration); | ||
325 | } | ||
326 | vmain = 3; | ||
327 | return; | ||
328 | } | ||
329 | |||
330 | if(vmain == 3) { | ||
331 | if(!expecting) { | ||
332 | // done with all init strings ? | ||
333 | if(substate < PPPData::NumInitStrings) { | ||
334 | vmain = 0; | ||
335 | return; | ||
336 | } | ||
337 | substate = -1; | ||
338 | // skip setting the volume if command is empty | ||
339 | if(gpppdata.volumeInitString().isEmpty()) { | ||
340 | vmain = 4; | ||
341 | return; | ||
342 | } | ||
343 | messg->setText(i18n("Setting speaker volume...")); | ||
344 | emit debugMessage(i18n("Setting speaker volume...")); | ||
345 | |||
346 | setExpect(gpppdata.modemInitResp()); | ||
347 | QString vol("AT"); | ||
348 | vol += gpppdata.volumeInitString(); | ||
349 | writeline(vol); | ||
350 | usleep(gpppdata.modemInitDelay() * 10000); // 0.01 - 3.0 sec | ||
351 | vmain = 4; | ||
352 | return; | ||
353 | } | ||
354 | } | ||
355 | |||
356 | if(vmain == 4) { | ||
357 | if(!expecting) { | ||
358 | if(!gpppdata.waitForDialTone()) { | ||
359 | QString msg = i18n("Turning off dial tone waiting..."); | ||
360 | messg->setText(msg); | ||
361 | emit debugMessage(msg); | ||
362 | setExpect(gpppdata.modemInitResp()); | ||
363 | writeline(gpppdata.modemNoDialToneDetectionStr()); | ||
364 | } | ||
365 | vmain = 1; | ||
366 | return; | ||
367 | } | ||
368 | } | ||
369 | |||
370 | // dial the number and wait to connect | ||
371 | if(vmain == 1) { | ||
372 | if(!expecting) { | ||
373 | |||
374 | timeout_timer->stop(); | ||
375 | timeout_timer->start(gpppdata.modemTimeout()*1000); | ||
376 | |||
377 | QStringList &plist = gpppdata.phonenumbers(); | ||
378 | QString bmarg= gpppdata.dialPrefix(); | ||
379 | bmarg += *plist.at(dialnumber); | ||
380 | QString bm = i18n("Dialing %1").arg(bmarg); | ||
381 | messg->setText(bm); | ||
382 | emit debugMessage(bm); | ||
383 | |||
384 | QString pn = gpppdata.modemDialStr(); | ||
385 | pn += gpppdata.dialPrefix(); | ||
386 | pn += *plist.at(dialnumber); | ||
387 | if(++dialnumber >= plist.count()) | ||
388 | dialnumber = 0; | ||
389 | writeline(pn); | ||
390 | |||
391 | setExpect(gpppdata.modemConnectResp()); | ||
392 | vmain = 100; | ||
393 | return; | ||
394 | } | ||
395 | } | ||
396 | |||
397 | // wait for connect, but redial if BUSY or wait for user cancel | ||
398 | // if NO CARRIER or NO DIALTONE | ||
399 | if(vmain == 100) { | ||
400 | if(!expecting) { | ||
401 | myreadbuffer = gpppdata.modemConnectResp(); | ||
402 | setExpect("\n"); | ||
403 | vmain = 101; | ||
404 | return; | ||
405 | } | ||
406 | |||
407 | if(readbuffer.contains(gpppdata.modemBusyResp())) { | ||
408 | timeout_timer->stop(); | ||
409 | timeout_timer->start(gpppdata.modemTimeout()*1000); | ||
410 | |||
411 | messg->setText(i18n("Line busy. Hanging up...")); | ||
412 | emit debugPutChar('\n'); | ||
413 | Modem::modem->hangup(); | ||
414 | |||
415 | if(gpppdata.busyWait() > 0) { | ||
416 | QString bm = i18n("Line busy. Waiting: %1 seconds").arg(gpppdata.busyWait()); | ||
417 | messg->setText(bm); | ||
418 | emit debugMessage(bm); | ||
419 | |||
420 | pausing = true; | ||
421 | |||
422 | pausetimer->start(gpppdata.busyWait()*1000, true); | ||
423 | timeout_timer->stop(); | ||
424 | } | ||
425 | |||
426 | Modem::modem->setDataMode(false); | ||
427 | vmain = 0; | ||
428 | substate = -1; | ||
429 | return; | ||
430 | } | ||
431 | |||
432 | if(readbuffer.contains(gpppdata.modemNoDialtoneResp())) { | ||
433 | timeout_timer->stop(); | ||
434 | |||
435 | messg->setText(i18n("No Dialtone")); | ||
436 | vmain = 20; | ||
437 | Modem::modem->unlockdevice(); | ||
438 | return; | ||
439 | } | ||
440 | |||
441 | if(readbuffer.contains(gpppdata.modemNoCarrierResp())) { | ||
442 | timeout_timer->stop(); | ||
443 | |||
444 | messg->setText(i18n("No Carrier")); | ||
445 | vmain = 20; | ||
446 | Modem::modem->unlockdevice(); | ||
447 | return; | ||
448 | } | ||
449 | } | ||
450 | |||
451 | // wait for newline after CONNECT response (so we get the speed) | ||
452 | if(vmain == 101) { | ||
453 | if(!expecting) { | ||
454 | Modem::modem->setDataMode(true); // modem will no longer respond to AT commands | ||
455 | |||
456 | emit startAccounting(); | ||
457 | // p_kppp->con_win->startClock(); | ||
458 | |||
459 | vmain = 2; | ||
460 | scriptTimeout=gpppdata.modemTimeout()*1000; | ||
461 | return; | ||
462 | } | ||
463 | } | ||
464 | |||
465 | // execute the script | ||
466 | if(vmain == 2) { | ||
467 | if(!expecting && !pausing && !scanning) { | ||
468 | |||
469 | timeout_timer->stop(); | ||
470 | timeout_timer->start(scriptTimeout); | ||
471 | |||
472 | if((unsigned) scriptindex < comlist->count()) { | ||
473 | scriptCommand = *(comlist->at(scriptindex)); | ||
474 | scriptArgument = *(arglist->at(scriptindex)); | ||
475 | } else { | ||
476 | qDebug( "End of script" ); | ||
477 | vmain = 10; | ||
478 | return; | ||
479 | } | ||
480 | |||
481 | if (scriptCommand == "Scan") { | ||
482 | QString bm = i18n("Scanning %1").arg(scriptArgument); | ||
483 | messg->setText(bm); | ||
484 | emit debugMessage(bm); | ||
485 | |||
486 | setScan(scriptArgument); | ||
487 | scriptindex++; | ||
488 | return; | ||
489 | } | ||
490 | |||
491 | if (scriptCommand == "Save") { | ||
492 | QString bm = i18n("Saving %1").arg(scriptArgument); | ||
493 | messg->setText(bm); | ||
494 | emit debugMessage(bm); | ||
495 | |||
496 | if (scriptArgument.lower() == "password") { | ||
497 | gpppdata.setPassword(scanvar); | ||
498 | p_kppp->setPW_Edit(scanvar); | ||
499 | if(gpppdata.storePassword()) | ||
500 | gpppdata.setStoredPassword(scanvar); | ||
501 | firstrunPW = true; | ||
502 | } | ||
503 | |||
504 | scriptindex++; | ||
505 | return; | ||
506 | } | ||
507 | |||
508 | |||
509 | if (scriptCommand == "Send" || scriptCommand == "SendNoEcho") { | ||
510 | QString bm = i18n("Sending %1"); | ||
511 | |||
512 | // replace %USERNAME% and %PASSWORD% | ||
513 | QString arg = scriptArgument; | ||
514 | QRegExp re1("%USERNAME%"); | ||
515 | QRegExp re2("%PASSWORD%"); | ||
516 | arg = arg.replace(re1, gpppdata.storedUsername()); | ||
517 | arg = arg.replace(re2, gpppdata.storedPassword()); | ||
518 | |||
519 | if (scriptCommand == "Send") | ||
520 | bm = bm.arg(scriptArgument); | ||
521 | else { | ||
522 | for(uint i = 0; i < scriptArgument.length(); i++) | ||
523 | bm = bm.arg("*"); | ||
524 | } | ||
525 | |||
526 | messg->setText(bm); | ||
527 | emit debugMessage(bm); | ||
528 | |||
529 | writeline(scriptArgument); | ||
530 | scriptindex++; | ||
531 | return; | ||
532 | } | ||
533 | |||
534 | if (scriptCommand == "Expect") { | ||
535 | QString bm = i18n("Expecting %1").arg(scriptArgument); | ||
536 | messg->setText(bm); | ||
537 | emit debugMessage(bm); | ||
538 | |||
539 | // The incrementing of the scriptindex MUST be before the | ||
540 | // call to setExpect otherwise the expect will miss a string that is | ||
541 | // already in the buffer. | ||
542 | scriptindex++; | ||
543 | setExpect(scriptArgument); | ||
544 | return; | ||
545 | } | ||
546 | |||
547 | |||
548 | if (scriptCommand == "Pause") { | ||
549 | QString bm = i18n("Pause %1 seconds").arg(scriptArgument); | ||
550 | messg->setText(bm); | ||
551 | emit debugMessage(bm); | ||
552 | |||
553 | pausing = true; | ||
554 | |||
555 | pausetimer->start(scriptArgument.toInt()*1000, true); | ||
556 | timeout_timer->stop(); | ||
557 | |||
558 | scriptindex++; | ||
559 | return; | ||
560 | } | ||
561 | |||
562 | if (scriptCommand == "Timeout") { | ||
563 | |||
564 | timeout_timer->stop(); | ||
565 | |||
566 | QString bm = i18n("Timeout %1 seconds").arg(scriptArgument); | ||
567 | messg->setText(bm); | ||
568 | emit debugMessage(bm); | ||
569 | |||
570 | scriptTimeout=scriptArgument.toInt()*1000; | ||
571 | timeout_timer->start(scriptTimeout); | ||
572 | |||
573 | scriptindex++; | ||
574 | return; | ||
575 | } | ||
576 | |||
577 | if (scriptCommand == "Hangup") { | ||
578 | messg->setText(i18n("Hangup")); | ||
579 | emit debugMessage(i18n("Hangup")); | ||
580 | |||
581 | writeline(gpppdata.modemHangupStr()); | ||
582 | setExpect(gpppdata.modemHangupResp()); | ||
583 | |||
584 | scriptindex++; | ||
585 | return; | ||
586 | } | ||
587 | |||
588 | if (scriptCommand == "Answer") { | ||
589 | |||
590 | timeout_timer->stop(); | ||
591 | |||
592 | messg->setText(i18n("Answer")); | ||
593 | emit debugMessage(i18n("Answer")); | ||
594 | |||
595 | setExpect(gpppdata.modemRingResp()); | ||
596 | vmain = 150; | ||
597 | return; | ||
598 | } | ||
599 | |||
600 | if (scriptCommand == "ID") { | ||
601 | QString bm = i18n("ID %1").arg(scriptArgument); | ||
602 | messg->setText(bm); | ||
603 | emit debugMessage(bm); | ||
604 | |||
605 | QString idstring = gpppdata.storedUsername(); | ||
606 | |||
607 | if(!idstring.isEmpty() && firstrunID) { | ||
608 | // the user entered an Id on the main kppp dialog | ||
609 | writeline(idstring); | ||
610 | firstrunID = false; | ||
611 | scriptindex++; | ||
612 | } | ||
613 | else { | ||
614 | // the user didn't enter and Id on the main kppp dialog | ||
615 | // let's query for an ID | ||
616 | /* if not around yet, then post window... */ | ||
617 | if (prompt->Consumed()) { | ||
618 | if (!(prompt->isVisible())) { | ||
619 | prompt->setPrompt(scriptArgument); | ||
620 | prompt->setEchoModeNormal(); | ||
621 | prompt->show(); | ||
622 | } | ||
623 | } else { | ||
624 | /* if prompt withdrawn ... then, */ | ||
625 | if(!(prompt->isVisible())) { | ||
626 | writeline(prompt->text()); | ||
627 | prompt->setConsumed(); | ||
628 | scriptindex++; | ||
629 | return; | ||
630 | } | ||
631 | /* replace timeout value */ | ||
632 | } | ||
633 | } | ||
634 | } | ||
635 | |||
636 | if (scriptCommand == "Password") { | ||
637 | QString bm = i18n("Password %1").arg(scriptArgument); | ||
638 | messg->setText(bm); | ||
639 | emit debugMessage(bm); | ||
640 | |||
641 | QString pwstring = gpppdata.password(); | ||
642 | |||
643 | if(!pwstring.isEmpty() && firstrunPW) { | ||
644 | // the user entered a password on the main kppp dialog | ||
645 | writeline(pwstring); | ||
646 | firstrunPW = false; | ||
647 | scriptindex++; | ||
648 | } | ||
649 | else { | ||
650 | // the user didn't enter a password on the main kppp dialog | ||
651 | // let's query for a password | ||
652 | /* if not around yet, then post window... */ | ||
653 | if (prompt->Consumed()) { | ||
654 | if (!(prompt->isVisible())) { | ||
655 | prompt->setPrompt(scriptArgument); | ||
656 | prompt->setEchoModePassword(); | ||
657 | prompt->show(); | ||
658 | } | ||
659 | } else { | ||
660 | /* if prompt withdrawn ... then, */ | ||
661 | if(!(prompt->isVisible())) { | ||
662 | p_kppp->setPW_Edit(prompt->text()); | ||
663 | writeline(prompt->text()); | ||
664 | prompt->setConsumed(); | ||
665 | scriptindex++; | ||
666 | return; | ||
667 | } | ||
668 | /* replace timeout value */ | ||
669 | } | ||
670 | } | ||
671 | } | ||
672 | |||
673 | if (scriptCommand == "Prompt") { | ||
674 | QString bm = i18n("Prompting %1"); | ||
675 | |||
676 | // if the scriptindex (aka the prompt text) includes a ## marker | ||
677 | // this marker should get substituted with the contents of our stored | ||
678 | // variable (from the subsequent scan). | ||
679 | |||
680 | QString ts = scriptArgument; | ||
681 | int vstart = ts.find( "##" ); | ||
682 | if( vstart != -1 ) { | ||
683 | ts.remove( vstart, 2 ); | ||
684 | ts.insert( vstart, scanvar ); | ||
685 | } | ||
686 | |||
687 | bm = bm.arg(ts); | ||
688 | messg->setText(bm); | ||
689 | emit debugMessage(bm); | ||
690 | |||
691 | /* if not around yet, then post window... */ | ||
692 | if (prompt->Consumed()) { | ||
693 | if (!(prompt->isVisible())) { | ||
694 | prompt->setPrompt( ts ); | ||
695 | prompt->setEchoModeNormal(); | ||
696 | prompt->show(); | ||
697 | } | ||
698 | } else { | ||
699 | /* if prompt withdrawn ... then, */ | ||
700 | if (!(prompt->isVisible())) { | ||
701 | writeline(prompt->text()); | ||
702 | prompt->setConsumed(); | ||
703 | scriptindex++; | ||
704 | return; | ||
705 | } | ||
706 | /* replace timeout value */ | ||
707 | } | ||
708 | } | ||
709 | |||
710 | if (scriptCommand == "PWPrompt") { | ||
711 | QString bm = i18n("PW Prompt %1").arg(scriptArgument); | ||
712 | messg->setText(bm); | ||
713 | emit debugMessage(bm); | ||
714 | |||
715 | /* if not around yet, then post window... */ | ||
716 | if (prompt->Consumed()) { | ||
717 | if (!(prompt->isVisible())) { | ||
718 | prompt->setPrompt(scriptArgument); | ||
719 | prompt->setEchoModePassword(); | ||
720 | prompt->show(); | ||
721 | } | ||
722 | } else { | ||
723 | /* if prompt withdrawn ... then, */ | ||
724 | if (!(prompt->isVisible())) { | ||
725 | writeline(prompt->text()); | ||
726 | prompt->setConsumed(); | ||
727 | scriptindex++; | ||
728 | return; | ||
729 | } | ||
730 | /* replace timeout value */ | ||
731 | } | ||
732 | } | ||
733 | |||
734 | if (scriptCommand == "LoopStart") { | ||
735 | |||
736 | QString bm = i18n("Loop Start %1").arg(scriptArgument); | ||
737 | |||
738 | // The incrementing of the scriptindex MUST be before the | ||
739 | // call to setExpect otherwise the expect will miss a string that is | ||
740 | // already in the buffer. | ||
741 | scriptindex++; | ||
742 | |||
743 | if ( loopnest > (MAXLOOPNEST-2) ) { | ||
744 | bm += i18n("ERROR: Nested too deep, ignored."); | ||
745 | vmain=20; | ||
746 | cancelbutton(); | ||
747 | QMessageBox::critical(0, "error", i18n("Loops nested too deeply!")); | ||
748 | } else { | ||
749 | setExpect(scriptArgument); | ||
750 | loopstartindex[loopnest] = scriptindex; | ||
751 | loopstr[loopnest] = scriptArgument; | ||
752 | loopend = false; | ||
753 | loopnest++; | ||
754 | } | ||
755 | messg->setText(bm); | ||
756 | emit debugMessage(bm); | ||
757 | |||
758 | } | ||
759 | |||
760 | if (scriptCommand == "LoopEnd") { | ||
761 | QString bm = i18n("Loop End %1").arg(scriptArgument); | ||
762 | if ( loopnest <= 0 ) { | ||
763 | bm = i18n("LoopEnd without matching Start! Line: %1").arg(bm); | ||
764 | vmain=20; | ||
765 | cancelbutton(); | ||
766 | QMessageBox::critical(0, "error", bm); | ||
767 | return; | ||
768 | } else { | ||
769 | // NB! The incrementing of the scriptindex MUST be before the | ||
770 | // call to setExpect otherwise the expect will miss a string | ||
771 | // that is already in the buffer. | ||
772 | scriptindex++; | ||
773 | setExpect(scriptArgument); | ||
774 | loopnest--; | ||
775 | loopend = true; | ||
776 | } | ||
777 | messg->setText(bm); | ||
778 | emit debugMessage(bm); | ||
779 | |||
780 | } | ||
781 | } | ||
782 | } | ||
783 | |||
784 | // this is a subroutine for the "Answer" script option | ||
785 | |||
786 | if(vmain == 150) { | ||
787 | if(!expecting) { | ||
788 | writeline(gpppdata.modemAnswerStr()); | ||
789 | setExpect(gpppdata.modemAnswerResp()); | ||
790 | |||
791 | vmain = 2; | ||
792 | scriptindex++; | ||
793 | return; | ||
794 | } | ||
795 | } | ||
796 | |||
797 | if(vmain == 30) { | ||
798 | // if (termwindow->isVisible()) | ||
799 | // return; | ||
800 | // if (termwindow->pressedContinue()) | ||
801 | // vmain = 10; | ||
802 | // else | ||
803 | cancelbutton(); | ||
804 | } | ||
805 | |||
806 | if(vmain == 10) { | ||
807 | if(!expecting) { | ||
808 | |||
809 | int result; | ||
810 | |||
811 | timeout_timer->stop(); | ||
812 | if_timeout_timer->stop(); // better be sure. | ||
813 | |||
814 | // stop reading of data | ||
815 | Modem::modem->stop(); | ||
816 | |||
817 | if(gpppdata.authMethod() == AUTH_TERMINAL) { | ||
818 | // if (termwindow) { | ||
819 | // delete termwindow; | ||
820 | // termwindow = 0L; | ||
821 | // this->show(); | ||
822 | // } else { | ||
823 | // termwindow = new LoginTerm(0L, 0L); | ||
824 | // hide(); | ||
825 | // termwindow->show(); | ||
826 | // vmain = 30; | ||
827 | // return; | ||
828 | // } | ||
829 | } | ||
830 | |||
831 | // Close the tty. This prevents the QTimer::singleShot() in | ||
832 | // Modem::readtty() from re-enabling the socket notifier. | ||
833 | // The port is still held open by the helper process. | ||
834 | Modem::modem->closetty(); | ||
835 | |||
836 | killTimer( main_timer_ID ); | ||
837 | |||
838 | if_timeout_timer->start(gpppdata.pppdTimeout()*1000); | ||
839 | qDebug( "started if timeout timer with %i", gpppdata.pppdTimeout()*1000); | ||
840 | |||
841 | // find out PPP interface and notify the stats module | ||
842 | // stats->setUnit(pppInterfaceNumber()); | ||
843 | |||
844 | qApp->flushX(); | ||
845 | semaphore = true; | ||
846 | result = execppp(); | ||
847 | |||
848 | emit debugMessage(i18n("Starting pppd...")); | ||
849 | qDebug("execppp() returned with return-code %i", result ); | ||
850 | |||
851 | if(result) { | ||
852 | if(!gpppdata.autoDNS()) | ||
853 | adddns(); | ||
854 | |||
855 | // O.K we are done here, let's change over to the if_waiting loop | ||
856 | // where we wait for the ppp if (interface) to come up. | ||
857 | |||
858 | emit if_waiting_signal(); | ||
859 | } else { | ||
860 | |||
861 | // starting pppd wasn't successful. Error messages were | ||
862 | // handled by execppp(); | ||
863 | if_timeout_timer->stop(); | ||
864 | this->hide(); | ||
865 | messg->setText(""); | ||
866 | p_kppp->quit_b->setFocus(); | ||
867 | p_kppp->show(); | ||
868 | qApp->processEvents(); | ||
869 | Modem::modem->hangup(); | ||
870 | emit stopAccounting(); | ||
871 | //p_kppp->con_win->stopClock(); | ||
872 | Modem::modem->closetty(); | ||
873 | Modem::modem->unlockdevice(); | ||
874 | |||
875 | } | ||
876 | |||
877 | return; | ||
878 | } | ||
879 | } | ||
880 | |||
881 | // this is a "wait until cancel" entry | ||
882 | |||
883 | if(vmain == 20) { | ||
884 | } | ||
885 | } | ||
886 | |||
887 | |||
888 | void ConnectWidget::set_con_speed_string() { | ||
889 | // Here we are trying to determine the speed at which we are connected. | ||
890 | // Usually the modem responds after connect with something like | ||
891 | // CONNECT 115200, so all we need to do is find the number after CONNECT | ||
892 | // or whatever the modemConnectResp() is. | ||
893 | p_kppp->con_speed = Modem::modem->parseModemSpeed(myreadbuffer); | ||
894 | } | ||
895 | |||
896 | |||
897 | |||
898 | void ConnectWidget::readChar(unsigned char c) { | ||
899 | if(semaphore) | ||
900 | return; | ||
901 | |||
902 | readbuffer += c; | ||
903 | myreadbuffer += c; | ||
904 | |||
905 | // While in scanning mode store each char to the scan buffer | ||
906 | // for use in the prompt command | ||
907 | if( scanning ) | ||
908 | scanbuffer += c; | ||
909 | |||
910 | // add to debug window | ||
911 | emit debugPutChar(c); | ||
912 | |||
913 | checkBuffers(); | ||
914 | } | ||
915 | |||
916 | |||
917 | void ConnectWidget::checkBuffers() { | ||
918 | // Let's check if we are finished with scanning: | ||
919 | // The scanstring have to be in the buffer and the latest character | ||
920 | // was a carriage return or an linefeed (depending on modem setup) | ||
921 | if( scanning && scanbuffer.contains(scanstr) && | ||
922 | ( scanbuffer.right(1) == "\n" || scanbuffer.right(1) == "\r") ) { | ||
923 | scanning = false; | ||
924 | |||
925 | int vstart = scanbuffer.find( scanstr ) + scanstr.length(); | ||
926 | scanvar = scanbuffer.mid( vstart, scanbuffer.length() - vstart); | ||
927 | scanvar = scanvar.stripWhiteSpace(); | ||
928 | |||
929 | // Show the Variabel content in the debug window | ||
930 | QString sv = i18n("Scan Var: %1").arg(scanvar); | ||
931 | emit debugMessage(sv); | ||
932 | } | ||
933 | |||
934 | if(expecting) { | ||
935 | if(readbuffer.contains(expectstr)) { | ||
936 | expecting = false; | ||
937 | // keep everything after the expected string | ||
938 | readbuffer.remove(0, readbuffer.find(expectstr) + expectstr.length()); | ||
939 | |||
940 | QString ts = i18n("Found: %1").arg(expectstr); | ||
941 | emit debugMessage(ts); | ||
942 | |||
943 | if (loopend) { | ||
944 | loopend=false; | ||
945 | } | ||
946 | } | ||
947 | |||
948 | if (loopend && readbuffer.contains(loopstr[loopnest])) { | ||
949 | expecting = false; | ||
950 | readbuffer = ""; | ||
951 | QString ts = i18n("Looping: %1").arg(loopstr[loopnest]); | ||
952 | emit debugMessage(ts); | ||
953 | scriptindex = loopstartindex[loopnest]; | ||
954 | loopend = false; | ||
955 | loopnest++; | ||
956 | } | ||
957 | // notify event loop if expected string was found | ||
958 | if(!expecting) | ||
959 | timerEvent((QTimerEvent *) 0); | ||
960 | } | ||
961 | } | ||
962 | |||
963 | |||
964 | |||
965 | void ConnectWidget::pause() { | ||
966 | pausing = false; | ||
967 | pausetimer->stop(); | ||
968 | } | ||
969 | |||
970 | |||
971 | void ConnectWidget::cancelbutton() { | ||
972 | Modem::modem->stop(); | ||
973 | killTimer(main_timer_ID); | ||
974 | timeout_timer->stop(); | ||
975 | if_timer->stop(); | ||
976 | if_timeout_timer->stop(); | ||
977 | |||
978 | // if (termwindow) { | ||
979 | // delete termwindow; | ||
980 | // termwindow = 0L; | ||
981 | // this->show(); | ||
982 | // } | ||
983 | |||
984 | messg->setText(i18n("One moment please...")); | ||
985 | |||
986 | // just to be sure | ||
987 | Modem::modem->removeSecret(AUTH_PAP); | ||
988 | Modem::modem->removeSecret(AUTH_CHAP); | ||
989 | removedns(); | ||
990 | |||
991 | qApp->processEvents(); | ||
992 | |||
993 | Modem::modem->killPPPDaemon(); | ||
994 | Modem::modem->hangup(); | ||
995 | |||
996 | this->hide(); | ||
997 | messg->setText(""); | ||
998 | p_kppp->quit_b->setFocus(); | ||
999 | p_kppp->show(); | ||
1000 | emit stopAccounting();// just to be sure | ||
1001 | // p_kppp->con_win->stopClock(); | ||
1002 | Modem::modem->closetty(); | ||
1003 | Modem::modem->unlockdevice(); | ||
1004 | |||
1005 | //abort prompt window... | ||
1006 | if (prompt->isVisible()) { | ||
1007 | prompt->hide(); | ||
1008 | } | ||
1009 | prompt->setConsumed(); | ||
1010 | |||
1011 | // if(p_kppp->quitOnDisconnect()) | ||
1012 | // qApp->exit(0); | ||
1013 | } | ||
1014 | |||
1015 | |||
1016 | void ConnectWidget::script_timed_out() { | ||
1017 | if(vmain == 20) { // we are in the 'wait for the user to cancel' state | ||
1018 | timeout_timer->stop(); | ||
1019 | emit stopAccounting(); | ||
1020 | // p_kppp->con_win->stopClock(); | ||
1021 | return; | ||
1022 | } | ||
1023 | |||
1024 | if (prompt->isVisible()) | ||
1025 | prompt->hide(); | ||
1026 | |||
1027 | prompt->setConsumed(); | ||
1028 | messg->setText(i18n("Script timed out!")); | ||
1029 | Modem::modem->hangup(); | ||
1030 | emit stopAccounting(); | ||
1031 | // p_kppp->con_win->stopClock(); | ||
1032 | |||
1033 | vmain = 0; // let's try again. | ||
1034 | substate = -1; | ||
1035 | } | ||
1036 | |||
1037 | |||
1038 | void ConnectWidget::setScan(const QString &n) { | ||
1039 | scanning = true; | ||
1040 | scanstr = n; | ||
1041 | scanbuffer = ""; | ||
1042 | |||
1043 | QString ts = i18n("Scanning: %1").arg(n); | ||
1044 | emit debugMessage(ts); | ||
1045 | } | ||
1046 | |||
1047 | |||
1048 | void ConnectWidget::setExpect(const QString &n) { | ||
1049 | expecting = true; | ||
1050 | expectstr = n; | ||
1051 | |||
1052 | QString ts = i18n("Expecting: %1").arg(n); | ||
1053 | ts.replace(QRegExp("\n"), "<LF>"); | ||
1054 | emit debugMessage(ts); | ||
1055 | |||
1056 | // check if the expected string is in the read buffer already. | ||
1057 | checkBuffers(); | ||
1058 | } | ||
1059 | |||
1060 | |||
1061 | void ConnectWidget::if_waiting_timed_out() { | ||
1062 | if_timer->stop(); | ||
1063 | if_timeout_timer->stop(); | ||
1064 | qDebug("if_waiting_timed_out()"); | ||
1065 | |||
1066 | gpppdata.setpppdError(E_IF_TIMEOUT); | ||
1067 | |||
1068 | // let's kill the stuck pppd | ||
1069 | Modem::modem->killPPPDaemon(); | ||
1070 | |||
1071 | emit stopAccounting(); | ||
1072 | // p_kppp->con_win->stopClock(); | ||
1073 | |||
1074 | |||
1075 | // killing ppp will generate a SIGCHLD which will be caught in pppdie() | ||
1076 | // in main.cpp what happens next will depend on the boolean | ||
1077 | // reconnect_on_disconnect which is set in ConnectWidget::init(); | ||
1078 | } | ||
1079 | |||
1080 | void ConnectWidget::pppdDied() | ||
1081 | { | ||
1082 | if_timer->stop(); | ||
1083 | if_timeout_timer->stop(); | ||
1084 | } | ||
1085 | |||
1086 | void ConnectWidget::if_waiting_slot() { | ||
1087 | messg->setText(i18n("Logging on to network...")); | ||
1088 | |||
1089 | // if(!stats->ifIsUp()) { | ||
1090 | |||
1091 | // if(gpppdata.pppdError() != 0) { | ||
1092 | // // we are here if pppd died immediately after starting it. | ||
1093 | // pppdDied(); | ||
1094 | // // error message handled in main.cpp: sigPPPDDied() | ||
1095 | // return; | ||
1096 | // } | ||
1097 | |||
1098 | // if_timer->start(100, TRUE); // single shot | ||
1099 | // return; | ||
1100 | // } | ||
1101 | |||
1102 | // O.K the ppp interface is up and running | ||
1103 | // give it a few time to come up completly (0.2 seconds) | ||
1104 | if_timeout_timer->stop(); | ||
1105 | if_timer->stop(); | ||
1106 | usleep(200000); | ||
1107 | |||
1108 | if(gpppdata.autoDNS()) | ||
1109 | addpeerdns(); | ||
1110 | |||
1111 | // Close the debugging window. If we are connected, we | ||
1112 | // are not really interested in debug output | ||
1113 | emit closeDebugWindow(); | ||
1114 | // p_kppp->statdlg->take_stats(); // start taking ppp statistics | ||
1115 | auto_hostname(); | ||
1116 | |||
1117 | if(!gpppdata.command_on_connect().isEmpty()) { | ||
1118 | messg->setText(i18n("Running startup command...")); | ||
1119 | |||
1120 | // make sure that we don't get any async errors | ||
1121 | qApp->flushX(); | ||
1122 | execute_command(gpppdata.command_on_connect()); | ||
1123 | messg->setText(i18n("Done")); | ||
1124 | } | ||
1125 | |||
1126 | // remove the authentication file | ||
1127 | Modem::modem->removeSecret(AUTH_PAP); | ||
1128 | Modem::modem->removeSecret(AUTH_CHAP); | ||
1129 | |||
1130 | emit debugMessage(i18n("Done")); | ||
1131 | set_con_speed_string(); | ||
1132 | |||
1133 | // p_kppp->con_win->setConnectionSpeed(p_kppp->con_speed); | ||
1134 | this->hide(); | ||
1135 | messg->setText(""); | ||
1136 | |||
1137 | // prepare the con_win so as to have the right size for | ||
1138 | // accounting / non-accounting mode | ||
1139 | // if(p_kppp->acct != 0) | ||
1140 | // p_kppp->con_win->accounting(p_kppp->acct->running()); | ||
1141 | // else | ||
1142 | // p_kppp->con_win->accounting(false); | ||
1143 | |||
1144 | if (gpppdata.get_dock_into_panel()) { | ||
1145 | // DockWidget::dock_widget->show(); | ||
1146 | // DockWidget::dock_widget->take_stats(); | ||
1147 | // this->hide(); | ||
1148 | } | ||
1149 | else { | ||
1150 | // p_kppp->con_win->show(); | ||
1151 | |||
1152 | if(gpppdata.get_iconify_on_connect()) { | ||
1153 | // p_kppp->con_win->showMinimized(); | ||
1154 | } | ||
1155 | } | ||
1156 | |||
1157 | Modem::modem->closetty(); | ||
1158 | } | ||
1159 | |||
1160 | |||
1161 | bool ConnectWidget::execppp() { | ||
1162 | QString command; | ||
1163 | |||
1164 | command = "pppd"; | ||
1165 | |||
1166 | // as of version 2.3.6 pppd falls back to the real user rights when | ||
1167 | // opening a device given in a command line. To avoid permission conflicts | ||
1168 | // we'll simply leave this argument away. pppd will then use the default tty | ||
1169 | // which is the serial port we connected stdin/stdout to in opener.cpp. | ||
1170 | // command += " "; | ||
1171 | // command += gpppdata.modemDevice(); | ||
1172 | |||
1173 | command += " " + gpppdata.speed(); | ||
1174 | |||
1175 | command += " -detach"; | ||
1176 | |||
1177 | if(gpppdata.ipaddr() != "0.0.0.0" || | ||
1178 | gpppdata.gateway() != "0.0.0.0") { | ||
1179 | if(gpppdata.ipaddr() != "0.0.0.0") { | ||
1180 | command += " "; | ||
1181 | command += gpppdata.ipaddr(); | ||
1182 | command += ":"; | ||
1183 | } | ||
1184 | else { | ||
1185 | command += " "; | ||
1186 | command += ":"; | ||
1187 | } | ||
1188 | |||
1189 | if(gpppdata.gateway() != "0.0.0.0") | ||
1190 | command += gpppdata.gateway(); | ||
1191 | } | ||
1192 | |||
1193 | if(gpppdata.subnetmask() != "0.0.0.0") | ||
1194 | command += " netmask " + gpppdata.subnetmask(); | ||
1195 | |||
1196 | if(gpppdata.flowcontrol() != "None") { | ||
1197 | if(gpppdata.flowcontrol() == "CRTSCTS") | ||
1198 | command += " crtscts"; | ||
1199 | else | ||
1200 | command += " xonxoff"; | ||
1201 | } | ||
1202 | |||
1203 | if(gpppdata.defaultroute()) | ||
1204 | command += " defaultroute"; | ||
1205 | |||
1206 | if(gpppdata.autoDNS()) | ||
1207 | command += " usepeerdns"; | ||
1208 | |||
1209 | QStringList &arglist = gpppdata.pppdArgument(); | ||
1210 | for ( QStringList::Iterator it = arglist.begin(); | ||
1211 | it != arglist.end(); | ||
1212 | ++it ) | ||
1213 | { | ||
1214 | command += " " + *it; | ||
1215 | } | ||
1216 | |||
1217 | // PAP settings | ||
1218 | if(gpppdata.authMethod() == AUTH_PAP) { | ||
1219 | command += " -chap user "; | ||
1220 | command = command + "\"" + gpppdata.storedUsername() + "\""; | ||
1221 | } | ||
1222 | |||
1223 | // CHAP settings | ||
1224 | if(gpppdata.authMethod() == AUTH_CHAP) { | ||
1225 | command += " -pap user "; | ||
1226 | command = command + "\"" + gpppdata.storedUsername() + "\""; | ||
1227 | } | ||
1228 | |||
1229 | // PAP/CHAP settings | ||
1230 | if(gpppdata.authMethod() == AUTH_PAPCHAP) { | ||
1231 | command += " user "; | ||
1232 | command = command + "\"" + gpppdata.storedUsername() + "\""; | ||
1233 | } | ||
1234 | |||
1235 | // check for debug | ||
1236 | if(gpppdata.getPPPDebug()) | ||
1237 | command += " debug"; | ||
1238 | |||
1239 | if (command.length() > MAX_CMDLEN) { | ||
1240 | QMessageBox::critical(this, "error", i18n( | ||
1241 | "pppd command + command-line arguments exceed " | ||
1242 | "2024 characters in length." | ||
1243 | )); | ||
1244 | |||
1245 | return false; // nonsensically long command which would bust my buffer buf. | ||
1246 | } | ||
1247 | |||
1248 | qApp->flushX(); | ||
1249 | |||
1250 | return Modem::modem->execPPPDaemon(command); | ||
1251 | } | ||
1252 | |||
1253 | |||
1254 | void ConnectWidget::closeEvent( QCloseEvent *e ) { | ||
1255 | e->ignore(); | ||
1256 | emit cancelbutton(); | ||
1257 | } | ||
1258 | |||
1259 | |||
1260 | void ConnectWidget::setMsg(const QString &msg) { | ||
1261 | messg->setText(msg); | ||
1262 | } | ||
1263 | |||
1264 | void ConnectWidget::writeline(const QString &s) { | ||
1265 | Modem::modem->writeLine(s.local8Bit()); | ||
1266 | } | ||
1267 | |||
1268 | // Set the hostname and domain from DNS Server | ||
1269 | void auto_hostname() { | ||
1270 | struct in_addr local_ip; | ||
1271 | struct hostent *hostname_entry; | ||
1272 | QString new_hostname; | ||
1273 | int dot; | ||
1274 | char tmp_str[100]; // buffer overflow safe | ||
1275 | |||
1276 | gethostname(tmp_str, sizeof(tmp_str)); | ||
1277 | tmp_str[sizeof(tmp_str)-1]=0; // panic | ||
1278 | old_hostname=tmp_str; // copy to QString | ||
1279 | |||
1280 | // if (!p_kppp->stats->local_ip_address.isEmpty() && gpppdata.autoname()) { | ||
1281 | if ( gpppdata.autoname()) { | ||
1282 | // local_ip.s_addr=inet_addr(p_kppp->stats->local_ip_address.ascii()); | ||
1283 | hostname_entry=gethostbyaddr((const char *)&local_ip,sizeof(in_addr),AF_INET); | ||
1284 | |||
1285 | if (hostname_entry != 0L) { | ||
1286 | new_hostname=hostname_entry->h_name; | ||
1287 | dot=new_hostname.find('.'); | ||
1288 | new_hostname=new_hostname.remove(dot,new_hostname.length()-dot); | ||
1289 | Modem::modem->setHostname(new_hostname); | ||
1290 | modified_hostname = TRUE; | ||
1291 | |||
1292 | new_hostname=hostname_entry->h_name; | ||
1293 | new_hostname.remove(0,dot+1); | ||
1294 | |||
1295 | add_domain(new_hostname); | ||
1296 | } | ||
1297 | } | ||
1298 | |||
1299 | } | ||
1300 | |||
1301 | // Replace the DNS domain entry in the /etc/resolv.conf file and | ||
1302 | // disable the nameserver entries if option is enabled | ||
1303 | void add_domain(const QString &domain) { | ||
1304 | |||
1305 | int fd; | ||
1306 | char c; | ||
1307 | QString resolv[MAX_RESOLVCONF_LINES]; | ||
1308 | |||
1309 | if (domain.isEmpty()) | ||
1310 | return; | ||
1311 | |||
1312 | if((fd = Modem::modem->openResolv(O_RDONLY)) >= 0) { | ||
1313 | |||
1314 | int i=0; | ||
1315 | while((read(fd, &c, 1) == 1) && (i < MAX_RESOLVCONF_LINES)) { | ||
1316 | if(c == '\n') { | ||
1317 | i++; | ||
1318 | } | ||
1319 | else { | ||
1320 | resolv[i] += c; | ||
1321 | } | ||
1322 | } | ||
1323 | close(fd); | ||
1324 | if ((c != '\n') && (i < MAX_RESOLVCONF_LINES)) i++; | ||
1325 | |||
1326 | if((fd = Modem::modem->openResolv(O_WRONLY|O_TRUNC)) >= 0) { | ||
1327 | QCString tmp = "domain " + domain.local8Bit() + | ||
1328 | " \t\t#kppp temp entry\n"; | ||
1329 | write(fd, tmp.data(), tmp.length()); | ||
1330 | |||
1331 | for(int j=0; j < i; j++) { | ||
1332 | if((resolv[j].contains("domain") || | ||
1333 | ( resolv[j].contains("nameserver") | ||
1334 | && !resolv[j].contains("#kppp temp entry") | ||
1335 | && gpppdata.exDNSDisabled())) | ||
1336 | && !resolv[j].contains("#entry disabled by kppp")) { | ||
1337 | QCString tmp = "# " + resolv[j].local8Bit() + | ||
1338 | " \t#entry disabled by kppp\n"; | ||
1339 | write(fd, tmp, tmp.length()); | ||
1340 | } | ||
1341 | else { | ||
1342 | QCString tmp = resolv[j].local8Bit() + "\n"; | ||
1343 | write(fd, tmp, tmp.length()); | ||
1344 | } | ||
1345 | } | ||
1346 | } | ||
1347 | close(fd); | ||
1348 | } | ||
1349 | } | ||
1350 | |||
1351 | |||
1352 | // adds the DNS entries in the /etc/resolv.conf file | ||
1353 | void adddns() | ||
1354 | { | ||
1355 | int fd; | ||
1356 | |||
1357 | if ((fd = Modem::modem->openResolv(O_WRONLY|O_APPEND)) >= 0) { | ||
1358 | QStringList &dnslist = gpppdata.dns(); | ||
1359 | for ( QStringList::Iterator it = dnslist.begin(); | ||
1360 | it != dnslist.end(); | ||
1361 | ++it ) | ||
1362 | { | ||
1363 | QCString dns = "nameserver " + (*it).local8Bit() + | ||
1364 | " \t#kppp temp entry\n"; | ||
1365 | write(fd, dns.data(), dns.length()); | ||
1366 | } | ||
1367 | close(fd); | ||
1368 | } | ||
1369 | add_domain(gpppdata.domain()); | ||
1370 | } | ||
1371 | |||
1372 | void addpeerdns() { | ||
1373 | int fd, fd2; | ||
1374 | |||
1375 | if((fd = Modem::modem->openResolv(O_WRONLY|O_APPEND)) >= 0) { | ||
1376 | if((fd2 = open("/etc/ppp/resolv.conf", O_RDONLY)) >= 0) { | ||
1377 | char c; | ||
1378 | int i = 0; | ||
1379 | while(i++ < 100 && read(fd2, &c, 1) == 1) { | ||
1380 | if(c == '\n') | ||
1381 | write(fd, "\t#kppp temp entry\n", 18); | ||
1382 | else | ||
1383 | write(fd, &c, 1); | ||
1384 | } | ||
1385 | close(fd2); | ||
1386 | } else | ||
1387 | fprintf(stderr, "failed to read from /etc/ppp/resolv.conf\n"); | ||
1388 | close(fd); | ||
1389 | } | ||
1390 | add_domain(gpppdata.domain()); | ||
1391 | } | ||
1392 | |||
1393 | // remove the dns entries from the /etc/resolv.conf file | ||
1394 | void removedns() { | ||
1395 | |||
1396 | int fd; | ||
1397 | char c; | ||
1398 | QString resolv[MAX_RESOLVCONF_LINES]; | ||
1399 | |||
1400 | if((fd = Modem::modem->openResolv(O_RDONLY)) >= 0) { | ||
1401 | |||
1402 | int i=0; | ||
1403 | while(read(fd, &c, 1) == 1 && i < MAX_RESOLVCONF_LINES) { | ||
1404 | if(c == '\n') { | ||
1405 | i++; | ||
1406 | } | ||
1407 | else { | ||
1408 | resolv[i] += c; | ||
1409 | } | ||
1410 | } | ||
1411 | close(fd); | ||
1412 | |||
1413 | if((fd = Modem::modem->openResolv(O_WRONLY|O_TRUNC)) >= 0) { | ||
1414 | for(int j=0; j < i; j++) { | ||
1415 | if(resolv[j].contains("#kppp temp entry")) continue; | ||
1416 | if(resolv[j].contains("#entry disabled by kppp")) { | ||
1417 | QCString tmp = resolv[j].local8Bit(); | ||
1418 | write(fd, tmp.data()+2, tmp.length() - 27); | ||
1419 | write(fd, "\n", 1); | ||
1420 | } | ||
1421 | else { | ||
1422 | QCString tmp = resolv[j].local8Bit() + "\n"; | ||
1423 | write(fd, tmp, tmp.length()); | ||
1424 | } | ||
1425 | } | ||
1426 | } | ||
1427 | close(fd); | ||
1428 | |||
1429 | } | ||
1430 | |||
1431 | if ( modified_hostname ) { | ||
1432 | Modem::modem->setHostname(old_hostname); | ||
1433 | modified_hostname = FALSE; | ||
1434 | } | ||
1435 | |||
1436 | } | ||
1437 | |||
1438 | |||
diff --git a/noncore/settings/networksettings/ppp/connect.h b/noncore/settings/networksettings/ppp/connect.h new file mode 100644 index 0000000..3127236 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/connect.h | |||
@@ -0,0 +1,152 @@ | |||
1 | /* -*- C++ -*- | ||
2 | * | ||
3 | * kPPP: A pppd front end for the KDE project | ||
4 | * | ||
5 | * $Id$ | ||
6 | * | ||
7 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
8 | * wuebben@math.cornell.edu | ||
9 | * | ||
10 | * based on EzPPP: | ||
11 | * Copyright (C) 1997 Jay Painter | ||
12 | * | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU Library General Public | ||
16 | * License as published by the Free Software Foundation; either | ||
17 | * version 2 of the License, or (at your option) any later version. | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, | ||
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
22 | * Library General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU Library General Public | ||
25 | * License along with this program; if not, write to the Free | ||
26 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
27 | */ | ||
28 | |||
29 | #ifndef _CONNECT_H_ | ||
30 | #define _CONNECT_H_ | ||
31 | |||
32 | #include <qtimer.h> | ||
33 | #include <qpushbutton.h> | ||
34 | #include <qlabel.h> | ||
35 | #include <qevent.h> | ||
36 | |||
37 | #include "kpppconfig.h" | ||
38 | #include "pwentry.h" | ||
39 | //#include "docking.h" | ||
40 | //#include "loginterm.h" | ||
41 | |||
42 | #define MAXLOOPNEST (MAX_SCRIPT_ENTRIES/2) | ||
43 | |||
44 | class PPPStats; | ||
45 | |||
46 | class ConnectWidget : public QWidget { | ||
47 | Q_OBJECT | ||
48 | public: | ||
49 | ConnectWidget(QWidget *parent, const char *name); | ||
50 | ~ConnectWidget(); | ||
51 | |||
52 | public: | ||
53 | void set_con_speed_string(); | ||
54 | void setMsg(const QString &); | ||
55 | void pppdDied(); | ||
56 | |||
57 | protected: | ||
58 | void timerEvent(QTimerEvent *); | ||
59 | void closeEvent( QCloseEvent *e ); | ||
60 | |||
61 | private slots: | ||
62 | void readChar(unsigned char); | ||
63 | void pause(); | ||
64 | void if_waiting_slot(); | ||
65 | |||
66 | public slots: | ||
67 | void init(); | ||
68 | void preinit(); | ||
69 | void script_timed_out(); | ||
70 | void if_waiting_timed_out(); | ||
71 | void cancelbutton(); | ||
72 | |||
73 | signals: | ||
74 | void if_waiting_signal(); | ||
75 | void debugMessage(const QString &); | ||
76 | void toggleDebugWindow(); | ||
77 | void closeDebugWindow(); | ||
78 | void debugPutChar(unsigned char); | ||
79 | void startAccounting(); | ||
80 | void stopAccounting(); | ||
81 | |||
82 | public: | ||
83 | QString myreadbuffer; // we want to keep every thing in order to fish for the | ||
84 | |||
85 | // connection speed later on | ||
86 | QPushButton *debug; | ||
87 | int main_timer_ID; | ||
88 | |||
89 | private: | ||
90 | int vmain; | ||
91 | int substate; | ||
92 | int scriptindex; | ||
93 | QString scriptCommand, scriptArgument; | ||
94 | QStringList *comlist, *arglist; | ||
95 | |||
96 | // static const int maxloopnest=(MAX_SCRIPT_ENTRIES/2); | ||
97 | int loopnest; | ||
98 | int loopstartindex[MAXLOOPNEST]; | ||
99 | bool loopend; | ||
100 | QString loopstr[MAXLOOPNEST]; | ||
101 | |||
102 | bool semaphore; | ||
103 | QTimer *inittimer; | ||
104 | |||
105 | QTimer *timeout_timer; | ||
106 | bool execppp(); | ||
107 | void writeline(const QString &); | ||
108 | void checkBuffers(); | ||
109 | |||
110 | void setExpect(const QString &); | ||
111 | bool expecting; | ||
112 | QString expectstr; | ||
113 | |||
114 | QString readbuffer; | ||
115 | |||
116 | void setScan(const QString &); | ||
117 | QString scanvar; | ||
118 | QString scanstr; | ||
119 | QString scanbuffer; | ||
120 | bool scanning; | ||
121 | |||
122 | bool pausing; | ||
123 | PWEntry *prompt; | ||
124 | // LoginTerm *termwindow; | ||
125 | |||
126 | int scriptTimeout; | ||
127 | QTimer *pausetimer; | ||
128 | QTimer *if_timer; | ||
129 | QTimer *if_timeout_timer; | ||
130 | |||
131 | QLabel *messg; | ||
132 | QPushButton *cancel; | ||
133 | |||
134 | bool firstrunID; | ||
135 | bool firstrunPW; | ||
136 | |||
137 | unsigned int dialnumber; // the current number to dial | ||
138 | |||
139 | // PPPStats *stats; | ||
140 | }; | ||
141 | |||
142 | |||
143 | // non-member function to kill&wait on the pppd child process | ||
144 | extern void killppp(); | ||
145 | void adddns(); | ||
146 | void addpeerdns(); | ||
147 | void removedns(); | ||
148 | void add_domain(const QString & newdomain); | ||
149 | void auto_hostname(); | ||
150 | |||
151 | #endif | ||
152 | |||
diff --git a/noncore/settings/networksettings/ppp/conwindow.cpp b/noncore/settings/networksettings/ppp/conwindow.cpp new file mode 100644 index 0000000..d6b3fbe --- a/dev/null +++ b/noncore/settings/networksettings/ppp/conwindow.cpp | |||
@@ -0,0 +1,341 @@ | |||
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 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU Library General Public | ||
11 | * License as published by the Free Software Foundation; either | ||
12 | * version 2 of the License, or (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * Library General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU Library General Public | ||
20 | * License along with this program; if not, write to the Free | ||
21 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | #include <qtooltip.h> | ||
25 | #include <qdialog.h> | ||
26 | #include "conwindow.h" | ||
27 | //#include "docking.h" | ||
28 | #include "pppdata.h" | ||
29 | // #include "pppstats.h" | ||
30 | // #include <klocale.h> | ||
31 | #define i18n QObject::tr | ||
32 | // #include <kglobal.h> | ||
33 | |||
34 | extern PPPData gpppdata; | ||
35 | |||
36 | ConWindow::ConWindow(QWidget *parent, const char *name, QDialog *mainwidget ) | ||
37 | // PPPStats *st) | ||
38 | : QWidget(parent, name, 0), | ||
39 | minutes(0), | ||
40 | seconds(0), | ||
41 | hours(0), | ||
42 | days(0), | ||
43 | tl1(0), | ||
44 | // stats(st), | ||
45 | accountingEnabled(false), | ||
46 | volumeAccountingEnabled(false) | ||
47 | { | ||
48 | info1 = new QLabel(i18n("Connected at:"), this); | ||
49 | info2 = new QLabel("", this); | ||
50 | |||
51 | timelabel1 = new QLabel(i18n("Time connected:"), this); | ||
52 | timelabel2 = new QLabel("000:00:00", this); | ||
53 | |||
54 | vollabel = new QLabel(i18n("Volume:"), this); | ||
55 | volinfo = new QLabel("", this); | ||
56 | |||
57 | // now the stuff for accounting | ||
58 | session_bill_l = new QLabel(i18n("Session Bill:"), this); | ||
59 | session_bill = new QLabel("", this); | ||
60 | total_bill_l = new QLabel(i18n("Total Bill:"), this); | ||
61 | total_bill = new QLabel("", this); | ||
62 | |||
63 | this->setCaption("kppp"); | ||
64 | |||
65 | cancelbutton = new QPushButton(this); | ||
66 | cancelbutton->setText(i18n("Disconnect")); | ||
67 | connect(cancelbutton, SIGNAL(clicked()), mainwidget, SLOT(disconnect())); | ||
68 | |||
69 | // statsbutton = new QPushButton(this); | ||
70 | // statsbutton->setText(i18n("Details")); | ||
71 | // statsbutton->setFocus(); | ||
72 | // connect(statsbutton, SIGNAL(clicked()), mainwidget, SLOT(showStats())); | ||
73 | |||
74 | clocktimer = new QTimer(this); | ||
75 | connect(clocktimer, SIGNAL(timeout()), SLOT(timeclick())); | ||
76 | |||
77 | // read window position from config file | ||
78 | int p_x, p_y; | ||
79 | gpppdata.winPosConWin(p_x, p_y); | ||
80 | setGeometry(p_x, p_y, 320, 110); | ||
81 | } | ||
82 | |||
83 | ConWindow::~ConWindow() { | ||
84 | stopClock(); | ||
85 | } | ||
86 | |||
87 | // save window position when window was closed | ||
88 | bool ConWindow::event(QEvent *e) { | ||
89 | if (e->type() == QEvent::Hide) | ||
90 | { | ||
91 | gpppdata.setWinPosConWin(x(), y()); | ||
92 | return true; | ||
93 | } | ||
94 | else | ||
95 | return QWidget::event(e); | ||
96 | } | ||
97 | |||
98 | QString ConWindow::prettyPrintVolume(unsigned int n) { | ||
99 | int idx = 0; | ||
100 | const QString quant[] = {i18n("Byte"), i18n("KB"), | ||
101 | i18n("MB"), i18n("GB"), QString::null}; | ||
102 | |||
103 | float n1 = n; | ||
104 | while(n >= 1024 && quant[idx] != QString::null) { | ||
105 | idx++; | ||
106 | n /= 1024; | ||
107 | } | ||
108 | |||
109 | int i = idx; | ||
110 | while(i--) | ||
111 | n1 = n1 / 1024.0; | ||
112 | |||
113 | QString s = QString::number( n1, 'f', idx==0 ? 0 : 1 ); //KGlobal::locale()->formatNumber( n1, idx==0 ? 0 : 1 ); | ||
114 | s += " " + quant[idx]; | ||
115 | return s; | ||
116 | } | ||
117 | |||
118 | void ConWindow::accounting(bool on) { | ||
119 | // cache accounting settings | ||
120 | accountingEnabled = on; | ||
121 | volumeAccountingEnabled = gpppdata.VolAcctEnabled(); | ||
122 | |||
123 | // delete old layout | ||
124 | if(tl1 != 0) | ||
125 | delete tl1; | ||
126 | |||
127 | // add layout now | ||
128 | tl1 = new QVBoxLayout(this, 10, 10); | ||
129 | tl1->addSpacing(5); | ||
130 | QHBoxLayout *tl = new QHBoxLayout; | ||
131 | tl1->addLayout(tl); | ||
132 | tl->addSpacing(20); | ||
133 | QGridLayout *l1; | ||
134 | |||
135 | int vol_lines = 0; | ||
136 | if(gpppdata.VolAcctEnabled()) | ||
137 | vol_lines = 1; | ||
138 | |||
139 | if(accountingEnabled) | ||
140 | l1 = new QGridLayout(4 + vol_lines, 2, 5); | ||
141 | else | ||
142 | l1 = new QGridLayout(2 + vol_lines, 2, 5); | ||
143 | tl->addLayout(l1); | ||
144 | l1->setColStretch(0, 0); | ||
145 | l1->setColStretch(1, 1); | ||
146 | |||
147 | info2->setAlignment(AlignRight|AlignVCenter); | ||
148 | timelabel2->setAlignment(AlignRight|AlignVCenter); | ||
149 | session_bill->setAlignment(AlignRight|AlignVCenter); | ||
150 | total_bill->setAlignment(AlignRight|AlignVCenter); | ||
151 | volinfo->setAlignment(AlignRight|AlignVCenter); | ||
152 | // make sure that there's enough space for the bills | ||
153 | QString s1 = session_bill->text(); | ||
154 | QString s2 = total_bill->text(); | ||
155 | QString s3 = volinfo->text(); | ||
156 | |||
157 | session_bill->setText("888888.88 XXX"); | ||
158 | total_bill->setText("888888.88 XXX"); | ||
159 | volinfo->setText("8888.8 MB"); | ||
160 | session_bill->setFixedSize(session_bill->sizeHint()); | ||
161 | total_bill->setFixedSize(total_bill->sizeHint()); | ||
162 | volinfo->setFixedSize(volinfo->sizeHint()); | ||
163 | session_bill->setText(s1); | ||
164 | total_bill->setText(s2); | ||
165 | volinfo->setText(s3); | ||
166 | |||
167 | l1->addWidget(info1, 0, 0); | ||
168 | l1->addWidget(info2, 0, 1); | ||
169 | l1->addWidget(timelabel1, 1, 0); | ||
170 | l1->addWidget(timelabel2, 1, 1); | ||
171 | if(accountingEnabled) { | ||
172 | session_bill_l->show(); | ||
173 | session_bill->show(); | ||
174 | total_bill_l->show(); | ||
175 | total_bill->show(); | ||
176 | l1->addWidget(session_bill_l, 2, 0); | ||
177 | l1->addWidget(session_bill, 2, 1); | ||
178 | l1->addWidget(total_bill_l, 3, 0); | ||
179 | l1->addWidget(total_bill, 3, 1); | ||
180 | |||
181 | if(volumeAccountingEnabled) { | ||
182 | vollabel->show(); | ||
183 | volinfo->show(); | ||
184 | l1->addWidget(vollabel, 4, 0); | ||
185 | l1->addWidget(volinfo, 4, 1); | ||
186 | } else { | ||
187 | vollabel->hide(); | ||
188 | volinfo->hide(); | ||
189 | } | ||
190 | |||
191 | } else { | ||
192 | session_bill_l->hide(); | ||
193 | session_bill->hide(); | ||
194 | total_bill_l->hide(); | ||
195 | total_bill->hide(); | ||
196 | |||
197 | if(volumeAccountingEnabled) { | ||
198 | vollabel->show(); | ||
199 | volinfo->show(); | ||
200 | l1->addWidget(vollabel, 2, 0); | ||
201 | l1->addWidget(volinfo, 2, 1); | ||
202 | } else { | ||
203 | vollabel->hide(); | ||
204 | volinfo->hide(); | ||
205 | } | ||
206 | } | ||
207 | |||
208 | tl->addSpacing(10); | ||
209 | QVBoxLayout *l2 = new QVBoxLayout(5); | ||
210 | tl->addLayout(l2); | ||
211 | l2->addStretch(1); | ||
212 | // l2->addWidget(statsbutton); | ||
213 | l2->addWidget(cancelbutton); | ||
214 | |||
215 | l2->addStretch(1); | ||
216 | |||
217 | tl1->addSpacing(5); | ||
218 | |||
219 | setFixedSize(sizeHint()); | ||
220 | /* | ||
221 | do not overwrite position read from config | ||
222 | setGeometry((QApplication::desktop()->width() - width()) / 2, | ||
223 | (QApplication::desktop()->height() - height())/2, | ||
224 | width(), | ||
225 | height()); | ||
226 | */ | ||
227 | } | ||
228 | |||
229 | |||
230 | void ConWindow::dock() { | ||
231 | // DockWidget::dock_widget->show(); | ||
232 | this->hide(); | ||
233 | } | ||
234 | |||
235 | |||
236 | void ConWindow::startClock() { | ||
237 | minutes = 0; | ||
238 | seconds = 0; | ||
239 | hours = 0; | ||
240 | QString title ; | ||
241 | |||
242 | title = gpppdata.accname(); | ||
243 | |||
244 | if(gpppdata.get_show_clock_on_caption()){ | ||
245 | title += " 00:00" ; | ||
246 | } | ||
247 | this->setCaption(title); | ||
248 | |||
249 | timelabel2->setText("00:00:00"); | ||
250 | clocktimer->start(1000); | ||
251 | } | ||
252 | |||
253 | |||
254 | void ConWindow::setConnectionSpeed(const QString &speed) { | ||
255 | info2->setText(speed); | ||
256 | } | ||
257 | |||
258 | |||
259 | void ConWindow::stopClock() { | ||
260 | clocktimer->stop(); | ||
261 | } | ||
262 | |||
263 | |||
264 | void ConWindow::timeclick() { | ||
265 | QString tooltip = i18n("Connection: %1\n" | ||
266 | "Connected at: %2\n" | ||
267 | "Time connected: %3") | ||
268 | .arg(gpppdata.accname()).arg(info2->text()) | ||
269 | .arg(time_string2); | ||
270 | |||
271 | if(accountingEnabled) | ||
272 | tooltip += i18n("\nSession Bill: %1\nTotal Bill: %2") | ||
273 | .arg(session_bill->text()).arg(total_bill->text()); | ||
274 | // volume accounting | ||
275 | if(volumeAccountingEnabled) { | ||
276 | |||
277 | volinfo->setEnabled(TRUE); | ||
278 | int bytes = gpppdata.totalBytes(); | ||
279 | volinfo->setText(prettyPrintVolume(bytes)); | ||
280 | } | ||
281 | |||
282 | seconds++; | ||
283 | |||
284 | if(seconds >= 60 ) { | ||
285 | minutes ++; | ||
286 | seconds = 0; | ||
287 | } | ||
288 | |||
289 | if (minutes >= 60){ | ||
290 | minutes = 0; | ||
291 | hours ++; | ||
292 | } | ||
293 | |||
294 | if( hours >= 24){ | ||
295 | days ++; | ||
296 | hours = 0; | ||
297 | } | ||
298 | |||
299 | time_string.sprintf("%02d:%02d",hours,minutes); | ||
300 | time_string2 = ""; | ||
301 | if (days) | ||
302 | time_string2.sprintf("%d d %02d:%02d:%02d", | ||
303 | days,hours,minutes,seconds); | ||
304 | |||
305 | else | ||
306 | time_string2.sprintf("%02d:%02d:%02d",hours,minutes,seconds); | ||
307 | |||
308 | caption_string = gpppdata.accname(); | ||
309 | caption_string += " "; | ||
310 | caption_string += time_string; | ||
311 | |||
312 | |||
313 | timelabel2->setText(time_string2); | ||
314 | |||
315 | if(gpppdata.get_show_clock_on_caption() && (seconds == 1)){ | ||
316 | // we update the Caption only once per minute not every second | ||
317 | // otherwise I get a flickering icon | ||
318 | this->setCaption(caption_string); | ||
319 | } | ||
320 | |||
321 | // QToolTip::add(DockWidget::dock_widget, tooltip); | ||
322 | } | ||
323 | |||
324 | |||
325 | void ConWindow::closeEvent( QCloseEvent *e ){ | ||
326 | // we don't want to lose the | ||
327 | // conwindow since this is our last connection kppp. | ||
328 | // if we lost it we could only kill the program by hand to get on with life. | ||
329 | e->ignore(); | ||
330 | |||
331 | if(gpppdata.get_dock_into_panel()) | ||
332 | dock(); | ||
333 | } | ||
334 | |||
335 | |||
336 | void ConWindow::slotAccounting(QString total, QString session) { | ||
337 | total_bill->setText(total); | ||
338 | session_bill->setText(session); | ||
339 | } | ||
340 | |||
341 | |||
diff --git a/noncore/settings/networksettings/ppp/conwindow.h b/noncore/settings/networksettings/ppp/conwindow.h new file mode 100644 index 0000000..20d3579 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/conwindow.h | |||
@@ -0,0 +1,96 @@ | |||
1 | /* -*- C++ -*- | ||
2 | * | ||
3 | * kPPP: A pppd front end for the KDE project | ||
4 | * | ||
5 | * $Id$ | ||
6 | * | ||
7 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
8 | * wuebben@math.cornell.edu | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU Library General Public | ||
12 | * License as published by the Free Software Foundation; either | ||
13 | * version 2 of the License, or (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | * Library General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU Library General Public | ||
21 | * License along with this program; if not, write to the Free | ||
22 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
23 | */ | ||
24 | |||
25 | #ifndef _CONWINDOW_H_ | ||
26 | #define _CONWINDOW_H_ | ||
27 | |||
28 | |||
29 | #include <qtimer.h> | ||
30 | #include <qpushbutton.h> | ||
31 | #include <qlabel.h> | ||
32 | #include <qdialog.h> | ||
33 | #include <qframe.h> | ||
34 | #include <qevent.h> | ||
35 | #include <qlayout.h> | ||
36 | |||
37 | //class PPPStats; | ||
38 | |||
39 | class ConWindow : public QWidget { | ||
40 | Q_OBJECT | ||
41 | |||
42 | public: | ||
43 | ConWindow(QWidget *parent, const char *name, QDialog* ); | ||
44 | ~ConWindow(); | ||
45 | |||
46 | protected: | ||
47 | void closeEvent( QCloseEvent *e ); | ||
48 | bool event( QEvent *e ); | ||
49 | |||
50 | private slots: | ||
51 | void timeclick(); | ||
52 | void dock(); | ||
53 | |||
54 | public: | ||
55 | void setConnectionSpeed(const QString&); | ||
56 | void startClock(); | ||
57 | void stopClock(); | ||
58 | void accounting(bool); // show/ hide accounting info | ||
59 | |||
60 | public slots: | ||
61 | void slotAccounting(QString, QString); | ||
62 | |||
63 | private: | ||
64 | QLabel *info1; | ||
65 | QLabel *info2; | ||
66 | QPushButton *cancelbutton; | ||
67 | QPushButton *statsbutton; | ||
68 | QString prettyPrintVolume(unsigned int); | ||
69 | int minutes; | ||
70 | int seconds; | ||
71 | int hours; | ||
72 | int days; | ||
73 | QFrame *fline; | ||
74 | QLabel *timelabel1; | ||
75 | QLabel *timelabel2; | ||
76 | QLabel *total_bill, *total_bill_l; | ||
77 | QLabel *session_bill, *session_bill_l; | ||
78 | QString caption_string; | ||
79 | QString time_string2; | ||
80 | QString time_string; | ||
81 | QTimer *clocktimer; | ||
82 | QVBoxLayout *tl1; | ||
83 | QLabel *vollabel; | ||
84 | QLabel *volinfo; | ||
85 | // PPPStats *stats; | ||
86 | bool accountingEnabled; | ||
87 | bool volumeAccountingEnabled; | ||
88 | }; | ||
89 | |||
90 | |||
91 | #endif | ||
92 | |||
93 | |||
94 | |||
95 | |||
96 | |||
diff --git a/noncore/settings/networksettings/ppp/debug.cpp b/noncore/settings/networksettings/ppp/debug.cpp new file mode 100644 index 0000000..8652931 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/debug.cpp | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | * kPPP: A pppd front end for the KDE project | ||
3 | * | ||
4 | * $Id$ | ||
5 | * Copyright (C) 1997 Bernd Wuebben | ||
6 | * wuebben@math.cornel.edu | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Library General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Library General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Library General Public | ||
19 | * License along with this program; if not, write to the Free | ||
20 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | */ | ||
22 | |||
23 | #include "debug.h" | ||
24 | //#include "main.h" | ||
25 | #include "pppdata.h" | ||
26 | //#include <klocale.h> | ||
27 | #define i18n QObject::tr | ||
28 | #include "kpppwidget.h" | ||
29 | #include <assert.h> | ||
30 | |||
31 | extern KPPPWidget *p_kppp; | ||
32 | |||
33 | myMultiEdit::myMultiEdit(QWidget *parent, const char *name) | ||
34 | : QMultiLineEdit(parent, name) | ||
35 | { | ||
36 | setReadOnly(true); | ||
37 | } | ||
38 | |||
39 | void myMultiEdit::insertChar(unsigned char c) { | ||
40 | QMultiLineEdit::insert(QChar(c)); | ||
41 | } | ||
42 | |||
43 | |||
44 | void myMultiEdit::newLine() { | ||
45 | QMultiLineEdit::newLine(); | ||
46 | } | ||
47 | |||
48 | |||
49 | DebugWidget::DebugWidget(QWidget *parent, const char *name) | ||
50 | : QDialog(parent, name, FALSE) | ||
51 | { | ||
52 | setCaption(i18n("Login Script Debug Window")); | ||
53 | |||
54 | text_window = new myMultiEdit(this,"debugwindow"); | ||
55 | text_window->setGeometry(2,5,400, 300); | ||
56 | // text_window->setReadOnly(FALSE); | ||
57 | |||
58 | statuslabel = new QLabel("", this, "statuslabel"); | ||
59 | |||
60 | statuslabel->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | ||
61 | statuslabel->setAlignment( AlignLeft|AlignVCenter ); | ||
62 | statuslabel->setGeometry(2, 307, 400, 20); | ||
63 | //statusPageLabel->setFont( QFont("helvetica",12,QFont::Normal) ); | ||
64 | |||
65 | dismiss = new QPushButton(this); | ||
66 | dismiss->setGeometry(330,340,70,30); | ||
67 | dismiss->setText(i18n("Close")); | ||
68 | dismiss->setFocus(); | ||
69 | connect(dismiss, SIGNAL(clicked()), SLOT(hide())); | ||
70 | |||
71 | |||
72 | /* fline = new QFrame(this,"line"); | ||
73 | fline->setFrameStyle(QFrame::HLine |QFrame::Sunken); | ||
74 | fline->setGeometry(2,332,398,5);*/ | ||
75 | adjustSize(); | ||
76 | setMinimumSize(width(),height()); | ||
77 | |||
78 | } | ||
79 | |||
80 | void DebugWidget::hideEvent(QHideEvent *) | ||
81 | { | ||
82 | assert(p_kppp); | ||
83 | // p_kppp->con->debug->setOn(false); | ||
84 | } | ||
85 | |||
86 | void DebugWidget::clear() { | ||
87 | text_window->clear(); | ||
88 | } | ||
89 | |||
90 | |||
91 | void DebugWidget::addChar(unsigned char c) { | ||
92 | QString stuff; | ||
93 | |||
94 | if(c == '\r' || c == '\n') { | ||
95 | if(c == '\n') | ||
96 | text_window->newLine(); | ||
97 | } else | ||
98 | text_window->insertChar(c); | ||
99 | } | ||
100 | |||
101 | |||
102 | void DebugWidget::statusLabel(const QString &s) { | ||
103 | statuslabel->setText(s); | ||
104 | } | ||
105 | |||
106 | |||
107 | /* | ||
108 | void DebugWidget::keyPressEvent(QKeyEvent *k) { | ||
109 | } | ||
110 | |||
111 | */ | ||
112 | void DebugWidget::resizeEvent(QResizeEvent *e){ | ||
113 | int w = width() ; | ||
114 | int h = height(); | ||
115 | e = e; | ||
116 | |||
117 | text_window->setGeometry(2,5,w - 2 ,h - 63); | ||
118 | statuslabel->setGeometry(2, h - 56 , w -2 , 20); | ||
119 | dismiss->setGeometry(w - 72 , h - 32, 70, 30); | ||
120 | // fline->setGeometry(2,h -70 ,w - 4,5); | ||
121 | } | ||
122 | |||
123 | |||
124 | void DebugWidget::enter() { | ||
125 | text_window->append("\r\n"); | ||
126 | } | ||
127 | |||
128 | |||
129 | void DebugWidget::toggleVisibility() { | ||
130 | if(isVisible()) | ||
131 | hide(); | ||
132 | else | ||
133 | show(); | ||
134 | |||
135 | bool showlog = isVisible(); | ||
136 | gpppdata.set_show_log_window(showlog); | ||
137 | } | ||
138 | |||
139 | |||
140 | |||
141 | |||
diff --git a/noncore/settings/networksettings/ppp/debug.h b/noncore/settings/networksettings/ppp/debug.h new file mode 100644 index 0000000..3565cec --- a/dev/null +++ b/noncore/settings/networksettings/ppp/debug.h | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | * kPPP: A pppd front end for the KDE project | ||
3 | * | ||
4 | * $Id$ | ||
5 | * Copyright (C) 1997 Bernd Wuebben | ||
6 | * wuebben@math.cornel.edu | ||
7 | * | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU Library General Public | ||
11 | * License as published by the Free Software Foundation; either | ||
12 | * version 2 of the License, or (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * Library General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU Library General Public | ||
20 | * License along with this program; if not, write to the Free | ||
21 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | #ifndef _DEBUGWIDGET_ | ||
25 | #define _DEBUGWIDGET_ | ||
26 | |||
27 | #include <qdialog.h> | ||
28 | #include <qstring.h> | ||
29 | #include <qlabel.h> | ||
30 | #include <qmultilineedit.h> | ||
31 | #include <qpushbutton.h> | ||
32 | |||
33 | |||
34 | class myMultiEdit : public QMultiLineEdit { | ||
35 | public: | ||
36 | |||
37 | myMultiEdit(QWidget *parent=0, const char *name=0); | ||
38 | |||
39 | void newLine(); | ||
40 | void insertChar(unsigned char c); | ||
41 | }; | ||
42 | |||
43 | |||
44 | class DebugWidget : public QDialog { | ||
45 | Q_OBJECT | ||
46 | public: | ||
47 | DebugWidget(QWidget *parent=0, const char *name=0); | ||
48 | |||
49 | void clear(); | ||
50 | |||
51 | public slots: | ||
52 | void statusLabel(const QString &); | ||
53 | void toggleVisibility(); | ||
54 | void addChar(unsigned char); | ||
55 | |||
56 | protected: | ||
57 | virtual void hideEvent(QHideEvent *); | ||
58 | virtual void resizeEvent(QResizeEvent *e); | ||
59 | |||
60 | private: | ||
61 | void enter(); | ||
62 | QFrame *fline; | ||
63 | QPushButton *dismiss; | ||
64 | myMultiEdit *text_window; | ||
65 | |||
66 | QLabel *statuslabel; | ||
67 | }; | ||
68 | |||
69 | #endif | ||
70 | |||
diff --git a/noncore/settings/networksettings/ppp/edit.cpp b/noncore/settings/networksettings/ppp/edit.cpp new file mode 100644 index 0000000..961047b --- a/dev/null +++ b/noncore/settings/networksettings/ppp/edit.cpp | |||
@@ -0,0 +1,1193 @@ | |||
1 | /* | ||
2 | * kPPP: A pppd Front End for the KDE project | ||
3 | * | ||
4 | * $Id$ | ||
5 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
6 | * wuebben@math.cornell.edu | ||
7 | * | ||
8 | * based on EzPPP: | ||
9 | * Copyright (C) 1997 Jay Painter | ||
10 | * | ||
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. | ||
15 | * | ||
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. | ||
20 | * | ||
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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
24 | */ | ||
25 | |||
26 | #include <string.h> | ||
27 | #include <termios.h> | ||
28 | #include <qlayout.h> | ||
29 | #include <qmessagebox.h> | ||
30 | #include <qwhatsthis.h> | ||
31 | #include <qregexp.h> | ||
32 | #include <qapplication.h> | ||
33 | //#include <kiconloader.h> | ||
34 | #include <qbuttongroup.h> | ||
35 | //#include <klocale.h> | ||
36 | #define i18n QObject::tr | ||
37 | #include <qvgroupbox.h> | ||
38 | #include <qhbox.h> | ||
39 | #include <qdialog.h> | ||
40 | //#include <kwin.h> | ||
41 | |||
42 | #include "edit.h" | ||
43 | #include "pppdata.h" | ||
44 | #include "newwidget.h" | ||
45 | #include "iplined.h" | ||
46 | #include "auth.h" | ||
47 | |||
48 | DialWidget::DialWidget( QWidget *parent, bool isnewaccount, const char *name ) | ||
49 | : QWidget(parent, name) | ||
50 | { | ||
51 | const int GRIDROWS = 6; | ||
52 | |||
53 | QGridLayout *tl = new QGridLayout(parent, GRIDROWS, 2, 0 );//, KDialog::spacingHint()); | ||
54 | |||
55 | connect_label = new QLabel(i18n("Connection name:"), parent); | ||
56 | tl->addWidget(connect_label, 0, 0); | ||
57 | |||
58 | connectname_l = new QLineEdit(parent); | ||
59 | connectname_l->setMaxLength(ACCNAME_SIZE); | ||
60 | tl->addWidget(connectname_l, 0, 1); | ||
61 | QString tmp = i18n("Type in a unique name for this connection"); | ||
62 | |||
63 | QWhatsThis::add(connect_label,tmp); | ||
64 | QWhatsThis::add(connectname_l,tmp); | ||
65 | |||
66 | |||
67 | number_label = new QLabel(i18n("Phone number:"), parent); | ||
68 | number_label->setAlignment(AlignTop|AlignLeft); | ||
69 | tl->addWidget(number_label, 1, 0); | ||
70 | |||
71 | QHBoxLayout *lpn = new QHBoxLayout(5); | ||
72 | tl->addLayout(lpn, 1, 1); | ||
73 | numbers = new QListBox(parent); | ||
74 | numbers->setMinimumSize(120, 70); | ||
75 | lpn->addWidget(numbers); | ||
76 | QVBoxLayout *lpn1 = new QVBoxLayout; | ||
77 | lpn->addLayout(lpn1); | ||
78 | add = new QPushButton(i18n("&Add..."), parent); | ||
79 | del = new QPushButton(i18n("&Remove"), parent); | ||
80 | |||
81 | up = new QPushButton(parent); | ||
82 | //FIXME: QPixmap pm = BarIcon("up"); | ||
83 | // up->setPixmap(pm); | ||
84 | down = new QPushButton(parent); | ||
85 | //FIXME: pm = BarIcon("down"); | ||
86 | // down->setPixmap(pm); | ||
87 | lpn1->addWidget(add); | ||
88 | lpn1->addWidget(del); | ||
89 | lpn1->addStretch(1); | ||
90 | lpn1->addWidget(up); | ||
91 | lpn1->addWidget(down); | ||
92 | connect(add, SIGNAL(clicked()), | ||
93 | this, SLOT(addNumber())); | ||
94 | connect(del, SIGNAL(clicked()), | ||
95 | this, SLOT(delNumber())); | ||
96 | connect(up, SIGNAL(clicked()), | ||
97 | this, SLOT(upNumber())); | ||
98 | connect(down, SIGNAL(clicked()), | ||
99 | this, SLOT(downNumber())); | ||
100 | connect(numbers, SIGNAL(highlighted(int)), | ||
101 | this, SLOT(selectionChanged(int))); | ||
102 | numbersChanged(); | ||
103 | |||
104 | tmp = i18n("<p>Specifies the phone numbers to dial. You\n" | ||
105 | "can supply multiple numbers here, simply\n" | ||
106 | "click on \"Add\". You can arrange the\n" | ||
107 | "order the numbers are tried by using the\n" | ||
108 | "arrow buttons.\n\n" | ||
109 | "When a number is busy or fails, <i>kppp</i> will \n" | ||
110 | "try the next number and so on"); | ||
111 | |||
112 | QWhatsThis::add(number_label,tmp); | ||
113 | QWhatsThis::add(numbers,tmp); | ||
114 | |||
115 | auth_l = new QLabel(i18n("Authentication:"), parent); | ||
116 | tl->addWidget(auth_l, 3, 0); | ||
117 | |||
118 | auth = new QComboBox(parent); | ||
119 | auth->insertItem(i18n("Script-based")); | ||
120 | auth->insertItem(i18n("PAP")); | ||
121 | auth->insertItem(i18n("Terminal-based")); | ||
122 | auth->insertItem(i18n("CHAP")); | ||
123 | auth->insertItem(i18n("PAP/CHAP")); | ||
124 | tl->addWidget(auth, 3, 1); | ||
125 | tmp = i18n("<p>Specifies the method used to identify yourself to\n" | ||
126 | "the PPP server. Most universities still use\n" | ||
127 | "<b>Terminal</b>- or <b>Script</b>-based authentication,\n" | ||
128 | "while most ISP use <b>PAP</b> and/or <b>CHAP</b>. If\n" | ||
129 | "unsure, contact your ISP.\n" | ||
130 | "\n" | ||
131 | "If you can choose between PAP and CHAP,\n" | ||
132 | "choose CHAP, because it's much safer. If you don't know\n" | ||
133 | "whether PAP or CHAP is right, choose PAP/CHAP."); | ||
134 | |||
135 | QWhatsThis::add(auth_l,tmp); | ||
136 | QWhatsThis::add(auth,tmp); | ||
137 | |||
138 | store_password = new QCheckBox(i18n("Store password"), parent); | ||
139 | store_password->setChecked(true); | ||
140 | tl->addMultiCellWidget(store_password, 4, 4, 0, 1, AlignRight); | ||
141 | QWhatsThis::add(store_password, | ||
142 | i18n("<p>When this is turned on, your ISP password\n" | ||
143 | "will be saved in <i>kppp</i>'s config file, so\n" | ||
144 | "you do not need to type it in every time.\n" | ||
145 | "\n" | ||
146 | "<b><font color=\"red\">Warning:</font> your password will be stored as\n" | ||
147 | "plain text in the config file, which is\n" | ||
148 | "readable only to you. Make sure nobody\n" | ||
149 | "gains access to this file!")); | ||
150 | |||
151 | pppdargs = new QPushButton(i18n("Customize pppd Arguments..."), parent); | ||
152 | connect(pppdargs, SIGNAL(clicked()), SLOT(pppdargsbutton())); | ||
153 | tl->addMultiCellWidget(pppdargs, 5, 5, 0, 1, AlignCenter); | ||
154 | |||
155 | // Set defaults if editing an existing connection | ||
156 | if(!isnewaccount) { | ||
157 | connectname_l->setText(gpppdata.accname()); | ||
158 | |||
159 | // insert the phone numbers into the listbox | ||
160 | QString n = gpppdata.phonenumber(); | ||
161 | QString tmp = ""; | ||
162 | uint idx = 0; | ||
163 | while(idx != n.length()) { | ||
164 | if(n[idx] == ':') { | ||
165 | if(tmp.length() > 0) | ||
166 | numbers->insertItem(tmp); | ||
167 | tmp = ""; | ||
168 | } else | ||
169 | tmp += n[idx]; | ||
170 | idx++; | ||
171 | } | ||
172 | if(tmp.length() > 0) | ||
173 | numbers->insertItem(tmp); | ||
174 | |||
175 | auth->setCurrentItem(gpppdata.authMethod()); | ||
176 | store_password->setChecked(gpppdata.storePassword()); | ||
177 | } else { | ||
178 | // select PAP/CHAP as default | ||
179 | auth->setCurrentItem(AUTH_PAPCHAP); | ||
180 | } | ||
181 | |||
182 | numbersChanged(); | ||
183 | tl->activate(); | ||
184 | } | ||
185 | |||
186 | |||
187 | bool DialWidget::save() { | ||
188 | //first check to make sure that the account name is unique! | ||
189 | if(connectname_l->text().isEmpty() || | ||
190 | !gpppdata.isUniqueAccname(connectname_l->text())) { | ||
191 | return false; | ||
192 | } else { | ||
193 | gpppdata.setAccname(connectname_l->text()); | ||
194 | |||
195 | QString number = ""; | ||
196 | for(uint i = 0; i < numbers->count(); i++) { | ||
197 | if(i != 0) | ||
198 | number += ":"; | ||
199 | number += numbers->text(i); | ||
200 | } | ||
201 | |||
202 | gpppdata.setPhonenumber(number); | ||
203 | gpppdata.setAuthMethod(auth->currentItem()); | ||
204 | gpppdata.setStorePassword(store_password->isChecked()); | ||
205 | return true; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | |||
210 | void DialWidget::numbersChanged() { | ||
211 | int sel = numbers->currentItem(); | ||
212 | |||
213 | del->setEnabled(sel != -1); | ||
214 | up->setEnabled(sel != -1 && sel != 0); | ||
215 | down->setEnabled(sel != -1 && sel != (int)numbers->count()-1); | ||
216 | } | ||
217 | |||
218 | |||
219 | void DialWidget::selectionChanged(int) { | ||
220 | numbersChanged(); | ||
221 | } | ||
222 | |||
223 | |||
224 | void DialWidget::addNumber() { | ||
225 | PhoneNumberDialog dlg(this); | ||
226 | if(dlg.exec()) { | ||
227 | numbers->insertItem(dlg.phoneNumber()); | ||
228 | numbersChanged(); | ||
229 | } | ||
230 | } | ||
231 | |||
232 | |||
233 | void DialWidget::delNumber() { | ||
234 | if(numbers->currentItem() != -1) { | ||
235 | numbers->removeItem(numbers->currentItem()); | ||
236 | numbersChanged(); | ||
237 | } | ||
238 | } | ||
239 | |||
240 | |||
241 | void DialWidget::upNumber() { | ||
242 | int idx = numbers->currentItem(); | ||
243 | if(idx != -1) { | ||
244 | QString item = numbers->text(idx); | ||
245 | numbers->removeItem(idx); | ||
246 | numbers->insertItem(item, idx-1); | ||
247 | numbers->setCurrentItem(idx-1); | ||
248 | numbersChanged(); | ||
249 | } | ||
250 | } | ||
251 | |||
252 | |||
253 | void DialWidget::downNumber() { | ||
254 | int idx = numbers->currentItem(); | ||
255 | if(idx != -1) { | ||
256 | QString item = numbers->text(idx); | ||
257 | numbers->removeItem(idx); | ||
258 | numbers->insertItem(item, idx+1); | ||
259 | numbers->setCurrentItem(idx+1); | ||
260 | numbersChanged(); | ||
261 | } | ||
262 | } | ||
263 | |||
264 | |||
265 | void DialWidget::pppdargsbutton() { | ||
266 | PPPdArguments pa(this); | ||
267 | pa.exec(); | ||
268 | } | ||
269 | |||
270 | |||
271 | |||
272 | ///////////////////////////////////////////////////////////////////////////// | ||
273 | // ExecWidget | ||
274 | ///////////////////////////////////////////////////////////////////////////// | ||
275 | ExecWidget::ExecWidget(QWidget *parent, bool isnewaccount, const char *name) : | ||
276 | QWidget(parent, name) | ||
277 | { | ||
278 | QVBoxLayout *tl = new QVBoxLayout(parent, 0 );//, KDialog::spacingHint()); | ||
279 | |||
280 | QLabel *l = new QLabel(\ | ||
281 | i18n("Here you can select commands to run at certain stages of the\n" | ||
282 | "connection. The commands are run with your real user id, so\n" | ||
283 | "you cannot run any commands here requiring root permissions\n" | ||
284 | "(unless, of course, you are root).\n\n" | ||
285 | "Be sure to supply the whole path to the program otherwise\n" | ||
286 | "kppp might be unable to find it."), parent); | ||
287 | l->setMinimumHeight(l->sizeHint().height()); | ||
288 | tl->addWidget(l); | ||
289 | tl->addStretch(1); | ||
290 | |||
291 | QGridLayout *l1 = new QGridLayout(4, 2, 10); | ||
292 | tl->addLayout(l1); | ||
293 | l1->setColStretch(0, 0); | ||
294 | l1->setColStretch(1, 1); | ||
295 | |||
296 | before_connect_l = new QLabel(i18n("Before connect:"), parent); | ||
297 | before_connect_l->setAlignment(AlignVCenter); | ||
298 | l1->addWidget(before_connect_l, 0, 0); | ||
299 | before_connect = new QLineEdit(parent); | ||
300 | before_connect->setMaxLength(COMMAND_SIZE); | ||
301 | l1->addWidget(before_connect, 0, 1); | ||
302 | QString tmp = i18n("Allows you to run a program <b>before</b> a connection\n" | ||
303 | "is established. It is called immediately before\n" | ||
304 | "dialing has begun.\n\n" | ||
305 | "This might be useful, e.g. to stop HylaFAX blocking the\n" | ||
306 | "modem."); | ||
307 | |||
308 | QWhatsThis::add(before_connect_l,tmp); | ||
309 | QWhatsThis::add(before_connect,tmp); | ||
310 | |||
311 | command_label = new QLabel(i18n("Upon connect:"), parent); | ||
312 | command_label->setAlignment(AlignVCenter); | ||
313 | l1->addWidget(command_label, 1, 0); | ||
314 | command = new QLineEdit(parent); | ||
315 | command->setMaxLength(COMMAND_SIZE); | ||
316 | l1->addWidget(command, 1, 1); | ||
317 | tmp = i18n("Allows you to run a program <b>after</b> a connection\n" | ||
318 | "is established. When your program is called, all\n" | ||
319 | "preparations for an Internet connection are finished.\n" | ||
320 | "\n" | ||
321 | "Very useful for fetching mail and news"); | ||
322 | |||
323 | QWhatsThis::add(command_label,tmp); | ||
324 | QWhatsThis::add(command,tmp); | ||
325 | |||
326 | predisconnect_label = new QLabel(i18n("Before disconnect:"), | ||
327 | parent); | ||
328 | predisconnect_label->setAlignment(AlignVCenter); | ||
329 | l1->addWidget(predisconnect_label, 2, 0); | ||
330 | predisconnect = new QLineEdit(parent); | ||
331 | predisconnect->setMaxLength(COMMAND_SIZE); | ||
332 | l1->addWidget(predisconnect, 2, 1); | ||
333 | tmp = i18n("Allows you to run a program <b>before</b> a connection\n" | ||
334 | "is closed. The connection will stay open until\n" | ||
335 | "the program exits."); | ||
336 | |||
337 | QWhatsThis::add(predisconnect_label,tmp); | ||
338 | QWhatsThis::add(predisconnect,tmp); | ||
339 | |||
340 | discommand_label = new QLabel(i18n("Upon disconnect:"), | ||
341 | parent); | ||
342 | discommand_label->setAlignment(AlignVCenter); | ||
343 | l1->addWidget(discommand_label, 3, 0); | ||
344 | |||
345 | discommand = new QLineEdit(parent); | ||
346 | discommand->setMaxLength(COMMAND_SIZE); | ||
347 | l1->addWidget(discommand, 3, 1); | ||
348 | tmp = i18n("Allows you to run a program <b>after</b> a connection\n" | ||
349 | "has been closed."); | ||
350 | |||
351 | QWhatsThis::add(discommand_label,tmp); | ||
352 | QWhatsThis::add(discommand,tmp); | ||
353 | |||
354 | // extra space between entries | ||
355 | l1->addRowSpacing(1, 5); | ||
356 | l1->addRowSpacing(3, 5); | ||
357 | |||
358 | tl->addStretch(1); | ||
359 | tl->activate(); | ||
360 | |||
361 | // Set defaults if editing an existing connection | ||
362 | if(!isnewaccount) { | ||
363 | before_connect->setText(gpppdata.command_before_connect()); | ||
364 | command->setText(gpppdata.command_on_connect()); | ||
365 | discommand->setText(gpppdata.command_on_disconnect()); | ||
366 | predisconnect->setText(gpppdata.command_before_disconnect()); | ||
367 | } | ||
368 | } | ||
369 | |||
370 | |||
371 | bool ExecWidget::save() { | ||
372 | gpppdata.setCommand_before_connect(before_connect->text()); | ||
373 | gpppdata.setCommand_on_connect(command->text()); | ||
374 | gpppdata.setCommand_before_disconnect(predisconnect->text()); | ||
375 | gpppdata.setCommand_on_disconnect(discommand->text()); | ||
376 | return true; | ||
377 | } | ||
378 | |||
379 | |||
380 | |||
381 | ///////////////////////////////////////////////////////////////////////////// | ||
382 | // | ||
383 | // IPWidget | ||
384 | // | ||
385 | ///////////////////////////////////////////////////////////////////////////// | ||
386 | IPWidget::IPWidget( QWidget *parent, bool isnewaccount, const char *name ) | ||
387 | : QWidget(parent, name) | ||
388 | { | ||
389 | QVBoxLayout *topLayout = new QVBoxLayout(parent); | ||
390 | topLayout->setSpacing( 3 );//KDialog::spacingHint()); | ||
391 | |||
392 | box = new QVGroupBox(i18n("Configuration"), parent); | ||
393 | // box->setInsideSpacing( 1 );//KDialog::spacingHint()); | ||
394 | |||
395 | rb = new QButtonGroup(parent); | ||
396 | rb->hide(); | ||
397 | connect(rb, SIGNAL(clicked(int)), | ||
398 | SLOT(hitIPSelect(int))); | ||
399 | |||
400 | dynamicadd_rb = new QRadioButton(box); | ||
401 | dynamicadd_rb->setText(i18n("Dynamic IP address")); | ||
402 | QWhatsThis::add(dynamicadd_rb, | ||
403 | i18n("Select this option when your computer gets an\n" | ||
404 | "internet address (IP) every time a\n" | ||
405 | "connection is made.\n" | ||
406 | "\n" | ||
407 | "Almost every Internet Service Provider uses\n" | ||
408 | "this method, so this should be turned on.")); | ||
409 | |||
410 | staticadd_rb = new QRadioButton(box); | ||
411 | staticadd_rb->setText(i18n("Static IP address")); | ||
412 | rb->insert(dynamicadd_rb, 0); | ||
413 | rb->insert(staticadd_rb, 1); | ||
414 | QWhatsThis::add(staticadd_rb, | ||
415 | i18n("Select this option when your computer has a\n" | ||
416 | "fixed internet address (IP). Most computers\n" | ||
417 | "don't have this, so you should probably select\n" | ||
418 | "dynamic IP addressing unless you know what you\n" | ||
419 | "are doing.")); | ||
420 | |||
421 | QWidget *ipWidget = new QWidget(box); | ||
422 | QGridLayout *ipLayout = new QGridLayout(ipWidget, 2, 2); | ||
423 | ipLayout->setSpacing( 2 );//KDialog::spacingHint()); | ||
424 | |||
425 | ipaddress_label = new QLabel(i18n("IP address:"), ipWidget); | ||
426 | QString tmp = i18n("If your computer has a permanent internet\n" | ||
427 | "address, you must supply your IP address here."); | ||
428 | ipLayout->addWidget(ipaddress_label, 0, 0); | ||
429 | |||
430 | ipaddress_l = new IPLineEdit(ipWidget); | ||
431 | ipLayout->addWidget(ipaddress_l, 0, 1); | ||
432 | |||
433 | QWhatsThis::add(ipaddress_label,tmp); | ||
434 | QWhatsThis::add(ipaddress_l,tmp); | ||
435 | |||
436 | sub_label = new QLabel(i18n("Subnet mask:"), ipWidget); | ||
437 | tmp = i18n("<p>If your computer has a static Internet address,\n" | ||
438 | "you must supply a network mask here. In almost\n" | ||
439 | "all cases this netmask will be <b>255.255.255.0</b>,\n" | ||
440 | "but your mileage may vary.\n" | ||
441 | "\n" | ||
442 | "If unsure, contact your Internet Service Provider"); | ||
443 | ipLayout->addWidget(sub_label, 1, 0); | ||
444 | |||
445 | subnetmask_l = new IPLineEdit(ipWidget); | ||
446 | ipLayout->addWidget(subnetmask_l, 1, 1); | ||
447 | |||
448 | QWhatsThis::add(sub_label,tmp); | ||
449 | QWhatsThis::add(subnetmask_l,tmp); | ||
450 | |||
451 | autoname = new QCheckBox(i18n("Auto-configure hostname from this IP"), parent); | ||
452 | autoname->setChecked(gpppdata.autoname()); | ||
453 | connect(autoname,SIGNAL(toggled(bool)), | ||
454 | this,SLOT(autoname_t(bool))); | ||
455 | |||
456 | QWhatsThis::add(autoname, | ||
457 | i18n("<p>Whenever you connect, this reconfigures\n" | ||
458 | "your hostname to match the IP address you\n" | ||
459 | "got from the PPP server. This may be useful\n" | ||
460 | "if you need to use a protocol which depends\n" | ||
461 | "on this information, but it can also cause several\n" | ||
462 | "<a href=\"kppp-7.html#autohostname\">problems</a>.\n" | ||
463 | "\n" | ||
464 | "Don't enable this unless you really need it.")); | ||
465 | |||
466 | topLayout->addWidget(box); | ||
467 | topLayout->addWidget(autoname); | ||
468 | topLayout->addStretch(); | ||
469 | |||
470 | //load info from gpppdata | ||
471 | if(!isnewaccount) { | ||
472 | if(gpppdata.ipaddr() == "0.0.0.0" && | ||
473 | gpppdata.subnetmask() == "0.0.0.0") { | ||
474 | dynamicadd_rb->setChecked(true); | ||
475 | hitIPSelect(0); | ||
476 | autoname->setChecked(gpppdata.autoname()); | ||
477 | } | ||
478 | else { | ||
479 | ipaddress_l->setText(gpppdata.ipaddr()); | ||
480 | subnetmask_l->setText(gpppdata.subnetmask()); | ||
481 | staticadd_rb->setChecked(true); | ||
482 | autoname->setChecked(false); | ||
483 | } | ||
484 | } | ||
485 | else { | ||
486 | dynamicadd_rb->setChecked(true); | ||
487 | hitIPSelect(0); | ||
488 | } | ||
489 | |||
490 | } | ||
491 | |||
492 | void IPWidget::autoname_t(bool on) { | ||
493 | static bool was_warned = false; | ||
494 | |||
495 | // big-fat warning when selecting the auto configure hostname option | ||
496 | if(on && !was_warned) { | ||
497 | QMessageBox::information(this, | ||
498 | i18n("Selecting this option might cause some weird " | ||
499 | "problems with the X-server and applications " | ||
500 | "while kppp is connected. Don't use it until " | ||
501 | "you know what you are doing!\n" | ||
502 | "For more information take a look at the " | ||
503 | "handbook (or help) in the section \"Frequently " | ||
504 | "asked questions\"."), | ||
505 | i18n("Warning")); | ||
506 | was_warned = true; | ||
507 | } | ||
508 | } | ||
509 | |||
510 | |||
511 | void IPWidget::save() { | ||
512 | if(dynamicadd_rb->isChecked()) { | ||
513 | gpppdata.setIpaddr("0.0.0.0"); | ||
514 | gpppdata.setSubnetmask("0.0.0.0"); | ||
515 | } else { | ||
516 | gpppdata.setIpaddr(ipaddress_l->text()); | ||
517 | gpppdata.setSubnetmask(subnetmask_l->text()); | ||
518 | } | ||
519 | gpppdata.setAutoname(autoname->isChecked()); | ||
520 | } | ||
521 | |||
522 | |||
523 | void IPWidget::hitIPSelect( int i ) { | ||
524 | if(i == 0) { | ||
525 | ipaddress_label->setEnabled(false); | ||
526 | sub_label->setEnabled(false); | ||
527 | ipaddress_l->setEnabled(false); | ||
528 | subnetmask_l->setEnabled(false); | ||
529 | } | ||
530 | else { | ||
531 | ipaddress_label->setEnabled(true); | ||
532 | sub_label->setEnabled(true); | ||
533 | ipaddress_l->setEnabled(true); | ||
534 | subnetmask_l->setEnabled(true); | ||
535 | } | ||
536 | } | ||
537 | |||
538 | |||
539 | |||
540 | DNSWidget::DNSWidget( QWidget *parent, bool isnewaccount, const char *name ) | ||
541 | : QWidget(parent, name) | ||
542 | { | ||
543 | // box = new QGroupBox(parent); | ||
544 | QGridLayout *tl = new QGridLayout(parent, 7, 2, 0 );//, KDialog::spacingHint()); | ||
545 | |||
546 | dnsdomain_label = new QLabel(i18n("Domain name:"), parent); | ||
547 | tl->addWidget(dnsdomain_label, 0, 0); | ||
548 | |||
549 | dnsdomain = new QLineEdit(parent); | ||
550 | dnsdomain->setMaxLength(DOMAIN_SIZE); | ||
551 | tl->addWidget(dnsdomain, 0, 1); | ||
552 | QString tmp = i18n("If you enter a domain name here, this domain\n" | ||
553 | "name is used for your computer while you are\n" | ||
554 | "connected. When the connection is closed, the\n" | ||
555 | "original domain name of your computer is\n" | ||
556 | "restored.\n" | ||
557 | "\n" | ||
558 | "If you leave this field blank, no changes are\n" | ||
559 | "made to the domain name."); | ||
560 | |||
561 | QWhatsThis::add(dnsdomain_label,tmp); | ||
562 | QWhatsThis::add(dnsdomain,tmp); | ||
563 | |||
564 | conf_label = new QLabel(i18n("Configuration:"), parent); | ||
565 | tl->addWidget(conf_label, 1, 0); | ||
566 | |||
567 | bg = new QButtonGroup("Group", this); | ||
568 | connect(bg, SIGNAL(clicked(int)), SLOT(DNS_Mode_Selected(int))); | ||
569 | bg->hide(); | ||
570 | |||
571 | autodns = new QRadioButton(i18n("Automatic"), parent); | ||
572 | bg->insert(autodns, 0); | ||
573 | tl->addWidget(autodns, 1, 1); | ||
574 | // no automatic DNS detection for pppd < 2.3.7 | ||
575 | if(!gpppdata.pppdVersionMin(2, 3, 7)) | ||
576 | autodns->setEnabled(false); | ||
577 | |||
578 | mandns = new QRadioButton(i18n("Manual"), parent); | ||
579 | bg->insert(mandns, 1); | ||
580 | tl->addWidget(mandns, 2, 1); | ||
581 | |||
582 | dns_label = new QLabel(i18n("DNS IP address:"), parent); | ||
583 | tl->addWidget(dns_label, 3, 0); | ||
584 | |||
585 | QHBoxLayout *l2 = new QHBoxLayout; | ||
586 | tl->addLayout(l2, 3, 1); | ||
587 | dnsipaddr = new IPLineEdit(parent); | ||
588 | connect(dnsipaddr, SIGNAL(returnPressed()), | ||
589 | SLOT(adddns())); | ||
590 | connect(dnsipaddr, SIGNAL(textChanged(const QString &)), | ||
591 | SLOT(DNS_Edit_Changed(const QString &))); | ||
592 | l2->addWidget(dnsipaddr, 1); | ||
593 | l2->addStretch(1); | ||
594 | tmp = i18n("<p>Allows you to specify a new DNS server to be\n" | ||
595 | "used while you are connected. When the\n" | ||
596 | "connection is closed, this DNS entry will be\n" | ||
597 | "removed again.\n" | ||
598 | "\n" | ||
599 | "To add a DNS server, type in the IP address of\n" | ||
600 | "the DNS server here and click on <b>Add</b>"); | ||
601 | |||
602 | QWhatsThis::add(dns_label, tmp); | ||
603 | QWhatsThis::add(dnsipaddr, tmp); | ||
604 | |||
605 | QHBoxLayout *l1 = new QHBoxLayout; | ||
606 | tl->addLayout(l1, 4, 1); | ||
607 | add = new QPushButton(i18n("Add"), parent); | ||
608 | connect(add, SIGNAL(clicked()), SLOT(adddns())); | ||
609 | int width = add->sizeHint().width(); | ||
610 | width = QMAX(width,60); | ||
611 | add->setMinimumWidth(width); | ||
612 | l1->addWidget(add); | ||
613 | l1->addStretch(1); | ||
614 | QWhatsThis::add(add, | ||
615 | i18n("Click this button to add the DNS server\n" | ||
616 | "specified in the field above. The entry\n" | ||
617 | "will then be added to the list below")); | ||
618 | |||
619 | remove = new QPushButton(i18n("Remove"), parent); | ||
620 | connect(remove, SIGNAL(clicked()), SLOT(removedns())); | ||
621 | width = remove->sizeHint().width(); | ||
622 | width = QMAX(width,60); | ||
623 | remove->setMinimumWidth(width); | ||
624 | l1->addWidget(remove); | ||
625 | QWhatsThis::add(remove, | ||
626 | i18n("Click this button to remove the selected DNS\n" | ||
627 | "server entry from the list below")); | ||
628 | |||
629 | servers_label = new QLabel(i18n("DNS address list:"), parent); | ||
630 | servers_label->setAlignment(AlignTop|AlignLeft); | ||
631 | tl->addWidget(servers_label, 5, 0); | ||
632 | |||
633 | dnsservers = new QListBox(parent); | ||
634 | dnsservers->setMinimumSize(150, 80); | ||
635 | connect(dnsservers, SIGNAL(highlighted(int)), | ||
636 | SLOT(DNS_Entry_Selected(int))); | ||
637 | tl->addWidget(dnsservers, 5, 1); | ||
638 | tmp = i18n("<p>This shows all defined DNS servers to use\n" | ||
639 | "while you are connected. Use the <b>Add</b> and\n" | ||
640 | "<b>Remove</b> buttons to modify the list"); | ||
641 | |||
642 | QWhatsThis::add(servers_label,tmp); | ||
643 | QWhatsThis::add(dnsservers,tmp); | ||
644 | |||
645 | exdnsdisabled_toggle = new QCheckBox(i18n( \ | ||
646 | "Disable existing DNS servers during connection"), | ||
647 | parent); | ||
648 | exdnsdisabled_toggle->setChecked(gpppdata.exDNSDisabled()); | ||
649 | tl->addMultiCellWidget(exdnsdisabled_toggle, 6, 6, 0, 1, AlignCenter); | ||
650 | QWhatsThis::add(exdnsdisabled_toggle, | ||
651 | i18n("<p>When this option is selected, all DNS\n" | ||
652 | "servers specified in <tt>/etc/resolv.conf</tt> are\n" | ||
653 | "temporary disabled while the dialup connection\n" | ||
654 | "is established. After the connection is\n" | ||
655 | "closed, the servers will be re-enabled\n" | ||
656 | "\n" | ||
657 | "Typically, there is no reason to use this\n" | ||
658 | "option, but it may become useful under \n" | ||
659 | "some circumstances.")); | ||
660 | |||
661 | |||
662 | // restore data if editing | ||
663 | if(!isnewaccount) { | ||
664 | dnsservers->insertStringList(gpppdata.dns()); | ||
665 | dnsdomain->setText(gpppdata.domain()); | ||
666 | } | ||
667 | |||
668 | int mode = gpppdata.autoDNS() ? 0 : 1; | ||
669 | bg->setButton(mode); | ||
670 | DNS_Mode_Selected(mode); | ||
671 | |||
672 | tl->activate(); | ||
673 | } | ||
674 | |||
675 | void DNSWidget::DNS_Edit_Changed(const QString &text) { | ||
676 | QRegExp r("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+"); | ||
677 | add->setEnabled(text.find(r) != -1); | ||
678 | } | ||
679 | |||
680 | void DNSWidget::DNS_Entry_Selected(int) { | ||
681 | remove->setEnabled(true); | ||
682 | } | ||
683 | |||
684 | void DNSWidget::DNS_Mode_Selected(int mode) { | ||
685 | bool on = (mode == 1); | ||
686 | dns_label->setEnabled(on); | ||
687 | servers_label->setEnabled(on); | ||
688 | dnsipaddr->setText(""); | ||
689 | dnsipaddr->setEnabled(on); | ||
690 | add->setEnabled(false); | ||
691 | remove->setEnabled(dnsservers->count()>0 && on); | ||
692 | dnsservers->clearSelection(); | ||
693 | dnsservers->setEnabled(on); | ||
694 | dnsservers->triggerUpdate(false); | ||
695 | } | ||
696 | |||
697 | void DNSWidget::save() { | ||
698 | gpppdata.setAutoDNS(bg->id(bg->selected()) == 0); | ||
699 | QStringList serverlist; | ||
700 | for(uint i=0; i < dnsservers->count(); i++) | ||
701 | serverlist.append(dnsservers->text(i)); | ||
702 | gpppdata.setDns(serverlist); | ||
703 | |||
704 | // strip leading dot | ||
705 | QString s(dnsdomain->text()); | ||
706 | if(s.left(1) == ".") | ||
707 | gpppdata.setDomain(s.mid(1)); | ||
708 | else | ||
709 | gpppdata.setDomain(dnsdomain->text()); | ||
710 | |||
711 | gpppdata.setExDNSDisabled(exdnsdisabled_toggle->isChecked()); | ||
712 | } | ||
713 | |||
714 | |||
715 | void DNSWidget::adddns() { | ||
716 | if(dnsservers->count() < MAX_DNS_ENTRIES) { | ||
717 | dnsservers->insertItem(dnsipaddr->text()); | ||
718 | dnsipaddr->setText(""); | ||
719 | } | ||
720 | } | ||
721 | |||
722 | |||
723 | void DNSWidget::removedns() { | ||
724 | int i; | ||
725 | i = dnsservers->currentItem(); | ||
726 | if(i != -1) | ||
727 | dnsservers->removeItem(i); | ||
728 | remove->setEnabled(dnsservers->count()>0); | ||
729 | } | ||
730 | |||
731 | |||
732 | // | ||
733 | // GatewayWidget | ||
734 | // | ||
735 | GatewayWidget::GatewayWidget( QWidget *parent, bool isnewaccount, const char *name ) | ||
736 | : QWidget(parent, name) | ||
737 | { | ||
738 | QVBoxLayout *topLayout = new QVBoxLayout(parent); | ||
739 | topLayout->setSpacing( 2 );//KDialog::spacingHint()); | ||
740 | |||
741 | box = new QVGroupBox(i18n("Configuration"), parent); | ||
742 | // box->setInsideSpacing( 2 );//KDialog::spacingHint()); | ||
743 | |||
744 | rb = new QButtonGroup(parent); | ||
745 | rb->hide(); | ||
746 | connect(rb, SIGNAL(clicked(int)), SLOT(hitGatewaySelect(int))); | ||
747 | |||
748 | defaultgateway = new QRadioButton(box); | ||
749 | defaultgateway->setText(i18n("Default gateway")); | ||
750 | rb->insert(defaultgateway, 0); | ||
751 | QWhatsThis::add(defaultgateway, | ||
752 | i18n("This makes the PPP peer computer (the computer\n" | ||
753 | "you are connected to with your modem) to act as\n" | ||
754 | "a gateway. Your computer will send all packets not\n" | ||
755 | "going to a computer inside your local net to this\n" | ||
756 | "computer, which will route these packets.\n" | ||
757 | "\n" | ||
758 | "This is the default for most ISPs, so you should\n" | ||
759 | "probably leave this option on.")); | ||
760 | |||
761 | |||
762 | staticgateway = new QRadioButton(box); | ||
763 | staticgateway->setText(i18n("Static gateway")); | ||
764 | rb->insert(staticgateway, 1); | ||
765 | QWhatsThis::add(staticgateway, | ||
766 | i18n("<p>Allows you to specify which computer you want\n" | ||
767 | "to use as gateway (see <i>Default Gateway</i> above)")); | ||
768 | |||
769 | QHBox *gateBox = new QHBox(box); | ||
770 | gate_label = new QLabel(i18n("Gateway IP address:"), gateBox); | ||
771 | gatewayaddr = new IPLineEdit(gateBox); | ||
772 | |||
773 | defaultroute = new QCheckBox(i18n("Assign the default route to this gateway"), | ||
774 | parent); | ||
775 | QWhatsThis::add(defaultroute, | ||
776 | i18n("If this option is enabled, all packets not\n" | ||
777 | "going to the local net are routed through\n" | ||
778 | "the PPP connection.\n" | ||
779 | "\n" | ||
780 | "Normally, you should turn this on")); | ||
781 | |||
782 | topLayout->addWidget(box); | ||
783 | topLayout->addWidget(defaultroute); | ||
784 | topLayout->addStretch(); | ||
785 | |||
786 | //load info from gpppdata | ||
787 | if(!isnewaccount) { | ||
788 | if(gpppdata.gateway() == "0.0.0.0") { | ||
789 | defaultgateway->setChecked(true); | ||
790 | hitGatewaySelect(0); | ||
791 | } | ||
792 | else { | ||
793 | gatewayaddr->setText(gpppdata.gateway()); | ||
794 | staticgateway->setChecked(true); | ||
795 | } | ||
796 | defaultroute->setChecked(gpppdata.defaultroute()); | ||
797 | } | ||
798 | else { | ||
799 | defaultgateway->setChecked(true); | ||
800 | hitGatewaySelect(0); | ||
801 | defaultroute->setChecked(true); | ||
802 | } | ||
803 | } | ||
804 | |||
805 | void GatewayWidget::save() { | ||
806 | gpppdata.setGateway(gatewayaddr->text()); | ||
807 | gpppdata.setDefaultroute(defaultroute->isChecked()); | ||
808 | } | ||
809 | |||
810 | |||
811 | void GatewayWidget::hitGatewaySelect( int i ) { | ||
812 | if(i == 0) { | ||
813 | gatewayaddr->setText("0.0.0.0"); | ||
814 | gatewayaddr->setEnabled(false); | ||
815 | gate_label->setEnabled(false); | ||
816 | } | ||
817 | else { | ||
818 | gatewayaddr->setEnabled(true); | ||
819 | gatewayaddr->setText(""); | ||
820 | gate_label->setEnabled(true); | ||
821 | } | ||
822 | } | ||
823 | |||
824 | |||
825 | |||
826 | ScriptWidget::ScriptWidget( QWidget *parent, bool isnewaccount, const char *name ) | ||
827 | : QWidget(parent, name) | ||
828 | { | ||
829 | QVBoxLayout *tl = new QVBoxLayout(parent, 0 );//, KDialog::spacingHint()); | ||
830 | se = new ScriptEdit(parent); | ||
831 | connect(se, SIGNAL(returnPressed()), SLOT(addButton())); | ||
832 | tl->addWidget(se); | ||
833 | |||
834 | // insert equal-sized buttons | ||
835 | QButtonGroup *bbox = new QButtonGroup(parent); | ||
836 | add = new QPushButton( bbox, i18n("Add") ); | ||
837 | bbox->insert(add); | ||
838 | connect(add, SIGNAL(clicked()), SLOT(addButton())); | ||
839 | // bbox->addStretch(1); | ||
840 | insert = new QPushButton( bbox, i18n("Insert") ); | ||
841 | bbox->insert(insert); | ||
842 | connect(insert, SIGNAL(clicked()), SLOT(insertButton())); | ||
843 | // bbox->addStretch(1); | ||
844 | remove = new QPushButton( bbox, i18n("Remove") ); | ||
845 | bbox->insert(remove); | ||
846 | connect(remove, SIGNAL(clicked()), SLOT(removeButton())); | ||
847 | bbox->layout(); | ||
848 | tl->addWidget(bbox); | ||
849 | |||
850 | QHBoxLayout *l12 = new QHBoxLayout(0); | ||
851 | tl->addLayout(l12); | ||
852 | stl = new QListBox(parent); | ||
853 | stl->setVScrollBarMode( QScrollView::AlwaysOff ); | ||
854 | connect(stl, SIGNAL(highlighted(int)), SLOT(stlhighlighted(int))); | ||
855 | stl->setMinimumSize(QSize(70, 140)); | ||
856 | |||
857 | sl = new QListBox(parent); | ||
858 | sl->setVScrollBarMode( QScrollView::AlwaysOff ); | ||
859 | connect(sl, SIGNAL(highlighted(int)), SLOT(slhighlighted(int))); | ||
860 | sl->setMinimumSize(QSize(150, 140)); | ||
861 | |||
862 | slb = new QScrollBar(parent); | ||
863 | slb->setFixedWidth(slb->sizeHint().width()); | ||
864 | connect(slb, SIGNAL(valueChanged(int)), SLOT(scrolling(int))); | ||
865 | |||
866 | l12->addWidget(stl, 1); | ||
867 | l12->addWidget(sl, 3); | ||
868 | l12->addWidget(slb, 0); | ||
869 | |||
870 | //load data from gpppdata | ||
871 | if(!isnewaccount) { | ||
872 | QStringList &comlist = gpppdata.scriptType(); | ||
873 | QStringList &arglist = gpppdata.script(); | ||
874 | QStringList::Iterator itcom = comlist.begin(); | ||
875 | QStringList::Iterator itarg = arglist.begin(); | ||
876 | |||
877 | for ( ; | ||
878 | itcom != comlist.end() && itarg != arglist.end(); | ||
879 | ++itcom, ++itarg ) | ||
880 | { | ||
881 | stl->insertItem(*itcom); | ||
882 | sl->insertItem(*itarg); | ||
883 | } | ||
884 | } | ||
885 | |||
886 | insert->setEnabled(false); | ||
887 | remove->setEnabled(false); | ||
888 | adjustScrollBar(); | ||
889 | tl->activate(); | ||
890 | } | ||
891 | |||
892 | bool ScriptWidget::check() { | ||
893 | uint lstart = 0; | ||
894 | uint lend = 0; | ||
895 | uint errcnt = 0; | ||
896 | |||
897 | if(sl->count() > 0) { | ||
898 | for( uint i=0; i <= sl->count()-1; i++) { | ||
899 | if(stl->text(i) == "LoopStart") { | ||
900 | lstart++; | ||
901 | } | ||
902 | if (stl->text(i) == "LoopEnd") { | ||
903 | lend++; | ||
904 | } | ||
905 | if ( lend > lstart ) errcnt++; | ||
906 | } | ||
907 | return ( (errcnt == 0 ) && (lstart == lend) ); | ||
908 | } | ||
909 | return true; | ||
910 | } | ||
911 | |||
912 | |||
913 | void ScriptWidget::save() { | ||
914 | QStringList typelist, arglist; | ||
915 | for(uint i=0; i < sl->count(); i++) { | ||
916 | typelist.append(stl->text(i)); | ||
917 | arglist.append(sl->text(i)); | ||
918 | } | ||
919 | gpppdata.setScriptType(typelist); | ||
920 | gpppdata.setScript(arglist); | ||
921 | } | ||
922 | |||
923 | |||
924 | |||
925 | void ScriptWidget::adjustScrollBar() { | ||
926 | if((int)sl->count() <= sl->numItemsVisible()) | ||
927 | slb->setRange(0, 0); | ||
928 | else | ||
929 | slb->setRange(0, (sl->count() - sl->numItemsVisible())+1); | ||
930 | } | ||
931 | |||
932 | |||
933 | void ScriptWidget::scrolling(int i) { | ||
934 | sl->setTopItem(i); | ||
935 | stl->setTopItem(i); | ||
936 | } | ||
937 | |||
938 | |||
939 | void ScriptWidget::slhighlighted(int i) { | ||
940 | insert->setEnabled(true); | ||
941 | remove->setEnabled(true); | ||
942 | stl->setCurrentItem(i); | ||
943 | } | ||
944 | |||
945 | |||
946 | void ScriptWidget::stlhighlighted(int i) { | ||
947 | insert->setEnabled(true); | ||
948 | remove->setEnabled(true); | ||
949 | sl->setCurrentItem(i); | ||
950 | } | ||
951 | |||
952 | |||
953 | void ScriptWidget::addButton() { | ||
954 | //don't allow more than the maximum script entries | ||
955 | if(sl->count() == MAX_SCRIPT_ENTRIES-1) | ||
956 | return; | ||
957 | |||
958 | switch(se->type()) { | ||
959 | case ScriptEdit::Expect: | ||
960 | stl->insertItem("Expect"); | ||
961 | sl->insertItem(se->text()); | ||
962 | break; | ||
963 | |||
964 | case ScriptEdit::Send: | ||
965 | stl->insertItem("Send"); | ||
966 | sl->insertItem(se->text()); | ||
967 | break; | ||
968 | |||
969 | case ScriptEdit::SendNoEcho: | ||
970 | stl->insertItem("SendNoEcho"); | ||
971 | sl->insertItem(se->text()); | ||
972 | break; | ||
973 | |||
974 | case ScriptEdit::Pause: | ||
975 | stl->insertItem("Pause"); | ||
976 | sl->insertItem(se->text()); | ||
977 | break; | ||
978 | |||
979 | case ScriptEdit::Hangup: | ||
980 | stl->insertItem("Hangup"); | ||
981 | sl->insertItem(""); | ||
982 | break; | ||
983 | |||
984 | case ScriptEdit::Answer: | ||
985 | stl->insertItem("Answer"); | ||
986 | sl->insertItem(""); | ||
987 | break; | ||
988 | |||
989 | case ScriptEdit::Timeout: | ||
990 | stl->insertItem("Timeout"); | ||
991 | sl->insertItem(se->text()); | ||
992 | break; | ||
993 | |||
994 | case ScriptEdit::Password: | ||
995 | stl->insertItem("Password"); | ||
996 | sl->insertItem(se->text()); | ||
997 | break; | ||
998 | |||
999 | case ScriptEdit::ID: | ||
1000 | stl->insertItem("ID"); | ||
1001 | sl->insertItem(se->text()); | ||
1002 | break; | ||
1003 | |||
1004 | case ScriptEdit::Prompt: | ||
1005 | stl->insertItem("Prompt"); | ||
1006 | sl->insertItem(se->text()); | ||
1007 | break; | ||
1008 | |||
1009 | case ScriptEdit::PWPrompt: | ||
1010 | stl->insertItem("PWPrompt"); | ||
1011 | sl->insertItem(se->text()); | ||
1012 | break; | ||
1013 | |||
1014 | case ScriptEdit::LoopStart: | ||
1015 | stl->insertItem("LoopStart"); | ||
1016 | sl->insertItem(se->text()); | ||
1017 | break; | ||
1018 | |||
1019 | case ScriptEdit::LoopEnd: | ||
1020 | stl->insertItem("LoopEnd"); | ||
1021 | sl->insertItem(se->text()); | ||
1022 | break; | ||
1023 | |||
1024 | case ScriptEdit::Scan: | ||
1025 | stl->insertItem("Scan"); | ||
1026 | sl->insertItem(se->text()); | ||
1027 | break; | ||
1028 | |||
1029 | case ScriptEdit::Save: | ||
1030 | stl->insertItem("Save"); | ||
1031 | sl->insertItem(se->text()); | ||
1032 | break; | ||
1033 | |||
1034 | default: | ||
1035 | break; | ||
1036 | } | ||
1037 | |||
1038 | //get the scrollbar adjusted, and scroll the list so we can see what | ||
1039 | //we're adding to | ||
1040 | adjustScrollBar(); | ||
1041 | slb->setValue(slb->maxValue()); | ||
1042 | |||
1043 | //clear the text in the entry box | ||
1044 | se->setText(""); | ||
1045 | } | ||
1046 | |||
1047 | |||
1048 | void ScriptWidget::insertButton() { | ||
1049 | //exit if there is no highlighted item, or we've reached the | ||
1050 | //maximum entries in the script list | ||
1051 | if(sl->currentItem() < 0 || (sl->count() == MAX_SCRIPT_ENTRIES-1)) | ||
1052 | return; | ||
1053 | |||
1054 | switch(se->type()) { | ||
1055 | case ScriptEdit::Expect: | ||
1056 | stl->insertItem("Expect", stl->currentItem()); | ||
1057 | sl->insertItem(se->text(), sl->currentItem()); | ||
1058 | break; | ||
1059 | |||
1060 | case ScriptEdit::Send: | ||
1061 | stl->insertItem("Send", stl->currentItem()); | ||
1062 | sl->insertItem(se->text(), sl->currentItem()); | ||
1063 | break; | ||
1064 | |||
1065 | case ScriptEdit::SendNoEcho: | ||
1066 | stl->insertItem("SendNoEcho", stl->currentItem()); | ||
1067 | sl->insertItem(se->text(), sl->currentItem()); | ||
1068 | break; | ||
1069 | |||
1070 | case ScriptEdit::Pause: | ||
1071 | stl->insertItem("Pause", stl->currentItem()); | ||
1072 | sl->insertItem(se->text(), sl->currentItem()); | ||
1073 | break; | ||
1074 | |||
1075 | case ScriptEdit::Hangup: | ||
1076 | stl->insertItem("Hangup", stl->currentItem()); | ||
1077 | sl->insertItem("", sl->currentItem()); | ||
1078 | break; | ||
1079 | |||
1080 | case ScriptEdit::Answer: | ||
1081 | stl->insertItem("Answer", stl->currentItem()); | ||
1082 | sl->insertItem("", sl->currentItem()); | ||
1083 | break; | ||
1084 | |||
1085 | case ScriptEdit::Timeout: | ||
1086 | stl->insertItem("Timeout", stl->currentItem()); | ||
1087 | sl->insertItem(se->text(), sl->currentItem()); | ||
1088 | break; | ||
1089 | |||
1090 | case ScriptEdit::Password: | ||
1091 | stl->insertItem("Password", stl->currentItem()); | ||
1092 | sl->insertItem(se->text(), sl->currentItem()); | ||
1093 | break; | ||
1094 | |||
1095 | case ScriptEdit::ID: | ||
1096 | stl->insertItem("ID", stl->currentItem()); | ||
1097 | sl->insertItem(se->text(), sl->currentItem()); | ||
1098 | break; | ||
1099 | |||
1100 | case ScriptEdit::Prompt: | ||
1101 | stl->insertItem("Prompt", stl->currentItem()); | ||
1102 | sl->insertItem(se->text(), sl->currentItem()); | ||
1103 | break; | ||
1104 | |||
1105 | case ScriptEdit::PWPrompt: | ||
1106 | stl->insertItem("PWPrompt", stl->currentItem()); | ||
1107 | sl->insertItem(se->text(), sl->currentItem()); | ||
1108 | break; | ||
1109 | |||
1110 | case ScriptEdit::LoopStart: | ||
1111 | stl->insertItem("LoopStart", stl->currentItem()); | ||
1112 | sl->insertItem(se->text(), sl->currentItem()); | ||
1113 | break; | ||
1114 | |||
1115 | case ScriptEdit::LoopEnd: | ||
1116 | stl->insertItem("LoopEnd", stl->currentItem()); | ||
1117 | sl->insertItem(se->text(), sl->currentItem()); | ||
1118 | break; | ||
1119 | |||
1120 | case ScriptEdit::Scan: | ||
1121 | stl->insertItem("Scan", stl->currentItem()); | ||
1122 | sl->insertItem(se->text(), sl->currentItem()); | ||
1123 | break; | ||
1124 | |||
1125 | case ScriptEdit::Save: | ||
1126 | stl->insertItem("Save", stl->currentItem()); | ||
1127 | sl->insertItem(se->text(), sl->currentItem()); | ||
1128 | break; | ||
1129 | |||
1130 | default: | ||
1131 | break; | ||
1132 | } | ||
1133 | adjustScrollBar(); | ||
1134 | se->setText(""); | ||
1135 | } | ||
1136 | |||
1137 | |||
1138 | void ScriptWidget::removeButton() { | ||
1139 | if(sl->currentItem() >= 0) { | ||
1140 | int stlc = stl->currentItem(); | ||
1141 | sl->removeItem(sl->currentItem()); | ||
1142 | stl->removeItem(stlc); | ||
1143 | adjustScrollBar(); | ||
1144 | insert->setEnabled(sl->currentItem() != -1); | ||
1145 | remove->setEnabled(sl->currentItem() != -1); | ||
1146 | } | ||
1147 | } | ||
1148 | |||
1149 | |||
1150 | |||
1151 | ///////////////////////////////////////////////////////////////////////////// | ||
1152 | // | ||
1153 | // Used to specify a new phone number | ||
1154 | // | ||
1155 | ///////////////////////////////////////////////////////////////////////////// | ||
1156 | PhoneNumberDialog::PhoneNumberDialog(QWidget *parent) | ||
1157 | : QDialog(parent, 0, true ) { | ||
1158 | setCaption( i18n("Add Phone Number") ); | ||
1159 | // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); | ||
1160 | |||
1161 | QHBox *hbox = new QHBox(this); | ||
1162 | // setMainWidget(hbox); | ||
1163 | |||
1164 | hbox->setSpacing( 2 );//KDialog::spacingHint()); | ||
1165 | |||
1166 | new QLabel(i18n("Enter a phone number:"), hbox); | ||
1167 | |||
1168 | le = newLineEdit(14, hbox); | ||
1169 | le->setMinimumWidth(125); | ||
1170 | |||
1171 | connect(le, SIGNAL(textChanged(const QString &)), | ||
1172 | this, SLOT(textChanged(const QString &))); | ||
1173 | |||
1174 | le->setFocus(); | ||
1175 | textChanged(""); | ||
1176 | |||
1177 | // enableButtonSeparator(true); | ||
1178 | } | ||
1179 | |||
1180 | |||
1181 | QString PhoneNumberDialog::phoneNumber() { | ||
1182 | QString s = le->text(); | ||
1183 | |||
1184 | return s; | ||
1185 | } | ||
1186 | |||
1187 | |||
1188 | void PhoneNumberDialog::textChanged(const QString &s) { | ||
1189 | // enableButtonOK(s.length() > 0); | ||
1190 | } | ||
1191 | |||
1192 | |||
1193 | //#include "edit.moc" | ||
diff --git a/noncore/settings/networksettings/ppp/edit.h b/noncore/settings/networksettings/ppp/edit.h new file mode 100644 index 0000000..cd0161f --- a/dev/null +++ b/noncore/settings/networksettings/ppp/edit.h | |||
@@ -0,0 +1,251 @@ | |||
1 | /* -*- C++ -*- | ||
2 | * | ||
3 | * kPPP: A pppd Front End for the KDE project | ||
4 | * | ||
5 | * $Id$ | ||
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 | * | ||
13 | * This library is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU Library General Public | ||
15 | * License as published by the Free Software Foundation; either | ||
16 | * version 2 of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This library is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
21 | * Library General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU Library General Public | ||
24 | * License along with this program; if not, write to the Free | ||
25 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
26 | */ | ||
27 | |||
28 | |||
29 | #ifndef _EDIT_H_ | ||
30 | #define _EDIT_H_ | ||
31 | |||
32 | #include <qdialog.h> | ||
33 | #include <qpushbutton.h> | ||
34 | #include <qgroupbox.h> | ||
35 | #include <qvgroupbox.h> | ||
36 | #include <qscrollbar.h> | ||
37 | #include <qcombobox.h> | ||
38 | #include <qlineedit.h> | ||
39 | #include <qlistbox.h> | ||
40 | #include <qradiobutton.h> | ||
41 | #include <qbuttongroup.h> | ||
42 | #include <qcheckbox.h> | ||
43 | #include <qlabel.h> | ||
44 | //#include <kdialogbase.h> | ||
45 | #include "scriptedit.h" | ||
46 | #include "kpppconfig.h" | ||
47 | #include "pppdargs.h" | ||
48 | |||
49 | class IPLineEdit; | ||
50 | |||
51 | class DialWidget : public QWidget { | ||
52 | Q_OBJECT | ||
53 | public: | ||
54 | DialWidget( QWidget *parent=0, bool isnewaccount = true, const char *name=0 ); | ||
55 | ~DialWidget() {} | ||
56 | |||
57 | public slots: | ||
58 | bool save(); | ||
59 | void pppdargsbutton(); | ||
60 | void numbersChanged(); | ||
61 | void selectionChanged(int); | ||
62 | void addNumber(); | ||
63 | void delNumber(); | ||
64 | void upNumber(); | ||
65 | void downNumber(); | ||
66 | |||
67 | private: | ||
68 | QLineEdit *connectname_l; | ||
69 | QLabel *connect_label; | ||
70 | QLabel *number_label; | ||
71 | QPushButton *pppdargs; | ||
72 | QComboBox *auth; | ||
73 | QLabel *auth_l; | ||
74 | QCheckBox *store_password; | ||
75 | |||
76 | // for the phonenumber selection | ||
77 | QPushButton *add, *del, *up, *down; | ||
78 | QListBox *numbers; | ||
79 | }; | ||
80 | |||
81 | |||
82 | ///////////////////////////////////////////////////////////////////////////// | ||
83 | // | ||
84 | // tab-window to select what to execute when | ||
85 | // | ||
86 | ///////////////////////////////////////////////////////////////////////////// | ||
87 | class ExecWidget : public QWidget { | ||
88 | Q_OBJECT | ||
89 | public: | ||
90 | ExecWidget(QWidget *parent=0, bool isnewaccount=true, const char *name=0); | ||
91 | |||
92 | public slots: | ||
93 | bool save(); | ||
94 | |||
95 | private: | ||
96 | QLineEdit *before_connect; | ||
97 | QLabel *before_connect_l; | ||
98 | |||
99 | QLineEdit *command; | ||
100 | QLabel *command_label; | ||
101 | |||
102 | QLineEdit *predisconnect; | ||
103 | QLabel *predisconnect_label; | ||
104 | |||
105 | QLineEdit *discommand; | ||
106 | QLabel *discommand_label; | ||
107 | }; | ||
108 | |||
109 | |||
110 | class IPWidget : public QWidget { | ||
111 | Q_OBJECT | ||
112 | public: | ||
113 | IPWidget( QWidget *parent=0, bool isnewaccount = true, const char *name=0 ); | ||
114 | ~IPWidget() {} | ||
115 | |||
116 | public slots: | ||
117 | void save(); | ||
118 | |||
119 | protected slots: | ||
120 | void hitIPSelect( int ); | ||
121 | void autoname_t(bool on); | ||
122 | |||
123 | private: | ||
124 | QLabel *ipaddress_label; | ||
125 | QLabel *sub_label; | ||
126 | QGroupBox *box1; | ||
127 | QVGroupBox *box; | ||
128 | |||
129 | QButtonGroup *rb; | ||
130 | QRadioButton *dynamicadd_rb; | ||
131 | QRadioButton *staticadd_rb; | ||
132 | |||
133 | IPLineEdit *ipaddress_l; | ||
134 | IPLineEdit *subnetmask_l; | ||
135 | |||
136 | QCheckBox *autoname; | ||
137 | }; | ||
138 | |||
139 | |||
140 | class DNSWidget : public QWidget { | ||
141 | Q_OBJECT | ||
142 | public: | ||
143 | DNSWidget( QWidget *parent=0, bool isnewaccount = true, const char *name=0 ); | ||
144 | ~DNSWidget() {} | ||
145 | |||
146 | public slots: | ||
147 | void save(); | ||
148 | |||
149 | protected slots: | ||
150 | void adddns(); | ||
151 | void removedns(); | ||
152 | void DNS_Edit_Changed(const QString &); | ||
153 | void DNS_Entry_Selected(int); | ||
154 | void DNS_Mode_Selected(int); | ||
155 | |||
156 | private: | ||
157 | QLabel *conf_label; | ||
158 | QButtonGroup *bg; | ||
159 | QRadioButton *autodns, *mandns; | ||
160 | QLabel *dns_label; | ||
161 | QLabel *servers_label; | ||
162 | IPLineEdit *dnsipaddr; | ||
163 | QPushButton *add; | ||
164 | QPushButton *remove; | ||
165 | QListBox *dnsservers; | ||
166 | QLineEdit *dnsdomain; | ||
167 | QLabel *dnsdomain_label; | ||
168 | QCheckBox *exdnsdisabled_toggle; | ||
169 | }; | ||
170 | |||
171 | |||
172 | class GatewayWidget : public QWidget { | ||
173 | Q_OBJECT | ||
174 | public: | ||
175 | GatewayWidget( QWidget *parent=0, bool isnewaccount = true, const char *name=0 ); | ||
176 | ~GatewayWidget() {} | ||
177 | |||
178 | public slots: | ||
179 | void save(); | ||
180 | |||
181 | private slots: | ||
182 | void hitGatewaySelect( int ); | ||
183 | |||
184 | private: | ||
185 | QGroupBox *box; | ||
186 | QLabel *gate_label; | ||
187 | QGroupBox *box1; | ||
188 | QButtonGroup *rb; | ||
189 | QRadioButton *defaultgateway; | ||
190 | QRadioButton *staticgateway; | ||
191 | IPLineEdit *gatewayaddr; | ||
192 | QCheckBox *defaultroute; | ||
193 | }; | ||
194 | |||
195 | |||
196 | class ScriptWidget : public QWidget { | ||
197 | Q_OBJECT | ||
198 | public: | ||
199 | ScriptWidget( QWidget *parent=0, bool isnewaccount = true, const char *name=0 ); | ||
200 | ~ScriptWidget() {} | ||
201 | |||
202 | public slots: | ||
203 | void save(); | ||
204 | bool check(); | ||
205 | |||
206 | private slots: | ||
207 | void addButton(); | ||
208 | void insertButton(); | ||
209 | void removeButton(); | ||
210 | |||
211 | //signals linked to the scroll bar | ||
212 | void scrolling(int); | ||
213 | |||
214 | //signals to keep the two listboxes highlighted in sync | ||
215 | void slhighlighted(int); | ||
216 | void stlhighlighted(int); | ||
217 | |||
218 | private: | ||
219 | void adjustScrollBar(); | ||
220 | |||
221 | ScriptEdit *se; | ||
222 | QPushButton *add; | ||
223 | QPushButton *remove; | ||
224 | QPushButton *insert; | ||
225 | QListBox *sl, *stl; | ||
226 | |||
227 | QScrollBar *slb; | ||
228 | }; | ||
229 | |||
230 | |||
231 | ///////////////////////////////////////////////////////////////////////////// | ||
232 | // | ||
233 | // Used to specify a new phone number | ||
234 | // | ||
235 | ///////////////////////////////////////////////////////////////////////////// | ||
236 | class PhoneNumberDialog : public QDialog { | ||
237 | Q_OBJECT | ||
238 | public: | ||
239 | PhoneNumberDialog(QWidget *parent = 0); | ||
240 | |||
241 | QString phoneNumber(); | ||
242 | |||
243 | private slots: | ||
244 | void textChanged(const QString &); | ||
245 | |||
246 | private: | ||
247 | QLineEdit *le; | ||
248 | }; | ||
249 | |||
250 | |||
251 | #endif | ||
diff --git a/noncore/settings/networksettings/ppp/general.cpp b/noncore/settings/networksettings/ppp/general.cpp new file mode 100644 index 0000000..f803628 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/general.cpp | |||
@@ -0,0 +1,421 @@ | |||
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 <termios.h> | ||
28 | #include <string.h> | ||
29 | #include <qwhatsthis.h> | ||
30 | |||
31 | #include "knuminput.h" | ||
32 | #include <qslider.h> | ||
33 | #include <qlayout.h> | ||
34 | #include "general.h" | ||
35 | //#include "version.h" | ||
36 | //#include "miniterm.h" | ||
37 | #include "modeminfo.h" | ||
38 | #include "modemcmds.h" | ||
39 | #include "devices.h" | ||
40 | #include "pppdata.h" | ||
41 | //#include <klocale.h> | ||
42 | #define i18n QObject::tr | ||
43 | |||
44 | |||
45 | |||
46 | ModemWidget::ModemWidget( QWidget *parent, const char *name) | ||
47 | : QWidget(parent, name) | ||
48 | { | ||
49 | int k; | ||
50 | |||
51 | QGridLayout *tl = new QGridLayout(this, 8, 2, 0 );//, KDialog::spacingHint()); | ||
52 | |||
53 | label1 = new QLabel(i18n("Modem de&vice:"), this); | ||
54 | tl->addWidget(label1, 0, 0); | ||
55 | |||
56 | modemdevice = new QComboBox(false, this); | ||
57 | label1->setBuddy(modemdevice); | ||
58 | |||
59 | for(k = 0; devices[k]; k++) | ||
60 | modemdevice->insertItem(devices[k]); | ||
61 | |||
62 | tl->addWidget(modemdevice, 0, 1); | ||
63 | connect(modemdevice, SIGNAL(activated(int)), | ||
64 | SLOT(setmodemdc(int))); | ||
65 | QString tmp = i18n("This specifies the serial port your modem is attached \n" | ||
66 | "to. On Linux/x86, typically this is either /dev/ttyS0 \n" | ||
67 | "(COM1 under DOS) or /dev/ttyS1 (COM2 under DOS).\n" | ||
68 | "\n" | ||
69 | "If you have an internal ISDN card with AT command\n" | ||
70 | "emulation (most cards under Linux support this), you\n" | ||
71 | "should select one of the /dev/ttyIx devices."); | ||
72 | |||
73 | QWhatsThis::add(label1,tmp); | ||
74 | QWhatsThis::add(modemdevice,tmp); | ||
75 | |||
76 | |||
77 | label2 = new QLabel(i18n("&Flow control:"), this); | ||
78 | tl->addWidget(label2, 1, 0); | ||
79 | |||
80 | flowcontrol = new QComboBox(false, this); | ||
81 | label2->setBuddy(flowcontrol); | ||
82 | flowcontrol->insertItem(i18n("Hardware [CRTSCTS]")); | ||
83 | flowcontrol->insertItem(i18n("Software [XON/XOFF]")); | ||
84 | flowcontrol->insertItem(i18n("None")); | ||
85 | tl->addWidget(flowcontrol, 1, 1); | ||
86 | connect(flowcontrol, SIGNAL(activated(int)), | ||
87 | SLOT(setflowcontrol(int))); | ||
88 | |||
89 | tmp = i18n("<p>Specifies how the serial port and modem\n" | ||
90 | "communicate. You should not change this unless\n" | ||
91 | "you know what you are doing.\n" | ||
92 | "\n" | ||
93 | "<b>Default</b>: CRTSCTS"); | ||
94 | |||
95 | QWhatsThis::add(label2,tmp); | ||
96 | QWhatsThis::add(flowcontrol,tmp); | ||
97 | |||
98 | labelenter = new QLabel(i18n("&Line termination:"), this); | ||
99 | tl->addWidget(labelenter, 2, 0); | ||
100 | |||
101 | enter = new QComboBox(false, this); | ||
102 | labelenter->setBuddy(enter); | ||
103 | enter->insertItem("CR"); | ||
104 | enter->insertItem("LF"); | ||
105 | enter->insertItem("CR/LF"); | ||
106 | tl->addWidget(enter, 2, 1); | ||
107 | connect(enter, SIGNAL(activated(int)), SLOT(setenter(int))); | ||
108 | tmp = i18n("<p>Specifies how AT commands are sent to your\n" | ||
109 | "modem. Most modems will work fine with the\n" | ||
110 | "default <i>CR/LF</i>. If your modem does not react\n" | ||
111 | "to the init string, you should try different\n" | ||
112 | "settings here\n" | ||
113 | "\n" | ||
114 | "<b>Default</b>: CR/LF"); | ||
115 | |||
116 | QWhatsThis::add(labelenter,tmp); | ||
117 | QWhatsThis::add(enter, tmp); | ||
118 | |||
119 | baud_label = new QLabel(i18n("Co&nnection speed:"), this); | ||
120 | tl->addWidget(baud_label, 3, 0); | ||
121 | baud_c = new QComboBox(this); | ||
122 | baud_label->setBuddy(baud_c); | ||
123 | |||
124 | static const char *baudrates[] = { | ||
125 | |||
126 | #ifdef B460800 | ||
127 | "460800", | ||
128 | #endif | ||
129 | |||
130 | #ifdef B230400 | ||
131 | "230400", | ||
132 | #endif | ||
133 | |||
134 | #ifdef B115200 | ||
135 | "115200", | ||
136 | #endif | ||
137 | |||
138 | #ifdef B57600 | ||
139 | "57600", | ||
140 | #endif | ||
141 | |||
142 | "38400", | ||
143 | "19200", | ||
144 | "9600", | ||
145 | "2400", | ||
146 | 0}; | ||
147 | |||
148 | for(k = 0; baudrates[k]; k++) | ||
149 | baud_c->insertItem(baudrates[k]); | ||
150 | |||
151 | baud_c->setCurrentItem(3); | ||
152 | connect(baud_c, SIGNAL(activated(int)), | ||
153 | this, SLOT(speed_selection(int))); | ||
154 | tl->addWidget(baud_c, 3, 1); | ||
155 | |||
156 | tmp = i18n("Specifies the speed your modem and the serial\n" | ||
157 | "port talk to each other. You should begin with\n" | ||
158 | "the default of 38400 bits/sec. If everything\n" | ||
159 | "works you can try to increase this value, but to\n" | ||
160 | "no more than 115200 bits/sec (unless you know\n" | ||
161 | "that your serial port supports higher speeds)."); | ||
162 | |||
163 | QWhatsThis::add(baud_label,tmp); | ||
164 | QWhatsThis::add(baud_c,tmp); | ||
165 | |||
166 | for(int i=0; i <= enter->count()-1; i++) { | ||
167 | if(gpppdata.enter() == enter->text(i)) | ||
168 | enter->setCurrentItem(i); | ||
169 | } | ||
170 | |||
171 | tl->addRowSpacing(4, 10); | ||
172 | |||
173 | //Modem Lock File | ||
174 | modemlockfile = new QCheckBox(i18n("&Use lock file"), this); | ||
175 | |||
176 | modemlockfile->setChecked(gpppdata.modemLockFile()); | ||
177 | connect(modemlockfile, SIGNAL(toggled(bool)), | ||
178 | SLOT(modemlockfilechanged(bool))); | ||
179 | tl->addMultiCellWidget(modemlockfile, 5, 5, 0, 1); | ||
180 | // l12->addStretch(1); | ||
181 | QWhatsThis::add(modemlockfile, | ||
182 | i18n("<p>To prevent other programs from accessing the\n" | ||
183 | "modem while a connection is established, a\n" | ||
184 | "file can be created to indicate that the modem\n" | ||
185 | "is in use. On Linux an example file would be\n" | ||
186 | "<tt>/var/lock/LCK..ttyS1</tt>\n" | ||
187 | "Here you can select whether this locking will\n" | ||
188 | "be done.\n" | ||
189 | "\n" | ||
190 | "<b>Default</b>: On")); | ||
191 | |||
192 | // Modem Timeout Line Edit Box | ||
193 | |||
194 | modemtimeout = new KIntNumInput(gpppdata.modemTimeout(), this); | ||
195 | modemtimeout->setLabel(i18n("Modem &timeout:")); | ||
196 | modemtimeout->setRange(1, 120, 1); | ||
197 | modemtimeout->setSuffix(i18n(" sec")); | ||
198 | connect(modemtimeout, SIGNAL(valueChanged(int)), | ||
199 | SLOT(modemtimeoutchanged(int))); | ||
200 | tl->addMultiCellWidget(modemtimeout, 6, 6, 0, 1); | ||
201 | |||
202 | QWhatsThis::add(modemtimeout, | ||
203 | i18n("This specifies how long <i>kppp</i> waits for a\n" | ||
204 | "<i>CONNECT</i> response from your modem. The\n" | ||
205 | "recommended value is 30 seconds.")); | ||
206 | |||
207 | //set stuff from gpppdata | ||
208 | for(int i=0; i <= enter->count()-1; i++) { | ||
209 | if(gpppdata.enter() == enter->text(i)) | ||
210 | enter->setCurrentItem(i); | ||
211 | } | ||
212 | |||
213 | for(int i=0; i <= modemdevice->count()-1; i++) { | ||
214 | if(gpppdata.modemDevice() == modemdevice->text(i)) | ||
215 | modemdevice->setCurrentItem(i); | ||
216 | } | ||
217 | |||
218 | for(int i=0; i <= flowcontrol->count()-1; i++) { | ||
219 | if(gpppdata.flowcontrol() == flowcontrol->text(i)) | ||
220 | flowcontrol->setCurrentItem(i); | ||
221 | } | ||
222 | |||
223 | //set the modem speed | ||
224 | for(int i=0; i < baud_c->count(); i++) | ||
225 | if(baud_c->text(i) == gpppdata.speed()) | ||
226 | baud_c->setCurrentItem(i); | ||
227 | |||
228 | tl->setRowStretch(7, 1); | ||
229 | } | ||
230 | |||
231 | |||
232 | void ModemWidget::speed_selection(int) { | ||
233 | gpppdata.setSpeed(baud_c->text(baud_c->currentItem())); | ||
234 | } | ||
235 | |||
236 | |||
237 | void ModemWidget::setenter(int ) { | ||
238 | gpppdata.setEnter(enter->text(enter->currentItem())); | ||
239 | } | ||
240 | |||
241 | |||
242 | void ModemWidget::setmodemdc(int i) { | ||
243 | gpppdata.setModemDevice(modemdevice->text(i)); | ||
244 | } | ||
245 | |||
246 | |||
247 | void ModemWidget::setflowcontrol(int i) { | ||
248 | gpppdata.setFlowcontrol(flowcontrol->text(i)); | ||
249 | } | ||
250 | |||
251 | |||
252 | void ModemWidget::modemlockfilechanged(bool set) { | ||
253 | gpppdata.setModemLockFile(set); | ||
254 | } | ||
255 | |||
256 | |||
257 | void ModemWidget::modemtimeoutchanged(int n) { | ||
258 | gpppdata.setModemTimeout(n); | ||
259 | } | ||
260 | |||
261 | |||
262 | ModemWidget2::ModemWidget2( QWidget *parent, const char *name) | ||
263 | : QWidget(parent, name) | ||
264 | { | ||
265 | QVBoxLayout *l1 = new QVBoxLayout(this, 0 );//, KDialog::spacingHint()); | ||
266 | |||
267 | |||
268 | waitfordt = new QCheckBox(i18n("&Wait for dial tone before dialing"), this); | ||
269 | waitfordt->setChecked(gpppdata.waitForDialTone()); | ||
270 | connect(waitfordt, SIGNAL(toggled(bool)), SLOT(waitfordtchanged(bool))); | ||
271 | l1->addWidget(waitfordt); | ||
272 | QWhatsThis::add(waitfordt, | ||
273 | i18n("<p>Normally the modem waits for a dial tone\n" | ||
274 | "from your phone line, indicating that it can\n" | ||
275 | "start to dial a number. If your modem does not\n" | ||
276 | "recognize this sound, or your local phone system\n" | ||
277 | "does not emit such a tone, uncheck this option\n" | ||
278 | "\n" | ||
279 | "<b>Default:</b>: On")); | ||
280 | |||
281 | busywait = new KIntNumInput(gpppdata.busyWait(), this); | ||
282 | busywait->setLabel(i18n("B&usy wait:")); | ||
283 | busywait->setRange(0, 300, 5, true); | ||
284 | busywait->setSuffix(i18n(" sec")); | ||
285 | connect(busywait, SIGNAL(valueChanged(int)), SLOT(busywaitchanged(int))); | ||
286 | l1->addWidget(busywait); | ||
287 | |||
288 | QWhatsThis::add(busywait, | ||
289 | i18n("Specifies the number of seconds to wait before\n" | ||
290 | "redial if all dialed numbers are busy. This is\n" | ||
291 | "necessary because some modems get stuck if the\n" | ||
292 | "same number is busy too often.\n" | ||
293 | "\n" | ||
294 | "The default is 0 seconds, you should not change\n" | ||
295 | "this unless you need to.")); | ||
296 | |||
297 | l1->addSpacing(10); | ||
298 | |||
299 | QHBoxLayout *hbl = new QHBoxLayout; | ||
300 | hbl->setSpacing(2);//KDialog::spacingHint()); | ||
301 | |||
302 | QLabel *volumeLabel = new QLabel(i18n("Modem &volume:"), this); | ||
303 | hbl->addWidget(volumeLabel); | ||
304 | volume = new QSlider(0, 2, 1, gpppdata.volume(), QSlider::Horizontal, this); | ||
305 | volumeLabel->setBuddy(volume); | ||
306 | volume->setTickmarks(QSlider::Below); | ||
307 | hbl->addWidget(volume); | ||
308 | |||
309 | l1->addLayout(hbl); | ||
310 | |||
311 | connect(volume, SIGNAL(valueChanged(int)), | ||
312 | this, SLOT(volumeChanged(int))); | ||
313 | QString tmp = i18n("Most modems have a speaker which makes\n" | ||
314 | "a lot of noise when dialing. Here you can\n" | ||
315 | "either turn this completely off or select a\n" | ||
316 | "lower volume.\n" | ||
317 | "\n" | ||
318 | "If this does not work for your modem,\n" | ||
319 | "you must modify the modem volume command."); | ||
320 | |||
321 | QWhatsThis::add(volumeLabel,tmp); | ||
322 | QWhatsThis::add(volume, tmp); | ||
323 | |||
324 | l1->addSpacing(20); | ||
325 | |||
326 | #if 0 | ||
327 | chkbox1 = new QCheckBox(i18n("Modem asserts CD line"), this); | ||
328 | chkbox1->setChecked(gpppdata.UseCDLine()); | ||
329 | connect(chkbox1,SIGNAL(toggled(bool)), | ||
330 | this,SLOT(use_cdline_toggled(bool))); | ||
331 | l12->addWidget(chkbox1); | ||
332 | l12->addStretch(1); | ||
333 | l1->addStretch(1); | ||
334 | QWhatsThis::add(chkbox1, | ||
335 | i18n("This controls how <i>kppp</i> detects that the modem\n" | ||
336 | "is not responding. Unless you are having\n" | ||
337 | "problems with this, do not modify this setting.\n" | ||
338 | "\n" | ||
339 | "<b>Default</b>: Off")); | ||
340 | #endif | ||
341 | |||
342 | modemcmds = new QPushButton(i18n("Mod&em Commands..."), this); | ||
343 | QWhatsThis::add(modemcmds, | ||
344 | i18n("Allows you to change the AT command for\n" | ||
345 | "your modem.")); | ||
346 | |||
347 | modeminfo_button = new QPushButton(i18n("&Query Modem..."), this); | ||
348 | QWhatsThis::add(modeminfo_button, | ||
349 | i18n("Most modems support the ATI command set to\n" | ||
350 | "find out vendor and revision of your modem.\n" | ||
351 | "\n" | ||
352 | "Press this button to query your modem for\n" | ||
353 | "this information. It can be useful to help\n" | ||
354 | "you setup the modem")); | ||
355 | |||
356 | // terminal_button = new QPushButton(i18n("&Terminal..."), this); | ||
357 | // QWhatsThis::add(terminal_button, | ||
358 | // i18n("Opens the built-in terminal program. You\n" | ||
359 | // "can use this if you want to play around\n" | ||
360 | // "with your modem's AT command set")); | ||
361 | |||
362 | QHBoxLayout *hbox = new QHBoxLayout(); | ||
363 | l1->addLayout(hbox); | ||
364 | hbox->addStretch(1); | ||
365 | QVBoxLayout *vbox = new QVBoxLayout(); | ||
366 | hbox->addLayout(vbox); | ||
367 | |||
368 | vbox->addWidget(modemcmds); | ||
369 | vbox->addWidget(modeminfo_button); | ||
370 | // vbox->addWidget(terminal_button); | ||
371 | |||
372 | hbox->addStretch(1); | ||
373 | l1->addStretch(1); | ||
374 | |||
375 | connect(modemcmds, SIGNAL(clicked()), | ||
376 | SLOT(modemcmdsbutton())); | ||
377 | connect(modeminfo_button, SIGNAL(clicked()), | ||
378 | SLOT(query_modem())); | ||
379 | // connect(terminal_button, SIGNAL(clicked()), | ||
380 | // SLOT(terminal())); | ||
381 | } | ||
382 | |||
383 | |||
384 | void ModemWidget2::modemcmdsbutton() { | ||
385 | ModemCommands mc(this); | ||
386 | mc.showMaximized(); | ||
387 | mc.exec(); | ||
388 | } | ||
389 | |||
390 | |||
391 | void ModemWidget2::query_modem() { | ||
392 | ModemTransfer mt(this); | ||
393 | mt.exec(); | ||
394 | } | ||
395 | |||
396 | |||
397 | // void ModemWidget2::terminal() { | ||
398 | // MiniTerm terminal(NULL,NULL); | ||
399 | // terminal.exec(); | ||
400 | // } | ||
401 | |||
402 | |||
403 | #if 0 | ||
404 | void ModemWidget2::use_cdline_toggled(bool on) { | ||
405 | gpppdata.setUseCDLine(on); | ||
406 | } | ||
407 | #endif | ||
408 | |||
409 | void ModemWidget2::waitfordtchanged(bool b) { | ||
410 | gpppdata.setWaitForDialTone((int)b); | ||
411 | } | ||
412 | |||
413 | void ModemWidget2::busywaitchanged(int n) { | ||
414 | gpppdata.setbusyWait(n); | ||
415 | } | ||
416 | |||
417 | |||
418 | void ModemWidget2::volumeChanged(int v) { | ||
419 | gpppdata.setVolume(v); | ||
420 | } | ||
421 | |||
diff --git a/noncore/settings/networksettings/ppp/general.h b/noncore/settings/networksettings/ppp/general.h new file mode 100644 index 0000000..66a9eec --- a/dev/null +++ b/noncore/settings/networksettings/ppp/general.h | |||
@@ -0,0 +1,100 @@ | |||
1 | /* | ||
2 | * | ||
3 | * kPPP: A pppd front end for the KDE project | ||
4 | * | ||
5 | * $Id$ | ||
6 | * | ||
7 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
8 | * wuebben@math.cornell.edu | ||
9 | * | ||
10 | * | ||
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. | ||
15 | * | ||
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. | ||
20 | * | ||
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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
24 | */ | ||
25 | |||
26 | #ifndef _GENERAL_H_ | ||
27 | #define _GENERAL_H_ | ||
28 | |||
29 | #include <qwidget.h> | ||
30 | #include <qcombobox.h> | ||
31 | #include <qlabel.h> | ||
32 | #include <qcheckbox.h> | ||
33 | #include <qgroupbox.h> | ||
34 | #include <qpushbutton.h> | ||
35 | //#include <kcolorbutton.h> | ||
36 | |||
37 | class QSlider; | ||
38 | class KIntNumInput; | ||
39 | |||
40 | |||
41 | |||
42 | class ModemWidget : public QWidget { | ||
43 | Q_OBJECT | ||
44 | public: | ||
45 | ModemWidget( QWidget *parent=0, const char *name=0 ); | ||
46 | |||
47 | private slots: | ||
48 | void setmodemdc(int); | ||
49 | void setflowcontrol(int); | ||
50 | void modemtimeoutchanged(int); | ||
51 | void modemlockfilechanged(bool); | ||
52 | void setenter(int); | ||
53 | void speed_selection(int); | ||
54 | |||
55 | private: | ||
56 | QComboBox *enter; | ||
57 | QLabel *label1; | ||
58 | QLabel *label2; | ||
59 | QLabel *labeltmp; | ||
60 | QLabel *labelenter; | ||
61 | QComboBox *modemdevice; | ||
62 | QComboBox *flowcontrol; | ||
63 | |||
64 | QComboBox *baud_c; | ||
65 | QLabel *baud_label; | ||
66 | |||
67 | KIntNumInput *modemtimeout; | ||
68 | QCheckBox *modemlockfile; | ||
69 | }; | ||
70 | |||
71 | |||
72 | class ModemWidget2 : public QWidget { | ||
73 | Q_OBJECT | ||
74 | public: | ||
75 | ModemWidget2( QWidget *parent=0, const char *name=0 ); | ||
76 | |||
77 | private slots: | ||
78 | void waitfordtchanged(bool); | ||
79 | void busywaitchanged(int); | ||
80 | // void use_cdline_toggled(bool); | ||
81 | void modemcmdsbutton(); | ||
82 | // void terminal(); | ||
83 | void query_modem(); | ||
84 | void volumeChanged(int); | ||
85 | |||
86 | private: | ||
87 | QLabel *labeltmp; | ||
88 | QPushButton *modemcmds; | ||
89 | QPushButton *modeminfo_button; | ||
90 | // QPushButton *terminal_button; | ||
91 | QFrame *fline; | ||
92 | QCheckBox *waitfordt; | ||
93 | KIntNumInput *busywait; | ||
94 | QCheckBox *chkbox1; | ||
95 | QSlider *volume; | ||
96 | }; | ||
97 | |||
98 | #endif | ||
99 | |||
100 | |||
diff --git a/noncore/settings/networksettings/ppp/iplined.cpp b/noncore/settings/networksettings/ppp/iplined.cpp new file mode 100644 index 0000000..f4fc370 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/iplined.cpp | |||
@@ -0,0 +1,42 @@ | |||
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 library 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 library 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 "iplined.h" | ||
28 | |||
29 | IPLineEdit::IPLineEdit( QWidget *parent, const char *name ) | ||
30 | : QLineEdit(parent, name )//, "0123456789.") | ||
31 | { | ||
32 | setMaxLength(3 * 4 + 1 * 3); | ||
33 | } | ||
34 | |||
35 | QSize IPLineEdit::sizeHint() const { | ||
36 | QFontMetrics fm = fontMetrics(); | ||
37 | |||
38 | QSize s; | ||
39 | s.setHeight(QLineEdit::sizeHint().height()); | ||
40 | s.setWidth(fm.boundingRect("888.888.888.888XX").width()); | ||
41 | return s; | ||
42 | } | ||
diff --git a/noncore/settings/networksettings/ppp/iplined.h b/noncore/settings/networksettings/ppp/iplined.h new file mode 100644 index 0000000..825f0ac --- a/dev/null +++ b/noncore/settings/networksettings/ppp/iplined.h | |||
@@ -0,0 +1,40 @@ | |||
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 library 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 library 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 | #ifndef _IPLINED_H_ | ||
28 | #define _IPLINED_H_ | ||
29 | |||
30 | #include <qlineedit.h> | ||
31 | |||
32 | class IPLineEdit : public QLineEdit { | ||
33 | public: | ||
34 | IPLineEdit( QWidget *parent=0, const char *name=0 ); | ||
35 | ~IPLineEdit() {} | ||
36 | |||
37 | virtual QSize sizeHint() const; | ||
38 | }; | ||
39 | |||
40 | #endif | ||
diff --git a/noncore/settings/networksettings/ppp/knuminput.cpp b/noncore/settings/networksettings/ppp/knuminput.cpp new file mode 100644 index 0000000..afaa581 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/knuminput.cpp | |||
@@ -0,0 +1,1103 @@ | |||
1 | // -*- c-basic-offset: 4 -*- | ||
2 | /* | ||
3 | * knuminput.cpp | ||
4 | * | ||
5 | * Initial implementation: | ||
6 | * Copyright (c) 1997 Patrick Dowler <dowler@morgul.fsh.uvic.ca> | ||
7 | * Rewritten and maintained by: | ||
8 | * Copyright (c) 2000 Dirk A. Mueller <mueller@kde.org> | ||
9 | * KDoubleSpinBox: | ||
10 | * Copyright (c) 2002 Marc Mutz <mutz@kde.org> | ||
11 | * | ||
12 | * Requires the Qt widget libraries, available at no cost at | ||
13 | * http://www.troll.no/ | ||
14 | * | ||
15 | * This library is free software; you can redistribute it and/or | ||
16 | * modify it under the terms of the GNU Library General Public | ||
17 | * License as published by the Free Software Foundation; either | ||
18 | * version 2 of the License, or (at your option) any later version. | ||
19 | * | ||
20 | * This library is distributed in the hope that it will be useful, | ||
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
23 | * Library General Public License for more details. | ||
24 | * | ||
25 | * You should have received a copy of the GNU Library General Public License | ||
26 | * along with this library; see the file COPYING.LIB. If not, write to | ||
27 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
28 | * Boston, MA 02111-1307, USA. | ||
29 | */ | ||
30 | |||
31 | //#include <config.h> | ||
32 | #ifdef HAVE_LIMITS_H | ||
33 | #include <limits.h> | ||
34 | #endif | ||
35 | #include <assert.h> | ||
36 | #include <math.h> | ||
37 | #include <algorithm> | ||
38 | |||
39 | #include <qlabel.h> | ||
40 | #include <qlineedit.h> | ||
41 | #include <qsize.h> | ||
42 | #include <qslider.h> | ||
43 | #include <qspinbox.h> | ||
44 | #include <qstyle.h> | ||
45 | |||
46 | //#include <kglobal.h> | ||
47 | |||
48 | template<class T> | ||
49 | inline const T& kMin (const T& a, const T& b) { return a < b ? a : b; } | ||
50 | |||
51 | template<class T> | ||
52 | inline const T& kMax (const T& a, const T& b) { return b < a ? a : b; } | ||
53 | |||
54 | //#include <klocale.h> | ||
55 | #define i18n QObject::tr | ||
56 | //#include <kdebug.h> | ||
57 | |||
58 | #include "knumvalidator.h" | ||
59 | #include "knuminput.h" | ||
60 | |||
61 | static inline int calcDiffByTen( int x, int y ) { | ||
62 | // calculate ( x - y ) / 10 without overflowing ints: | ||
63 | return ( x / 10 ) - ( y / 10 ) + ( x % 10 - y % 10 ) / 10; | ||
64 | }; | ||
65 | |||
66 | // ---------------------------------------------------------------------------- | ||
67 | |||
68 | KNumInput::KNumInput(QWidget* parent, const char* name) | ||
69 | : QWidget(parent, name) | ||
70 | { | ||
71 | init(); | ||
72 | } | ||
73 | |||
74 | KNumInput::KNumInput(KNumInput* below, QWidget* parent, const char* name) | ||
75 | : QWidget(parent, name) | ||
76 | { | ||
77 | init(); | ||
78 | |||
79 | if(below) { | ||
80 | m_next = below->m_next; | ||
81 | m_prev = below; | ||
82 | below->m_next = this; | ||
83 | if(m_next) | ||
84 | m_next->m_prev = this; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | void KNumInput::init() | ||
89 | { | ||
90 | m_prev = m_next = 0; | ||
91 | m_colw1 = m_colw2 = 0; | ||
92 | |||
93 | m_label = 0; | ||
94 | m_slider = 0; | ||
95 | m_alignment = 0; | ||
96 | } | ||
97 | |||
98 | KNumInput::~KNumInput() | ||
99 | { | ||
100 | if(m_prev) | ||
101 | m_prev->m_next = m_next; | ||
102 | |||
103 | if(m_next) | ||
104 | m_next->m_prev = m_prev; | ||
105 | } | ||
106 | |||
107 | void KNumInput::setLabel(const QString & label, int a) | ||
108 | { | ||
109 | if(label.isEmpty()) { | ||
110 | delete m_label; | ||
111 | m_label = 0; | ||
112 | m_alignment = 0; | ||
113 | } | ||
114 | else { | ||
115 | if (m_label) m_label->setText(label); | ||
116 | else m_label = new QLabel(label, this, "KNumInput::QLabel"); | ||
117 | m_label->setAlignment((a & (~(AlignTop|AlignBottom|AlignVCenter))) | ||
118 | | AlignVCenter); | ||
119 | // if no vertical alignment set, use Top alignment | ||
120 | if(!(a & (AlignTop|AlignBottom|AlignVCenter))) | ||
121 | a |= AlignTop; | ||
122 | m_alignment = a; | ||
123 | } | ||
124 | |||
125 | layout(true); | ||
126 | } | ||
127 | |||
128 | QString KNumInput::label() const | ||
129 | { | ||
130 | if (m_label) return m_label->text(); | ||
131 | return QString::null; | ||
132 | } | ||
133 | |||
134 | void KNumInput::layout(bool deep) | ||
135 | { | ||
136 | int w1 = m_colw1; | ||
137 | int w2 = m_colw2; | ||
138 | |||
139 | // label sizeHint | ||
140 | m_sizeLabel = (m_label ? m_label->sizeHint() : QSize(0,0)); | ||
141 | |||
142 | if(m_label && (m_alignment & AlignVCenter)) | ||
143 | m_colw1 = m_sizeLabel.width() + 4; | ||
144 | else | ||
145 | m_colw1 = 0; | ||
146 | |||
147 | // slider sizeHint | ||
148 | m_sizeSlider = (m_slider ? m_slider->sizeHint() : QSize(0, 0)); | ||
149 | |||
150 | doLayout(); | ||
151 | |||
152 | if(!deep) { | ||
153 | m_colw1 = w1; | ||
154 | m_colw2 = w2; | ||
155 | return; | ||
156 | } | ||
157 | |||
158 | KNumInput* p = this; | ||
159 | while(p) { | ||
160 | p->doLayout(); | ||
161 | w1 = QMAX(w1, p->m_colw1); | ||
162 | w2 = QMAX(w2, p->m_colw2); | ||
163 | p = p->m_prev; | ||
164 | } | ||
165 | |||
166 | p = m_next; | ||
167 | while(p) { | ||
168 | p->doLayout(); | ||
169 | w1 = QMAX(w1, p->m_colw1); | ||
170 | w2 = QMAX(w2, p->m_colw2); | ||
171 | p = p->m_next; | ||
172 | } | ||
173 | |||
174 | p = this; | ||
175 | while(p) { | ||
176 | p->m_colw1 = w1; | ||
177 | p->m_colw2 = w2; | ||
178 | p = p->m_prev; | ||
179 | } | ||
180 | |||
181 | p = m_next; | ||
182 | while(p) { | ||
183 | p->m_colw1 = w1; | ||
184 | p->m_colw2 = w2; | ||
185 | p = p->m_next; | ||
186 | } | ||
187 | |||
188 | // kdDebug() << "w1 " << w1 << " w2 " << w2 << endl; | ||
189 | } | ||
190 | |||
191 | QSizePolicy KNumInput::sizePolicy() const | ||
192 | { | ||
193 | return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ); | ||
194 | } | ||
195 | |||
196 | QSize KNumInput::sizeHint() const | ||
197 | { | ||
198 | return minimumSizeHint(); | ||
199 | } | ||
200 | |||
201 | void KNumInput::setSteps(int minor, int major) | ||
202 | { | ||
203 | if(m_slider) | ||
204 | m_slider->setSteps( minor, major ); | ||
205 | } | ||
206 | |||
207 | |||
208 | // ---------------------------------------------------------------------------- | ||
209 | |||
210 | KIntSpinBox::KIntSpinBox(QWidget *parent, const char *name) | ||
211 | : QSpinBox(0, 99, 1, parent, name) | ||
212 | { | ||
213 | editor()->setAlignment(AlignRight); | ||
214 | val_base = 10; | ||
215 | setValue(0); | ||
216 | } | ||
217 | |||
218 | KIntSpinBox::~KIntSpinBox() | ||
219 | { | ||
220 | } | ||
221 | |||
222 | KIntSpinBox::KIntSpinBox(int lower, int upper, int step, int value, int base, | ||
223 | QWidget* parent, const char* name) | ||
224 | : QSpinBox(lower, upper, step, parent, name) | ||
225 | { | ||
226 | editor()->setAlignment(AlignRight); | ||
227 | val_base = base; | ||
228 | setValue(value); | ||
229 | } | ||
230 | |||
231 | void KIntSpinBox::setBase(int base) | ||
232 | { | ||
233 | val_base = base; | ||
234 | } | ||
235 | |||
236 | |||
237 | int KIntSpinBox::base() const | ||
238 | { | ||
239 | return val_base; | ||
240 | } | ||
241 | |||
242 | QString KIntSpinBox::mapValueToText(int v) | ||
243 | { | ||
244 | return QString::number(v, val_base); | ||
245 | } | ||
246 | |||
247 | int KIntSpinBox::mapTextToValue(bool* ok) | ||
248 | { | ||
249 | return cleanText().toInt(ok, val_base); | ||
250 | } | ||
251 | |||
252 | void KIntSpinBox::setEditFocus(bool mark) | ||
253 | { | ||
254 | editor()->setFocus(); | ||
255 | if(mark) | ||
256 | editor()->selectAll(); | ||
257 | } | ||
258 | |||
259 | |||
260 | // ---------------------------------------------------------------------------- | ||
261 | |||
262 | class KIntNumInput::KIntNumInputPrivate { | ||
263 | public: | ||
264 | int referencePoint; | ||
265 | short blockRelative; | ||
266 | KIntNumInputPrivate( int r ) | ||
267 | : referencePoint( r ), | ||
268 | blockRelative( 0 ) {} | ||
269 | }; | ||
270 | |||
271 | |||
272 | KIntNumInput::KIntNumInput(KNumInput* below, int val, QWidget* parent, | ||
273 | int _base, const char* name) | ||
274 | : KNumInput(below, parent, name) | ||
275 | { | ||
276 | init(val, _base); | ||
277 | } | ||
278 | |||
279 | KIntNumInput::KIntNumInput(QWidget *parent, const char *name) | ||
280 | : KNumInput(parent, name) | ||
281 | { | ||
282 | init(0, 10); | ||
283 | } | ||
284 | |||
285 | KIntNumInput::KIntNumInput(int val, QWidget *parent, int _base, const char *name) | ||
286 | : KNumInput(parent, name) | ||
287 | { | ||
288 | init(val, _base); | ||
289 | |||
290 | } | ||
291 | |||
292 | void KIntNumInput::init(int val, int _base) | ||
293 | { | ||
294 | d = new KIntNumInputPrivate( val ); | ||
295 | m_spin = new KIntSpinBox(INT_MIN, INT_MAX, 1, val, _base, this, "KIntNumInput::KIntSpinBox"); | ||
296 | m_spin->setValidator(new KIntValidator(this, _base, "KNumInput::KIntValidtr")); | ||
297 | connect(m_spin, SIGNAL(valueChanged(int)), SLOT(spinValueChanged(int))); | ||
298 | connect(this, SIGNAL(valueChanged(int)), | ||
299 | SLOT(slotEmitRelativeValueChanged(int))); | ||
300 | |||
301 | setFocusProxy(m_spin); | ||
302 | layout(true); | ||
303 | } | ||
304 | |||
305 | void KIntNumInput::setReferencePoint( int ref ) { | ||
306 | // clip to valid range: | ||
307 | ref = kMin( maxValue(), kMax( minValue(), ref ) ); | ||
308 | d->referencePoint = ref; | ||
309 | } | ||
310 | |||
311 | int KIntNumInput::referencePoint() const { | ||
312 | return d->referencePoint; | ||
313 | } | ||
314 | |||
315 | void KIntNumInput::spinValueChanged(int val) | ||
316 | { | ||
317 | if(m_slider) | ||
318 | m_slider->setValue(val); | ||
319 | |||
320 | emit valueChanged(val); | ||
321 | } | ||
322 | |||
323 | void KIntNumInput::slotEmitRelativeValueChanged( int value ) { | ||
324 | if ( d->blockRelative || !d->referencePoint ) return; | ||
325 | emit relativeValueChanged( double( value ) / double( d->referencePoint ) ); | ||
326 | } | ||
327 | |||
328 | void KIntNumInput::setRange(int lower, int upper, int step, bool slider) | ||
329 | { | ||
330 | upper = kMax(upper, lower); | ||
331 | lower = kMin(upper, lower); | ||
332 | m_spin->setMinValue(lower); | ||
333 | m_spin->setMaxValue(upper); | ||
334 | m_spin->setLineStep(step); | ||
335 | |||
336 | step = m_spin->lineStep(); // maybe QRangeControl didn't like out lineStep? | ||
337 | |||
338 | if(slider) { | ||
339 | if (m_slider) | ||
340 | m_slider->setRange(lower, upper); | ||
341 | else { | ||
342 | m_slider = new QSlider(lower, upper, step, m_spin->value(), | ||
343 | QSlider::Horizontal, this); | ||
344 | m_slider->setTickmarks(QSlider::Below); | ||
345 | connect(m_slider, SIGNAL(valueChanged(int)), | ||
346 | m_spin, SLOT(setValue(int))); | ||
347 | } | ||
348 | |||
349 | // calculate (upper-lower)/10 without overflowing int's: | ||
350 | int major = calcDiffByTen( upper, lower ); | ||
351 | if ( major==0 ) major = step; // #### workaround Qt bug in 2.1-beta4 | ||
352 | |||
353 | m_slider->setSteps(step, major); | ||
354 | m_slider->setTickInterval(major); | ||
355 | } | ||
356 | else { | ||
357 | delete m_slider; | ||
358 | m_slider = 0; | ||
359 | } | ||
360 | |||
361 | // check that reference point is still inside valid range: | ||
362 | setReferencePoint( referencePoint() ); | ||
363 | |||
364 | layout(true); | ||
365 | } | ||
366 | |||
367 | void KIntNumInput::setMinValue(int min) | ||
368 | { | ||
369 | setRange(min, m_spin->maxValue(), m_spin->lineStep(), m_slider); | ||
370 | } | ||
371 | |||
372 | int KIntNumInput::minValue() const | ||
373 | { | ||
374 | return m_spin->minValue(); | ||
375 | } | ||
376 | |||
377 | void KIntNumInput::setMaxValue(int max) | ||
378 | { | ||
379 | setRange(m_spin->minValue(), max, m_spin->lineStep(), m_slider); | ||
380 | } | ||
381 | |||
382 | int KIntNumInput::maxValue() const | ||
383 | { | ||
384 | return m_spin->maxValue(); | ||
385 | } | ||
386 | |||
387 | void KIntNumInput::setSuffix(const QString &suffix) | ||
388 | { | ||
389 | m_spin->setSuffix(suffix); | ||
390 | |||
391 | layout(true); | ||
392 | } | ||
393 | |||
394 | QString KIntNumInput::suffix() const | ||
395 | { | ||
396 | return m_spin->suffix(); | ||
397 | } | ||
398 | |||
399 | void KIntNumInput::setPrefix(const QString &prefix) | ||
400 | { | ||
401 | m_spin->setPrefix(prefix); | ||
402 | |||
403 | layout(true); | ||
404 | } | ||
405 | |||
406 | QString KIntNumInput::prefix() const | ||
407 | { | ||
408 | return m_spin->prefix(); | ||
409 | } | ||
410 | |||
411 | void KIntNumInput::setEditFocus(bool mark) | ||
412 | { | ||
413 | m_spin->setEditFocus(mark); | ||
414 | } | ||
415 | |||
416 | QSize KIntNumInput::minimumSizeHint() const | ||
417 | { | ||
418 | constPolish(); | ||
419 | |||
420 | int w; | ||
421 | int h; | ||
422 | |||
423 | h = 2 + QMAX(m_sizeSpin.height(), m_sizeSlider.height()); | ||
424 | |||
425 | // if in extra row, then count it here | ||
426 | if(m_label && (m_alignment & (AlignBottom|AlignTop))) | ||
427 | h += 4 + m_sizeLabel.height(); | ||
428 | else | ||
429 | // label is in the same row as the other widgets | ||
430 | h = QMAX(h, m_sizeLabel.height() + 2); | ||
431 | |||
432 | w = m_slider ? m_slider->sizeHint().width() + 8 : 0; | ||
433 | w += m_colw1 + m_colw2; | ||
434 | |||
435 | if(m_alignment & (AlignTop|AlignBottom)) | ||
436 | w = QMAX(w, m_sizeLabel.width() + 4); | ||
437 | |||
438 | return QSize(w, h); | ||
439 | } | ||
440 | |||
441 | void KIntNumInput::doLayout() | ||
442 | { | ||
443 | m_sizeSpin = m_spin->sizeHint(); | ||
444 | m_colw2 = m_sizeSpin.width(); | ||
445 | |||
446 | if (m_label) | ||
447 | m_label->setBuddy(m_spin); | ||
448 | } | ||
449 | |||
450 | void KIntNumInput::resizeEvent(QResizeEvent* e) | ||
451 | { | ||
452 | int w = m_colw1; | ||
453 | int h = 0; | ||
454 | |||
455 | if(m_label && (m_alignment & AlignTop)) { | ||
456 | m_label->setGeometry(0, 0, e->size().width(), m_sizeLabel.height()); | ||
457 | h += m_sizeLabel.height() + 4; | ||
458 | } | ||
459 | |||
460 | if(m_label && (m_alignment & AlignVCenter)) | ||
461 | m_label->setGeometry(0, 0, w, m_sizeSpin.height()); | ||
462 | |||
463 | m_spin->setGeometry(w, h, m_slider ? m_colw2 : QMAX(m_colw2, e->size().width() - w), m_sizeSpin.height()); | ||
464 | w += m_colw2 + 8; | ||
465 | |||
466 | if(m_slider) | ||
467 | m_slider->setGeometry(w, h, e->size().width() - w, m_sizeSpin.height()); | ||
468 | |||
469 | h += m_sizeSpin.height() + 2; | ||
470 | |||
471 | if(m_label && (m_alignment & AlignBottom)) | ||
472 | m_label->setGeometry(0, h, m_sizeLabel.width(), m_sizeLabel.height()); | ||
473 | } | ||
474 | |||
475 | KIntNumInput::~KIntNumInput() | ||
476 | { | ||
477 | delete d; | ||
478 | } | ||
479 | |||
480 | void KIntNumInput::setValue(int val) | ||
481 | { | ||
482 | m_spin->setValue(val); | ||
483 | // slider value is changed by spinValueChanged | ||
484 | } | ||
485 | |||
486 | void KIntNumInput::setRelativeValue( double r ) { | ||
487 | if ( !d->referencePoint ) return; | ||
488 | ++d->blockRelative; | ||
489 | setValue( int( d->referencePoint * r + 0.5 ) ); | ||
490 | --d->blockRelative; | ||
491 | } | ||
492 | |||
493 | double KIntNumInput::relativeValue() const { | ||
494 | if ( !d->referencePoint ) return 0; | ||
495 | return double( value() ) / double ( d->referencePoint ); | ||
496 | } | ||
497 | |||
498 | int KIntNumInput::value() const | ||
499 | { | ||
500 | return m_spin->value(); | ||
501 | } | ||
502 | |||
503 | void KIntNumInput::setSpecialValueText(const QString& text) | ||
504 | { | ||
505 | m_spin->setSpecialValueText(text); | ||
506 | layout(true); | ||
507 | }; | ||
508 | |||
509 | QString KIntNumInput::specialValueText() const | ||
510 | { | ||
511 | return m_spin->specialValueText(); | ||
512 | } | ||
513 | |||
514 | void KIntNumInput::setLabel(const QString & label, int a) | ||
515 | { | ||
516 | KNumInput::setLabel(label, a); | ||
517 | |||
518 | if(m_label) | ||
519 | m_label->setBuddy(m_spin); | ||
520 | } | ||
521 | |||
522 | // ---------------------------------------------------------------------------- | ||
523 | |||
524 | class KDoubleNumInput::KDoubleNumInputPrivate { | ||
525 | public: | ||
526 | KDoubleNumInputPrivate( double r ) | ||
527 | : spin( 0 ), | ||
528 | referencePoint( r ), | ||
529 | blockRelative ( 0 ) {} | ||
530 | KDoubleSpinBox * spin; | ||
531 | double referencePoint; | ||
532 | short blockRelative; | ||
533 | }; | ||
534 | |||
535 | KDoubleNumInput::KDoubleNumInput(QWidget *parent, const char *name) | ||
536 | : KNumInput(parent, name) | ||
537 | { | ||
538 | init(0.0, 0.0, 9999.0, 0.01, 2); | ||
539 | } | ||
540 | |||
541 | KDoubleNumInput::KDoubleNumInput(double lower, double upper, double value, | ||
542 | double step, int precision, QWidget* parent, | ||
543 | const char *name) | ||
544 | : KNumInput(parent, name) | ||
545 | { | ||
546 | init(value, lower, upper, step, precision); | ||
547 | } | ||
548 | |||
549 | KDoubleNumInput::KDoubleNumInput(KNumInput *below, | ||
550 | double lower, double upper, double value, | ||
551 | double step, int precision, QWidget* parent, | ||
552 | const char *name) | ||
553 | : KNumInput(below, parent, name) | ||
554 | { | ||
555 | init(value, lower, upper, step, precision); | ||
556 | } | ||
557 | |||
558 | KDoubleNumInput::KDoubleNumInput(double value, QWidget *parent, const char *name) | ||
559 | : KNumInput(parent, name) | ||
560 | { | ||
561 | init(value, kMin(0.0, value), kMax(0.0, value), 0.01, 2 ); | ||
562 | } | ||
563 | |||
564 | KDoubleNumInput::KDoubleNumInput(KNumInput* below, double value, QWidget* parent, | ||
565 | const char* name) | ||
566 | : KNumInput(below, parent, name) | ||
567 | { | ||
568 | init( value, kMin(0.0, value), kMax(0.0, value), 0.01, 2 ); | ||
569 | } | ||
570 | |||
571 | KDoubleNumInput::~KDoubleNumInput() | ||
572 | { | ||
573 | delete d; | ||
574 | } | ||
575 | |||
576 | // ### remove when BIC changes are allowed again: | ||
577 | |||
578 | bool KDoubleNumInput::eventFilter( QObject * o, QEvent * e ) { | ||
579 | return KNumInput::eventFilter( o, e ); | ||
580 | } | ||
581 | |||
582 | void KDoubleNumInput::resetEditBox() { | ||
583 | |||
584 | } | ||
585 | |||
586 | // ### end stuff to remove when BIC changes are allowed again | ||
587 | |||
588 | |||
589 | |||
590 | void KDoubleNumInput::init(double value, double lower, double upper, | ||
591 | double step, int precision ) | ||
592 | { | ||
593 | // ### init no longer used members: | ||
594 | edit = 0; | ||
595 | m_range = true; | ||
596 | m_value = 0.0; | ||
597 | m_precision = 2; | ||
598 | // ### end | ||
599 | |||
600 | d = new KDoubleNumInputPrivate( value ); | ||
601 | |||
602 | d->spin = new KDoubleSpinBox( lower, upper, step, value, precision, | ||
603 | this, "KDoubleNumInput::d->spin" ); | ||
604 | setFocusProxy(d->spin); | ||
605 | connect( d->spin, SIGNAL(valueChanged(double)), | ||
606 | this, SIGNAL(valueChanged(double)) ); | ||
607 | connect( this, SIGNAL(valueChanged(double)), | ||
608 | this, SLOT(slotEmitRelativeValueChanged(double)) ); | ||
609 | |||
610 | updateLegacyMembers(); | ||
611 | |||
612 | layout(true); | ||
613 | } | ||
614 | |||
615 | void KDoubleNumInput::updateLegacyMembers() { | ||
616 | // ### update legacy members that are either not private or for | ||
617 | // which an inlined getter exists: | ||
618 | m_lower = minValue(); | ||
619 | m_upper = maxValue(); | ||
620 | m_step = d->spin->lineStep(); | ||
621 | m_specialvalue = specialValueText(); | ||
622 | } | ||
623 | |||
624 | |||
625 | double KDoubleNumInput::mapSliderToSpin( int val ) const | ||
626 | { | ||
627 | // map [slidemin,slidemax] to [spinmin,spinmax] | ||
628 | double spinmin = d->spin->minValue(); | ||
629 | double spinmax = d->spin->maxValue(); | ||
630 | double slidemin = m_slider->minValue(); // cast int to double to avoid | ||
631 | double slidemax = m_slider->maxValue(); // overflow in rel denominator | ||
632 | double rel = ( double(val) - slidemin ) / ( slidemax - slidemin ); | ||
633 | return spinmin + rel * ( spinmax - spinmin ); | ||
634 | } | ||
635 | |||
636 | void KDoubleNumInput::sliderMoved(int val) | ||
637 | { | ||
638 | d->spin->setValue( mapSliderToSpin( val ) ); | ||
639 | } | ||
640 | |||
641 | void KDoubleNumInput::slotEmitRelativeValueChanged( double value ) | ||
642 | { | ||
643 | if ( !d->referencePoint ) return; | ||
644 | emit relativeValueChanged( value / d->referencePoint ); | ||
645 | } | ||
646 | |||
647 | QSize KDoubleNumInput::minimumSizeHint() const | ||
648 | { | ||
649 | constPolish(); | ||
650 | |||
651 | int w; | ||
652 | int h; | ||
653 | |||
654 | h = 2 + QMAX(m_sizeEdit.height(), m_sizeSlider.height()); | ||
655 | |||
656 | // if in extra row, then count it here | ||
657 | if(m_label && (m_alignment & (AlignBottom|AlignTop))) | ||
658 | h += 4 + m_sizeLabel.height(); | ||
659 | else | ||
660 | // label is in the same row as the other widgets | ||
661 | h = QMAX(h, m_sizeLabel.height() + 2); | ||
662 | |||
663 | w = m_slider ? m_slider->sizeHint().width() + 8 : 0; | ||
664 | w += m_colw1 + m_colw2; | ||
665 | |||
666 | if(m_alignment & (AlignTop|AlignBottom)) | ||
667 | w = QMAX(w, m_sizeLabel.width() + 4); | ||
668 | |||
669 | return QSize(w, h); | ||
670 | } | ||
671 | |||
672 | void KDoubleNumInput::resizeEvent(QResizeEvent* e) | ||
673 | { | ||
674 | int w = m_colw1; | ||
675 | int h = 0; | ||
676 | |||
677 | if(m_label && (m_alignment & AlignTop)) { | ||
678 | m_label->setGeometry(0, 0, e->size().width(), m_sizeLabel.height()); | ||
679 | h += m_sizeLabel.height() + 4; | ||
680 | } | ||
681 | |||
682 | if(m_label && (m_alignment & AlignVCenter)) | ||
683 | m_label->setGeometry(0, 0, w, m_sizeEdit.height()); | ||
684 | |||
685 | d->spin->setGeometry(w, h, m_slider ? m_colw2 | ||
686 | : e->size().width() - w, m_sizeEdit.height()); | ||
687 | w += m_colw2 + 8; | ||
688 | |||
689 | if(m_slider) | ||
690 | m_slider->setGeometry(w, h, e->size().width() - w, m_sizeEdit.height()); | ||
691 | |||
692 | h += m_sizeEdit.height() + 2; | ||
693 | |||
694 | if(m_label && (m_alignment & AlignBottom)) | ||
695 | m_label->setGeometry(0, h, m_sizeLabel.width(), m_sizeLabel.height()); | ||
696 | } | ||
697 | |||
698 | void KDoubleNumInput::doLayout() | ||
699 | { | ||
700 | m_sizeEdit = d->spin->sizeHint(); | ||
701 | m_colw2 = m_sizeEdit.width(); | ||
702 | } | ||
703 | |||
704 | void KDoubleNumInput::setValue(double val) | ||
705 | { | ||
706 | d->spin->setValue( val ); | ||
707 | } | ||
708 | |||
709 | void KDoubleNumInput::setRelativeValue( double r ) | ||
710 | { | ||
711 | if ( !d->referencePoint ) return; | ||
712 | ++d->blockRelative; | ||
713 | setValue( r * d->referencePoint ); | ||
714 | --d->blockRelative; | ||
715 | } | ||
716 | |||
717 | void KDoubleNumInput::setReferencePoint( double ref ) | ||
718 | { | ||
719 | // clip to valid range: | ||
720 | ref = kMin( maxValue(), kMax( minValue(), ref ) ); | ||
721 | d->referencePoint = ref; | ||
722 | } | ||
723 | |||
724 | void KDoubleNumInput::setRange(double lower, double upper, double step, | ||
725 | bool slider) | ||
726 | { | ||
727 | if( m_slider ) { | ||
728 | // don't update the slider to avoid an endless recursion | ||
729 | QSpinBox * spin = d->spin; | ||
730 | disconnect(spin, SIGNAL(valueChanged(int)), | ||
731 | m_slider, SLOT(setValue(int)) ); | ||
732 | } | ||
733 | d->spin->setRange( lower, upper, step, d->spin->precision() ); | ||
734 | |||
735 | if(slider) { | ||
736 | // upcast to base type to get the min/maxValue in int form: | ||
737 | QSpinBox * spin = d->spin; | ||
738 | int slmax = spin->maxValue(); | ||
739 | int slmin = spin->minValue(); | ||
740 | int slvalue = spin->value(); | ||
741 | int slstep = spin->lineStep(); | ||
742 | if (m_slider) { | ||
743 | m_slider->setRange(slmin, slmax); | ||
744 | m_slider->setLineStep(slstep); | ||
745 | m_slider->setValue(slvalue); | ||
746 | } else { | ||
747 | m_slider = new QSlider(slmin, slmax, slstep, slvalue, | ||
748 | QSlider::Horizontal, this); | ||
749 | m_slider->setTickmarks(QSlider::Below); | ||
750 | // feedback line: when one moves, the other moves, too: | ||
751 | connect(m_slider, SIGNAL(valueChanged(int)), | ||
752 | SLOT(sliderMoved(int)) ); | ||
753 | } | ||
754 | connect(spin, SIGNAL(valueChanged(int)), | ||
755 | m_slider, SLOT(setValue(int)) ); | ||
756 | // calculate ( slmax - slmin ) / 10 without overflowing ints: | ||
757 | int major = calcDiffByTen( slmax, slmin ); | ||
758 | if ( !major ) major = slstep; // ### needed? | ||
759 | m_slider->setTickInterval(major); | ||
760 | } else { | ||
761 | delete m_slider; | ||
762 | m_slider = 0; | ||
763 | } | ||
764 | |||
765 | setReferencePoint( referencePoint() ); | ||
766 | |||
767 | layout(true); | ||
768 | updateLegacyMembers(); | ||
769 | } | ||
770 | |||
771 | void KDoubleNumInput::setMinValue(double min) | ||
772 | { | ||
773 | setRange(min, maxValue(), d->spin->lineStep(), m_slider); | ||
774 | } | ||
775 | |||
776 | double KDoubleNumInput::minValue() const | ||
777 | { | ||
778 | return d->spin->minValue(); | ||
779 | } | ||
780 | |||
781 | void KDoubleNumInput::setMaxValue(double max) | ||
782 | { | ||
783 | setRange(minValue(), max, d->spin->lineStep(), m_slider); | ||
784 | } | ||
785 | |||
786 | double KDoubleNumInput::maxValue() const | ||
787 | { | ||
788 | return d->spin->maxValue(); | ||
789 | } | ||
790 | |||
791 | double KDoubleNumInput::value() const | ||
792 | { | ||
793 | return d->spin->value(); | ||
794 | } | ||
795 | |||
796 | double KDoubleNumInput::relativeValue() const | ||
797 | { | ||
798 | if ( !d->referencePoint ) return 0; | ||
799 | return value() / d->referencePoint; | ||
800 | } | ||
801 | |||
802 | double KDoubleNumInput::referencePoint() const | ||
803 | { | ||
804 | return d->referencePoint; | ||
805 | } | ||
806 | |||
807 | QString KDoubleNumInput::suffix() const | ||
808 | { | ||
809 | return d->spin->suffix(); | ||
810 | } | ||
811 | |||
812 | QString KDoubleNumInput::prefix() const | ||
813 | { | ||
814 | return d->spin->prefix(); | ||
815 | } | ||
816 | |||
817 | void KDoubleNumInput::setSuffix(const QString &suffix) | ||
818 | { | ||
819 | d->spin->setSuffix( suffix ); | ||
820 | |||
821 | layout(true); | ||
822 | } | ||
823 | |||
824 | void KDoubleNumInput::setPrefix(const QString &prefix) | ||
825 | { | ||
826 | d->spin->setPrefix( prefix ); | ||
827 | |||
828 | layout(true); | ||
829 | } | ||
830 | |||
831 | void KDoubleNumInput::setPrecision(int precision) | ||
832 | { | ||
833 | d->spin->setPrecision( precision ); | ||
834 | |||
835 | layout(true); | ||
836 | } | ||
837 | |||
838 | int KDoubleNumInput::precision() const | ||
839 | { | ||
840 | return d->spin->precision(); | ||
841 | } | ||
842 | |||
843 | void KDoubleNumInput::setSpecialValueText(const QString& text) | ||
844 | { | ||
845 | d->spin->setSpecialValueText( text ); | ||
846 | |||
847 | layout(true); | ||
848 | updateLegacyMembers(); | ||
849 | }; | ||
850 | |||
851 | void KDoubleNumInput::setLabel(const QString & label, int a) | ||
852 | { | ||
853 | KNumInput::setLabel(label, a); | ||
854 | |||
855 | if(m_label) | ||
856 | m_label->setBuddy(d->spin); | ||
857 | |||
858 | } | ||
859 | |||
860 | // ---------------------------------------------------------------------------- | ||
861 | |||
862 | |||
863 | // We use a kind of fixed-point arithmetic to represent the range of | ||
864 | // doubles [mLower,mUpper] in steps of 10^(-mPrecision). Thus, the | ||
865 | // following relations hold: | ||
866 | // | ||
867 | // 1. factor = 10^mPrecision | ||
868 | // 2. basicStep = 1/factor = 10^(-mPrecision); | ||
869 | // 3. lowerInt = lower * factor; | ||
870 | // 4. upperInt = upper * factor; | ||
871 | // 5. lower = lowerInt * basicStep; | ||
872 | // 6. upper = upperInt * basicStep; | ||
873 | class KDoubleSpinBox::Private { | ||
874 | public: | ||
875 | Private( int precision=1 ) | ||
876 | : mPrecision( precision ), | ||
877 | mValidator( 0 ) | ||
878 | { | ||
879 | } | ||
880 | |||
881 | int factor() const { | ||
882 | int f = 1; | ||
883 | for ( int i = 0 ; i < mPrecision ; ++i ) f *= 10; | ||
884 | return f; | ||
885 | } | ||
886 | |||
887 | double basicStep() const { | ||
888 | return 1.0/double(factor()); | ||
889 | } | ||
890 | |||
891 | int mapToInt( double value, bool * ok ) const { | ||
892 | assert( ok ); | ||
893 | const double f = factor(); | ||
894 | if ( value > double(INT_MAX) / f ) { | ||
895 | // kdWarning() << "KDoubleSpinBox: can't represent value " << value | ||
896 | // << "in terms of fixed-point numbers with precision " | ||
897 | // << mPrecision << endl; | ||
898 | *ok = false; | ||
899 | return INT_MAX; | ||
900 | } else if ( value < double(INT_MIN) / f ) { | ||
901 | // kdWarning() << "KDoubleSpinBox: can't represent value " << value | ||
902 | // << "in terms of fixed-point numbers with precision " | ||
903 | // << mPrecision << endl; | ||
904 | *ok = false; | ||
905 | return INT_MIN; | ||
906 | } else { | ||
907 | *ok = true; | ||
908 | return int( value * f + ( value < 0 ? -0.5 : 0.5 ) ); | ||
909 | } | ||
910 | } | ||
911 | |||
912 | double mapToDouble( int value ) const { | ||
913 | return double(value) * basicStep(); | ||
914 | } | ||
915 | |||
916 | int mPrecision; | ||
917 | KDoubleValidator * mValidator; | ||
918 | }; | ||
919 | |||
920 | KDoubleSpinBox::KDoubleSpinBox( QWidget * parent, const char * name ) | ||
921 | : QSpinBox( parent, name ) | ||
922 | { | ||
923 | editor()->setAlignment( Qt::AlignRight ); | ||
924 | d = new Private(); | ||
925 | updateValidator(); | ||
926 | } | ||
927 | |||
928 | KDoubleSpinBox::KDoubleSpinBox( double lower, double upper, double step, | ||
929 | double value, int precision, | ||
930 | QWidget * parent, const char * name ) | ||
931 | : QSpinBox( parent, name ) | ||
932 | { | ||
933 | editor()->setAlignment( Qt::AlignRight ); | ||
934 | d = new Private(); | ||
935 | setRange( lower, upper, step, precision ); | ||
936 | setValue( value ); | ||
937 | connect( this, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)) ); | ||
938 | } | ||
939 | |||
940 | KDoubleSpinBox::~KDoubleSpinBox() { | ||
941 | delete d; d = 0; | ||
942 | } | ||
943 | |||
944 | bool KDoubleSpinBox::acceptLocalizedNumbers() const { | ||
945 | if ( !d->mValidator ) return true; // we'll set one that does; | ||
946 | // can't do it now, since we're const | ||
947 | return d->mValidator->acceptLocalizedNumbers(); | ||
948 | } | ||
949 | |||
950 | void KDoubleSpinBox::setAcceptLocalizedNumbers( bool accept ) { | ||
951 | if ( !d->mValidator ) updateValidator(); | ||
952 | d->mValidator->setAcceptLocalizedNumbers( accept ); | ||
953 | } | ||
954 | |||
955 | void KDoubleSpinBox::setRange( double lower, double upper, double step, | ||
956 | int precision ) { | ||
957 | lower = kMin(upper, lower); | ||
958 | upper = kMax(upper, lower); | ||
959 | setPrecision( precision, true ); // disable bounds checking, since | ||
960 | setMinValue( lower ); // it's done in set{Min,Max}Value | ||
961 | setMaxValue( upper ); // anyway and we want lower, upper | ||
962 | setLineStep( step ); // and step to have the right precision | ||
963 | } | ||
964 | |||
965 | int KDoubleSpinBox::precision() const { | ||
966 | return d->mPrecision; | ||
967 | } | ||
968 | |||
969 | void KDoubleSpinBox::setPrecision( int precision ) { | ||
970 | setPrecision( precision, false ); | ||
971 | } | ||
972 | |||
973 | void KDoubleSpinBox::setPrecision( int precision, bool force ) { | ||
974 | if ( precision < 1 ) return; | ||
975 | if ( !force ) { | ||
976 | int maxPrec = maxPrecision(); | ||
977 | if ( precision > maxPrec ) | ||
978 | precision = maxPrec; | ||
979 | } | ||
980 | d->mPrecision = precision; | ||
981 | updateValidator(); | ||
982 | } | ||
983 | |||
984 | int KDoubleSpinBox::maxPrecision() const { | ||
985 | // INT_MAX must be > maxAbsValue * 10^precision | ||
986 | // ==> 10^precision < INT_MAX / maxAbsValue | ||
987 | // ==> precision < log10 ( INT_MAX / maxAbsValue ) | ||
988 | // ==> maxPrecision = floor( log10 ( INT_MAX / maxAbsValue ) ); | ||
989 | double maxAbsValue = kMax( fabs(minValue()), fabs(maxValue()) ); | ||
990 | if ( maxAbsValue == 0 ) return 6; // return arbitrary value to avoid dbz... | ||
991 | |||
992 | return int( floor( log10( double(INT_MAX) / maxAbsValue ) ) ); | ||
993 | } | ||
994 | |||
995 | double KDoubleSpinBox::value() const { | ||
996 | return d->mapToDouble( base::value() ); | ||
997 | } | ||
998 | |||
999 | void KDoubleSpinBox::setValue( double value ) { | ||
1000 | if ( value == this->value() ) return; | ||
1001 | if ( value < minValue() ) | ||
1002 | base::setValue( base::minValue() ); | ||
1003 | else if ( value > maxValue() ) | ||
1004 | base::setValue( base::maxValue() ); | ||
1005 | else { | ||
1006 | bool ok = false; | ||
1007 | base::setValue( d->mapToInt( value, &ok ) ); | ||
1008 | assert( ok ); | ||
1009 | } | ||
1010 | } | ||
1011 | |||
1012 | double KDoubleSpinBox::minValue() const { | ||
1013 | return d->mapToDouble( base::minValue() ); | ||
1014 | } | ||
1015 | |||
1016 | void KDoubleSpinBox::setMinValue( double value ) { | ||
1017 | bool ok = false; | ||
1018 | int min = d->mapToInt( value, &ok ); | ||
1019 | if ( !ok ) return; | ||
1020 | base::setMinValue( min ); | ||
1021 | updateValidator(); | ||
1022 | } | ||
1023 | |||
1024 | |||
1025 | double KDoubleSpinBox::maxValue() const { | ||
1026 | return d->mapToDouble( base::maxValue() ); | ||
1027 | } | ||
1028 | |||
1029 | void KDoubleSpinBox::setMaxValue( double value ) { | ||
1030 | bool ok = false; | ||
1031 | int max = d->mapToInt( value, &ok ); | ||
1032 | if ( !ok ) return; | ||
1033 | base::setMaxValue( max ); | ||
1034 | updateValidator(); | ||
1035 | } | ||
1036 | |||
1037 | double KDoubleSpinBox::lineStep() const { | ||
1038 | return d->mapToDouble( base::lineStep() ); | ||
1039 | } | ||
1040 | |||
1041 | void KDoubleSpinBox::setLineStep( double step ) { | ||
1042 | bool ok = false; | ||
1043 | if ( step > maxValue() - minValue() ) | ||
1044 | base::setLineStep( 1 ); | ||
1045 | else | ||
1046 | base::setLineStep( kMax( d->mapToInt( step, &ok ), 1 ) ); | ||
1047 | } | ||
1048 | |||
1049 | QString KDoubleSpinBox::mapValueToText( int value ) { | ||
1050 | // if ( acceptLocalizedNumbers() ) | ||
1051 | // return KGlobal::locale() | ||
1052 | // ->formatNumber( d->mapToDouble( value ), d->mPrecision ); | ||
1053 | // else | ||
1054 | return QString().setNum( d->mapToDouble( value ), 'f', d->mPrecision ); | ||
1055 | } | ||
1056 | |||
1057 | int KDoubleSpinBox::mapTextToValue( bool * ok ) { | ||
1058 | double value; | ||
1059 | // if ( acceptLocalizedNumbers() ) | ||
1060 | // value = KGlobal::locale()->readNumber( cleanText(), ok ); | ||
1061 | // else | ||
1062 | value = cleanText().toDouble( ok ); | ||
1063 | if ( !*ok ) return 0; | ||
1064 | if ( value > maxValue() ) | ||
1065 | value = maxValue(); | ||
1066 | else if ( value < minValue() ) | ||
1067 | value = minValue(); | ||
1068 | return d->mapToInt( value, ok ); | ||
1069 | } | ||
1070 | |||
1071 | void KDoubleSpinBox::setValidator( const QValidator * ) { | ||
1072 | // silently discard the new validator. We don't want another one ;-) | ||
1073 | } | ||
1074 | |||
1075 | void KDoubleSpinBox::slotValueChanged( int value ) { | ||
1076 | emit valueChanged( d->mapToDouble( value ) ); | ||
1077 | } | ||
1078 | |||
1079 | void KDoubleSpinBox::updateValidator() { | ||
1080 | if ( !d->mValidator ) { | ||
1081 | d->mValidator = new KDoubleValidator( minValue(), maxValue(), precision(), | ||
1082 | this, "d->mValidator" ); | ||
1083 | base::setValidator( d->mValidator ); | ||
1084 | } else | ||
1085 | d->mValidator->setRange( minValue(), maxValue(), precision() ); | ||
1086 | } | ||
1087 | |||
1088 | void KNumInput::virtual_hook( int, void* ) | ||
1089 | { /*BASE::virtual_hook( id, data );*/ } | ||
1090 | |||
1091 | void KIntNumInput::virtual_hook( int id, void* data ) | ||
1092 | { KNumInput::virtual_hook( id, data ); } | ||
1093 | |||
1094 | void KDoubleNumInput::virtual_hook( int id, void* data ) | ||
1095 | { KNumInput::virtual_hook( id, data ); } | ||
1096 | |||
1097 | void KIntSpinBox::virtual_hook( int, void* ) | ||
1098 | { /*BASE::virtual_hook( id, data );*/ } | ||
1099 | |||
1100 | void KDoubleSpinBox::virtual_hook( int, void* ) | ||
1101 | { /*BASE::virtual_hook( id, data );*/ } | ||
1102 | |||
1103 | //#include "knuminput.moc" | ||
diff --git a/noncore/settings/networksettings/ppp/knuminput.h b/noncore/settings/networksettings/ppp/knuminput.h new file mode 100644 index 0000000..67f3b44 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/knuminput.h | |||
@@ -0,0 +1,947 @@ | |||
1 | /* | ||
2 | * knuminput.h | ||
3 | * | ||
4 | * Copyright (c) 1997 Patrick Dowler <dowler@morgul.fsh.uvic.ca> | ||
5 | * Copyright (c) 2000 Dirk A. Mueller <mueller@kde.org> | ||
6 | * Copyright (c) 2002 Marc Mutz <mutz@kde.org> | ||
7 | * | ||
8 | * Requires the Qt widget libraries, available at no cost at | ||
9 | * http://www.troll.no/ | ||
10 | * | ||
11 | * This library 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. | ||
15 | * | ||
16 | * This library 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. | ||
20 | * | ||
21 | * You should have received a copy of the GNU Library General Public License | ||
22 | * along with this library; see the file COPYING.LIB. If not, write to | ||
23 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
24 | * Boston, MA 02111-1307, USA. | ||
25 | */ | ||
26 | |||
27 | #ifndef K_NUMINPUT_H | ||
28 | #define K_NUMINPUT_H | ||
29 | |||
30 | #include <qwidget.h> | ||
31 | #include <qspinbox.h> | ||
32 | |||
33 | class QLabel; | ||
34 | class QSlider; | ||
35 | class QLineEdit; | ||
36 | class QLayout; | ||
37 | class QValidator; | ||
38 | |||
39 | class KIntSpinBox; | ||
40 | |||
41 | /* ------------------------------------------------------------------------ */ | ||
42 | |||
43 | /** | ||
44 | * You need to inherit from this class if you want to implement K*NumInput | ||
45 | * for a different variable type | ||
46 | * | ||
47 | */ | ||
48 | class KNumInput : public QWidget | ||
49 | { | ||
50 | Q_OBJECT | ||
51 | Q_PROPERTY( QString label READ label WRITE setLabel ) | ||
52 | public: | ||
53 | /** | ||
54 | * Default constructor | ||
55 | * | ||
56 | */ | ||
57 | KNumInput(QWidget* parent=0, const char* name=0); | ||
58 | |||
59 | /** | ||
60 | * @param below A pointer to another KNumInput. | ||
61 | * | ||
62 | */ | ||
63 | KNumInput(KNumInput* below, QWidget* parent=0, const char* name=0); | ||
64 | ~KNumInput(); | ||
65 | |||
66 | /** | ||
67 | * Sets the text and alignment of the main description label. | ||
68 | * | ||
69 | * @param label The text of the label. | ||
70 | * Use QString::null to remove an existing one. | ||
71 | * | ||
72 | * @param a one of @p AlignLeft, @p AlignHCenter, YAlignRight and | ||
73 | * @p AlignTop, @p AlignVCenter, @p AlignBottom. | ||
74 | * default is @p AlignLeft | @p AlignTop. | ||
75 | * | ||
76 | * The vertical alignment flags have special meaning with this | ||
77 | * widget: | ||
78 | * | ||
79 | * @li @p AlignTop The label is placed above the edit/slider | ||
80 | * @li @p AlignVCenter The label is placed left beside the edit | ||
81 | * @li @p AlignBottom The label is placed below the edit/slider | ||
82 | * | ||
83 | */ | ||
84 | virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop); | ||
85 | |||
86 | /** | ||
87 | * @return the text of the label. | ||
88 | */ | ||
89 | QString label() const; | ||
90 | |||
91 | /** | ||
92 | * @return if the num input has a slider. | ||
93 | * @since 3.1 | ||
94 | */ | ||
95 | bool showSlider() const { return m_slider; } | ||
96 | |||
97 | /** | ||
98 | * Sets the spacing of tickmarks for the slider. | ||
99 | * | ||
100 | * @param minor Minor tickmark separation. | ||
101 | * @param major Major tickmark separation. | ||
102 | */ | ||
103 | void setSteps(int minor, int major); | ||
104 | |||
105 | /** | ||
106 | * Specifies that this widget may stretch horizontally, but is | ||
107 | * fixed vertically (like @ref QSpinBox itself). | ||
108 | */ | ||
109 | QSizePolicy sizePolicy() const; | ||
110 | |||
111 | /** | ||
112 | * Returns a size which fits the contents of the control. | ||
113 | * | ||
114 | * @return the preferred size necessary to show the control | ||
115 | */ | ||
116 | virtual QSize sizeHint() const; | ||
117 | |||
118 | protected: | ||
119 | /** | ||
120 | * Call this function whenever you change something in the geometry | ||
121 | * of your KNumInput child. | ||
122 | * | ||
123 | */ | ||
124 | void layout(bool deep); | ||
125 | |||
126 | /** | ||
127 | * You need to overwrite this method and implement your layout | ||
128 | * calculations there. | ||
129 | * | ||
130 | * See KIntNumInput::doLayout and KDoubleNumInput::doLayout implementation | ||
131 | * for details. | ||
132 | * | ||
133 | */ | ||
134 | virtual void doLayout() = 0; | ||
135 | |||
136 | KNumInput* m_prev, *m_next; | ||
137 | int m_colw1, m_colw2; | ||
138 | |||
139 | QLabel* m_label; | ||
140 | QSlider* m_slider; | ||
141 | QSize m_sizeSlider, m_sizeLabel; | ||
142 | |||
143 | int m_alignment; | ||
144 | |||
145 | private: | ||
146 | void init(); | ||
147 | |||
148 | protected: | ||
149 | virtual void virtual_hook( int id, void* data ); | ||
150 | private: | ||
151 | class KNumInputPrivate; | ||
152 | KNumInputPrivate *d; | ||
153 | }; | ||
154 | |||
155 | /* ------------------------------------------------------------------------ */ | ||
156 | |||
157 | /** | ||
158 | * KIntNumInput combines a @ref QSpinBox and optionally a @ref QSlider | ||
159 | * with a label to make an easy to use control for setting some integer | ||
160 | * parameter. This is especially nice for configuration dialogs, | ||
161 | * which can have many such combinated controls. | ||
162 | * | ||
163 | * The slider is created only when the user specifies a range | ||
164 | * for the control using the setRange function with the slider | ||
165 | * parameter set to "true". | ||
166 | * | ||
167 | * A special feature of KIntNumInput, designed specifically for | ||
168 | * the situation when there are several KIntNumInputs in a column, | ||
169 | * is that you can specify what portion of the control is taken by the | ||
170 | * QSpinBox (the remaining portion is used by the slider). This makes | ||
171 | * it very simple to have all the sliders in a column be the same size. | ||
172 | * | ||
173 | * It uses @ref KIntValidator validator class. KIntNumInput enforces the | ||
174 | * value to be in the given range, and can display it in any base | ||
175 | * between 2 and 36. | ||
176 | * | ||
177 | * @short An input widget for integer numbers, consisting of a spinbox and a slider. | ||
178 | * @version $Id$ | ||
179 | */ | ||
180 | |||
181 | class KIntNumInput : public KNumInput | ||
182 | { | ||
183 | Q_OBJECT | ||
184 | Q_PROPERTY( int value READ value WRITE setValue ) | ||
185 | Q_PROPERTY( int minValue READ minValue WRITE setMinValue ) | ||
186 | Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) | ||
187 | Q_PROPERTY( int referencePoint READ referencePoint WRITE setReferencePoint ) | ||
188 | Q_PROPERTY( QString suffix READ suffix WRITE setSuffix ) | ||
189 | Q_PROPERTY( QString prefix READ prefix WRITE setPrefix ) | ||
190 | Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText ) | ||
191 | |||
192 | public: | ||
193 | /** | ||
194 | * Constructs an input control for integer values | ||
195 | * with base 10 and initial value 0. | ||
196 | */ | ||
197 | KIntNumInput(QWidget *parent=0, const char *name=0); | ||
198 | /** | ||
199 | * Constructor | ||
200 | * It constructs a QSpinBox that allows the input of integer numbers | ||
201 | * in the range of -INT_MAX to +INT_MAX. To set a descriptive label, | ||
202 | * use setLabel(). To enforce the value being in a range and optionally to | ||
203 | * attach a slider to it, use setRange(). | ||
204 | * | ||
205 | * @param value initial value for the control | ||
206 | * @param base numeric base used for display | ||
207 | * @param parent parent QWidget | ||
208 | * @param name internal name for this widget | ||
209 | */ | ||
210 | KIntNumInput(int value, QWidget* parent=0, int base = 10, const char *name=0); | ||
211 | |||
212 | /** | ||
213 | * Constructor | ||
214 | * | ||
215 | * the difference to the one above is the "below" parameter. It tells | ||
216 | * this instance that it is visually put below some other KNumInput widget. | ||
217 | * Note that these two KNumInput's need not to have the same parent widget | ||
218 | * or be in the same layout group. | ||
219 | * The effect is that it'll adjust it's layout in correspondence | ||
220 | * with the layout of the other KNumInput's (you can build an arbitary long | ||
221 | * chain). | ||
222 | * | ||
223 | * @param below append KIntNumInput to the KNumInput chain | ||
224 | * @param value initial value for the control | ||
225 | * @param base numeric base used for display | ||
226 | * @param parent parent QWidget | ||
227 | * @param name internal name for this widget | ||
228 | */ | ||
229 | KIntNumInput(KNumInput* below, int value, QWidget* parent=0, int base = 10, const char *name=0); | ||
230 | |||
231 | /** | ||
232 | * Destructor | ||
233 | * | ||
234 | * | ||
235 | */ | ||
236 | virtual ~KIntNumInput(); | ||
237 | |||
238 | /** | ||
239 | * @return the current value. | ||
240 | */ | ||
241 | int value() const; | ||
242 | |||
243 | /** | ||
244 | * @return the curent value in units of the @ref referencePoint. | ||
245 | * @since 3.1 | ||
246 | */ | ||
247 | double relativeValue() const; | ||
248 | |||
249 | /** | ||
250 | * @return the current reference point | ||
251 | * @since 3.1 | ||
252 | */ | ||
253 | int referencePoint() const; | ||
254 | |||
255 | /** | ||
256 | * @return the suffix displayed behind the value. | ||
257 | * @see #setSuffix() | ||
258 | */ | ||
259 | QString suffix() const; | ||
260 | /** | ||
261 | * @return the prefix displayed in front of the value. | ||
262 | * @see #setPrefix() | ||
263 | */ | ||
264 | QString prefix() const; | ||
265 | /** | ||
266 | * @return the string displayed for a special value. | ||
267 | * @see #setSpecialValueText() | ||
268 | */ | ||
269 | QString specialValueText() const; | ||
270 | |||
271 | /** | ||
272 | * @param min minimum value | ||
273 | * @param max maximum value | ||
274 | * @param step step size for the QSlider | ||
275 | */ | ||
276 | void setRange(int min, int max, int step=1, bool slider=true); | ||
277 | /** | ||
278 | * Sets the minimum value. | ||
279 | */ | ||
280 | void setMinValue(int min); | ||
281 | /** | ||
282 | * @return the minimum value. | ||
283 | */ | ||
284 | int minValue() const; | ||
285 | /** | ||
286 | * Sets the maximum value. | ||
287 | */ | ||
288 | void setMaxValue(int max); | ||
289 | /** | ||
290 | * @return the maximum value. | ||
291 | */ | ||
292 | int maxValue() const; | ||
293 | |||
294 | /** | ||
295 | * Sets the special value text. If set, the SpinBox will display | ||
296 | * this text instead of the numeric value whenever the current | ||
297 | * value is equal to minVal(). Typically this is used for indicating | ||
298 | * that the choice has a special (default) meaning. | ||
299 | */ | ||
300 | void setSpecialValueText(const QString& text); | ||
301 | |||
302 | /** | ||
303 | * @reimplemented | ||
304 | */ | ||
305 | virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop); | ||
306 | |||
307 | /** | ||
308 | * This method returns the minimum size necessary to display the | ||
309 | * control. The minimum size is enough to show all the labels | ||
310 | * in the current font (font change may invalidate the return value). | ||
311 | * | ||
312 | * @return the minimum size necessary to show the control | ||
313 | */ | ||
314 | virtual QSize minimumSizeHint() const; | ||
315 | |||
316 | public slots: | ||
317 | /** | ||
318 | * Sets the value of the control. | ||
319 | */ | ||
320 | void setValue(int); | ||
321 | |||
322 | /** | ||
323 | * Sets the value in units of the @ref referencePoint | ||
324 | * @since 3.1 | ||
325 | */ | ||
326 | void setRelativeValue(double); | ||
327 | |||
328 | /** | ||
329 | * Sets the reference point for @ref relativeValue. | ||
330 | * @since 3.1 | ||
331 | */ | ||
332 | void setReferencePoint(int); | ||
333 | |||
334 | /** | ||
335 | * Sets the suffix to @p suffix. | ||
336 | * Use QString::null to disable this feature. | ||
337 | * Formatting has to be provided (e.g. a space separator between the | ||
338 | * prepended @p value and the suffix's text has to be provided | ||
339 | * as the first character in the suffix). | ||
340 | * | ||
341 | * @see QSpinBox::setSuffix(), #setPrefix() | ||
342 | */ | ||
343 | void setSuffix(const QString &suffix); | ||
344 | |||
345 | /** | ||
346 | * Sets the prefix to @p prefix. | ||
347 | * Use QString::null to disable this feature. | ||
348 | * Formatting has to be provided (see above). | ||
349 | * | ||
350 | * @see QSpinBox::setPrefix(), #setSuffix() | ||
351 | */ | ||
352 | void setPrefix(const QString &prefix); | ||
353 | |||
354 | /** | ||
355 | * sets focus to the edit widget and marks all text in if mark == true | ||
356 | * | ||
357 | */ | ||
358 | void setEditFocus( bool mark = true ); | ||
359 | |||
360 | signals: | ||
361 | /** | ||
362 | * Emitted every time the value changes (by calling @ref setValue() or | ||
363 | * by user interaction). | ||
364 | */ | ||
365 | void valueChanged(int); | ||
366 | |||
367 | /** | ||
368 | * Emitted whenever @ref #valueChanged is. Contains the change | ||
369 | * relative to the @ref referencePoint. | ||
370 | * @since 3.1 | ||
371 | */ | ||
372 | void relativeValueChanged(double); | ||
373 | |||
374 | private slots: | ||
375 | void spinValueChanged(int); | ||
376 | void slotEmitRelativeValueChanged(int); | ||
377 | |||
378 | protected: | ||
379 | /** | ||
380 | * @reimplemented | ||
381 | */ | ||
382 | virtual void doLayout(); | ||
383 | /** | ||
384 | * @reimplemented | ||
385 | */ | ||
386 | void resizeEvent ( QResizeEvent * ); | ||
387 | |||
388 | KIntSpinBox* m_spin; | ||
389 | QSize m_sizeSpin; | ||
390 | |||
391 | private: | ||
392 | void init(int value, int _base); | ||
393 | |||
394 | protected: | ||
395 | virtual void virtual_hook( int id, void* data ); | ||
396 | private: | ||
397 | class KIntNumInputPrivate; | ||
398 | KIntNumInputPrivate *d; | ||
399 | }; | ||
400 | |||
401 | |||
402 | /* ------------------------------------------------------------------------ */ | ||
403 | |||
404 | class KDoubleLine; | ||
405 | |||
406 | /** | ||
407 | * KDoubleNumInput combines a @ref QSpinBox and optionally a @ref QSlider | ||
408 | * with a label to make an easy to use control for setting some float | ||
409 | * parameter. This is especially nice for configuration dialogs, | ||
410 | * which can have many such combinated controls. | ||
411 | * | ||
412 | * The slider is created only when the user specifies a range | ||
413 | * for the control using the setRange function with the slider | ||
414 | * parameter set to "true". | ||
415 | * | ||
416 | * A special feature of KDoubleNumInput, designed specifically for | ||
417 | * the situation when there are several instances in a column, | ||
418 | * is that you can specify what portion of the control is taken by the | ||
419 | * QSpinBox (the remaining portion is used by the slider). This makes | ||
420 | * it very simple to have all the sliders in a column be the same size. | ||
421 | * | ||
422 | * It uses the @ref KDoubleValidator validator class. KDoubleNumInput | ||
423 | * enforces the value to be in the given range, but see the class | ||
424 | * documentation of @ref KDoubleSpinBox for the tricky | ||
425 | * interrelationship of precision and values. All of what is said | ||
426 | * there applies here, too. | ||
427 | * | ||
428 | * @see KIntNumInput, KDoubleSpinBox | ||
429 | * @short An input control for real numbers, consisting of a spinbox and a slider. | ||
430 | */ | ||
431 | |||
432 | class KDoubleNumInput : public KNumInput | ||
433 | { | ||
434 | Q_OBJECT | ||
435 | Q_PROPERTY( double value READ value WRITE setValue ) | ||
436 | Q_PROPERTY( double minValue READ minValue WRITE setMinValue ) | ||
437 | Q_PROPERTY( double maxValue READ maxValue WRITE setMaxValue ) | ||
438 | Q_PROPERTY( QString suffix READ suffix WRITE setSuffix ) | ||
439 | Q_PROPERTY( QString prefix READ prefix WRITE setPrefix ) | ||
440 | Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText ) | ||
441 | |||
442 | public: | ||
443 | /** | ||
444 | * Constructs an input control for double values | ||
445 | * with initial value 0.00. | ||
446 | */ | ||
447 | KDoubleNumInput(QWidget *parent=0, const char *name=0); | ||
448 | |||
449 | /** | ||
450 | * @deprecated (value is rounded to a multiple of 1/100) | ||
451 | * Constructor | ||
452 | * | ||
453 | * @param value initial value for the control | ||
454 | * @param parent parent QWidget | ||
455 | * @param name internal name for this widget | ||
456 | */ | ||
457 | KDoubleNumInput(double value, QWidget *parent=0, const char *name=0); | ||
458 | |||
459 | /** | ||
460 | * Constructor | ||
461 | * | ||
462 | * @param lower lower boundary value | ||
463 | * @param upper upper boundary value | ||
464 | * @param value initial value for the control | ||
465 | * @param step step size to use for up/down arrow clicks | ||
466 | * @param precision number of digits after the decimal point | ||
467 | * @param parent parent QWidget | ||
468 | * @param name internal name for this widget | ||
469 | * @since 3.1 | ||
470 | */ | ||
471 | KDoubleNumInput(double lower, double upper, double value, double step=0.01, | ||
472 | int precision=2, QWidget *parent=0, const char *name=0); | ||
473 | |||
474 | /** | ||
475 | * destructor | ||
476 | */ | ||
477 | virtual ~KDoubleNumInput(); | ||
478 | |||
479 | /** | ||
480 | * @deprecated (rounds @p value to a mulitple of 1/100) | ||
481 | * Constructor | ||
482 | * | ||
483 | * puts it below other KNumInput | ||
484 | * | ||
485 | * @param below | ||
486 | * @param value initial value for the control | ||
487 | * @param parent parent QWidget | ||
488 | * @param name internal name for this widget | ||
489 | **/ | ||
490 | KDoubleNumInput(KNumInput* below, double value, QWidget* parent=0, const char* name=0); | ||
491 | |||
492 | /** | ||
493 | * Constructor | ||
494 | * | ||
495 | * puts it below other KNumInput | ||
496 | * | ||
497 | * @param lower lower boundary value | ||
498 | * @param upper upper boundary value | ||
499 | * @param value initial value for the control | ||
500 | * @param step step size to use for up/down arrow clicks | ||
501 | * @param precision number of digits after the decimal point | ||
502 | * @param parent parent QWidget | ||
503 | * @param name internal name for this widget | ||
504 | * @since 3.1 | ||
505 | */ | ||
506 | KDoubleNumInput(KNumInput* below, | ||
507 | double lower, double upper, double value, double step=0.02, | ||
508 | int precision=2, QWidget *parent=0, const char *name=0); | ||
509 | |||
510 | /** | ||
511 | * @return the current value. | ||
512 | */ | ||
513 | double value() const; | ||
514 | |||
515 | /** | ||
516 | * @return the suffix. | ||
517 | * @see #setSuffix() | ||
518 | */ | ||
519 | QString suffix() const; | ||
520 | |||
521 | /** | ||
522 | * @return the prefix. | ||
523 | * @see #setPrefix() | ||
524 | */ | ||
525 | QString prefix() const; | ||
526 | |||
527 | /** | ||
528 | * @return the precision. | ||
529 | * @see #setPrecision() | ||
530 | */ | ||
531 | int precision() const; | ||
532 | |||
533 | /** | ||
534 | * @return the string displayed for a special value. | ||
535 | * @see #setSpecialValueText() | ||
536 | */ | ||
537 | QString specialValueText() const { return m_specialvalue; } | ||
538 | |||
539 | /** | ||
540 | * @param min minimum value | ||
541 | * @param max maximum value | ||
542 | * @param step step size for the QSlider | ||
543 | */ | ||
544 | void setRange(double min, double max, double step=1, bool slider=true); | ||
545 | /** | ||
546 | * Sets the minimum value. | ||
547 | */ | ||
548 | void setMinValue(double min); | ||
549 | /** | ||
550 | * @return the minimum value. | ||
551 | */ | ||
552 | double minValue() const; | ||
553 | /** | ||
554 | * Sets the maximum value. | ||
555 | */ | ||
556 | void setMaxValue(double max); | ||
557 | /** | ||
558 | * @return the maximum value. | ||
559 | */ | ||
560 | double maxValue() const; | ||
561 | |||
562 | /** | ||
563 | * Specifies the number of digits to use. | ||
564 | */ | ||
565 | void setPrecision(int precision); | ||
566 | |||
567 | /** | ||
568 | * @return the reference point for @ref #relativeValue calculation | ||
569 | * @since 3.1 | ||
570 | */ | ||
571 | double referencePoint() const; | ||
572 | |||
573 | /** | ||
574 | * @return the current value in units of @ref #referencePoint. | ||
575 | * @since 3.1 | ||
576 | */ | ||
577 | double relativeValue() const; | ||
578 | |||
579 | /** | ||
580 | * Sets the special value text. If set, the spin box will display | ||
581 | * this text instead of the numeric value whenever the current | ||
582 | * value is equal to @ref #minVal(). Typically this is used for indicating | ||
583 | * that the choice has a special (default) meaning. | ||
584 | */ | ||
585 | void setSpecialValueText(const QString& text); | ||
586 | |||
587 | /** | ||
588 | * @reimplemented | ||
589 | */ | ||
590 | virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop); | ||
591 | /** | ||
592 | * @reimplemented | ||
593 | */ | ||
594 | virtual QSize minimumSizeHint() const; | ||
595 | /** | ||
596 | * @reimplemented | ||
597 | */ | ||
598 | virtual bool eventFilter(QObject*, QEvent*); | ||
599 | |||
600 | public slots: | ||
601 | /** | ||
602 | * Sets the value of the control. | ||
603 | */ | ||
604 | void setValue(double); | ||
605 | |||
606 | /** | ||
607 | * Sets the value in units of @ref #referencePoint. | ||
608 | * @since 3.1 | ||
609 | */ | ||
610 | void setRelativeValue(double); | ||
611 | |||
612 | /** | ||
613 | * Sets the reference Point to @p ref. It @p ref == 0, emitting of | ||
614 | * @ref #relativeValueChanged is blocked and @ref #relativeValue | ||
615 | * just returns 0. | ||
616 | * @since 3.1 | ||
617 | */ | ||
618 | void setReferencePoint(double ref); | ||
619 | |||
620 | /** | ||
621 | * Sets the suffix to be displayed to @p suffix. Use QString::null to disable | ||
622 | * this feature. Note that the suffix is attached to the value without any | ||
623 | * spacing. So if you prefer to display a space separator, set suffix | ||
624 | * to something like " cm". | ||
625 | * @see #setSuffix() | ||
626 | */ | ||
627 | void setSuffix(const QString &suffix); | ||
628 | |||
629 | /** | ||
630 | * Sets the prefix to be displayed to @p prefix. Use QString::null to disable | ||
631 | * this feature. Note that the prefix is attached to the value without any | ||
632 | * spacing. | ||
633 | * @see #setPrefix() | ||
634 | */ | ||
635 | void setPrefix(const QString &prefix); | ||
636 | |||
637 | signals: | ||
638 | /** | ||
639 | * Emitted every time the value changes (by calling @ref setValue() or | ||
640 | * by user interaction). | ||
641 | */ | ||
642 | void valueChanged(double); | ||
643 | /** | ||
644 | * This is an overloaded member function, provided for | ||
645 | * convenience. It essentially behaves like the above function. | ||
646 | * | ||
647 | * Contains the value in units of @ref #referencePoint. | ||
648 | * @since 3.1 | ||
649 | */ | ||
650 | void relativeValueChanged(double); | ||
651 | |||
652 | private slots: | ||
653 | void sliderMoved(int); | ||
654 | void slotEmitRelativeValueChanged(double); | ||
655 | |||
656 | protected: | ||
657 | |||
658 | /** | ||
659 | * @reimplemented | ||
660 | */ | ||
661 | virtual void doLayout(); | ||
662 | /** | ||
663 | * @reimplemented | ||
664 | */ | ||
665 | void resizeEvent ( QResizeEvent * ); | ||
666 | virtual void resetEditBox(); | ||
667 | |||
668 | // ### no longer used, remove when BIC allowed | ||
669 | KDoubleLine* edit; | ||
670 | |||
671 | bool m_range; | ||
672 | double m_lower, m_upper, m_step; | ||
673 | // ### end no longer used | ||
674 | |||
675 | QSize m_sizeEdit; | ||
676 | |||
677 | friend class KDoubleLine; | ||
678 | private: | ||
679 | void init(double value, double lower, double upper, | ||
680 | double step, int precision); | ||
681 | double mapSliderToSpin(int) const; | ||
682 | void updateLegacyMembers(); | ||
683 | // ### no longer used, remove when BIC allowed: | ||
684 | QString m_specialvalue, m_prefix, m_suffix; | ||
685 | double m_value; | ||
686 | short m_precision; | ||
687 | // ### end remove when BIC allowed | ||
688 | |||
689 | protected: | ||
690 | virtual void virtual_hook( int id, void* data ); | ||
691 | private: | ||
692 | class KDoubleNumInputPrivate; | ||
693 | KDoubleNumInputPrivate *d; | ||
694 | }; | ||
695 | |||
696 | |||
697 | /* ------------------------------------------------------------------------ */ | ||
698 | |||
699 | /** | ||
700 | * A @ref QSpinBox with support for arbitrary base numbers | ||
701 | * (e.g. hexadecimal). | ||
702 | * | ||
703 | * The class provides an easy interface to use other | ||
704 | * numeric systems then the decimal. | ||
705 | * | ||
706 | * @short A @ref QSpinBox with support for arbitrary base numbers. | ||
707 | */ | ||
708 | class KIntSpinBox : public QSpinBox | ||
709 | { | ||
710 | Q_OBJECT | ||
711 | Q_PROPERTY( int base READ base WRITE setBase ) | ||
712 | |||
713 | public: | ||
714 | |||
715 | /** | ||
716 | * Constructor. | ||
717 | * | ||
718 | * Constructs a widget with an integer inputline with a little scrollbar | ||
719 | * and a slider, with minimal value 0, maximal value 99, step 1, base 10 | ||
720 | * and initial value 0. | ||
721 | */ | ||
722 | KIntSpinBox( QWidget *parent=0, const char *name=0); | ||
723 | |||
724 | /** | ||
725 | * Constructor. | ||
726 | * | ||
727 | * Constructs a widget with an integer inputline with a little scrollbar | ||
728 | * and a slider. | ||
729 | * | ||
730 | * @param lower The lowest valid value. | ||
731 | * @param upper The greatest valid value. | ||
732 | * @param step The step size of the scrollbar. | ||
733 | * @param value The actual value. | ||
734 | * @param base The base of the used number system. | ||
735 | * @param parent The parent of the widget. | ||
736 | * @param name The Name of the widget. | ||
737 | */ | ||
738 | KIntSpinBox(int lower, int upper, int step, int value, int base = 10, | ||
739 | QWidget* parent = 0, const char* name = 0); | ||
740 | |||
741 | /** | ||
742 | * Destructor. | ||
743 | */ | ||
744 | virtual ~KIntSpinBox(); | ||
745 | |||
746 | /** | ||
747 | * Sets the base in which the numbers in the spin box are represented. | ||
748 | */ | ||
749 | void setBase(int base); | ||
750 | /** | ||
751 | * @return the base in which numbers in the spin box are represented. | ||
752 | */ | ||
753 | int base() const; | ||
754 | /** | ||
755 | * sets focus and optionally marks all text | ||
756 | * | ||
757 | */ | ||
758 | void setEditFocus(bool mark); | ||
759 | |||
760 | protected: | ||
761 | |||
762 | /** | ||
763 | * Overloaded the method in QSpinBox | ||
764 | * to make use of the base given in the constructor. | ||
765 | */ | ||
766 | virtual QString mapValueToText(int); | ||
767 | |||
768 | /** | ||
769 | * Overloaded the method in QSpinBox | ||
770 | * to make use of the base given in the constructor. | ||
771 | */ | ||
772 | virtual int mapTextToValue(bool*); | ||
773 | |||
774 | private: | ||
775 | int val_base; | ||
776 | protected: | ||
777 | virtual void virtual_hook( int id, void* data ); | ||
778 | private: | ||
779 | class KIntSpinBoxPrivate; | ||
780 | KIntSpinBoxPrivate *d; | ||
781 | }; | ||
782 | |||
783 | |||
784 | /* --------------------------------------------------------------------------- */ | ||
785 | |||
786 | /** | ||
787 | This class provides a spin box for fractional numbers. | ||
788 | |||
789 | @sect Parameters | ||
790 | |||
791 | There are a number of interdependent parameters whose relation to | ||
792 | each other you need to understand in order to make successful use | ||
793 | of the spin box. | ||
794 | |||
795 | @li precision: The number of decimals after the decimal point. | ||
796 | @li maxValue/minValue: upper and lower bound of the valid range | ||
797 | @li lineStep: the size of the step that is taken when the user hits | ||
798 | the up or down buttons | ||
799 | |||
800 | Since we work with fixed-point numbers internally, the maximum | ||
801 | precision is a function of the valid range and vice versa. More | ||
802 | precisely, the following relations hold: | ||
803 | <pre> | ||
804 | max( abs(minValue()), abs(maxValue() ) <= INT_MAX/10^precision | ||
805 | maxPrecision = floor( log10( INT_MAX/max(abs(minValue()),abs(maxValue())) ) ) | ||
806 | </pre> | ||
807 | |||
808 | Since the value, bounds and step are rounded to the current | ||
809 | precision, you may experience that the order of setting above | ||
810 | parameters matters. E.g. the following are @em not equivalent (try | ||
811 | it!): | ||
812 | |||
813 | <pre> | ||
814 | // sets precision, | ||
815 | // then min/max value (rounded to precison and clipped to obtainable range if needed) | ||
816 | // then value and lineStep | ||
817 | KDoubleSpinBox * spin = new KDoubleSpinBox( 0, 9.999, 0.001, 4.321, 3, this ); | ||
818 | |||
819 | // sets minValue to 0; maxValue to 10.00(!); value to 4.32(!) and only then | ||
820 | // increases the precision - too late, since e.g. value has already been rounded... | ||
821 | KDpubleSpinBox * spin = new KDoubleSpinBox( this ); | ||
822 | spin->setMinValue( 0 ); | ||
823 | spin->setMaxValue( 9.999 ); | ||
824 | spin->setValue( 4.321 ); | ||
825 | spin->setPrecision( 3 ); | ||
826 | </pre> | ||
827 | |||
828 | @short A spin box for fractional numbers. | ||
829 | @author Marc Mutz <mutz@kde.org> | ||
830 | @version $Id$ | ||
831 | @since 3.1 | ||
832 | **/ | ||
833 | |||
834 | class KDoubleSpinBox : public QSpinBox { | ||
835 | Q_OBJECT | ||
836 | Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers ) | ||
837 | Q_OVERRIDE( double maxValue READ maxValue WRITE setMaxValue ) | ||
838 | Q_OVERRIDE( double minValue READ minValue WRITE setMinValue ) | ||
839 | Q_OVERRIDE( double lineStep READ lineStep WRITE setLineStep ) | ||
840 | Q_OVERRIDE( double value READ value WRITE setValue ) | ||
841 | Q_PROPERTY( int precision READ precision WRITE setPrecision ) | ||
842 | |||
843 | public: | ||
844 | /** Constructs a @ref KDoubleSpinBox with parent @p parent and | ||
845 | default values for range and value (whatever @ref QRangeControl | ||
846 | uses) and precision (2). */ | ||
847 | KDoubleSpinBox( QWidget * parent=0, const char * name=0 ); | ||
848 | /** Constructs a @ref KDoubleSpinBox with parent @p parent, range | ||
849 | [@p lower,@p upper], @ref lineStep @p step, @ref precision @p | ||
850 | precision and initial value @p value. */ | ||
851 | KDoubleSpinBox( double lower, double upper, double step, double value, | ||
852 | int precision=2, QWidget * parent=0, const char * name=0 ); | ||
853 | |||
854 | virtual ~KDoubleSpinBox(); | ||
855 | |||
856 | /** @return whether the spinbox uses localized numbers */ | ||
857 | bool acceptLocalizedNumbers() const; | ||
858 | /** Sets whether to use and accept localized numbers as returned by | ||
859 | @ref KLocale::formatNumber() */ | ||
860 | virtual void setAcceptLocalizedNumbers( bool accept ); | ||
861 | |||
862 | /** Sets a new range for the spin box values. Note that @p lower, @p | ||
863 | upper and @p step are rounded to @p precision decimal points | ||
864 | first. */ | ||
865 | void setRange( double lower, double upper, double step=0.01, int precision=2 ); | ||
866 | |||
867 | /** @return the current number of decimal points displayed. */ | ||
868 | int precision() const; | ||
869 | /** Equivalent to @ref setPrecsion( @p precison, @p false ); Needed | ||
870 | since Qt's moc doesn't ignore trailing parameters with default | ||
871 | args when searching for a property setter method. */ | ||
872 | void setPrecision( int precision ); | ||
873 | /** Sets the number of decimal points to use. Note that there is a | ||
874 | tradeoff between the precision used and the available range of | ||
875 | values. See the class docs for more. | ||
876 | @param precision the new number of decimal points to use | ||
877 | |||
878 | @param force disables checking of bound violations that can | ||
879 | arise if you increase the precision so much that the | ||
880 | minimum and maximum values can't be represented | ||
881 | anymore. Disabling is useful if you don't want to keep | ||
882 | the current min and max values anyway. This is what | ||
883 | e.g. @ref setRange() does. | ||
884 | **/ | ||
885 | virtual void setPrecision( int precision, bool force ); | ||
886 | |||
887 | /** @return the current value */ | ||
888 | double value() const; | ||
889 | /** @return the current lower bound */ | ||
890 | double minValue() const; | ||
891 | /** Sets the lower bound of the range to @p value, subject to the | ||
892 | contraints that @p value is first rounded to the current | ||
893 | precision and then clipped to the maximum representable | ||
894 | interval. | ||
895 | @see maxValue, minValue, setMaxValue, setRange | ||
896 | */ | ||
897 | void setMinValue( double value ); | ||
898 | /** @return the current upper bound */ | ||
899 | double maxValue() const; | ||
900 | /** Sets the upper bound of the range to @p value, subject to the | ||
901 | contraints that @p value is first rounded to the current | ||
902 | precision and then clipped to the maximum representable | ||
903 | interval. | ||
904 | @see minValue, maxValue, setMinValue, setRange | ||
905 | */ | ||
906 | void setMaxValue( double value ); | ||
907 | |||
908 | /** @return the current step size */ | ||
909 | double lineStep() const; | ||
910 | /** Sets the step size for clicking the up/down buttons to @p step, | ||
911 | subject to the constraints that @p step is first rounded to the | ||
912 | current precision and then clipped to the meaningful interval | ||
913 | [1, @p maxValue - @p minValue]. */ | ||
914 | void setLineStep( double step ); | ||
915 | |||
916 | /** Overridden to ignore any setValidator() calls. */ | ||
917 | void setValidator( const QValidator * ); | ||
918 | |||
919 | signals: | ||
920 | /** Emitted whenever @ref QSpinBox::valueChanged( int ) is emitted. */ | ||
921 | void valueChanged( double value ); | ||
922 | |||
923 | public slots: | ||
924 | /** Sets the current value to @p value, cubject to the constraints | ||
925 | that @p value is frist rounded to the current precision and then | ||
926 | clipped to the interval [@p minvalue(),@p maxValue()]. */ | ||
927 | virtual void setValue( double value ); | ||
928 | |||
929 | protected: | ||
930 | virtual QString mapValueToText(int); | ||
931 | virtual int mapTextToValue(bool*); | ||
932 | |||
933 | protected slots: | ||
934 | void slotValueChanged( int value ); | ||
935 | |||
936 | protected: | ||
937 | virtual void virtual_hook( int id, void* data ); | ||
938 | private: | ||
939 | typedef QSpinBox base; | ||
940 | void updateValidator(); | ||
941 | int maxPrecision() const; | ||
942 | |||
943 | class Private; | ||
944 | Private * d; | ||
945 | }; | ||
946 | |||
947 | #endif // K_NUMINPUT_H | ||
diff --git a/noncore/settings/networksettings/ppp/knumvalidator.cpp b/noncore/settings/networksettings/ppp/knumvalidator.cpp new file mode 100644 index 0000000..44f7a60 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/knumvalidator.cpp | |||
@@ -0,0 +1,376 @@ | |||
1 | /********************************************************************** | ||
2 | ** | ||
3 | ** $Id$ | ||
4 | ** | ||
5 | ** KIntValidator, KFloatValidator: | ||
6 | ** Copyright (C) 1999 Glen Parker <glenebob@nwlink.com> | ||
7 | ** KDoubleValidator: | ||
8 | ** Copyright (c) 2002 Marc Mutz <mutz@kde.org> | ||
9 | ** | ||
10 | ** This library is free software; you can redistribute it and/or | ||
11 | ** modify it under the terms of the GNU Library General Public | ||
12 | ** License as published by the Free Software Foundation; either | ||
13 | ** version 2 of the License, or (at your option) any later version. | ||
14 | ** | ||
15 | ** This library is distributed in the hope that it will be useful, | ||
16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | ** Library General Public License for more details. | ||
19 | ** | ||
20 | ** You should have received a copy of the GNU Library General Public | ||
21 | ** License along with this library; if not, write to the Free | ||
22 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | ** | ||
24 | *****************************************************************************/ | ||
25 | |||
26 | #include <qwidget.h> | ||
27 | #include <qstring.h> | ||
28 | |||
29 | #include "knumvalidator.h" | ||
30 | //#include <klocale.h> | ||
31 | #define i18n QObject::tr | ||
32 | //#include <kglobal.h> | ||
33 | //#include <kdebug.h> | ||
34 | |||
35 | /////////////////////////////////////////////////////////////// | ||
36 | // Implementation of KIntValidator | ||
37 | // | ||
38 | |||
39 | KIntValidator::KIntValidator ( QWidget * parent, int base, const char * name ) | ||
40 | : QValidator(parent, name) | ||
41 | { | ||
42 | _base = base; | ||
43 | if (_base < 2) _base = 2; | ||
44 | if (_base > 36) _base = 36; | ||
45 | |||
46 | _min = _max = 0; | ||
47 | } | ||
48 | |||
49 | KIntValidator::KIntValidator ( int bottom, int top, QWidget * parent, int base, const char * name ) | ||
50 | : QValidator(parent, name) | ||
51 | { | ||
52 | _base = base; | ||
53 | if (_base > 36) _base = 36; | ||
54 | |||
55 | _min = bottom; | ||
56 | _max = top; | ||
57 | } | ||
58 | |||
59 | KIntValidator::~KIntValidator () | ||
60 | {} | ||
61 | |||
62 | QValidator::State KIntValidator::validate ( QString &str, int & ) const | ||
63 | { | ||
64 | bool ok; | ||
65 | int val = 0; | ||
66 | QString newStr; | ||
67 | |||
68 | newStr = str.stripWhiteSpace(); | ||
69 | if (_base > 10) | ||
70 | newStr = newStr.upper(); | ||
71 | |||
72 | if (newStr == QString::fromLatin1("-")) // a special case | ||
73 | if ((_min || _max) && _min >= 0) | ||
74 | ok = false; | ||
75 | else | ||
76 | return QValidator::Acceptable; | ||
77 | else if (newStr.length()) | ||
78 | val = newStr.toInt(&ok, _base); | ||
79 | else { | ||
80 | val = 0; | ||
81 | ok = true; | ||
82 | } | ||
83 | |||
84 | if (! ok) | ||
85 | return QValidator::Invalid; | ||
86 | |||
87 | if ((! _min && ! _max) || (val >= _min && val <= _max)) | ||
88 | return QValidator::Acceptable; | ||
89 | |||
90 | if (_max && _min >= 0 && val < 0) | ||
91 | return QValidator::Invalid; | ||
92 | |||
93 | return QValidator::Valid; | ||
94 | } | ||
95 | |||
96 | void KIntValidator::fixup ( QString &str ) const | ||
97 | { | ||
98 | int dummy; | ||
99 | int val; | ||
100 | QValidator::State state; | ||
101 | |||
102 | state = validate(str, dummy); | ||
103 | |||
104 | if (state == QValidator::Invalid || state == QValidator::Acceptable) | ||
105 | return; | ||
106 | |||
107 | if (! _min && ! _max) | ||
108 | return; | ||
109 | |||
110 | val = str.toInt(0, _base); | ||
111 | |||
112 | if (val < _min) val = _min; | ||
113 | if (val > _max) val = _max; | ||
114 | |||
115 | str.setNum(val, _base); | ||
116 | } | ||
117 | |||
118 | void KIntValidator::setRange ( int bottom, int top ) | ||
119 | { | ||
120 | _min = bottom; | ||
121 | _max = top; | ||
122 | |||
123 | if (_max < _min) | ||
124 | _max = _min; | ||
125 | } | ||
126 | |||
127 | void KIntValidator::setBase ( int base ) | ||
128 | { | ||
129 | _base = base; | ||
130 | if (_base < 2) _base = 2; | ||
131 | } | ||
132 | |||
133 | int KIntValidator::bottom () const | ||
134 | { | ||
135 | return _min; | ||
136 | } | ||
137 | |||
138 | int KIntValidator::top () const | ||
139 | { | ||
140 | return _max; | ||
141 | } | ||
142 | |||
143 | int KIntValidator::base () const | ||
144 | { | ||
145 | return _base; | ||
146 | } | ||
147 | |||
148 | |||
149 | /////////////////////////////////////////////////////////////// | ||
150 | // Implementation of KFloatValidator | ||
151 | // | ||
152 | |||
153 | class KFloatValidatorPrivate | ||
154 | { | ||
155 | public: | ||
156 | KFloatValidatorPrivate() | ||
157 | { | ||
158 | } | ||
159 | ~KFloatValidatorPrivate() | ||
160 | { | ||
161 | } | ||
162 | bool acceptLocalizedNumbers; | ||
163 | }; | ||
164 | |||
165 | |||
166 | KFloatValidator::KFloatValidator ( QWidget * parent, const char * name ) | ||
167 | : QValidator(parent, name) | ||
168 | { | ||
169 | d = new KFloatValidatorPrivate; | ||
170 | d->acceptLocalizedNumbers=false; | ||
171 | _min = _max = 0; | ||
172 | } | ||
173 | |||
174 | KFloatValidator::KFloatValidator ( double bottom, double top, QWidget * parent, const char * name ) | ||
175 | : QValidator(parent, name) | ||
176 | { | ||
177 | d = new KFloatValidatorPrivate; | ||
178 | d->acceptLocalizedNumbers=false; | ||
179 | _min = bottom; | ||
180 | _max = top; | ||
181 | } | ||
182 | |||
183 | KFloatValidator::KFloatValidator ( double bottom, double top, bool localeAware, QWidget * parent, const char * name ) | ||
184 | : QValidator(parent, name) | ||
185 | { | ||
186 | d = new KFloatValidatorPrivate; | ||
187 | d->acceptLocalizedNumbers = localeAware; | ||
188 | _min = bottom; | ||
189 | _max = top; | ||
190 | } | ||
191 | |||
192 | KFloatValidator::~KFloatValidator () | ||
193 | { | ||
194 | delete d; | ||
195 | } | ||
196 | |||
197 | void KFloatValidator::setAcceptLocalizedNumbers(bool _b) | ||
198 | { | ||
199 | d->acceptLocalizedNumbers=_b; | ||
200 | } | ||
201 | |||
202 | bool KFloatValidator::acceptLocalizedNumbers() const | ||
203 | { | ||
204 | return d->acceptLocalizedNumbers; | ||
205 | } | ||
206 | |||
207 | //#include <kdebug.h> | ||
208 | QValidator::State KFloatValidator::validate ( QString &str, int & ) const | ||
209 | { | ||
210 | bool ok; | ||
211 | double val = 0; | ||
212 | QString newStr; | ||
213 | newStr = str.stripWhiteSpace(); | ||
214 | |||
215 | if (newStr == QString::fromLatin1("-")) // a special case | ||
216 | if ((_min || _max) && _min >= 0) | ||
217 | ok = false; | ||
218 | else | ||
219 | return QValidator::Acceptable; | ||
220 | else if (newStr == QString::fromLatin1(".") ) // FIXME :|| (d->acceptLocalizedNumbers && newStr==KGlobal::locale()->decimalSymbol())) // another special case | ||
221 | return QValidator::Acceptable; | ||
222 | else if (newStr.length()) | ||
223 | { | ||
224 | val = newStr.toDouble(&ok); | ||
225 | // if(!ok && d->acceptLocalizedNumbers) | ||
226 | // val= KGlobal::locale()->readNumber(newStr,&ok); | ||
227 | } | ||
228 | else { | ||
229 | val = 0; | ||
230 | ok = true; | ||
231 | } | ||
232 | |||
233 | if (! ok) | ||
234 | return QValidator::Invalid; | ||
235 | |||
236 | if (( !_min && !_max) || (val >= _min && val <= _max)) | ||
237 | return QValidator::Acceptable; | ||
238 | |||
239 | if (_max && _min >= 0 && val < 0) | ||
240 | return QValidator::Invalid; | ||
241 | |||
242 | if ( (_min || _max) && (val < _min || val > _max)) | ||
243 | return QValidator::Invalid; | ||
244 | |||
245 | return QValidator::Valid; | ||
246 | } | ||
247 | |||
248 | void KFloatValidator::fixup ( QString &str ) const | ||
249 | { | ||
250 | int dummy; | ||
251 | double val; | ||
252 | QValidator::State state; | ||
253 | |||
254 | state = validate(str, dummy); | ||
255 | |||
256 | if (state == QValidator::Invalid || state == QValidator::Acceptable) | ||
257 | return; | ||
258 | |||
259 | if (! _min && ! _max) | ||
260 | return; | ||
261 | |||
262 | val = str.toDouble(); | ||
263 | |||
264 | if (val < _min) val = _min; | ||
265 | if (val > _max) val = _max; | ||
266 | |||
267 | str.setNum(val); | ||
268 | } | ||
269 | |||
270 | void KFloatValidator::setRange ( double bottom, double top ) | ||
271 | { | ||
272 | _min = bottom; | ||
273 | _max = top; | ||
274 | |||
275 | if (_max < _min) | ||
276 | _max = _min; | ||
277 | } | ||
278 | |||
279 | double KFloatValidator::bottom () const | ||
280 | { | ||
281 | return _min; | ||
282 | } | ||
283 | |||
284 | double KFloatValidator::top () const | ||
285 | { | ||
286 | return _max; | ||
287 | } | ||
288 | |||
289 | |||
290 | |||
291 | |||
292 | /////////////////////////////////////////////////////////////// | ||
293 | // Implementation of KDoubleValidator | ||
294 | // | ||
295 | |||
296 | class KDoubleValidator::Private { | ||
297 | public: | ||
298 | Private( bool accept=false ) : acceptLocalizedNumbers( accept ) {} | ||
299 | |||
300 | bool acceptLocalizedNumbers; | ||
301 | }; | ||
302 | |||
303 | //KDoubleValidator::KDoubleValidator( QObject * parent, const char * name ) | ||
304 | KDoubleValidator::KDoubleValidator( QWidget * parent, const char * name ) | ||
305 | : QDoubleValidator( parent, name ), d( 0 ) | ||
306 | { | ||
307 | d = new Private(); | ||
308 | } | ||
309 | |||
310 | KDoubleValidator::KDoubleValidator( double bottom, double top, int decimals, | ||
311 | // QObject * parent, const char * name ) | ||
312 | QWidget * parent, const char * name ) | ||
313 | : QDoubleValidator( bottom, top, decimals, parent, name ), d( 0 ) | ||
314 | { | ||
315 | d = new Private(); | ||
316 | } | ||
317 | |||
318 | KDoubleValidator::~KDoubleValidator() | ||
319 | { | ||
320 | delete d; | ||
321 | } | ||
322 | |||
323 | bool KDoubleValidator::acceptLocalizedNumbers() const { | ||
324 | return d->acceptLocalizedNumbers; | ||
325 | } | ||
326 | |||
327 | void KDoubleValidator::setAcceptLocalizedNumbers( bool accept ) { | ||
328 | d->acceptLocalizedNumbers = accept; | ||
329 | } | ||
330 | |||
331 | QValidator::State KDoubleValidator::validate( QString & input, int & p ) const { | ||
332 | QString s = input; | ||
333 | if ( acceptLocalizedNumbers() ) { | ||
334 | // KLocale * l = KGlobal::locale(); | ||
335 | // ok, we have to re-format the number to have: | ||
336 | // 1. decimalSymbol == '.' | ||
337 | // 2. negativeSign == '-' | ||
338 | // 3. positiveSign == <empty> | ||
339 | // 4. thousandsSeparator() == <empty> (we don't check that there | ||
340 | // are exactly three decimals between each separator): | ||
341 | QString d = ".",//l->decimalSymbol(), | ||
342 | n = "-",//l->negativeSign(), | ||
343 | p = "", //l->positiveSign(), | ||
344 | t = "";//l->thousandsSeparator(); | ||
345 | // first, delete p's and t's: | ||
346 | if ( !p.isEmpty() ) | ||
347 | for ( int idx = s.find( p ) ; idx >= 0 ; idx = s.find( p, idx ) ) | ||
348 | s.remove( idx, p.length() ); | ||
349 | |||
350 | |||
351 | if ( !t.isEmpty() ) | ||
352 | for ( int idx = s.find( t ) ; idx >= 0 ; idx = s.find( t, idx ) ) | ||
353 | s.remove( idx, t.length() ); | ||
354 | |||
355 | // then, replace the d's and n's | ||
356 | if ( ( !n.isEmpty() && n.find('.') != -1 ) || | ||
357 | ( !d.isEmpty() && d.find('-') != -1 ) ) { | ||
358 | // make sure we don't replace something twice: | ||
359 | // kdWarning() << "KDoubleValidator: decimal symbol contains '-' or " | ||
360 | // "negative sign contains '.' -> improve algorithm" << endl; | ||
361 | return Invalid; | ||
362 | } | ||
363 | |||
364 | if ( !d.isEmpty() && d != "." ) | ||
365 | for ( int idx = s.find( d ) ; idx >= 0 ; idx = s.find( d, idx + 1 ) ) | ||
366 | s.replace( idx, d.length(), "."); | ||
367 | |||
368 | if ( !n.isEmpty() && n != "-" ) | ||
369 | for ( int idx = s.find( n ) ; idx >= 0 ; idx = s.find( n, idx + 1 ) ) | ||
370 | s.replace( idx, n.length(), "-" ); | ||
371 | } | ||
372 | |||
373 | return base::validate( s, p ); | ||
374 | } | ||
375 | |||
376 | //#include "knumvalidator.moc" | ||
diff --git a/noncore/settings/networksettings/ppp/knumvalidator.h b/noncore/settings/networksettings/ppp/knumvalidator.h new file mode 100644 index 0000000..c95293a --- a/dev/null +++ b/noncore/settings/networksettings/ppp/knumvalidator.h | |||
@@ -0,0 +1,211 @@ | |||
1 | /********************************************************************** | ||
2 | ** | ||
3 | ** $Id$ | ||
4 | ** | ||
5 | ** Copyright (C) 1999 Glen Parker <glenebob@nwlink.com> | ||
6 | ** Copyright (C) 2002 Marc Mutz <mutz@kde.org> | ||
7 | ** | ||
8 | ** This library is free software; you can redistribute it and/or | ||
9 | ** modify it under the terms of the GNU Library General Public | ||
10 | ** License as published by the Free Software Foundation; either | ||
11 | ** version 2 of the License, or (at your option) any later version. | ||
12 | ** | ||
13 | ** This library is distributed in the hope that it will be useful, | ||
14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | ** Library General Public License for more details. | ||
17 | ** | ||
18 | ** You should have received a copy of the GNU Library General Public | ||
19 | ** License along with this library; if not, write to the Free | ||
20 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | ** | ||
22 | *****************************************************************************/ | ||
23 | |||
24 | #ifndef __KNUMVALIDATOR_H | ||
25 | #define __KNUMVALIDATOR_H | ||
26 | |||
27 | #include <qvalidator.h> | ||
28 | |||
29 | class QWidget; | ||
30 | class QString; | ||
31 | |||
32 | /** | ||
33 | * @ref QValidator for integers. | ||
34 | |||
35 | This can be used by @ref QLineEdit or subclass to provide validated | ||
36 | text entry. Can be provided with a base value (default is 10), to allow | ||
37 | the proper entry of hexadecimal, octal, or any other base numeric data. | ||
38 | |||
39 | @author Glen Parker <glenebob@nwlink.com> | ||
40 | @version 0.0.1 | ||
41 | */ | ||
42 | class KIntValidator : public QValidator { | ||
43 | |||
44 | public: | ||
45 | /** | ||
46 | Constuctor. Also sets the base value. | ||
47 | */ | ||
48 | KIntValidator ( QWidget * parent, int base = 10, const char * name = 0 ); | ||
49 | /** | ||
50 | * Constructor. Also sets the minimum, maximum, and numeric base values. | ||
51 | */ | ||
52 | KIntValidator ( int bottom, int top, QWidget * parent, int base = 10, const char * name = 0 ); | ||
53 | /** | ||
54 | * Destructs the validator. | ||
55 | */ | ||
56 | virtual ~KIntValidator (); | ||
57 | /** | ||
58 | * Validates the text, and return the result. Does not modify the parameters. | ||
59 | */ | ||
60 | virtual State validate ( QString &, int & ) const; | ||
61 | /** | ||
62 | * Fixes the text if possible, providing a valid string. The parameter may be modified. | ||
63 | */ | ||
64 | virtual void fixup ( QString & ) const; | ||
65 | /** | ||
66 | * Sets the minimum and maximum values allowed. | ||
67 | */ | ||
68 | virtual void setRange ( int bottom, int top ); | ||
69 | /** | ||
70 | * Sets the numeric base value. | ||
71 | */ | ||
72 | virtual void setBase ( int base ); | ||
73 | /** | ||
74 | * Returns the current minimum value allowed. | ||
75 | */ | ||
76 | virtual int bottom () const; | ||
77 | /** | ||
78 | * Returns the current maximum value allowed. | ||
79 | */ | ||
80 | virtual int top () const; | ||
81 | /** | ||
82 | * Returns the current numeric base. | ||
83 | */ | ||
84 | virtual int base () const; | ||
85 | |||
86 | private: | ||
87 | int _base; | ||
88 | int _min; | ||
89 | int _max; | ||
90 | |||
91 | }; | ||
92 | |||
93 | class KFloatValidatorPrivate; | ||
94 | |||
95 | /** | ||
96 | @obsolete Use @ref KDoubleValidator | ||
97 | |||
98 | @ref QValidator for floating point entry. | ||
99 | Extends the QValidator class to properly validate double numeric data. | ||
100 | This can be used by @ref QLineEdit or subclass to provide validated | ||
101 | text entry. | ||
102 | |||
103 | @author Glen Parker <glenebob@nwlink.com> | ||
104 | @version 0.0.1 | ||
105 | */ | ||
106 | class KFloatValidator : public QValidator { | ||
107 | |||
108 | public: | ||
109 | /** | ||
110 | * Constructor. | ||
111 | */ | ||
112 | KFloatValidator ( QWidget * parent, const char * name = 0 ); | ||
113 | /** | ||
114 | * Constructor. Also sets the minimum and maximum values. | ||
115 | */ | ||
116 | KFloatValidator ( double bottom, double top, QWidget * parent, const char * name = 0 ); | ||
117 | /** | ||
118 | * Constructor. Sets the validator to be locale aware if @p localeAware is true. | ||
119 | */ | ||
120 | KFloatValidator ( double bottom, double top, bool localeAware, QWidget * parent, const char * name = 0 ); | ||
121 | /** | ||
122 | * Destructs the validator. | ||
123 | */ | ||
124 | virtual ~KFloatValidator (); | ||
125 | /** | ||
126 | * Validates the text, and return the result. Does not modify the parameters. | ||
127 | */ | ||
128 | virtual State validate ( QString &, int & ) const; | ||
129 | /** | ||
130 | * Fixes the text if possible, providing a valid string. The parameter may be modified. | ||
131 | */ | ||
132 | virtual void fixup ( QString & ) const; | ||
133 | /** | ||
134 | * Sets the minimum and maximum value allowed. | ||
135 | */ | ||
136 | virtual void setRange ( double bottom, double top ); | ||
137 | /** | ||
138 | * Returns the current minimum value allowed. | ||
139 | */ | ||
140 | virtual double bottom () const; | ||
141 | /** | ||
142 | * Returns the current maximum value allowed. | ||
143 | */ | ||
144 | virtual double top () const; | ||
145 | /** | ||
146 | * Sets the validator to be locale aware if @p is true. In this case, the | ||
147 | * character KLocale::decimalSymbol() from the global locale is recognized | ||
148 | * as decimal separator. | ||
149 | */ | ||
150 | void setAcceptLocalizedNumbers(bool b); | ||
151 | /** | ||
152 | * Returns true if the validator is locale aware. | ||
153 | * @see setAcceptLocalizedNumbers(). | ||
154 | */ | ||
155 | bool acceptLocalizedNumbers() const; | ||
156 | |||
157 | private: | ||
158 | double _min; | ||
159 | double _max; | ||
160 | |||
161 | KFloatValidatorPrivate *d; | ||
162 | }; | ||
163 | |||
164 | /** | ||
165 | KDoubleValidator extends @ref QDoubleValidator to be | ||
166 | locale-aware. That means that - subject to not being disabled - | ||
167 | @ref KLocale::decimalPoint(), @ref KLocale::thousandsSeparator() | ||
168 | and @ref KLocale::positiveSign() and @ref KLocale::negativeSign() | ||
169 | are respected. | ||
170 | |||
171 | @short A locale-aware @ref QDoubleValidator | ||
172 | @author Marc Mutz <mutz@kde.org> | ||
173 | @version $Id$ | ||
174 | @see KIntValidator | ||
175 | @since 3.1 | ||
176 | **/ | ||
177 | |||
178 | class KDoubleValidator : public QDoubleValidator { | ||
179 | Q_OBJECT | ||
180 | Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers ) | ||
181 | public: | ||
182 | /** Constuct a locale-aware KDoubleValidator with default range | ||
183 | (whatever @ref QDoubleValidator uses for that) and parent @p | ||
184 | parent */ | ||
185 | // KDoubleValidator( QObject * parent, const char * name=0 ); | ||
186 | KDoubleValidator( QWidget * parent, const char * name=0 ); | ||
187 | /** Constuct a locale-aware KDoubleValidator for range [@p bottom,@p | ||
188 | top] and a precision of @p decimals decimals after the decimal | ||
189 | point. */ | ||
190 | KDoubleValidator( double bottom, double top, int decimals, | ||
191 | QWidget * parent, const char * name=0 ); | ||
192 | // QObject * parent, const char * name=0 ); | ||
193 | /** Destructs the validator. | ||
194 | */ | ||
195 | virtual ~KDoubleValidator(); | ||
196 | |||
197 | /** Overloaded for internal reasons. The API is not affected. */ | ||
198 | virtual QValidator::State validate( QString & input, int & pos ) const; | ||
199 | |||
200 | /** @return whether localized numbers are accepted (default: true) */ | ||
201 | bool acceptLocalizedNumbers() const; | ||
202 | /** Sets whether to accept localized numbers (default: true) */ | ||
203 | void setAcceptLocalizedNumbers( bool accept ); | ||
204 | |||
205 | private: | ||
206 | typedef QDoubleValidator base; | ||
207 | class Private; | ||
208 | Private * d; | ||
209 | }; | ||
210 | |||
211 | #endif | ||
diff --git a/noncore/settings/networksettings/ppp/kpppwidget.cpp b/noncore/settings/networksettings/ppp/kpppwidget.cpp new file mode 100644 index 0000000..2f9feda --- a/dev/null +++ b/noncore/settings/networksettings/ppp/kpppwidget.cpp | |||
@@ -0,0 +1,905 @@ | |||
1 | /* | ||
2 | * | ||
3 | * kPPP: A pppd front end for the KDE project | ||
4 | * | ||
5 | * $Id$ | ||
6 | * | ||
7 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
8 | * wuebben@math.cornell.edu | ||
9 | * | ||
10 | * Copyright (C) 1998-2002 Harri Porten <porten@kde.org> | ||
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 "kpppwidget.h" | ||
28 | |||
29 | #include <qapplication.h> | ||
30 | #include <qcombobox.h> | ||
31 | #include <qdir.h> | ||
32 | #include <qevent.h> | ||
33 | #include <qdialog.h> | ||
34 | #include <qlabel.h> | ||
35 | #include <qpushbutton.h> | ||
36 | #include <qregexp.h> | ||
37 | #include <qtabwidget.h> | ||
38 | #include <qdialog.h> | ||
39 | #include <qwhatsthis.h> | ||
40 | |||
41 | // #include <kaboutdata.h> | ||
42 | // #include <kapplication.h> | ||
43 | #include <qbuttongroup.h> | ||
44 | //#include <kcmdlineargs.h> | ||
45 | //#include <kconfig.h> | ||
46 | //#include <kdebug.h> | ||
47 | #define i18n QObject::tr | ||
48 | //#include <kiconloader.h> // For BarIcon | ||
49 | //#include <klocale.h> | ||
50 | #include <qmessagebox.h> | ||
51 | // #include <kseparator.h> | ||
52 | // #include <kstandarddirs.h> | ||
53 | // #include <kwin.h> | ||
54 | // #include <khelpmenu.h> | ||
55 | #include <qpushbutton.h> | ||
56 | //#include <kguiitem.h> | ||
57 | |||
58 | #include <stdlib.h> | ||
59 | #include <errno.h> | ||
60 | #include <signal.h> | ||
61 | |||
62 | #include "runtests.h" | ||
63 | |||
64 | //#include "main.h" | ||
65 | #include "auth.h" | ||
66 | #include "modem.h" | ||
67 | //#include "ppplog.h" | ||
68 | //#include "opener.h" | ||
69 | //#include "requester.h" | ||
70 | //#include "pppstats.h" | ||
71 | #include "pppdata.h" | ||
72 | #include "general.h" | ||
73 | |||
74 | #define execute_command system | ||
75 | |||
76 | KPPPWidget *p_kppp = 0; | ||
77 | |||
78 | KPPPWidget::KPPPWidget( QWidget *parent, const char *name, bool modal, WFlags fl ) | ||
79 | : QDialog(parent, name, modal, fl) | ||
80 | // , acct(0) | ||
81 | // , m_bCmdlAccount (false) | ||
82 | { | ||
83 | // tabWindow = 0; | ||
84 | p_kppp = this; | ||
85 | // before doing anything else, run a few tests | ||
86 | |||
87 | int result = runTests(); | ||
88 | if(result == TEST_CRITICAL) | ||
89 | exit(4); | ||
90 | |||
91 | // installEventFilter(this); | ||
92 | |||
93 | // QVBoxLayout *tl = new QVBoxLayout(this, 10, 10); | ||
94 | |||
95 | // QGridLayout *l1 = new QGridLayout(3, 4); | ||
96 | // tl->addLayout(l1); | ||
97 | // l1->addColSpacing(0, 10); | ||
98 | // l1->addColSpacing(3, 10); | ||
99 | // l1->setColStretch(1, 3); | ||
100 | // l1->setColStretch(2, 4); | ||
101 | |||
102 | // label1 = new QLabel(i18n("C&onnect to: "), this); | ||
103 | // l1->addWidget(label1, 0, 1); | ||
104 | |||
105 | // connectto_c = new QComboBox(false, this); | ||
106 | // label1->setBuddy(connectto_c); | ||
107 | |||
108 | // connect(connectto_c, SIGNAL(activated(int)), | ||
109 | // SLOT(newdefaultaccount(int))); | ||
110 | // l1->addWidget(connectto_c, 0, 2); | ||
111 | |||
112 | // ID_Label = new QLabel(i18n("&Login ID:"), this); | ||
113 | // l1->addWidget(ID_Label, 1, 1); | ||
114 | |||
115 | // // the entry line for usernames | ||
116 | // ID_Edit = new QLineEdit(this); | ||
117 | // ID_Label->setBuddy(ID_Edit); | ||
118 | // l1->addWidget(ID_Edit, 1, 2); | ||
119 | // connect(ID_Edit, SIGNAL(returnPressed()), | ||
120 | // this, SLOT(enterPressedInID())); | ||
121 | // QString tmp = i18n("<p>Type in the username that you got from your\n" | ||
122 | // "ISP. This is especially important for PAP\n" | ||
123 | // "and CHAP. You may omit this when you use\n" | ||
124 | // "terminal-based or script-based authentication.\n" | ||
125 | // "\n" | ||
126 | // "<b>Important</b>: case is important here:\n" | ||
127 | // "<i>myusername</i> is not the same as <i>MyUserName</i>!"); | ||
128 | |||
129 | // QWhatsThis::add(ID_Label,tmp); | ||
130 | // QWhatsThis::add(ID_Edit,tmp); | ||
131 | |||
132 | // PW_Label = new QLabel(i18n("&Password:"), this); | ||
133 | // l1->addWidget(PW_Label, 2, 1); | ||
134 | |||
135 | // PW_Edit= new QLineEdit(this); | ||
136 | // PW_Label->setBuddy(PW_Edit); | ||
137 | // PW_Edit->setEchoMode(QLineEdit::Password); | ||
138 | // l1->addWidget(PW_Edit, 2, 2); | ||
139 | // connect(PW_Edit, SIGNAL(returnPressed()), | ||
140 | // this, SLOT(enterPressedInPW())); | ||
141 | |||
142 | // tmp = i18n("<p>Type in the password that you got from your\n" | ||
143 | // "ISP. This is especially important for PAP\n" | ||
144 | // "and CHAP. You may omit this when you use\n" | ||
145 | // "terminal-based or script-based authentication.\n" | ||
146 | // "\n" | ||
147 | // "<b>Important</b>: case is important here:\n" | ||
148 | // "<i>mypassword</i> is not the same as <i>MyPassword</i>!"); | ||
149 | |||
150 | // QWhatsThis::add(PW_Label,tmp); | ||
151 | // QWhatsThis::add(PW_Edit,tmp); | ||
152 | |||
153 | // QHBoxLayout *l3 = new QHBoxLayout; | ||
154 | // tl->addSpacing(5); | ||
155 | // tl->addLayout(l3); | ||
156 | // tl->addSpacing(5); | ||
157 | // l3->addSpacing(10); | ||
158 | // log = new QCheckBox(i18n("Show lo&g window"), this); | ||
159 | // connect(log, SIGNAL(toggled(bool)), | ||
160 | // this, SLOT(log_window_toggled(bool))); | ||
161 | // log->setChecked(gpppdata.get_show_log_window()); | ||
162 | // l3->addWidget(log); | ||
163 | |||
164 | // QWhatsThis::add(log, | ||
165 | // i18n("<p>This controls whether a log window is shown.\n" | ||
166 | // "A log window shows the communication between\n" | ||
167 | // "<i>kppp</i> and your modem. This will help you\n" | ||
168 | // "in tracking down problems.\n" | ||
169 | // "\n" | ||
170 | // "Turn it off if <i>kppp</i> routinely connects without\n" | ||
171 | // "problems")); | ||
172 | |||
173 | // // fline = new QSeparator( KSeparator::HLine, this); | ||
174 | // // tl->addWidget(fline); | ||
175 | |||
176 | // QHBoxLayout *l2 = new QHBoxLayout(this); | ||
177 | // tl->addLayout(l2); | ||
178 | |||
179 | // int minw = 0; | ||
180 | // quit_b = new QPushButton(i18n("&Quit"), this); | ||
181 | // // quit_b-> setGuiItem (KGuiItem(i18n("&Quit"), "exit" ) ); | ||
182 | // connect( quit_b, SIGNAL(clicked()), SLOT(quitbutton())); | ||
183 | // if(quit_b->sizeHint().width() > minw) | ||
184 | // minw = quit_b->sizeHint().width(); | ||
185 | |||
186 | // setup_b = new QPushButton(i18n("&Setup..."), this); | ||
187 | // // setup_b->setGuiItem (KGuiItem(i18n("&Setup...")) ); | ||
188 | // connect( setup_b, SIGNAL(clicked()), SLOT(expandbutton())); | ||
189 | // if(setup_b->sizeHint().width() > minw) | ||
190 | // minw = setup_b->sizeHint().width(); | ||
191 | |||
192 | |||
193 | |||
194 | // if(gpppdata.access() != KConfig::ReadWrite) | ||
195 | // setup_b->setEnabled(false); | ||
196 | |||
197 | // help_b = new QPushButton(i18n("&Help"), this); | ||
198 | // connect( help_b, SIGNAL(clicked()), SLOT(helpbutton())); | ||
199 | |||
200 | // KHelpMenu *helpMenu = new KHelpMenu(this, KGlobal::instance()->aboutData(), true); | ||
201 | // help_b->setPopup((QPopupMenu*)helpMenu->menu()); | ||
202 | // help_b->setGuiItem (KGuiItem(i18n("&Help"), "help" ) ); | ||
203 | |||
204 | // if(help_b->sizeHint().width() > minw) | ||
205 | // minw = help_b->sizeHint().width(); | ||
206 | |||
207 | // connect_b = new QPushButton(i18n("&Connect"), this); | ||
208 | // connect_b->setDefault(true); | ||
209 | // connect_b->setFocus(); | ||
210 | // connect(connect_b, SIGNAL(clicked()), SLOT(beginConnect())); | ||
211 | // if(connect_b->sizeHint().width() > minw) | ||
212 | // minw = connect_b->sizeHint().width(); | ||
213 | |||
214 | // quit_b->setFixedWidth(minw); | ||
215 | // setup_b->setFixedWidth(minw); | ||
216 | // // help_b->setFixedWidth(help_b->sizeHint().width()); | ||
217 | // connect_b->setFixedWidth(minw); | ||
218 | |||
219 | // l2->addWidget(quit_b); | ||
220 | // l2->addWidget(setup_b); | ||
221 | // // l2->addWidget(help_b); | ||
222 | // l2->addSpacing(20); | ||
223 | // l2->addWidget(connect_b); | ||
224 | |||
225 | setFixedSize(sizeHint()); | ||
226 | |||
227 | (void)new Modem; | ||
228 | |||
229 | // we also connect cmld_start to the beginConnect so that I can run | ||
230 | // the dialer through a command line argument | ||
231 | connect(this,SIGNAL(cmdl_start()),this,SLOT(beginConnect())); | ||
232 | |||
233 | // stats = new PPPStats; | ||
234 | |||
235 | // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); | ||
236 | |||
237 | // constructor of con_win reads position from config file | ||
238 | // con_win = new ConWindow(0, "conw", this); | ||
239 | // KWin::setIcons(con_win->winId(), kapp->icon(), kapp->miniIcon()); | ||
240 | |||
241 | // statdlg = new PPPStatsDlg(0, "stats", this, stats); | ||
242 | // statdlg->hide(); | ||
243 | |||
244 | debugwindow = new DebugWidget(0,"debugwindow"); | ||
245 | // KWin::setIcons(debugwindow->winId(), kapp->icon(), kapp->miniIcon()); | ||
246 | debugwindow->hide(); | ||
247 | |||
248 | // load up the accounts combo box | ||
249 | |||
250 | // resetaccounts(); | ||
251 | // con = new ConnectWidget(0, "con"); | ||
252 | //KWin::setIcons(con->winId(), kapp->icon(), kapp->miniIcon() ); | ||
253 | // connect(this, SIGNAL(begin_connect()),con, SLOT(preinit())); | ||
254 | // Is this the best we can do here? it's not right. | ||
255 | // QRect desk = QApplication::desktop()->screenGeometry( | ||
256 | // QApplication::desktop()->screenNumber(topLevelWidget())); | ||
257 | // con->setGeometry(desk.center().x()-175, desk.center().y()-55, 350,110); | ||
258 | |||
259 | // connect the ConnectWidgets various signals | ||
260 | // connect(con, SIGNAL(closeDebugWindow()), | ||
261 | // debugwindow, SLOT(hide())); | ||
262 | // connect(con, SIGNAL(debugMessage(const QString &)), | ||
263 | // debugwindow, SLOT(statusLabel(const QString &))); | ||
264 | // connect(con, SIGNAL(toggleDebugWindow()), | ||
265 | // debugwindow, SLOT(toggleVisibility())); | ||
266 | // connect(con, SIGNAL(debugPutChar(unsigned char)), | ||
267 | // debugwindow, SLOT(addChar(unsigned char))); | ||
268 | // // connect(con, SIGNAL(startAccounting()), | ||
269 | // // this, SLOT(startAccounting())); | ||
270 | // // connect(con, SIGNAL(stopAccounting()), | ||
271 | // // this, SLOT(stopAccounting())); | ||
272 | // connect(qApp, SIGNAL(saveYourself()), | ||
273 | // this, SLOT(saveMyself())); | ||
274 | // connect(qApp, SIGNAL(shutDown()), | ||
275 | // this, SLOT(shutDown())); | ||
276 | |||
277 | // debugwindow->setGeometry(desk.center().x()+190, desk.center().y()-55, | ||
278 | // debugwindow->width(),debugwindow->height()); | ||
279 | |||
280 | // move(desk.center().x()-width()/2, desk.center().y()-height()/2); | ||
281 | |||
282 | |||
283 | // KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); | ||
284 | |||
285 | // m_strCmdlAccount = args->getOption("c"); | ||
286 | // m_bQuitOnDisconnect = args->isSet("q"); | ||
287 | |||
288 | // if(!m_strCmdlAccount.isEmpty()) { | ||
289 | // m_bCmdlAccount = true; | ||
290 | // kdDebug(5002) << "cmdl_account: " << m_bCmdlAccount << endl; | ||
291 | // } | ||
292 | |||
293 | // if(m_bCmdlAccount){ | ||
294 | // bool result = gpppdata.setAccount(m_strCmdlAccount); | ||
295 | // if (!result){ | ||
296 | // QString string; | ||
297 | // string = i18n("No such Account:\n%1").arg(m_strCmdlAccount); | ||
298 | // KMessageBox::error(this, string); | ||
299 | // m_bCmdlAccount = false; | ||
300 | // this->show(); | ||
301 | // } else { | ||
302 | // beginConnect(); | ||
303 | // } | ||
304 | // } else | ||
305 | // expandbutton(); | ||
306 | // show(); | ||
307 | |||
308 | |||
309 | //#define KPPP_SHOW_NEWS | ||
310 | #ifdef KPPP_SHOW_NEWS | ||
311 | // keep user informed about recent changes | ||
312 | if(!m_bCmdlAccount) | ||
313 | showNews(); | ||
314 | #endif | ||
315 | } | ||
316 | |||
317 | KPPPWidget::~KPPPWidget() | ||
318 | { | ||
319 | p_kppp = 0; | ||
320 | // delete stats; | ||
321 | } | ||
322 | |||
323 | // bool KPPPWidget::eventFilter(QObject *o, QEvent *e) { | ||
324 | // if(e->type() == QEvent::User) { | ||
325 | // switch(((SignalEvent*)e)->sigType()) { | ||
326 | // case SIGINT: | ||
327 | // qDebug( "Received a SIGINT" ); | ||
328 | // interruptConnection(); | ||
329 | // break; | ||
330 | // case SIGCHLD: | ||
331 | // sigChld(); | ||
332 | // break; | ||
333 | // case SIGUSR1: | ||
334 | // sigPPPDDied(); | ||
335 | // break; | ||
336 | // } | ||
337 | // return true; | ||
338 | // } | ||
339 | |||
340 | // if(o == connect_b) { | ||
341 | // if(e->type() == QEvent::KeyPress) { | ||
342 | // if(connect_b->hasFocus() && ((QKeyEvent *)e)->key() == Qt::Key_Return) { | ||
343 | // beginConnect(); | ||
344 | // return true; | ||
345 | // } | ||
346 | // } | ||
347 | // } | ||
348 | |||
349 | // return false; | ||
350 | // } | ||
351 | |||
352 | |||
353 | |||
354 | |||
355 | void KPPPWidget::enterPressedInID() { | ||
356 | PW_Edit->setFocus(); | ||
357 | } | ||
358 | |||
359 | |||
360 | void KPPPWidget::enterPressedInPW() { | ||
361 | connect_b->setFocus(); | ||
362 | } | ||
363 | |||
364 | // triggered by the session manager | ||
365 | void KPPPWidget::saveMyself() { | ||
366 | gpppdata.save(); | ||
367 | } | ||
368 | |||
369 | void KPPPWidget::shutDown() { | ||
370 | interruptConnection(); | ||
371 | saveMyself(); | ||
372 | } | ||
373 | |||
374 | void KPPPWidget::log_window_toggled(bool on) { | ||
375 | gpppdata.set_show_log_window(on); | ||
376 | } | ||
377 | |||
378 | |||
379 | |||
380 | |||
381 | // void KPPPWidget::resetaccounts() { | ||
382 | // connectto_c->clear(); | ||
383 | |||
384 | // int count = gpppdata.count(); | ||
385 | |||
386 | // // enable/disable controls | ||
387 | // connectto_c->setEnabled(count > 0); | ||
388 | // connect_b->setEnabled(count > 0); | ||
389 | // log->setEnabled(count > 0); | ||
390 | // ID_Edit->setEnabled(count > 0); | ||
391 | // PW_Edit->setEnabled(count > 0); | ||
392 | |||
393 | // //load the accounts | ||
394 | // for(int i=0; i < count; i++) { | ||
395 | // gpppdata.setAccountbyIndex(i); | ||
396 | // connectto_c->insertItem(gpppdata.accname()); | ||
397 | // } | ||
398 | |||
399 | // //set the default account | ||
400 | // if(!gpppdata.defaultAccount().isEmpty()) { | ||
401 | // for(int i=0; i < count; i++) | ||
402 | // if(gpppdata.defaultAccount() == connectto_c->text(i)) { | ||
403 | // connectto_c->setCurrentItem(i); | ||
404 | // gpppdata.setAccountbyIndex(i); | ||
405 | |||
406 | // ID_Edit->setText(gpppdata.storedUsername()); | ||
407 | // PW_Edit->setText(gpppdata.storedPassword()); | ||
408 | // } | ||
409 | // } | ||
410 | // else | ||
411 | // if(count > 0) { | ||
412 | // gpppdata.setDefaultAccount(connectto_c->text(0)); | ||
413 | // gpppdata.save(); | ||
414 | // ID_Edit->setText(gpppdata.storedUsername()); | ||
415 | // PW_Edit->setText(gpppdata.storedPassword()); | ||
416 | // } | ||
417 | |||
418 | // connect(ID_Edit, SIGNAL(textChanged(const QString &)), | ||
419 | // this, SLOT(usernameChanged(const QString &))); | ||
420 | |||
421 | // connect(PW_Edit, SIGNAL(textChanged(const QString &)), | ||
422 | // this, SLOT(passwordChanged(const QString &))); | ||
423 | |||
424 | // if (ID_Edit->text().isEmpty()) | ||
425 | // ID_Edit->setFocus(); | ||
426 | // else if (PW_Edit->text().isEmpty()) | ||
427 | // PW_Edit->setFocus(); | ||
428 | // } | ||
429 | |||
430 | |||
431 | void KPPPWidget::interruptConnection() { | ||
432 | // interrupt dial up | ||
433 | // if (con->isVisible()) | ||
434 | // emit con->cancelbutton(); | ||
435 | |||
436 | // disconnect if online | ||
437 | if (gpppdata.pppdRunning()) | ||
438 | emit disconnect(); | ||
439 | } | ||
440 | |||
441 | |||
442 | void KPPPWidget::sigPPPDDied() { | ||
443 | qDebug( "Received a SIGUSR1" ); | ||
444 | |||
445 | // if we are not connected pppdpid is -1 so have have to check for that | ||
446 | // in the followin line to make sure that we don't raise a false alarm | ||
447 | // such as would be the case when the log file viewer exits. | ||
448 | if(gpppdata.pppdRunning() || gpppdata.pppdError()) { | ||
449 | qDebug( "It was pppd that died" ); | ||
450 | |||
451 | // when we killpppd() on Cancel in ConnectWidget | ||
452 | // we set pppid to -1 so we won't | ||
453 | // enter this block | ||
454 | |||
455 | // just to be sure | ||
456 | |||
457 | Modem::modem->removeSecret(AUTH_PAP); | ||
458 | Modem::modem->removeSecret(AUTH_CHAP); | ||
459 | |||
460 | gpppdata.setpppdRunning(false); | ||
461 | |||
462 | qDebug( "Executing command on disconnect since pppd has died." ); | ||
463 | QApplication::flushX(); | ||
464 | execute_command(gpppdata.command_on_disconnect()); | ||
465 | |||
466 | // stopAccounting(); | ||
467 | |||
468 | // con_win->stopClock(); | ||
469 | // DockWidget::dock_widget->stop_stats(); | ||
470 | // DockWidget::dock_widget->hide(); | ||
471 | |||
472 | if(!gpppdata.pppdError()) | ||
473 | gpppdata.setpppdError(E_PPPD_DIED); | ||
474 | removedns(); | ||
475 | Modem::modem->unlockdevice(); | ||
476 | // con->pppdDied(); | ||
477 | |||
478 | if(!gpppdata.automatic_redial()) { | ||
479 | quit_b->setFocus(); | ||
480 | show(); | ||
481 | // con_win->stopClock(); | ||
482 | //stopAccounting(); | ||
483 | // con_win->hide(); | ||
484 | // con->hide(); | ||
485 | |||
486 | gpppdata.setpppdRunning(false); | ||
487 | // // not in a signal handler !!! KNotifyClient::beep(); | ||
488 | QString msg; | ||
489 | if (gpppdata.pppdError() == E_IF_TIMEOUT) | ||
490 | msg = i18n("Timeout expired while waiting for the PPP interface " | ||
491 | "to come up!"); | ||
492 | else { | ||
493 | msg = i18n("<p>The pppd daemon died unexpectedly!</p>"); | ||
494 | Modem::modem->pppdExitStatus(); | ||
495 | if (Modem::modem->lastStatus != 99) {// more recent pppds only | ||
496 | msg += i18n("<p>Exit status: %1").arg(Modem::modem->lastStatus); | ||
497 | msg += i18n("</p><p>See 'man pppd' for an explanation of the error " | ||
498 | "codes or take a look at the kppp FAQ on " | ||
499 | " <a href=http://devel-home.kde.org/~kppp/index.html>" | ||
500 | "http://devel-home.kde.org/~kppp/index.html</a></p>"); | ||
501 | } | ||
502 | } | ||
503 | |||
504 | // if(QMessageBox::warning(0, msg, i18n("Error"), i18n("&OK"), i18n("&Details...")) == QMessageBox::No) | ||
505 | // // PPPL_ShowLog(); | ||
506 | // } else { /* reconnect on disconnect */ | ||
507 | if (false){ | ||
508 | qDebug( "Trying to reconnect... " ); | ||
509 | |||
510 | if(gpppdata.authMethod() == AUTH_PAP || | ||
511 | gpppdata.authMethod() == AUTH_CHAP || | ||
512 | gpppdata.authMethod() == AUTH_PAPCHAP) | ||
513 | Modem::modem->setSecret(gpppdata.authMethod(), | ||
514 | encodeWord(gpppdata.storedUsername()), | ||
515 | encodeWord(gpppdata.password())); | ||
516 | |||
517 | // con_win->hide(); | ||
518 | // con_win->stopClock(); | ||
519 | //stopAccounting(); | ||
520 | gpppdata.setpppdRunning(false); | ||
521 | // not in a signal handler !!!KNotifyClient::beep(); | ||
522 | emit cmdl_start(); | ||
523 | } | ||
524 | } | ||
525 | gpppdata.setpppdError(0); | ||
526 | } | ||
527 | } | ||
528 | |||
529 | // void KPPPWidget::sigChld() { | ||
530 | // qDebug( "sigchld()" ); | ||
531 | // // pid_t id = wait(0L); | ||
532 | // // if(id == helperPid && helperPid != -1) { | ||
533 | // // kdDebug(5002) << "It was the setuid child that died" << endl; | ||
534 | // // helperPid = -1; | ||
535 | // QString msg = i18n("kppp's helper process just died.\n" | ||
536 | // "Since a further execution would be pointless, " | ||
537 | // "kppp will shut down now."); | ||
538 | // QMessageBox::warning(0L,"error", msg); | ||
539 | // //remove_pidfile(); | ||
540 | // exit(1); | ||
541 | // // } | ||
542 | // } | ||
543 | |||
544 | |||
545 | void KPPPWidget::newdefaultaccount(int i) { | ||
546 | gpppdata.setDefaultAccount(connectto_c->text(i)); | ||
547 | gpppdata.save(); | ||
548 | ID_Edit->setText(gpppdata.storedUsername()); | ||
549 | PW_Edit->setText(gpppdata.storedPassword()); | ||
550 | } | ||
551 | |||
552 | |||
553 | |||
554 | |||
555 | void KPPPWidget::beginConnect() { | ||
556 | // make sure to connect to the account that is selected in the combo box | ||
557 | // (exeption: an account given by a command line argument) | ||
558 | // if(!m_bCmdlAccount) { | ||
559 | // gpppdata.setAccount(connectto_c->currentText()); | ||
560 | // gpppdata.setPassword(PW_Edit->text()); | ||
561 | // } else { | ||
562 | gpppdata.setPassword(gpppdata.storedPassword()); | ||
563 | // } | ||
564 | |||
565 | QFileInfo info(pppdPath()); | ||
566 | |||
567 | if(!info.exists()){ | ||
568 | QMessageBox::warning(this, "error", i18n("Cannot find the PPP daemon!\n" | ||
569 | "Make sure that pppd is installed and " | ||
570 | "that you have entered the correct path.")); | ||
571 | return; | ||
572 | } | ||
573 | #if 0 | ||
574 | if(!info.isExecutable()){ | ||
575 | |||
576 | QString string; | ||
577 | string = i18n("kppp cannot execute:\n %1\n" | ||
578 | "Please make sure that you have given kppp " | ||
579 | "setuid permission and that " | ||
580 | "pppd is executable.").arg(gpppdata.pppdPath()); | ||
581 | KMessageBox::error(this, string); | ||
582 | return; | ||
583 | |||
584 | } | ||
585 | #endif | ||
586 | |||
587 | QFileInfo info2(gpppdata.modemDevice()); | ||
588 | |||
589 | if(!info2.exists()){ | ||
590 | QString string; | ||
591 | string = i18n("kppp can not find:\n %1\nPlease make sure you have setup " | ||
592 | "your modem device properly " | ||
593 | "and/or adjust the location of the modem device on " | ||
594 | "the modem tab of " | ||
595 | "the setup dialog.").arg(gpppdata.modemDevice()); | ||
596 | QMessageBox::warning(this, "error", string); | ||
597 | return; | ||
598 | } | ||
599 | |||
600 | // if this is a PAP or CHAP account, ensure that username is | ||
601 | // supplied | ||
602 | if(gpppdata.authMethod() == AUTH_PAP || | ||
603 | gpppdata.authMethod() == AUTH_CHAP || | ||
604 | gpppdata.authMethod() == AUTH_PAPCHAP ) { | ||
605 | if(ID_Edit->text().isEmpty()) { | ||
606 | QMessageBox::warning(this,"error", | ||
607 | i18n( | ||
608 | "You have selected the authentication " | ||
609 | "method PAP or CHAP. This requires that you " | ||
610 | "supply a username and a password!")); | ||
611 | return; | ||
612 | } else { | ||
613 | if(!Modem::modem->setSecret(gpppdata.authMethod(), | ||
614 | encodeWord(gpppdata.storedUsername()), | ||
615 | encodeWord(gpppdata.password()))) { | ||
616 | QString s; | ||
617 | s = i18n("Cannot create PAP/CHAP authentication\n" | ||
618 | "file \"%1\"").arg(PAP_AUTH_FILE); | ||
619 | QMessageBox::warning(this, "error", s); | ||
620 | return; | ||
621 | } | ||
622 | } | ||
623 | } | ||
624 | |||
625 | if (gpppdata.phonenumber().isEmpty()) { | ||
626 | QString s = i18n("You must specify a telephone number!"); | ||
627 | QMessageBox::warning(this, "error", s); | ||
628 | return; | ||
629 | } | ||
630 | |||
631 | this->hide(); | ||
632 | |||
633 | QString tit = i18n("Connecting to: %1").arg(gpppdata.accname()); | ||
634 | // con->setCaption(tit); | ||
635 | |||
636 | // con->show(); | ||
637 | |||
638 | bool show_debug = gpppdata.get_show_log_window(); | ||
639 | // con->debug->setOn(show_debug);// toggle button | ||
640 | debugwindow->clear(); | ||
641 | if (!show_debug) | ||
642 | debugwindow->hide(); | ||
643 | else { | ||
644 | debugwindow->show(); | ||
645 | // con->raise(); | ||
646 | } | ||
647 | |||
648 | emit begin_connect(); | ||
649 | } | ||
650 | |||
651 | |||
652 | void KPPPWidget::disconnect() { | ||
653 | if (!gpppdata.command_before_disconnect().isEmpty()) { | ||
654 | // con_win->hide(); | ||
655 | // con->show(); | ||
656 | // con->setCaption(i18n("Disconnecting...")); | ||
657 | // con->setMsg(i18n("Executing command before disconnection.")); | ||
658 | |||
659 | qApp->processEvents(); | ||
660 | QApplication::flushX(); | ||
661 | // pid_t id = | ||
662 | execute_command(gpppdata.command_before_disconnect()); | ||
663 | // int i, status; | ||
664 | |||
665 | // do { | ||
666 | // kapp->processEvents(); | ||
667 | // i = waitpid(id, &status, WNOHANG); | ||
668 | // usleep(500000); | ||
669 | // } while (i == 0 && errno == 0); | ||
670 | |||
671 | // con->hide(); | ||
672 | } | ||
673 | |||
674 | qApp->processEvents(); | ||
675 | |||
676 | // statdlg->stop_stats(); | ||
677 | Modem::modem->killPPPDaemon(); | ||
678 | |||
679 | QApplication::flushX(); | ||
680 | execute_command(gpppdata.command_on_disconnect()); | ||
681 | |||
682 | Modem::modem->removeSecret(AUTH_PAP); | ||
683 | Modem::modem->removeSecret(AUTH_CHAP); | ||
684 | |||
685 | removedns(); | ||
686 | Modem::modem->unlockdevice(); | ||
687 | |||
688 | // con_win->stopClock(); | ||
689 | // p_kppp->stopAccounting(); | ||
690 | // con_win->hide(); | ||
691 | |||
692 | // DockWidget::dock_widget->stop_stats(); | ||
693 | // DockWidget::dock_widget->hide(); | ||
694 | |||
695 | // if(m_bQuitOnDisconnect) | ||
696 | // kapp->exit(0); | ||
697 | // else { | ||
698 | this->quit_b->setFocus(); | ||
699 | this->show(); | ||
700 | // } | ||
701 | } | ||
702 | |||
703 | |||
704 | // void KPPPWidget::helpbutton() { | ||
705 | // kapp->invokeHelp(); | ||
706 | // } | ||
707 | |||
708 | |||
709 | void KPPPWidget::quitbutton() { | ||
710 | if(gpppdata.pppdRunning()) { | ||
711 | int ok = QMessageBox::warning(this, | ||
712 | i18n("Exiting kPPP will close your PPP Session."), | ||
713 | i18n("Quit kPPP?")); | ||
714 | if(ok == QMessageBox::Yes) { | ||
715 | Modem::modem->killPPPDaemon(); | ||
716 | QApplication::flushX(); | ||
717 | execute_command(gpppdata.command_on_disconnect()); | ||
718 | removedns(); | ||
719 | Modem::modem->unlockdevice(); | ||
720 | } | ||
721 | } else { | ||
722 | if (!gpppdata.accname().isEmpty() && !gpppdata.storePassword()) | ||
723 | gpppdata.setStoredPassword(""); | ||
724 | } | ||
725 | gpppdata.save(); | ||
726 | qApp->quit(); | ||
727 | } | ||
728 | |||
729 | |||
730 | // void KPPPWidget::rulesetLoadError() { | ||
731 | // QMessageBox::warning(this,"error", ruleset_load_errmsg); | ||
732 | // } | ||
733 | |||
734 | |||
735 | // void KPPPWidget::startAccounting() { | ||
736 | // // volume accounting | ||
737 | // stats->totalbytes = 0; | ||
738 | |||
739 | // kdDebug() << "AcctEnabled: " << gpppdata.AcctEnabled() << endl; | ||
740 | |||
741 | // // load the ruleset | ||
742 | // if(!gpppdata.AcctEnabled()) | ||
743 | // return; | ||
744 | |||
745 | // QString d = AccountingBase::getAccountingFile(gpppdata.accountingFile()); | ||
746 | // // if(::access(d.data(), X_OK) != 0) | ||
747 | // acct = new Accounting(this, stats); | ||
748 | // // else | ||
749 | // // acct = new ExecutableAccounting(this); | ||
750 | |||
751 | // // connect to the accounting object | ||
752 | // connect(acct, SIGNAL(changed(QString, QString)), | ||
753 | // con_win, SLOT(slotAccounting(QString, QString))); | ||
754 | |||
755 | // // if(!acct->loadRuleSet(gpppdata.accountingFile())) { | ||
756 | // // QString s= i18n("Can not load the accounting " | ||
757 | // // "ruleset \"%1\"!").arg(gpppdata.accountingFile()); | ||
758 | |||
759 | // // starting the messagebox with a timer will prevent us | ||
760 | // // from blocking the calling function ConnectWidget::timerEvent | ||
761 | // ruleset_load_errmsg = s; | ||
762 | // QTimer::singleShot(0, this, SLOT(rulesetLoadError())); | ||
763 | // return; | ||
764 | // } | ||
765 | // //else | ||
766 | // // acct->slotStart(); | ||
767 | // } | ||
768 | |||
769 | // void KPPPWidget::stopAccounting() { | ||
770 | // // store volume accounting | ||
771 | // // if(stats->totalbytes != 0) | ||
772 | // // gpppdata.setTotalBytes(stats->totalbytes); | ||
773 | |||
774 | // if(!gpppdata.AcctEnabled()) | ||
775 | // return; | ||
776 | |||
777 | // // if(acct != 0) { | ||
778 | // // acct->slotStop(); | ||
779 | // // delete acct; | ||
780 | // // acct = 0; | ||
781 | // // } | ||
782 | // } | ||
783 | |||
784 | |||
785 | // void KPPPWidget::showStats() { | ||
786 | // if(statdlg) { | ||
787 | // statdlg->show(); | ||
788 | // statdlg->raise(); | ||
789 | // } | ||
790 | // } | ||
791 | |||
792 | |||
793 | void KPPPWidget::usernameChanged(const QString &) { | ||
794 | // store username for later use | ||
795 | gpppdata.setStoredUsername(ID_Edit->text()); | ||
796 | } | ||
797 | |||
798 | |||
799 | void KPPPWidget::passwordChanged(const QString &) { | ||
800 | // store the password if so requested | ||
801 | if(gpppdata.storePassword()) | ||
802 | gpppdata.setStoredPassword(PW_Edit->text()); | ||
803 | else | ||
804 | gpppdata.setStoredPassword(""); | ||
805 | } | ||
806 | |||
807 | |||
808 | void KPPPWidget::setPW_Edit(const QString &pw) { | ||
809 | PW_Edit->setText(pw); | ||
810 | } | ||
811 | |||
812 | |||
813 | // void KPPPWidget::resetCosts(const QString &s) { | ||
814 | // AccountingBase::resetCosts(s); | ||
815 | // } | ||
816 | |||
817 | |||
818 | // void KPPPWidget::resetVolume(const QString &s) { | ||
819 | // AccountingBase::resetVolume(s); | ||
820 | // } | ||
821 | |||
822 | /** | ||
823 | * pppd's getword() function knows about escape characters. | ||
824 | * If we write the username and password to the secrets file | ||
825 | * we'll therefore have to escape back slashes. | ||
826 | */ | ||
827 | QString KPPPWidget::encodeWord(const QString &s) { | ||
828 | QString r = s; | ||
829 | r.replace(QRegExp("\\"), "\\\\"); | ||
830 | return r; | ||
831 | } | ||
832 | |||
833 | // void KPPPWidget::setQuitOnDisconnect (bool b) | ||
834 | // { | ||
835 | // m_bQuitOnDisconnect = b; | ||
836 | // } | ||
837 | |||
838 | void KPPPWidget::showNews() { | ||
839 | #ifdef KPPP_SHOW_NEWS | ||
840 | /* | ||
841 | * Introduce the QuickHelp feature to new users of this version | ||
842 | */ | ||
843 | #define QUICKHELP_HINT "Hint_QuickHelp" | ||
844 | if(gpppdata.readNumConfig(GENERAL_GRP, QUICKHELP_HINT, 0) == 0) { | ||
845 | QDialog dlg(0, 0, true); | ||
846 | dlg.setCaption(i18n("Recent Changes in KPPP")); | ||
847 | |||
848 | QVBoxLayout *tl = new QVBoxLayout(&dlg, 10, 10); | ||
849 | QHBoxLayout *l1 = new QHBoxLayout(10); | ||
850 | QVBoxLayout *l2 = new QVBoxLayout(10); | ||
851 | tl->addLayout(l1); | ||
852 | |||
853 | QLabel *icon = new QLabel(&dlg); | ||
854 | icon->setPixmap(BarIcon("exclamation")); | ||
855 | icon->setFixedSize(icon->sizeHint()); | ||
856 | l1->addWidget(icon); | ||
857 | l1->addLayout(l2); | ||
858 | |||
859 | QLabel *l = new QLabel(i18n("From version 1.4.8 on, kppp has a new feature\n" | ||
860 | "called \"Quickhelp\". It's similar to a tooltip,\n" | ||
861 | "but you can activate it whenever you want.\n" | ||
862 | "\n" | ||
863 | "To activate it, simply click on a control like\n" | ||
864 | "a button or a label with the right mouse button.\n" | ||
865 | "If the item supports Quickhelp, a popup menu\n" | ||
866 | "will appear leading to Quickhelp.\n" | ||
867 | "\n" | ||
868 | "To test it, right-click somewhere in this text."), | ||
869 | &dlg); | ||
870 | |||
871 | QCheckBox *cb = new QCheckBox(i18n("Don't show this hint again"), &dlg); | ||
872 | cb->setFixedSize(cb->sizeHint()); | ||
873 | |||
874 | KButtonBox *bbox = new KButtonBox(&dlg); | ||
875 | bbox->addStretch(1); | ||
876 | QPushButton *ok = bbox->addButton(i18n("OK")); | ||
877 | ok->setDefault(true); | ||
878 | dlg.connect(ok, SIGNAL(clicked()), | ||
879 | &dlg, SLOT(accept())); | ||
880 | bbox->addStretch(1); | ||
881 | bbox->layout(); | ||
882 | |||
883 | l2->addWidget(l); | ||
884 | l2->addWidget(cb); | ||
885 | tl->addWidget(bbox); | ||
886 | |||
887 | QString tmp = i18n("This is an example of <b>QuickHelp</b>.\n" | ||
888 | "This window will stay open until you\n" | ||
889 | "click a mouse button or a press a key.\n"); | ||
890 | |||
891 | QWhatsThis::add(cb,tmp); | ||
892 | QWhatsThis::add(l, tmp); | ||
893 | |||
894 | dlg.exec(); | ||
895 | if(cb->isChecked()) { | ||
896 | gpppdata.writeConfig(GENERAL_GRP, QUICKHELP_HINT, 1); | ||
897 | gpppdata.save(); | ||
898 | } | ||
899 | } | ||
900 | #endif | ||
901 | } | ||
902 | |||
903 | |||
904 | //#include "kpppwidget.moc" | ||
905 | |||
diff --git a/noncore/settings/networksettings/ppp/kpppwidget.h b/noncore/settings/networksettings/ppp/kpppwidget.h new file mode 100644 index 0000000..266d829 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/kpppwidget.h | |||
@@ -0,0 +1,157 @@ | |||
1 | /* | ||
2 | * | ||
3 | * kPPP: A pppd front end for the KDE project | ||
4 | * | ||
5 | * $Id$ | ||
6 | * | ||
7 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
8 | * wuebben@math.cornell.edu | ||
9 | * | ||
10 | * Copyright (C) 1998-2002 Harri Porten <porten@kde.org> | ||
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 | #ifndef __KPPPWIDGET_H__ | ||
28 | #define __KPPPWIDGET_H__ | ||
29 | |||
30 | #include <qstring.h> | ||
31 | |||
32 | //#include "accounting.h" | ||
33 | #include "conwindow.h" | ||
34 | #include "accounts.h" | ||
35 | #include "connect.h" | ||
36 | #include "debug.h" | ||
37 | //#include "pppstatdlg.h" | ||
38 | |||
39 | //class GraphSetup; | ||
40 | //class AboutWidget; | ||
41 | //class PPPStats; | ||
42 | class QDialog; | ||
43 | class QPushButton; | ||
44 | |||
45 | /* class SignalEvent : public QEvent { */ | ||
46 | /* public: */ | ||
47 | /* SignalEvent(int s) : QEvent(User), sig(s) { } */ | ||
48 | /* int sigType() const { return sig; } */ | ||
49 | /* private: */ | ||
50 | /* int sig; */ | ||
51 | /* }; */ | ||
52 | |||
53 | |||
54 | class KPPPWidget : public QDialog { | ||
55 | Q_OBJECT | ||
56 | public: | ||
57 | |||
58 | KPPPWidget( QWidget *parent=0, const char *name=0, bool modal = false, WFlags fl = 0 ); | ||
59 | ~KPPPWidget(); | ||
60 | |||
61 | void setPW_Edit(const QString &); | ||
62 | // virtual bool eventFilter(QObject *, QEvent *); | ||
63 | |||
64 | void setQuitOnDisconnect (bool b); | ||
65 | // bool quitOnDisconnect () {return m_bQuitOnDisconnect;}; | ||
66 | |||
67 | private slots: | ||
68 | void newdefaultaccount(int); | ||
69 | // void expandbutton(); | ||
70 | void beginConnect(); | ||
71 | void quitbutton(); | ||
72 | // void helpbutton(); | ||
73 | // void setup(); | ||
74 | // void rulesetLoadError(); | ||
75 | void usernameChanged(const QString &); | ||
76 | void passwordChanged(const QString &); | ||
77 | void enterPressedInID(); | ||
78 | void enterPressedInPW(); | ||
79 | void saveMyself(); | ||
80 | void shutDown(); | ||
81 | |||
82 | /* protected slots: */ | ||
83 | /* virtual void accept(); */ | ||
84 | /* virtual void reject(); */ | ||
85 | |||
86 | public slots: | ||
87 | // void resetaccounts(); | ||
88 | /* void resetCosts(const QString &); */ | ||
89 | /* void resetVolume(const QString &); */ | ||
90 | void disconnect(); | ||
91 | void log_window_toggled(bool on); | ||
92 | /* void startAccounting(); */ | ||
93 | /* void stopAccounting(); */ | ||
94 | /* void showStats(); */ | ||
95 | |||
96 | signals: | ||
97 | void begin_connect(); | ||
98 | void cmdl_start(); | ||
99 | |||
100 | public: | ||
101 | QCheckBox *log; | ||
102 | bool connected; | ||
103 | DebugWidget *debugwindow; | ||
104 | QString con_speed; | ||
105 | // ConnectWidget *con; | ||
106 | // ConWindow *con_win; | ||
107 | // PPPStatsDlg *statdlg; | ||
108 | // AccountingBase *acct; | ||
109 | QPushButton *quit_b; | ||
110 | //PPPStats *stats; | ||
111 | |||
112 | private: | ||
113 | // void prepareSetupDialog(); | ||
114 | void interruptConnection(); | ||
115 | void sigChld(); | ||
116 | void sigPPPDDied(); | ||
117 | QString encodeWord(const QString &s); | ||
118 | void showNews (); | ||
119 | |||
120 | QString ruleset_load_errmsg; | ||
121 | |||
122 | // QPushButton *help_b; | ||
123 | QPushButton *setup_b; | ||
124 | QFrame *fline; | ||
125 | QFrame *fline1; | ||
126 | QPushButton *connect_b; | ||
127 | QComboBox *connectto_c; | ||
128 | QLabel *ID_Label; | ||
129 | QLabel *PW_Label; | ||
130 | QLineEdit *ID_Edit; | ||
131 | QLineEdit *PW_Edit; | ||
132 | QLabel *label1; | ||
133 | QLabel *label2; | ||
134 | QLabel *label3; | ||
135 | QLabel *label4; | ||
136 | QLabel *label5; | ||
137 | QLabel *label6; | ||
138 | QLabel *radio_label; | ||
139 | |||
140 | |||
141 | // QTabWidget *tabWindow; | ||
142 | // AccountWidget *accounts; | ||
143 | // GeneralWidget *general; | ||
144 | // ModemWidget *modem1; | ||
145 | // ModemWidget2 *modem2; | ||
146 | // GraphSetup *graph; | ||
147 | // AboutWidget *about; | ||
148 | |||
149 | |||
150 | /* QString m_strCmdlAccount; */ | ||
151 | /* bool m_bQuitOnDisconnect; */ | ||
152 | /* bool m_bCmdlAccount; */ | ||
153 | }; | ||
154 | |||
155 | |||
156 | #endif | ||
157 | |||
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp index e9e3f06..a2f77c5 100644 --- a/noncore/settings/networksettings/ppp/modem.cpp +++ b/noncore/settings/networksettings/ppp/modem.cpp | |||
@@ -32,2 +32,3 @@ | |||
32 | #include <setjmp.h> | 32 | #include <setjmp.h> |
33 | #include <regex.h> | ||
33 | #include <qregexp.h> | 34 | #include <qregexp.h> |
@@ -35,5 +36,5 @@ | |||
35 | 36 | ||
37 | #include "auth.h" | ||
36 | #include "modem.h" | 38 | #include "modem.h" |
37 | #include "pppdata.h" | 39 | #include "pppdata.h" |
38 | //#include "requester.h" | ||
39 | //#include <klocale.h> | 40 | //#include <klocale.h> |
@@ -53,12 +54,39 @@ Modem *Modem::modem = 0; | |||
53 | 54 | ||
54 | Modem::Modem() : | 55 | |
55 | modemfd(-1), | 56 | const char* pppdPath() { |
56 | sn(0L), | 57 | // wasting a few bytes |
57 | data_mode(false), | 58 | static char buffer[sizeof(PPPDSEARCHPATH)+sizeof(PPPDNAME)]; |
58 | modem_is_locked(false) | 59 | static char *pppdPath = 0L; |
60 | char *p; | ||
61 | |||
62 | if(pppdPath == 0L) { | ||
63 | const char *c = PPPDSEARCHPATH; | ||
64 | while(*c != '\0') { | ||
65 | while(*c == ':') | ||
66 | c++; | ||
67 | p = buffer; | ||
68 | while(*c != '\0' && *c != ':') | ||
69 | *p++ = *c++; | ||
70 | *p = '\0'; | ||
71 | strcat(p, "/"); | ||
72 | strcat(p, PPPDNAME); | ||
73 | if(access(buffer, F_OK) == 0) | ||
74 | return (pppdPath = buffer); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | return pppdPath; | ||
79 | } | ||
80 | |||
81 | |||
82 | Modem::Modem() | ||
59 | { | 83 | { |
84 | if (Modem::modem != 0) return; //CORRECT? | ||
85 | modemfd = -1; | ||
86 | sn = 0L; | ||
87 | data_mode = false; | ||
88 | modem_is_locked = false; | ||
60 | lockfile[0] = '\0'; | 89 | lockfile[0] = '\0'; |
61 | device = "/dev/modem"; | 90 | device = "/dev/modem"; |
62 | assert(modem==0); | 91 | modem = this; |
63 | modem = this; | ||
64 | } | 92 | } |
@@ -646,26 +674,136 @@ void alarm_handler(int) { | |||
646 | 674 | ||
675 | const char* Modem::authFile(Auth method, int version) { | ||
676 | switch(method|version) { | ||
677 | case PAP|Original: | ||
678 | return PAP_AUTH_FILE; | ||
679 | break; | ||
680 | case PAP|New: | ||
681 | return PAP_AUTH_FILE".new"; | ||
682 | break; | ||
683 | case PAP|Old: | ||
684 | return PAP_AUTH_FILE".old"; | ||
685 | break; | ||
686 | case CHAP|Original: | ||
687 | return CHAP_AUTH_FILE; | ||
688 | break; | ||
689 | case CHAP|New: | ||
690 | return CHAP_AUTH_FILE".new"; | ||
691 | break; | ||
692 | case CHAP|Old: | ||
693 | return CHAP_AUTH_FILE".old"; | ||
694 | break; | ||
695 | default: | ||
696 | return 0L; | ||
697 | } | ||
698 | } | ||
647 | 699 | ||
648 | const char* pppdPath() { | ||
649 | // wasting a few bytes | ||
650 | static char buffer[sizeof(PPPDSEARCHPATH)+sizeof(PPPDNAME)]; | ||
651 | static char *pppdPath = 0L; | ||
652 | char *p; | ||
653 | 700 | ||
654 | if(pppdPath == 0L) { | 701 | bool Modem::createAuthFile(Auth method, const char *username, const char *password) { |
655 | const char *c = PPPDSEARCHPATH; | 702 | const char *authfile, *oldName, *newName; |
656 | while(*c != '\0') { | 703 | char line[100]; |
657 | while(*c == ':') | 704 | char regexp[2*MaxStrLen+30]; |
658 | c++; | 705 | regex_t preg; |
659 | p = buffer; | 706 | |
660 | while(*c != '\0' && *c != ':') | 707 | if(!(authfile = authFile(method))) |
661 | *p++ = *c++; | 708 | return false; |
662 | *p = '\0'; | 709 | |
663 | strcat(p, "/"); | 710 | if(!(newName = authFile(method, New))) |
664 | strcat(p, PPPDNAME); | 711 | return false; |
665 | if(access(buffer, F_OK) == 0) | 712 | |
666 | return (pppdPath = buffer); | 713 | // look for username, "username" or 'username' |
714 | // if you modify this RE you have to adapt regexp's size above | ||
715 | snprintf(regexp, sizeof(regexp), "^[ \t]*%s[ \t]\\|^[ \t]*[\"\']%s[\"\']", | ||
716 | username,username); | ||
717 | MY_ASSERT(regcomp(&preg, regexp, 0) == 0); | ||
718 | |||
719 | // copy to new file pap- or chap-secrets | ||
720 | int old_umask = umask(0077); | ||
721 | FILE *fout = fopen(newName, "w"); | ||
722 | if(fout) { | ||
723 | // copy old file | ||
724 | FILE *fin = fopen(authfile, "r"); | ||
725 | if(fin) { | ||
726 | while(fgets(line, sizeof(line), fin)) { | ||
727 | if(regexec(&preg, line, 0, 0L, 0) == 0) | ||
728 | continue; | ||
729 | fputs(line, fout); | ||
730 | } | ||
731 | fclose(fin); | ||
667 | } | 732 | } |
733 | |||
734 | // append user/pass pair | ||
735 | fprintf(fout, "\"%s\"\t*\t\"%s\"\n", username, password); | ||
736 | fclose(fout); | ||
668 | } | 737 | } |
669 | 738 | ||
670 | return pppdPath; | 739 | // restore umask |
740 | umask(old_umask); | ||
741 | |||
742 | // free memory allocated by regcomp | ||
743 | regfree(&preg); | ||
744 | |||
745 | if(!(oldName = authFile(method, Old))) | ||
746 | return false; | ||
747 | |||
748 | // delete old file if any | ||
749 | unlink(oldName); | ||
750 | |||
751 | rename(authfile, oldName); | ||
752 | rename(newName, authfile); | ||
753 | |||
754 | return true; | ||
755 | } | ||
756 | |||
757 | |||
758 | bool Modem::setSecret(int method, const char* name, const char* password) | ||
759 | { | ||
760 | |||
761 | Auth auth; | ||
762 | if(method == AUTH_PAPCHAP) | ||
763 | return setSecret(AUTH_PAP, name, password) && | ||
764 | setSecret(AUTH_CHAP, name, password); | ||
765 | |||
766 | switch(method) { | ||
767 | case AUTH_PAP: | ||
768 | auth = Modem::PAP; | ||
769 | break; | ||
770 | case AUTH_CHAP: | ||
771 | auth = Modem::CHAP; | ||
772 | break; | ||
773 | default: | ||
774 | return false; | ||
775 | } | ||
776 | |||
777 | return createAuthFile(auth, name, password); | ||
778 | |||
779 | } | ||
780 | |||
781 | bool Modem::removeSecret(int) | ||
782 | { | ||
783 | return true; | ||
784 | } | ||
785 | |||
786 | void Modem::killPPPDaemon() | ||
787 | { | ||
788 | } | ||
789 | |||
790 | int Modem::pppdExitStatus() | ||
791 | { | ||
792 | return -1; | ||
671 | } | 793 | } |
794 | |||
795 | bool Modem::execPPPDaemon(const QString & arguments) | ||
796 | { | ||
797 | return true; | ||
798 | } | ||
799 | |||
800 | int Modem::openResolv(int flags) | ||
801 | { | ||
802 | return -1; | ||
803 | } | ||
804 | |||
805 | bool Modem::setHostname(const QString & name) | ||
806 | { | ||
807 | return true; | ||
808 | } | ||
809 | |||
diff --git a/noncore/settings/networksettings/ppp/modem.h b/noncore/settings/networksettings/ppp/modem.h index c23524a..052be4a 100644 --- a/noncore/settings/networksettings/ppp/modem.h +++ b/noncore/settings/networksettings/ppp/modem.h | |||
@@ -68,4 +68,14 @@ public: | |||
68 | 68 | ||
69 | bool setSecret(int,const char*,const char*); | ||
70 | bool removeSecret(int); | ||
71 | void killPPPDaemon(); | ||
72 | int pppdExitStatus(); | ||
73 | bool execPPPDaemon(const QString & arguments); | ||
74 | int openResolv(int flags); | ||
75 | bool setHostname(const QString & name); | ||
76 | |||
69 | public: | 77 | public: |
78 | enum Auth { PAP = 1, CHAP }; | ||
70 | static Modem *modem; | 79 | static Modem *modem; |
80 | int lastStatus; | ||
71 | 81 | ||
@@ -80,2 +90,7 @@ private slots: | |||
80 | private: | 90 | private: |
91 | enum { MaxPathLen = 30, MaxStrLen = 40, MaxArgs = 100 }; | ||
92 | enum { Original=0x100, New=0x200, Old=0x400 } Version; | ||
93 | |||
94 | const char* authFile(Auth method, int version = Original ); | ||
95 | bool createAuthFile(Auth method,const char *username,const char *password); | ||
81 | void escape_to_command_mode(); | 96 | void escape_to_command_mode(); |
diff --git a/noncore/settings/networksettings/ppp/modemcmds.cpp b/noncore/settings/networksettings/ppp/modemcmds.cpp new file mode 100644 index 0000000..766ba0f --- a/dev/null +++ b/noncore/settings/networksettings/ppp/modemcmds.cpp | |||
@@ -0,0 +1,321 @@ | |||
1 | /* | ||
2 | * kPPP: A front end for pppd 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 library 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 library 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 dummyWidget program; if not, write to the Free | ||
24 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
25 | */ | ||
26 | |||
27 | #include <qlayout.h> | ||
28 | #include <qslider.h> | ||
29 | #include <qbuttongroup.h> | ||
30 | #include <stdlib.h> | ||
31 | //#include <kapplication.h> // for getMiniIcon() | ||
32 | //#include <klocale.h> | ||
33 | #define i18n QObject::tr | ||
34 | #include "modemcmds.h" | ||
35 | #include "pppdata.h" | ||
36 | //#include <kwin.h> | ||
37 | |||
38 | #define ADJUSTEDIT(e) //e->setText("XXXXXXXXqy"); e->setMinimumSize(e->sizeHint()); /*e->setFixedHeight(e->sizeHint().height());*/ e->setText(""); e->setMaxLength(MODEMSTR_SIZE); | ||
39 | |||
40 | // a little trick to make the label look like a disabled lineedit | ||
41 | #define FORMATSLIDERLABEL(l) //l->setFixedWidth(l->sizeHint().width()); l->setFixedHeight(QLineEdit(dummyWidget).sizeHint().height()); l->setAlignment(AlignCenter); l->setFrameStyle(QFrame::WinPanel|QFrame::Sunken); l->setLineWidth(2); | ||
42 | |||
43 | ModemCommands::ModemCommands(QWidget *parent, const char *name) | ||
44 | : QDialog(parent, name, true ) //, i18n("Edit Modem Commands") , Ok|Cancel) | ||
45 | { | ||
46 | setCaption(i18n("Edit Modem Commands")); | ||
47 | // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); | ||
48 | QWidget *dummyWidget = new QWidget(this); | ||
49 | // setMainWidget(dummyWidget); | ||
50 | |||
51 | const int GRIDROWS = 22; | ||
52 | int row = 0; | ||
53 | |||
54 | // toplevel layout | ||
55 | QVBoxLayout *tl = new QVBoxLayout(this, 10, 4); | ||
56 | |||
57 | // add grid + frame | ||
58 | QGridLayout *l1 = new QGridLayout(GRIDROWS, 4); | ||
59 | tl->addLayout(l1); | ||
60 | box = new QGroupBox(this, "box"); | ||
61 | l1->addMultiCellWidget(box, row++, GRIDROWS, 0, 3); | ||
62 | |||
63 | // put slider and label into a separate H-Box | ||
64 | QHBoxLayout *l2 = new QHBoxLayout; | ||
65 | l1->addLayout(l2, row, 2); | ||
66 | lpreinitslider = new QLabel("MMMM", this); | ||
67 | FORMATSLIDERLABEL(lpreinitslider); | ||
68 | |||
69 | QSlider *preinitslider = new QSlider(0, 300, 1, 0, | ||
70 | QSlider::Horizontal, this); | ||
71 | // preinitslider->setFixedHeight(preinitslider->sizeHint().height()); | ||
72 | connect(preinitslider, SIGNAL(valueChanged(int)), | ||
73 | lpreinitslider, SLOT(setNum(int))); | ||
74 | l2->addWidget(lpreinitslider, 0); | ||
75 | l2->addWidget(preinitslider, 1); | ||
76 | |||
77 | lpreinit = new QLabel(i18n("Pre-init delay (sec/100):"), this); | ||
78 | l1->addWidget(lpreinit, row++, 1); | ||
79 | |||
80 | for(int i = 0; i < PPPData::NumInitStrings; i++) { | ||
81 | initstr[i] = new QLineEdit(this); | ||
82 | QLabel *initLabel = new QLabel(i18n("Initialization string %1:").arg(i + 1), | ||
83 | this); | ||
84 | ADJUSTEDIT(initstr[i]); | ||
85 | l1->addWidget(initLabel, row, 1); | ||
86 | l1->addWidget(initstr[i], row++, 2); | ||
87 | } | ||
88 | |||
89 | QHBoxLayout *l3 = new QHBoxLayout; | ||
90 | l1->addLayout(l3, row, 2); | ||
91 | linitslider = new QLabel("MMMM", this); | ||
92 | FORMATSLIDERLABEL(linitslider); | ||
93 | QSlider *initslider = new QSlider(1, 300, 1, 0, | ||
94 | QSlider::Horizontal, this); | ||
95 | // initslider->setFixedHeight(initslider->sizeHint().height()); | ||
96 | connect(initslider, SIGNAL(valueChanged(int)), | ||
97 | linitslider, SLOT(setNum(int))); | ||
98 | l3->addWidget(linitslider, 0); | ||
99 | l3->addWidget(initslider, 1); | ||
100 | |||
101 | label3 = new QLabel(i18n("Post-init delay (sec/100):"), this); | ||
102 | l1->addWidget(label3, row++, 1); | ||
103 | |||
104 | /* Set ATS11 (Dial tone duration) between 0-255 (Default ~ 70) */ | ||
105 | QHBoxLayout *l4 = new QHBoxLayout; | ||
106 | l1->addLayout(l4, row, 2); | ||
107 | ldurationslider = new QLabel("MMMM", this); | ||
108 | FORMATSLIDERLABEL(ldurationslider); | ||
109 | QSlider *durationslider = new QSlider(1, 255, 1, 0, | ||
110 | QSlider::Horizontal, this); | ||
111 | // durationslider->setFixedHeight(durationslider->sizeHint().height()); | ||
112 | connect(durationslider, SIGNAL(valueChanged(int)), | ||
113 | ldurationslider, SLOT(setNum(int))); | ||
114 | l4->addWidget(ldurationslider, 0); | ||
115 | l4->addWidget(durationslider, 1); | ||
116 | |||
117 | lduration = new QLabel(i18n("Dialing speed (sec/100):"), this); | ||
118 | l1->addWidget(lduration, row++, 1); | ||
119 | |||
120 | |||
121 | initresp = new QLineEdit(this); | ||
122 | label2 = new QLabel(i18n("Init response:"), this); | ||
123 | ADJUSTEDIT(initresp); | ||
124 | l1->addWidget(label2, row, 1); | ||
125 | l1->addWidget(initresp, row++, 2); | ||
126 | |||
127 | nodetectdialtone = new QLineEdit(this); | ||
128 | lnodetectdialtone = new QLabel(i18n("No dial tone detection:"), this); | ||
129 | ADJUSTEDIT(nodetectdialtone); | ||
130 | l1->addWidget(lnodetectdialtone, row, 1); | ||
131 | l1->addWidget(nodetectdialtone, row++, 2); | ||
132 | |||
133 | dialstr = new QLineEdit(this); | ||
134 | label4 = new QLabel(i18n("Dial string:"),this); | ||
135 | ADJUSTEDIT(dialstr); | ||
136 | l1->addWidget(label4, row, 1); | ||
137 | l1->addWidget(dialstr, row++, 2); | ||
138 | |||
139 | connectresp = new QLineEdit(this); | ||
140 | label5 = new QLabel(i18n("Connect response:"), this); | ||
141 | ADJUSTEDIT(connectresp); | ||
142 | l1->addWidget(label5, row, 1); | ||
143 | l1->addWidget(connectresp, row++, 2); | ||
144 | |||
145 | busyresp = new QLineEdit(this); | ||
146 | label6 = new QLabel(i18n("Busy response:"), this); | ||
147 | ADJUSTEDIT(busyresp); | ||
148 | l1->addWidget(label6, row, 1); | ||
149 | l1->addWidget(busyresp, row++, 2); | ||
150 | |||
151 | nocarrierresp = new QLineEdit(this); | ||
152 | label7 = new QLabel(i18n("No carrier response:"), this); | ||
153 | ADJUSTEDIT(nocarrierresp); | ||
154 | l1->addWidget(label7, row, 1); | ||
155 | l1->addWidget(nocarrierresp, row++, 2); | ||
156 | |||
157 | nodialtoneresp = new QLineEdit(this); | ||
158 | label8 = new QLabel(i18n("No dial tone response:"), this); | ||
159 | ADJUSTEDIT(nodialtoneresp); | ||
160 | l1->addWidget(label8, row, 1); | ||
161 | l1->addWidget(nodialtoneresp, row++, 2); | ||
162 | |||
163 | hangupstr = new QLineEdit(this); | ||
164 | label9 = new QLabel(i18n("Hangup string:"), this); | ||
165 | ADJUSTEDIT(hangupstr); | ||
166 | l1->addWidget(label9, row, 1); | ||
167 | l1->addWidget(hangupstr, row++, 2); | ||
168 | |||
169 | hangupresp = new QLineEdit(this); | ||
170 | label10 = new QLabel(i18n("Hangup response:"), this); | ||
171 | ADJUSTEDIT(hangupresp); | ||
172 | l1->addWidget(label10, row, 1); | ||
173 | l1->addWidget(hangupresp, row++, 2); | ||
174 | |||
175 | answerstr = new QLineEdit(this); | ||
176 | label11 = new QLabel(i18n("Answer string:"), this); | ||
177 | ADJUSTEDIT(answerstr); | ||
178 | l1->addWidget(label11, row, 1); | ||
179 | l1->addWidget(answerstr, row++, 2); | ||
180 | |||
181 | ringresp = new QLineEdit(this); | ||
182 | label12 = new QLabel(i18n("Ring response:"), this); | ||
183 | ADJUSTEDIT(ringresp); | ||
184 | l1->addWidget(label12, row, 1); | ||
185 | l1->addWidget(ringresp, row++, 2); | ||
186 | |||
187 | answerresp = new QLineEdit(this); | ||
188 | label13 = new QLabel(i18n("Answer response:"), this); | ||
189 | ADJUSTEDIT(answerresp); | ||
190 | l1->addWidget(label13, row, 1); | ||
191 | l1->addWidget(answerresp, row++, 2); | ||
192 | |||
193 | escapestr = new QLineEdit(this); | ||
194 | label14 = new QLabel(i18n("Escape string:"), this); | ||
195 | ADJUSTEDIT(escapestr); | ||
196 | l1->addWidget(label14, row, 1); | ||
197 | l1->addWidget(escapestr, row++, 2); | ||
198 | |||
199 | escaperesp = new QLineEdit(this); | ||
200 | label15 = new QLabel(i18n("Escape response:"), this); | ||
201 | ADJUSTEDIT(escaperesp); | ||
202 | l1->addWidget(label15, row, 1); | ||
203 | l1->addWidget(escaperesp, row++, 2); | ||
204 | |||
205 | QHBoxLayout *l5 = new QHBoxLayout; | ||
206 | l1->addLayout(l5, row, 2); | ||
207 | lslider = new QLabel("MMMM", this); | ||
208 | FORMATSLIDERLABEL(lslider); | ||
209 | |||
210 | QSlider *slider = new QSlider(0, 255, 1, 0, | ||
211 | QSlider::Horizontal, this); | ||
212 | // slider->setFixedHeight(slider->sizeHint().height()); | ||
213 | connect(slider, SIGNAL(valueChanged(int)), | ||
214 | lslider, SLOT(setNum(int))); | ||
215 | l5->addWidget(lslider, 0); | ||
216 | l5->addWidget(slider, 1); | ||
217 | |||
218 | label16 = new QLabel(i18n("Guard time (sec/50):"), this); | ||
219 | l1->addWidget(label16, row++, 1); | ||
220 | |||
221 | QLabel *l = new QLabel(i18n("Volume off/low/high:"), this); | ||
222 | l1->addWidget(l, row, 1); | ||
223 | QHBoxLayout *l6 = new QHBoxLayout; | ||
224 | l1->addLayout(l6, row++, 2); | ||
225 | volume_off = new QLineEdit(this); | ||
226 | // volume_off->setFixedHeight(volume_off->sizeHint().height()); | ||
227 | // volume_off->setMinimumWidth((int)(volume_off->sizeHint().width() / 2)); | ||
228 | volume_medium = new QLineEdit(this); | ||
229 | // volume_medium->setFixedHeight(volume_medium->sizeHint().height()); | ||
230 | // volume_medium->setMinimumWidth((int)(volume_medium->sizeHint().width() / 2)); | ||
231 | volume_high = new QLineEdit(this); | ||
232 | // volume_high->setFixedHeight(volume_high->sizeHint().height()); | ||
233 | // volume_high->setMinimumWidth((int)(volume_high->sizeHint().width() / 2)); | ||
234 | l6->addWidget(volume_off); | ||
235 | l6->addWidget(volume_medium); | ||
236 | l6->addWidget(volume_high); | ||
237 | |||
238 | initstr[0]->setFocus(); | ||
239 | |||
240 | l1->addColSpacing(0, 10); | ||
241 | l1->addColSpacing(3, 10); | ||
242 | l1->addRowSpacing(0, 5); | ||
243 | l1->addRowSpacing(GRIDROWS, 5); | ||
244 | |||
245 | //set stuff from gpppdata | ||
246 | preinitslider->setValue(gpppdata.modemPreInitDelay()); | ||
247 | lpreinitslider->setNum(gpppdata.modemPreInitDelay()); | ||
248 | for(int i = 0; i < PPPData::NumInitStrings; i++) | ||
249 | initstr[i]->setText(gpppdata.modemInitStr(i)); | ||
250 | initslider->setValue(gpppdata.modemInitDelay()); | ||
251 | linitslider->setNum(gpppdata.modemInitDelay()); | ||
252 | initresp->setText(gpppdata.modemInitResp()); | ||
253 | |||
254 | durationslider->setValue(gpppdata.modemToneDuration()); | ||
255 | ldurationslider->setNum(gpppdata.modemToneDuration()); | ||
256 | |||
257 | nodetectdialtone->setText(gpppdata.modemNoDialToneDetectionStr()); | ||
258 | dialstr->setText(gpppdata.modemDialStr()); | ||
259 | connectresp->setText(gpppdata.modemConnectResp()); | ||
260 | busyresp->setText(gpppdata.modemBusyResp()); | ||
261 | nocarrierresp->setText(gpppdata.modemNoCarrierResp()); | ||
262 | nodialtoneresp->setText(gpppdata.modemNoDialtoneResp()); | ||
263 | |||
264 | escapestr->setText(gpppdata.modemEscapeStr()); | ||
265 | escaperesp->setText(gpppdata.modemEscapeResp()); | ||
266 | |||
267 | hangupstr->setText(gpppdata.modemHangupStr()); | ||
268 | hangupresp->setText(gpppdata.modemHangupResp()); | ||
269 | |||
270 | answerstr->setText(gpppdata.modemAnswerStr()); | ||
271 | ringresp->setText(gpppdata.modemRingResp()); | ||
272 | answerresp->setText(gpppdata.modemAnswerResp()); | ||
273 | |||
274 | slider->setValue(gpppdata.modemEscapeGuardTime()); | ||
275 | lslider->setNum(gpppdata.modemEscapeGuardTime()); | ||
276 | |||
277 | volume_off->setText(gpppdata.volumeOff()); | ||
278 | volume_medium->setText(gpppdata.volumeMedium()); | ||
279 | volume_high->setText(gpppdata.volumeHigh()); | ||
280 | } | ||
281 | |||
282 | |||
283 | void ModemCommands::slotOk() { | ||
284 | gpppdata.setModemPreInitDelay(lpreinitslider->text().toInt()); | ||
285 | for(int i = 0; i < PPPData::NumInitStrings; i++) | ||
286 | gpppdata.setModemInitStr(i, initstr[i]->text()); | ||
287 | gpppdata.setModemInitResp(initresp->text()); | ||
288 | gpppdata.setModemInitDelay(linitslider->text().toInt()); | ||
289 | |||
290 | gpppdata.setModemToneDuration(ldurationslider->text().toInt()); | ||
291 | gpppdata.setModemNoDialToneDetectionStr(nodetectdialtone->text()); | ||
292 | gpppdata.setModemDialStr(dialstr->text()); | ||
293 | gpppdata.setModemConnectResp(connectresp->text()); | ||
294 | gpppdata.setModemBusyResp(busyresp->text()); | ||
295 | gpppdata.setModemNoCarrierResp(nocarrierresp->text()); | ||
296 | gpppdata.setModemNoDialtoneResp(nodialtoneresp->text()); | ||
297 | |||
298 | gpppdata.setModemEscapeStr(escapestr->text()); | ||
299 | gpppdata.setModemEscapeResp(escaperesp->text()); | ||
300 | gpppdata.setModemEscapeGuardTime(lslider->text().toInt()); | ||
301 | gpppdata.setModemHangupStr(hangupstr->text()); | ||
302 | gpppdata.setModemHangupResp(hangupresp->text()); | ||
303 | |||
304 | gpppdata.setModemAnswerStr(answerstr->text()); | ||
305 | gpppdata.setModemRingResp(ringresp->text()); | ||
306 | gpppdata.setModemAnswerResp(answerresp->text()); | ||
307 | |||
308 | gpppdata.setVolumeHigh(volume_high->text()); | ||
309 | gpppdata.setVolumeMedium(volume_medium->text()); | ||
310 | gpppdata.setVolumeOff(volume_off->text()); | ||
311 | |||
312 | gpppdata.save(); | ||
313 | accept(); | ||
314 | } | ||
315 | |||
316 | |||
317 | void ModemCommands::slotCancel() { | ||
318 | reject(); | ||
319 | } | ||
320 | |||
321 | //#include "modemcmds.moc" | ||
diff --git a/noncore/settings/networksettings/ppp/modemcmds.h b/noncore/settings/networksettings/ppp/modemcmds.h new file mode 100644 index 0000000..9d078ec --- a/dev/null +++ b/noncore/settings/networksettings/ppp/modemcmds.h | |||
@@ -0,0 +1,119 @@ | |||
1 | |||
2 | /* | ||
3 | * | ||
4 | * kPPP: A front end for pppd for the KDE project | ||
5 | * | ||
6 | * $Id$ | ||
7 | * | ||
8 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
9 | * wuebben@math.cornell.edu | ||
10 | * | ||
11 | * based on EzPPP: | ||
12 | * Copyright (C) 1997 Jay Painter | ||
13 | * | ||
14 | * This library is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU Library General Public | ||
16 | * License as published by the Free Software Foundation; either | ||
17 | * version 2 of the License, or (at your option) any later version. | ||
18 | * | ||
19 | * This library is distributed in the hope that it will be useful, | ||
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
22 | * Library General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU Library General Public | ||
25 | * License along with this program; if not, write to the Free | ||
26 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
27 | * | ||
28 | */ | ||
29 | |||
30 | |||
31 | #ifndef _MODEMCMDS_H_ | ||
32 | #define _MODEMCMDS_H_ | ||
33 | |||
34 | #include <qgroupbox.h> | ||
35 | #include <qdialog.h> | ||
36 | #include <qlineedit.h> | ||
37 | #include <qpushbutton.h> | ||
38 | #include <qlabel.h> | ||
39 | #include "pppdata.h" | ||
40 | |||
41 | class ModemCommands : public QDialog { | ||
42 | |||
43 | Q_OBJECT | ||
44 | |||
45 | public: | ||
46 | |||
47 | ModemCommands(QWidget *parent=0, const char *name=0); | ||
48 | ~ModemCommands() {} | ||
49 | |||
50 | private slots: | ||
51 | void slotCancel(); | ||
52 | void slotOk(); | ||
53 | |||
54 | private: | ||
55 | |||
56 | QGroupBox *box; | ||
57 | |||
58 | QLineEdit *initstr[int(PPPData::NumInitStrings)]; | ||
59 | |||
60 | QLineEdit *initresp; | ||
61 | QLabel *label2; | ||
62 | |||
63 | QLabel *lpreinitslider; | ||
64 | QLabel *lpreinit; | ||
65 | |||
66 | QLabel *linitslider; | ||
67 | QLabel *label3; | ||
68 | |||
69 | QLabel *ldurationslider; | ||
70 | QLabel *lduration; | ||
71 | |||
72 | QLineEdit *nodetectdialtone; | ||
73 | QLabel *lnodetectdialtone; | ||
74 | |||
75 | QLineEdit *dialstr; | ||
76 | QLabel *label4; | ||
77 | |||
78 | QLineEdit *connectresp; | ||
79 | QLabel *label5; | ||
80 | |||
81 | QLineEdit *busyresp; | ||
82 | QLabel *label6; | ||
83 | |||
84 | QLineEdit *nocarrierresp; | ||
85 | QLabel *label7; | ||
86 | |||
87 | QLineEdit *nodialtoneresp; | ||
88 | QLabel *label8; | ||
89 | |||
90 | QLineEdit *hangupstr; | ||
91 | QLabel *label9; | ||
92 | |||
93 | QLineEdit *hangupresp; | ||
94 | QLabel *label10; | ||
95 | |||
96 | QLineEdit *answerstr; | ||
97 | QLabel *label11; | ||
98 | |||
99 | QLineEdit *ringresp; | ||
100 | QLabel *label12; | ||
101 | |||
102 | QLineEdit *answerresp; | ||
103 | QLabel *label13; | ||
104 | |||
105 | QLineEdit *escapestr; | ||
106 | QLabel *label14; | ||
107 | |||
108 | QLineEdit *escaperesp; | ||
109 | QLabel *label15; | ||
110 | |||
111 | QLabel *lslider; | ||
112 | QLabel *label16; | ||
113 | |||
114 | QLineEdit *volume_off, *volume_medium, *volume_high; | ||
115 | }; | ||
116 | #endif | ||
117 | |||
118 | |||
119 | |||
diff --git a/noncore/settings/networksettings/ppp/modeminfo.cpp b/noncore/settings/networksettings/ppp/modeminfo.cpp index 8c81e67..4dbbcf5 100644 --- a/noncore/settings/networksettings/ppp/modeminfo.cpp +++ b/noncore/settings/networksettings/ppp/modeminfo.cpp | |||
@@ -107,2 +107,3 @@ void ModemTransfer::ati_done() { | |||
107 | mi->setAtiString(i, ati_query_strings[i]); | 107 | mi->setAtiString(i, ati_query_strings[i]); |
108 | mi->showMaximized(); | ||
108 | mi->exec(); | 109 | mi->exec(); |
diff --git a/noncore/settings/networksettings/ppp/newwidget.cpp b/noncore/settings/networksettings/ppp/newwidget.cpp new file mode 100644 index 0000000..d2182fb --- a/dev/null +++ b/noncore/settings/networksettings/ppp/newwidget.cpp | |||
@@ -0,0 +1,17 @@ | |||
1 | ///////////////////////////////////////////////////////////////////////////// | ||
2 | // | ||
3 | // functions generating layout-aware widgets | ||
4 | // | ||
5 | ///////////////////////////////////////////////////////////////////////////// | ||
6 | |||
7 | #include "newwidget.h" | ||
8 | |||
9 | QLineEdit *newLineEdit(int visiblewidth, QWidget *parent) { | ||
10 | QLineEdit *l = new QLineEdit(parent); | ||
11 | if(visiblewidth == 0) | ||
12 | l->setMinimumWidth(l->sizeHint().width()); | ||
13 | else | ||
14 | l->setFixedWidth(l->fontMetrics().width('H') * visiblewidth); | ||
15 | |||
16 | return l; | ||
17 | } | ||
diff --git a/noncore/settings/networksettings/ppp/newwidget.h b/noncore/settings/networksettings/ppp/newwidget.h new file mode 100644 index 0000000..52f2ec7 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/newwidget.h | |||
@@ -0,0 +1,19 @@ | |||
1 | ///////////////////////////////////////////////////////////////////////////// | ||
2 | // | ||
3 | // functions generating layout-aware widgets | ||
4 | // | ||
5 | ///////////////////////////////////////////////////////////////////////////// | ||
6 | |||
7 | #ifndef __NEWWIDGET__H__ | ||
8 | #define __NEWWIDGET__H__ | ||
9 | |||
10 | #include <qwidget.h> | ||
11 | #include <qlineedit.h> | ||
12 | |||
13 | #define L_FIXEDW 1 | ||
14 | #define L_FIXEDH 2 | ||
15 | #define L_FIXED (L_FIXEDW | L_FIXEDH) | ||
16 | |||
17 | QLineEdit *newLineEdit(int visiblewidth, QWidget *parent); | ||
18 | |||
19 | #endif | ||
diff --git a/noncore/settings/networksettings/ppp/ppp.pro b/noncore/settings/networksettings/ppp/ppp.pro index da32395..a456427 100644 --- a/noncore/settings/networksettings/ppp/ppp.pro +++ b/noncore/settings/networksettings/ppp/ppp.pro | |||
@@ -1,2 +1,3 @@ | |||
1 | #TEMPLATE = app | 1 | #TEMPLATE = app |
2 | # | ||
2 | TEMPLATE = lib | 3 | TEMPLATE = lib |
@@ -5,4 +6,4 @@ CONFIG += qt warn_on debug | |||
5 | DESTDIR = $(OPIEDIR)/plugins/networksettings | 6 | DESTDIR = $(OPIEDIR)/plugins/networksettings |
6 | HEADERS = pppimp.h pppmodule.h devices.h modem.h modeminfo.h pppdata.h kpppconfig.h pppdata.h runtests.h | 7 | HEADERS = pppmodule.h devices.h modem.h modeminfo.h pppdata.h kpppconfig.h pppdata.h runtests.h general.h modemcmds.h knuminput.h knumvalidator.h kpppwidget.h conwindow.h debug.h accounts.h connect.h edit.h scriptedit.h pppdargs.h newwidget.h iplined.h pwentry.h pppconfig.h |
7 | SOURCES = pppimp.cpp pppmodule.cpp modem.cpp modeminfo.cpp pppdata.cpp runtests.cpp | 8 | SOURCES = pppmodule.cpp modem.cpp modeminfo.cpp pppdata.cpp runtests.cpp general.cpp modemcmds.cpp knuminput.cpp knumvalidator.cpp kpppwidget.cpp conwindow.cpp debug.cpp accounts.cpp connect.cpp edit.cpp scriptedit.cpp pppdargs.cpp newwidget.cpp iplined.cpp pwentry.cpp pppconfig.cpp |
8 | INCLUDEPATH+= $(OPIEDIR)/include ../ ../interfaces/ | 9 | INCLUDEPATH+= $(OPIEDIR)/include ../ ../interfaces/ |
@@ -10,3 +11,3 @@ DEPENDPATH += $(OPIEDIR)/include | |||
10 | LIBS += -lqpe -L../interfaces/ -linterfaces | 11 | LIBS += -lqpe -L../interfaces/ -linterfaces |
11 | INTERFACES= ppp.ui | 12 | INTERFACES= |
12 | TARGET = pppplugin | 13 | TARGET = pppplugin |
diff --git a/noncore/settings/networksettings/ppp/pppconfig.cpp b/noncore/settings/networksettings/ppp/pppconfig.cpp new file mode 100644 index 0000000..7b2b21b --- a/dev/null +++ b/noncore/settings/networksettings/ppp/pppconfig.cpp | |||
@@ -0,0 +1,62 @@ | |||
1 | |||
2 | #include <qlayout.h> | ||
3 | #include <qmessagebox.h> | ||
4 | #include <qtabwidget.h> | ||
5 | |||
6 | #include "accounts.h" | ||
7 | #include "general.h" | ||
8 | #include "pppconfig.h" | ||
9 | #include "pppdata.h" | ||
10 | #include "runtests.h" | ||
11 | #include "modem.h" | ||
12 | |||
13 | PPPConfigWidget::PPPConfigWidget( QWidget *parent, const char *name, | ||
14 | bool modal, WFlags fl ) | ||
15 | : QDialog(parent, name, modal, fl) | ||
16 | { | ||
17 | setCaption(tr("Configure Modem")); | ||
18 | int result = runTests(); | ||
19 | if(result == TEST_CRITICAL){ | ||
20 | QMessageBox::critical(0, tr("Modem failure"), tr("A critical failure appeard while testing the modem") ); | ||
21 | return; | ||
22 | } | ||
23 | |||
24 | // setFixedSize(sizeHint()); | ||
25 | |||
26 | (void)new Modem; | ||
27 | |||
28 | QVBoxLayout *layout = new QVBoxLayout( this ); | ||
29 | layout->setSpacing( 0 ); | ||
30 | layout->setMargin( 1 ); | ||
31 | tabWindow = new QTabWidget( this, "tabWidget" ); | ||
32 | layout->addWidget( tabWindow ); | ||
33 | |||
34 | accounts = new AccountWidget( tabWindow, "accounts" ); | ||
35 | tabWindow->addTab( accounts, tr("&Accounts") ); | ||
36 | modem1 = new ModemWidget( tabWindow, "modem1" ); | ||
37 | tabWindow->addTab( modem1, tr("&Device") ); | ||
38 | modem2 = new ModemWidget2( tabWindow, "modem2" ); | ||
39 | tabWindow->addTab( modem2, tr("&Modem") ); | ||
40 | // graph = new GraphSetup( tabWindow->addPage( tr("&Graph"), tr("Throughput Graph" ) ) ); | ||
41 | // general = new GeneralWidget( tabWindow->addPage( tr("M&isc"), tr("Miscellaneous Settings") ) ); | ||
42 | |||
43 | } | ||
44 | |||
45 | |||
46 | PPPConfigWidget::~PPPConfigWidget() | ||
47 | { | ||
48 | |||
49 | } | ||
50 | |||
51 | void PPPConfigWidget::accept() | ||
52 | { | ||
53 | gpppdata.save(); | ||
54 | QDialog::accept(); | ||
55 | } | ||
56 | |||
57 | |||
58 | void PPPConfigWidget::reject() | ||
59 | { | ||
60 | gpppdata.cancel(); | ||
61 | QDialog::reject(); | ||
62 | } | ||
diff --git a/noncore/settings/networksettings/ppp/pppconfig.h b/noncore/settings/networksettings/ppp/pppconfig.h new file mode 100644 index 0000000..ec64878 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/pppconfig.h | |||
@@ -0,0 +1,34 @@ | |||
1 | #ifndef _PPPCONFIG_H_ | ||
2 | #define _PPPCONFIG_H_ | ||
3 | |||
4 | #include <qdialog.h> | ||
5 | |||
6 | class QTabWidget; | ||
7 | class AccountWidget; | ||
8 | class GeneralWidget; | ||
9 | class ModemWidget; | ||
10 | class ModemWidget2; | ||
11 | |||
12 | class PPPConfigWidget : public QDialog { | ||
13 | Q_OBJECT | ||
14 | public: | ||
15 | |||
16 | PPPConfigWidget( QWidget *parent=0, const char *name=0, | ||
17 | bool modal = false, WFlags fl = 0 ); | ||
18 | ~PPPConfigWidget(); | ||
19 | |||
20 | |||
21 | protected slots: | ||
22 | virtual void accept(); | ||
23 | virtual void reject(); | ||
24 | |||
25 | private: | ||
26 | QTabWidget *tabWindow; | ||
27 | AccountWidget *accounts; | ||
28 | GeneralWidget *general; | ||
29 | ModemWidget *modem1; | ||
30 | ModemWidget2 *modem2; | ||
31 | }; | ||
32 | |||
33 | |||
34 | #endif | ||
diff --git a/noncore/settings/networksettings/ppp/pppdargs.cpp b/noncore/settings/networksettings/ppp/pppdargs.cpp new file mode 100644 index 0000000..04d0dd0 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/pppdargs.cpp | |||
@@ -0,0 +1,166 @@ | |||
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 | * | ||
13 | * This library is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU Library General Public | ||
15 | * License as published by the Free Software Foundation; either | ||
16 | * version 2 of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This library is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
21 | * Library General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU Library General Public | ||
24 | * License along with this program; if not, write to the Free | ||
25 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
26 | */ | ||
27 | |||
28 | #include <qlayout.h> | ||
29 | #include <qbuttongroup.h> | ||
30 | //#include <kwin.h> | ||
31 | #include <qapplication.h> | ||
32 | #include "pppdargs.h" | ||
33 | #include "pppdata.h" | ||
34 | //#include <klocale.h> | ||
35 | #define i18n QObject::tr | ||
36 | |||
37 | PPPdArguments::PPPdArguments(QWidget *parent, const char *name) | ||
38 | : QDialog(parent, name, TRUE) | ||
39 | { | ||
40 | setCaption(i18n("Customize pppd Arguments")); | ||
41 | // KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); | ||
42 | QVBoxLayout *l = new QVBoxLayout(this, 10, 10); | ||
43 | QHBoxLayout *tl = new QHBoxLayout(10); | ||
44 | l->addLayout(tl); | ||
45 | QVBoxLayout *l1 = new QVBoxLayout(); | ||
46 | QVBoxLayout *l2 = new QVBoxLayout(); | ||
47 | tl->addLayout(l1, 1); | ||
48 | tl->addLayout(l2, 0); | ||
49 | |||
50 | QHBoxLayout *l11 = new QHBoxLayout(10); | ||
51 | l1->addLayout(l11); | ||
52 | |||
53 | argument_label = new QLabel(i18n("Argument:"), this); | ||
54 | l11->addWidget(argument_label); | ||
55 | |||
56 | argument = new QLineEdit(this); | ||
57 | connect(argument, SIGNAL(returnPressed()), | ||
58 | SLOT(addbutton())); | ||
59 | l11->addWidget(argument); | ||
60 | connect(argument, SIGNAL(textChanged(const QString &)), | ||
61 | this, SLOT(textChanged(const QString &))); | ||
62 | |||
63 | arguments = new QListBox(this); | ||
64 | arguments->setMinimumSize(1, fontMetrics().lineSpacing()*10); | ||
65 | connect(arguments, SIGNAL(highlighted(int)), | ||
66 | this, SLOT(itemSelected(int))); | ||
67 | l1->addWidget(arguments, 1); | ||
68 | |||
69 | add = new QPushButton(i18n("Add"), this); | ||
70 | connect(add, SIGNAL(clicked()), SLOT(addbutton())); | ||
71 | l2->addWidget(add); | ||
72 | l2->addStretch(1); | ||
73 | |||
74 | remove = new QPushButton(i18n("Remove"), this); | ||
75 | connect(remove, SIGNAL(clicked()), SLOT(removebutton())); | ||
76 | l2->addWidget(remove); | ||
77 | |||
78 | defaults = new QPushButton(i18n("Defaults"), this); | ||
79 | connect(defaults, SIGNAL(clicked()), SLOT(defaultsbutton())); | ||
80 | l2->addWidget(defaults); | ||
81 | |||
82 | l->addSpacing(5); | ||
83 | |||
84 | QButtonGroup *bbox = new QButtonGroup(this); | ||
85 | // bbox->addStretch(1); | ||
86 | closebtn = new QPushButton( bbox, i18n("OK")); | ||
87 | bbox->insert(closebtn); | ||
88 | connect(closebtn, SIGNAL(clicked()), SLOT(closebutton())); | ||
89 | QPushButton *cancel = new QPushButton( bbox, i18n("Cancel")); | ||
90 | bbox->insert(cancel); | ||
91 | connect(cancel, SIGNAL(clicked()), | ||
92 | this, SLOT(reject())); | ||
93 | bbox->layout(); | ||
94 | l->addWidget(bbox); | ||
95 | |||
96 | setFixedSize(sizeHint()); | ||
97 | |||
98 | //load info from gpppdata | ||
99 | init(); | ||
100 | |||
101 | add->setEnabled(false); | ||
102 | remove->setEnabled(false); | ||
103 | argument->setFocus(); | ||
104 | } | ||
105 | |||
106 | |||
107 | void PPPdArguments::addbutton() { | ||
108 | if(!argument->text().isEmpty() && arguments->count() < MAX_PPPD_ARGUMENTS) { | ||
109 | arguments->insertItem(argument->text()); | ||
110 | argument->setText(""); | ||
111 | } | ||
112 | } | ||
113 | |||
114 | |||
115 | void PPPdArguments::removebutton() { | ||
116 | if(arguments->currentItem() >= 0) | ||
117 | arguments->removeItem(arguments->currentItem()); | ||
118 | } | ||
119 | |||
120 | |||
121 | void PPPdArguments::defaultsbutton() { | ||
122 | // all of this is a hack | ||
123 | // save current list | ||
124 | QStringList arglist(gpppdata.pppdArgument()); | ||
125 | |||
126 | // get defaults | ||
127 | gpppdata.setpppdArgumentDefaults(); | ||
128 | init(); | ||
129 | |||
130 | // restore old list | ||
131 | gpppdata.setpppdArgument(arglist); | ||
132 | } | ||
133 | |||
134 | |||
135 | void PPPdArguments::closebutton() { | ||
136 | QStringList arglist; | ||
137 | for(uint i=0; i < arguments->count(); i++) | ||
138 | arglist.append(arguments->text(i)); | ||
139 | gpppdata.setpppdArgument(arglist); | ||
140 | |||
141 | done(0); | ||
142 | } | ||
143 | |||
144 | |||
145 | void PPPdArguments::init() { | ||
146 | while(arguments->count()) | ||
147 | arguments->removeItem(0); | ||
148 | |||
149 | QStringList &arglist = gpppdata.pppdArgument(); | ||
150 | for ( QStringList::Iterator it = arglist.begin(); | ||
151 | it != arglist.end(); | ||
152 | ++it ) | ||
153 | arguments->insertItem(*it); | ||
154 | } | ||
155 | |||
156 | |||
157 | void PPPdArguments::textChanged(const QString &s) { | ||
158 | add->setEnabled(s.length() > 0); | ||
159 | } | ||
160 | |||
161 | |||
162 | void PPPdArguments::itemSelected(int idx) { | ||
163 | remove->setEnabled(idx != -1); | ||
164 | } | ||
165 | |||
166 | |||
diff --git a/noncore/settings/networksettings/ppp/pppdargs.h b/noncore/settings/networksettings/ppp/pppdargs.h new file mode 100644 index 0000000..c1cd28d --- a/dev/null +++ b/noncore/settings/networksettings/ppp/pppdargs.h | |||
@@ -0,0 +1,76 @@ | |||
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 | * | ||
13 | * This library is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU Library General Public | ||
15 | * License as published by the Free Software Foundation; either | ||
16 | * version 2 of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This library is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
21 | * Library General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU Library General Public | ||
24 | * License along with this program; if not, write to the Free | ||
25 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
26 | */ | ||
27 | |||
28 | #ifndef _PPPDARGS_H_ | ||
29 | #define _PPPDARGS_H_ | ||
30 | |||
31 | #include <qdialog.h> | ||
32 | #include <qlineedit.h> | ||
33 | #include <qpushbutton.h> | ||
34 | #include <qlistbox.h> | ||
35 | #include <qlabel.h> | ||
36 | |||
37 | class PPPdArguments : public QDialog { | ||
38 | Q_OBJECT | ||
39 | public: | ||
40 | PPPdArguments(QWidget *parent=0, const char *name=0); | ||
41 | ~PPPdArguments() {} | ||
42 | |||
43 | private slots: | ||
44 | void addbutton(); | ||
45 | void removebutton(); | ||
46 | void defaultsbutton(); | ||
47 | void closebutton(); | ||
48 | void textChanged(const QString &); | ||
49 | void itemSelected(int); | ||
50 | |||
51 | private: | ||
52 | void init(); | ||
53 | |||
54 | QLabel *argument_label; | ||
55 | |||
56 | QLineEdit *argument; | ||
57 | |||
58 | QPushButton *add; | ||
59 | QPushButton *remove; | ||
60 | QPushButton *defaults; | ||
61 | |||
62 | QListBox *arguments; | ||
63 | |||
64 | QPushButton *closebtn; | ||
65 | }; | ||
66 | #endif | ||
67 | |||
68 | |||
69 | |||
70 | |||
71 | |||
72 | |||
73 | |||
74 | |||
75 | |||
76 | |||
diff --git a/noncore/settings/networksettings/ppp/pppmodule.cpp b/noncore/settings/networksettings/ppp/pppmodule.cpp index 40d2455..d6ca88a 100644 --- a/noncore/settings/networksettings/ppp/pppmodule.cpp +++ b/noncore/settings/networksettings/ppp/pppmodule.cpp | |||
@@ -1,3 +1,5 @@ | |||
1 | #include "pppconfig.h" | ||
1 | #include "pppmodule.h" | 2 | #include "pppmodule.h" |
2 | #include "pppimp.h" | 3 | //#include "pppimp.h" |
4 | #include "kpppwidget.h" | ||
3 | #include "interfaceinformationimp.h" | 5 | #include "interfaceinformationimp.h" |
@@ -55,3 +57,4 @@ bool PPPModule::isOwner(Interface *i){ | |||
55 | QWidget *PPPModule::configure(Interface *i){ | 57 | QWidget *PPPModule::configure(Interface *i){ |
56 | PPPConfigureImp *pppconfig = new PPPConfigureImp(0, "PPPConfig", /* i,*/ false, Qt::WDestructiveClose); | 58 | qDebug("return ModemWidget"); |
59 | PPPConfigWidget *pppconfig = new PPPConfigWidget( 0, "PPPConfig", false, Qt::WDestructiveClose ); | ||
57 | // pppconfig->setProfile(profile); | 60 | // pppconfig->setProfile(profile); |
@@ -67,2 +70,3 @@ QWidget *PPPModule::information(Interface *i){ | |||
67 | // TODO ^ | 70 | // TODO ^ |
71 | qDebug("return PPPModule::information"); | ||
68 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i); | 72 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i); |
@@ -88,5 +92,6 @@ QList<Interface> PPPModule::getInterfaces(){ | |||
88 | Interface *PPPModule::addNewInterface(const QString &newInterface){ | 92 | Interface *PPPModule::addNewInterface(const QString &newInterface){ |
89 | // If the | 93 | |
90 | qDebug("try to add iface %s",newInterface.latin1()); | 94 | qDebug("try to add iface %s",newInterface.latin1()); |
91 | PPPConfigureImp imp(0, "PPPConfigImp"); | 95 | |
96 | PPPConfigWidget imp(0, "PPPConfigImp", true); | ||
92 | imp.showMaximized(); | 97 | imp.showMaximized(); |
diff --git a/noncore/settings/networksettings/ppp/pwentry.cpp b/noncore/settings/networksettings/ppp/pwentry.cpp new file mode 100644 index 0000000..842dc87 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/pwentry.cpp | |||
@@ -0,0 +1,116 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Kppp: A pppd front end for the KDE project | ||
4 | * | ||
5 | * $Id$ | ||
6 | * | ||
7 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
8 | * wuebben@math.cornell.edu | ||
9 | * | ||
10 | * | ||
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. | ||
15 | * | ||
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. | ||
20 | * | ||
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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
24 | */ | ||
25 | |||
26 | |||
27 | |||
28 | #include <stdio.h> | ||
29 | #include <qapplication.h> | ||
30 | #include "pwentry.h" | ||
31 | |||
32 | PWEntry::PWEntry( QWidget *parent, const char *name ) | ||
33 | : QWidget(NULL, name) { | ||
34 | |||
35 | if(parent){ | ||
36 | |||
37 | QPoint point = this->mapToGlobal (QPoint (0,0)); | ||
38 | QRect pos = this->geometry(); | ||
39 | |||
40 | setGeometry(point.x() + pos.width()/2 - 300/2, | ||
41 | point.y() + pos.height()/2 - 90/2, | ||
42 | 300, | ||
43 | 90); | ||
44 | } | ||
45 | // else{ | ||
46 | // int scnum = QApplication::desktop()->screenNumber(parent); | ||
47 | // QRect desk = QApplication::desktop()->screenGeometry(scnum); | ||
48 | // setGeometry( desk.center().x() - 150, desk.center().y() - 50, 300, 90 ); | ||
49 | // } | ||
50 | |||
51 | frame = new QGroupBox(name, this ); | ||
52 | |||
53 | this->setFocusPolicy( QWidget::StrongFocus ); | ||
54 | |||
55 | pw = new QLineEdit( this, "le" ); | ||
56 | pw->setEchoMode( QLineEdit::Password ); | ||
57 | connect( pw, SIGNAL(returnPressed()), this, SLOT(hide()) ); | ||
58 | |||
59 | isconsumed = TRUE; | ||
60 | } | ||
61 | |||
62 | QString PWEntry::text() { return (pw->text()); } | ||
63 | |||
64 | void PWEntry::focusInEvent( QFocusEvent *){ | ||
65 | |||
66 | pw->setFocus(); | ||
67 | |||
68 | } | ||
69 | |||
70 | void PWEntry::setEchoModeNormal() { | ||
71 | |||
72 | pw->setEchoMode(QLineEdit::Normal); | ||
73 | |||
74 | } | ||
75 | |||
76 | void PWEntry::setEchoModePassword() { | ||
77 | |||
78 | pw->setEchoMode(QLineEdit::Password); | ||
79 | |||
80 | } | ||
81 | |||
82 | void PWEntry::setPrompt(const QString &p) { | ||
83 | |||
84 | frame->setTitle(p); | ||
85 | |||
86 | } | ||
87 | |||
88 | void PWEntry::resizeEvent(QResizeEvent* ){ | ||
89 | |||
90 | pw->setGeometry( 15,35, this->width() - 30, 25 ); | ||
91 | frame->setGeometry(5,5,this->width() - 10, this->height() - 10 ); | ||
92 | |||
93 | } | ||
94 | |||
95 | |||
96 | void PWEntry::show() { | ||
97 | |||
98 | pw->setText(""); | ||
99 | isconsumed = FALSE; | ||
100 | QWidget::show(); | ||
101 | } | ||
102 | |||
103 | bool PWEntry::Consumed() { | ||
104 | return(isconsumed); | ||
105 | } | ||
106 | |||
107 | void PWEntry::setConsumed() { | ||
108 | isconsumed = TRUE; | ||
109 | } | ||
110 | |||
111 | void PWEntry::hide() { | ||
112 | QWidget::hide(); | ||
113 | return; | ||
114 | } | ||
115 | |||
116 | //#include "pwentry.moc" | ||
diff --git a/noncore/settings/networksettings/ppp/pwentry.h b/noncore/settings/networksettings/ppp/pwentry.h new file mode 100644 index 0000000..4a5e554 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/pwentry.h | |||
@@ -0,0 +1,72 @@ | |||
1 | /* | ||
2 | * | ||
3 | * kPPP: A pppd front end for the KDE project | ||
4 | * | ||
5 | * $Id$ | ||
6 | * | ||
7 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
8 | * wuebben@math.cornell.edu | ||
9 | * | ||
10 | * | ||
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. | ||
15 | * | ||
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. | ||
20 | * | ||
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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
24 | */ | ||
25 | |||
26 | |||
27 | #ifndef PWENTRY_H | ||
28 | #define PWENTRY_H | ||
29 | |||
30 | #include <qwidget.h> | ||
31 | #include <qlineedit.h> | ||
32 | #include <qlabel.h> | ||
33 | #include <qgroupbox.h> | ||
34 | |||
35 | class PWEntry : public QWidget { | ||
36 | |||
37 | Q_OBJECT | ||
38 | |||
39 | public: | ||
40 | |||
41 | PWEntry( QWidget *parent=0, const char *name=0 ); | ||
42 | bool Consumed(); | ||
43 | void setConsumed(); | ||
44 | QString text(); | ||
45 | void setPrompt(const QString &); | ||
46 | |||
47 | public slots: | ||
48 | |||
49 | void setEchoModeNormal(); | ||
50 | void setEchoModePassword(); | ||
51 | void hide(); | ||
52 | void show(); | ||
53 | |||
54 | signals: | ||
55 | |||
56 | void returnPressed(); | ||
57 | |||
58 | protected: | ||
59 | |||
60 | void resizeEvent(QResizeEvent* qre); | ||
61 | void focusInEvent( QFocusEvent *); | ||
62 | |||
63 | private: | ||
64 | |||
65 | QGroupBox *frame; | ||
66 | QLineEdit *pw; | ||
67 | QLabel *pl; | ||
68 | bool isconsumed; | ||
69 | |||
70 | }; | ||
71 | |||
72 | #endif | ||
diff --git a/noncore/settings/networksettings/ppp/scriptedit.cpp b/noncore/settings/networksettings/ppp/scriptedit.cpp new file mode 100644 index 0000000..b8afad5 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/scriptedit.cpp | |||
@@ -0,0 +1,174 @@ | |||
1 | |||
2 | /* | ||
3 | * kPPP: A front end for pppd for the KDE project | ||
4 | * | ||
5 | * $Id$ | ||
6 | * | ||
7 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
8 | * wuebben@math.cornell.edu | ||
9 | * | ||
10 | * based on EzPPP: | ||
11 | * Copyright (C) 1997 Jay Painter | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU Library General Public | ||
15 | * License as published by the Free Software Foundation; either | ||
16 | * version 2 of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
21 | * Library General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU Library General Public | ||
24 | * License along with this program; if not, write to the Free | ||
25 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
26 | */ | ||
27 | |||
28 | #include "scriptedit.h" | ||
29 | #include <qlayout.h> | ||
30 | #include <qcombobox.h> | ||
31 | #include <qlineedit.h> | ||
32 | |||
33 | ScriptEdit::ScriptEdit( QWidget *parent, const char *name ) | ||
34 | : QWidget(parent, name) | ||
35 | { | ||
36 | QHBoxLayout *tl = new QHBoxLayout(this, 0, 10); | ||
37 | |||
38 | st = new QComboBox(this, "st"); | ||
39 | st->insertItem("Expect"); | ||
40 | st->insertItem("Send"); | ||
41 | st->insertItem("Pause (sec)"); | ||
42 | st->insertItem("Hangup"); | ||
43 | st->insertItem("Answer"); | ||
44 | st->insertItem("Timeout (sec)"); | ||
45 | st->insertItem("Password"); | ||
46 | st->insertItem("ID"); | ||
47 | st->insertItem("Prompt"); | ||
48 | st->insertItem("PWPrompt"); | ||
49 | st->insertItem("LoopStart"); | ||
50 | st->insertItem("LoopEnd"); | ||
51 | st->insertItem("Scan"); | ||
52 | st->insertItem("Save"); | ||
53 | st->insertItem("SendNoEcho"); | ||
54 | connect(st, SIGNAL(activated(int)), SLOT(setType(int))); | ||
55 | |||
56 | se = new QLineEdit(this, "se"); | ||
57 | se->setGeometry(120, 5, 140, 25); | ||
58 | se->setMaxLength(50); | ||
59 | connect(se, SIGNAL(returnPressed()), SLOT(seReturnPressed())); | ||
60 | |||
61 | tl->addWidget(st, 3); | ||
62 | tl->addWidget(se, 7); | ||
63 | |||
64 | setType(0); | ||
65 | |||
66 | tl->activate(); | ||
67 | } | ||
68 | |||
69 | |||
70 | void ScriptEdit::setEnabled(bool b) { | ||
71 | se->setEnabled(b); | ||
72 | st->setEnabled(b); | ||
73 | } | ||
74 | |||
75 | void ScriptEdit::seReturnPressed() { | ||
76 | emit returnPressed(); | ||
77 | } | ||
78 | |||
79 | |||
80 | QString ScriptEdit::text() { | ||
81 | return se->text(); | ||
82 | } | ||
83 | |||
84 | void ScriptEdit::setText(const QString &t) { | ||
85 | se->setText(t); | ||
86 | } | ||
87 | |||
88 | |||
89 | int ScriptEdit::type() { | ||
90 | return st->currentItem(); | ||
91 | } | ||
92 | |||
93 | void ScriptEdit::setType(int i) { | ||
94 | switch(i) { | ||
95 | case Expect: | ||
96 | se->setText(""); | ||
97 | se->setEnabled(TRUE); | ||
98 | break; | ||
99 | |||
100 | case Send: | ||
101 | se->setText(""); | ||
102 | se->setEnabled(TRUE); | ||
103 | break; | ||
104 | |||
105 | case Pause: | ||
106 | se->setText(""); | ||
107 | se->setEnabled(TRUE); | ||
108 | break; | ||
109 | |||
110 | case Hangup: | ||
111 | se->setText(""); | ||
112 | se->setEnabled(FALSE); | ||
113 | break; | ||
114 | |||
115 | case Answer: | ||
116 | se->setText(""); | ||
117 | se->setEnabled(FALSE); | ||
118 | break; | ||
119 | |||
120 | case Timeout: | ||
121 | se->setText(""); | ||
122 | se->setEnabled(TRUE); | ||
123 | break; | ||
124 | |||
125 | case Password: | ||
126 | se->setText(""); | ||
127 | se->setEnabled(TRUE); | ||
128 | break; | ||
129 | |||
130 | case ID: | ||
131 | se->setText(""); | ||
132 | se->setEnabled(TRUE); | ||
133 | break; | ||
134 | |||
135 | case Prompt: | ||
136 | se->setText(""); | ||
137 | se->setEnabled(TRUE); | ||
138 | break; | ||
139 | |||
140 | case PWPrompt: | ||
141 | se->setText(""); | ||
142 | se->setEnabled(TRUE); | ||
143 | break; | ||
144 | |||
145 | case LoopStart: | ||
146 | se->setText(""); | ||
147 | se->setEnabled(TRUE); | ||
148 | break; | ||
149 | |||
150 | case LoopEnd: | ||
151 | se->setText(""); | ||
152 | se->setEnabled(TRUE); | ||
153 | break; | ||
154 | |||
155 | case Scan: | ||
156 | se->setText(""); | ||
157 | se->setEnabled(TRUE); | ||
158 | break; | ||
159 | |||
160 | case Save: | ||
161 | se->setText("password"); | ||
162 | se->setEnabled(FALSE); | ||
163 | break; | ||
164 | |||
165 | default: break; | ||
166 | } | ||
167 | } | ||
168 | |||
169 | |||
170 | |||
171 | |||
172 | |||
173 | |||
174 | |||
diff --git a/noncore/settings/networksettings/ppp/scriptedit.h b/noncore/settings/networksettings/ppp/scriptedit.h new file mode 100644 index 0000000..47565b8 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/scriptedit.h | |||
@@ -0,0 +1,79 @@ | |||
1 | |||
2 | /* | ||
3 | * kPPP: A front end for pppd for the KDE project | ||
4 | * | ||
5 | * $Id$ | ||
6 | * | ||
7 | * Copyright (C) 1997 Bernd Johannes Wuebben | ||
8 | * wuebben@math.cornell.edu | ||
9 | * | ||
10 | * based on EzPPP: | ||
11 | * Copyright (C) 1997 Jay Painter | ||
12 | * | ||
13 | * This library is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU Library General Public | ||
15 | * License as published by the Free Software Foundation; either | ||
16 | * version 2 of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This library is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
21 | * Library General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU Library General Public | ||
24 | * License along with this program; if not, write to the Free | ||
25 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
26 | */ | ||
27 | |||
28 | #ifndef _SCRIPTEDIT_H_ | ||
29 | #define _SCRIPTEDIT_H_ | ||
30 | |||
31 | #include <qwidget.h> | ||
32 | |||
33 | class QComboBox; | ||
34 | class QLineEdit; | ||
35 | |||
36 | class ScriptEdit : public QWidget { | ||
37 | Q_OBJECT | ||
38 | public: | ||
39 | ScriptEdit( QWidget *parent=0, const char *name=0 ); | ||
40 | ~ScriptEdit() {} | ||
41 | |||
42 | QString text(); | ||
43 | void setText(const QString &); | ||
44 | int type(); | ||
45 | |||
46 | virtual void setEnabled(bool); | ||
47 | |||
48 | signals: | ||
49 | void returnPressed(); | ||
50 | |||
51 | private slots: | ||
52 | void setType(int); | ||
53 | void seReturnPressed(); | ||
54 | |||
55 | private: | ||
56 | QComboBox *st; | ||
57 | QLineEdit *se; | ||
58 | |||
59 | public: | ||
60 | enum setypes { Expect = 0, | ||
61 | Send = 1, | ||
62 | Pause = 2, | ||
63 | Hangup = 3, | ||
64 | Answer = 4, | ||
65 | Timeout = 5, | ||
66 | Password = 6, | ||
67 | ID = 7, | ||
68 | Prompt = 8, | ||
69 | PWPrompt = 9, | ||
70 | LoopStart = 10, | ||
71 | LoopEnd = 11, | ||
72 | Scan = 12, | ||
73 | Save = 13, | ||
74 | SendNoEcho = 14 | ||
75 | }; | ||
76 | }; | ||
77 | |||
78 | #endif | ||
79 | |||