ConfigManager.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. class LMMS_EXPORT ConfigManager : public QObject
  45. {
  46. Q_OBJECT
  47. public:
  48. static inline ConfigManager * inst()
  49. {
  50. if(s_instanceOfMe == NULL )
  51. {
  52. s_instanceOfMe = new ConfigManager();
  53. }
  54. return s_instanceOfMe;
  55. }
  56. const QString & workingDir() const
  57. {
  58. return m_workingDir;
  59. }
  60. const QString & dataDir() const
  61. {
  62. return m_dataDir;
  63. }
  64. QString factoryProjectsDir() const
  65. {
  66. return dataDir() + PROJECTS_PATH;
  67. }
  68. QString factoryTemplatesDir() const
  69. {
  70. return factoryProjectsDir() + TEMPLATE_PATH;
  71. }
  72. QString factoryPresetsDir() const
  73. {
  74. return dataDir() + PRESETS_PATH;
  75. }
  76. QString factorySamplesDir() const
  77. {
  78. return dataDir() + SAMPLES_PATH;
  79. }
  80. QString userProjectsDir() const
  81. {
  82. return workingDir() + PROJECTS_PATH;
  83. }
  84. QString userTemplateDir() const
  85. {
  86. return workingDir() + TEMPLATE_PATH;
  87. }
  88. QString userPresetsDir() const
  89. {
  90. return workingDir() + PRESETS_PATH;
  91. }
  92. QString userSamplesDir() const
  93. {
  94. return workingDir() + SAMPLES_PATH;
  95. }
  96. const QString & vstDir() const
  97. {
  98. return m_vstDir;
  99. }
  100. const QString & ladspaDir() const
  101. {
  102. return m_ladspaDir;
  103. }
  104. const QString & sf2Dir() const
  105. {
  106. return m_sf2Dir;
  107. }
  108. #ifdef LMMS_HAVE_FLUIDSYNTH
  109. const QString & sf2File() const
  110. {
  111. return m_sf2File;
  112. }
  113. #endif
  114. #ifdef LMMS_HAVE_STK
  115. const QString & stkDir() const
  116. {
  117. return m_stkDir;
  118. }
  119. #endif
  120. const QString & gigDir() const
  121. {
  122. return m_gigDir;
  123. }
  124. QString userVstDir() const
  125. {
  126. return m_vstDir;
  127. }
  128. QString userLadspaDir() const
  129. {
  130. return workingDir() + LADSPA_PATH;
  131. }
  132. QString userSf2Dir() const
  133. {
  134. return workingDir() + SF2_PATH;
  135. }
  136. QString userGigDir() const
  137. {
  138. return workingDir() + GIG_PATH;
  139. }
  140. QString defaultThemeDir() const
  141. {
  142. return m_dataDir + DEFAULT_THEME_PATH;
  143. }
  144. QString themeDir() const
  145. {
  146. return m_themeDir;
  147. }
  148. const QString & backgroundPicFile() const
  149. {
  150. return m_backgroundPicFile;
  151. }
  152. QString trackIconsDir() const
  153. {
  154. return m_dataDir + TRACK_ICON_PATH;
  155. }
  156. const QString recoveryFile() const
  157. {
  158. return m_workingDir + "recover.mmp";
  159. }
  160. inline const QStringList & recentlyOpenedProjects() const
  161. {
  162. return m_recentlyOpenedProjects;
  163. }
  164. QString localeDir() const
  165. {
  166. return m_dataDir + LOCALE_PATH;
  167. }
  168. const QString & version() const
  169. {
  170. return m_version;
  171. }
  172. QString defaultVersion() const;
  173. static QStringList availabeVstEmbedMethods();
  174. QString vstEmbedMethod() const;
  175. // Returns true if the working dir (e.g. ~/lmms) exists on disk.
  176. bool hasWorkingDir() const;
  177. void addRecentlyOpenedProject(const QString & _file);
  178. const QString & value(const QString & cls,
  179. const QString & attribute) const;
  180. const QString & value(const QString & cls,
  181. const QString & attribute,
  182. const QString & defaultVal) const;
  183. void setValue(const QString & cls, const QString & attribute,
  184. const QString & value);
  185. void deleteValue(const QString & cls, const QString & attribute);
  186. void loadConfigFile(const QString & configFile = "");
  187. void saveConfigFile();
  188. void setWorkingDir(const QString & workingDir);
  189. void setVSTDir(const QString & vstDir);
  190. void setLADSPADir(const QString & ladspaDir);
  191. void setSF2Dir(const QString & sf2Dir);
  192. void setSF2File(const QString & sf2File);
  193. void setSTKDir(const QString & stkDir);
  194. void setGIGDir(const QString & gigDir);
  195. void setThemeDir(const QString & themeDir);
  196. void setBackgroundPicFile(const QString & backgroundPicFile);
  197. // Creates the working directory & subdirectories on disk.
  198. void createWorkingDir();
  199. signals:
  200. void valueChanged( QString cls, QString attribute, QString value );
  201. private:
  202. static ConfigManager * s_instanceOfMe;
  203. ConfigManager();
  204. ConfigManager(const ConfigManager & _c);
  205. ~ConfigManager();
  206. void upgrade_1_1_90();
  207. void upgrade_1_1_91();
  208. void upgrade();
  209. QString m_workingDir;
  210. QString m_dataDir;
  211. QString m_vstDir;
  212. QString m_ladspaDir;
  213. QString m_sf2Dir;
  214. #ifdef LMMS_HAVE_FLUIDSYNTH
  215. QString m_sf2File;
  216. #endif
  217. #ifdef LMMS_HAVE_STK
  218. QString m_stkDir;
  219. #endif
  220. QString m_gigDir;
  221. QString m_themeDir;
  222. QString m_backgroundPicFile;
  223. QString m_lmmsRcFile;
  224. QString m_version;
  225. QStringList m_recentlyOpenedProjects;
  226. typedef QVector<QPair<QString, QString> > stringPairVector;
  227. typedef QMap<QString, stringPairVector> settingsMap;
  228. settingsMap m_settings;
  229. friend class LmmsCore;
  230. };
  231. #endif