firstrundialog.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. *openPilotLog - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020-2023 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. #ifndef FIRSTRUNDIALOG_H
  19. #define FIRSTRUNDIALOG_H
  20. #include "src/database/currencyentry.h"
  21. #include <QDialog>
  22. #include <QButtonGroup>
  23. #include <QMessageBox>
  24. #include <QStringBuilder>
  25. #include <QDateEdit>
  26. namespace Ui {
  27. class FirstRunDialog;
  28. }
  29. /*!
  30. * \brief The FirstRunDialog is used as a set-up wizard for the application.
  31. * \details The Application does not ship with a database, it is created on the fly. This is the main purpose of the
  32. * FirstRunDialog. Apart from this main task, user details and preferences are gathered and saved using Settings.
  33. *
  34. * The Dialog contains a tabbed widget which guides the user through the set up process.
  35. *
  36. * ### 1 - Welcome
  37. *
  38. * In this tab, the user is greeted and has the option to import an existing database instead of creating a new one.
  39. *
  40. * ### 2 - Personal Data
  41. *
  42. * In this tab, the users personal data is collected, which is used to create the first Pilot Entry in the database.
  43. * ROW ID (1) identifies the logbook owner, which is also referred to as "self" in the application.
  44. *
  45. * ### 3 - Currencies
  46. *
  47. * In this tab, the user can enter the expiration dates of his licenses, medical or other currencies that he wishes to keep
  48. * track of. These are stored in the database within the currencies table.
  49. *
  50. * ### 4 - Flight Logging
  51. *
  52. * In this tab, the user can determine what the defualt selections for logging a new flight will be. These selections (Pilot Function,
  53. * Flight Rules,...) are stored in an INI file using the Settings class.
  54. *
  55. * ### 5 - Customization
  56. *
  57. * In this tab, the user can make selections regarding the application layout and theming, as well as with regards to how data is being
  58. * displayed. These settings are stored in an INI file using the Settings class.
  59. *
  60. * ### 6 - Finish / Database creation
  61. *
  62. * In this tab the user can select how the database is created. There are two options, either downloading database templates from the
  63. * github repository, or to fall back to a set of JSON files inclnuded in the application ressources (see templates.qrc). These built
  64. * in files are probably not as up-to-date, but enable the application to function if no internet connection is available or the links
  65. * to the online ressources are broken.
  66. *
  67. * For Debug purcposes, pressing <ctrl+t> will enable a line edit in which a different branch than main can be selected from which the
  68. * database templates are to be pulled.
  69. *
  70. *
  71. *
  72. * Upon successful completion of the FirstRunDialog, a Setting is written so that the dialog is not shown on subsequent runs.
  73. */
  74. class FirstRunDialog : public QDialog
  75. {
  76. Q_OBJECT
  77. public:
  78. explicit FirstRunDialog(QWidget *parent = nullptr);
  79. ~FirstRunDialog();
  80. private slots:
  81. void on_previousPushButton_clicked();
  82. void on_nextPushButton_clicked();
  83. void on_styleComboBox_currentTextChanged(const QString &new_style_setting);
  84. /*!
  85. * \brief Import an existing database instead of creating a new one
  86. */
  87. void on_importPushButton_clicked();
  88. private:
  89. Ui::FirstRunDialog *ui;
  90. bool useRessourceData;
  91. /*!
  92. * \brief finishSetup - once all the necessary data is entered by the user, this functions executes the steps necessary
  93. * to collect the data, process it and create the database
  94. */
  95. bool finishSetup();
  96. /*!
  97. * \brief writeSettings - collects input from the UI and writes the user selections to an INI file
  98. */
  99. void writeSettings();
  100. /*!
  101. * \brief setupDatabase - creates the sqlite database
  102. */
  103. bool setupDatabase();
  104. /*!
  105. * \brief createUserEntry - create the database entry for the logbook owner (identified by ROW_ID = 1)
  106. */
  107. bool createUserEntry();
  108. /*!
  109. * \brief setupPreviousExperienceEntry - set up a stub database entry for previous experience
  110. */
  111. bool setupPreviousExperienceEntry();
  112. /*!
  113. * \brief writeCurrencies - submits the user input to the currencies table in the database
  114. */
  115. bool writeCurrencies();
  116. /*!
  117. * \brief downloadTemplates - Downloads the airports and aircraft database as JSON files from github
  118. */
  119. bool downloadTemplates(QString branch_name);
  120. /*!
  121. * \brief verifyTemplates - run a MD5 checksum hash
  122. */
  123. bool verifyTemplates();
  124. protected:
  125. void reject() override;
  126. /*!
  127. * \brief Shows the debug widget by pressing <ctrl + t>
  128. */
  129. /*!
  130. * \brief keyPressEvent ctrl + t enables debug mode, showing the branch selector
  131. * which is used to select a git branch other than main for downloading the templates
  132. * \param keyEvent
  133. */
  134. void keyPressEvent(QKeyEvent* keyEvent) override;
  135. };
  136. #endif // FIRSTRUNDIALOG_H