Forwardport:
[kdenetwork.git] / kppp / pppdargs.cpp
blobf92de3bf1c89436086a6c56d0b603d49041fdf20
1 /*
2 * kPPP: A pppd front end for the KDE project
4 * $Id$
6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
9 * based on EzPPP:
10 * Copyright (C) 1997 Jay Painter
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.
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.
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.
27 #include <kguiitem.h>
28 #include <qlayout.h>
29 //Added by qt3to4:
30 #include <QVBoxLayout>
31 #include <QHBoxLayout>
32 #include <kwin.h>
33 #include <kapplication.h>
34 #include "pppdargs.h"
35 #include "pppdata.h"
36 #include <klocale.h>
37 #include <qlineedit.h>
38 #include <qpushbutton.h>
39 #include <q3listbox.h>
40 #include <qlabel.h>
41 #include <KStandardGuiItem>
42 #include <kpushbutton.h>
43 #include <KStandardGuiItem>
44 #include <kiconloader.h>
46 PPPdArguments::PPPdArguments(QWidget *parent, const char *name)
47 : KDialog(parent)
49 setObjectName(name);
51 setWindowTitle(i18n("Customize pppd Arguments"));
52 KWin::setIcons(winId(), qApp->windowIcon().pixmap(IconSize(K3Icon::Desktop),IconSize(K3Icon::Desktop)), qApp->windowIcon().pixmap(IconSize(K3Icon::Small),IconSize(K3Icon::Small)));
53 QVBoxLayout *l = new QVBoxLayout(this);
54 l->setSpacing(10);
55 l->setMargin(10);
56 QHBoxLayout *tl = new QHBoxLayout();
57 tl->setSpacing( 10 );
58 l->addLayout(tl);
59 QVBoxLayout *l1 = new QVBoxLayout();
60 QVBoxLayout *l2 = new QVBoxLayout();
61 tl->addLayout(l1, 1);
62 tl->addLayout(l2, 0);
64 QHBoxLayout *l11 = new QHBoxLayout();
65 l11->setSpacing( 10 );
66 l1->addLayout(l11);
68 argument_label = new QLabel(i18n("Arg&ument:"), this);
69 l11->addWidget(argument_label);
71 argument = new QLineEdit(this);
72 argument_label->setBuddy(argument);
73 connect(argument, SIGNAL(returnPressed()),
74 SLOT(addbutton()));
75 l11->addWidget(argument);
76 connect(argument, SIGNAL(textChanged(const QString &)),
77 this, SLOT(textChanged(const QString &)));
79 arguments = new Q3ListBox(this);
80 arguments->setMinimumSize(1, fontMetrics().lineSpacing()*10);
81 connect(arguments, SIGNAL(highlighted(int)),
82 this, SLOT(itemSelected(int)));
83 l1->addWidget(arguments, 1);
85 add = new QPushButton(i18n("&Add"), this);
86 connect(add, SIGNAL(clicked()), SLOT(addbutton()));
87 l2->addWidget(add);
88 l2->addStretch(1);
90 remove = new QPushButton(i18n("&Remove"), this);
91 connect(remove, SIGNAL(clicked()), SLOT(removebutton()));
92 l2->addWidget(remove);
94 defaults = new KPushButton(KStandardGuiItem::defaults(), this);
95 connect(defaults, SIGNAL(clicked()), SLOT(defaultsbutton()));
96 l2->addWidget(defaults);
98 l->addSpacing(5);
100 setButtons(Ok | Cancel);
101 connect(this, SIGNAL(okClicked()), SLOT(closebutton()));
103 setFixedSize(sizeHint());
105 //load info from gpppdata
106 init();
108 add->setEnabled(false);
109 remove->setEnabled(false);
110 argument->setFocus();
114 void PPPdArguments::addbutton() {
115 if(!argument->text().isEmpty() && arguments->count() < MAX_PPPD_ARGUMENTS) {
116 arguments->insertItem(argument->text());
117 argument->setText("");
122 void PPPdArguments::removebutton() {
123 if(arguments->currentItem() >= 0)
124 arguments->removeItem(arguments->currentItem());
128 void PPPdArguments::defaultsbutton() {
129 // all of this is a hack
130 // save current list
131 QStringList arglist(gpppdata.pppdArgument());
133 // get defaults
134 gpppdata.setpppdArgumentDefaults();
135 init();
137 // restore old list
138 gpppdata.setpppdArgument(arglist);
142 void PPPdArguments::closebutton() {
143 QStringList arglist;
144 for(uint i=0; i < arguments->count(); i++)
145 arglist.append(arguments->text(i));
146 gpppdata.setpppdArgument(arglist);
148 done(0);
152 void PPPdArguments::init() {
153 while(arguments->count())
154 arguments->removeItem(0);
156 QStringList &arglist = gpppdata.pppdArgument();
157 for ( QStringList::Iterator it = arglist.begin();
158 it != arglist.end();
159 ++it )
160 arguments->insertItem(*it);
164 void PPPdArguments::textChanged(const QString &s) {
165 add->setEnabled(s.length() > 0);
169 void PPPdArguments::itemSelected(int idx) {
170 remove->setEnabled(idx != -1);
173 #include "pppdargs.moc"