main.cpp 3.8 KB

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