1 /*
2  * Part of WCM Commander
3  * https://github.com/corporateshark/WCMCommander
4  * wcm@linderdaum.com
5  */
6 
7 #pragma once
8 
9 #include "ncdialogs.h"
10 
11 #include <string>
12 
13 class NCWin;
14 
15 
16 class IniHash
17 {
18 private:
19 	cstrhash< cstrhash< std::string > > hash;
20 	std::string* Find( const char* section, const char* var );
21 	std::string* Create( const char* section, const char* var );
22 	void Delete( const char* section, const char* var );
23 
24 public:
IniHash()25 	IniHash() { }
~IniHash()26 	~IniHash() { }
27 
28 	void SetStrValue( const char* section, const char* var, const char* value );
29 	void SetIntValue( const char* section, const char* var, int value );
30 	void SetBoolValue( const char* section, const char* var, bool value );
31 	const char* GetStrValue( const char* section, const char* var, const char* def );
32 	int GetIntValue( const char* section, const char* var, int def );
33 	bool GetBoolValue( const char* section, const char* var, bool def );
34 
Clear()35 	void Clear()
36 	{
37 		hash.clear();
38 	}
39 
Size()40 	int Size() const
41 	{
42 		return hash.count();
43 	}
44 
Keys()45 	std::vector<const char*> Keys()
46 	{
47 		 return hash.keys();
48 	}
49 
Exist(const char * key)50 	cstrhash<std::string>* Exist( const char* key)
51 	{
52 		 return hash.exist( key );
53 	}
54 };
55 
56 void IniHashLoad( IniHash& iniHash, const char* sectName );
57 void IniHashSave( IniHash& iniHash, const char* sectName );
58 
59 
60 enum ePanelSpacesMode
61 {
62 	ePanelSpacesMode_None = 0,
63 	ePanelSpacesMode_All = 1,
64 	ePanelSpacesMode_Trailing = 2
65 };
66 
67 class clWcmConfig
68 {
69 private:
70 	enum eMapType { MT_BOOL, MT_INT, MT_STR };
71 	/// no need to make this polymorphic type
72 	struct sNode
73 	{
sNodesNode74 		sNode()
75 			: m_Type( MT_INT )
76 			, m_Section( NULL )
77 			, m_Name( NULL )
78 			, m_Current()
79 			, m_Default()
80 		{}
sNodesNode81 		sNode( eMapType Type, const char* Section, const char* Name )
82 			: m_Type( Type )
83 			, m_Section( Section )
84 			, m_Name( Name )
85 			, m_Current()
86 			, m_Default()
87 		{}
88 		eMapType    m_Type;
89 		const char* m_Section;
90 		const char* m_Name;
91 		/// holds a pointer to the currently valid value
92 		union
93 		{
94 			int* m_Int;
95 			bool* m_Bool;
96 			std::string* m_Str;
97 		} m_Current;
98 
GetDefaultIntsNode99 		int GetDefaultInt() const { return m_Default.m_Int; }
GetDefaultBoolsNode100 		bool GetDefaultBool() const { return m_Default.m_Bool; }
GetDefaultStrsNode101 		const char* GetDefaultStr() const { return m_Default.m_Str; }
102 
GetCurrentIntsNode103 		int GetCurrentInt() const { return m_Current.m_Int ? *m_Current.m_Int : 0; }
GetCurrentBoolsNode104 		bool GetCurrentBool() const { return m_Current.m_Bool ? *m_Current.m_Bool : false; }
GetCurrentStrsNode105 		const char* GetCurrentStr() const { return m_Current.m_Str ? m_Current.m_Str->data() : NULL; }
106 
CreateIntNodesNode107 		static sNode CreateIntNode( const char* Section, const char* Name, int* pInt, int DefaultValue )
108 		{
109 			sNode N( MT_INT, Section, Name );
110 			N.m_Current.m_Int = pInt;
111 			N.m_Default.m_Int = DefaultValue;
112 			return N;
113 		}
CreateBoolNodesNode114 		static sNode CreateBoolNode( const char* Section, const char* Name, bool* pBool, bool DefaultValue )
115 		{
116 			sNode N( MT_BOOL, Section, Name );
117 			N.m_Current.m_Bool = pBool;
118 			N.m_Default.m_Bool = DefaultValue;
119 			return N;
120 		}
CreateStrNodesNode121 		static sNode CreateStrNode( const char* Section, const char* Name, std::string* pStr, const char* DefaultValue )
122 		{
123 			sNode N( MT_STR, Section, Name );
124 			N.m_Current.m_Str = pStr;
125 			N.m_Default.m_Str = DefaultValue;
126 			return N;
127 		}
128 
129 	private:
130 		/// default value
131 		union
132 		{
133 			int m_Int;
134 			bool m_Bool;
135 			const char* m_Str;
136 		} m_Default;
137 	};
138 
139 public:
140 
141 	#pragma region System settings
142 	bool systemAskOpenExec;
143 	bool systemEscPanel;
144 	bool systemEscCommandLine;
145 	bool systemBackSpaceUpDir;
146 	bool systemAutoComplete;
147 	bool systemAutoSaveSetup;
148 	bool systemShowHostName;
149 	bool systemStorePasswords;
150 	std::string systemLang; //"+" - auto "-" -internal eng.
151 	#pragma endregion
152 
153 	#pragma region Panel settings
154 	bool panelShowHiddenFiles;
155 	bool panelCaseSensitive;
156 	bool panelSelectFolders;
157 	bool panelShowDotsInRoot;
158 	bool panelShowFolderIcons;
159 	bool panelShowExecutableIcons;
160 	bool panelShowLinkIcons;
161 	bool panelShowScrollbar;
162 	ePanelSpacesMode panelShowSpacesMode;
163 	int panelModeLeft;
164 	int panelModeRight;
165 	#pragma endregion
166 
167 	#pragma region Editor settings
168 	bool editSavePos;
169 	bool editAutoIdent;
170 	int editTabSize;
171 	bool editShl;
172 	bool editClearHistoryAfterSaving;
173 	#pragma endregion
174 
175 	#pragma region Terminal settings
176 	int terminalBackspaceKey;
177 	#pragma endregion
178 
179 	#pragma region Style settings
180 	bool styleShow3DUI;
181 	std::string styleColorTheme;
182 	bool styleShowToolBar;
183 	bool styleShowButtonBar;
184 	bool styleShowButtonBarIcons;
185 	bool styleShowMenuBar;
186 	#pragma endregion
187 
188 	#pragma region Window position and size to be restored on the next startup
189 	int windowX;
190 	int windowY;
191 	int windowWidth;
192 	int windowHeight;
193 	#pragma endregion
194 
195 	#pragma region Fonts
196 	std::string panelFontUri;
197 	std::string viewerFontUri;
198 	std::string editorFontUri;
199 	std::string dialogFontUri;
200 	std::string terminalFontUri;
201 	std::string helpTextFontUri;
202 	std::string helpBoldFontUri;
203 	std::string helpHeadFontUri;
204 
205 	/// store properties of the currently active fonts in ...Uri fields
206 	void ImpCurrentFonts();
207 	#pragma endregion
208 
209 	#pragma region Paths of the panels to be restored on the next startup
210 	std::string leftPanelPath;
211 	std::string rightPanelPath;
212 	#pragma endregion
213 
214 	clWcmConfig();
215 	void Load( NCWin* nc, const std::string& StartupDir );
216 	void Save( NCWin* nc );
217 
218 private:
219 	void MapInt( const char* Section, const char* Name, int* pInt, int DefaultValue );
220 	void MapBool( const char* Section, const char* Name, bool* pInt, bool DefaultValue );
221 	void MapStr( const char* Section, const char* Name, std::string* pStr, const char* DefaultValue = NULL );
222 
223 private:
224 	std::vector<sNode> m_MapList;
225 };
226 
227 void InitConfigPath();
228 
229 bool DoPanelConfigDialog( NCDialogParent* parent );
230 bool DoEditConfigDialog( NCDialogParent* parent );
231 bool DoStyleConfigDialog( NCDialogParent* parent );
232 bool DoSystemConfigDialog( NCDialogParent* parent );
233 bool DoTerminalConfigDialog( NCDialogParent* parent );
234 
235 bool LoadStringList( const char* section, std::vector< std::string >& list );
236 void SaveStringList( const char* section, std::vector< std::string >& list );
237