/**********************************************************************
 * 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 "vaderutil.h"
#include <QAction>
#include "proto/headers.h"

namespace LC
{
namespace Azoth
{
namespace Vader
{
namespace VaderUtil
{
	State StatusID2State (quint32 id)
	{
		if (id == Proto::UserState::Online)
			return SOnline;
		else if (id == Proto::UserState::Away)
			return SAway;
		else
			return SOffline;
	}

	quint32 State2StatusID (State state)
	{
		switch (state)
		{
		case SOnline:
		case SChat:
			return Proto::UserState::Online;
		case SOffline:
			return Proto::UserState::Offline;
		case SConnecting:
		case SError:
			return Proto::UserState::Undeterm;
		default:
			return Proto::UserState::Away;
		}
	}

	QList<QAction*> GetBuddyServices (QObject *receiver, const char *slot)
	{
		QList<QAction*> result;
		QAction *world = new QAction (QObject::tr ("MyWorld@Mail.ru"), receiver);
		world->setProperty ("URL", "http://r.mail.ru/cln3587/my.mail.ru/%2/%1/");
		QObject::connect (world,
				SIGNAL (triggered ()),
				receiver,
				slot);
		result << world;
		QAction *photo = new QAction (QObject::tr ("Photo@Mail.ru"), receiver);
		photo->setProperty ("URL", "http://r.mail.ru/cln3565/foto.mail.ru/%2/%1/");
		QObject::connect (photo,
				SIGNAL (triggered ()),
				receiver,
				slot);
		result << photo;
		QAction *video = new QAction (QObject::tr ("Video@Mail.ru"), receiver);
		video->setProperty ("URL", "http://r.mail.ru/cln3567/video.mail.ru/%2/%1/");
		QObject::connect (video,
				SIGNAL (triggered ()),
				receiver,
				slot);
		result << video;
		QAction *blogs = new QAction (QObject::tr ("Blogs@Mail.ru"), receiver);
		blogs->setProperty ("URL", "http://r.mail.ru/cln3566/blogs.mail.ru/%2/%1/");
		QObject::connect (blogs,
				SIGNAL (triggered ()),
				receiver,
				slot);
		result << blogs;
		return result;
	}

	QString SubstituteNameDomain (const QString& string, const QString& fullEmail)
	{
		const QStringList& splitted = fullEmail.split ('@', QString::SkipEmptyParts);
		const QString& name = splitted.value (0);
		QString domain = splitted.value (1);
		if (domain.endsWith (".ru"))
			domain.chop (3);
		return string
				.arg (name)
				.arg (domain);
	}
}
}
}
}
