Common: Add title, modal information to ProgressCallback

This commit is contained in:
Connor McLaughlin 2020-08-06 19:32:53 +10:00
parent 8c1a72f640
commit 6e586311e8
6 changed files with 65 additions and 48 deletions

View File

@ -93,6 +93,18 @@ bool ProgressCallback::DisplayFormattedModalConfirmation(const char* format, ...
return ModalConfirmation(str); return ModalConfirmation(str);
} }
void ProgressCallback::DisplayFormattedModalInformation(const char* format, ...)
{
SmallString str;
va_list ap;
va_start(ap, format);
str.FormatVA(format, ap);
va_end(ap);
ModalInformation(str);
}
void ProgressCallback::UpdateProgressFromStream(ByteStream* pStream) void ProgressCallback::UpdateProgressFromStream(ByteStream* pStream)
{ {
u32 streamSize = (u32)pStream->GetSize(); u32 streamSize = (u32)pStream->GetSize();
@ -112,6 +124,7 @@ public:
bool IsCancellable() const override { return false; } bool IsCancellable() const override { return false; }
void SetCancellable(bool cancellable) override {} void SetCancellable(bool cancellable) override {}
void SetTitle(const char* title) override {}
void SetStatusText(const char* statusText) override {} void SetStatusText(const char* statusText) override {}
void SetProgressRange(u32 range) override {} void SetProgressRange(u32 range) override {}
void SetProgressValue(u32 value) override {} void SetProgressValue(u32 value) override {}
@ -128,12 +141,7 @@ public:
Log_InfoPrint(message); Log_InfoPrint(message);
return false; return false;
} }
u32 ModalPrompt(const char* message, u32 nOptions, ...) override void ModalInformation(const char* message) override { Log_InfoPrint(message); }
{
DebugAssert(nOptions > 0);
Log_InfoPrint(message);
return 0;
}
}; };
static NullProgressCallbacks s_nullProgressCallbacks; static NullProgressCallbacks s_nullProgressCallbacks;
@ -264,6 +272,13 @@ void ConsoleProgressCallback::SetCancellable(bool cancellable)
Redraw(false); Redraw(false);
} }
void ConsoleProgressCallback::SetTitle(const char* title)
{
Clear();
std::fprintf(stdout, "== %s ==\n", title);
Redraw(false);
}
void ConsoleProgressCallback::SetStatusText(const char* text) void ConsoleProgressCallback::SetStatusText(const char* text)
{ {
BaseProgressCallback::SetStatusText(text); BaseProgressCallback::SetStatusText(text);
@ -387,11 +402,9 @@ bool ConsoleProgressCallback::ModalConfirmation(const char* message)
return false; return false;
} }
u32 ConsoleProgressCallback::ModalPrompt(const char* message, u32 num_options, ...) void ConsoleProgressCallback::ModalInformation(const char* message)
{ {
Clear(); Clear();
DebugAssert(num_options > 0);
Log_InfoPrint(message); Log_InfoPrint(message);
Redraw(false); Redraw(false);
return 0;
} }

View File

