summaryrefslogtreecommitdiffstats
path: root/gui/dialogs/UpdateDialog.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-07-09 00:49:37 +0200
committerPetr Mrázek <peterix@gmail.com>2014-07-09 00:49:37 +0200
commitfc911add58c97b878b5b2eff867ce35216eb2a1e (patch)
tree0ccfc76bd875cde1d61d23463cdfb00f05f89d14 /gui/dialogs/UpdateDialog.cpp
parent6349800f070781b29e1ab3674d1872a3ce070e19 (diff)
downloadMultiMC-fc911add58c97b878b5b2eff867ce35216eb2a1e.tar
MultiMC-fc911add58c97b878b5b2eff867ce35216eb2a1e.tar.gz
MultiMC-fc911add58c97b878b5b2eff867ce35216eb2a1e.tar.lz
MultiMC-fc911add58c97b878b5b2eff867ce35216eb2a1e.tar.xz
MultiMC-fc911add58c97b878b5b2eff867ce35216eb2a1e.zip
Show changelog in the update dialog.
Diffstat (limited to 'gui/dialogs/UpdateDialog.cpp')
-rw-r--r--gui/dialogs/UpdateDialog.cpp145
1 files changed, 145 insertions, 0 deletions
diff --git a/gui/dialogs/UpdateDialog.cpp b/gui/dialogs/UpdateDialog.cpp
index c56798b4..3194208f 100644
--- a/gui/dialogs/UpdateDialog.cpp
+++ b/gui/dialogs/UpdateDialog.cpp
@@ -1,17 +1,162 @@
#include "UpdateDialog.h"
#include "ui_UpdateDialog.h"
#include "gui/Platform.h"
+#include <BuildConfig.h>
+#include "logger/QsLog.h"
UpdateDialog::UpdateDialog(QWidget *parent) : QDialog(parent), ui(new Ui::UpdateDialog)
{
MultiMCPlatform::fixWM_CLASS(this);
ui->setupUi(this);
+ loadChangelog();
}
UpdateDialog::~UpdateDialog()
{
}
+void UpdateDialog::loadChangelog()
+{
+ dljob.reset(new NetJob("Changelog"));
+ auto url = QString("https://raw.githubusercontent.com/MultiMC/MultiMC5/%1/changelog.md").arg(BuildConfig.VERSION_CHANNEL);
+ changelogDownload = ByteArrayDownload::make(QUrl(url));
+ dljob->addNetAction(changelogDownload);
+ connect(dljob.get(), &NetJob::succeeded, this, &UpdateDialog::changelogLoaded);
+ connect(dljob.get(), &NetJob::failed, this, &UpdateDialog::changelogFailed);
+ dljob->start();
+}
+
+// TODO: this will be replaced.
+QString reprocessMarkdown(QString markdown)
+{
+ QString htmlData;
+ QTextStream html(&htmlData);
+ auto lines = markdown.split(QRegExp("[\r]?[\n]"),QString::KeepEmptyParts);
+ enum
+ {
+ BASE,
+ LIST1,
+ LIST2
+ }state = BASE;
+ html << "<html>";
+ int i = 0;
+ auto procLine = [&](QString line) -> QString
+ {
+ // [GitHub issues](https://github.com/MultiMC/MultiMC5/issues)
+ line.replace(QRegExp("\\[(.+)\\]\\((.+)\\)"), "<a href=\"\\2\">\\1</a>");
+ return line;
+ };
+ for(auto line: lines)
+ {
+ if(line.isEmpty())
+ {
+ // html << "<br />\n";
+ }
+ else switch (state)
+ {
+ case BASE:
+ if(line.startsWith("##"))
+ {
+ html << "<h2>" << procLine(line.mid(2)) << "</h2>\n";
+ }
+ else if(line.startsWith("#"))
+ {
+ html << "<h1>" << procLine(line.mid(1)) << "</h1>\n";
+ }
+ else if(line.startsWith("- "))
+ {
+ state = LIST1;
+ html << "<ul>\n";
+ html << "<li>" << procLine(line.mid(2)) << "</li>\n";
+ }
+ else QLOG_ERROR() << "Invalid input on line " << i << ": " << line;
+ break;
+ case LIST1:
+ if(line.startsWith("##"))
+ {
+ state = BASE;
+ html << "</ul>\n";
+ html << "<h2>" << procLine(line.mid(2)) << "</h2>\n";
+ }
+ else if(line.startsWith("#"))
+ {
+ state = BASE;
+ html << "</ul>\n";
+ html << "<h1>" << procLine(line.mid(1)) << "</h1>\n";
+ }
+ else if(line.startsWith("- "))
+ {
+ html << "<li>" << procLine(line.mid(2)) << "</li>\n";
+ }
+ else if(line.startsWith(" - "))
+ {
+ state = LIST2;
+ html << "<ul>\n";
+ html << "<li>" << procLine(line.mid(4)) << "</li>\n";
+ }
+ else QLOG_ERROR() << "Invalid input on line " << i << ": " << line;
+ break;
+ case LIST2:
+ if(line.startsWith("##"))
+ {
+ state = BASE;
+ html << "</ul>\n";
+ html << "</ul>\n";
+ html << "<h2>" << procLine(line.mid(2)) << "</h2>\n";
+ }
+ else if(line.startsWith("#"))
+ {
+ state = BASE;
+ html << "</ul>\n";
+ html << "</ul>\n";
+ html << "<h1>" << procLine(line.mid(1)) << "</h1>\n";
+ }
+ else if(line.startsWith("- "))
+ {
+ state = LIST1;
+ html << "</ul>\n";
+ html << "<li>" << procLine(line.mid(2)) << "</li>\n";
+ }
+ else if(line.startsWith(" - "))
+ {
+ html << "<li>" << procLine(line.mid(4)) << "</li>\n";
+ }
+ else QLOG_ERROR() << "Invalid input on line " << i << ": " << line;
+ break;
+ }
+ i++;
+ }
+ if(state == LIST2)
+ {
+ html << "</ul>\n";
+ state = LIST1;
+ }
+ if(state == LIST1)
+ {
+ html << "</ul>\n";
+ state = BASE;
+ }
+ if (state != BASE)
+ {
+ QLOG_ERROR() << "Reprocessing markdown didn't end in a final state!";
+ }
+ html << "</html>\n";
+ QLOG_DEBUG() << htmlData;
+ return htmlData;
+}
+
+void UpdateDialog::changelogLoaded()
+{
+ auto rawMarkdown = QString::fromUtf8(changelogDownload->m_data);
+ auto html = reprocessMarkdown(rawMarkdown);
+ ui->changelogBrowser->setHtml(html);
+}
+
+void UpdateDialog::changelogFailed()
+{
+ ui->changelogBrowser->setHtml(tr("<p align=\"center\" <span style=\"font-size:22pt;\">Failed to fetch changelog...</span></p>"));
+}
+
void UpdateDialog::on_btnUpdateLater_clicked()
{
reject();