/**********************************************************************
 * 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 <memory>
#include <QMetaType>
#include <QtNetwork/QNetworkAccessManager>

class IShortcutProxy;
class IMWProxy;
class ITagsManager;
class IPluginsManager;
class ICoreTabWidget;
class IEntityManager;
class QTreeView;
class QModelIndex;
class QIcon;
class QMainWindow;
class QAbstractItemModel;
class QTabWidget;
class IColorThemeManager;
class IIconThemeManager;
class QAction;

namespace LeechCraft
{
	namespace Util
	{
		class BaseSettingsManager;
	}
}

class IRootWindowsManager;

/** @brief Proxy class for the communication with LeechCraft.
 *
 * Allows one to talk with LeechCraft, requesting and getting various
 * services.
 */
class Q_DECL_EXPORT ICoreProxy
{
public:
	virtual ~ICoreProxy () {}

	/** @brief Returns application-wide network access manager.
	 *
	 * If your plugin wants to work well with other internet-related
	 * ones and wants to integrate with application-wide cookie database
	 * and network cache, it should use the returned
	 * QNetworkAccessManager.
	 *
	 * @return The application-wide QNetworkAccessManager.
	 */
	virtual QNetworkAccessManager* GetNetworkAccessManager () const = 0;

	/** @brief Returns the shortcut proxy used to communicate with the
	 * shortcut manager.
	 *
	 * @return The application-wide shortcut proxy.
	 *
	 * @sa IShortcutProxy
	 */
	virtual IShortcutProxy* GetShortcutProxy () const = 0;

	/** @brief Maps the given index to the plugin's model.
	 */
	virtual QModelIndex MapToSource (const QModelIndex& index) const = 0;

	/** @brief Returns the LeechCraft's settings manager.
	 *
	 * In the returned settings manager you can use any property name
	 * you want if it starts from "PluginsStorage". To avoid name
	 * collisions from different plugins it's strongly encouraged to
	 * also use the plugin name in the property. So the property name
	 * would look like "PluginsStorage/PluginName/YourProperty".
	 *
	 * @return The Core settings manager.
	 */
	virtual LeechCraft::Util::BaseSettingsManager* GetSettingsManager () const = 0;

	/** @brief Returns the icon theme manager.
	 *
	 * @return The icon manager.
	 *
	 * @sa IIconThemeManager
	 */
	virtual IIconThemeManager* GetIconThemeManager () const = 0;

	/** @brief Returns the color theme manager.
	 *
	 * @return The color manager.
	 *
	 * @sa IColorThemeManager
	 */
	virtual IColorThemeManager* GetColorThemeManager () const = 0;

	/** @brief Returns the root windows manager.
	 *
	 * @return The root windows manager.
	 *
	 * @sa IRootWindowsManager
	 */
	virtual IRootWindowsManager* GetRootWindowsManager () const = 0;

	/** @brief Returns the application-wide tags manager.
	 *
	 * @return The application-wide tags manager.
	 *
	 * @sa ITagsManager
	 */
	virtual ITagsManager* GetTagsManager () const = 0;

	/** Returns the list of all possible search categories from the
	 * finders installed.
	 *
	 * This function merely aggregates all the search categories from all
	 * the plugins implementing the IFinder interface, calling
	 * IFinder::GetCategories().
	 *
	 * @return The search categories of all finder.
	 *
	 * @sa IFinder
	 */
	virtual QStringList GetSearchCategories () const = 0;

	/** @brief Returns an ID for a delegated task from the pool.
	 *
	 * Use this in your downloader plugin when generating an ID for a
	 * newly added task. This way you can avoid ID clashes with other
	 * downloaders.
	 *
	 * @return The ID of the task.
	 *
	 * @sa FreeID()
	 */
	virtual int GetID () = 0;

	/** @brief Marks an ID previously returned by GetID as unused.
	 *
	 * Returns the id to the global ID pool. Use this in your downloader
	 * plugins after your download finishes.
	 *
	 * @param[in] id An ID previously obtained by GetID().
	 *
	 * @sa GetID()
	 */
	virtual void FreeID (int id) = 0;

	/** @brief Returns the application's plugin manager.
	 *
	 * @return The application plugins manager.
	 *
	 * @sa IPluginsManager
	 */
	virtual IPluginsManager* GetPluginsManager () const = 0;

	/** @brief Returns the entity manager object.
	 *
	 * Entity manager is used to perform interoperation with other plugins
	 * by exchanging entity objects with them.
	 *
	 * @return The application-wide entity manager.
	 *
	 * @sa LeechCraft::Entity
	 * @sa IEntityManager
	 */
	virtual IEntityManager* GetEntityManager () const = 0;

	/** @brief Returns the version of LeechCraft core and base system.
	 *
	 * The returned strings reflects the runtime version of the Core.
	 *
	 * @return The version of the LeechCraft Core.
	 */
	virtual QString GetVersion () const = 0;

	/** @brief Registers the given action as having skinnable icons.
	 *
	 * Registers the given action so that it automatically gets its icon
	 * updated whenever the current iconset changes.
	 *
	 * @param[in] action The action to register.
	 */
	virtual void RegisterSkinnable (QAction *action) = 0;

	/** @brief Checks if LeechCraft is currently shutting down.
	 *
	 * This function returns whether shutdown sequence has been
	 * initiated.
	 *
	 * For example, in this case user interaction is discouraged.
	 *
	 * @return Whether LeechCraft is shutting down.
	 */
	virtual bool IsShuttingDown () = 0;
};

using ICoreProxy_ptr = std::shared_ptr<ICoreProxy>;

Q_DECLARE_METATYPE (ICoreProxy_ptr)
Q_DECLARE_INTERFACE (ICoreProxy, "org.Deviant.LeechCraft.ICoreProxy/1.0");
