/*******************************************************************************
***  This file is part of Dux Rei Nummariae.                                 ***
***                                                                          ***
***  Copyright (C) 2017, 2018, 2019, 2020, 2021                              ***
***  John Schneiderman <Licensing _AT_ Schneiderman _DOT_ me>                ***
***                                                                          ***
***  This program is free software: you can redistribute it and/or modify it ***
***  under the terms of the GNU Affero 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 Affero General Public License for more details.             ***
***                                                                          ***
***  You should have received a copy of the GNU Affero General Public License***
***  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
*******************************************************************************/
#ifndef DRN_DESKTOP_UI_INTERNAL_CONFIGUREWIDGET_H_
#define DRN_DESKTOP_UI_INTERNAL_CONFIGUREWIDGET_H_

#include <pecunia/Codes.h>
#include <QDialog>

#include <chrono>
#include <set>

#include <foundation/CalendarTime.hpp>
#include <ui_ConfigureDialog.h>


class QAbstractButton;
class QWidget;

namespace drn
{
namespace foundation
{

template<typename>
class ObserverPtr;

}
namespace desktop_ui
{
namespace internal
{

/**
 * @brief A Qt dialog to display and enter application settings.
 */
class ConfigureDialog : public QDialog, Ui::ConfigureDlg
{
	Q_OBJECT

	void handleSave();

	const std::set<pecunia::currency::Iso4217Codes> used_;

private slots:
	void updateUsable(const int& index);
	void handleClicked(QAbstractButton* button);

public slots:
	void onSaveSucceeded();
	void onSaveFailed(const ::QString& errorMessage);
	bool close();

signals:
	void updated(
		const std::chrono::hours& hrInWeek,
		const foundation::Days& dayInWeek,
		const foundation::Days& notifyDueWithin,
		const pecunia::currency::Iso4217Codes& preferred,
		const std::set<pecunia::currency::Iso4217Codes>& usable
	);
	/// @brief Triggered when the dialog is in the process of being closed.
	void closing();

public:
	ConfigureDialog(
		const std::chrono::hours& hrInWeek,
		const foundation::Days& dayInWeek,
		const foundation::Days& notifyDueWithin,
		const pecunia::currency::Iso4217Codes& preferred,
		const std::set<pecunia::currency::Iso4217Codes>& usable,
		const std::set<pecunia::currency::Iso4217Codes>& used,
		const foundation::ObserverPtr<::QWidget>& parent
	);
};

}}}

#endif
