main.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. *openPilotLog - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020-2021 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/database/adatabase.h"
  22. #include "src/classes/asettings.h"
  23. #include "src/classes/astandardpaths.h"
  24. #include "src/classes/asettings.h"
  25. #include "src/classes/astyle.h"
  26. #include "src/oplconstants.h"
  27. #include "src/functions/alog.h"
  28. #include <QApplication>
  29. #include <QProcess>
  30. #include <QSettings>
  31. #include <QFileInfo>
  32. #include <QStandardPaths>
  33. #include <QDebug>
  34. #define APPNAME QStringLiteral("openPilotLog")
  35. #define ORGNAME QStringLiteral("opl")
  36. #define ORGDOMAIN QStringLiteral("https://github.com/fiffty-50/openpilotlog")
  37. int main(int argc, char *argv[])
  38. {
  39. QApplication openPilotLog(argc, argv);
  40. QCoreApplication::setOrganizationName(ORGNAME);
  41. QCoreApplication::setOrganizationDomain(ORGDOMAIN);
  42. QCoreApplication::setApplicationName(APPNAME);
  43. if(!AStandardPaths::setup()){
  44. LOG << "Unable to create directories.\n";
  45. return 1;
  46. }
  47. ASettings::setup();
  48. AStyle::setup();
  49. if (!aDB->connect()) {
  50. LOG << "Error establishing database connection\n";
  51. return 2;
  52. }
  53. if (!ASettings::read(ASettings::Main::SetupComplete).toBool()) {
  54. if(FirstRunDialog().exec() == QDialog::Rejected){
  55. LOG << "Initial setup incomplete or unsuccessfull. Exiting.\n";
  56. return 3;
  57. }
  58. ASettings::write(ASettings::Main::SetupComplete, true);
  59. DEB << "Wrote setup_commplete";
  60. }
  61. ARunGuard guard(QStringLiteral("opl_single_key"));
  62. if ( !guard.tryToRun() ){
  63. LOG << "Another Instance of openPilotLog is already running. Exiting.\n";
  64. return 0;
  65. }
  66. MainWindow w;
  67. w.setWindowIcon(QIcon(Opl::Assets::APP_ICON_FILLED));
  68. //w.showMaximized();
  69. w.show();
  70. return openPilotLog.exec();
  71. }