/*
 *  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.
 */

#ifndef STOKEN_ITEM_H
#define STOKEN_ITEM_H

#include "TreeItem.h"
#include "crd_ut10xx.h"

//#define WITH_RBG
//#define WITH_DET_INFO

class GenInfoWidget;
class AdminWidget;
class LoginWidget;
class RbgWidget;
class DetInfoWidget;
	
class STokenItem: public TreeItem
{
	Q_OBJECT;
	
public:
	STokenItem(CRD_UT10XX_t *ut = 0, TreeItem *parent = 0);
	~STokenItem();
	
	int libIndex();
	virtual void displayContextMenu(const QModelIndex &index);
	
public slots:
	void refresh();
	
private slots:
	void genReqFinished(const QString &fileName, const QString &mail);
	
	void confSlot(const char *name, int soPinLim, const char *soPin, int userPinLim, 
		const char *userPin, bool upcna);
	void unLockSlot(const char *soPin);
	
	void soLoginSlot(const char *pin, bool &correct);
	void userLoginSlot(const char *pin, bool &correct);
	void logoutSlot();
	
	void userPinChangeSlot(const char *newPin);
	void soPinChangeSlot(const char *newPin);
	void eraseSlot();
	
	void generateKeySlot(const char *name, int id);
	void deleteKeySlot(int id);
	void generateCertReqSlot(int keyId, QString &fileName, QStringList &dn, QString &mail);
	
#	ifdef WITH_RBG
	void rbgSlot(int octets, int fmt, QString &fileName);
#	endif
	
	void addFileSlot(QString &srcFileName, QString &dstFileName);
	void deleteFileSlot(QString &fileName);
	void saveFileSlot(QString &srcFileName, QString &dstFileName);
	
	void currentChangedSlot(int index);
	void loginPageSlot();
	
signals:
	void soLoginSig();
	void userLoginSig();
	void logoutSig();
	
private:
	static const int StateClear = 0;
	static const int StateInit = 1;
	static const int StateConf = 2;
	static const int StateLock = 3;
	
	int sTokenState();
	
private:
	const char *mPin;
	const char *mSoPin;
	const char *mUserPin;
	int mPinId;
	
	CRD_UT10XX_t *mUt;
	
	QTabWidget *mMainTabWidget;
	
	GenInfoWidget *mGenInfoWidget;
	AdminWidget *mAdminWidget;
	LoginWidget *mLoginWidget;
#	ifdef WITH_RBG
	RbgWidget *mRbgWidget;
#	endif

#	ifdef WITH_DET_INFO
	DetInfoWidget *mDetInfoWidget;
#	endif
};

#endif
