/**********************************************************************
 * 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.
 **********************************************************************/

#pragma once

#include <QImage>
#include <QFuture>
#include <QtPlugin>

namespace LC
{
namespace Azoth
{
	/** @brief Describes an entry that can have an associated avatar.
	 */
	class IHaveAvatars
	{
	protected:
		virtual ~IHaveAvatars () {}
	public:
		/** @brief The size of the avatar.
		 */
		enum class Size
		{
			/** @brief Full-size avatar.
			 */
			Full,

			/** @brief Thumbnail avatar, possibly cropped.
			 */
			Thumbnail
		};

		/** @brief Requests the avatar of the given \em size.
		 *
		 * This function should schedule fetching the avatar and return a
		 * future that will become ready once the avatar is fetched.
		 *
		 * If there is no avatar, a null QImage should be returned.
		 *
		 * No cached copies should be returned, the avatar information
		 * should be rerequested from scratch (hence <em>refrech</em> in
		 * the method name).
		 *
		 * If \em size is not supported, an empty, cancelled future should
		 * be returned.
		 *
		 * @param[in] size The required size of the avatar.
		 * @return A future providing the avatar's image.
		 */
		virtual QFuture<QImage> RefreshAvatar (Size size) = 0;

		/** @brief Returns whether this exact entry has any avatar.
		 *
		 * @return Whether there is an avatar.
		 */
		virtual bool HasAvatar () const = 0;

		/** @brief Whether this entry has an avatar of the given \em size.
		 *
		 * @param[in] size The desired size of the avatar.
		 * @return Whether the entry has this size.
		 */
		virtual bool SupportsSize (Size size) const = 0;
	protected:
		/** @brief Notifies that the avatar of the entry has been changed.
		 *
		 * This signal should be emitted when the entry detects that the
		 * avatar has been changed.
		 *
		 * If possible, the new avatar should \em not be fetched unless
		 * RefreshAvatar() is called.
		 *
		 * @note This function is expected to be a signal.
		 *
		 * @param[out] thisObject The <code>this</code> pointer.
		 */
		virtual void avatarChanged (QObject *thisObject) = 0;
	};

	/** @brief Defines a hashing function for avatar sizes.
	 *
	 * @param[in] size The size of the avatar.
	 * @return The hash of the size.
	 */
	inline uint qHash (IHaveAvatars::Size size)
	{
		return static_cast<uint> (size);
	}
}
}

Q_DECLARE_INTERFACE (LC::Azoth::IHaveAvatars,
		"org.LeechCraft.Azoth.IHaveAvatars/1.0")
