main.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 firstRun - is run if the application is run for the first time and launches
  37. * the FirstRunDialog which guides the user through the initial set-up process.
  38. */
  39. bool firstRun()
  40. {
  41. if(FirstRunDialog().exec() == QDialog::Rejected){
  42. LOG << "Initial setup incomplete or unsuccessfull.";
  43. return false;
  44. }
  45. Settings::setSetupCompleted(true);
  46. LOG << "Initial Setup Completed successfully";
  47. QMessageBox mb;
  48. mb.setText("Initial set-up has been completed successfully.<br><br>Please re-start the application.");
  49. mb.exec();
  50. return true;
  51. }
  52. /*!
  53. * \brief init - Sets up the logging facilities, loads the user settings and sets
  54. * up the application style before the MainWindow is instantiated
  55. */
  56. bool init()
  57. {
  58. // Check if another instance of the application is already running, we don't want
  59. // different processes writing to the same database
  60. RunGuard guard(QStringLiteral("opl_single_key"));
  61. if ( !guard.tryToRun() ){
  62. LOG << "Another Instance of openPilotLog is already running. Exiting.";
  63. return false;
  64. }
  65. LOG << "Setting up / verifying Application Directories...";
  66. if(OPL::Paths::setup()) {
  67. LOG << "Application Directories... verified";
  68. } else {
  69. return false;
  70. LOG << "Unable to create directories.";
  71. }
  72. LOG << "Setting up logging facilities...";
  73. if(OPL::Log::init(true)) {
  74. LOG << "Logging enabled.";
  75. } else {
  76. LOG << "Unable to initalise logging.";
  77. }
  78. LOG << "Reading Settings...";
  79. Settings::init();
  80. LOG << "Setting up application style...";
  81. OPL::Style::setup();
  82. // Translations to be done at a later stage
  83. //LOG << "Installing translator...";
  84. //ATranslator::installTranslator(OPL::Translations::English);
  85. // Check for First Run and launch Setup Wizard
  86. if(!Settings::getSetupCompleted())
  87. return firstRun();
  88. return true;
  89. }
  90. int main(int argc, char *argv[])
  91. {
  92. QApplication openPilotLog(argc, argv);
  93. QCoreApplication::setOrganizationName(ORGNAME);
  94. QCoreApplication::setOrganizationDomain(ORGDOMAIN);
  95. QCoreApplication::setApplicationName(APPNAME);
  96. // Set Up the Application
  97. if(!init())
  98. return 1;
  99. // Create Main Window and set Window Icon acc. to Platform
  100. MainWindow w;
  101. #ifdef __linux__
  102. w.setWindowIcon(QIcon(OPL::Assets::ICON_APPICON_LINUX));
  103. #elif defined(_WIN32) || defined(_WIN64)
  104. w.setWindowIcon(QIcon(OPL::Assets::ICON_APPICON_WIN));
  105. #elif __APPLE__
  106. #include <TargetConditionals.h>
  107. #if TARGET_IPHONE_SIMULATOR
  108. // iOS Simulator
  109. #elif TARGET_OS_IPHONE
  110. // iOS device
  111. #elif TARGET_OS_MAC
  112. w.setWindowIcon(QIcon(OPL::Assets::ICON_APPICON_IOS));
  113. #else
  114. # error "Unknown Apple platform"
  115. #endif
  116. #endif
  117. //w.showMaximized();
  118. w.show();
  119. return openPilotLog.exec();
  120. }