LCOV - code coverage report
Current view: top level - src/utilities - UpdateChecker.h (source / functions) Coverage Total Hit
Test: coverage.info.cleaned Lines: 100.0 % 1 1
Test Date: 2026-03-23 10:19:47 Functions: 50.0 % 2 1

            Line data    Source code
       1              : #ifndef UPDATECHECKER_H
       2              : #define UPDATECHECKER_H
       3              : 
       4              : #include <QObject>
       5              : #include <QTimer>
       6              : #include <QUrl>
       7              : #include <QSettings>
       8              : 
       9              : #include "../FangObject.h"
      10              : #include "../parser/NewsParser.h"
      11              : #include "SettingsInterface.h"
      12              : 
      13              : /*!
      14              :     \brief Checks for application updates by fetching a release feed.
      15              : 
      16              :     On application start and every 24 hours, fetches the Fang release feed
      17              :     and compares the latest version to the current application version.
      18              :     Emits updateAvailable() if a newer version is found.
      19              :  */
      20              : class UpdateChecker : public FangObject
      21              : {
      22              :     Q_OBJECT
      23              : 
      24              : public:
      25              :     /*!
      26              :         \param parent Parent QObject.
      27              :         \param parser Optional parser for dependency injection (used for testing).
      28              :                       If this is provided the caller is responsible for its lifecycle.
      29              :         \param settings Optional settings for dependency injection (used for testing).
      30              :                         If null, uses FangApp::instance()->getSettings().
      31              :      */
      32              :     explicit UpdateChecker(QObject *parent = nullptr,
      33              :                            ParserInterface* parser = nullptr,
      34              :                            SettingsInterface* settings = nullptr);
      35           22 :     inline virtual ~UpdateChecker() = default;
      36              : 
      37              :     /*!
      38              :         \brief Starts the update checker.
      39              :         Performs an immediate check and sets up periodic checking.
      40              :      */
      41              :     void start();
      42              : 
      43              :     /*!
      44              :         \brief Performs an update check now.
      45              :      */
      46              :     void checkNow();
      47              : 
      48              :     /*!
      49              :         \brief Returns the latest version found, or empty string if none.
      50              :      */
      51              :     QString latestVersion() const { return _latestVersion; }
      52              : 
      53              :     /*!
      54              :         \brief Returns true if an update is available.
      55              :      */
      56              :     bool isUpdateAvailable() const { return _updateAvailable; }
      57              : 
      58              : signals:
      59              :     /*!
      60              :         \brief Emitted when a newer version is available.
      61              :         \param newVersion The version string of the new release.
      62              :      */
      63              :     void updateAvailable(const QString& newVersion);
      64              : 
      65              : private slots:
      66              :     void onParserDone();
      67              : 
      68              : protected:
      69              :     /*!
      70              :         \brief Extracts version string from a feed item title.
      71              :         Expected format: "Fang X.Y.Z" or "Fang X.Y.Z-beta"
      72              :         \param title The feed item title.
      73              :         \return The version string, or empty if not found.
      74              :      */
      75              :     QString extractVersion(const QString& title);
      76              : 
      77              :     /*!
      78              :         \brief Compares two version strings.
      79              :         \return true if newVersion is greater than currentVersion.
      80              :      */
      81              :     bool isNewerVersion(const QString& currentVersion, const QString& newVersion);
      82              : 
      83              : private:
      84              : 
      85              :     static const QUrl UPDATE_FEED_URL;
      86              :     static const int CHECK_INTERVAL_MS; // 24 hours in milliseconds
      87              : 
      88              :     ParserInterface* parser;
      89              :     SettingsInterface* settingsInterface;  // Injected or from FangApp
      90              :     QTimer timer;
      91              :     QString _latestVersion;
      92              :     bool _updateAvailable;
      93              : };
      94              : 
      95              : #endif // UPDATECHECKER_H
        

Generated by: LCOV version 2.0-1