From b8aaf4e813d1e77622e15cbaadbfa6f78518b5a6 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Fri, 17 Jan 2014 13:06:54 -0600 Subject: [PATCH] CR fixes --- interface/src/Application.cpp | 36 ++++++++++++++------------ interface/src/Application.h | 22 ++++++---------- interface/src/ui/UpdateDialog.cpp | 42 +++++++++++-------------------- interface/src/ui/UpdateDialog.h | 5 ++-- 4 files changed, 44 insertions(+), 61 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e1e0446ef4..f8621f03c6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -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(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index d9ea3c8ae3..3b5276f891 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -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__) */ diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 5096c462d3..256183682b 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -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("downloadButton"); - QPushButton *_skipButton = dialogWidget->findChild("skipButton"); - QPushButton *_closeButton = dialogWidget->findChild("closeButton"); - QLabel *_updateContent = dialogWidget->findChild("updateContent"); + QPushButton *downloadButton = dialogWidget->findChild("downloadButton"); + QPushButton *skipButton = dialogWidget->findChild("skipButton"); + QPushButton *closeButton = dialogWidget->findChild("closeButton"); + QLabel *updateContent = dialogWidget->findChild("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(); } \ No newline at end of file diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index 50ab7dacbe..f91424c656 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -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(); };