diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-11-25 00:47:45 -0500 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-11-25 00:47:45 -0500 |
| commit | 0e45044dbd724e9050bea00511585dc023afe144 (patch) | |
| tree | 46841f3a56f83670c5ddf9e6df72547e808fa77e /src/lootdialog.cpp | |
| parent | 48fcf9521f796bc3b6e536545877a9ea2e37360d (diff) | |
fixed cancel button
debug logs, some cleanup
Diffstat (limited to 'src/lootdialog.cpp')
| -rw-r--r-- | src/lootdialog.cpp | 92 |
1 files changed, 58 insertions, 34 deletions
diff --git a/src/lootdialog.cpp b/src/lootdialog.cpp index 80664415..43929c00 100644 --- a/src/lootdialog.cpp +++ b/src/lootdialog.cpp @@ -8,6 +8,29 @@ using namespace MOBase; +QString progressToString(lootcli::Progress p) +{ + using P = lootcli::Progress; + + static const std::map<P, QString> map = { + {P::CheckingMasterlistExistence, QObject::tr("Checking masterlist existence")}, + {P::UpdatingMasterlist, QObject::tr("Updating masterlist")}, + {P::LoadingLists, QObject::tr("Loading lists")}, + {P::ReadingPlugins, QObject::tr("Reading plugins")}, + {P::SortingPlugins, QObject::tr("Sorting plugins")}, + {P::WritingLoadorder, QObject::tr("Writing loadorder.txt")}, + {P::ParsingLootMessages, QObject::tr("Parsing loot messages")}, + {P::Done, QObject::tr("Done")} + }; + + auto itor = map.find(p); + if (itor == map.end()) { + return QString("unknown progress %1").arg(static_cast<int>(p)); + } else { + return itor->second; + } +} + MarkdownDocument::MarkdownDocument(QObject* parent) : QObject(parent) @@ -74,7 +97,11 @@ void LootDialog::setText(const QString& s) void LootDialog::setProgress(lootcli::Progress p) { - setText(progressToString(p)); + // don't overwrite the "stopping loot" message even if lootcli generates a new + // progress message + if (!m_cancelling) { + setText(progressToString(p)); + } if (p == lootcli::Progress::Done) { ui->progressBar->setRange(0, 1); @@ -82,24 +109,6 @@ void LootDialog::setProgress(lootcli::Progress p) } } -QString LootDialog::progressToString(lootcli::Progress p) -{ - using P = lootcli::Progress; - - switch (p) - { - case P::CheckingMasterlistExistence: return tr("Checking masterlist existence"); - case P::UpdatingMasterlist: return tr("Updating masterlist"); - case P::LoadingLists: return tr("Loading lists"); - case P::ReadingPlugins: return tr("Reading plugins"); - case P::SortingPlugins: return tr("Sorting plugins"); - case P::WritingLoadorder: return tr("Writing loadorder.txt"); - case P::ParsingLootMessages: return tr("Parsing loot messages"); - case P::Done: return tr("Done"); - default: return QString("unknown progress %1").arg(static_cast<int>(p)); - } -} - void LootDialog::addOutput(const QString& s) { if (m_core.settings().diagnostics().lootLogLevel() > lootcli::LogLevels::Debug) { @@ -125,8 +134,12 @@ bool LootDialog::result() const void LootDialog::cancel() { if (!m_finished && !m_cancelling) { - addLineOutput(tr("Stopping LOOT...")); + log::debug("loot dialog: cancelling"); m_loot.cancel(); + + setText(tr("Stopping LOOT...")); + addLineOutput("stopping loot"); + ui->buttons->setEnabled(false); m_cancelling = true; } @@ -138,6 +151,22 @@ void LootDialog::openReport() shell::Open(path); } +void LootDialog::accept() +{ + // no-op +} + +void LootDialog::reject() +{ + if (m_finished) { + log::debug("loot dialog reject: loot finished, closing"); + QDialog::reject(); + } else { + log::debug("loot dialog reject: not finished, cancelling"); + cancel(); + } +} + void LootDialog::createUI() { ui->setupUi(this); @@ -169,7 +198,7 @@ void LootDialog::createUI() new ExpanderWidget(ui->details, ui->detailsPanel); - connect(ui->buttons, &QDialogButtonBox::clicked, [&](auto* b){ onButton(b); }); + ui->buttons->setStandardButtons(QDialogButtonBox::Cancel); resize(650, 450); } @@ -177,24 +206,15 @@ void LootDialog::createUI() void LootDialog::closeEvent(QCloseEvent* e) { if (m_finished) { + log::debug("loot dialog close event: finished, closing"); QDialog::closeEvent(e); } else { + log::debug("loot dialog close event: not finished, cancelling"); cancel(); e->ignore(); } } -void LootDialog::onButton(QAbstractButton* b) -{ - if (ui->buttons->buttonRole(b) == QDialogButtonBox::RejectRole) { - if (m_finished) { - close(); - } else { - cancel(); - } - } -} - void LootDialog::addLineOutput(const QString& line) { ui->output->appendPlainText(line); @@ -202,12 +222,16 @@ void LootDialog::addLineOutput(const QString& line) void LootDialog::onFinished() { + log::debug("loot dialog: loot is finished"); + m_finished = true; if (m_cancelling) { + log::debug("loot dialog: was cancelling, closing"); close(); } else { - handleReport(); + log::debug("loot dialog: showing report"); + showReport(); ui->openJsonReport->setEnabled(true); ui->buttons->setStandardButtons(QDialogButtonBox::Close); } @@ -224,7 +248,7 @@ void LootDialog::log(log::Levels lv, const QString& s) } } -void LootDialog::handleReport() +void LootDialog::showReport() { const auto& lootReport = m_loot.report(); |
