
//  Copyright (C) 2009 by Arnaud Dupuis
//  a.dupuis@infinityperl.org
//  http://www.infinityperl.org
// 
//  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, write to the
//  Free Software Foundation, Inc.,
//  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA

#ifndef ASSUMAASSOCIATIONSETTINGS_H
#define ASSUMAASSOCIATIONSETTINGS_H

#include <QWidget>
#include "ui_assuma_associationsettings.h"
#include "assuma_configmanager.h"

class AssumaEffect;
class AssumaCustomWidgetBase;

/*! \class AssumaAssociationSettings
* \brief The association configuration widget.
*
* This class is used to edit settings of an association.
*/
class AssumaAssociationSettings : public QWidget, public Ui::AssumaAssociationSettings{
	Q_OBJECT
	public:
		/*! Constructor
		\param parent the parent widget
		*/
		AssumaAssociationSettings(QWidget *parent = 0);
		/*! Returns the current custom fields file name.
		\return the custom field file name currently used.
		*/
		QString getCustomFieldFileName();
		int getMaxCoursesPerWeek(QString);
		QMap<QString, QStringList> getCoursesLessonsNumberData();
		QStringList getCoursesList();
		QString getCourseFee( QString , int );
		void updateTranslation();
	public slots:
		/*!
		Load the theme passed as argument.
		If no argument is provided, the "default" theme is loaded.
		\warning please note that the theme name provided must refers to a directory into the themes/ directory.
		\param themeName the name of the theme.
		*/
		void loadTheme( const QString & themeName = "default" );
		/*! Save custom fields presents in the AssumaAssociationSettings widget into a XML file.
		\param fileName the name of the XML file to save the custom fields into. If no argument is provided, the value of getCustomFieldFileName() is used.
		\sa getCustomFieldFileName() setCustomFieldFileName
		*/
		void saveCustomFields( const QString & fileName = "" );
		/*! Sets the current custom fields file name.
		\param fileName the name of the custom fields file name.
		*/
		void setCustomFieldsFileName(const QString &);
		/*!
		\todo write documentation for the updateTranslations() slot.
		*/
		void updateTranslations();
		/*!
		\todo write documentation for the addActivity(const QString) slot.
		*/
		void addActivity(const QString );
	signals:
		void customFieldsChanged();
	private:
		// Variables
		AssumaEffect *m_booleanBoxEffect;
		AssumaCustomWidgetBase *m_previewWidget;
		QString m_customFieldsFileName;
		bool m_saveOnChange;
		// Methods
		QString escapeXml( const QString & );
		bool saveCurrentFederation();
		QStringList listWidgetToStringList( QListWidget * );
		QTreeWidget* currentCoursesTreeWidget();
		QTreeWidget* coursesTreeWidget(int);
		QString serializeCourses();
		QString serializeContacts();
	private slots:
		void updateConfiguration( AssumaConfigManager::Token, const QVariant & );
		void on_removeFieldPushButton_clicked();
		void on_removeValuePushButton_clicked();
		void on_fieldTypeComboBox_currentIndexChanged(const QString &);
		void on_addFieldPushButton_clicked();
		void updatePreviewFromFields();
		void on_fieldTypeLineEdit_textChanged( const QString & );
		void on_customFieldsTable_cellClicked ( int, int );
		void on_addValuePushButton_clicked();
		void updatePreview( const QString &, const QString &, const QStringList & );
		void on_customFieldsTable_itemChanged ( QTableWidgetItem * );
		void on_trimesterSpinBox_valueChanged(int);
		void on_taxSpinBox_valueChanged(int);
		void on_AssociationNameLineEdit_textChanged( const QString & );
		
		// Start Federation editor's slots
		void on_saveFederationPushButton_clicked();
		void on_removeLicensePushButton_clicked();
		void on_addLicensePushButton_clicked();
		void on_federationComboBox_currentIndexChanged ( const QString &  );
		// Stop Federation editor's slots
		
		// Start Fee management's slot
		void on_removeCurrentFeeCancelButton_clicked();
		void on_removeCurrentFeeConfirmButton_clicked();
		void on_removeFeeButton_clicked();
		void on_addFeeCancelButton_clicked();
		void on_addFeeAddButton_clicked();
		void on_addFeeButton_clicked();
		// Stop Fee management's slot
		
		// Start activity's slot
		void on_removeCurrentActivityConfirmButton_clicked();
		void on_removeCurrentActivityCancelButton_clicked();
		void on_removeActivityButton_clicked();
		void on_addActivityCancelButton_clicked();
		void on_addActivityAddButton_clicked();
		void on_addActivityButton_clicked();
		// Stop activity's slot
		
		// Start contact's slot
		void on_removeEmailConfirmPushButton_clicked();
		void on_removeEmailCancelPushButton_clicked();
		void on_addEmailAddPushButton_clicked();
		void on_addEmailCancelPushButton_clicked();
		void on_removeEmailPushButton_clicked();
		void on_addEmailPushButton_clicked();
		// Stop contact's slot
};

#endif
