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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
26 | */ |
27 | #include <kguiitem.h> |
28 | #include <qlayout.h> |
29 | //Added by qt3to4: |
30 | #include <QVBoxLayout> |
31 | #include <QHBoxLayout> |
32 | #include <QApplication> |
33 | #include <kwindowsystem.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 <kiconloader.h> |
44 | |
45 | PPPdArguments::PPPdArguments(QWidget *parent, const char *name) |
46 | : KDialog(parent) |
47 | { |
48 | setObjectName(name); |
49 | |
50 | setWindowTitle(i18n("Customize pppd Arguments" )); |
51 | QWidget *widget = new QWidget(this); |
52 | setMainWidget(widget); |
53 | KWindowSystem::setIcons(winId(), qApp->windowIcon().pixmap(IconSize(KIconLoader::Desktop),IconSize(KIconLoader::Desktop)), qApp->windowIcon().pixmap(IconSize(KIconLoader::Small),IconSize(KIconLoader::Small))); |
54 | QVBoxLayout *l = new QVBoxLayout(widget); |
55 | l->setSpacing(10); |
56 | l->setMargin(10); |
57 | QHBoxLayout *tl = new QHBoxLayout(); |
58 | tl->setSpacing( 10 ); |
59 | l->addLayout(tl); |
60 | QVBoxLayout *l1 = new QVBoxLayout(); |
61 | QVBoxLayout *l2 = new QVBoxLayout(); |
62 | tl->addLayout(l1, 1); |
63 | tl->addLayout(l2, 0); |
64 | |
65 | QHBoxLayout *l11 = new QHBoxLayout(); |
66 | l11->setSpacing( 10 ); |
67 | l1->addLayout(l11); |
68 | |
69 | argument_label = new QLabel(i18n("Arg&ument:" ), widget); |
70 | l11->addWidget(argument_label); |
71 | |
72 | argument = new QLineEdit(widget); |
73 | argument_label->setBuddy(argument); |
74 | connect(argument, SIGNAL(returnPressed()), |
75 | SLOT(addbutton())); |
76 | l11->addWidget(argument); |
77 | connect(argument, SIGNAL(textChanged(QString)), |
78 | this, SLOT(textChanged(QString))); |
79 | |
80 | arguments = new Q3ListBox(widget); |
81 | arguments->setMinimumSize(1, fontMetrics().lineSpacing()*10); |
82 | connect(arguments, SIGNAL(highlighted(int)), |
83 | this, SLOT(itemSelected(int))); |
84 | l1->addWidget(arguments, 1); |
85 | |
86 | add = new QPushButton(i18n("&Add" ), widget); |
87 | connect(add, SIGNAL(clicked()), SLOT(addbutton())); |
88 | l2->addWidget(add); |
89 | l2->addStretch(1); |
90 | |
91 | remove = new QPushButton(i18n("&Remove" ), widget); |
92 | connect(remove, SIGNAL(clicked()), SLOT(removebutton())); |
93 | l2->addWidget(remove); |
94 | |
95 | defaults = new KPushButton(KStandardGuiItem::defaults(), widget); |
96 | connect(defaults, SIGNAL(clicked()), SLOT(defaultsbutton())); |
97 | l2->addWidget(defaults); |
98 | |
99 | l->addSpacing(5); |
100 | |
101 | setButtons(Ok | Cancel); |
102 | connect(this, SIGNAL(okClicked()), SLOT(closebutton())); |
103 | |
104 | setFixedSize(sizeHint()); |
105 | |
106 | //load info from gpppdata |
107 | init(); |
108 | |
109 | add->setEnabled(false); |
110 | remove->setEnabled(false); |
111 | argument->setFocus(); |
112 | } |
113 | |
114 | |
115 | void PPPdArguments::addbutton() { |
116 | if(!argument->text().isEmpty() && arguments->count() < MAX_PPPD_ARGUMENTS) { |
117 | arguments->insertItem(argument->text()); |
118 | argument->setText("" ); |
119 | } |
120 | } |
121 | |
122 | |
123 | void PPPdArguments::removebutton() { |
124 | if(arguments->currentItem() >= 0) |
125 | arguments->removeItem(arguments->currentItem()); |
126 | } |
127 | |
128 | |
129 | void PPPdArguments::defaultsbutton() { |
130 | // all of this is a hack |
131 | // save current list |
132 | QStringList arglist(gpppdata.pppdArgument()); |
133 | |
134 | // get defaults |
135 | gpppdata.setpppdArgumentDefaults(); |
136 | init(); |
137 | |
138 | // restore old list |
139 | gpppdata.setpppdArgument(arglist); |
140 | } |
141 | |
142 | |
143 | void PPPdArguments::closebutton() { |
144 | QStringList arglist; |
145 | for(uint i=0; i < arguments->count(); i++) |
146 | arglist.append(arguments->text(i)); |
147 | gpppdata.setpppdArgument(arglist); |
148 | |
149 | done(0); |
150 | } |
151 | |
152 | |
153 | void PPPdArguments::init() { |
154 | while(arguments->count()) |
155 | arguments->removeItem(0); |
156 | |
157 | QStringList &arglist = gpppdata.pppdArgument(); |
158 | for ( QStringList::Iterator it = arglist.begin(); |
159 | it != arglist.end(); |
160 | ++it ) |
161 | arguments->insertItem(*it); |
162 | } |
163 | |
164 | |
165 | void PPPdArguments::textChanged(const QString &s) { |
166 | add->setEnabled(s.length() > 0); |
167 | } |
168 | |
169 | |
170 | void PPPdArguments::itemSelected(int idx) { |
171 | remove->setEnabled(idx != -1); |
172 | } |
173 | |
174 | #include "pppdargs.moc" |
175 | |