consolegenerator.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include <QDebug>
  2. #include <QCoreApplication>
  3. #include <QTimer>
  4. #include <QDesktopServices>
  5. #include <QUrl>
  6. #include "generatorconsoleoutput.h"
  7. #include "generatorfileoutput.h"
  8. #include "consolegenerator.h"
  9. #include "progressdialog.h"
  10. #include "qtprojectgeneratorfactory.h"
  11. ConsoleGenerator::ConsoleGenerator(const ArgumentParser& parser)
  12. : m_parser(parser)
  13. {
  14. m_dialog = new ProgressDialog();
  15. if (parser.guiEnabled())
  16. {
  17. // GUI -> use file logger and an option to open it
  18. m_logger = new GeneratorFileOutput(Settings::get(Settings::LogFilePath).toString());
  19. m_dialog->show();
  20. }
  21. else
  22. {
  23. // No GUI -> user console logger
  24. m_logger = new GeneratorConsoleOutput();
  25. m_dialog->hide();
  26. }
  27. QtProjectGeneratorFactory
  28. generatorFactory;
  29. // TODO this should come from CLI
  30. m_generator = generatorFactory.createProjectGenerator(parser.getPlatform(),
  31. *m_logger);
  32. // Status updater
  33. m_updater = m_generator->createStatusUpdater(this);
  34. /* OBS
  35. m_generator = new QtProjectGenerator(*m_logger);
  36. m_updater = new StatusUpdater(*m_generator, this);
  37. */
  38. m_dialog->setMaximumProgress(m_updater->maximumProgress());
  39. connect(m_updater, SIGNAL(updated()), this, SLOT(progressUpdated()));
  40. connect(m_updater, SIGNAL(finished(bool)), this, SLOT(progressFinished(bool)));
  41. connect(m_dialog, SIGNAL(openSIS()), this, SLOT(openSisClicked()));
  42. // Hackish way to return execution to main(), in order to get
  43. // the application loop running before we start processing.
  44. // This allows us to e.g. use QCoreApplication::exit().
  45. QTimer::singleShot(100, this, SLOT(startGenerator()));
  46. }
  47. void ConsoleGenerator::startGenerator()
  48. {
  49. QTextStream cin(stdin, QIODevice::ReadOnly);
  50. QTextStream cout(stdout, QIODevice::WriteOnly);
  51. QTextStream cerr(stderr, QIODevice::WriteOnly);
  52. switch (m_parser.getTarget())
  53. {
  54. case PREVIEW:
  55. m_generator->preview(m_parser.getFile());
  56. break;
  57. case BUILD:
  58. // TODO no remote compilation supported by console yet
  59. m_generator->build(m_parser.getFile(),
  60. *(static_cast<RcSession*>(NULL)));
  61. break;
  62. default:
  63. cerr << "The selected build action is currently not supported in CLI mode.\n";
  64. break;
  65. }
  66. }
  67. ConsoleGenerator::~ConsoleGenerator()
  68. {
  69. delete m_logger;
  70. delete m_generator;
  71. delete m_dialog;
  72. }
  73. void ConsoleGenerator::progressUpdated()
  74. {
  75. m_dialog->updateProgress(m_updater->currentProgress());
  76. m_dialog->updateStatusText(m_updater->statusText());
  77. }
  78. void ConsoleGenerator::progressFinished(bool success)
  79. {
  80. qDebug() << "exiting";
  81. if (!m_parser.guiEnabled())
  82. {
  83. qDebug() << "exit";
  84. QCoreApplication::exit(success ? EXIT_FAILURE : EXIT_SUCCESS);
  85. }
  86. else
  87. {
  88. m_dialog->setFinishedView(m_parser.getTarget(), success);
  89. }
  90. }
  91. void ConsoleGenerator::openSisClicked()
  92. {
  93. QFileInfo
  94. pkgFile = m_updater->pkgFileInfo();
  95. IQtProjectGenerator::PkgInstallResult
  96. result = m_generator->installPkg(pkgFile);
  97. // TODO maybe some action about supportedness / success
  98. Q_UNUSED(result)
  99. }