ctkExampleHostMain.cpp 3.5 KB

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