diff options
| author | Chris Bessent <lost.dragonist@gmail.com> | 2021-02-08 08:24:51 -0700 |
|---|---|---|
| committer | Chris Bessent <lost.dragonist@gmail.com> | 2021-02-11 17:58:10 -0700 |
| commit | 3dd05ff869e5113fc9a5f474786c226dd556fc1b (patch) | |
| tree | c028228dcf5b1f4be43bcc68624a4f97d7cc2de1 /src | |
| parent | f058125e6679560e5ade95a76c05acd6eb5274d4 (diff) | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/organizer.pro | 5 | ||||
| -rw-r--r-- | src/selfupdater.cpp | 24 | ||||
| -rw-r--r-- | src/updatedialog.cpp | 59 | ||||
| -rw-r--r-- | src/updatedialog.h | 27 | ||||
| -rw-r--r-- | src/updatedialog.ui | 237 |
5 files changed, 335 insertions, 17 deletions
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 <http://www.gnu.org/licenses/>. #include <versioninfo.h>
#include <report.h>
#include "shared/util.h"
+#include "updatedialog.h"
#include <QApplication>
#include <QCoreApplication>
@@ -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<QTextEdit*>();
+ 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 <QWebChannel> + +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 <QDialog> + +#include <expanderwidget.h> +#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::UpdateDialog> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>UpdateDialog</class> + <widget class="QDialog" name="UpdateDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>578</width> + <height>539</height> + </rect> + </property> + <property name="minimumSize"> + <size> + <width>460</width> + <height>0</height> + </size> + </property> + <property name="windowTitle"> + <string notr="true">New update available (xxxx)</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <property name="modal"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,1"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,1,0"> + <property name="spacing"> + <number>0</number> + </property> + <property name="leftMargin"> + <number>9</number> + </property> + <property name="rightMargin"> + <number>9</number> + </property> + <item> + <widget class="QLabel" name="iconLabel"> + <property name="minimumSize"> + <size> + <width>32</width> + <height>32</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>32</width> + <height>32</height> + </size> + </property> + <property name="text"> + <string notr="true"><?></string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="margin"> + <number>0</number> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>10</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="updateLabel"> + <property name="minimumSize"> + <size> + <width>400</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>400</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string>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.</string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QToolButton" name="detailsButton"> + <property name="text"> + <string>Show Details...</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> + <item> + <widget class="QPushButton" name="installButton"> + <property name="text"> + <string>Install</string> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="cancelButton"> + <property name="text"> + <string>Cancel</string> + </property> + <property name="autoDefault"> + <bool>false</bool> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QWidget" name="detailsWidget" native="true"> + <layout class="QVBoxLayout" name="verticalLayout" stretch="0"> + <property name="spacing"> + <number>0</number> + </property> + <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="QFrame" name="frame"> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3" stretch="0"> + <property name="spacing"> + <number>0</number> + </property> + <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="QWebEngineView" name="detailsWebView" native="true"> + <property name="minimumSize"> + <size> + <width>650</width> + <height>450</height> + </size> + </property> + <property name="url" stdset="0"> + <url> + <string>about:blank</string> + </url> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>QWebEngineView</class> + <extends>QWidget</extends> + <header location="global">QtWebEngineWidgets/QWebEngineView</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> |
