ctkPluginArchive.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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::getUnlocalizedAttributes() const
  43. {
  44. return manifest.getMainAttributes();
  45. }
  46. int PluginArchive::getPluginId() const
  47. {
  48. return id;
  49. }
  50. QUrl PluginArchive::getPluginLocation() const
  51. {
  52. return location;
  53. }
  54. QString PluginArchive::getLibLocation() const
  55. {
  56. return localPluginPath;
  57. }
  58. QByteArray PluginArchive::getPluginResource(const QString& component) const
  59. {
  60. return storage->getPluginResource(getPluginId(), component);
  61. }
  62. QStringList PluginArchive::findResourcesPath(const QString& path) const
  63. {
  64. return storage->findResourcesPath(getPluginId(), path);
  65. }
  66. int PluginArchive::getStartLevel() const
  67. {
  68. //TODO
  69. return 0;
  70. }
  71. void PluginArchive::setStartLevel(int level)
  72. {
  73. //TODO
  74. // if (startLevel != level)
  75. // {
  76. // startLevel = level;
  77. // putContent(...);
  78. // }
  79. }
  80. qtimestamp PluginArchive::getLastModified() const
  81. {
  82. return lastModified;
  83. }
  84. void PluginArchive::setLastModified(qtimestamp clockticks)
  85. {
  86. lastModified = clockticks;
  87. //TDOO
  88. //putContent(...)
  89. }
  90. int PluginArchive::getAutostartSetting() const
  91. {
  92. return autostartSetting;
  93. }
  94. void PluginArchive::setAutostartSetting(int setting)
  95. {
  96. if (autostartSetting != setting)
  97. {
  98. autostartSetting = setting;
  99. //TODO
  100. //putContent(...)
  101. }
  102. }
  103. void PluginArchive::purge()
  104. {
  105. storage->removeArchive(this);
  106. }
  107. }