2024-07-19 04:49:12 +00:00
|
|
|
// SPDX-FileCopyrightText: 2019-2024 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-07-21 14:03:01 +00:00
|
|
|
#include "host_interface_progress_callback.h"
|
|
|
|
#include "common/log.h"
|
2022-07-11 13:03:29 +00:00
|
|
|
#include "host.h"
|
2020-07-21 14:03:01 +00:00
|
|
|
Log_SetChannel(HostInterfaceProgressCallback);
|
|
|
|
|
2024-07-19 04:49:12 +00:00
|
|
|
HostInterfaceProgressCallback::HostInterfaceProgressCallback() : ProgressCallback()
|
2023-09-20 13:49:14 +00:00
|
|
|
{
|
|
|
|
}
|
2020-07-21 14:03:01 +00:00
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
void HostInterfaceProgressCallback::PushState()
|
|
|
|
{
|
2024-07-19 04:49:12 +00:00
|
|
|
ProgressCallback::PushState();
|
2022-07-11 13:03:29 +00:00
|
|
|
}
|
2020-07-21 14:03:01 +00:00
|
|
|
|
|
|
|
void HostInterfaceProgressCallback::PopState()
|
|
|
|
{
|
2024-07-19 04:49:12 +00:00
|
|
|
ProgressCallback::PopState();
|
2020-07-21 14:03:01 +00:00
|
|
|
Redraw(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HostInterfaceProgressCallback::SetCancellable(bool cancellable)
|
|
|
|
{
|
2024-07-19 04:49:12 +00:00
|
|
|
ProgressCallback::SetCancellable(cancellable);
|
2020-07-21 14:03:01 +00:00
|
|
|
Redraw(true);
|
|
|
|
}
|
|
|
|
|
2024-07-19 04:49:12 +00:00
|
|
|
void HostInterfaceProgressCallback::SetTitle(const std::string_view title)
|
2020-08-06 09:32:53 +00:00
|
|
|
{
|
|
|
|
// todo?
|
|
|
|
}
|
|
|
|
|
2024-07-19 04:49:12 +00:00
|
|
|
void HostInterfaceProgressCallback::SetStatusText(const std::string_view text)
|
2020-07-21 14:03:01 +00:00
|
|
|
{
|
2024-07-19 04:49:12 +00:00
|
|
|
ProgressCallback::SetStatusText(text);
|
2020-07-21 14:03:01 +00:00
|
|
|
Redraw(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HostInterfaceProgressCallback::SetProgressRange(u32 range)
|
|
|
|
{
|
|
|
|
u32 last_range = m_progress_range;
|
|
|
|
|
2024-07-19 04:49:12 +00:00
|
|
|
ProgressCallback::SetProgressRange(range);
|
2020-07-21 14:03:01 +00:00
|
|
|
|
|
|
|
if (m_progress_range != last_range)
|
|
|
|
Redraw(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HostInterfaceProgressCallback::SetProgressValue(u32 value)
|
|
|
|
{
|
|
|
|
u32 lastValue = m_progress_value;
|
|
|
|
|
2024-07-19 04:49:12 +00:00
|
|
|
ProgressCallback::SetProgressValue(value);
|
2020-07-21 14:03:01 +00:00
|
|
|
|
|
|
|
if (m_progress_value != lastValue)
|
|
|
|
Redraw(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HostInterfaceProgressCallback::Redraw(bool force)
|
|
|
|
{
|
2023-12-14 06:50:07 +00:00
|
|
|
if (m_last_progress_percent < 0 && m_open_time.GetTimeSeconds() < m_open_delay)
|
|
|
|
return;
|
|
|
|
|
2020-07-21 14:03:01 +00:00
|
|
|
const int percent =
|
|
|
|
static_cast<int>((static_cast<float>(m_progress_value) / static_cast<float>(m_progress_range)) * 100.0f);
|
|
|
|
if (percent == m_last_progress_percent && !force)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_last_progress_percent = percent;
|
2023-09-20 13:49:14 +00:00
|
|
|
Host::DisplayLoadingScreen(m_status_text.c_str(), 0, static_cast<int>(m_progress_range),
|
|
|
|
static_cast<int>(m_progress_value));
|
2020-07-21 14:03:01 +00:00
|
|
|
}
|
|
|
|
|
2024-07-19 04:49:12 +00:00
|
|
|
void HostInterfaceProgressCallback::ModalError(const std::string_view message)
|
2020-08-06 09:32:53 +00:00
|
|
|
{
|
2024-05-23 10:55:28 +00:00
|
|
|
ERROR_LOG(message);
|
2022-07-11 13:03:29 +00:00
|
|
|
Host::ReportErrorAsync("Error", message);
|
2020-08-06 09:32:53 +00:00
|
|
|
}
|
2020-07-21 14:03:01 +00:00
|
|
|
|
2024-07-19 04:49:12 +00:00
|
|
|
bool HostInterfaceProgressCallback::ModalConfirmation(const std::string_view message)
|
2020-07-21 14:03:01 +00:00
|
|
|
{
|
2024-05-23 10:55:28 +00:00
|
|
|
INFO_LOG(message);
|
2022-07-11 13:03:29 +00:00
|
|
|
return Host::ConfirmMessage("Confirm", message);
|
2020-07-21 14:03:01 +00:00
|
|
|
}
|