summaryrefslogtreecommitdiff
path: root/OptionEngine.h
blob: 960553567cc7110d4338724f66ea3eac6783241b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/** \file OptionEngine.h
\brief Define the class of the option engine
\author alpha_one_x86
\version 0.3
\date 2010
\licence GPL3, see the file COPYING */

#ifndef OPTION_ENGINE_H
#define OPTION_ENGINE_H

#include <QDialog>
#include <QList>
#include <QSettings>
#include <QFormLayout>
#include <QLayout>
#include <QStringList>
#include <QFormLayout>
#include <QCheckBox>
#include <QComboBox>
#include <QSpinBox>
#include <QAbstractButton>
#include <QTimer>
#include <QWidget>

#include "interface/OptionInterface.h"

#include "Environment.h"
#include "Singleton.h"
#include "ResourcesManager.h"

/** \brief To store the options

  That's allow to have mutualised way to store the options. Then the plugins just keep Ultracopier manage it, the portable version will store on the disk near the application, and the normal version will keep at the normal location.
  That's allow to have cache and buffer to not slow down Ultracopier when it's doing heavy copy/move.
*/
class OptionEngine : public QObject, public Singleton<OptionEngine>
{
	Q_OBJECT
	//class OptionEngine : public OptionInterface, public QDialog, public Singleton<OptionEngine>
	friend class Singleton<OptionEngine>;
	public:
		/// \brief To add option group to options
		bool addOptionGroup(const QString &groupName,const QList<QPair<QString, QVariant> > &KeysList);
		/// \brief To remove option group to options, remove the widget need be do into the calling object
		bool removeOptionGroup(const QString &groupName);
		/// \brief To get option value
		QVariant getOptionValue(const QString &groupName,const QString &variableName);
		/// \brief To set option value
		void setOptionValue(const QString &groupName,const QString &variableName,const QVariant &value);
		/// \brief To invalid option value
		//void setInvalidOptionValue(const QString &groupName,const QString &variableName);
		/// \brief get query reset options
		void queryResetOptions();
	private:
		/// \brief Initiate the option, load from backend
		OptionEngine();
		/// \brief Destroy the option
		~OptionEngine();

		/// \brief OptionEngineGroupKey then: Group -> Key
		struct OptionEngineGroupKey
		{
			QString variableName;
			QVariant defaultValue;
			QVariant currentValue;
			bool emptyList;
		};
		/// \brief OptionEngineGroup then: Group
		struct OptionEngineGroup
		{
			QString groupName;
			QList<OptionEngineGroupKey> KeysList;
		};

		/// \brief store the option group list
		QList<OptionEngineGroup> GroupKeysList;
		QStringList unmanagedTabName;
		/// \brief Enumeration of backend
		enum Backend
		{
			Memory,		//Do intensive usage of memory, used only if the file backend is not available
			File		//Store all directly into file
		};
		/// \brief The current backend
		Backend currentBackend;
		/// \brief To store QSettings for the backend
		QSettings *settings;
		#ifdef ULTRACOPIER_VERSION_PORTABLE
		ResourcesManager *resources;
		#endif // ULTRACOPIER_VERSION_PORTABLE
		//the reset of right value of widget need be do into the calling object
		void internal_resetToDefaultValue();
		//temp variable
		int loop_size,loop_sub_size,indexGroup,indexGroupKey,index;
	signals:
		void newOptionValue(const QString&,const QString&,const QVariant&);
		void resetOptions();
};

#endif // OPTION_ENGINE_H