ctkPluginArchive.cxx 3.5 KB

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