/**********************************************************************
 * 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 <QString>
#include <QList>
#include <QtPlugin>

class QObject;

namespace LeechCraft
{
namespace Monocle
{
	/** @brief Describes a single font.
	 */
	struct FontInfo
	{
		/** @brief The name of the font as it appears in the document.
		 *
		 * This name does not have to be equal to some commonly used name
		 * like "Droid Sans Mono".
		 */
		QString FontName_;

		/** @brief The path to the local font file used.
		 *
		 * This variable makes no sense if the font is embedded.
		 */
		QString LocalPath_;

		/** @brief Whether the font is embedded into the document.
		 */
		bool IsEmbedded_;
	};

	/** @brief A list of FontInfo structures.
	 */
	typedef QList<FontInfo> FontInfos_t;

	/** @brief A proxy object for a pending font info request.
	 *
	 * The IPendingFontInfoRequest object is returned from the
	 * IHaveFontInfo::RequestFontInfos() method. The object is initially
	 * in pending state until the ready() signal is emitted, after which
	 * the font info can be obtained via the GetFontInfos() method.
	 * The GetQObject() method can be used to get a <code>QObject*</code>
	 * to pass in <code>connect()</code>.
	 *
	 * The object is used to support asynchronous font info fetching,
	 * though some single-threaded format implementations may block.
	 *
	 * The IPendingFontInfoRequest objects are self-owning, that is,
	 * they schedule their own destruction shortly after emitting the
	 * ready() signal. The object can be used no later than in slots
	 * connected to the ready() signal via <code>Qt::DirectConnection</code>.
	 */
	class IPendingFontInfoRequest
	{
	public:
		virtual ~IPendingFontInfoRequest () {}

		/** @brief Returns this object as a QObject.
		 *
		 * @return This object as a QObject.
		 */
		virtual QObject* GetQObject () = 0;

		/** @brief Returns the font information list for the document.
		 *
		 * If the request object is ready, then the list of FontInfo
		 * structures is returned, otherwise an empty list is returned.
		 *
		 * @return The list of font information structures, or an empty
		 * list if the object is not ready.
		 *
		 * @sa ready()
		 */
		virtual QList<FontInfo> GetFontInfos () const = 0;
	protected:
		/** @brief Notifies that the request is completed.
		 *
		 * This signal is emitted to notify that the
		 * IPendingFontInfoRequest object became ready and can now be
		 * queried via the GetFontInfos() method.
		 *
		 * The IPendingFontInfoRequest will schedule the self deletion
		 * after emitting this signal.
		 *
		 * @note This function is expected to be a signal.
		 *
		 * @sa GetFontInfos()
		 */
		virtual void ready () = 0;
	};

	/** @brief Interface for querying font information in a document.
	 *
	 * This interface can be implemented by documents supporting querying
	 * font information, like PDF.
	 */
	class IHaveFontInfo
	{
	public:
		virtual ~IHaveFontInfo () {}

		/** @brief Requests the font information for the document.
		 *
		 * The returned object is self-owned, that is, it is destroyed
		 * shortly after becoming ready (and emitting
		 * IPendingFontInfoRequest::ready()).
		 *
		 * This function may or may not block.
		 *
		 * @return The pending font info request.
		 *
		 * @sa IPendingFontInfoRequest
		 */
		virtual IPendingFontInfoRequest* RequestFontInfos () const = 0;
	};
}
}

Q_DECLARE_INTERFACE (LeechCraft::Monocle::IPendingFontInfoRequest,
		"org.LeechCraft.Monocle.IPendingFontInfoRequest/1.0")
Q_DECLARE_INTERFACE (LeechCraft::Monocle::IHaveFontInfo,
		"org.LeechCraft.Monocle.IHaveFontInfo/1.0")
