main.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 <QCoreApplication>
  20. #include <QApplication>
  21. #include <QFile>
  22. #include <QTextStream>
  23. #include <QDir>
  24. #include <QPalette>
  25. #include <QColor>
  26. #include <QSqlDatabase>
  27. #include <QSqlDriver>
  28. #include <QSqlError>
  29. #include <QSqlQuery>
  30. #include "dbsettings.h"
  31. #include <QDebug>
  32. int selectedtheme = 1; //Variable to store theming information
  33. void connectToDatabase()
  34. {
  35. const QString DRIVER("QSQLITE");
  36. if(QSqlDatabase::isDriverAvailable(DRIVER))
  37. {
  38. QSqlDatabase db = QSqlDatabase::addDatabase(DRIVER);
  39. /*For a release, we need to decide where to put the database, for now
  40. *it is in the executable working directory for ease of developtment*/
  41. //QString pathtodb = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
  42. //db.setDatabaseName(pathtodb+"/logbook.db");
  43. //qDebug() << "Database: " << pathtodb+"/logbook.db";
  44. db.setDatabaseName("logbook.db");
  45. if(!db.open())
  46. qWarning() << "MainWindow::DatabaseConnect - ERROR: " << db.lastError().text();
  47. }
  48. else
  49. qWarning() << "MainWindow::DatabaseConnect - ERROR: no driver " << DRIVER << " available";
  50. }
  51. int main(int argc, char *argv[])
  52. {
  53. QCoreApplication::setOrganizationName("Fiffty50");
  54. QCoreApplication::setOrganizationDomain("https://github.com/fiffty-50/openpilotlog");
  55. QCoreApplication::setApplicationName("openLog");
  56. QApplication openLog(argc, argv);
  57. connectToDatabase();
  58. //Theming with CSS inlcues QFile,QTextStream, QDir, themes folder and TARGET = flog, RESOURCES = themes/breeze.qrc in pro
  59. // credit: https://github.com/Alexhuszagh/BreezeStyleSheets
  60. selectedtheme = dbSettings::retreiveSetting(10).toInt();
  61. QDir::setCurrent("/themes");
  62. if (selectedtheme == 1){
  63. qDebug() << "Loading light theme";
  64. QFile file(":light.qss");
  65. file.open(QFile::ReadOnly | QFile::Text);
  66. QTextStream stream(&file);
  67. openLog.setStyleSheet(stream.readAll());
  68. }else if (selectedtheme == 2){
  69. qDebug() << "Loading dark theme";
  70. QFile file(":dark.qss");
  71. file.open(QFile::ReadOnly | QFile::Text);
  72. QTextStream stream(&file);
  73. openLog.setStyleSheet(stream.readAll());
  74. }
  75. MainWindow w;
  76. w.show();
  77. return openLog.exec();
  78. }