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

#include "veneer/iconloader.h"

#include <QDesktopServices>
#include <QUrl>
#include <qglobal.h>

AboutDialog::AboutDialog(QWidget* parent) :
	QDialog(parent)
{
	setupUi(this);

	setWindowTitle(tr("About %1").arg(QCoreApplication::applicationName()));
	setAttribute(Qt::WA_DeleteOnClose);

	QIcon windowIcon = DesktopIcon(QCoreApplication::applicationName().toLower());

	if (windowIcon.isNull())
		windowIcon = qApp->windowIcon();

	iconLabel->setPixmap(windowIcon.pixmap(64, 64));

	titleLabel->setText(QCoreApplication::applicationName());

	const QString subTitleText = tr("<b>Version: %1</b><br>Using Qt Application Framework %2").arg(VERSION).arg(QT_VERSION_STR);
	subTitleLabel->setText(subTitleText);

	const QString descriptionText = tr("Cross-platform Sports and Activity Tracker");

	const QString copyrightText = tr("(c) 2010 Volker Lanz");

	const QString homePageText = QString("<a href=\"%1\">%1</a>").arg("http://www.volker-lanz.de");
	const QString licenseText = tr("<a href=\"%1\">License: GNU General Public License Version 2</a>").arg("http://www.gnu.org/licenses/gpl-2.0.txt");

	const QString aboutText =
		"<br/>" + descriptionText + "<br/>" +
		"<br/>" + copyrightText + "<br/>" +
		"<br/>" + homePageText + "<br/>" +
		"<br/>" + licenseText;

	aboutLabel->setText(aboutText);

	const QString bugText = tr("Please use <a href=\"%1\">%1</a> to report bugs.").arg("http://bugs.kde.org");
	const QString authorText = tr("%1<p style=\"margin:0px; margin-left:15px\"><a href=\"mailto:%2\">%2</a></p>").arg("Volker Lanz").arg("vl@fidra.de");

	authorLabel->setText("<br/>" + bugText + "<br/>" + "<br/>" + authorText);

	connect(aboutLabel, SIGNAL(linkActivated(const QString&)), SLOT(openLink(const QString&)));
	connect(authorLabel, SIGNAL(linkActivated(const QString&)), SLOT(openLink(const QString&)));
}

void AboutDialog::openLink(const QString& url)
{
	QDesktopServices::openUrl(QUrl(url));
}

