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

/** @brief An instance of a spell checker.
 *
 * This interface provides access to the spell checking capabilities of
 * plugins implementing ISpellCheckProvider and is obtained via a call
 * to ISpellCheckProvider::CreateSpellchecker().
 *
 * @sa ISpellCheckProvider
 */
class ISpellChecker
{
public:
	/** @brief Destroys the spell checker instance.
	 */
	virtual ~ISpellChecker () {}

	/** @brief Returns if the given \em word is correct.
	 *
	 * If the word is incorrect, it probably makes sense to get a list
	 * of possible corrections via GetPropositions().
	 *
	 * The spell checker uses the configuration of ISpellCheckProvider
	 * to figure out enabled languages, locales, spell checking options
	 * and so on.
	 *
	 * @param[in] word The word to check.
	 * @return Whether the word is correct.
	 *
	 * @sa GetPropositions()
	 * @sa LearnWord()
	 */
	virtual bool IsCorrect (const QString& word) const = 0;

	/** @brief Returns the list of propositions for the \em word.
	 *
	 * If the word is correct or no propositions are found, an empty
	 * list is returned.
	 *
	 * @param[in] word The word for which to return the list of
	 * propositions.
	 * @return The possibly empty list of propositions.
	 *
	 * @sa IsCorrect()
	 */
	virtual QStringList GetPropositions (const QString& word) const = 0;

	/** @brief Asks the spell checker to learn the given \em word.
	 *
	 * This function is allowed to do nothing if the spell checker does
	 * not support user dictionaries. In this case, IsCorrect() may still
	 * return <code>false</code> for the given \em word even after
	 * calling this function.
	 *
	 * @param[in] word The word to learn.
	 *
	 * @sa IsCorrect()
	 */
	virtual void LearnWord (const QString& word) = 0;
};

/** @brief A shared pointer to an ISpellChecker instance.
 */
using ISpellChecker_ptr = std::shared_ptr<ISpellChecker>;

/** @brief Interface for plugins providing spell checker capabilities.
 *
 * This interface itself does not expose anything for spell checking.
 * Instead, a spell checker instance should be requested via
 * CreateSpellchecker().
 *
 * Plugins implementing this interface have their own options for
 * languages, locales and so on. Thus, this interface offers no way to
 * tune these parameters.
 *
 * @sa ISpellChecker
 */
class ISpellCheckProvider
{
protected:
	virtual ~ISpellCheckProvider () {}
public:
	/** @brief Requests a new spellchecker.
	 *
	 * The ownership is passed to the caller.
	 *
	 * @return A ISpellChecker object.
	 */
	virtual ISpellChecker_ptr CreateSpellchecker () = 0;
};

Q_DECLARE_INTERFACE (ISpellChecker, "org.LeechCraft.ISpellChecker/1.0")
Q_DECLARE_INTERFACE (ISpellCheckProvider, "org.LeechCraft.ISpellCheckProvider/1.0")
