2
0

main.cpp 3.4 KB

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