main.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. const auto DATA_DIR = QLatin1String("data");
  26. /*!
  27. * \brief setup checks if data folder and settings files exists.
  28. * \return
  29. */
  30. bool setup()
  31. {
  32. if (!QDir(DATA_DIR).exists())
  33. QDir().mkdir(DATA_DIR);
  34. QDir settingspath(DATA_DIR + QLatin1Char('/') + QCoreApplication::organizationName());
  35. QString settingsfile = QCoreApplication::applicationName() + QLatin1String(".ini");
  36. QFileInfo check_file(settingspath,settingsfile);
  37. return check_file.exists() && check_file.isFile();
  38. };
  39. int main(int argc, char *argv[])
  40. {
  41. //sqlite does not deal well with multiple connections, ensure only one instance is running
  42. RunGuard guard("opl_single_key");
  43. if ( !guard.tryToRun() ){
  44. qDebug() << "Another Instance is already running. Exiting.";
  45. return 0;
  46. }
  47. QCoreApplication::setOrganizationName("openPilotLog");
  48. QCoreApplication::setOrganizationDomain("https://github.com/fiffty-50/openpilotlog");
  49. QCoreApplication::setApplicationName("openPilotLog");
  50. QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, DATA_DIR);
  51. QSettings::setDefaultFormat(QSettings::IniFormat);
  52. QSettings settings;
  53. QApplication openPilotLog(argc, argv);
  54. if(!setup()){
  55. FirstRunDialog dialog;
  56. dialog.exec();
  57. }
  58. //Theming
  59. int selectedtheme = settings.value("main/theme").toInt();
  60. QDir::setCurrent("/themes");
  61. switch (selectedtheme) {
  62. case 1:{
  63. qDebug() << "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. qDebug() << "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. MainWindow w;
  82. //w.showMaximized();
  83. w.show();
  84. return openPilotLog.exec();
  85. }