Diffstat (limited to 'noncore/settings/networksettings/ppp/devices.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/devices.cpp | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/noncore/settings/networksettings/ppp/devices.cpp b/noncore/settings/networksettings/ppp/devices.cpp new file mode 100644 index 0000000..e94904b --- a/dev/null +++ b/noncore/settings/networksettings/ppp/devices.cpp | |||
@@ -0,0 +1,212 @@ | |||
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 <qvgroupbox.h> | ||
39 | |||
40 | #include "interfaceppp.h" | ||
41 | #include "devices.h" | ||
42 | #include "authwidget.h" | ||
43 | #include "pppdata.h" | ||
44 | #include "edit.h" | ||
45 | #include "general.h" | ||
46 | |||
47 | void parseargs(char* buf, char** args); | ||
48 | |||
49 | DevicesWidget::DevicesWidget( InterfacePPP* ip, QWidget *parent, const char *name, WFlags f ) | ||
50 | : ChooserWidget(ip->data(), parent, name, f) | ||
51 | { | ||
52 | _ifaceppp = ip; | ||
53 | QWhatsThis::add(edit_b, tr("Allows you to modify the selected device")); | ||
54 | QWhatsThis::add(new_b, tr("Create a new device") ); | ||
55 | |||
56 | QWhatsThis::add(copy_b, | ||
57 | tr("Makes a copy of the selected device. All\n" | ||
58 | "settings of the selected device are copied\n" | ||
59 | "to a new device, that you can modify to fit your\n" | ||
60 | "needs")); | ||
61 | QWhatsThis::add(delete_b, | ||
62 | tr("<p>Deletes the selected device\n\n" | ||
63 | "<font color=\"red\"><b>Use with care!</b></font>")); | ||
64 | |||
65 | copy_b->setEnabled( false ); //FIXME | ||
66 | // delete_b->setEnabled( false ); //FIXME | ||
67 | |||
68 | QStringList tmp = _pppdata->getDevicesNamesList(); | ||
69 | qDebug("DevicesWidget::DevicesWidget got devices %s",tmp.join("--").latin1()); | ||
70 | listListbox->insertStringList(tmp); | ||
71 | |||
72 | for (uint i = 0; i < listListbox->count(); i++){ | ||
73 | qDebug("listListbox->text(i) %s == _pppdata->devname() %s",listListbox->text(i).latin1(), _pppdata->devname().latin1()); | ||
74 | if ( listListbox->text(i) == _pppdata->devname() ) | ||
75 | listListbox->setCurrentItem( i ); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | |||
80 | |||
81 | void DevicesWidget::slotListBoxSelect(int idx) { | ||
82 | bool ok = _pppdata->setDevice( listListbox->text(idx) ); | ||
83 | delete_b->setEnabled((bool)(idx != -1)); | ||
84 | edit_b->setEnabled((bool)(idx != -1)); | ||
85 | //FIXME copy_b->setEnabled((bool)(idx != -1)); | ||
86 | } | ||
87 | |||
88 | void DevicesWidget::edit() { | ||
89 | _pppdata->setDevice(listListbox->text(listListbox->currentItem())); | ||
90 | |||
91 | int result = doTab(); | ||
92 | |||
93 | if(result == QDialog::Accepted) { | ||
94 | listListbox->changeItem(_pppdata->devname(),listListbox->currentItem()); | ||
95 | _pppdata->save(); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | |||
100 | void DevicesWidget::create() { | ||
101 | |||
102 | // if(listListbox->count() == MAX_ACCOUNTS) { | ||
103 | // QMessageBox::information(this, "sorry", | ||
104 | // tr("Maximum number of accounts reached.")); | ||
105 | // return; | ||
106 | // } | ||
107 | |||
108 | int result; | ||
109 | if (_pppdata->newdevice() == -1){ | ||
110 | return; | ||
111 | } | ||
112 | result = doTab(); | ||
113 | |||
114 | if(result == QDialog::Accepted) { | ||
115 | listListbox->insertItem(_pppdata->devname()); | ||
116 | listListbox->setSelected(listListbox->findItem(_pppdata->devname()),true ); | ||
117 | |||
118 | _pppdata->save(); | ||
119 | } else | ||
120 | _pppdata->deleteDevice(); | ||
121 | } | ||
122 | |||
123 | |||
124 | void DevicesWidget::copy() { | ||
125 | // if(listListbox->count() == MAX_ACCOUNTS) { | ||
126 | // QMessageBox::information(this, "sorry", tr("Maximum number of accounts reached.")); | ||
127 | // return; | ||
128 | // } | ||
129 | |||
130 | if(listListbox->currentItem()<0) { | ||
131 | QMessageBox::information(this, "sorry", tr("No devices selected.")); | ||
132 | return; | ||
133 | } | ||
134 | |||
135 | _pppdata->copydevice(listListbox->currentText()); | ||
136 | |||
137 | listListbox->insertItem(_pppdata->devname()); | ||
138 | _pppdata->save(); | ||
139 | } | ||
140 | |||
141 | |||
142 | void DevicesWidget::remove() { | ||
143 | |||
144 | QString s = tr("Are you sure you want to delete\nthe device \"%1\"?") | ||
145 | .arg(listListbox->text(listListbox->currentItem())); | ||
146 | |||
147 | if(QMessageBox::warning(this,tr("Confirm"),s, | ||
148 | QMessageBox::Yes,QMessageBox::No | ||
149 | ) != QMessageBox::Yes) | ||
150 | return; | ||
151 | |||
152 | if(_pppdata->deleteDevice(listListbox->text(listListbox->currentItem()))) | ||
153 | listListbox->removeItem(listListbox->currentItem()); | ||
154 | |||
155 | |||
156 | // _pppdata->save(); | ||
157 | |||
158 | |||
159 | slotListBoxSelect(listListbox->currentItem()); | ||
160 | |||
161 | } | ||
162 | |||
163 | |||
164 | int DevicesWidget::doTab(){ | ||
165 | QDialog *dlg = new QDialog( 0, "newDevice", true, Qt::WStyle_ContextHelp ); | ||
166 | QVBoxLayout *layout = new QVBoxLayout( dlg ); | ||
167 | layout->setSpacing( 0 ); | ||
168 | layout->setMargin( 1 ); | ||
169 | |||
170 | QTabWidget *tabWindow = new QTabWidget( dlg, "tabWindow" ); | ||
171 | layout->addWidget( tabWindow ); | ||
172 | |||
173 | bool isnew; | ||
174 | |||
175 | if(_pppdata->devname().isEmpty()) { | ||
176 | dlg->setCaption(tr("New Device")); | ||
177 | isnew = true; | ||
178 | } else { | ||
179 | QString tit = tr("Edit Device: "); | ||
180 | tit += _pppdata->devname(); | ||
181 | dlg->setCaption(tit); | ||
182 | isnew = false; | ||
183 | } | ||
184 | |||
185 | modem1 = new ModemWidget( _pppdata, tabWindow, "modem1" ); | ||
186 | tabWindow->addTab( modem1, tr("&Device") ); | ||
187 | modem2 = new ModemWidget2( _pppdata, _ifaceppp, tabWindow, "modem2" ); | ||
188 | tabWindow->addTab( modem2, tr("&Modem") ); | ||
189 | |||
190 | int result = 0; | ||
191 | bool ok = false; | ||
192 | |||
193 | while (!ok){ | ||
194 | dlg->showMaximized(); | ||
195 | result = dlg->exec(); | ||
196 | ok = true; | ||
197 | |||
198 | if(result == QDialog::Accepted) { | ||
199 | if (!modem1->save()){ | ||
200 | QMessageBox::critical(this, "error", tr( "You must enter a unique device name")); | ||
201 | ok = false; | ||
202 | }else{ | ||
203 | modem2->save(); | ||
204 | } | ||
205 | } | ||
206 | } | ||
207 | |||
208 | delete dlg; | ||
209 | |||
210 | return result; | ||
211 | } | ||
212 | |||