4 * Copyright (c) 2001 George Staikos <staikos@kde.org>
5 * Copyright (c) 2001 Fernando Llobregat <fernando.llobregat@free.fr>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include <QPushButton>
28 #include <dcopclient.h>
30 #include <kaboutdata.h>
31 #include <kapplication.h>
33 #include <kcardfactory.h>
34 #include <kcardgsm_impl.h>
39 #include <k3listview.h>
41 #include <kmessagebox.h>
43 #include <kgenericfactory.h>
45 #include "smartcard.h"
47 typedef KGenericFactory
<KSmartcardConfig
> KSmartcardConfigFactory
;
48 K_EXPORT_COMPONENT_FACTORY(kcm_smartcard
, KSmartcardConfigFactory("kcmsmartcard"))
50 KSmartcardConfig::KSmartcardConfig(QWidget
*parent
, const QStringList
&)
51 : KCModule(KSmartcardConfig::componentData(), parent
)
52 , DCOPObject("kcmsmartcard")
54 QVBoxLayout
*layout
= new QVBoxLayout(this);
55 layout
->setSpacing(KDialog::spacingHint());
56 layout
->setMargin(KDialog::marginHint());
57 config
= new KConfig("ksmartcardrc", false, false);
59 DCOPClient
*dc
= KApplication::kApplication()->dcopClient();
62 dc
->remoteInterfaces("kded", "kardsvc", &_ok
);
65 new KAboutData(I18N_NOOP("kcmsmartcard"), 0, ki18n("KDE Smartcard Control Module"),
66 0, KLocalizedString(), KAboutData::License_GPL
,
67 ki18n("(c) 2001 George Staikos"));
69 about
->addAuthor(ki18n("George Staikos"), KLocalizedString(), "staikos@kde.org");
70 setAboutData( about
);
75 base
= new SmartcardBase(this);
78 _popUpKardChooser
= new KMenu(this,"KpopupKardChooser");
79 _popUpKardChooser
->insertItem(i18n("Change Module..."),
81 SLOT(slotLaunchChooser()));
84 connect(base
->launchManager
, SIGNAL(clicked()), SLOT( changed() ));
85 connect(base
->beepOnInsert
, SIGNAL(clicked()), SLOT( changed() ));
86 connect(base
->enableSupport
, SIGNAL(clicked()), SLOT( changed() ));
89 connect(base
->enablePolling
, SIGNAL(clicked()), SLOT( changed() ));
90 connect(base
->_readerHostsListView
,
91 SIGNAL(rightButtonPressed(QListViewItem
*,const QPoint
&,int)),
93 SLOT(slotShowPopup(QListViewItem
*,const QPoint
&,int)));
97 if (!connectDCOPSignal("",
99 "signalReaderListChanged(QStringList)",
100 "loadReadersTab(QStringList)",
103 kDebug()<<"Error connecting to DCOP server";
106 if (!connectDCOPSignal("",
108 "signalCardStateChanged(QString,bool,QString)",
109 "updateReadersState (QString,bool,QString) ",
112 kDebug()<<"Error connecting to DCOP server";
113 _cardDB
= new KCardDB();
116 layout
->add(new NoSmartcardBase(this));
123 KSmartcardConfig::~KSmartcardConfig()
129 void KSmartcardConfig::slotLaunchChooser(){
132 if ( KCardDB::launchSelector(base
->_readerHostsListView
->currentItem()->parent()->text(0))){
134 KMessageBox::sorry(this,i18n("Unable to launch KCardChooser"));
140 void KSmartcardConfig::slotShowPopup(QListViewItem
* item
,const QPoint
& _point
,int i
)
143 //The popup only appears in cards, not in the slots1
144 if (item
->isSelectable()) return;
145 _popUpKardChooser
->exec(_point
);
149 void KSmartcardConfig::loadSmartCardSupportTab(){
153 //Update the toggle buttons with the current configuration
156 base
->enableSupport
->setChecked(config
->readEntry("Enable Support",
158 base
->enablePolling
->setChecked(config
->readEntry("Enable Polling",
160 base
->beepOnInsert
->setChecked(config
->readEntry("Beep on Insert",
162 base
->launchManager
->setChecked(config
->readEntry("Launch Manager",
170 void KSmartcardConfig::updateReadersState (QString
&readerName
,
174 K3ListViewItem
* tID
=(K3ListViewItem
*) base
->_readerHostsListView
->findItem(readerName
, 0);
177 K3ListViewItem
* tIDChild
=(K3ListViewItem
*) tID
->firstChild();
178 if (tIDChild
==NULL
) return;
183 (void) new K3ListViewItem(tID
,i18n("No card inserted"));
186 getSupportingModule(tID
,atr
);
194 void KSmartcardConfig::loadReadersTab( QStringList
&lr
){
196 //Prepare data for dcop calls
197 QByteArray data
, retval
;
199 QDataStream
arg(&data
, QIODevice::WriteOnly
);
201 arg
.setVersion(QDataStream::Qt_3_1
);
202 DCOPCString modName
= "kardsvc";
206 K3ListViewItem
* temp
;
208 //If the smartcard support is disabled we unload the kardsvc KDED module
211 base
->_readerHostsListView
->clear();
213 if (!config
->readEntry("Enable Support", false)) {
219 K3ListViewItem
* temp
;
220 kapp
->dcopClient()->call("kded", "kded", "unloadModule(QCString)",
221 data
, rettype
, retval
);
223 (void) new K3ListViewItem(base
->_readerHostsListView
,
224 i18n("Smart card support disabled"));
234 (void) new K3ListViewItem(base
->_readerHostsListView
,
235 i18n("No readers found. Check 'pcscd' is running"));
239 for (QStringList::Iterator _slot
=lr
.begin();_slot
!=lr
.end();++_slot
){
241 temp
= new K3ListViewItem(base
->_readerHostsListView
,*_slot
);
245 QDataStream
argATR(&dataATR
,QIODevice::WriteOnly
);
247 argATR
.setVersion(QDataStream::Qt_3_1
);
250 kapp
->dcopClient()->call("kded", "kardsvc", "getCardATR(QString)",
251 dataATR
, rettype
, retval
);
255 QDataStream
retReaderATR(retval
);
256 retReaderATR
>>cardATR
;
258 if (cardATR
.isNull()){
260 (void) new K3ListViewItem(temp
,i18n("NO ATR or no card inserted"));
264 getSupportingModule(temp
,cardATR
);
274 void KSmartcardConfig::getSupportingModule( K3ListViewItem
* ant
,
275 QString
& cardATR
) const{
278 if (cardATR
.isNull()){
280 (void) new K3ListViewItem(ant
,i18n("NO ATR or no card inserted"));
285 QString modName
=_cardDB
->getModuleName(cardATR
);
286 if (!modName
.isNull()){
287 QStringList mng
= modName
.split( ",");
289 QString subType
=mng
[1];
290 QString subSubType
=mng
[2];
291 K3ListViewItem
* hil
=new K3ListViewItem(ant
,
292 i18n("Managed by: "),
296 hil
->setSelectable(false);
301 K3ListViewItem
* hil
=new K3ListViewItem(ant
,
302 i18n("No module managing this card"));
303 hil
->setSelectable(false);
308 void KSmartcardConfig::load()
312 //Prepare data for dcop calls
313 QByteArray data
, retval
;
315 QDataStream
arg(&data
, QIODevice::WriteOnly
);
317 arg
.setVersion(QDataStream::Qt_3_1
);
318 DCOPCString modName
= "kardsvc";
321 loadSmartCardSupportTab();
324 // We call kardsvc to retrieve the current readers
325 kapp
->dcopClient()->call("kded", "kardsvc", "getSlotList ()",
326 data
, rettype
, retval
);
329 QDataStream
retReader(retval
);
332 //And we update the panel
333 loadReadersTab(readers
);
340 void KSmartcardConfig::save()
343 config
->writeEntry("Enable Support", base
->enableSupport
->isChecked());
344 config
->writeEntry("Enable Polling", base
->enablePolling
->isChecked());
345 config
->writeEntry("Beep on Insert", base
->beepOnInsert
->isChecked());
346 config
->writeEntry("Launch Manager", base
->launchManager
->isChecked());
349 QByteArray data
, retval
;
351 QDataStream
arg(&data
, QIODevice::WriteOnly
);
353 arg
.setVersion(QDataStream::Qt_3_1
);
354 DCOPCString modName
= "kardsvc";
357 // Start or stop the server as needed
358 if (base
->enableSupport
->isChecked()) {
360 kapp
->dcopClient()->call("kded", "kded", "loadModule(QCString)",
361 data
, rettype
, retval
);
364 kapp
->dcopClient()->call("kded", "kardsvc", "reconfigure()",
365 data
, rettype
, retval
);
370 kapp
->dcopClient()->call("kded", "kded", "unloadModule(QCString)",
371 data
, rettype
, retval
);
379 void KSmartcardConfig::defaults()
382 base
->enableSupport
->setChecked(false);
383 base
->enablePolling
->setChecked(true);
384 base
->beepOnInsert
->setChecked(true);
385 base
->launchManager
->setChecked(true);
393 QString
KSmartcardConfig::quickHelp() const
395 return i18n("<h1>smartcard</h1> This module allows you to configure KDE support"
396 " for smartcards. These can be used for various tasks such as storing"
397 " SSL certificates and logging in to the system.");
402 KDE_EXPORT
void kcminit_smartcard()
404 KConfig
*config
= new KConfig("ksmartcardrc", false, false);
405 bool start
= config
->readEntry("Enable Support", false);
409 QByteArray data
, retval
;
411 QDataStream
arg(&data
, QIODevice::WriteOnly
);
413 arg
.setVersion(QDataStream::Qt_3_1
);
414 DCOPCString modName
= "kardsvc";
416 kapp
->dcopClient()->call("kded", "kded", "loadModule(QCString)",
417 data
, rettype
, retval
);
423 #include "smartcard.moc"