diff options
| author | Mikaƫl Capelle <capelle.mikael@gmail.com> | 2021-02-12 18:08:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-12 18:08:54 +0100 |
| commit | 9f0c8c31a6267ae9bf3181b29f65710fb30fad79 (patch) | |
| tree | d6dc8a1bc7c03bc7db6a97f65d717a094cd20e45 /src/updatedialog.cpp | |
| parent | 2fe627c261d54daf7c471898446ea53cbfaebf5b (diff) | |
| parent | 31c8415e8894ff380996f25095e8d43e2c79d9ee (diff) | |
Merge pull request #1405 from LostDragonist/update_fixes
Fixes for the update dialog window
Diffstat (limited to 'src/updatedialog.cpp')
| -rw-r--r-- | src/updatedialog.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/updatedialog.cpp b/src/updatedialog.cpp new file mode 100644 index 00000000..d3336e93 --- /dev/null +++ b/src/updatedialog.cpp @@ -0,0 +1,67 @@ +#include "updatedialog.h" +#include "ui_updatedialog.h" + +#include "lootdialog.h" // for MarkdownPage +#include <QWebChannel> + +using namespace MOBase; + +UpdateDialog::UpdateDialog(QWidget* parent) : + QDialog(parent, Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint), ui(new Ui::UpdateDialog) +{ + // Basic UI stuff + ui->setupUi(this); + 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); +} + +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) + ); +} |
