gamelistrefreshthread.h (1490B)
1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> 2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) 3 4 #pragma once 5 6 #include <QtCore/QSemaphore> 7 #include <QtCore/QThread> 8 9 #include "common/progress_callback.h" 10 #include "common/timer.h" 11 12 class GameListRefreshThread; 13 14 class AsyncRefreshProgressCallback : public ProgressCallback 15 { 16 public: 17 AsyncRefreshProgressCallback(GameListRefreshThread* parent); 18 19 float timeSinceStart() const; 20 21 void Cancel(); 22 23 void PushState() override; 24 void PopState() override; 25 26 void SetStatusText(const std::string_view text) override; 27 void SetProgressRange(u32 range) override; 28 void SetProgressValue(u32 value) override; 29 30 void ModalError(const std::string_view message) override; 31 bool ModalConfirmation(const std::string_view message) override; 32 void ModalInformation(const std::string_view message) override; 33 34 private: 35 void fireUpdate(); 36 37 GameListRefreshThread* m_parent; 38 Common::Timer m_start_time; 39 QString m_status_text; 40 int m_last_range = 1; 41 int m_last_value = 0; 42 }; 43 44 class GameListRefreshThread final : public QThread 45 { 46 Q_OBJECT 47 48 public: 49 GameListRefreshThread(bool invalidate_cache); 50 ~GameListRefreshThread(); 51 52 float timeSinceStart() const; 53 54 void cancel(); 55 56 Q_SIGNALS: 57 void refreshProgress(const QString& status, int current, int total, float time); 58 void refreshComplete(); 59 60 protected: 61 void run(); 62 63 private: 64 AsyncRefreshProgressCallback m_progress; 65 bool m_invalidate_cache; 66 };