main.cpp 3.6 KB

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