/**********************************************************************
 * 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 UTIL_SELECTABLEBROWSER_H
#define UTIL_SELECTABLEBROWSER_H
#include <memory>
#include <QWidget>
#include <QTextBrowser>
#include <interfaces/iwebbrowser.h>
#include "guiconfig.h"

namespace LeechCraft
{
	namespace Util
	{
		/** @brief A "browser" that shows HTML either via QTextBrowser or
		 * a browser plugin.
		 *
		 * This class is used to display HTML content via some web
		 * browser plugin (like Poshuku) and, if such plugins aren't
		 * available, downgrade to QTextBrowser.
		 *
		 * Currently using this class is generally discouraged. QtWebKit
		 * isn't as new and uncommon as it was a couple of years ago, so
		 * in most cases it's easier to just embed a QWebView.
		 *
		 * @ingroup GuiUtil
		 */
		class UTIL_GUI_API SelectableBrowser : public QWidget
		{
			Q_OBJECT

			bool Internal_;
			std::unique_ptr<QTextBrowser> InternalBrowser_;
			std::unique_ptr<IWebWidget> ExternalBrowser_;
		public:
			/** @brief Constructs the browser with the given parent.
			 *
			 * By default, if no other functions are called, this browser
			 * widget will use QTextBrowser to display content. Call
			 * Construct() and pass a pointer to a web browser plugin to
			 * use it.
			 *
			 * @param[in] parent The parent widget.
			 *
			 * @sa Construct()
			 */
			SelectableBrowser (QWidget *parent = 0);

			/** @brief Initialize the widget with the browser plugin.
			 *
			 * After calling this function the widget will use the
			 * browser plugin to show HTML content.
			 *
			 * If the browser is nullptr, this function does nothing and
			 * the widget still uses the QTextBrowser.
			 *
			 * Any HTML content currently set will be cleared after
			 * calling this function.
			 *
			 * @param[in] browser The browser to use.
			 */
			void Construct (IWebBrowser *browser);

			/** @brief Sets the HTML content to display.
			 *
			 * @param[in] html The HTML content to display.
			 * @param[in] base The base URL which is used to resolve
			 * relative URLs found in the HTML content.
			 */
			void SetHtml (const QString& html, const QUrl& base = QUrl ());

			/** @brief Sets whether navigation bar should be visible.
			 *
			 * The navigation bar typically includes the address edit
			 * button with back/forward/reload buttons. Some plugins may
			 * find it undesirable.
			 *
			 * The default state is unspecified.
			 *
			 * @param[in] visible Whether navigation bar should be
			 * visible.
			 */
			void SetNavBarVisible (bool visible);

			/** @brief Sets whether other UI elements should be visible.
			 *
			 * Sometimes it's not desirable to show, for example, browser
			 * history or bookmarks panes. Use this function to hide
			 * them.
			 *
			 * The default state is unspecified.
			 *
			 * @param[in] visible Whether irrelevant UI elements should be
			 * visible.
			 */
			void SetEverythingElseVisible (bool visible);
		private:
			void PrepareInternal ();
		};
	};
};

#endif

