ctkPluginGeneratorMain.cpp 3.2 KB

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