ctkPluginGeneratorMain.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 <ctkConfig.h>
  16. #include <ctkPluginFrameworkFactory.h>
  17. #include <ctkPluginFramework.h>
  18. #include <ctkPluginException.h>
  19. #include <ctkPluginGeneratorConstants.h>
  20. #include <ctkPluginContext.h>
  21. #include "ctkPluginGenerator_p.h"
  22. #include <QApplication>
  23. #include <QSettings>
  24. #include <QDirIterator>
  25. #include <QInputDialog>
  26. #include <QDebug>
  27. int main(int argv, char** argc)
  28. {
  29. QApplication app(argv, argc);
  30. qApp->setOrganizationName("CTK");
  31. qApp->setOrganizationDomain("commontk.org");
  32. qApp->setApplicationName("ctkPluginGenerator");
  33. // init global template defaults
  34. QSettings settings;
  35. if (!settings.contains(ctkPluginGeneratorConstants::PLUGIN_LICENSE_MARKER))
  36. {
  37. QFile license(":/generatordefaults/license.txt");
  38. license.open(QIODevice::ReadOnly);
  39. QString licenseText = license.readAll();
  40. bool ok;
  41. QString organization = QInputDialog::getText(0, qApp->translate("OrganizationInputDialog", "CTK Plugin Generator"),
  42. qApp->translate("OrganizationInputDialog", "Enter the name of your organization:"),
  43. QLineEdit::Normal, qApp->translate("OrganizationInputDialog", "<your-organization>"), &ok);
  44. if (!ok)
  45. {
  46. exit(0);
  47. }
  48. organization.replace("\\n", "\n");
  49. settings.setValue(ctkPluginGeneratorConstants::PLUGIN_LICENSE_MARKER, licenseText.arg(organization));
  50. }
  51. ctkPluginFrameworkFactory fwFactory;
  52. QSharedPointer<ctkPluginFramework> framework = fwFactory.getFramework();
  53. try {
  54. framework->init();
  55. }
  56. catch (const ctkPluginException& exc)
  57. {
  58. qCritical() << "Failed to initialize the plug-in framework:" << exc;
  59. exit(1);
  60. }
  61. #ifdef CMAKE_INTDIR
  62. QString pluginPath = CTK_PLUGIN_DIR CMAKE_INTDIR "/";
  63. #else
  64. QString pluginPath = CTK_PLUGIN_DIR;
  65. #endif
  66. qApp->addLibraryPath(pluginPath);
  67. QStringList libFilter;
  68. libFilter << "*.dll" << "*.so" << "*.dylib";
  69. QDirIterator dirIter(pluginPath, libFilter, QDir::Files);
  70. while(dirIter.hasNext())
  71. {
  72. try
  73. {
  74. QString fileLocation = dirIter.next();
  75. if (fileLocation.contains("org_commontk_plugingenerator"))
  76. {
  77. QSharedPointer<ctkPlugin> plugin = framework->getPluginContext()->installPlugin(QUrl::fromLocalFile(fileLocation));
  78. plugin->start(ctkPlugin::START_TRANSIENT);
  79. }
  80. }
  81. catch (const ctkPluginException& e)
  82. {
  83. qCritical() << e.what();
  84. }
  85. }
  86. framework->start();
  87. ctkPluginGenerator generator(framework.data());
  88. generator.show();
  89. return app.exec();
  90. }