summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-11-24 20:11:50 -0500
committerisanae <14251494+isanae@users.noreply.github.com>2019-11-24 20:11:50 -0500
commitcd876a0f9ffd03c711812c2ade92836e5d6c0203 (patch)
treecf472e0d3aa07e874721eb069a3a5d99f7ccf3f2 /src
parentf5476531ae39fdae8c3adc63d4c4a11f92600ff8 (diff)
split loot dialog, added ui file
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt10
-rw-r--r--src/loot.cpp271
-rw-r--r--src/lootdialog.cpp222
-rw-r--r--src/lootdialog.h47
-rw-r--r--src/lootdialog.ui214
5 files changed, 492 insertions, 272 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3b74ea37..db3bda73 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -143,6 +143,7 @@ SET(organizer_SRCS
processrunner.cpp
uilocker.cpp
loot.cpp
+ lootdialog.cpp
shared/windows_error.cpp
shared/error_report.cpp
@@ -265,6 +266,7 @@ SET(organizer_HDRS
processrunner.h
uilocker.h
loot.h
+ lootdialog.h
json.h
shared/windows_error.h
@@ -392,6 +394,11 @@ set(executables
editexecutablesdialog
)
+set(loot
+ loot
+ lootdialog
+)
+
set(modinfo
modinfo
modinfobackup
@@ -468,7 +475,6 @@ set(utilities
shared/util
usvfsconnector
shared/windows_error
- loot
json
)
@@ -490,7 +496,7 @@ set(widgets
)
set(src_filters
- application core browser dialogs downloads env executables modinfo
+ application core browser dialogs downloads env executables loot modinfo
modinfo\\dialog modlist plugins previews profiles settings settingsdialog
utilities widgets
)
diff --git a/src/loot.cpp b/src/loot.cpp
index c73dcaa7..f0618b0b 100644
--- a/src/loot.cpp
+++ b/src/loot.cpp
@@ -1,4 +1,5 @@
#include "loot.h"
+#include "lootdialog.h"
#include "spawn.h"
#include "organizercore.h"
#include "json.h"
@@ -32,276 +33,6 @@ log::Levels levelFromLoot(lootcli::LogLevels level)
}
}
-class LootDialog : public QDialog
-{
-public:
- LootDialog(QWidget* parent, OrganizerCore& core, Loot& loot) :
- QDialog(parent), m_core(core), m_loot(loot),
- m_label(nullptr), m_progress(nullptr),
- m_report(nullptr), m_output(nullptr), m_buttons(nullptr),
- m_finished(false), m_cancelling(false)
- {
- createUI();
- m_progress->setMaximum(0);
-
- QObject::connect(
- &m_loot, &Loot::output, this,
- [&](auto&& s){ addOutput(s); }, Qt::QueuedConnection);
-
- QObject::connect(
- &m_loot, &Loot::progress,
- this, [&](auto&& p){ setProgress(p); }, Qt::QueuedConnection);
-
- QObject::connect(
- &m_loot, &Loot::log, this,
- [&](auto&& lv, auto&& s){ log(lv, s); }, Qt::QueuedConnection);
-
- QObject::connect(
- &m_loot, &Loot::finished, this,
- [&]{ onFinished(); }, Qt::QueuedConnection);
- }
-
- void setText(const QString& s)
- {
- m_label->setText(s);
- }
-
- void setProgress(lootcli::Progress p)
- {
- setText(progressToString(p));
-
- if (p == lootcli::Progress::Done) {
- m_progress->setRange(0, 1);
- m_progress->setValue(1);
- }
- }
-
- QString 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 addOutput(const QString& s)
- {
- if (m_core.settings().diagnostics().lootLogLevel() > lootcli::LogLevels::Debug) {
- return;
- }
-
- const auto lines = s.split(QRegExp("[\\r\\n]"), QString::SkipEmptyParts);
-
- for (auto&& line : lines) {
- if (line.isEmpty()) {
- continue;
- }
-
- addLineOutput(line);
- }
- }
-
- bool result() const
- {
- return m_loot.result();
- }
-
- void cancel()
- {
- if (!m_finished && !m_cancelling) {
- addLineOutput(tr("Stopping LOOT..."));
- m_loot.cancel();
- m_buttons->setEnabled(false);
- m_cancelling = true;
- }
- }
-
- int exec() override
- {
- return QDialog::exec();
- }
-
- void openReport()
- {
- const auto path = m_loot.outPath();
- shell::Open(path);
- }
-
-private:
- OrganizerCore& m_core;
- Loot& m_loot;
- QLabel* m_label;
- QProgressBar* m_progress;
- QTextEdit* m_messages;
- QPushButton* m_report;
- QPlainTextEdit* m_output;
- QDialogButtonBox* m_buttons;
- bool m_finished;
- bool m_cancelling;
-
- void createUI()
- {
- auto* root = new QWidget(this);
- auto* ly = new QVBoxLayout(root);
-
- setLayout(new QVBoxLayout);
- layout()->setContentsMargins(0, 0, 0, 0);
- layout()->addWidget(root);
-
- m_label = new QLabel;
- ly->addWidget(m_label);
-
- m_progress = new QProgressBar;
- ly->addWidget(m_progress);
-
- m_messages = new QTextEdit;
- ly->addWidget(m_messages);
-
- auto* more = createMoreUI();
- ly->addWidget(more);
-
- resize(700, 400);
- }
-
- QWidget* createMoreUI()
- {
- auto* more = new QWidget;
- auto* ly = new QVBoxLayout(more);
- ly->setContentsMargins(0, 0, 0, 0);
-
- auto* buttons = new QHBoxLayout;
- buttons->setContentsMargins(0, 0, 0, 0);
- m_report = new QPushButton(tr("Open JSON report"));
- m_report->setEnabled(false);
- connect(m_report, &QPushButton::clicked, [&]{ openReport(); });
- buttons->addWidget(m_report);
- buttons->addStretch(1);
- ly->addLayout(buttons);
-
- m_output = new QPlainTextEdit;
- ly->addWidget(m_output);
-
- m_buttons = new QDialogButtonBox(QDialogButtonBox::Cancel);
- connect(m_buttons, &QDialogButtonBox::clicked, [&](auto* b){ onButton(b); });
- ly->addWidget(m_buttons);
-
- return more;
- }
-
- void closeEvent(QCloseEvent* e) override
- {
- if (m_finished) {
- QDialog::closeEvent(e);
- } else {
- cancel();
- e->ignore();
- }
- }
-
- void onButton(QAbstractButton* b)
- {
- if (m_buttons->buttonRole(b) == QDialogButtonBox::RejectRole) {
- if (m_finished) {
- close();
- } else {
- cancel();
- }
- }
- }
-
- void addLineOutput(const QString& line)
- {
- m_output->appendPlainText(line);
- }
-
- void onFinished()
- {
- m_finished = true;
-
- if (m_cancelling) {
- close();
- } else {
- handleReport();
- m_report->setEnabled(true);
- m_buttons->setStandardButtons(QDialogButtonBox::Close);
- }
- }
-
- void log(log::Levels lv, const QString& s)
- {
- if (lv >= log::Levels::Warning) {
- log::log(lv, "{}", s);
- }
-
- if (m_core.settings().diagnostics().lootLogLevel() > lootcli::LogLevels::Debug) {
- addLineOutput(QString("[%1] %2").arg(log::levelToString(lv)).arg(s));
- }
- }
-
- void handleReport()
- {
- const auto& report = m_loot.report();
-
- if (!report.messages.empty()) {
- addLineOutput("");
- }
-
- QString html;
-
- if (!report.messages.empty()) {
- html += "<ul>";
-
- for (auto&& m : report.messages) {
- log(m.type, m.text);
-
- html += "<li>";
-
- switch (m.type)
- {
- case log::Error:
- {
- html += "<b>" + QObject::tr("Error") + "</b>: ";
- break;
- }
-
- case log::Warning:
- {
- html += "<b>" + QObject::tr("Warning") + "</b>: ";
- break;
- }
-
- default:
- {
- break;
- }
- }
-
- html += m.text + "</li>";
- }
-
- html + "</ul>";
- } else {
- html += QObject::tr("No messages.");
- }
-
- m_messages->setHtml(html);
-
- for (auto&& p : report.plugins) {
- m_core.pluginList()->addLootReport(p.name, p);
- }
- }
-};
-
QString Loot::Dirty::toString(bool isClean) const
{
diff --git a/src/lootdialog.cpp b/src/lootdialog.cpp
new file mode 100644
index 00000000..db41959d
--- /dev/null
+++ b/src/lootdialog.cpp
@@ -0,0 +1,222 @@
+#include "lootdialog.h"
+#include "ui_lootdialog.h"
+#include "loot.h"
+#include "organizercore.h"
+#include <utility.h>
+#include <expanderwidget.h>
+
+using namespace MOBase;
+
+LootDialog::LootDialog(QWidget* parent, OrganizerCore& core, Loot& loot) :
+ QDialog(parent), ui(new Ui::LootDialog), m_core(core), m_loot(loot),
+ m_finished(false), m_cancelling(false)
+{
+ createUI();
+
+ QObject::connect(
+ &m_loot, &Loot::output, this,
+ [&](auto&& s){ addOutput(s); }, Qt::QueuedConnection);
+
+ QObject::connect(
+ &m_loot, &Loot::progress,
+ this, [&](auto&& p){ setProgress(p); }, Qt::QueuedConnection);
+
+ QObject::connect(
+ &m_loot, &Loot::log, this,
+ [&](auto&& lv, auto&& s){ log(lv, s); }, Qt::QueuedConnection);
+
+ QObject::connect(
+ &m_loot, &Loot::finished, this,
+ [&]{ onFinished(); }, Qt::QueuedConnection);
+}
+
+LootDialog::~LootDialog() = default;
+
+void LootDialog::setText(const QString& s)
+{
+ ui->progressText->setText(s);
+}
+
+void LootDialog::setProgress(lootcli::Progress p)
+{
+ setText(progressToString(p));
+
+ if (p == lootcli::Progress::Done) {
+ ui->progressBar->setRange(0, 1);
+ ui->progressBar->setValue(1);
+ }
+}
+
+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) {
+ return;
+ }
+
+ const auto lines = s.split(QRegExp("[\\r\\n]"), QString::SkipEmptyParts);
+
+ for (auto&& line : lines) {
+ if (line.isEmpty()) {
+ continue;
+ }
+
+ addLineOutput(line);
+ }
+}
+
+bool LootDialog::result() const
+{
+ return m_loot.result();
+}
+
+void LootDialog::cancel()
+{
+ if (!m_finished && !m_cancelling) {
+ addLineOutput(tr("Stopping LOOT..."));
+ m_loot.cancel();
+ ui->buttons->setEnabled(false);
+ m_cancelling = true;
+ }
+}
+
+void LootDialog::openReport()
+{
+ const auto path = m_loot.outPath();
+ shell::Open(path);
+}
+
+void LootDialog::createUI()
+{
+ ui->setupUi(this);
+ ui->progressBar->setMaximum(0);
+
+ ui->openJsonReport->setEnabled(false);
+ connect(ui->openJsonReport, &QPushButton::clicked, [&]{ openReport(); });
+
+ new ExpanderWidget(ui->details, ui->detailsPanel);
+
+ connect(ui->buttons, &QDialogButtonBox::clicked, [&](auto* b){ onButton(b); });
+
+ resize(480, 275);
+}
+
+void LootDialog::closeEvent(QCloseEvent* e)
+{
+ if (m_finished) {
+ QDialog::closeEvent(e);
+ } else {
+ 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);
+}
+
+void LootDialog::onFinished()
+{
+ m_finished = true;
+
+ if (m_cancelling) {
+ close();
+ } else {
+ handleReport();
+ ui->openJsonReport->setEnabled(true);
+ ui->buttons->setStandardButtons(QDialogButtonBox::Close);
+ }
+}
+
+void LootDialog::log(log::Levels lv, const QString& s)
+{
+ if (lv >= log::Levels::Warning) {
+ log::log(lv, "{}", s);
+ }
+
+ if (m_core.settings().diagnostics().lootLogLevel() > lootcli::LogLevels::Debug) {
+ addLineOutput(QString("[%1] %2").arg(log::levelToString(lv)).arg(s));
+ }
+}
+
+void LootDialog::handleReport()
+{
+ const auto& report = m_loot.report();
+
+ if (!report.messages.empty()) {
+ addLineOutput("");
+ }
+
+ QString html;
+
+ if (!report.messages.empty()) {
+ html += "<ul>";
+
+ for (auto&& m : report.messages) {
+ log(m.type, m.text);
+
+ html += "<li>";
+
+ switch (m.type)
+ {
+ case log::Error:
+ {
+ html += "<b>" + QObject::tr("Error") + "</b>: ";
+ break;
+ }
+
+ case log::Warning:
+ {
+ html += "<b>" + QObject::tr("Warning") + "</b>: ";
+ break;
+ }
+
+ default:
+ {
+ break;
+ }
+ }
+
+ html += m.text + "</li>";
+ }
+
+ html + "</ul>";
+ } else {
+ html += QObject::tr("No messages.");
+ }
+
+ ui->report->setHtml(html);
+
+ for (auto&& p : report.plugins) {
+ m_core.pluginList()->addLootReport(p.name, p);
+ }
+}
diff --git a/src/lootdialog.h b/src/lootdialog.h
new file mode 100644
index 00000000..e4647b5c
--- /dev/null
+++ b/src/lootdialog.h
@@ -0,0 +1,47 @@
+#ifndef MODORGANIZER_LOOTDIALOG_H
+#define MODORGANIZER_LOOTDIALOG_H
+
+#include <lootcli/lootcli.h>
+#include <log.h>
+
+namespace Ui { class LootDialog; }
+
+class OrganizerCore;
+class Loot;
+
+class LootDialog : public QDialog
+{
+public:
+ LootDialog(QWidget* parent, OrganizerCore& core, Loot& loot);
+ ~LootDialog();
+
+ void setText(const QString& s);
+ void setProgress(lootcli::Progress p);
+
+ QString progressToString(lootcli::Progress p);
+
+ void addOutput(const QString& s);
+
+ bool result() const;
+
+ void cancel();
+
+ void openReport();
+
+private:
+ std::unique_ptr<Ui::LootDialog> ui;
+ OrganizerCore& m_core;
+ Loot& m_loot;
+ bool m_finished;
+ bool m_cancelling;
+
+ void createUI();
+ void closeEvent(QCloseEvent* e) override;
+ void onButton(QAbstractButton* b);
+ void addLineOutput(const QString& line);
+ void onFinished();
+ void log(MOBase::log::Levels lv, const QString& s);
+ void handleReport();
+};
+
+#endif // MODORGANIZER_LOOTDIALOG_H
diff --git a/src/lootdialog.ui b/src/lootdialog.ui
new file mode 100644
index 00000000..7e10b1db
--- /dev/null
+++ b/src/lootdialog.ui
@@ -0,0 +1,214 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>LootDialog</class>
+ <widget class="QDialog" name="LootDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>457</width>
+ <height>343</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>LOOT</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QWidget" name="widget" native="true">
+ <layout class="QVBoxLayout" name="verticalLayout_5">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QWidget" name="widget_2" native="true">
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="progressText">
+ <property name="text">
+ <string>Progress</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QProgressBar" name="progressBar">
+ <property name="value">
+ <number>24</number>
+ </property>
+ <property name="textVisible">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QTextEdit" name="report">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::TextBrowserInteraction</set>
+ </property>
+ <property name="placeholderText">
+ <string>LOOT Report</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QWidget" name="widget_3" native="true">
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QToolButton" name="details">
+ <property name="text">
+ <string>Details</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QWidget" name="detailsPanel" native="true">
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QWidget" name="widget_5" native="true">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QPushButton" name="openJsonReport">
+ <property name="text">
+ <string>Open JSON report</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPlainTextEdit" name="output"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttons">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Close</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttons</sender>
+ <signal>accepted()</signal>
+ <receiver>LootDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttons</sender>
+ <signal>rejected()</signal>
+ <receiver>LootDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>