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