Use a nicer way to check if rdesktop is installed.
[kdenetwork.git] / kppp / modemdb.cpp
blob3af94ff7c952bc57b2ccc664c967da704b2ea60e
1 //---------------------------------------------------------------------------
2 //
3 // kPPP: A pppd front end for the KDE project
4 //
5 //---------------------------------------------------------------------------
6 //
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 //---------------------------------------------------------------------------
15 // $Id$
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 //---------------------------------------------------------------------------
35 #include <qlabel.h>
36 //Added by qt3to4:
37 #include <QVBoxLayout>
38 #include <QHBoxLayout>
39 #include <qlayout.h>
40 #include "modemdb.h"
41 #include <klocale.h>
42 #include <qpushbutton.h>
43 #include <q3listbox.h>
44 #include <kconfig.h>
45 #include <KStandardGuiItem>
46 #include <kguiitem.h>
47 #include <kdialog.h>
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);
53 tl->setSpacing(10);
54 tl->setMargin(10);
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."),
59 this);
60 l1->setAlignment(Qt::AlignLeft);
61 l1->setWordWrap( true );
62 l1->setFixedWidth(400);
63 l1->setMinimumHeight(50);
64 tl->addWidget(l1, 0);
66 tl->addSpacing(10);
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() {
101 delete db;
105 void ModemSelector::vendorSelected(int idx) {
106 enableButton(Ok,false);
108 QString name = vendor->text(idx);
109 QStringList *models = db->models(name);
110 model->clear();
111 model->insertStringList(*models);
113 // FIXME: work around Qt bug
114 if(models->count() == 0)
115 model->update();
116 delete models;
120 void ModemSelector::modelSelected(int) {
121 enableButton(Ok,true);
124 void ModemSelector::selected(int) {
125 accept();
129 ModemDatabase::ModemDatabase() {
130 load();
134 ModemDatabase::~ModemDatabase() {
135 delete lvendors;
136 delete modemDB;
140 const QStringList *ModemDatabase::vendors() {
141 return lvendors;
145 QStringList *ModemDatabase::models(QString vendor) {
146 QStringList *sl = new QStringList;
147 QString s = i18n("<Generic>");
148 if(vendor == s)
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"]);
158 sl->sort();
160 return sl;
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);
171 it = map.begin();
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()));
182 it++;
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);
193 else
194 // inherit common at last
195 if (key != "Common")
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);
212 loadModem(*it, *c);
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));
222 modems.append(c);
224 if(cg.hasKey("Vendor")) {
225 QString vendor = cg.readEntry("Vendor");
226 if(lvendors->indexOf(vendor) == -1)
227 lvendors->append(vendor);
229 ++it;
232 lvendors->sort();
234 lvendors->insert(0, i18n("<Generic>"));
238 void ModemDatabase::save(KConfig *) {
241 #include "modemdb.moc"