main.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. int main(int argc, char *argv[])
  31. {
  32. QApplication openPilotLog(argc, argv);
  33. QCoreApplication::setOrganizationName("openPilotLog");
  34. QCoreApplication::setOrganizationDomain("https://github.com/fiffty-50/openpilotlog");
  35. QCoreApplication::setApplicationName("openPilotLog");
  36. AStandardPaths::setup();
  37. AStandardPaths::scan_paths();
  38. if(!AStandardPaths::validate_paths()){
  39. DEB("Standard paths not valid.");
  40. return 1;
  41. }
  42. ASettings::setup();
  43. aDB()->connect();
  44. if (!ASettings::read("setup/setup_complete").toBool()) {
  45. FirstRunDialog dialog;
  46. dialog.exec();
  47. }
  48. //Theming
  49. int selectedtheme = ASettings::getSettings().value("main/theme").toInt();
  50. QDir::setCurrent("/themes");
  51. switch (2) {
  52. case 1:{
  53. DEB "main :: Loading light theme";
  54. QFile file(":light.qss");
  55. file.open(QFile::ReadOnly | QFile::Text);
  56. QTextStream stream(&file);
  57. openPilotLog.setStyleSheet(stream.readAll());
  58. break;
  59. }
  60. case 2:{
  61. DEB "Loading dark theme";
  62. QFile file(":dark.qss");
  63. file.open(QFile::ReadOnly | QFile::Text);
  64. QTextStream stream(&file);
  65. openPilotLog.setStyleSheet(stream.readAll());
  66. break;
  67. }
  68. default:
  69. break;
  70. }
  71. //sqlite does not deal well with multiple connections, ensure only one instance is running
  72. ARunGuard guard("opl_single_key");
  73. if ( !guard.tryToRun() ){
  74. DEB "Another Instance is already running. Exiting.";
  75. return 0;
  76. }
  77. MainWindow w;
  78. //w.showMaximized();
  79. w.show();
  80. return openPilotLog.exec();
  81. }