main.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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/experimental/adatabase.h"
  22. #include "src/classes/asettings.h"
  23. #include <QApplication>
  24. #include <QProcess>
  25. #include <QSettings>
  26. #include <QFileInfo>
  27. const auto DATA_DIR = QLatin1String("data");
  28. /*!
  29. * \brief setup checks if data folder and settings files exists.
  30. * \return
  31. */
  32. bool setup()
  33. {
  34. if (!QDir(DATA_DIR).exists())
  35. QDir().mkdir(DATA_DIR);
  36. QDir settingspath(DATA_DIR + QLatin1Char('/') + QCoreApplication::organizationName());
  37. QString settingsfile = QCoreApplication::applicationName() + QLatin1String(".ini");
  38. QFileInfo check_file(settingspath,settingsfile);
  39. QSettings settings;
  40. settings.setValue("setup/touch", true);
  41. settings.sync();
  42. return check_file.exists() && check_file.isFile();
  43. };
  44. int main(int argc, char *argv[])
  45. {
  46. QCoreApplication::setOrganizationName("openPilotLog");
  47. QCoreApplication::setOrganizationDomain("https://github.com/fiffty-50/openpilotlog");
  48. QCoreApplication::setApplicationName("openPilotLog");
  49. QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, DATA_DIR);
  50. QSettings::setDefaultFormat(QSettings::IniFormat);
  51. QSettings settings;
  52. experimental::aDB()->connect();
  53. QApplication openPilotLog(argc, argv);
  54. if(!setup()){
  55. DEB("error creating required directories");
  56. return 0;
  57. }
  58. if (!ASettings::read("setup/setup_complete").toBool()) {
  59. FirstRunDialog dialog;
  60. dialog.exec();
  61. }
  62. //Theming
  63. int selectedtheme = settings.value("main/theme").toInt();
  64. QDir::setCurrent("/themes");
  65. switch (selectedtheme) {
  66. case 1:{
  67. qDebug() << "main :: Loading light theme";
  68. QFile file(":light.qss");
  69. file.open(QFile::ReadOnly | QFile::Text);
  70. QTextStream stream(&file);
  71. openPilotLog.setStyleSheet(stream.readAll());
  72. break;
  73. }
  74. case 2:{
  75. qDebug() << "Loading dark theme";
  76. QFile file(":dark.qss");
  77. file.open(QFile::ReadOnly | QFile::Text);
  78. QTextStream stream(&file);
  79. openPilotLog.setStyleSheet(stream.readAll());
  80. break;
  81. }
  82. default:
  83. break;
  84. }
  85. //sqlite does not deal well with multiple connections, ensure only one instance is running
  86. ARunGuard guard("opl_single_key");
  87. if ( !guard.tryToRun() ){
  88. qDebug() << "Another Instance is already running. Exiting.";
  89. return 0;
  90. }
  91. MainWindow w;
  92. //w.showMaximized();
  93. w.show();
  94. return openPilotLog.exec();
  95. }