/**********************************************************************
 * LeechCraft - modular cross-platform feature rich internet client.
 * Copyright (C) 2006-2014  Georg Rudoy
 *
 * Boost Software License - Version 1.0 - August 17th, 2003
 *
 * Permission is hereby granted, free of charge, to any person or organization
 * obtaining a copy of the software and accompanying documentation covered by
 * this license (the "Software") to use, reproduce, display, distribute,
 * execute, and transmit the Software, and to prepare derivative works of the
 * Software, and to permit third-parties to whom the Software is furnished to
 * do so, all subject to the following:
 *
 * The copyright notices in the Software and this entire statement, including
 * the above license grant, this restriction and the following disclaimer,
 * must be included in all copies of the Software, in whole or in part, and
 * all derivative works of the Software, unless such copies or derivative
 * works are solely in the form of machine-executable object code generated by
 * a source language processor.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
 * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
 * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 **********************************************************************/

#include "mooddialog.h"
#include <util/sys/resourceloader.h>
#include "core.h"
#include "xmlsettingsmanager.h"
#include "resourcesmanager.h"

namespace LeechCraft
{
namespace Azoth
{
	QString MoodDialog::ToHumanReadable (const QString& str)
	{
		return tr (str.toLatin1 ());
	}

	MoodDialog::MoodDialog (QWidget *parent)
	: QDialog (parent)
	{
		Ui_.setupUi (this);

		const char* moodStr[] =
		{
			QT_TR_NOOP ("afraid"),
			QT_TR_NOOP ("amazed"),
			QT_TR_NOOP ("amorous"),
			QT_TR_NOOP ("angry"),
			QT_TR_NOOP ("annoyed"),
			QT_TR_NOOP ("anxious"),
			QT_TR_NOOP ("aroused"),
			QT_TR_NOOP ("ashamed"),
			QT_TR_NOOP ("bored"),
			QT_TR_NOOP ("brave"),
			QT_TR_NOOP ("calm"),
			QT_TR_NOOP ("cautious"),
			QT_TR_NOOP ("cold"),
			QT_TR_NOOP ("confident"),
			QT_TR_NOOP ("confused"),
			QT_TR_NOOP ("contemplative"),
			QT_TR_NOOP ("contented"),
			QT_TR_NOOP ("cranky"),
			QT_TR_NOOP ("crazy"),
			QT_TR_NOOP ("creative"),
			QT_TR_NOOP ("curious"),
			QT_TR_NOOP ("dejected"),
			QT_TR_NOOP ("depressed"),
			QT_TR_NOOP ("disappointed"),
			QT_TR_NOOP ("disgusted"),
			QT_TR_NOOP ("dismayed"),
			QT_TR_NOOP ("distracted"),
			QT_TR_NOOP ("embarrassed"),
			QT_TR_NOOP ("envious"),
			QT_TR_NOOP ("excited"),
			QT_TR_NOOP ("flirtatious"),
			QT_TR_NOOP ("frustrated"),
			QT_TR_NOOP ("grateful"),
			QT_TR_NOOP ("grieving"),
			QT_TR_NOOP ("grumpy"),
			QT_TR_NOOP ("guilty"),
			QT_TR_NOOP ("happy"),
			QT_TR_NOOP ("hopeful"),
			QT_TR_NOOP ("hot"),
			QT_TR_NOOP ("humbled"),
			QT_TR_NOOP ("humiliated"),
			QT_TR_NOOP ("hungry"),
			QT_TR_NOOP ("hurt"),
			QT_TR_NOOP ("impressed"),
			QT_TR_NOOP ("in_awe"),
			QT_TR_NOOP ("in_love"),
			QT_TR_NOOP ("indignant"),
			QT_TR_NOOP ("interested"),
			QT_TR_NOOP ("intoxicated"),
			QT_TR_NOOP ("invincible"),
			QT_TR_NOOP ("jealous"),
			QT_TR_NOOP ("lonely"),
			QT_TR_NOOP ("lost"),
			QT_TR_NOOP ("lucky"),
			QT_TR_NOOP ("mean"),
			QT_TR_NOOP ("moody"),
			QT_TR_NOOP ("nervous"),
			QT_TR_NOOP ("neutral"),
			QT_TR_NOOP ("offended"),
			QT_TR_NOOP ("outraged"),
			QT_TR_NOOP ("playful"),
			QT_TR_NOOP ("proud"),
			QT_TR_NOOP ("relaxed"),
			QT_TR_NOOP ("relieved"),
			QT_TR_NOOP ("remorseful"),
			QT_TR_NOOP ("restless"),
			QT_TR_NOOP ("sad"),
			QT_TR_NOOP ("sarcastic"),
			QT_TR_NOOP ("satisfied"),
			QT_TR_NOOP ("serious"),
			QT_TR_NOOP ("shocked"),
			QT_TR_NOOP ("shy"),
			QT_TR_NOOP ("sick"),
			QT_TR_NOOP ("sleepy"),
			QT_TR_NOOP ("spontaneous"),
			QT_TR_NOOP ("stressed"),
			QT_TR_NOOP ("strong"),
			QT_TR_NOOP ("surprised"),
			QT_TR_NOOP ("thankful"),
			QT_TR_NOOP ("thirsty"),
			QT_TR_NOOP ("tired"),
			QT_TR_NOOP ("undefined"),
			QT_TR_NOOP ("weak"),
			QT_TR_NOOP ("worried")
		};

		const auto rl = ResourcesManager::Instance ()
				.GetResourceLoader (ResourcesManager::RLTMoodIconLoader);
		const QString& theme = XmlSettingsManager::Instance ()
				.property ("MoodIcons").toString () + '/';

		Ui_.Mood_->addItem (tr ("<clear>"));

		QMap<QString, QPair<QVariant, QIcon>> list;

		for (uint i = 0; i < sizeof (moodStr) / sizeof (moodStr [0]); ++i)
		{
			QString name (moodStr [i]);
			name [0] = name.at (0).toUpper ();
			QIcon icon (rl->GetIconPath (theme + name));

			list [tr (moodStr [i])] = qMakePair<QVariant, QIcon> (QString (moodStr [i]), icon);
		}

		Q_FOREACH (const QString& key, list.keys ())
			Ui_.Mood_->addItem (list [key].second,
					key, list [key].first);
	}

	QString MoodDialog::GetMood () const
	{
		return Ui_.Mood_->itemData (Ui_.Mood_->currentIndex ()).toString ();
	}

	void MoodDialog::SetMood (const QString& mood)
	{
		const int idx = std::max (0, Ui_.Mood_->findData (mood));
		Ui_.Mood_->setCurrentIndex (idx);
	}

	QString MoodDialog::GetText () const
	{
		return Ui_.Text_->text ();
	}

	void MoodDialog::SetText (const QString& text)
	{
		Ui_.Text_->setText (text);
	}
}
}
