Show changelog in the update dialog.
This commit is contained in:
		| @@ -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(); | ||||
|   | ||||
| @@ -16,6 +16,8 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <QDialog> | ||||
| #include "logic/net/ByteArrayDownload.h" | ||||
| #include "logic/net/NetJob.h" | ||||
|  | ||||
| namespace Ui | ||||
| { | ||||
| @@ -43,4 +45,17 @@ public slots: | ||||
| 	void on_btnUpdateNow_clicked(); | ||||
| 	void on_btnUpdateOnExit_clicked(); | ||||
| 	void on_btnUpdateLater_clicked(); | ||||
|  | ||||
| 	/// Starts loading the changelog | ||||
| 	void loadChangelog(); | ||||
| 	 | ||||
| 	/// Slot for when the chengelog loads successfully. | ||||
| 	void changelogLoaded(); | ||||
| 	 | ||||
| 	/// Slot for when the chengelog fails to load... | ||||
| 	void changelogFailed(); | ||||
| 	 | ||||
| private: | ||||
| 	ByteArrayDownloadPtr changelogDownload; | ||||
| 	NetJobPtr dljob; | ||||
| }; | ||||
|   | ||||
| @@ -6,65 +6,101 @@ | ||||
|    <rect> | ||||
|     <x>0</x> | ||||
|     <y>0</y> | ||||
|     <width>350</width> | ||||
|     <height>260</height> | ||||
|     <width>657</width> | ||||
|     <height>673</height> | ||||
|    </rect> | ||||
|   </property> | ||||
|   <property name="windowTitle"> | ||||
|    <string>MultiMC Update</string> | ||||
|   </property> | ||||
|   <property name="windowIcon"> | ||||
|    <iconset resource="../../graphics.qrc"> | ||||
|    <iconset> | ||||
|     <normaloff>:/icons/toolbar/checkupdate</normaloff>:/icons/toolbar/checkupdate</iconset> | ||||
|   </property> | ||||
|   <layout class="QVBoxLayout" name="verticalLayout"> | ||||
|    <item> | ||||
|     <widget class="QLabel" name="label"> | ||||
|      <property name="text"> | ||||
|       <string>A new MultiMC update is available!</string> | ||||
|     <layout class="QHBoxLayout" name="horizontalLayout_2"> | ||||
|      <item> | ||||
|       <widget class="QLabel" name="label"> | ||||
|        <property name="font"> | ||||
|         <font> | ||||
|          <pointsize>14</pointsize> | ||||
|         </font> | ||||
|        </property> | ||||
|        <property name="text"> | ||||
|         <string>A new MultiMC update is available!</string> | ||||
|        </property> | ||||
|        <property name="alignment"> | ||||
|         <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> | ||||
|        </property> | ||||
|        <property name="buddy"> | ||||
|         <cstring>changelogBrowser</cstring> | ||||
|        </property> | ||||
|       </widget> | ||||
|      </item> | ||||
|     </layout> | ||||
|    </item> | ||||
|    <item> | ||||
|     <widget class="QTextBrowser" name="changelogBrowser"> | ||||
|      <property name="html"> | ||||
|       <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | ||||
| <html><head><meta name="qrichtext" content="1" /><style type="text/css"> | ||||
| p, li { white-space: pre-wrap; } | ||||
| </style></head><body style=" font-family:'Bitstream Vera Sans'; font-size:11pt; font-weight:400; font-style:normal;"> | ||||
| <p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:22pt;">Loading changelog...</span></p></body></html></string> | ||||
|      </property> | ||||
|      <property name="alignment"> | ||||
|       <set>Qt::AlignCenter</set> | ||||
|      <property name="openExternalLinks"> | ||||
|       <bool>true</bool> | ||||
|      </property> | ||||
|     </widget> | ||||
|    </item> | ||||
|    <item> | ||||
|     <widget class="QPushButton" name="btnUpdateNow"> | ||||
|      <property name="sizePolicy"> | ||||
|       <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> | ||||
|        <horstretch>0</horstretch> | ||||
|        <verstretch>0</verstretch> | ||||
|       </sizepolicy> | ||||
|      </property> | ||||
|      <property name="text"> | ||||
|       <string>Update now</string> | ||||
|      </property> | ||||
|     </widget> | ||||
|    </item> | ||||
|    <item> | ||||
|     <widget class="QPushButton" name="btnUpdateOnExit"> | ||||
|      <property name="text"> | ||||
|       <string>Update after MultiMC closes</string> | ||||
|      </property> | ||||
|     </widget> | ||||
|    </item> | ||||
|    <item> | ||||
|     <widget class="QPushButton" name="btnUpdateLater"> | ||||
|      <property name="sizePolicy"> | ||||
|       <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> | ||||
|        <horstretch>0</horstretch> | ||||
|        <verstretch>0</verstretch> | ||||
|       </sizepolicy> | ||||
|      </property> | ||||
|      <property name="text"> | ||||
|       <string>Don't update yet</string> | ||||
|      </property> | ||||
|     </widget> | ||||
|     <layout class="QHBoxLayout" name="horizontalLayout"> | ||||
|      <item> | ||||
|       <widget class="QPushButton" name="btnUpdateNow"> | ||||
|        <property name="sizePolicy"> | ||||
|         <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> | ||||
|          <horstretch>0</horstretch> | ||||
|          <verstretch>0</verstretch> | ||||
|         </sizepolicy> | ||||
|        </property> | ||||
|        <property name="text"> | ||||
|         <string>Update now</string> | ||||
|        </property> | ||||
|       </widget> | ||||
|      </item> | ||||
|      <item> | ||||
|       <widget class="QPushButton" name="btnUpdateOnExit"> | ||||
|        <property name="text"> | ||||
|         <string>Update after MultiMC closes</string> | ||||
|        </property> | ||||
|       </widget> | ||||
|      </item> | ||||
|      <item> | ||||
|       <widget class="QPushButton" name="btnUpdateLater"> | ||||
|        <property name="sizePolicy"> | ||||
|         <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> | ||||
|          <horstretch>0</horstretch> | ||||
|          <verstretch>0</verstretch> | ||||
|         </sizepolicy> | ||||
|        </property> | ||||
|        <property name="text"> | ||||
|         <string>Don't update yet</string> | ||||
|        </property> | ||||
|       </widget> | ||||
|      </item> | ||||
|     </layout> | ||||
|    </item> | ||||
|   </layout> | ||||
|  </widget> | ||||
|  <tabstops> | ||||
|   <tabstop>changelogBrowser</tabstop> | ||||
|   <tabstop>btnUpdateNow</tabstop> | ||||
|   <tabstop>btnUpdateOnExit</tabstop> | ||||
|   <tabstop>btnUpdateLater</tabstop> | ||||
|  </tabstops> | ||||
|  <resources> | ||||
|   <include location="../../graphics.qrc"/> | ||||
|   <include location="../../resources/multimc/multimc.qrc"/> | ||||
|  </resources> | ||||
|  <connections/> | ||||
| </ui> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user