Improve update check information dialog.

Show the user both the current and updated version.

Change-Id: Ief693cce020a39a0c79bf2705da4a44b7bd15928
This commit is contained in:
Dominik Riebeling 2015-01-31 18:30:42 +01:00
parent 43b1ccffcc
commit 72b81c2559
5 changed files with 60 additions and 15 deletions

View file

@ -342,6 +342,20 @@ QString Utils::checkEnvironment(bool permission)
else
return text;
}
/** @brief Trim version string from filename to version part only.
* @param s Version string
* @return Version part of string if found, input string on error.
*/
QString Utils::trimVersionString(QString s)
{
QRegExp r = QRegExp(".*([\\d\\.]+\\d+[a-z]?).*");
if(r.indexIn(s) != -1) {
return r.cap(1);
}
return s;
}
/** @brief Compare two version strings.
* @param s1 first version string
* @param s2 second version string

View file

@ -49,6 +49,7 @@ public:
static QString findExecutable(QString name);
static QString checkEnvironment(bool permission);
static int compareVersionStrings(QString s1, QString s2);
static QString trimVersionString(QString s);
static QString filesystemName(QString path);
static QStringList mountpoints(enum MountpointsFilter type = MountpointsAll);
static QString resolveDevicename(QString path);

View file

@ -21,6 +21,7 @@ Version 1.4
* Fix manual link for Archos Recorder V2.
Version 1.4.1
* Fix crash on detecting player in MTP mode.
* Fix crash on detecting player in MTP mode (FS#12989).
* Extend hint when uninstallation requires reinstalling the Original Firmware.
* Improve update check information dialog.

View file

@ -729,10 +729,11 @@ void RbUtilQt::downloadUpdateDone(bool error)
#endif
url += foundVersion;
QMessageBox::information(this,tr("RockboxUtility Update available"),
tr("<b>New RockboxUtility Version available.</b> <br><br>"
"Download it from here: <a href='%1'>%2</a>")
.arg(url).arg(foundVersion));
QMessageBox::information(this,tr("Rockbox Utility Update available"),
tr("<b>New Rockbox Utility version available.</b><br><br>"
"You are currently using version %1. "
"Get version %2 at <a href='%3'>%3</a>")
.arg(VERSION).arg(Utils::trimVersionString(foundVersion)).arg(url));
ui.statusbar->showMessage(tr("New version of Rockbox Utility available."));
}
else {

View file

@ -27,17 +27,18 @@ class TestVersionCompare : public QObject
{
Q_OBJECT
private slots:
void testMain();
void testCompare();
void testTrim();
};
struct testvector {
struct compvector {
const char* first;
const char* second;
const int expected;
};
const struct testvector testdata[] =
const struct compvector compdata[] =
{
{ "1.2.3", "1.2.3 ", 0 },
{ "1.2.3", " 1.2.3", 0 },
@ -73,17 +74,44 @@ const struct testvector testdata[] =
{ "prog-1.2a-64bit.tar.bz2","prog-1.2.3-64bit.tar.bz2", 1 },
};
struct trimvector {
const char* input;
const QString expected;
};
void TestVersionCompare::testMain()
const struct trimvector trimdata[] =
{
{ "prog-1.2-64bit.tar.bz2", "1.2" },
{ "prog-1.2.tar.bz2", "1.2" },
{ "1.2.3", "1.2.3" },
{ " 1.2.3", "1.2.3" },
{ "1.2.3 ", "1.2.3" },
{ "10.22.33", "10.22.33" },
{ "test-1.2.3", "1.2.3" },
{ "1.2.3", "1.2.3" },
{ "test-1.2.3.tar.gz", "1.2.3" },
{ "prog-1.2-64bit.tar.bz2", "1.2" },
{ "prog-1.2a.tar.bz2", "1.2a" },
{ "prog-1.2a-64bit.tar.bz2","1.2a" },
};
void TestVersionCompare::testCompare()
{
unsigned int i;
for(i = 0; i < sizeof(testdata) / sizeof(struct testvector); i++) {
QCOMPARE(Utils::compareVersionStrings(testdata[i].first,
testdata[i].second), testdata[i].expected);
for(i = 0; i < sizeof(compdata) / sizeof(struct compvector); i++) {
QCOMPARE(Utils::compareVersionStrings(compdata[i].first,
compdata[i].second), compdata[i].expected);
// inverse test possible because function return values are symmetrical.
if(testdata[i].expected != 0)
QCOMPARE(Utils::compareVersionStrings(testdata[i].second,
testdata[i].first), -testdata[i].expected);
if(compdata[i].expected != 0)
QCOMPARE(Utils::compareVersionStrings(compdata[i].second,
compdata[i].first), -compdata[i].expected);
}
}
void TestVersionCompare::testTrim()
{
for(int i = 0; i < sizeof(trimdata) / sizeof(struct trimvector); i++) {
QCOMPARE(Utils::trimVersionString(trimdata[i].input), trimdata[i].expected);
}
}