main.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. *openPilot Log - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020 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/gui/dialogues/firstrundialog.h"
  20. #include "src/classes/arunguard.h"
  21. #include "src/database/adatabase.h"
  22. #include "src/classes/asettings.h"
  23. #include "src/astandardpaths.h"
  24. #include "src/classes/asettings.h"
  25. #include <QApplication>
  26. #include <QProcess>
  27. #include <QSettings>
  28. #include <QFileInfo>
  29. #include <QStandardPaths>
  30. #include <QDebug>
  31. #define APPNAME QStringLiteral("openPilotLog")
  32. #define ORGNAME QStringLiteral("opl")
  33. #define ORGDOMAIN QStringLiteral("https://github.com/fiffty-50/openpilotlog")
  34. int main(int argc, char *argv[])
  35. {
  36. QApplication openPilotLog(argc, argv);
  37. QCoreApplication::setOrganizationName(ORGNAME);
  38. QCoreApplication::setOrganizationDomain(ORGDOMAIN);
  39. QCoreApplication::setApplicationName(APPNAME);
  40. AStandardPaths::setup();
  41. AStandardPaths::scan_paths();
  42. if(!AStandardPaths::validate_paths()){
  43. DEB << "Standard paths not valid.";
  44. return 1;
  45. }
  46. ASettings::setup();
  47. //Debug firstrundialog
  48. ASettings::write(ASettings::Setup::SetupComplete, false);
  49. aDB()->connect();
  50. if (!ASettings::read(ASettings::Setup::SetupComplete).toBool()) {
  51. FirstRunDialog dialog;
  52. if(dialog.exec() == QDialog::Accepted) {
  53. qApp->quit();
  54. QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
  55. } else {
  56. DEB "First run not accepted. Exiting.";
  57. return 0;
  58. }
  59. }
  60. //Theming
  61. switch (ASettings::read(ASettings::Main::Theme).toInt()) {
  62. case 1:{
  63. DEB << "main :: Loading light theme";
  64. QFile file(":light.qss");
  65. file.open(QFile::ReadOnly | QFile::Text);
  66. QTextStream stream(&file);
  67. openPilotLog.setStyleSheet(stream.readAll());
  68. break;
  69. }
  70. case 2:{
  71. DEB << "Loading dark theme";
  72. QFile file(":dark.qss");
  73. file.open(QFile::ReadOnly | QFile::Text);
  74. QTextStream stream(&file);
  75. openPilotLog.setStyleSheet(stream.readAll());
  76. break;
  77. }
  78. default:
  79. break;
  80. }
  81. //sqlite does not deal well with multiple connections, ensure only one instance is running
  82. ARunGuard guard(QStringLiteral("opl_single_key"));
  83. if ( !guard.tryToRun() ){
  84. DEB << "Another Instance is already running. Exiting.";
  85. return 0;
  86. }
  87. MainWindow w;
  88. //w.showMaximized();
  89. w.show();
  90. return openPilotLog.exec();
  91. }