changelogcontents.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /***************************************************************************
  2. changelogcontents.h - Changelog
  3. ---------------------
  4. begin : Nov 2020
  5. copyright : (C) 2020 by Ivan Ivanov
  6. email : ivan@opengis.ch
  7. ***************************************************************************
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. ***************************************************************************/
  15. #ifndef CHANGELOGCONTENTS_H
  16. #define CHANGELOGCONTENTS_H
  17. #include <QObject>
  18. //! Obtain the QField changelog contents from the GitHub releases API.
  19. class ChangelogContents : public QObject
  20. {
  21. Q_OBJECT
  22. //! Holds the current changelog contents formatted as markdown.
  23. Q_PROPERTY( QString markdown READ markdown NOTIFY markdownChanged )
  24. //! Holds the current changelog contents status.
  25. Q_PROPERTY( Status status READ status NOTIFY statusChanged )
  26. public:
  27. //! Constructor
  28. explicit ChangelogContents( QObject *parent = nullptr );
  29. //! Changelog contents status.
  30. enum Status
  31. {
  32. //! Changelog has not been requested
  33. IdleStatus,
  34. //! Changelog has been requested, but still not received
  35. LoadingStatus,
  36. //! Changelog has been successfully generated
  37. SuccessStatus,
  38. //! Changelog has been requested, but failed to be generated
  39. ErrorStatus,
  40. };
  41. Q_ENUM( Status )
  42. /**
  43. * Initiates a HTTP request to obtain the changelog contents.
  44. * @see markdownChanged()
  45. * @see statusChanged()
  46. */
  47. Q_INVOKABLE void request();
  48. //! Returns the current changelog contents formatted as markdown. Null string if no changelog.
  49. QString markdown();
  50. //! Returns the current changelog contents status.
  51. Status status();
  52. signals:
  53. //! Emitted when the markdown contents has been changed.
  54. void markdownChanged();
  55. //! Emitted when the status has been changed.
  56. void statusChanged();
  57. private:
  58. //! Parses a given \a version string into a list of three numbers, e.g. 'v1.5.6-dev' to [1, 5, 6]. Returns an empty list if cannot be parsed.
  59. QList<int> parseVersion( const QString &version );
  60. //! Holds the current changelog contents formatted as markdown. Null string if no changelog.
  61. QString mMarkdown;
  62. //! Holds the current status.
  63. Status mStatus = Status::IdleStatus;
  64. };
  65. #endif // CHANGELOGCONTENTS_H