main.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. *openPilotLog - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020-2022 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. * Helper functions that prepare and set up the application
  37. */
  38. namespace Main {
  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. bool firstRun()
  62. {
  63. if(FirstRunDialog().exec() == QDialog::Rejected){
  64. LOG << "Initial setup incomplete or unsuccessfull.";
  65. return false;
  66. }
  67. Settings::write(Settings::Main::SetupComplete, true);
  68. LOG << "Initial Setup Completed successfully";
  69. return true;
  70. }
  71. } // namespace Main
  72. int main(int argc, char *argv[])
  73. {
  74. QApplication openPilotLog(argc, argv);
  75. QCoreApplication::setOrganizationName(ORGNAME);
  76. QCoreApplication::setOrganizationDomain(ORGDOMAIN);
  77. QCoreApplication::setApplicationName(APPNAME);
  78. // Check for another instance already running
  79. RunGuard guard(QStringLiteral("opl_single_key"));
  80. if ( !guard.tryToRun() ){
  81. LOG << "Another Instance of openPilotLog is already running. Exiting.";
  82. return 0;
  83. }
  84. // Set Up the Application
  85. Main::init();
  86. // Check for First Run and launch Setup Wizard
  87. if (!Settings::read(Settings::Main::SetupComplete).toBool())
  88. if(!Main::firstRun())
  89. return 0;
  90. // Create Main Window and set Window Icon acc. to Platform
  91. MainWindow w;
  92. #ifdef __linux__
  93. w.setWindowIcon(QIcon(OPL::Assets::ICON_APPICON_LINUX));
  94. #elif defined(_WIN32) || defined(_WIN64)
  95. w.setWindowIcon(QIcon(OPL::Assets::ICON_APPICON_WIN));
  96. #elif __APPLE__
  97. #include <TargetConditionals.h>
  98. #if TARGET_IPHONE_SIMULATOR
  99. // iOS Simulator
  100. #elif TARGET_OS_IPHONE
  101. // iOS device
  102. #elif TARGET_OS_MAC
  103. w.setWindowIcon(QIcon(OPL::Assets::ICON_APPICON_IOS));
  104. #else
  105. # error "Unknown Apple platform"
  106. #endif
  107. #endif
  108. //w.showMaximized();
  109. w.show();
  110. return openPilotLog.exec();
  111. }