Use optional instead of hardcoded cancelled string

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2022-12-26 14:58:02 +00:00
parent bf04becc9e
commit 434f639b0c
3 changed files with 12 additions and 9 deletions

View File

@ -50,7 +50,7 @@
#include <DesktopServices.h>
#include <BuildConfig.h>
QString GuiUtil::uploadPaste(const QString &name, const QString &text, QWidget *parentWidget)
std::optional<QString> GuiUtil::uploadPaste(const QString &name, const QString &text, QWidget *parentWidget)
{
ProgressDialog dialog(parentWidget);
auto pasteTypeSetting = static_cast<PasteUpload::PasteType>(APPLICATION->settings()->get("PastebinType").toInt());
@ -63,7 +63,8 @@ QString GuiUtil::uploadPaste(const QString &name, const QString &text, QWidget *
else
baseUrl = pasteCustomAPIBaseSetting;
if (baseUrl.isValid()) {
if (baseUrl.isValid())
{
auto response = CustomMessageBox::selectable(parentWidget, QObject::tr("Confirm Upload"),
QObject::tr("You are about to upload \"%1\" to %2.\n"
"You should double-check for personal information.\n\n"
@ -73,7 +74,7 @@ QString GuiUtil::uploadPaste(const QString &name, const QString &text, QWidget *
->exec();
if (response != QMessageBox::Yes)
return "canceled";
return {};
}
}

View File

@ -1,10 +1,11 @@
#pragma once
#include <QWidget>
#include <optional>
namespace GuiUtil
{
QString uploadPaste(const QString &name, const QString &text, QWidget *parentWidget);
std::optional<QString> uploadPaste(const QString &name, const QString &text, QWidget *parentWidget);
void setClipboardText(const QString &text);
QStringList BrowseForFiles(QString context, QString caption, QString filter, QString defaultPath, QWidget *parentWidget);
QString BrowseForFile(QString context, QString caption, QString filter, QString defaultPath, QWidget *parentWidget);

View File

@ -283,17 +283,18 @@ void LogPage::on_btnPaste_clicked()
)
);
auto url = GuiUtil::uploadPaste(tr("Minecraft Log"), m_model->toPlainText(), this);
if(url == "canceled")
if(!url.has_value())
{
m_model->append(MessageLevel::Error, QString("Log upload canceled"));
}
else if(!url.isEmpty())
else if (url->isNull())
{
m_model->append(MessageLevel::Launcher, QString("Log uploaded to: %1").arg(url));
}
else {
m_model->append(MessageLevel::Error, QString("Log upload failed!"));
}
else
{
m_model->append(MessageLevel::Launcher, QString("Log uploaded to: %1").arg(url.value()));
}
}
void LogPage::on_btnCopy_clicked()