2 * kPPP: A pppd front end for the KDE project
7 * Copyright (C) 2004 Simone Gotti
8 * <simone.gotti@email.it>
11 * Copyright (C) 1997 Jay Painter
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <QVBoxLayout>
31 #include <QHBoxLayout>
34 #include <q3tabdialog.h>
36 #include <qmessagebox.h>
37 #include <QApplication>
38 #include <kmessagebox.h>
41 #include <kwindowsystem.h>
42 #include <kpagedialog.h>
43 #include <kiconloader.h>
48 #include "accounting.h"
49 #include "providerdb.h"
52 void parseargs(char* buf
, char** args
);
54 ModemsWidget::ModemsWidget( QWidget
*parent
, const char *name
)
60 QVBoxLayout
*l1
= new QVBoxLayout(parent
);
65 QHBoxLayout
*l11
= new QHBoxLayout
;
68 modemlist_l
= new Q3ListBox(parent
);
69 modemlist_l
->setMinimumSize(160, 128);
70 connect(modemlist_l
, SIGNAL(highlighted(int)),
71 this, SLOT(slotListBoxSelect(int)));
72 connect(modemlist_l
, SIGNAL(selected(int)),
73 this, SLOT(editmodem()));
74 l11
->addWidget(modemlist_l
, 10);
76 QVBoxLayout
*l111
= new QVBoxLayout
;
77 l11
->addLayout(l111
, 1);
78 edit_b
= new QPushButton(i18n("&Edit..."), parent
);
79 connect(edit_b
, SIGNAL(clicked()), SLOT(editmodem()));
80 edit_b
->setWhatsThis( i18n("Allows you to modify the selected account"));
82 min
= edit_b
->sizeHint().width();
84 edit_b
->setMinimumWidth(min
);
86 l111
->addWidget(edit_b
);
88 new_b
= new QPushButton(i18n("&New..."), parent
);
89 connect(new_b
, SIGNAL(clicked()), SLOT(newmodem()));
90 l111
->addWidget(new_b
);
91 new_b
->setWhatsThis( i18n("Create a new dialup connection\n"
94 copy_b
= new QPushButton(i18n("Co&py"), parent
);
95 connect(copy_b
, SIGNAL(clicked()), SLOT(copymodem()));
96 l111
->addWidget(copy_b
);
98 i18n("Makes a copy of the selected account. All\n"
99 "settings of the selected account are copied\n"
100 "to a new account that you can modify to fit your\n"
103 delete_b
= new QPushButton(i18n("De&lete"), parent
);
104 connect(delete_b
, SIGNAL(clicked()), SLOT(deletemodem()));
105 l111
->addWidget(delete_b
);
106 delete_b
->setWhatsThis(
107 i18n("<p>Deletes the selected account\n\n"
108 "<font color=\"red\"><b>Use with care!</b></font>"));
110 //load up account list from gppdata to the list box
111 // but keep the current one selected in gpppdata
112 if(gpppdata
.modemCount() > 0) {
113 const QString currentmodem
= gpppdata
.modname();
114 for(int i
=0; i
<= gpppdata
.modemCount()-1; i
++) {
115 gpppdata
.setModemByIndex(i
);
116 modemlist_l
->insertItem(gpppdata
.modname());
118 gpppdata
.setModem(currentmodem
);
121 slotListBoxSelect(modemlist_l
->currentItem());
128 void ModemsWidget::slotListBoxSelect(int idx
) {
129 delete_b
->setEnabled((bool)(idx
!= -1));
130 edit_b
->setEnabled((bool)(idx
!= -1));
131 copy_b
->setEnabled((bool)(idx
!= -1));
133 QString modem
= gpppdata
.modname();
134 gpppdata
.setModemByIndex(modemlist_l
->currentItem());
135 gpppdata
.setModem(modem
);
139 void ModemsWidget::editmodem() {
140 gpppdata
.setModem(modemlist_l
->text(modemlist_l
->currentItem()));
142 int result
= doTab();
144 if(result
== QDialog::Accepted
) {
145 modemlist_l
->changeItem(gpppdata
.modname(),modemlist_l
->currentItem());
152 void ModemsWidget::newmodem() {
153 if(modemlist_l
->count() == MAX_MODEMS
) {
154 KMessageBox::sorry(this, i18n("Maximum number of modems reached."));
160 if (gpppdata
.newmodem() == -1)
165 if(result
== QDialog::Accepted
) {
166 modemlist_l
->insertItem(gpppdata
.modname());
167 modemlist_l
->setSelected(modemlist_l
->findItem(gpppdata
.modname()),
172 gpppdata
.deleteModem();
176 void ModemsWidget::copymodem() {
177 if(modemlist_l
->count() == MAX_MODEMS
) {
178 KMessageBox::sorry(this, i18n("Maximum number of modems reached."));
182 if(modemlist_l
->currentItem()<0) {
183 KMessageBox::sorry(this, i18n("No modem selected."));
187 gpppdata
.copymodem(modemlist_l
->currentItem());
189 modemlist_l
->insertItem(gpppdata
.modname());
195 void ModemsWidget::deletemodem() {
197 QString s
= i18n("Are you sure you want to delete\nthe modem \"%1\"?",
198 modemlist_l
->text(modemlist_l
->currentItem()));
200 if(KMessageBox::warningContinueCancel(this, s
, i18n("Confirm"), KStandardGuiItem::del()) != KMessageBox::Continue
)
203 if(gpppdata
.deleteModem(modemlist_l
->text(modemlist_l
->currentItem())))
204 modemlist_l
->removeItem(modemlist_l
->currentItem());
209 slotListBoxSelect(modemlist_l
->currentItem());
214 int ModemsWidget::doTab(){
215 tabWindow
= new KPageDialog( this );
216 tabWindow
->setModal( true );
217 tabWindow
->setButtons( KDialog::Ok
|KDialog::Cancel
);
218 tabWindow
->setDefaultButton( KDialog::Ok
);
219 tabWindow
->setFaceType( KPageDialog::Tabbed
);
220 KWindowSystem::setIcons(tabWindow
->winId(), qApp
->windowIcon().pixmap(IconSize(KIconLoader::Desktop
),IconSize(KIconLoader::Desktop
)), qApp
->windowIcon().pixmap(IconSize(KIconLoader::Small
),IconSize(KIconLoader::Small
)));
223 if(gpppdata
.modname().isEmpty()) {
224 tabWindow
->setCaption(i18n("New Modem"));
227 QString tit
= i18n("Edit Modem: ");
228 tit
+= gpppdata
.modname();
229 tabWindow
->setCaption(tit
);
232 QFrame
*frame
= new QFrame();
233 KPageWidgetItem
*pageItem
= new KPageWidgetItem( frame
, i18n("&Device") );
234 pageItem
->setHeader( i18n("Serial Device") );
235 tabWindow
->addPage( pageItem
);
236 modem1
= new ModemWidget(frame
, isnewmodem
);
238 frame
= new QFrame();
239 pageItem
= new KPageWidgetItem( frame
, i18n("&Modem") );
240 pageItem
->setHeader( i18n("Modem Settings") );
241 tabWindow
->addPage( pageItem
);
243 modem2
= new ModemWidget2(frame
);
244 connect ( modem1
->connectName(), SIGNAL(textChanged ( const QString
& )), this, SLOT(modemNameChanged(const QString
& )));
246 modemNameChanged(modem1
->connectName()->text());
251 result
= tabWindow
->exec();
254 if(result
== QDialog::Accepted
) {
258 KMessageBox::error(this, i18n( "You must enter a unique\n"
269 void ModemsWidget::modemNameChanged(const QString
& text
)
271 tabWindow
->enableButtonOk( !text
.isEmpty() );
274 QString
ModemsWidget::prettyPrintVolume(unsigned int n
) {
276 const QString quant
[] = {i18n("Byte"), i18n("KiB"),
277 i18n("MiB"), i18n("GiB"), QString()};
280 while(n
>= 1024 && !quant
[idx
].isNull()) {
289 QString s
= KGlobal::locale()->formatNumber( n1
, idx
==0 ? 0 : 1 );
290 s
+= ' ' + quant
[idx
];
294 #include "modems.moc"