/* PlayerPlugin.h */

/* Copyright (C) 2011-2024 Michael Lugmair (Lucio Carreras)
 *
 * This file is part of sayonara player
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef PLAYERPLUGIN_H
#define PLAYERPLUGIN_H

#include "Gui/Utils/Widgets/Widget.h"
#include "Utils/Pimpl.h"

class QAction;

namespace PlayerPlugin
{
	class Handler;
	class Base :
		public Gui::Widget
	{
		friend class Handler;

			Q_OBJECT
			PIMPL(Base)

		public:
			explicit Base(QWidget* parent = nullptr);
			~Base() override;

		signals:
			void sigActionTriggered(bool checked);
			void sigReload(PlayerPlugin::Base* plugin);

			void sigOpened();

		private slots:
			void actionTriggered(bool checked);

		private:
			void setUiInitialized();
			void languageChanged() final;

			virtual void initUi() = 0;

		protected:
			virtual void finalizeInitialization();

			virtual bool isUiInitialized() const;
			virtual void assignUiVariables();

			virtual void retranslate() = 0;

			template<typename T, typename UiClass>
			void setupParent(T* widget, UiClass** ui)
			{
				if(isUiInitialized())
				{
					return;
				}

				*ui = new UiClass();
				(*ui)->setupUi(widget);

				assignUiVariables();
				finalizeInitialization();
			}

			void closeEvent(QCloseEvent* e) override;
			void showEvent(QShowEvent* e) override;

		public:
			[[nodiscard]] virtual QAction* pluginAction() const final;

			[[nodiscard]] virtual QString name() const = 0;

			[[nodiscard]] virtual QString displayName() const = 0;

			[[nodiscard]] virtual bool hasTitle() const;

			[[nodiscard]] virtual bool hasLoadingBar() const;
	};
}

Q_DECLARE_INTERFACE(PlayerPlugin::Base, "com.sayonara-player.playerplugin")

#endif // PLAYERPLUGIN_H
