From f058125e6679560e5ade95a76c05acd6eb5274d4 Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Mon, 8 Feb 2021 06:09:06 -0700 Subject: Fix concatenating update logs --- src/selfupdater.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/selfupdater.cpp') diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp index c0f3b005..70ab9090 100644 --- a/src/selfupdater.cpp +++ b/src/selfupdater.cpp @@ -129,7 +129,7 @@ void SelfUpdater::testForUpdate(const Settings& settings) auto lastKey = mreleases.begin()->first; if (lastKey > this->m_MOVersion) { - // Fill m_UpdateCandidates with version strictly greater than the + // Fill m_UpdateCandidates with version strictly greater than the // current version: m_UpdateCandidates.clear(); for (auto p : mreleases) { @@ -182,7 +182,7 @@ void SelfUpdater::startUpdate() } // Stop including pre-release as soon as we find a non-prerelease: - if (!release["prelease"].toBool()) { + if (!release["prerelease"].toBool()) { includePreRelease = false; } -- cgit v1.3.1 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/selfupdater.cpp') 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 From f486e6fa4e5893c4f437147e5a031e64b48035e7 Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Thu, 11 Feb 2021 18:39:06 -0700 Subject: Updates to text, title and buttons --- src/selfupdater.cpp | 8 +++++--- src/updatedialog.cpp | 12 ++++++++++-- src/updatedialog.h | 3 ++- src/updatedialog.ui | 34 ++++------------------------------ 4 files changed, 21 insertions(+), 36 deletions(-) (limited to 'src/selfupdater.cpp') diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp index 68aecc46..4b2894fd 100644 --- a/src/selfupdater.cpp +++ b/src/selfupdater.cpp @@ -165,9 +165,11 @@ void SelfUpdater::startUpdate() auto latestRelease = m_UpdateCandidates.begin()->second; - UpdateDialog dialog(m_Parent, tr("New update available (%1 -> %2)") - .arg(MOShared::createVersionInfo().displayString(3)) - .arg(latestRelease["tag_name"].toString())); + UpdateDialog dialog(m_Parent); + dialog.setVersions( + MOShared::createVersionInfo().displayString(3), + latestRelease["tag_name"].toString() + ); // We concatenate release details. We only include pre-release if those are // the latest release: diff --git a/src/updatedialog.cpp b/src/updatedialog.cpp index 1be58576..d3336e93 100644 --- a/src/updatedialog.cpp +++ b/src/updatedialog.cpp @@ -6,12 +6,11 @@ using namespace MOBase; -UpdateDialog::UpdateDialog(QWidget* parent, const QString& title) : +UpdateDialog::UpdateDialog(QWidget* parent) : 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); }); @@ -57,3 +56,12 @@ void UpdateDialog::setChangeLogs(const QString& text) { m_changeLogs.setText(text); } + +void UpdateDialog::setVersions(const QString& oldVersion, const QString& newVersion) +{ + ui->updateLabel->setText( + tr("Mod Organizer %1 is available. The current version is %2. Updating will not affect your mods or profiles.") + .arg(newVersion) + .arg(oldVersion) + ); +} diff --git a/src/updatedialog.h b/src/updatedialog.h index dbcf28a7..1dd5e0b1 100644 --- a/src/updatedialog.h +++ b/src/updatedialog.h @@ -13,10 +13,11 @@ class UpdateDialog : public QDialog Q_OBJECT; public: - UpdateDialog(QWidget* parent, const QString& title); + UpdateDialog(QWidget* parent); ~UpdateDialog(); void setChangeLogs(const QString& text); + void setVersions(const QString& oldVersion, const QString& newVersion); private: std::unique_ptr ui; diff --git a/src/updatedialog.ui b/src/updatedialog.ui index 43a17346..874cbb80 100644 --- a/src/updatedialog.ui +++ b/src/updatedialog.ui @@ -17,7 +17,7 @@ - New update available (xxxx) + Update available true @@ -27,7 +27,7 @@ - + 0 @@ -80,40 +80,14 @@ - - - 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. + Update text placeholder true - - - - Qt::Horizontal - - - - 20 - 20 - - - - @@ -121,7 +95,7 @@ Select Show Details option to see the full change-log. - Show Details... + Changelog -- cgit v1.3.1 From 31c8415e8894ff380996f25095e8d43e2c79d9ee Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Fri, 12 Feb 2021 01:31:41 -0700 Subject: Use release name for changelogs --- src/selfupdater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/selfupdater.cpp') diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp index 4b2894fd..ea012a94 100644 --- a/src/selfupdater.cpp +++ b/src/selfupdater.cpp @@ -188,7 +188,7 @@ void SelfUpdater::startUpdate() includePreRelease = false; } - details += "\n## " + release["tag_name"].toString() + "\n---\n"; + details += "\n## " + release["name"].toString() + "\n---\n"; details += release["body"].toString(); } -- cgit v1.3.1