firstrundialog.h 5.2 KB

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