/*
 *  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 "Request.h"

Request::Request()
{
	QTreeWidgetItem::setIcon(0, QIcon(QString(":img/add_user.png")));
}

void
Request::setFileName(const QString &name)
{
	mFileName = name;
}

void
Request::setText(const QString &text)
{
	mText = text;
	
	mSigAlg = mText;
	int i = mSigAlg.indexOf(QString("Signature Algorithm: "));
	int j = mSigAlg.indexOf(QChar('\n'), i);
	mSigAlg.chop(mSigAlg.count() - j);
	mSigAlg.remove(0, i + QString("Signature Algorithm: ").count());
}

void
Request::setSubject(const QString &subj)
{
	Subject::setAll(subj);
	
	if (Subject::organizationName() != QString())
	{
		QTreeWidgetItem::setText(0, Subject::commonName() + QString(",  ") + 
			Subject::organizationName());
	}
	else
	{
		QTreeWidgetItem::setText(0, Subject::commonName());
	}
}

QString
Request::fileName()
{
	return mFileName;
}

QString
Request::text()
{
	return mText;
}

QString
Request::subject()
{
	return Subject::all();
}

QString
Request::signatureAlgorithm()
{
	return mSigAlg;
}
