main.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #define APPNAME QStringLiteral("openPilotLog")
  36. #define ORGNAME QStringLiteral("opl")
  37. #define ORGDOMAIN QStringLiteral("https://github.com/fiffty-50/openpilotlog")
  38. /*!
  39. * Helper functions that prepare and set up the application
  40. */
  41. namespace Main {
  42. void init()
  43. {
  44. LOG << "Setting up / verifying Application Directories...";
  45. if(OPL::Paths::setup()) {
  46. LOG << "Application Directories... verified";
  47. } else {
  48. LOG << "Unable to create directories.";
  49. }
  50. LOG << "Setting up logging facilities...";
  51. if(OPL::Log::init(true)) {
  52. LOG << "Logging enabled.";
  53. } else {
  54. LOG << "Unable to initalise logging.";
  55. }
  56. LOG << "Reading Settings...";
  57. Settings::setup();
  58. LOG << "Setting up application style...";
  59. OPL::Style::setup();
  60. // Translations to be done at a later stage
  61. //LOG << "Installing translator...";
  62. //ATranslator::installTranslator(OPL::Translations::English);
  63. }
  64. bool firstRun()
  65. {
  66. if(FirstRunDialog().exec() == QDialog::Rejected){
  67. LOG << "Initial setup incomplete or unsuccessfull.";
  68. return false;
  69. }
  70. Settings::write(Settings::Main::SetupComplete, true);
  71. LOG << "Initial Setup Completed successfully";
  72. return true;
  73. }
  74. } // namespace Main
  75. int main(int argc, char *argv[])
  76. {
  77. QApplication openPilotLog(argc, argv);
  78. QCoreApplication::setOrganizationName(ORGNAME);
  79. QCoreApplication::setOrganizationDomain(ORGDOMAIN);
  80. QCoreApplication::setApplicationName(APPNAME);
  81. // Check for another instance already running
  82. RunGuard guard(QStringLiteral("opl_single_key"));
  83. if ( !guard.tryToRun() ){
  84. LOG << "Another Instance of openPilotLog is already running. Exiting.";
  85. return 0;
  86. }
  87. // Set Up the Application
  88. Main::init();
  89. // Check for First Run and launch Setup Wizard
  90. if (!Settings::read(Settings::Main::SetupComplete).toBool())
  91. if(!Main::firstRun())
  92. return 0;
  93. // Create Main Window and set Window Icon acc. to Platform
  94. MainWindow w;
  95. #ifdef __linux__
  96. w.setWindowIcon(QIcon(OPL::Assets::ICON_APPICON_LINUX));
  97. #elif defined(_WIN32) || defined(_WIN64)
  98. w.setWindowIcon(QIcon(OPL::Assets::ICON_APPICON_WIN));
  99. #elif __APPLE__
  100. #include <TargetConditionals.h>
  101. #if TARGET_IPHONE_SIMULATOR
  102. // iOS Simulator
  103. #elif TARGET_OS_IPHONE
  104. // iOS device
  105. #elif TARGET_OS_MAC
  106. w.setWindowIcon(QIcon(OPL::Assets::ICON_APPICON_IOS));
  107. #else
  108. # error "Unknown Apple platform"
  109. #endif
  110. #endif
  111. //w.showMaximized();
  112. w.show();
  113. return openPilotLog.exec();
  114. }