ctkPluginArchive.cpp 3.3 KB

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