ConfigManager.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. #ifndef CONFIG_MGR_H
  25. #define CONFIG_MGR_H
  26. #include "lmmsconfig.h"
  27. #include <QtCore/QMap>
  28. #include <QtCore/QPair>
  29. #include <QtCore/QStringList>
  30. #include <QtCore/QVector>
  31. #include <QtCore/QObject>
  32. #include "lmms_export.h"
  33. class LmmsCore;
  34. const QString PROJECTS_PATH = "projects/";
  35. const QString TEMPLATE_PATH = "templates/";
  36. const QString PRESETS_PATH = "presets/";
  37. const QString SAMPLES_PATH = "samples/";
  38. const QString GIG_PATH = "samples/gig/";
  39. const QString SF2_PATH = "samples/soundfonts/";
  40. const QString LADSPA_PATH ="plugins/ladspa/";
  41. const QString DEFAULT_THEME_PATH = "themes/default/";
  42. const QString TRACK_ICON_PATH = "track_icons/";
  43. const QString LOCALE_PATH = "locale/";
  44. const QString PORTABLE_MODE_FILE = "/portable_mode.txt";
  45. class LMMS_EXPORT ConfigManager : public QObject
  46. {
  47. Q_OBJECT
  48. using UpgradeMethod = void(ConfigManager::*)();
  49. public:
  50. static inline ConfigManager * inst()
  51. {
  52. if(s_instanceOfMe == nullptr )
  53. {
  54. s_instanceOfMe = new ConfigManager();
  55. }
  56. return s_instanceOfMe;
  57. }
  58. const QString & workingDir() const
  59. {
  60. return m_workingDir;
  61. }
  62. void initPortableWorkingDir();
  63. void initInstalledWorkingDir();
  64. void initDevelopmentWorkingDir();
  65. const QString & dataDir() const
  66. {
  67. return m_dataDir;
  68. }
  69. QString factoryProjectsDir() const
  70. {
  71. return dataDir() + PROJECTS_PATH;
  72. }
  73. QString factoryTemplatesDir() const
  74. {
  75. return factoryProjectsDir() + TEMPLATE_PATH;
  76. }
  77. QString factoryPresetsDir() const
  78. {
  79. return dataDir() + PRESETS_PATH;
  80. }
  81. QString factorySamplesDir() const
  82. {
  83. return dataDir() + SAMPLES_PATH;
  84. }
  85. QString userProjectsDir() const
  86. {
  87. return workingDir() + PROJECTS_PATH;
  88. }
  89. QString userTemplateDir() const
  90. {
  91. return workingDir() + TEMPLATE_PATH;
  92. }
  93. QString userPresetsDir() const
  94. {
  95. return workingDir() + PRESETS_PATH;
  96. }
  97. QString userSamplesDir() const
  98. {
  99. return workingDir() + SAMPLES_PATH;
  100. }
  101. const QString & vstDir() const
  102. {
  103. return m_vstDir;
  104. }
  105. const QString & ladspaDir() const
  106. {
  107. return m_ladspaDir;
  108. }
  109. const QString & sf2Dir() const
  110. {
  111. return m_sf2Dir;
  112. }
  113. #ifdef LMMS_HAVE_FLUIDSYNTH
  114. const QString & sf2File() const
  115. {
  116. return m_sf2File;
  117. }
  118. #endif
  119. #ifdef LMMS_HAVE_STK
  120. const QString & stkDir() const
  121. {
  122. return m_stkDir;
  123. }
  124. #endif
  125. const QString & gigDir() const
  126. {
  127. return m_gigDir;
  128. }
  129. QString userVstDir() const
  130. {
  131. return m_vstDir;
  132. }
  133. QString userLadspaDir() const
  134. {
  135. return workingDir() + LADSPA_PATH;
  136. }
  137. QString userSf2Dir() const
  138. {
  139. return workingDir() + SF2_PATH;
  140. }
  141. QString userGigDir() const
  142. {
  143. return workingDir() + GIG_PATH;
  144. }
  145. QString defaultThemeDir() const
  146. {
  147. return m_dataDir + DEFAULT_THEME_PATH;
  148. }
  149. QString themeDir() const
  150. {
  151. return m_themeDir;
  152. }
  153. const QString & backgroundPicFile() const
  154. {
  155. return m_backgroundPicFile;
  156. }
  157. QString trackIconsDir() const
  158. {
  159. return m_dataDir + TRACK_ICON_PATH;
  160. }
  161. const QString recoveryFile() const
  162. {
  163. return m_workingDir + "recover.mmp";
  164. }
  165. inline const QStringList & recentlyOpenedProjects() const
  166. {
  167. return m_recentlyOpenedProjects;
  168. }
  169. QString localeDir() const
  170. {
  171. return m_dataDir + LOCALE_PATH;
  172. }
  173. const QString & version() const
  174. {
  175. return m_version;
  176. }
  177. // Used when the configversion attribute is not present in a configuration file.
  178. // Returns the appropriate config file version based on the LMMS version.
  179. unsigned int legacyConfigVersion();
  180. QString defaultVersion() const;
  181. static QStringList availableVstEmbedMethods();
  182. QString vstEmbedMethod() const;
  183. // Returns true if the working dir (e.g. ~/lmms) exists on disk.
  184. bool hasWorkingDir() const;
  185. void addRecentlyOpenedProject(const QString & _file);
  186. const QString & value(const QString & cls,
  187. const QString & attribute) const;
  188. const QString & value(const QString & cls,
  189. const QString & attribute,
  190. const QString & defaultVal) const;
  191. void setValue(const QString & cls, const QString & attribute,
  192. const QString & value);
  193. void deleteValue(const QString & cls, const QString & attribute);
  194. void loadConfigFile(const QString & configFile = "");
  195. void saveConfigFile();
  196. void setWorkingDir(const QString & workingDir);
  197. void setVSTDir(const QString & vstDir);
  198. void setLADSPADir(const QString & ladspaDir);
  199. void setSF2Dir(const QString & sf2Dir);
  200. void setSF2File(const QString & sf2File);
  201. void setSTKDir(const QString & stkDir);
  202. void setGIGDir(const QString & gigDir);
  203. void setThemeDir(const QString & themeDir);
  204. void setBackgroundPicFile(const QString & backgroundPicFile);
  205. // Creates the working directory & subdirectories on disk.
  206. void createWorkingDir();
  207. signals:
  208. void valueChanged( QString cls, QString attribute, QString value );
  209. private:
  210. static ConfigManager * s_instanceOfMe;
  211. ConfigManager();
  212. ConfigManager(const ConfigManager & _c);
  213. ~ConfigManager();
  214. void upgrade_1_1_90();
  215. void upgrade_1_1_91();
  216. void upgrade_1_2_2();
  217. void upgrade();
  218. // List of all upgrade methods
  219. static const std::vector<UpgradeMethod> UPGRADE_METHODS;
  220. QString m_workingDir;
  221. QString m_dataDir;
  222. QString m_vstDir;
  223. QString m_ladspaDir;
  224. QString m_sf2Dir;
  225. #ifdef LMMS_HAVE_FLUIDSYNTH
  226. QString m_sf2File;
  227. #endif
  228. #ifdef LMMS_HAVE_STK
  229. QString m_stkDir;
  230. #endif
  231. QString m_gigDir;
  232. QString m_themeDir;
  233. QString m_backgroundPicFile;
  234. QString m_lmmsRcFile;
  235. QString m_version;
  236. unsigned int m_configVersion;
  237. QStringList m_recentlyOpenedProjects;
  238. typedef QVector<QPair<QString, QString> > stringPairVector;
  239. typedef QMap<QString, stringPairVector> settingsMap;
  240. settingsMap m_settings;
  241. friend class LmmsCore;
  242. };
  243. #endif