ctkPluginArchiveSQL.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 "ctkPluginArchiveSQL_p.h"
  16. #include "ctkPluginException.h"
  17. #include "ctkPluginStorageSQL_p.h"
  18. #include "ctkPluginDatabaseException.h"
  19. #include <QStringList>
  20. #include <QFile>
  21. //----------------------------------------------------------------------------
  22. ctkPluginArchiveSQL::ctkPluginArchiveSQL(ctkPluginStorageSQL* pluginStorage,
  23. const QUrl& pluginLocation, const QString& localPluginPath,
  24. int pluginId, int startLevel, const QDateTime& lastModified,
  25. int autostartSetting)
  26. : key(-1), autostartSetting(autostartSetting), id(pluginId), generation(0)
  27. , startLevel(startLevel), lastModified(lastModified), location(pluginLocation)
  28. , localPluginPath(localPluginPath), storage(pluginStorage)
  29. {
  30. }
  31. //----------------------------------------------------------------------------
  32. ctkPluginArchiveSQL::ctkPluginArchiveSQL(QSharedPointer<ctkPluginArchiveSQL> old, int generation,
  33. const QUrl &pluginLocation, const QString &localPluginPath)
  34. : key(-1), autostartSetting(old->autostartSetting), id(old->id), generation(generation)
  35. , startLevel(0), location(pluginLocation), localPluginPath(localPluginPath)
  36. , storage(old->storage)
  37. {
  38. }
  39. void ctkPluginArchiveSQL::readManifest(const QByteArray& manifestResource)
  40. {
  41. QByteArray manifestRes = manifestResource.isNull() ? this->getPluginResource("META-INF/MANIFEST.MF")
  42. : manifestResource;
  43. if (manifestRes.isEmpty())
  44. {
  45. throw ctkPluginException(QString("ctkPlugin has no MANIFEST.MF resource, location=") + localPluginPath);
  46. }
  47. manifest.read(manifestRes);
  48. }
  49. //----------------------------------------------------------------------------
  50. QString ctkPluginArchiveSQL::getAttribute(const QString& key) const
  51. {
  52. return manifest.getAttribute(key);
  53. }
  54. //----------------------------------------------------------------------------
  55. QHash<QString,QString> ctkPluginArchiveSQL::getUnlocalizedAttributes() const
  56. {
  57. return manifest.getMainAttributes();
  58. }
  59. int ctkPluginArchiveSQL::getPluginGeneration() const
  60. {
  61. return generation;
  62. }
  63. //----------------------------------------------------------------------------
  64. int ctkPluginArchiveSQL::getPluginId() const
  65. {
  66. return id;
  67. }
  68. //----------------------------------------------------------------------------
  69. QUrl ctkPluginArchiveSQL::getPluginLocation() const
  70. {
  71. return location;
  72. }
  73. //----------------------------------------------------------------------------
  74. QString ctkPluginArchiveSQL::getLibLocation() const
  75. {
  76. return localPluginPath;
  77. }
  78. //----------------------------------------------------------------------------
  79. QByteArray ctkPluginArchiveSQL::getPluginResource(const QString& component) const
  80. {
  81. try
  82. {
  83. return storage->getPluginResource(key, component);
  84. }
  85. catch (const ctkPluginDatabaseException& exc)
  86. {
  87. qDebug() << QString("Getting plugin resource %1 failed:").arg(component) << exc;
  88. return QByteArray();
  89. }
  90. }
  91. //----------------------------------------------------------------------------
  92. QStringList ctkPluginArchiveSQL::findResourcesPath(const QString& path) const
  93. {
  94. try
  95. {
  96. return storage->findResourcesPath(key, path);
  97. }
  98. catch (const ctkPluginDatabaseException& exc)
  99. {
  100. qDebug() << QString("Getting plugin resource paths for %1 failed:").arg(path) << exc;
  101. }
  102. return QStringList();
  103. }
  104. //----------------------------------------------------------------------------
  105. int ctkPluginArchiveSQL::getStartLevel() const
  106. {
  107. return startLevel;
  108. }
  109. //----------------------------------------------------------------------------
  110. void ctkPluginArchiveSQL::setStartLevel(int level)
  111. {
  112. if (startLevel != level)
  113. {
  114. startLevel = level;
  115. storage->setStartLevel(key, level);
  116. }
  117. }
  118. //----------------------------------------------------------------------------
  119. QDateTime ctkPluginArchiveSQL::getLastModified() const
  120. {
  121. return lastModified;
  122. }
  123. //----------------------------------------------------------------------------
  124. void ctkPluginArchiveSQL::setLastModified(const QDateTime& dateTime)
  125. {
  126. lastModified = dateTime;
  127. storage->setLastModified(key, dateTime);
  128. }
  129. //----------------------------------------------------------------------------
  130. int ctkPluginArchiveSQL::getAutostartSetting() const
  131. {
  132. return autostartSetting;
  133. }
  134. //----------------------------------------------------------------------------
  135. void ctkPluginArchiveSQL::setAutostartSetting(int setting)
  136. {
  137. if (autostartSetting != setting)
  138. {
  139. autostartSetting = setting;
  140. storage->setAutostartSetting(key, setting);
  141. }
  142. }
  143. //----------------------------------------------------------------------------
  144. void ctkPluginArchiveSQL::purge()
  145. {
  146. storage->removeArchive(this);
  147. }
  148. //----------------------------------------------------------------------------
  149. void ctkPluginArchiveSQL::close()
  150. {
  151. }