|
|
|
/**
|
|
|
|
* smartcard.cpp
|
|
|
|
*
|
|
|
|
* Copyright (c) 2001 George Staikos <staikos@kde.org>
|
|
|
|
* Copyright (c) 2001 Fernando Llobregat <fernando.llobregat@free.fr>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <tqcheckbox.h>
|
|
|
|
#include <tqlabel.h>
|
|
|
|
#include <tqlayout.h>
|
|
|
|
#include <tqlineedit.h>
|
|
|
|
#include <tqpushbutton.h>
|
|
|
|
|
|
|
|
#include <dcopclient.h>
|
|
|
|
|
|
|
|
#include <kaboutdata.h>
|
|
|
|
#include <kapplication.h>
|
|
|
|
#include <kcarddb.h>
|
|
|
|
#include <kcardfactory.h>
|
|
|
|
#include <kcardgsm_impl.h>
|
|
|
|
#include <kconfig.h>
|
|
|
|
#include <kdebug.h>
|
|
|
|
#include <kdialog.h>
|
|
|
|
#include <kglobal.h>
|
|
|
|
#include <klistview.h>
|
|
|
|
#include <klocale.h>
|
|
|
|
#include <kmessagebox.h>
|
|
|
|
#include <kpopupmenu.h>
|
|
|
|
|
|
|
|
#include "smartcard.h"
|
|
|
|
|
|
|
|
KSmartcardConfig::KSmartcardConfig(TQWidget *parent, const char *name)
|
|
|
|
: KCModule(parent, name),DCOPObject(name)
|
|
|
|
{
|
|
|
|
|
|
|
|
TQVBoxLayout *layout = new TQVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint());
|
|
|
|
config = new KConfig("ksmartcardrc", false, false);
|
|
|
|
|
|
|
|
DCOPClient *dc = KApplication::kApplication()->dcopClient();
|
|
|
|
|
|
|
|
_ok = false;
|
|
|
|
dc->remoteInterfaces("kded", "kardsvc", &_ok);
|
|
|
|
|
|
|
|
KAboutData *about =
|
|
|
|
new KAboutData(I18N_NOOP("kcmsmartcard"), I18N_NOOP("KDE Smartcard Control Module"),
|
|
|
|
0, 0, KAboutData::License_GPL,
|
|
|
|
I18N_NOOP("(c) 2001 George Staikos"));
|
|
|
|
|
|
|
|
about->addAuthor("George Staikos", 0, "staikos@kde.org");
|
|
|
|
setAboutData( about );
|
|
|
|
|
|
|
|
if (_ok) {
|
|
|
|
|
|
|
|
|
|
|
|
base = new SmartcardBase(this);
|
|
|
|
layout->add(base);
|
|
|
|
|
|
|
|
_popUpKardChooser = new KPopupMenu(this,"KpopupKardChooser");
|
|
|
|
_popUpKardChooser->insertItem(i18n("Change Module..."),
|
|
|
|
this,
|
|
|
|
TQT_SLOT(slotLaunchChooser()));
|
|
|
|
// The config backend
|
|
|
|
|
|
|
|
connect(base->launchManager, TQT_SIGNAL(clicked()), TQT_SLOT( changed() ));
|
|
|
|
connect(base->beepOnInsert, TQT_SIGNAL(clicked()), TQT_SLOT( changed() ));
|
|
|
|
connect(base->enableSupport, TQT_SIGNAL(clicked()), TQT_SLOT( changed() ));
|
|
|
|
|
|
|
|
|
|
|
|
connect(base->enablePolling, TQT_SIGNAL(clicked()), TQT_SLOT( changed() ));
|
|
|
|
connect(base->_readerHostsListView,
|
|
|
|
TQT_SIGNAL(rightButtonPressed(TQListViewItem *,const TQPoint &,int)),
|
|
|
|
this,
|
|
|
|
TQT_SLOT(slotShowPopup(TQListViewItem *,const TQPoint &,int)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!connectDCOPSignal("",
|
|
|
|
"",
|
|
|
|
"signalReaderListChanged(TQStringList)",
|
|
|
|
"loadReadersTab(TQStringList)",
|
|
|
|
FALSE))
|
|
|
|
|
|
|
|
kdDebug()<<"Error connecting to DCOP server" <<endl;
|
|
|
|
|
|
|
|
|
|
|
|
if (!connectDCOPSignal("",
|
|
|
|
"",
|
|
|
|
"signalCardStateChanged(TQString,bool,TQString)",
|
|
|
|
"updateReadersState (TQString,bool,TQString) ",
|
|
|
|
FALSE))
|
|
|
|
|
|
|
|
kdDebug()<<"Error connecting to DCOP server" <<endl;
|
|
|
|
_cardDB= new KCardDB();
|
|
|
|
load();
|
|
|
|
} else {
|
|
|
|
layout->add(new NoSmartcardBase(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KSmartcardConfig::~KSmartcardConfig()
|
|
|
|
{
|
|
|
|
delete config;
|
|
|
|
delete _cardDB;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KSmartcardConfig::slotLaunchChooser(){
|
|
|
|
|
|
|
|
|
|
|
|
if ( KCardDB::launchSelector(base->_readerHostsListView->currentItem()->parent()->text(0))){
|
|
|
|
|
|
|
|
KMessageBox::sorry(this,i18n("Unable to launch KCardChooser"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void KSmartcardConfig::slotShowPopup(TQListViewItem * item ,const TQPoint & _point,int i)
|
|
|
|
{
|
|
|
|
|
|
|
|
//The popup only appears in cards, not in the slots1
|
|
|
|
if (item->isSelectable()) return;
|
|
|
|
_popUpKardChooser->exec(_point);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KSmartcardConfig::updateReadersState (TQString readerName,
|
|
|
|
bool isCardPresent,
|
|
|
|
TQString atr) {
|
|
|
|
|
|
|
|
KListViewItem * tID=(KListViewItem *) base->_readerHostsListView->findItem(readerName, 0);
|
|
|
|
if (tID==0) return;
|
|
|
|
|
|
|
|
KListViewItem * tIDChild=(KListViewItem*) tID->firstChild();
|
|
|
|
if (tIDChild==NULL) return;
|
|
|
|
|
|
|
|
delete tIDChild;
|
|
|
|
|
|
|
|
if (!isCardPresent)
|
|
|
|
(void) new KListViewItem(tID,i18n("No card inserted"));
|
|
|
|
else{
|
|
|
|
|
|
|
|
getSupportingModule(tID,atr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KSmartcardConfig::loadReadersTab( TQStringList lr){
|
|
|
|
|
|
|
|
//Prepare data for dcop calls
|
|
|
|
TQByteArray data, retval;
|
|
|
|
TQCString rettype;
|
|
|
|
TQDataStream arg(data, IO_WriteOnly);
|
|
|
|
TQCString modName = "kardsvc";
|
|
|
|
arg << modName;
|
|
|
|
|
|
|
|
// New view items
|
|
|
|
KListViewItem * temp;
|
|
|
|
|
|
|
|
//If the smartcard support is disabled we unload the kardsvc KDED module
|
|
|
|
// and return
|
|
|
|
|
|
|
|
base->_readerHostsListView->clear();
|
|
|
|
|
|
|
|
if (!config->readBoolEntry("Enable Support", false)){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// New view items
|
|
|
|
KListViewItem * temp;
|
|
|
|
kapp->dcopClient()->call("kded", "kded", "unloadModule(TQCString)",
|
|
|
|
data, rettype, retval);
|
|
|
|
|
|
|
|
(void) new KListViewItem(base->_readerHostsListView,
|
|
|
|
i18n("Smart card support disabled"));
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lr.isEmpty()){
|
|
|
|
|
|
|
|
|
|
|
|
(void) new KListViewItem(base->_readerHostsListView,
|
|
|
|
i18n("No readers found. Check 'pcscd' is running"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (TQStringList::Iterator _slot=lr.begin();_slot!=lr.end();++_slot){
|
|
|
|
|
|
|
|
temp= new KListViewItem(base->_readerHostsListView,*_slot);
|
|
|
|
|
|
|
|
|
|
|
|
TQByteArray dataATR;
|
|
|
|
TQDataStream argATR(dataATR,IO_WriteOnly);
|
|
|
|
argATR << *_slot;
|
|
|
|
|
|
|
|
kapp->dcopClient()->call("kded", "kardsvc", "getCardATR(TQString)",
|
|
|
|
dataATR, rettype, retval);
|
|
|
|
|
|
|
|
|
|
|
|
TQString cardATR;
|
|
|
|
TQDataStream retReaderATR(retval, IO_ReadOnly);
|
|
|
|
retReaderATR>>cardATR;
|
|
|
|
|
|
|
|
if (cardATR.isNull()){
|
|
|
|
|
|
|
|
(void) new KListViewItem(temp,i18n("NO ATR or no card inserted"));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
getSupportingModule(temp,cardATR);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KSmartcardConfig::getSupportingModule( KListViewItem * ant,
|
|
|
|
TQString & cardATR) const{
|
|
|
|
|
|
|
|
|
|
|
|
if (cardATR.isNull()){
|
|
|
|
|
|
|
|
(void) new KListViewItem(ant,i18n("NO ATR or no card inserted"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TQString modName=_cardDB->getModuleName(cardATR);
|
|
|
|
if (!modName.isNull()){
|
|
|
|
TQStringList mng= TQStringList::split(",",modName);
|
|
|
|
TQString type=mng[0];
|
|
|
|
TQString subType=mng[1];
|
|
|
|
TQString subSubType=mng[2];
|
|
|
|
KListViewItem * hil =new KListViewItem(ant,
|
|
|
|
i18n("Managed by: "),
|
|
|
|
type,
|
|
|
|
subType,
|
|
|
|
subSubType);
|
|
|
|
hil->setSelectable(FALSE);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
|
|
|
|
|
|
|
|
KListViewItem * hil =new KListViewItem(ant,
|
|
|
|
i18n("No module managing this card"));
|
|
|
|
hil->setSelectable(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
void KSmartcardConfig::load()
|
|
|
|
{
|
|
|
|
load( false );
|
|
|
|
|
|
|
|
void KSmartcardConfig::load(bool useDefaults )
|
|
|
|
{
|
|
|
|
|
|
|
|
//Prepare data for dcop calls
|
|
|
|
TQByteArray data, retval;
|
|
|
|
TQCString rettype;
|
|
|
|
TQDataStream arg(data, IO_WriteOnly);
|
|
|
|
TQCString modName = "kardsvc";
|
|
|
|
arg << modName;
|
|
|
|
|
|
|
|
//Update the toggle buttons with the current configuration
|
|
|
|
|
|
|
|
config->setReadDefaults( useDefaults );
|
|
|
|
|
|
|
|
if (_ok) {
|
|
|
|
base->enableSupport->setChecked(config->readBoolEntry("Enable Support",
|
|
|
|
false));
|
|
|
|
base->enablePolling->setChecked(config->readBoolEntry("Enable Polling",
|
|
|
|
true));
|
|
|
|
base->beepOnInsert->setChecked(config->readBoolEntry("Beep on Insert",
|
|
|
|
true));
|
|
|
|
base->launchManager->setChecked(config->readBoolEntry("Launch Manager",
|
|
|
|
true));
|
|
|
|
}
|
|
|
|
|
|
|
|
// We call kardsvc to retrieve the current readers
|
|
|
|
kapp->dcopClient()->call("kded", "kardsvc", "getSlotList ()",
|
|
|
|
data, rettype, retval);
|
|
|
|
TQStringList readers;
|
|
|
|
readers.clear();
|
|
|
|
TQDataStream retReader(retval, IO_ReadOnly);
|
|
|
|
retReader>>readers;
|
|
|
|
|
|
|
|
//And we update the panel
|
|
|
|
loadReadersTab(readers);
|
|
|
|
|
|
|
|
emit changed(useDefaults);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KSmartcardConfig::save()
|
|
|
|
{
|
|
|
|
if (_ok) {
|
|
|
|
config->writeEntry("Enable Support", base->enableSupport->isChecked());
|
|
|
|
config->writeEntry("Enable Polling", base->enablePolling->isChecked());
|
|
|
|
config->writeEntry("Beep on Insert", base->beepOnInsert->isChecked());
|
|
|
|
config->writeEntry("Launch Manager", base->launchManager->isChecked());
|
|
|
|
|
|
|
|
|
|
|
|
TQByteArray data, retval;
|
|
|
|
TQCString rettype;
|
|
|
|
TQDataStream arg(data, IO_WriteOnly);
|
|
|
|
TQCString modName = "kardsvc";
|
|
|
|
arg << modName;
|
|
|
|
|
|
|
|
// Start or stop the server as needed
|
|
|
|
if (base->enableSupport->isChecked()) {
|
|
|
|
|
|
|
|
kapp->dcopClient()->call("kded", "kded", "loadModule(TQCString)",
|
|
|
|
data, rettype, retval);
|
|
|
|
config->sync();
|
|
|
|
|
|
|
|
kapp->dcopClient()->call("kded", "kardsvc", "reconfigure()",
|
|
|
|
data, rettype, retval);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kapp->dcopClient()->call("kded", "kded", "unloadModule(TQCString)",
|
|
|
|
data, rettype, retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
emit changed(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KSmartcardConfig::defaults()
|
|
|
|
{
|
|
|
|
load( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TQString KSmartcardConfig::quickHelp() const
|
|
|
|
{
|
|
|
|
return i18n("<h1>smartcard</h1> This module allows you to configure KDE support"
|
|
|
|
" for smartcards. These can be used for various tasks such as storing"
|
|
|
|
" SSL certificates and logging in to the system.");
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
KDE_EXPORT KCModule *create_smartcard(TQWidget *parent, const char *)
|
|
|
|
{
|
|
|
|
return new KSmartcardConfig(parent, "kcmsmartcard");
|
|
|
|
}
|
|
|
|
|
|
|
|
KDE_EXPORT void init_smartcard()
|
|
|
|
{
|
|
|
|
KConfig *config = new KConfig("ksmartcardrc", false, false);
|
|
|
|
bool start = config->readBoolEntry("Enable Support", false);
|
|
|
|
delete config;
|
|
|
|
|
|
|
|
if (start) {
|
|
|
|
TQByteArray data, retval;
|
|
|
|
TQCString rettype;
|
|
|
|
TQDataStream arg(data, IO_WriteOnly);
|
|
|
|
TQCString modName = "kardsvc";
|
|
|
|
arg << modName;
|
|
|
|
kapp->dcopClient()->call("kded", "kded", "loadModule(TQCString)",
|
|
|
|
data, rettype, retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include "smartcard.moc"
|
|
|
|
|