1 /*
2  * ConfigManager.h - class ConfigManager, a class for managing LMMS-configuration
3  *
4  * Copyright (c) 2005-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5  *
6  * This file is part of LMMS - https://lmms.io
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this program (see COPYING); if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301 USA.
22  *
23  */
24 
25 
26 #ifndef CONFIG_MGR_H
27 #define CONFIG_MGR_H
28 
29 #include "lmmsconfig.h"
30 
31 #include <QtCore/QMap>
32 #include <QtCore/QPair>
33 #include <QtCore/QStringList>
34 #include <QtCore/QVector>
35 #include <QtCore/QObject>
36 
37 #include "export.h"
38 
39 class LmmsCore;
40 
41 
42 const QString PROJECTS_PATH = "projects/";
43 const QString TEMPLATE_PATH = "templates/";
44 const QString PRESETS_PATH = "presets/";
45 const QString SAMPLES_PATH = "samples/";
46 const QString GIG_PATH = "samples/gig/";
47 const QString SF2_PATH = "samples/soundfonts/";
48 const QString LADSPA_PATH ="plugins/ladspa/";
49 const QString DEFAULT_THEME_PATH = "themes/default/";
50 const QString TRACK_ICON_PATH = "track_icons/";
51 const QString LOCALE_PATH = "locale/";
52 
53 
54 class EXPORT ConfigManager : public QObject
55 {
56 	Q_OBJECT
57 public:
inst()58 	static inline ConfigManager * inst()
59 	{
60 		if( s_instanceOfMe == NULL )
61 		{
62 			s_instanceOfMe = new ConfigManager();
63 		}
64 		return s_instanceOfMe;
65 	}
66 
dataDir()67 	const QString & dataDir() const
68 	{
69 		return m_dataDir;
70 	}
71 
workingDir()72 	const QString & workingDir() const
73 	{
74 		return m_workingDir;
75 	}
76 
userProjectsDir()77 	QString userProjectsDir() const
78 	{
79 		return workingDir() + PROJECTS_PATH;
80 	}
81 
userTemplateDir()82 	QString userTemplateDir() const
83 	{
84 		return workingDir() + TEMPLATE_PATH;
85 	}
86 
userPresetsDir()87 	QString userPresetsDir() const
88 	{
89 		return workingDir() + PRESETS_PATH;
90 	}
91 
userSamplesDir()92 	QString userSamplesDir() const
93 	{
94 		return workingDir() + SAMPLES_PATH;
95 	}
96 
userGigDir()97 	QString userGigDir() const
98 	{
99 		return workingDir() + GIG_PATH;
100 	}
101 
userSf2Dir()102 	QString userSf2Dir() const
103 	{
104 		return workingDir() + SF2_PATH;
105 	}
106 
userLadspaDir()107 	QString userLadspaDir() const
108 	{
109 		return workingDir() + LADSPA_PATH;
110 	}
111 
userVstDir()112 	QString userVstDir() const
113 	{
114 		return m_vstDir;
115 	}
116 
factoryProjectsDir()117 	QString factoryProjectsDir() const
118 	{
119 		return dataDir() + PROJECTS_PATH;
120 	}
121 
factoryTemplatesDir()122 	QString factoryTemplatesDir() const
123 	{
124 		return factoryProjectsDir() + TEMPLATE_PATH;
125 	}
126 
factoryPresetsDir()127 	QString factoryPresetsDir() const
128 	{
129 		return dataDir() + PRESETS_PATH;
130 	}
131 
factorySamplesDir()132 	QString factorySamplesDir() const
133 	{
134 		return dataDir() + SAMPLES_PATH;
135 	}
136 
137 	QString defaultVersion() const;
138 
defaultArtworkDir()139 	QString defaultArtworkDir() const
140 	{
141 		return m_dataDir + DEFAULT_THEME_PATH;
142 	}
143 
artworkDir()144 	QString artworkDir() const
145 	{
146 		return m_artworkDir;
147 	}
148 
trackIconsDir()149 	QString trackIconsDir() const
150 	{
151 		return m_dataDir + TRACK_ICON_PATH;
152 	}
153 
localeDir()154 	QString localeDir() const
155 	{
156 		return m_dataDir + LOCALE_PATH;
157 	}
158 
gigDir()159 	const QString & gigDir() const
160 	{
161 		return m_gigDir;
162 	}
163 
sf2Dir()164 	const QString & sf2Dir() const
165 	{
166 		return m_sf2Dir;
167 	}
168 
vstDir()169 	const QString & vstDir() const
170 	{
171 		return m_vstDir;
172 	}
173 
ladspaDir()174 	const QString & ladspaDir() const
175 	{
176 		return m_ladDir;
177 	}
178 
recoveryFile()179 	const QString recoveryFile() const
180 	{
181 		return m_workingDir + "recover.mmp";
182 	}
183 
version()184 	const QString & version() const
185 	{
186 		return m_version;
187 	}
188 
189 #ifdef LMMS_HAVE_STK
stkDir()190 	const QString & stkDir() const
191 	{
192 		return m_stkDir;
193 	}
194 #endif
195 
196 #ifdef LMMS_HAVE_FLUIDSYNTH
defaultSoundfont()197 	const QString & defaultSoundfont() const
198 	{
199 		return m_defaultSoundfont;
200 	}
201 #endif
202 
backgroundArtwork()203 	const QString & backgroundArtwork() const
204 	{
205 		return m_backgroundArtwork;
206 	}
207 
recentlyOpenedProjects()208 	inline const QStringList & recentlyOpenedProjects() const
209 	{
210 		return m_recentlyOpenedProjects;
211 	}
212 
213 	static QStringList availabeVstEmbedMethods();
214 	QString vstEmbedMethod() const;
215 
216 	// returns true if the working dir (e.g. ~/lmms) exists on disk
217 	bool hasWorkingDir() const;
218 
219 	void addRecentlyOpenedProject( const QString & _file );
220 
221 	const QString & value( const QString & cls,
222 					const QString & attribute ) const;
223 	const QString & value( const QString & cls,
224 					const QString & attribute,
225 					const QString & defaultVal ) const;
226 	void setValue( const QString & cls, const QString & attribute,
227 						const QString & value );
228 	void deleteValue( const QString & cls, const QString & attribute);
229 
230 	void loadConfigFile( const QString & configFile = "" );
231 	void saveConfigFile();
232 
233 
234 	void setWorkingDir( const QString & _wd );
235 	void setVSTDir( const QString & _vd );
236 	void setArtworkDir( const QString & _ad );
237 	void setLADSPADir( const QString & _fd );
238 	void setVersion( const QString & _cv );
239 	void setSTKDir( const QString & _fd );
240 	void setDefaultSoundfont( const QString & _sf );
241 	void setBackgroundArtwork( const QString & _ba );
242 	void setGIGDir( const QString & gd );
243 	void setSF2Dir( const QString & sfd );
244 
245 	// creates the working directory & subdirectories on disk.
246 	void createWorkingDir();
247 
248 signals:
249 	void valueChanged( QString cls, QString attribute, QString value );
250 
251 private:
252 	static ConfigManager * s_instanceOfMe;
253 
254 	ConfigManager();
255 	ConfigManager( const ConfigManager & _c );
256 	~ConfigManager();
257 
258 	void upgrade_1_1_90();
259 	void upgrade_1_1_91();
260 	void upgrade();
261 
262 	QString m_lmmsRcFile;
263 	QString m_workingDir;
264 	QString m_dataDir;
265 	QString m_artworkDir;
266 	QString m_vstDir;
267 	QString m_ladDir;
268 	QString m_gigDir;
269 	QString m_sf2Dir;
270 	QString m_version;
271 #ifdef LMMS_HAVE_STK
272 	QString m_stkDir;
273 #endif
274 #ifdef LMMS_HAVE_FLUIDSYNTH
275 	QString m_defaultSoundfont;
276 #endif
277 	QString m_backgroundArtwork;
278 	QStringList m_recentlyOpenedProjects;
279 
280 	typedef QVector<QPair<QString, QString> > stringPairVector;
281 	typedef QMap<QString, stringPairVector> settingsMap;
282 	settingsMap m_settings;
283 
284 
285 	friend class LmmsCore;
286 
287 } ;
288 
289 #endif
290