main.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <QApplication>
  21. #include <QProcess>
  22. #include <QSettings>
  23. #include <QFileInfo>
  24. const auto DATA_DIR = QLatin1String("data");
  25. /*!
  26. * \brief setup checks if data folder and settings files exists.
  27. * \return
  28. */
  29. bool setup()
  30. {
  31. if (!QDir(DATA_DIR).exists())
  32. QDir().mkdir(DATA_DIR);
  33. QDir settingspath(DATA_DIR + QLatin1Char('/') + QCoreApplication::organizationName());
  34. QString settingsfile = QCoreApplication::applicationName() + QLatin1String(".ini");
  35. QFileInfo check_file(settingspath,settingsfile);
  36. return check_file.exists() && check_file.isFile();
  37. };
  38. int main(int argc, char *argv[])
  39. {
  40. QCoreApplication::setOrganizationName("openPilotLog");
  41. QCoreApplication::setOrganizationDomain("https://github.com/fiffty-50/openpilotlog");
  42. QCoreApplication::setApplicationName("openPilotLog");
  43. QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, DATA_DIR);
  44. QSettings::setDefaultFormat(QSettings::IniFormat);
  45. QSettings settings;
  46. QApplication openPilotLog(argc, argv);
  47. if(!setup()){
  48. FirstRunDialog dialog;
  49. dialog.exec();
  50. }
  51. //Theming
  52. int selectedtheme = settings.value("main/theme").toInt();
  53. QDir::setCurrent("/themes");
  54. switch (selectedtheme) {
  55. case 1:{
  56. qDebug() << "main :: Loading light theme";
  57. QFile file(":light.qss");
  58. file.open(QFile::ReadOnly | QFile::Text);
  59. QTextStream stream(&file);
  60. openPilotLog.setStyleSheet(stream.readAll());
  61. break;
  62. }
  63. case 2:{
  64. qDebug() << "Loading dark theme";
  65. QFile file(":dark.qss");
  66. file.open(QFile::ReadOnly | QFile::Text);
  67. QTextStream stream(&file);
  68. openPilotLog.setStyleSheet(stream.readAll());
  69. break;
  70. }
  71. default:
  72. break;
  73. }
  74. MainWindow w;
  75. //w.showMaximized();
  76. w.show();
  77. return openPilotLog.exec();
  78. }