From 3dd05ff869e5113fc9a5f474786c226dd556fc1b Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Mon, 8 Feb 2021 08:24:51 -0700 Subject: Create a new dialog for the update window The idea here is to be able to resize the window and better handle markdown formatting. Everything was stolen from the LOOT dialog. --- src/organizer.pro | 5 +- src/selfupdater.cpp | 24 ++---- src/updatedialog.cpp | 59 +++++++++++++ src/updatedialog.h | 27 ++++++ src/updatedialog.ui | 237 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 335 insertions(+), 17 deletions(-) create mode 100644 src/updatedialog.cpp create mode 100644 src/updatedialog.h create mode 100644 src/updatedialog.ui (limited to 'src') diff --git a/src/organizer.pro b/src/organizer.pro index ddf676f2..54080112 100644 --- a/src/organizer.pro +++ b/src/organizer.pro @@ -83,6 +83,7 @@ SOURCES += \ modflagicondelegate.cpp \ genericicondelegate.cpp \ organizerproxy.cpp \ + updatedialog.cpp \ viewmarkingscrollbar.cpp \ plugincontainer.cpp \ organizercore.cpp \ @@ -161,6 +162,7 @@ HEADERS += \ modflagicondelegate.h \ genericicondelegate.h \ organizerproxy.h \ + updatedialog.h \ viewmarkingscrollbar.h \ plugincontainer.h \ organizercore.h \ @@ -203,7 +205,8 @@ FORMS += \ aboutdialog.ui \ listdialog.ui \ forcedloaddialog.ui \ - forcedloaddialogwidget.ui + forcedloaddialogwidget.ui \ + updatedialog.ui RESOURCES += \ resources.qrc \ diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp index 70ab9090..68aecc46 100644 --- a/src/selfupdater.cpp +++ b/src/selfupdater.cpp @@ -32,6 +32,7 @@ along with Mod Organizer. If not, see . #include #include #include "shared/util.h" +#include "updatedialog.h" #include #include @@ -164,10 +165,9 @@ void SelfUpdater::startUpdate() auto latestRelease = m_UpdateCandidates.begin()->second; - QMessageBox query(QMessageBox::Question, - tr("New update available (%1)") - .arg(latestRelease["tag_name"].toString()), tr("Do you want to install update? All your mods and setup will be left untouched.\nSelect Show Details option to see the full change-log."), - QMessageBox::Yes | QMessageBox::Cancel, m_Parent); + UpdateDialog dialog(m_Parent, tr("New update available (%1 -> %2)") + .arg(MOShared::createVersionInfo().displayString(3)) + .arg(latestRelease["tag_name"].toString())); // We concatenate release details. We only include pre-release if those are // the latest release: @@ -186,24 +186,16 @@ void SelfUpdater::startUpdate() includePreRelease = false; } - details += "\n# " + release["tag_name"].toString() + "\n---\n"; + details += "\n## " + release["tag_name"].toString() + "\n---\n"; details += release["body"].toString(); } // Need to call setDetailedText to create the QTextEdit and then be able to retrieve it: - query.setDetailedText(details); - QTextEdit* textEdit = query.findChild(); + dialog.setChangeLogs(details); - // If we have the text edit, we can call setMarkdown to get proper formatting. - if (textEdit) { - textEdit->setMarkdown(details); - } - - query.button(QMessageBox::Yes)->setText(tr("Install")); - - int res = query.exec(); + int res = dialog.exec(); - if (query.result() == QMessageBox::Yes) { + if (dialog.result() == QDialog::Accepted) { bool found = false; for (const QJsonValue &assetVal : latestRelease["assets"].toArray()) { QJsonObject asset = assetVal.toObject(); diff --git a/src/updatedialog.cpp b/src/updatedialog.cpp new file mode 100644 index 00000000..1be58576 --- /dev/null +++ b/src/updatedialog.cpp @@ -0,0 +1,59 @@ +#include "updatedialog.h" +#include "ui_updatedialog.h" + +#include "lootdialog.h" // for MarkdownPage +#include + +using namespace MOBase; + +UpdateDialog::UpdateDialog(QWidget* parent, const QString& title) : + QDialog(parent, Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint), ui(new Ui::UpdateDialog) +{ + // Basic UI stuff + ui->setupUi(this); + setWindowTitle(title); + connect(ui->installButton, &QPushButton::pressed, this, [&]{ done(QDialog::Accepted); }); + connect(ui->cancelButton, &QPushButton::pressed, this, [&]{ done(QDialog::Rejected); }); + + // Replace a label with an icon + QIcon icon = style()->standardIcon(QStyle::SP_MessageBoxQuestion); + QPixmap pixmap = icon.pixmap(QSize(32, 32)); + ui->iconLabel->setPixmap(pixmap); + ui->iconLabel->setScaledContents(true); + + // Setting up the Markdown stuff + auto* page = new MarkdownPage(this); + ui->detailsWebView->setPage(page); + + auto* channel = new QWebChannel(this); + channel->registerObject("content", &m_changeLogs); + page->setWebChannel(channel); + + const QString path = QApplication::applicationDirPath() + "/resources/markdown.html"; + QFile f(path); + + if (f.open(QFile::ReadOnly)) { + const QString html = f.readAll(); + if (!html.isEmpty()) { + ui->detailsWebView->setHtml(html); + } else { + log::error("failed to read '{}', {}", path, f.errorString()); + } + } else { + log::error("can't open '{}', {}", path, f.errorString()); + } + + // Setting up the expander + m_expander.set(ui->detailsButton, ui->detailsWidget); + connect(&m_expander, &ExpanderWidget::toggled, this, [&]{ adjustSize(); }); + + // Adjust sizes after the expander hides stuff + adjustSize(); +} + +UpdateDialog::~UpdateDialog() = default; + +void UpdateDialog::setChangeLogs(const QString& text) +{ + m_changeLogs.setText(text); +} diff --git a/src/updatedialog.h b/src/updatedialog.h new file mode 100644 index 00000000..dbcf28a7 --- /dev/null +++ b/src/updatedialog.h @@ -0,0 +1,27 @@ +#ifndef MODORGANIZER_UPDATEDIALOG_H +#define MODORGANIZER_UPDATEDIALOG_H + +#include + +#include +#include "lootdialog.h" // for MarkdownDocument + +namespace Ui { class UpdateDialog; } + +class UpdateDialog : public QDialog +{ + Q_OBJECT; + +public: + UpdateDialog(QWidget* parent, const QString& title); + ~UpdateDialog(); + + void setChangeLogs(const QString& text); + +private: + std::unique_ptr ui; + MOBase::ExpanderWidget m_expander; + MarkdownDocument m_changeLogs; +}; + +#endif // MODORGANIZER_UPDATEDIALOG_H diff --git a/src/updatedialog.ui b/src/updatedialog.ui new file mode 100644 index 00000000..43a17346 --- /dev/null +++ b/src/updatedialog.ui @@ -0,0 +1,237 @@ + + + UpdateDialog + + + + 0 + 0 + 578 + 539 + + + + + 460 + 0 + + + + New update available (xxxx) + + + true + + + true + + + + + + 0 + + + 9 + + + 9 + + + + + + 32 + 32 + + + + + 32 + 32 + + + + <?> + + + Qt::AlignCenter + + + 0 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + + 400 + 0 + + + + + 400 + 16777215 + + + + Do you want to install the update? All your mods and setup will be left untouched. +Select Show Details option to see the full change-log. + + + true + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + + + + Show Details... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Install + + + true + + + + + + + Cancel + + + false + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 650 + 450 + + + + + about:blank + + + + + + + + + + + + + + + QWebEngineView + QWidget +
QtWebEngineWidgets/QWebEngineView
+
+
+ + +
-- cgit v1.3.1