-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #590 from GriffinRichards/update-promoter
Add update promoter
- Loading branch information
Showing
18 changed files
with
782 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>UpdatePromoter</class> | ||
<widget class="QDialog" name="UpdatePromoter"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>592</width> | ||
<height>484</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Porymap Version Update</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<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_2"> | ||
<item> | ||
<widget class="QLabel" name="label_Status"> | ||
<property name="text"> | ||
<string/> | ||
</property> | ||
<property name="wordWrap"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QLabel" name="label_Warning"> | ||
<property name="text"> | ||
<string><html><head/><body><p><span style=" font-size:13pt; color:#d7000c;">WARNING: </span><span style=" font-weight:400;">Updating Porymap may require you to update your projects. See "Breaking Changes" in the Changelog for details.</span></p></body></html></string> | ||
</property> | ||
<property name="wordWrap"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QFrame" name="frame_Changelog"> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="frameShape"> | ||
<enum>QFrame::NoFrame</enum> | ||
</property> | ||
<property name="frameShadow"> | ||
<enum>QFrame::Plain</enum> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout_3"> | ||
<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="QTextBrowser" name="text_Changelog"> | ||
<property name="openExternalLinks"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QCheckBox" name="checkBox_StopAlerts"> | ||
<property name="text"> | ||
<string>Do not alert me about new updates</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Close|QDialogButtonBox::Retry</set> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#ifndef NETWORK_H | ||
#define NETWORK_H | ||
|
||
/* | ||
The two classes defined here provide a simplified interface for Qt's network classes QNetworkAccessManager and QNetworkReply. | ||
With the Qt classes, the workflow for a GET is roughly: generate a QNetworkRequest, give this request to QNetworkAccessManager::get, | ||
connect the returned object to QNetworkReply::finished, and in the slot of that connection handle the various HTTP headers and attributes, | ||
then manage errors or process the webpage's body. | ||
These classes handle generating the QNetworkRequest with a given URL and manage the HTTP headers in the reply. They will automatically | ||
respect rate limits and return cached data if the webpage hasn't changed since previous requests. Instead of interacting with a QNetworkReply, | ||
callers interact with a simplified NetworkReplyData. | ||
Example that logs Porymap's description on GitHub: | ||
NetworkAccessManager * manager = new NetworkAccessManager(this); | ||
NetworkReplyData * reply = manager->get("https://api.github.com/repos/huderlem/porymap"); | ||
connect(reply, &NetworkReplyData::finished, [reply] () { | ||
if (!reply->errorString().isEmpty()) { | ||
logError(QString("Failed to read description: %1").arg(reply->errorString())); | ||
} else { | ||
auto webpage = QJsonDocument::fromJson(reply->body()); | ||
logInfo(QString("Porymap: %1").arg(webpage["description"].toString())); | ||
} | ||
reply->deleteLater(); | ||
}); | ||
*/ | ||
|
||
#include <QNetworkAccessManager> | ||
#include <QNetworkRequest> | ||
#include <QNetworkReply> | ||
#include <QDateTime> | ||
|
||
class NetworkReplyData : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QUrl url() const { return m_url; } | ||
QUrl nextUrl() const { return m_nextUrl; } | ||
QByteArray body() const { return m_body; } | ||
QString errorString() const { return m_error; } | ||
QDateTime retryAfter() const { return m_retryAfter; } | ||
bool isFinished() const { return m_finished; } | ||
|
||
friend class NetworkAccessManager; | ||
|
||
private: | ||
QUrl m_url; | ||
QUrl m_nextUrl; | ||
QByteArray m_body; | ||
QString m_error; | ||
QDateTime m_retryAfter; | ||
bool m_finished; | ||
|
||
void finish() { | ||
m_finished = true; | ||
emit finished(); | ||
}; | ||
|
||
signals: | ||
void finished(); | ||
}; | ||
|
||
class NetworkAccessManager : public QNetworkAccessManager | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
NetworkAccessManager(QObject * parent = nullptr); | ||
~NetworkAccessManager(); | ||
NetworkReplyData * get(const QString &url); | ||
NetworkReplyData * get(const QUrl &url); | ||
|
||
private: | ||
// For a more complex cache we could implement a QAbstractCache for the manager | ||
struct CacheEntry { | ||
QString eTag; | ||
QByteArray data; | ||
}; | ||
QMap<QUrl, CacheEntry*> cache; | ||
QMap<QUrl, QDateTime> rateLimitTimes; | ||
void processReply(QNetworkReply * reply, NetworkReplyData * data); | ||
const QNetworkRequest getRequest(const QUrl &url); | ||
}; | ||
|
||
#endif // NETWORK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.