1 //---------------------------------------------------------------------------
3 // kPPP: A pppd front end for the KDE project
5 //---------------------------------------------------------------------------
7 // (c) 1997-1998 Bernd Johannes Wuebben <wuebben@kde.org>
8 // (c) 1997-1999 Mario Weilguni <mweilguni@kde.org>
9 // (c) 1998-1999 Harri Porten <porten@kde.org>
11 // derived from Jay Painters "ezppp"
13 //---------------------------------------------------------------------------
17 //---------------------------------------------------------------------------
19 // This program is free software; you can redistribute it and-or
20 // modify it under the terms of the GNU Library General Public
21 // License as published by the Free Software Foundation; either
22 // version 2 of the License, or (at your option) any later version.
24 // This program is distributed in the hope that it will be useful,
25 // but WITHOUT ANY WARRANTY; without even the implied warranty of
26 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 // Library General Public License for more details.
29 // You should have received a copy of the GNU Library General Public
30 // License along with this program; if not, write to the Free
31 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
33 //---------------------------------------------------------------------------
37 #include <QVBoxLayout>
38 #include <QHBoxLayout>
42 #include <qpushbutton.h>
43 #include <q3listbox.h>
45 #include <KStandardGuiItem>
49 ModemSelector::ModemSelector(QWidget
*parent
) : KDialog(parent
) {
50 // set up widgets and such
51 setWindowTitle(i18n("Select Modem Type"));
52 QVBoxLayout
*tl
= new QVBoxLayout(this);
55 QLabel
*l1
= new QLabel(i18n("To set up your modem, first choose its vendor in the "
56 "list to the left, and then select the model from the "
57 "right list. If you don't know which modem you have, "
58 "you can try out one of the \"Generic\" modems."),
60 l1
->setAlignment(Qt::AlignLeft
);
61 l1
->setWordWrap( true );
62 l1
->setFixedWidth(400);
63 l1
->setMinimumHeight(50);
68 QHBoxLayout
*tl1
= new QHBoxLayout();
69 tl1
->setSpacing( 10 );
70 tl
->addLayout(tl1
, 1);
71 vendor
= new Q3ListBox(this);
72 model
= new Q3ListBox(this);
73 vendor
->setMinimumSize(200, 130);
74 model
->setMinimumSize(200, 130);
75 tl1
->addWidget(vendor
, 2);
76 tl1
->addWidget(model
, 3);
78 setButtons(Ok
|Cancel
);
79 enableButton(Ok
,false);
80 setFixedSize(sizeHint());
82 // set up modem database
83 db
= new ModemDatabase();
85 // set up signal/slots
86 connect(vendor
, SIGNAL(highlighted(int)),
87 this, SLOT(vendorSelected(int)));
88 connect(model
, SIGNAL(highlighted(int)),
89 this, SLOT(modelSelected(int)));
90 connect(model
, SIGNAL(selected(int)),
91 this, SLOT(selected(int)));
93 // fill vendor list with life
94 vendor
->insertStringList(*db
->vendors());
96 vendor
->setCurrentItem(0);
100 ModemSelector::~ModemSelector() {
105 void ModemSelector::vendorSelected(int idx
) {
106 enableButton(Ok
,false);
108 QString name
= vendor
->text(idx
);
109 QStringList
*models
= db
->models(name
);
111 model
->insertStringList(*models
);
113 // FIXME: work around Qt bug
114 if(models
->count() == 0)
120 void ModemSelector::modelSelected(int) {
121 enableButton(Ok
,true);
124 void ModemSelector::selected(int) {
129 ModemDatabase::ModemDatabase() {
134 ModemDatabase::~ModemDatabase() {
140 const QStringList
*ModemDatabase::vendors() {
145 QStringList
*ModemDatabase::models(QString vendor
) {
146 QStringList
*sl
= new QStringList
;
147 QString s
= i18n("<Generic>");
149 vendor
= i18n("<Generic>");
151 for(uint i
= 0; i
< modems
.count(); i
++) {
152 CharDict
*dict
= modems
.at(i
);
153 if(dict
->find("Vendor") != 0) {
154 if(vendor
== *(*dict
)["Vendor"] && (*(*dict
)["Name"]).at(0) != '!')
155 sl
->append(*(*dict
)["Name"]);
164 void ModemDatabase::loadModem(const QString
&key
, CharDict
&dict
) {
165 // KEntryIterator *it = modemDB->entryIterator(key);
166 // KEntryDictEntry *e;
167 QMap
<QString
, QString
> map
;
168 QMap
<QString
, QString
>::Iterator it
;
169 // KEntryMapConstIterator e;
170 map
= modemDB
->entryMap(key
);
173 // remove parent attribute
174 dict
.setAutoDelete(true);
175 dict
.remove("Parent");
177 // e = it->current();
178 while(!it
.key().isNull()) {
179 if(dict
.find(it
.key()) == 0) {
180 dict
.insert(it
.key(), new QString(it
.value()));
185 // check name attribute
186 if(dict
["Name"] == 0 || key
[0]=='!') {
187 dict
.replace("Name", new QString(key
));
190 // check parent attribute
191 if(dict
["Parent"] != 0)
192 loadModem(*dict
["Parent"], dict
);
194 // inherit common at last
196 loadModem("Common", dict
);
201 void ModemDatabase::load() {
202 modemDB
= new KConfig("DB/modemDB.rc");
203 lvendors
= new QStringList
;
204 modems
.setAutoDelete(true);
206 QStringList list
= modemDB
->groupList();
207 QStringList::Iterator it
= list
.begin();
208 while(it
!= list
.end()) {
209 KConfigGroup
cg ( modemDB
, *it
);
210 CharDict
*c
= new CharDict
;
211 c
->setAutoDelete(true);
214 // if(strcmp(it->latin1(), "Common") == 0) {
215 if(*it
== "Common") {
216 QString s
= i18n("Hayes(tm) compatible modem");
217 c
->replace("Name", new QString (s
));
219 s
= i18n("<Generic>");
220 c
->replace("Vendor", new QString(s
));
224 if(cg
.hasKey("Vendor")) {
225 QString vendor
= cg
.readEntry("Vendor");
226 if(lvendors
->indexOf(vendor
) == -1)
227 lvendors
->append(vendor
);
234 lvendors
->insert(0, i18n("<Generic>"));
238 void ModemDatabase::save(KConfig
*) {
241 #include "modemdb.moc"