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

#ifndef INTERFACES_IWEBBROWSER_H
#define INTERFACES_IWEBBROWSER_H
#include <QString>
#include <QWidget>
#include <QUrl>
#include <QtPlugin>

/** @brief Common interface for a web widget.
 *
 * A widget that is capable of showing/rendering web pages should
 * implement this interface in order to communicate with other modules
 * of LeechCraft.
 */
class Q_DECL_EXPORT IWebWidget
{
public:
	virtual ~IWebWidget () {}

	/** @brief Loads a given url.
	 *
	 * The url should be UTF8-encoded.
	 *
	 * @param[in] url The url of the resource.
	 */
	virtual void Load (const QString& url) = 0;

	/** @brief Sets the contents of the web widget to the specified
	 * html.
	 *
	 * External objects such as stylesheets or images referenced in the
	 * HTML document are located relative to the base.
	 *
	 * @param[in] html The HTML with the new contents.
	 * @param[in] base Base address for resolution of external elements.
	 */
	virtual void SetHtml (const QString& html,
			const QUrl& base = QUrl ()) = 0;

	/** @brief Sets whether the navigation bar of the widget (where the
	 * address bar and reload/back/forward/etc buttons are) is visible.
	 *
	 * If the widget doesn't have such bar this function does nothing.
	 *
	 * @param[in] visible Whether to show or hide the navbar.
	 */
	virtual void SetNavBarVisible (bool visible) = 0;

	/** @brief Shows or hides every other panel in the browser but navbar.
	 *
	 * If the IWebBrowser implementation has additional panels,
	 * toolbars, sidebars and similar stuff, it should be set visible
	 * according to the visible parameter.
	 *
	 * @param[in] visible Whether additional stuff should be visible.
	 */
	virtual void SetEverythingElseVisible (bool visible) = 0;

	/** @brief Returns the IWebWidget as a QWidget.
	 *
	 * @return A widget corresponding to this IWebWidget.
	 */
	virtual QWidget* Widget () = 0;
};

class QWebView;

/** @brief Base class for plugins that provide a web browser.
 */
class Q_DECL_EXPORT IWebBrowser
{
public:
	/** @brief Opens the url in the web browser itself.
	 *
	 * @param[in] url The URL to open.
	 */
	virtual void Open (const QString& url) = 0;

	/** @brief Returns the IWebWidget for use in another modules of
	 * LeechCraft.
	 *
	 * The ownership transfers to the caller.
	 *
	 * @return The IWebWidget.
	 */
	virtual IWebWidget* GetWidget () const = 0;

	//virtual QWebView* CreateWindow () = 0;

	virtual ~IWebBrowser () {}
};

Q_DECLARE_INTERFACE (IWebWidget, "org.Deviant.LeechCraft.IWebWidget/1.0");
Q_DECLARE_INTERFACE (IWebBrowser, "org.Deviant.LeechCraft.IWebBrowser/1.0");

#endif

