duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

qtprogresscallback.h (2279B)


      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 "common/progress_callback.h"
      7 #include "common/timer.h"
      8 
      9 #include <QtCore/QSemaphore>
     10 #include <QtCore/QThread>
     11 #include <QtWidgets/QProgressDialog>
     12 #include <atomic>
     13 
     14 class QtModalProgressCallback final : public QObject, public ProgressCallback
     15 {
     16   Q_OBJECT
     17 
     18 public:
     19   QtModalProgressCallback(QWidget* parent_widget, float show_delay = 0.0f);
     20   ~QtModalProgressCallback();
     21 
     22   QProgressDialog& GetDialog() { return m_dialog; }
     23 
     24   void SetCancellable(bool cancellable) override;
     25   void SetTitle(const std::string_view title) override;
     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 Q_SLOTS:
     35   void dialogCancelled();
     36 
     37 private:
     38   void checkForDelayedShow();
     39 
     40   QProgressDialog m_dialog;
     41   Common::Timer m_show_timer;
     42   float m_show_delay;
     43 };
     44 
     45 class QtAsyncProgressThread : public QThread, public ProgressCallback
     46 {
     47   Q_OBJECT
     48 
     49 public:
     50   QtAsyncProgressThread(QWidget* parent);
     51   ~QtAsyncProgressThread();
     52 
     53   bool IsCancelled() const override;
     54 
     55   void SetCancellable(bool cancellable) override;
     56   void SetTitle(const std::string_view title) override;
     57   void SetStatusText(const std::string_view text) override;
     58   void SetProgressRange(u32 range) override;
     59   void SetProgressValue(u32 value) override;
     60 
     61   void ModalError(const std::string_view message) override;
     62   bool ModalConfirmation(const std::string_view message) override;
     63   void ModalInformation(const std::string_view message) override;
     64 
     65 Q_SIGNALS:
     66   void titleUpdated(const QString& title);
     67   void statusUpdated(const QString& status);
     68   void progressUpdated(int value, int range);
     69   void threadStarting();
     70   void threadFinished();
     71 
     72 public Q_SLOTS:
     73   void start();
     74   void join();
     75 
     76 protected:
     77   virtual void runAsync() = 0;
     78   void run() final;
     79 
     80 private:
     81   QWidget* parentWidget() const;
     82 
     83   QSemaphore m_start_semaphore;
     84   QThread* m_starting_thread = nullptr;
     85 };