ctkPluginFrameworkProperties.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkPluginFrameworkProperties_p.h"
  16. #include "ctkPluginFrameworkLauncher.h"
  17. #include <QDir>
  18. #include <QCoreApplication>
  19. QMutex ctkPluginFrameworkProperties::lock;
  20. ctkProperties ctkPluginFrameworkProperties::properties;
  21. //----------------------------------------------------------------------------
  22. ctkProperties& ctkPluginFrameworkProperties::getProperties()
  23. {
  24. return properties;
  25. }
  26. //----------------------------------------------------------------------------
  27. QVariant ctkPluginFrameworkProperties::getProperty(const QString& key)
  28. {
  29. return getProperty(key, QVariant());
  30. }
  31. //----------------------------------------------------------------------------
  32. QVariant ctkPluginFrameworkProperties::getProperty(const QString& key, const QVariant& defaultValue)
  33. {
  34. QMutexLocker l(&lock);
  35. ctkProperties::iterator iter = properties.find(key);
  36. if (iter != properties.end()) return iter.value();
  37. return defaultValue;
  38. }
  39. //----------------------------------------------------------------------------
  40. QVariant ctkPluginFrameworkProperties::setProperty(const QString& key, const QVariant& value)
  41. {
  42. QMutexLocker l(&lock);
  43. QVariant oldVal = properties[key];
  44. properties[key] = value;
  45. return oldVal;
  46. }
  47. //----------------------------------------------------------------------------
  48. QVariant ctkPluginFrameworkProperties::clearProperty(const QString& key)
  49. {
  50. QMutexLocker l(&lock);
  51. return properties.take(key);
  52. }
  53. //----------------------------------------------------------------------------
  54. void ctkPluginFrameworkProperties::setProperties(const ctkProperties& input)
  55. {
  56. QMutexLocker l(&lock);
  57. properties = input;
  58. }
  59. //----------------------------------------------------------------------------
  60. void ctkPluginFrameworkProperties::initializeProperties()
  61. {
  62. // initialize some framework properties that must always be set
  63. setProperty(ctkPluginFrameworkLauncher::PROP_USER_HOME, QDir::homePath());
  64. setProperty(ctkPluginFrameworkLauncher::PROP_USER_DIR, QDir::currentPath());
  65. if (getProperty(ctkPluginFrameworkLauncher::PROP_INSTALL_AREA).isNull())
  66. {
  67. setProperty(ctkPluginFrameworkLauncher::PROP_INSTALL_AREA, QCoreApplication::applicationDirPath());
  68. }
  69. }