ctkExampleHostMain.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. // Qt includes
  16. #include <QApplication>
  17. #include <QMainWindow>
  18. #include <QVBoxLayout>
  19. #include <QDebug>
  20. #include <QString>
  21. #include <QStringList>
  22. #include <QDirIterator>
  23. #include <QWidget>
  24. #include <QUrl>
  25. // CTKPluginFramework includes
  26. #include <ctkPluginFrameworkFactory.h>
  27. #include <ctkPluginFramework.h>
  28. #include <ctkPluginException.h>
  29. #include <ctkPluginContext.h>
  30. // CTK includes
  31. #include <ctkExampleDicomHost.h>
  32. #include <ctkHostAppExampleWidget.h>
  33. #include <ui_ctkExampleHostMainWindow.h>
  34. // STD includes
  35. #include <cstdlib>
  36. int main(int argv, char** argc)
  37. {
  38. QApplication app(argv, argc);
  39. qApp->setOrganizationName("CTK");
  40. qApp->setOrganizationDomain("commontk.org");
  41. qApp->setApplicationName("ctkExampleHost");
  42. ctkPluginFrameworkFactory fwFactory;
  43. QSharedPointer<ctkPluginFramework> framework = fwFactory.getFramework();
  44. try
  45. {
  46. framework->init();
  47. }
  48. catch (const ctkPluginException& exc)
  49. {
  50. qCritical() << "Failed to initialize the plug-in framework:" << exc;
  51. return EXIT_FAILURE;
  52. }
  53. #ifdef CMAKE_INTDIR
  54. QString pluginPath = qApp->applicationDirPath() + "/../plugins/" CMAKE_INTDIR "/";
  55. #else
  56. QString pluginPath = qApp->applicationDirPath() + "/plugins/";
  57. #endif
  58. qApp->addLibraryPath(pluginPath);
  59. QStringList libFilter;
  60. libFilter << "*.dll" << "*.so" << "*.dylib";
  61. QDirIterator dirIter(pluginPath, libFilter, QDir::Files);
  62. QStringList pluginsToInstall;
  63. pluginsToInstall << "org_commontk_dah_core" << "org_commontk_dah_host"
  64. << "org_commontk_dah_examplehost";
  65. QList<QSharedPointer<ctkPlugin> > installedPlugins;
  66. while(dirIter.hasNext())
  67. {
  68. try
  69. {
  70. QString fileLocation = dirIter.next();
  71. foreach(QString pluginToInstall, pluginsToInstall)
  72. {
  73. if (fileLocation.contains(pluginToInstall))
  74. {
  75. QSharedPointer<ctkPlugin> plugin = framework->getPluginContext()->installPlugin(QUrl::fromLocalFile(fileLocation));
  76. installedPlugins << plugin;
  77. break;
  78. }
  79. }
  80. }
  81. catch (const ctkPluginException& e)
  82. {
  83. qCritical() << e.what();
  84. }
  85. }
  86. framework->start();
  87. foreach(QSharedPointer<ctkPlugin> plugin, installedPlugins)
  88. {
  89. plugin->start();
  90. }
  91. QMainWindow mainWindow;
  92. Ui::MainWindow ui;
  93. ui.setupUi(&mainWindow);
  94. if ( QApplication::argc() > 1 )
  95. {
  96. ui.controlWidget->setAppFileName(QApplication::argv()[1]);
  97. }
  98. // mainWindow.addDockWidget(static_cast<Qt::DockWidgetArea>(4),new ctkHostAppExampleWidget());
  99. // QVBoxLayout* layout = new QVBoxLayout(&mainWindow);
  100. // ctkHostAppExampleWidget* placeholder = new ctkHostAppExampleWidget(&mainWindow);
  101. // layout->addWidget(placeholder);
  102. mainWindow.show();
  103. return app.exec();
  104. }