2
0

main.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. *openPilotLog - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020-2023 Felix Turowsky
  4. *
  5. *This program is free software: you can redistribute it and/or modify
  6. *it under the terms of the GNU General Public License as published by
  7. *the Free Software Foundation, either version 3 of the License, or
  8. *(at your option) any later version.
  9. *
  10. *This program is distributed in the hope that it will be useful,
  11. *but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. *GNU General Public License for more details.
  14. *
  15. *You should have received a copy of the GNU General Public License
  16. *along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. #include "mainwindow.h"
  19. #include "src/opl.h"
  20. #include "src/functions/log.h"
  21. #include "src/gui/dialogues/firstrundialog.h"
  22. #include "src/classes/runguard.h"
  23. #include "src/classes/settings.h"
  24. #include "src/classes/settings.h"
  25. #include "src/classes/style.h"
  26. #include "src/functions/log.h"
  27. #include "src/classes/paths.h"
  28. #include <QApplication>
  29. #include <QProcess>
  30. #include <QSettings>
  31. #include <QFileInfo>
  32. #include <QStandardPaths>
  33. #include <QDebug>
  34. #include <QTranslator>
  35. /*!
  36. * \brief init - Sets up the logging facilities, loads the user settings and sets
  37. * up the application style before the MainWindow is instantiated
  38. */
  39. void init()
  40. {
  41. LOG << "Setting up / verifying Application Directories...";
  42. if(OPL::Paths::setup()) {
  43. LOG << "Application Directories... verified";
  44. } else {
  45. LOG << "Unable to create directories.";
  46. }
  47. LOG << "Setting up logging facilities...";
  48. if(OPL::Log::init(true)) {
  49. LOG << "Logging enabled.";
  50. } else {
  51. LOG << "Unable to initalise logging.";
  52. }
  53. LOG << "Reading Settings...";
  54. Settings::setup();
  55. LOG << "Setting up application style...";
  56. OPL::Style::setup();
  57. // Translations to be done at a later stage
  58. //LOG << "Installing translator...";
  59. //ATranslator::installTranslator(OPL::Translations::English);
  60. }
  61. /*!
  62. * \brief firstRun - is run if the application is run for the first time and launches
  63. * the FirstRunDialog which guides the user through the initial set-up process.
  64. */
  65. int firstRun()
  66. {
  67. if(FirstRunDialog().exec() == QDialog::Rejected){
  68. LOG << "Initial setup incomplete or unsuccessfull.";
  69. return 1;
  70. }
  71. Settings::write(Settings::Main::SetupComplete, true);
  72. LOG << "Initial Setup Completed successfully";
  73. QMessageBox mb;
  74. mb.setText("Initial set-up has been completed successfully.<br><br>Please re-start the application.");
  75. mb.exec();
  76. return 0;
  77. }
  78. int main(int argc, char *argv[])
  79. {
  80. QApplication openPilotLog(argc, argv);
  81. QCoreApplication::setOrganizationName(ORGNAME);
  82. QCoreApplication::setOrganizationDomain(ORGDOMAIN);
  83. QCoreApplication::setApplicationName(APPNAME);
  84. // Check of another instance of the application is already running, we don't want
  85. // different processes writing to the same database
  86. RunGuard guard(QStringLiteral("opl_single_key"));
  87. if ( !guard.tryToRun() ){
  88. LOG << "Another Instance of openPilotLog is already running. Exiting.";
  89. return 0;
  90. }
  91. // Set Up the Application
  92. init();
  93. // Check for First Run and launch Setup Wizard
  94. if (!Settings::read(Settings::Main::SetupComplete).toBool())
  95. return firstRun();
  96. // Create Main Window and set Window Icon acc. to Platform
  97. MainWindow w;
  98. #ifdef __linux__
  99. w.setWindowIcon(QIcon(OPL::Assets::ICON_APPICON_LINUX));
  100. #elif defined(_WIN32) || defined(_WIN64)
  101. w.setWindowIcon(QIcon(OPL::Assets::ICON_APPICON_WIN));
  102. #elif __APPLE__
  103. #include <TargetConditionals.h>
  104. #if TARGET_IPHONE_SIMULATOR
  105. // iOS Simulator
  106. #elif TARGET_OS_IPHONE
  107. // iOS device
  108. #elif TARGET_OS_MAC
  109. w.setWindowIcon(QIcon(OPL::Assets::ICON_APPICON_IOS));
  110. #else
  111. # error "Unknown Apple platform"
  112. #endif
  113. #endif
  114. //w.showMaximized();
  115. w.show();
  116. return openPilotLog.exec();
  117. }