ctkPluginArchive.cpp 4.5 KB

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