ConfigManager.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 "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 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 & dataDir() const
  57. {
  58. return m_dataDir;
  59. }
  60. const QString & workingDir() const
  61. {
  62. return m_workingDir;
  63. }
  64. QString userProjectsDir() const
  65. {
  66. return workingDir() + PROJECTS_PATH;
  67. }
  68. QString userTemplateDir() const
  69. {
  70. return workingDir() + TEMPLATE_PATH;
  71. }
  72. QString userPresetsDir() const
  73. {
  74. return workingDir() + PRESETS_PATH;
  75. }
  76. QString userSamplesDir() const
  77. {
  78. return workingDir() + SAMPLES_PATH;
  79. }
  80. QString userGigDir() const
  81. {
  82. return workingDir() + GIG_PATH;
  83. }
  84. QString userSf2Dir() const
  85. {
  86. return workingDir() + SF2_PATH;
  87. }
  88. QString userLadspaDir() const
  89. {
  90. return workingDir() + LADSPA_PATH;
  91. }
  92. QString userVstDir() const
  93. {
  94. return m_vstDir;
  95. }
  96. QString factoryProjectsDir() const
  97. {
  98. return dataDir() + PROJECTS_PATH;
  99. }
  100. QString factoryTemplatesDir() const
  101. {
  102. return factoryProjectsDir() + TEMPLATE_PATH;
  103. }
  104. QString factoryPresetsDir() const
  105. {
  106. return dataDir() + PRESETS_PATH;
  107. }
  108. QString factorySamplesDir() const
  109. {
  110. return dataDir() + SAMPLES_PATH;
  111. }
  112. QString defaultVersion() const;
  113. QString defaultArtworkDir() const
  114. {
  115. return m_dataDir + DEFAULT_THEME_PATH;
  116. }
  117. QString artworkDir() const
  118. {
  119. return m_artworkDir;
  120. }
  121. QString trackIconsDir() const
  122. {
  123. return m_dataDir + TRACK_ICON_PATH;
  124. }
  125. QString localeDir() const
  126. {
  127. return m_dataDir + LOCALE_PATH;
  128. }
  129. const QString & gigDir() const
  130. {
  131. return m_gigDir;
  132. }
  133. const QString & sf2Dir() const
  134. {
  135. return m_sf2Dir;
  136. }
  137. const QString & vstDir() const
  138. {
  139. return m_vstDir;
  140. }
  141. const QString & ladspaDir() const
  142. {
  143. return m_ladDir;
  144. }
  145. const QString recoveryFile() const
  146. {
  147. return m_workingDir + "recover.mmp";
  148. }
  149. const QString & version() const
  150. {
  151. return m_version;
  152. }
  153. #ifdef LMMS_HAVE_STK
  154. const QString & stkDir() const
  155. {
  156. return m_stkDir;
  157. }
  158. #endif
  159. #ifdef LMMS_HAVE_FLUIDSYNTH
  160. const QString & defaultSoundfont() const
  161. {
  162. return m_defaultSoundfont;
  163. }
  164. #endif
  165. const QString & backgroundArtwork() const
  166. {
  167. return m_backgroundArtwork;
  168. }
  169. inline const QStringList & recentlyOpenedProjects() const
  170. {
  171. return m_recentlyOpenedProjects;
  172. }
  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 & _wd );
  189. void setVSTDir( const QString & _vd );
  190. void setArtworkDir( const QString & _ad );
  191. void setLADSPADir( const QString & _fd );
  192. void setVersion( const QString & _cv );
  193. void setSTKDir( const QString & _fd );
  194. void setDefaultSoundfont( const QString & _sf );
  195. void setBackgroundArtwork( const QString & _ba );
  196. void setGIGDir( const QString & gd );
  197. void setSF2Dir( const QString & sfd );
  198. // creates the working directory & subdirectories on disk.
  199. void createWorkingDir();
  200. signals:
  201. void valueChanged( QString cls, QString attribute, QString value );
  202. private:
  203. static ConfigManager * s_instanceOfMe;
  204. ConfigManager();
  205. ConfigManager( const ConfigManager & _c );
  206. ~ConfigManager();
  207. void upgrade_1_1_90();
  208. void upgrade_1_1_91();
  209. void upgrade();
  210. QString m_lmmsRcFile;
  211. QString m_workingDir;
  212. QString m_dataDir;
  213. QString m_artworkDir;
  214. QString m_vstDir;
  215. QString m_ladDir;
  216. QString m_gigDir;
  217. QString m_sf2Dir;
  218. QString m_version;
  219. #ifdef LMMS_HAVE_STK
  220. QString m_stkDir;
  221. #endif
  222. #ifdef LMMS_HAVE_FLUIDSYNTH
  223. QString m_defaultSoundfont;
  224. #endif
  225. QString m_backgroundArtwork;
  226. QStringList m_recentlyOpenedProjects;
  227. typedef QVector<QPair<QString, QString> > stringPairVector;
  228. typedef QMap<QString, stringPairVector> settingsMap;
  229. settingsMap m_settings;
  230. friend class LmmsCore;
  231. } ;
  232. #endif