2023-11-24 06:08:28 +00:00
|
|
|
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
|
2022-12-04 11:03:45 +00:00
|
|
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
|
|
|
|
2020-03-12 05:32:15 +00:00
|
|
|
#pragma once
|
2023-11-24 06:08:28 +00:00
|
|
|
|
2020-03-12 05:32:15 +00:00
|
|
|
#include "common/progress_callback.h"
|
2021-01-24 08:55:35 +00:00
|
|
|
#include "common/timer.h"
|
2023-11-24 06:08:28 +00:00
|
|
|
|
2022-09-13 10:29:17 +00:00
|
|
|
#include <QtCore/QSemaphore>
|
2023-11-24 06:08:28 +00:00
|
|
|
#include <QtCore/QThread>
|
2020-03-12 05:32:15 +00:00
|
|
|
#include <QtWidgets/QProgressDialog>
|
2022-09-13 10:29:17 +00:00
|
|
|
#include <atomic>
|
2020-03-12 05:32:15 +00:00
|
|
|
|
2022-09-13 10:29:17 +00:00
|
|
|
class QtModalProgressCallback final : public QObject, public BaseProgressCallback
|
2020-03-12 05:32:15 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-09-13 10:29:17 +00:00
|
|
|
QtModalProgressCallback(QWidget* parent_widget, float show_delay = 0.0f);
|
|
|
|
~QtModalProgressCallback();
|
2020-03-12 05:32:15 +00:00
|
|
|
|
2023-11-24 06:08:28 +00:00
|
|
|
QProgressDialog& GetDialog() { return m_dialog; }
|
2020-03-12 05:32:15 +00:00
|
|
|
|
|
|
|
void SetCancellable(bool cancellable) override;
|
2020-08-06 09:32:53 +00:00
|
|
|
void SetTitle(const char* title) override;
|
2020-03-12 05:32:15 +00:00
|
|
|
void SetStatusText(const char* text) override;
|
|
|
|
void SetProgressRange(u32 range) override;
|
|
|
|
void SetProgressValue(u32 value) override;
|
|
|
|
|
|
|
|
void DisplayError(const char* message) override;
|
|
|
|
void DisplayWarning(const char* message) override;
|
|
|
|
void DisplayInformation(const char* message) override;
|
|
|
|
void DisplayDebugMessage(const char* message) override;
|
|
|
|
|
|
|
|
void ModalError(const char* message) override;
|
|
|
|
bool ModalConfirmation(const char* message) override;
|
2020-08-06 09:32:53 +00:00
|
|
|
void ModalInformation(const char* message) override;
|
2020-03-12 05:32:15 +00:00
|
|
|
|
2023-11-24 06:08:28 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
void dialogCancelled();
|
|
|
|
|
2020-03-12 05:32:15 +00:00
|
|
|
private:
|
2021-01-24 08:55:35 +00:00
|
|
|
void checkForDelayedShow();
|
|
|
|
|
2020-03-12 05:32:15 +00:00
|
|
|
QProgressDialog m_dialog;
|
2021-01-24 08:55:35 +00:00
|
|
|
Common::Timer m_show_timer;
|
|
|
|
float m_show_delay;
|
2022-09-13 10:29:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class QtAsyncProgressThread : public QThread, public BaseProgressCallback
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
QtAsyncProgressThread(QWidget* parent);
|
|
|
|
~QtAsyncProgressThread();
|
|
|
|
|
|
|
|
bool IsCancelled() const override;
|
|
|
|
|
|
|
|
void SetCancellable(bool cancellable) override;
|
|
|
|
void SetTitle(const char* title) override;
|
|
|
|
void SetStatusText(const char* text) override;
|
|
|
|
void SetProgressRange(u32 range) override;
|
|
|
|
void SetProgressValue(u32 value) override;
|
|
|
|
|
|
|
|
void DisplayError(const char* message) override;
|
|
|
|
void DisplayWarning(const char* message) override;
|
|
|
|
void DisplayInformation(const char* message) override;
|
|
|
|
void DisplayDebugMessage(const char* message) override;
|
|
|
|
|
|
|
|
void ModalError(const char* message) override;
|
|
|
|
bool ModalConfirmation(const char* message) override;
|
|
|
|
void ModalInformation(const char* message) override;
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void titleUpdated(const QString& title);
|
|
|
|
void statusUpdated(const QString& status);
|
|
|
|
void progressUpdated(int value, int range);
|
|
|
|
void threadStarting();
|
|
|
|
void threadFinished();
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void start();
|
|
|
|
void join();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void runAsync() = 0;
|
|
|
|
void run() final;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QWidget* parentWidget() const;
|
|
|
|
|
|
|
|
QSemaphore m_start_semaphore;
|
|
|
|
QThread* m_starting_thread = nullptr;
|
|
|
|
};
|