changeset 554:866129da93cb

The version check now really compares the version numbers as numbers and not only as different strings. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@794 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Thu, 02 Oct 2008 14:16:28 +0000
parents 3ba421b9a389
children a859299fb54a
files src/updatecheckdialog.cpp src/updatecheckdialog.h
diffstat 2 files changed, 37 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/updatecheckdialog.cpp	Wed Oct 01 20:23:31 2008 +0000
+++ b/src/updatecheckdialog.cpp	Thu Oct 02 14:16:28 2008 +0000
@@ -19,6 +19,8 @@
 
 #include "updatecheckdialog.h"
 
+#include <QRegExpValidator>
+
 /*!
     \class UpdateCheckDialog
     \ingroup grp_MainWindow
@@ -114,8 +116,12 @@
             // Get the pure version string from returned string.
             returnedString = returnedString.mid( leftPosition+17, rightPosition-(leftPosition+17) );
 
-            // Only show update dialog, if the current version string is not equal to the received one.
-            if ( returnedString != currentVersion ) {
+            // Create integer values from the version strings.
+            int versionOnServerInt = convertVersionStringToNumber( returnedString );
+            int currentVersionInt = convertVersionStringToNumber( currentVersion );
+
+            // Only show update dialog, if the current version number is lower than the one received from the server.
+            if ( versionOnServerInt > currentVersionInt && currentVersionInt >= 0 && versionOnServerInt >= 0 ) {
                 // Show message box whether to download the new version.
                 showNewVersionAvailableDialog(returnedString);
 
@@ -232,3 +238,31 @@
     // Update the progress bar value.
     progressBar->setValue(updateCheckProgressCounter);
 }
+
+
+/*!
+    \brief Converts the as string given version \a versionString to an integer number.
+
+    The \a versionString must have the format x.x.x where each x represents a number
+    of a maximum of 999. If the input format is wrong, -1 will be returned.The first 
+    number will be multiplied by 1000000 the second by 1000 and then all three will
+    be summarized.
+
+    Thus for example 12.5.170 will result in 12005170.
+ */
+int UpdateCheckDialog::convertVersionStringToNumber(QString versionString) {
+    int versionInteger = 0;
+    int pos = 0;
+
+    QRegExp regEx("\\d{1,3}.\\d{1,3}.\\d{1,3}");
+    QRegExpValidator validator(regEx, NULL);
+
+    if ( validator.validate(versionString, pos) == QValidator::Acceptable ) {
+        QStringList versionNumberStringList = versionString.split(".");
+    }
+    else {
+        versionInteger = -1;
+    }
+
+    return versionInteger;
+}
--- a/src/updatecheckdialog.h	Wed Oct 01 20:23:31 2008 +0000
+++ b/src/updatecheckdialog.h	Thu Oct 02 14:16:28 2008 +0000
@@ -57,6 +57,7 @@
     QDialogButtonBox::ButtonRole roleOfClickedButton;
     QTimer *updateCheckProgressTimer;
     int updateCheckProgressCounter;
+    int convertVersionStringToNumber(QString versionString);
 
 private slots:
     void checkResultsOfFetchedPadXMLFile(bool errorOccurred);