mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-14 20:55:46 -04:00
ProgressCallback: Eliminate redundancy and drop C format strings
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#include "gamelistrefreshthread.h"
|
||||
#include "qtutils.h"
|
||||
|
||||
#include "core/game_list.h"
|
||||
|
||||
@ -11,7 +12,9 @@
|
||||
|
||||
#include <QtWidgets/QMessageBox>
|
||||
|
||||
AsyncRefreshProgressCallback::AsyncRefreshProgressCallback(GameListRefreshThread* parent) : m_parent(parent) {}
|
||||
AsyncRefreshProgressCallback::AsyncRefreshProgressCallback(GameListRefreshThread* parent) : m_parent(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void AsyncRefreshProgressCallback::Cancel()
|
||||
{
|
||||
@ -19,9 +22,9 @@ void AsyncRefreshProgressCallback::Cancel()
|
||||
m_cancelled = true;
|
||||
}
|
||||
|
||||
void AsyncRefreshProgressCallback::SetStatusText(const char* text)
|
||||
void AsyncRefreshProgressCallback::SetStatusText(const std::string_view text)
|
||||
{
|
||||
QString new_text(QString::fromUtf8(text));
|
||||
const QString new_text = QtUtils::StringViewToQString(text);
|
||||
if (new_text == m_status_text)
|
||||
return;
|
||||
|
||||
@ -31,7 +34,7 @@ void AsyncRefreshProgressCallback::SetStatusText(const char* text)
|
||||
|
||||
void AsyncRefreshProgressCallback::SetProgressRange(u32 range)
|
||||
{
|
||||
BaseProgressCallback::SetProgressRange(range);
|
||||
ProgressCallback::SetProgressRange(range);
|
||||
if (static_cast<int>(m_progress_range) == m_last_range)
|
||||
return;
|
||||
|
||||
@ -41,7 +44,7 @@ void AsyncRefreshProgressCallback::SetProgressRange(u32 range)
|
||||
|
||||
void AsyncRefreshProgressCallback::SetProgressValue(u32 value)
|
||||
{
|
||||
BaseProgressCallback::SetProgressValue(value);
|
||||
ProgressCallback::SetProgressValue(value);
|
||||
if (static_cast<int>(m_progress_value) == m_last_value)
|
||||
return;
|
||||
|
||||
@ -49,41 +52,20 @@ void AsyncRefreshProgressCallback::SetProgressValue(u32 value)
|
||||
fireUpdate();
|
||||
}
|
||||
|
||||
void AsyncRefreshProgressCallback::SetTitle(const char* title) {}
|
||||
|
||||
void AsyncRefreshProgressCallback::DisplayError(const char* message)
|
||||
void AsyncRefreshProgressCallback::ModalError(const std::string_view message)
|
||||
{
|
||||
QMessageBox::critical(nullptr, QStringLiteral("Error"), QString::fromUtf8(message));
|
||||
QMessageBox::critical(nullptr, QStringLiteral("Error"), QtUtils::StringViewToQString(message));
|
||||
}
|
||||
|
||||
void AsyncRefreshProgressCallback::DisplayWarning(const char* message)
|
||||
bool AsyncRefreshProgressCallback::ModalConfirmation(const std::string_view message)
|
||||
{
|
||||
QMessageBox::warning(nullptr, QStringLiteral("Warning"), QString::fromUtf8(message));
|
||||
return QMessageBox::question(nullptr, QStringLiteral("Question"), QtUtils::StringViewToQString(message)) ==
|
||||
QMessageBox::Yes;
|
||||
}
|
||||
|
||||
void AsyncRefreshProgressCallback::DisplayInformation(const char* message)
|
||||
void AsyncRefreshProgressCallback::ModalInformation(const std::string_view message)
|
||||
{
|
||||
QMessageBox::information(nullptr, QStringLiteral("Information"), QString::fromUtf8(message));
|
||||
}
|
||||
|
||||
void AsyncRefreshProgressCallback::DisplayDebugMessage(const char* message)
|
||||
{
|
||||
Log::Write("AsyncRefreshProgressCallback", "", LOGLEVEL_DEV, message);
|
||||
}
|
||||
|
||||
void AsyncRefreshProgressCallback::ModalError(const char* message)
|
||||
{
|
||||
QMessageBox::critical(nullptr, QStringLiteral("Error"), QString::fromUtf8(message));
|
||||
}
|
||||
|
||||
bool AsyncRefreshProgressCallback::ModalConfirmation(const char* message)
|
||||
{
|
||||
return QMessageBox::question(nullptr, QStringLiteral("Question"), QString::fromUtf8(message)) == QMessageBox::Yes;
|
||||
}
|
||||
|
||||
void AsyncRefreshProgressCallback::ModalInformation(const char* message)
|
||||
{
|
||||
QMessageBox::information(nullptr, QStringLiteral("Information"), QString::fromUtf8(message));
|
||||
QMessageBox::information(nullptr, QStringLiteral("Information"), QtUtils::StringViewToQString(message));
|
||||
}
|
||||
|
||||
void AsyncRefreshProgressCallback::fireUpdate()
|
||||
|
@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#pragma once
|
||||
@ -11,24 +11,20 @@
|
||||
|
||||
class GameListRefreshThread;
|
||||
|
||||
class AsyncRefreshProgressCallback : public BaseProgressCallback
|
||||
class AsyncRefreshProgressCallback : public ProgressCallback
|
||||
{
|
||||
public:
|
||||
AsyncRefreshProgressCallback(GameListRefreshThread* parent);
|
||||
|
||||
void Cancel();
|
||||
|
||||
void SetStatusText(const char* text) override;
|
||||
void SetStatusText(const std::string_view text) override;
|
||||
void SetProgressRange(u32 range) override;
|
||||
void SetProgressValue(u32 value) override;
|
||||
void SetTitle(const char* title) 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;
|
||||
|
||||
void ModalError(const std::string_view message) override;
|
||||
bool ModalConfirmation(const std::string_view message) override;
|
||||
void ModalInformation(const std::string_view message) override;
|
||||
|
||||
private:
|
||||
void fireUpdate();
|
||||
|
@ -1,8 +1,11 @@
|
||||
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#include "qtprogresscallback.h"
|
||||
#include "qtutils.h"
|
||||
|
||||
#include "common/assert.h"
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
@ -27,27 +30,27 @@ void QtModalProgressCallback::SetCancellable(bool cancellable)
|
||||
if (m_cancellable == cancellable)
|
||||
return;
|
||||
|
||||
BaseProgressCallback::SetCancellable(cancellable);
|
||||
ProgressCallback::SetCancellable(cancellable);
|
||||
m_dialog.setCancelButtonText(cancellable ? tr("Cancel") : QString());
|
||||
}
|
||||
|
||||
void QtModalProgressCallback::SetTitle(const char* title)
|
||||
void QtModalProgressCallback::SetTitle(const std::string_view title)
|
||||
{
|
||||
m_dialog.setWindowTitle(QString::fromUtf8(title));
|
||||
m_dialog.setWindowTitle(QtUtils::StringViewToQString(title));
|
||||
}
|
||||
|
||||
void QtModalProgressCallback::SetStatusText(const char* text)
|
||||
void QtModalProgressCallback::SetStatusText(const std::string_view text)
|
||||
{
|
||||
BaseProgressCallback::SetStatusText(text);
|
||||
ProgressCallback::SetStatusText(text);
|
||||
checkForDelayedShow();
|
||||
|
||||
if (m_dialog.isVisible())
|
||||
m_dialog.setLabelText(QString::fromUtf8(text));
|
||||
m_dialog.setLabelText(QtUtils::StringViewToQString(text));
|
||||
}
|
||||
|
||||
void QtModalProgressCallback::SetProgressRange(u32 range)
|
||||
{
|
||||
BaseProgressCallback::SetProgressRange(range);
|
||||
ProgressCallback::SetProgressRange(range);
|
||||
checkForDelayedShow();
|
||||
|
||||
if (m_dialog.isVisible())
|
||||
@ -56,7 +59,7 @@ void QtModalProgressCallback::SetProgressRange(u32 range)
|
||||
|
||||
void QtModalProgressCallback::SetProgressValue(u32 value)
|
||||
{
|
||||
BaseProgressCallback::SetProgressValue(value);
|
||||
ProgressCallback::SetProgressValue(value);
|
||||
checkForDelayedShow();
|
||||
|
||||
if (m_dialog.isVisible() && static_cast<u32>(m_dialog.value()) != m_progress_range)
|
||||
@ -65,40 +68,20 @@ void QtModalProgressCallback::SetProgressValue(u32 value)
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
|
||||
void QtModalProgressCallback::DisplayError(const char* message)
|
||||
void QtModalProgressCallback::ModalError(const std::string_view message)
|
||||
{
|
||||
qWarning() << message;
|
||||
QMessageBox::critical(&m_dialog, tr("Error"), QtUtils::StringViewToQString(message));
|
||||
}
|
||||
|
||||
void QtModalProgressCallback::DisplayWarning(const char* message)
|
||||
bool QtModalProgressCallback::ModalConfirmation(const std::string_view message)
|
||||
{
|
||||
qWarning() << message;
|
||||
}
|
||||
|
||||
void QtModalProgressCallback::DisplayInformation(const char* message)
|
||||
{
|
||||
qWarning() << message;
|
||||
}
|
||||
|
||||
void QtModalProgressCallback::DisplayDebugMessage(const char* message)
|
||||
{
|
||||
qWarning() << message;
|
||||
}
|
||||
|
||||
void QtModalProgressCallback::ModalError(const char* message)
|
||||
{
|
||||
QMessageBox::critical(&m_dialog, tr("Error"), QString::fromUtf8(message));
|
||||
}
|
||||
|
||||
bool QtModalProgressCallback::ModalConfirmation(const char* message)
|
||||
{
|
||||
return (QMessageBox::question(&m_dialog, tr("Question"), QString::fromUtf8(message), QMessageBox::Yes,
|
||||
return (QMessageBox::question(&m_dialog, tr("Question"), QtUtils::StringViewToQString(message), QMessageBox::Yes,
|
||||
QMessageBox::No) == QMessageBox::Yes);
|
||||
}
|
||||
|
||||
void QtModalProgressCallback::ModalInformation(const char* message)
|
||||
void QtModalProgressCallback::ModalInformation(const std::string_view message)
|
||||
{
|
||||
QMessageBox::information(&m_dialog, tr("Information"), QString::fromUtf8(message));
|
||||
QMessageBox::information(&m_dialog, tr("Information"), QtUtils::StringViewToQString(message));
|
||||
}
|
||||
|
||||
void QtModalProgressCallback::dialogCancelled()
|
||||
@ -120,7 +103,9 @@ void QtModalProgressCallback::checkForDelayedShow()
|
||||
}
|
||||
|
||||
// NOTE: We deliberately don't set the thread parent, because otherwise we can't move it.
|
||||
QtAsyncProgressThread::QtAsyncProgressThread(QWidget* parent) : QThread() {}
|
||||
QtAsyncProgressThread::QtAsyncProgressThread(QWidget* parent) : QThread()
|
||||
{
|
||||
}
|
||||
|
||||
QtAsyncProgressThread::~QtAsyncProgressThread() = default;
|
||||
|
||||
@ -134,66 +119,46 @@ void QtAsyncProgressThread::SetCancellable(bool cancellable)
|
||||
if (m_cancellable == cancellable)
|
||||
return;
|
||||
|
||||
BaseProgressCallback::SetCancellable(cancellable);
|
||||
ProgressCallback::SetCancellable(cancellable);
|
||||
}
|
||||
|
||||
void QtAsyncProgressThread::SetTitle(const char* title)
|
||||
void QtAsyncProgressThread::SetTitle(const std::string_view title)
|
||||
{
|
||||
emit titleUpdated(QString::fromUtf8(title));
|
||||
emit titleUpdated(QtUtils::StringViewToQString(title));
|
||||
}
|
||||
|
||||
void QtAsyncProgressThread::SetStatusText(const char* text)
|
||||
void QtAsyncProgressThread::SetStatusText(const std::string_view text)
|
||||
{
|
||||
BaseProgressCallback::SetStatusText(text);
|
||||
emit statusUpdated(QString::fromUtf8(text));
|
||||
ProgressCallback::SetStatusText(text);
|
||||
emit statusUpdated(QtUtils::StringViewToQString(text));
|
||||
}
|
||||
|
||||
void QtAsyncProgressThread::SetProgressRange(u32 range)
|
||||
{
|
||||
BaseProgressCallback::SetProgressRange(range);
|
||||
ProgressCallback::SetProgressRange(range);
|
||||
emit progressUpdated(static_cast<int>(m_progress_value), static_cast<int>(m_progress_range));
|
||||
}
|
||||
|
||||
void QtAsyncProgressThread::SetProgressValue(u32 value)
|
||||
{
|
||||
BaseProgressCallback::SetProgressValue(value);
|
||||
ProgressCallback::SetProgressValue(value);
|
||||
emit progressUpdated(static_cast<int>(m_progress_value), static_cast<int>(m_progress_range));
|
||||
}
|
||||
|
||||
void QtAsyncProgressThread::DisplayError(const char* message)
|
||||
void QtAsyncProgressThread::ModalError(const std::string_view message)
|
||||
{
|
||||
qWarning() << message;
|
||||
QMessageBox::critical(parentWidget(), tr("Error"), QtUtils::StringViewToQString(message));
|
||||
}
|
||||
|
||||
void QtAsyncProgressThread::DisplayWarning(const char* message)
|
||||
bool QtAsyncProgressThread::ModalConfirmation(const std::string_view message)
|
||||
{
|
||||
qWarning() << message;
|
||||
}
|
||||
|
||||
void QtAsyncProgressThread::DisplayInformation(const char* message)
|
||||
{
|
||||
qWarning() << message;
|
||||
}
|
||||
|
||||
void QtAsyncProgressThread::DisplayDebugMessage(const char* message)
|
||||
{
|
||||
qWarning() << message;
|
||||
}
|
||||
|
||||
void QtAsyncProgressThread::ModalError(const char* message)
|
||||
{
|
||||
QMessageBox::critical(parentWidget(), tr("Error"), QString::fromUtf8(message));
|
||||
}
|
||||
|
||||
bool QtAsyncProgressThread::ModalConfirmation(const char* message)
|
||||
{
|
||||
return (QMessageBox::question(parentWidget(), tr("Question"), QString::fromUtf8(message), QMessageBox::Yes,
|
||||
return (QMessageBox::question(parentWidget(), tr("Question"), QtUtils::StringViewToQString(message), QMessageBox::Yes,
|
||||
QMessageBox::No) == QMessageBox::Yes);
|
||||
}
|
||||
|
||||
void QtAsyncProgressThread::ModalInformation(const char* message)
|
||||
void QtAsyncProgressThread::ModalInformation(const std::string_view message)
|
||||
{
|
||||
QMessageBox::information(parentWidget(), tr("Information"), QString::fromUtf8(message));
|
||||
QMessageBox::information(parentWidget(), tr("Information"), QtUtils::StringViewToQString(message));
|
||||
}
|
||||
|
||||
void QtAsyncProgressThread::start()
|
||||
|
@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#pragma once
|
||||
@ -11,7 +11,7 @@
|
||||
#include <QtWidgets/QProgressDialog>
|
||||
#include <atomic>
|
||||
|
||||
class QtModalProgressCallback final : public QObject, public BaseProgressCallback
|
||||
class QtModalProgressCallback final : public QObject, public ProgressCallback
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -22,19 +22,14 @@ public:
|
||||
QProgressDialog& GetDialog() { return m_dialog; }
|
||||
|
||||
void SetCancellable(bool cancellable) override;
|
||||
void SetTitle(const char* title) override;
|
||||
void SetStatusText(const char* text) override;
|
||||
void SetTitle(const std::string_view title) override;
|
||||
void SetStatusText(const std::string_view 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;
|
||||
void ModalError(const std::string_view message) override;
|
||||
bool ModalConfirmation(const std::string_view message) override;
|
||||
void ModalInformation(const std::string_view message) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void dialogCancelled();
|
||||
@ -47,7 +42,7 @@ private:
|
||||
float m_show_delay;
|
||||
};
|
||||
|
||||
class QtAsyncProgressThread : public QThread, public BaseProgressCallback
|
||||
class QtAsyncProgressThread : public QThread, public ProgressCallback
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -58,19 +53,14 @@ public:
|
||||
bool IsCancelled() const override;
|
||||
|
||||
void SetCancellable(bool cancellable) override;
|
||||
void SetTitle(const char* title) override;
|
||||
void SetStatusText(const char* text) override;
|
||||
void SetTitle(const std::string_view title) override;
|
||||
void SetStatusText(const std::string_view 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;
|
||||
void ModalError(const std::string_view message) override;
|
||||
bool ModalConfirmation(const std::string_view message) override;
|
||||
void ModalInformation(const std::string_view message) override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void titleUpdated(const QString& title);
|
||||
|
Reference in New Issue
Block a user