/***************************************************************************
 *   Copyright (C) 2010 by Volker Lanz <vl@fidra.de>                       *
 *                                                                         *
 *   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 "gui/profiledockwidget.h"

#include "core/profile.h"

#include "veneer/datetime.h"

#include "util/unit.h"

#include <kicon.h>

#include <QDebug>


ProfileDockWidget::ProfileDockWidget(QWidget* parent) :
	QWidget(parent),
	m_Profile(NULL)
{
	setupUi(this);

}

void ProfileDockWidget::clear()
{
	birthLabel->clear();
	nameLabel->clear();
	photoButton->setIcon(KIcon());
	genderLabel->clear();
	heightLabel->clear();
}

void ProfileDockWidget::on_photoButton_clicked(bool)
{
	emit photoClicked();
}

void ProfileDockWidget::updateProfile(Profile* profile)
{
	m_Profile = profile;

	if (m_Profile == NULL)
	{
		clear();
		setEnabled(false);
		return;
	}

	setEnabled(true);

	photoButton->setIcon(m_Profile->photo());
	birthLabel->setText(Veneer::formatShortDate(m_Profile->birthDate()));
	nameLabel->setText(m_Profile->name());

	heightLabel->setText(Unit::formatHeight(m_Profile->height()));

	genderLabel->setText(m_Profile->gender() == Profile::Male ? tr("male") : tr("female"));
}
