The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. ApplicationProperties::ApplicationProperties()
  19. : commonSettingsAreReadOnly (0)
  20. {
  21. }
  22. ApplicationProperties::~ApplicationProperties()
  23. {
  24. closeFiles();
  25. }
  26. //==============================================================================
  27. void ApplicationProperties::setStorageParameters (const PropertiesFile::Options& newOptions)
  28. {
  29. options = newOptions;
  30. }
  31. //==============================================================================
  32. void ApplicationProperties::openFiles()
  33. {
  34. // You need to call setStorageParameters() before trying to get hold of the properties!
  35. jassert (options.applicationName.isNotEmpty());
  36. if (options.applicationName.isNotEmpty())
  37. {
  38. PropertiesFile::Options o (options);
  39. if (userProps == nullptr)
  40. {
  41. o.commonToAllUsers = false;
  42. userProps = new PropertiesFile (o);
  43. }
  44. if (commonProps == nullptr)
  45. {
  46. o.commonToAllUsers = true;
  47. commonProps = new PropertiesFile (o);
  48. }
  49. userProps->setFallbackPropertySet (commonProps);
  50. }
  51. }
  52. PropertiesFile* ApplicationProperties::getUserSettings()
  53. {
  54. if (userProps == nullptr)
  55. openFiles();
  56. return userProps;
  57. }
  58. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly)
  59. {
  60. if (commonProps == nullptr)
  61. openFiles();
  62. if (returnUserPropsIfReadOnly)
  63. {
  64. if (commonSettingsAreReadOnly == 0)
  65. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  66. if (commonSettingsAreReadOnly > 0)
  67. return userProps;
  68. }
  69. return commonProps;
  70. }
  71. bool ApplicationProperties::saveIfNeeded()
  72. {
  73. return (userProps == nullptr || userProps->saveIfNeeded())
  74. && (commonProps == nullptr || commonProps->saveIfNeeded());
  75. }
  76. void ApplicationProperties::closeFiles()
  77. {
  78. userProps = nullptr;
  79. commonProps = nullptr;
  80. }