ctkPluginArchive.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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 PluginArchive::AUTOSTART_SETTING_STOPPED("stopped");
  21. const QString PluginArchive::AUTOSTART_SETTING_EAGER("eager");
  22. const QString PluginArchive::AUTOSTART_SETTING_ACTIVATION_POLICY("activation_policy");
  23. PluginArchive::PluginArchive(PluginStorage* pluginStorage,
  24. const QUrl& pluginLocation, const QString& localPluginPath,
  25. int pluginId)
  26. : autostartSetting(-1), id(pluginId), lastModified(0),
  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 PluginException(QString("Plugin has no MANIFEST.MF resource, location=") + pluginLocation.toString());
  34. }
  35. manifest.read(manifestResource);
  36. }
  37. QString PluginArchive::getAttribute(const QString& key) const
  38. {
  39. return manifest.getAttribute(key);
  40. }
  41. QHash<QString,QString> PluginArchive::getUnlocalizedAttributes() const
  42. {
  43. return manifest.getMainAttributes();
  44. }
  45. int PluginArchive::getPluginId() const
  46. {
  47. return id;
  48. }
  49. QUrl PluginArchive::getPluginLocation() const
  50. {
  51. return location;
  52. }
  53. QString PluginArchive::getLibLocation() const
  54. {
  55. return localPluginPath;
  56. }
  57. QByteArray PluginArchive::getPluginResource(const QString& component) const
  58. {
  59. return storage->getPluginResource(getPluginId(), component);
  60. }
  61. QStringList PluginArchive::findResourcesPath(const QString& path) const
  62. {
  63. return storage->findResourcesPath(getPluginId(), path);
  64. }
  65. int PluginArchive::getStartLevel() const
  66. {
  67. //TODO
  68. return 0;
  69. }
  70. void PluginArchive::setStartLevel(int level)
  71. {
  72. //TODO
  73. // if (startLevel != level)
  74. // {
  75. // startLevel = level;
  76. // putContent(...);
  77. // }
  78. }
  79. qtimestamp PluginArchive::getLastModified() const
  80. {
  81. return lastModified;
  82. }
  83. void PluginArchive::setLastModified(qtimestamp clockticks)
  84. {
  85. lastModified = clockticks;
  86. //TDOO
  87. //putContent(...)
  88. }
  89. int PluginArchive::getAutostartSetting() const
  90. {
  91. return autostartSetting;
  92. }
  93. void PluginArchive::setAutostartSetting(int setting)
  94. {
  95. if (autostartSetting != setting)
  96. {
  97. autostartSetting = setting;
  98. //TODO
  99. //putContent(...)
  100. }
  101. }
  102. void PluginArchive::purge()
  103. {
  104. storage->removeArchive(this);
  105. }