main.cpp 3.2 KB

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