@ -17,6 +17,7 @@ public:
virtual void SetCancellable(bool cancellable) = 0; virtual void SetCancellable(bool cancellable) = 0;
virtual void SetTitle(const char* title) = 0;
virtual void SetStatusText(const char* text) = 0; virtual void SetStatusText(const char* text) = 0;
virtual void SetProgressRange(u32 range) = 0; virtual void SetProgressRange(u32 range) = 0;
virtual void SetProgressValue(u32 value) = 0; virtual void SetProgressValue(u32 value) = 0;
@ -31,7 +32,7 @@ public:
virtual void ModalError(const char* message) = 0; virtual void ModalError(const char* message) = 0;
virtual bool ModalConfirmation(const char* message) = 0; virtual bool ModalConfirmation(const char* message) = 0;
virtual u32 ModalPrompt(const char* message, u32 num_options, ...) = 0; virtual void ModalInformation(const char* message) = 0;
void DisplayFormattedError(const char* format, ...); void DisplayFormattedError(const char* format, ...);
void DisplayFormattedWarning(const char* format, ...); void DisplayFormattedWarning(const char* format, ...);
@ -39,6 +40,7 @@ public:
void DisplayFormattedDebugMessage(const char* format, ...); void DisplayFormattedDebugMessage(const char* format, ...);
void DisplayFormattedModalError(const char* format, ...); void DisplayFormattedModalError(const char* format, ...);
bool DisplayFormattedModalConfirmation(const char* format, ...); bool DisplayFormattedModalConfirmation(const char* format, ...);
void DisplayFormattedModalInformation(const char* format, ...);
void UpdateProgressFromStream(ByteStream* stream); void UpdateProgressFromStream(ByteStream* stream);
@ -86,7 +88,7 @@ protected:
State* m_saved_state; State* m_saved_state;
}; };
class ConsoleProgressCallback : public BaseProgressCallback class ConsoleProgressCallback final : public BaseProgressCallback
{ {
public: public:
static const u32 COLUMNS = 78; static const u32 COLUMNS = 78;
@ -95,22 +97,23 @@ public:
ConsoleProgressCallback(); ConsoleProgressCallback();
~ConsoleProgressCallback(); ~ConsoleProgressCallback();
virtual void PushState() override; void PushState() override;
virtual void PopState() override; void PopState() override;
virtual void SetCancellable(bool cancellable) override; void SetCancellable(bool cancellable) override;
virtual void SetStatusText(const char* text) override; void SetTitle(const char* title) override;
virtual void SetProgressRange(u32 range) override; void SetStatusText(const char* text) override;
virtual void SetProgressValue(u32 value) override; void SetProgressRange(u32 range) override;
void SetProgressValue(u32 value) override;
virtual void DisplayError(const char* message) override; void DisplayError(const char* message) override;
virtual void DisplayWarning(const char* message) override; void DisplayWarning(const char* message) override;
virtual void DisplayInformation(const char* message) override; void DisplayInformation(const char* message) override;
virtual void DisplayDebugMessage(const char* message) override; void DisplayDebugMessage(const char* message) override;
virtual void ModalError(const char* message) override; void ModalError(const char* message) override;
virtual bool ModalConfirmation(const char* message) override; bool ModalConfirmation(const char* message) override;
virtual u32 ModalPrompt(const char* message, u32 num_options, ...) override; void ModalInformation(const char* message) override;
private: private:
void Clear(); void Clear();

View File

@ -18,6 +18,11 @@ void HostInterfaceProgressCallback::SetCancellable(bool cancellable)
Redraw(true); Redraw(true);
} }
void HostInterfaceProgressCallback::SetTitle(const char* title)
{
// todo?
}
void HostInterfaceProgressCallback::SetStatusText(const char* text) void HostInterfaceProgressCallback::SetStatusText(const char* text)
{ {
BaseProgressCallback::SetStatusText(text); BaseProgressCallback::SetStatusText(text);
@ -64,15 +69,20 @@ void HostInterfaceProgressCallback::DisplayInformation(const char* message) { Lo
void HostInterfaceProgressCallback::DisplayDebugMessage(const char* message) { Log_DevPrint(message); } void HostInterfaceProgressCallback::DisplayDebugMessage(const char* message) { Log_DevPrint(message); }
void HostInterfaceProgressCallback::ModalError(const char* message) { g_host_interface->ReportError(message); } void HostInterfaceProgressCallback::ModalError(const char* message)
{
Log_ErrorPrint(message);
g_host_interface->ReportError(message);
}
bool HostInterfaceProgressCallback::ModalConfirmation(const char* message) bool HostInterfaceProgressCallback::ModalConfirmation(const char* message)
{ {
Log_InfoPrint(message);
return g_host_interface->ConfirmMessage(message); return g_host_interface->ConfirmMessage(message);
} }
u32 HostInterfaceProgressCallback::ModalPrompt(const char* message, u32 num_options, ...) void HostInterfaceProgressCallback::ModalInformation(const char* message)
{ {
Log_InfoPrint(message); Log_InfoPrint(message);
return 0; g_host_interface->ReportMessage(message);
} }

View File

@ -2,7 +2,7 @@
#include "common/progress_callback.h" #include "common/progress_callback.h"
#include "host_interface.h" #include "host_interface.h"
class HostInterfaceProgressCallback : public BaseProgressCallback class HostInterfaceProgressCallback final : public BaseProgressCallback
{ {
public: public:
HostInterfaceProgressCallback(); HostInterfaceProgressCallback();
@ -11,6 +11,7 @@ public:
void PopState() override; void PopState() override;
void SetCancellable(bool cancellable) override; void SetCancellable(bool cancellable) override;
void SetTitle(const char* title) override;
void SetStatusText(const char* text) override; void SetStatusText(const char* text) override;
void SetProgressRange(u32 range) override; void SetProgressRange(u32 range) override;
void SetProgressValue(u32 value) override; void SetProgressValue(u32 value) override;
@ -22,7 +23,7 @@ public:
void ModalError(const char* message) override; void ModalError(const char* message) override;
bool ModalConfirmation(const char* message) override; bool ModalConfirmation(const char* message) override;
u32 ModalPrompt(const char* message, u32 num_options, ...) override; void ModalInformation(const char* message) override;
private: private:
void Redraw(bool force); void Redraw(bool force);

View File

@ -29,6 +29,11 @@ void QtProgressCallback::SetCancellable(bool cancellable)
m_dialog.setCancelButtonText(cancellable ? tr("Cancel") : QString()); m_dialog.setCancelButtonText(cancellable ? tr("Cancel") : QString());
} }
void QtProgressCallback::SetTitle(const char* title)
{
m_dialog.setWindowTitle(QString::fromUtf8(title));
}
void QtProgressCallback::SetStatusText(const char* text) void QtProgressCallback::SetStatusText(const char* text)
{ {
BaseProgressCallback::SetStatusText(text); BaseProgressCallback::SetStatusText(text);
@ -83,23 +88,7 @@ bool QtProgressCallback::ModalConfirmation(const char* message)
QMessageBox::No) == QMessageBox::Yes); QMessageBox::No) == QMessageBox::Yes);
} }
u32 QtProgressCallback::ModalPrompt(const char* message, u32 num_options, ...) void QtProgressCallback::ModalInformation(const char* message)
{ {
enum : u32 QMessageBox::information(&m_dialog, tr("Information"), QString::fromUtf8(message));
{
MAX_OPTIONS = 3,
};
std::array<QString, MAX_OPTIONS> options;
std::va_list ap;
va_start(ap, num_options);
for (u32 i = 0; i < num_options && i < MAX_OPTIONS; i++)
options[i] = QString::fromUtf8(va_arg(ap, const char*));
va_end(ap);
return static_cast<u32>(QMessageBox::question(&m_dialog, tr("Question"), QString::fromUtf8(message), options[0],
options[1], options[2], 0, 0));
} }

View File

@ -13,6 +13,7 @@ public:
bool IsCancelled() const override; bool IsCancelled() const override;
void SetCancellable(bool cancellable) override; void SetCancellable(bool cancellable) override;
void SetTitle(const char* title) override;
void SetStatusText(const char* text) override; void SetStatusText(const char* text) override;
void SetProgressRange(u32 range) override; void SetProgressRange(u32 range) override;
void SetProgressValue(u32 value) override; void SetProgressValue(u32 value) override;
@ -24,7 +25,7 @@ public:
void ModalError(const char* message) override; void ModalError(const char* message) override;
bool ModalConfirmation(const char* message) override; bool ModalConfirmation(const char* message) override;
u32 ModalPrompt(const char* message, u32 num_options, ...) override; void ModalInformation(const char* message) override;
private: private:
QProgressDialog m_dialog; QProgressDialog m_dialog;