ctkPluginArchive.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 "ctkPluginArchive_p.h"
  16. #include "ctkPluginException.h"
  17. #include "ctkPluginStorage_p.h"
  18. #include <QStringList>
  19. #include <QFile>
  20. const QString ctkPluginArchive::AUTOSTART_SETTING_STOPPED("stopped");
  21. const QString ctkPluginArchive::AUTOSTART_SETTING_EAGER("eager");
  22. const QString ctkPluginArchive::AUTOSTART_SETTING_ACTIVATION_POLICY("activation_policy");
  23. //----------------------------------------------------------------------------
  24. ctkPluginArchive::ctkPluginArchive(ctkPluginStorage* pluginStorage,
  25. const QUrl& pluginLocation, const QString& localPluginPath,
  26. int pluginId)
  27. : autostartSetting(-1), id(pluginId), startLevel(-1),
  28. location(pluginLocation), localPluginPath(localPluginPath),
  29. storage(pluginStorage)
  30. {
  31. QByteArray manifestResource = this->getPluginResource("META-INF/MANIFEST.MF");
  32. if (manifestResource.isEmpty())
  33. {
  34. throw ctkPluginException(QString("ctkPlugin has no MANIFEST.MF resource, location=") + pluginLocation.toString());
  35. }
  36. manifest.read(manifestResource);
  37. }
  38. //----------------------------------------------------------------------------
  39. QString ctkPluginArchive::getAttribute(const QString& key) const
  40. {
  41. return manifest.getAttribute(key);
  42. }
  43. //----------------------------------------------------------------------------
  44. QHash<QString,QString> ctkPluginArchive::getUnlocalizedAttributes() const
  45. {
  46. return manifest.getMainAttributes();
  47. }
  48. //----------------------------------------------------------------------------
  49. int ctkPluginArchive::getPluginId() const
  50. {
  51. return id;
  52. }
  53. //----------------------------------------------------------------------------
  54. QUrl ctkPluginArchive::getPluginLocation() const
  55. {
  56. return location;
  57. }
  58. //----------------------------------------------------------------------------
  59. QString ctkPluginArchive::getLibLocation() const
  60. {
  61. return localPluginPath;
  62. }
  63. //----------------------------------------------------------------------------
  64. QByteArray ctkPluginArchive::getPluginResource(const QString& component) const
  65. {
  66. return storage->getPluginResource(getPluginId(), component);
  67. }
  68. //----------------------------------------------------------------------------
  69. QStringList ctkPluginArchive::findResourcesPath(const QString& path) const
  70. {
  71. return storage->findResourcesPath(getPluginId(), path);
  72. }
  73. //----------------------------------------------------------------------------
  74. int ctkPluginArchive::getStartLevel() const
  75. {
  76. return startLevel;
  77. }
  78. //----------------------------------------------------------------------------
  79. void ctkPluginArchive::setStartLevel(int level)
  80. {
  81. if (startLevel != level)
  82. {
  83. startLevel = level;
  84. storage->setStartLevel(this);
  85. }
  86. }
  87. //----------------------------------------------------------------------------
  88. QDateTime ctkPluginArchive::getLastModified() const
  89. {
  90. return lastModified;
  91. }
  92. //----------------------------------------------------------------------------
  93. void ctkPluginArchive::setLastModified(const QDateTime& dateTime)
  94. {
  95. lastModified = dateTime;
  96. storage->setLastModified(this);
  97. }
  98. //----------------------------------------------------------------------------
  99. int ctkPluginArchive::getAutostartSetting() const
  100. {
  101. return autostartSetting;
  102. }
  103. //----------------------------------------------------------------------------
  104. void ctkPluginArchive::setAutostartSetting(int setting)
  105. {
  106. if (autostartSetting != setting)
  107. {
  108. autostartSetting = setting;
  109. storage->setAutostartSetting(this);
  110. }
  111. }
  112. //----------------------------------------------------------------------------
  113. void ctkPluginArchive::purge()
  114. {
  115. storage->removeArchive(this);
  116. }