/*
 *  Copyright (C) 2007-2008 CMM Sigma Andrzej Chmielowiec <cmmsigma@cmmsigma.eu>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 3
 *  as published by the Free Software Foundation.
 *
 *  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.
 */

#include <QIcon>

#include "STokenKeyItem.h"
#include "GenCertReqWidget.h"

#include "crd_ut10xx.h"

STokenKeyItem::STokenKeyItem(int keyId, CRD_UT10XX_t *ut, TreeItem *parent): TreeItem(parent)
{
	mUt = ut;
	mId = keyId;
	mMainTabWidget = new QTabWidget;
	
	mGenCertReqWidget = new GenCertReqWidget;
	
	connect(mGenCertReqWidget, SIGNAL(generateCertReqSig(QString&, QStringList&, QString&)), 
		this, SLOT(generateCertReqSlot(QString&, QStringList&, QString&)));
	
	mMainTabWidget->addTab(mGenCertReqWidget, QIcon(QString(":img/filetype_userreq.png")), 
		tr("Certificate request"));
	
	setPage(mMainTabWidget);
}

STokenKeyItem::~STokenKeyItem()
{
}

int
STokenKeyItem::id()
{
	return mId;
}

void
STokenKeyItem::refresh()
{
	QVariant keyName = trUtf8((mUt->keys + mId)->name);
	QVariant keyIcon = QIcon(QString(":img/key.png"));
	
	setData(keyName, Qt::DisplayRole);
	setData(keyIcon, Qt::DecorationRole);
}

void
STokenKeyItem::userLoginSlot()
{
	mGenCertReqWidget->enable();
}

void
STokenKeyItem::logoutSlot()
{
	mGenCertReqWidget->disable();
}

void
STokenKeyItem::generateCertReqSlot(QString &fileName, QStringList &dn, QString &mail)
{
	emit generateCertReqSig(mId, fileName, dn, mail);
}
