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

View file

@ -208,18 +208,6 @@ public:
/// set a voxel which is to be rendered with a highlight /// set a voxel which is to be rendered with a highlight
void setHighlightVoxel(const VoxelDetail& highlightVoxel) { _highlightVoxel = highlightVoxel; } void setHighlightVoxel(const VoxelDetail& highlightVoxel) { _highlightVoxel = highlightVoxel; }
void setIsHighlightVoxel(bool isHighlightVoxel) { _isHighlightVoxel = isHighlightVoxel; } 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: public slots:
void domainChanged(const QString& domainHostname); void domainChanged(const QString& domainHostname);
@ -267,8 +255,6 @@ private slots:
void restoreMirrorView(); void restoreMirrorView();
void shrinkMirrorView(); void shrinkMirrorView();
void resetSensors(); void resetSensors();
void parseVersionXml(QNetworkReply *reply);
private: private:
void resetCamerasOnResizeGL(Camera& camera, int width, int height); void resetCamerasOnResizeGL(Camera& camera, int width, int height);
@ -522,6 +508,14 @@ private:
QString getLocalVoxelCacheFileName(); QString getLocalVoxelCacheFileName();
void updateLocalOctreeCache(bool firstTime = false); 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__) */ #endif /* defined(__interface__Application__) */

View file

@ -16,7 +16,7 @@
#include "SharedUtil.h" #include "SharedUtil.h"
#include "UpdateDialog.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(); Application* application = Application::getInstance();
QUiLoader updateDialogLoader; 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. \ 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.") 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); setAttribute(Qt::WA_DeleteOnClose);
QPushButton *_downloadButton = dialogWidget->findChild<QPushButton *>("downloadButton"); QPushButton *downloadButton = dialogWidget->findChild<QPushButton *>("downloadButton");
QPushButton *_skipButton = dialogWidget->findChild<QPushButton *>("skipButton"); QPushButton *skipButton = dialogWidget->findChild<QPushButton *>("skipButton");
QPushButton *_closeButton = dialogWidget->findChild<QPushButton *>("closeButton"); QPushButton *closeButton = dialogWidget->findChild<QPushButton *>("closeButton");
QLabel *_updateContent = dialogWidget->findChild<QLabel *>("updateContent"); QLabel *updateContent = dialogWidget->findChild<QLabel *>("updateContent");
_updateContent->setText(updateRequired); updateContent->setText(updateRequired);
connect(_downloadButton, SIGNAL(released()), this, SLOT(handleDownload())); connect(downloadButton, SIGNAL(released()), this, SLOT(handleDownload(QUrl downloadURL)));
connect(_skipButton, SIGNAL(released()), this, SLOT(handleSkip())); connect(skipButton, SIGNAL(released()), this, SLOT(handleSkip()));
connect(_closeButton, SIGNAL(released()), this, SLOT(handleClose())); connect(closeButton, SIGNAL(released()), this, SLOT(handleClose()));
dialogWidget->show(); dialogWidget->show();
} }
UpdateDialog::~UpdateDialog() { void UpdateDialog::handleDownload(QUrl downloadURL) {
deleteLater();
}
void UpdateDialog::toggleUpdateDialog() {
if (this->dialogWidget->isVisible()) {
this->dialogWidget->hide();
} else {
this->dialogWidget->show();
}
}
void UpdateDialog::handleDownload() {
Application* application = Application::getInstance(); Application* application = Application::getInstance();
QDesktopServices::openUrl(*application->_downloadURL); QDesktopServices::openUrl(downloadURL);
application->quit(); application->quit();
} }
void UpdateDialog::handleSkip() { void UpdateDialog::handleSkip() {
Application* application = Application::getInstance(); this->close();
application->skipVersion();
this->toggleUpdateDialog();
} }
void UpdateDialog::handleClose() { void UpdateDialog::handleClose() {
this->toggleUpdateDialog(); this->close();
} }

View file

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