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 /noncore/settings/networksettings/ppp/kpppwidget.cpp | |
parent | 34b9974063032242e5de65fa56d4c2cb5e1ce565 (diff) | |
download | opie-9b6b21112f38181f49b07e973bfe00c0d83a6900.zip opie-9b6b21112f38181f49b07e973bfe00c0d83a6900.tar.gz opie-9b6b21112f38181f49b07e973bfe00c0d83a6900.tar.bz2 |
configure dialog basicly working
more kppp stuff... ;)
Diffstat (limited to 'noncore/settings/networksettings/ppp/kpppwidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/kpppwidget.cpp | 905 |
1 files changed, 905 insertions, 0 deletions
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 | |||