This commit is contained in:
Leonardo Murillo 2014-01-17 13:06:54 -06:00
parent 746b45d939
commit b8aaf4e813
4 changed files with 44 additions and 61 deletions

View file

@ -4422,18 +4422,22 @@ void Application::checkVersion() {
}
void Application::parseVersionXml(QNetworkReply *reply) {
QString *_operatingSystem;
QString *operatingSystem;
#ifdef Q_OS_WIN32
_operatingSystem = new QString("win");
operatingSystem = new QString("win");
#endif
#ifdef Q_OS_MAC
_operatingSystem = new QString("mac");
operatingSystem = new QString("mac");
#endif
QString _releaseDate;
QString _releaseNotes;
QString releaseDate;
QString releaseNotes;
QString latestVersion;
QUrl downloadURL;
QWidget *updateDialog;
QXmlStreamReader xml(reply);
while (!xml.atEnd() && !xml.hasError()) {
@ -4442,25 +4446,25 @@ void Application::parseVersionXml(QNetworkReply *reply) {
if (token == QXmlStreamReader::StartElement) {
if (xml.name() == "ReleaseDate") {
xml.readNext();
_releaseDate = xml.text().toString();
releaseDate = xml.text().toString();
}
if (xml.name() == "ReleaseNotes") {
xml.readNext();
_releaseNotes = xml.text().toString();
releaseNotes = xml.text().toString();
}
if (xml.name() == "Version") {
xml.readNext();
_latestVersion = new QString(xml.text().toString());
latestVersion = xml.text().toString();
}
if (xml.name() == _operatingSystem) {
if (xml.name() == operatingSystem) {
xml.readNext();
_downloadURL = new QUrl(xml.text().toString());
downloadURL = QUrl(xml.text().toString());
}
}
}
if (!shouldSkipVersion() && applicationVersion() != _latestVersion) {
_updateDialog = new UpdateDialog(_glWidget, _releaseNotes);
if (!shouldSkipVersion(latestVersion) && applicationVersion() != latestVersion) {
updateDialog = new UpdateDialog(_glWidget, releaseNotes);
}
}
@ -4472,20 +4476,20 @@ QFile *Application::loadSkipFile() {
return file;
}
bool Application::shouldSkipVersion() {
bool Application::shouldSkipVersion(QString latestVersion) {
QFile *skipFile = loadSkipFile();
QByteArray skipFileContents = skipFile->readAll();
QString *skipVersion = new QString(skipFileContents);
skipFile->close();
if (*skipVersion == *_latestVersion || applicationVersion() == "0.1") {
if (*skipVersion == latestVersion || applicationVersion() == "0.1") {
return true;
}
return false;
}
void Application::skipVersion() {
void Application::skipVersion(QString latestVersion) {
QFile *skipFile = loadSkipFile();
skipFile->seek(0);
skipFile->write(_latestVersion->toStdString().c_str());
skipFile->write(latestVersion.toStdString().c_str());
skipFile->close();
}

View file

@ -208,18 +208,6 @@ public:
/// set a voxel which is to be rendered with a highlight
void setHighlightVoxel(const VoxelDetail& highlightVoxel) { _highlightVoxel = highlightVoxel; }
void setIsHighlightVoxel(bool isHighlightVoxel) { _isHighlightVoxel = isHighlightVoxel; }
// Get XML with version information and parse it
// Display dialog when version is not the latest and allow for new version download from link
QFile *loadSkipFile();
void checkVersion();
void displayUpdateDialog();
bool shouldSkipVersion();
void skipVersion();
QString *_latestVersion;
QUrl *_downloadURL;
QWidget *_updateDialog;
public slots:
void domainChanged(const QString& domainHostname);
@ -267,8 +255,6 @@ private slots:
void restoreMirrorView();
void shrinkMirrorView();
void resetSensors();
void parseVersionXml(QNetworkReply *reply);
private:
void resetCamerasOnResizeGL(Camera& camera, int width, int height);
@ -522,6 +508,14 @@ private:
QString getLocalVoxelCacheFileName();
void updateLocalOctreeCache(bool firstTime = false);
QFile *loadSkipFile();
void checkVersion();
void displayUpdateDialog();
bool shouldSkipVersion(QString latestVersion);
void skipVersion(QString latestVersion);
void parseVersionXml(QNetworkReply *reply);
};
#endif /* defined(__interface__Application__) */

View file

@ -16,7 +16,7 @@
#include "SharedUtil.h"
#include "UpdateDialog.h"
UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes) : QDialog(parent, Qt::Dialog) {
UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString latestVersion, QUrl downloadURL) : QDialog(parent, Qt::Dialog) {
Application* application = Application::getInstance();
QUiLoader updateDialogLoader;
@ -28,48 +28,34 @@ UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes) : QDialog(pare
const QString updateRequired = QString("You are currently running build %1, the latest build released is %2. \
Please download and install the most recent release to access the latest features and bug fixes.")
.arg(application->applicationVersion(), *application->_latestVersion);
.arg(application->applicationVersion(), latestVersion);
setAttribute(Qt::WA_DeleteOnClose);
QPushButton *_downloadButton = dialogWidget->findChild<QPushButton *>("downloadButton");
QPushButton *_skipButton = dialogWidget->findChild<QPushButton *>("skipButton");
QPushButton *_closeButton = dialogWidget->findChild<QPushButton *>("closeButton");
QLabel *_updateContent = dialogWidget->findChild<QLabel *>("updateContent");
QPushButton *downloadButton = dialogWidget->findChild<QPushButton *>("downloadButton");
QPushButton *skipButton = dialogWidget->findChild<QPushButton *>("skipButton");
QPushButton *closeButton = dialogWidget->findChild<QPushButton *>("closeButton");
QLabel *updateContent = dialogWidget->findChild<QLabel *>("updateContent");
_updateContent->setText(updateRequired);
updateContent->setText(updateRequired);
connect(_downloadButton, SIGNAL(released()), this, SLOT(handleDownload()));
connect(_skipButton, SIGNAL(released()), this, SLOT(handleSkip()));
connect(_closeButton, SIGNAL(released()), this, SLOT(handleClose()));
connect(downloadButton, SIGNAL(released()), this, SLOT(handleDownload(QUrl downloadURL)));
connect(skipButton, SIGNAL(released()), this, SLOT(handleSkip()));
connect(closeButton, SIGNAL(released()), this, SLOT(handleClose()));
dialogWidget->show();
}
UpdateDialog::~UpdateDialog() {
deleteLater();
}
void UpdateDialog::toggleUpdateDialog() {
if (this->dialogWidget->isVisible()) {
this->dialogWidget->hide();
} else {
this->dialogWidget->show();
}
}
void UpdateDialog::handleDownload() {
void UpdateDialog::handleDownload(QUrl downloadURL) {
Application* application = Application::getInstance();
QDesktopServices::openUrl(*application->_downloadURL);
QDesktopServices::openUrl(downloadURL);
application->quit();
}
void UpdateDialog::handleSkip() {
Application* application = Application::getInstance();
application->skipVersion();
this->toggleUpdateDialog();
this->close();
}
void UpdateDialog::handleClose() {
this->toggleUpdateDialog();
this->close();
}

View file

@ -21,15 +21,14 @@ class UpdateDialog : public QDialog {
Q_OBJECT
public:
UpdateDialog(QWidget*, QString releaseNotes);
UpdateDialog(QWidget*, QString releaseNotes, QString latestVersion, QUrl downloadURL);
~UpdateDialog();
void toggleUpdateDialog();
private:
QWidget *dialogWidget;
private slots:
void handleDownload();
void handleDownload(QUrl downloadURL);
void handleSkip();
void handleClose();
};