summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/rbutilqt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/rbutilqt.cpp')
-rw-r--r--rbutil/rbutilqt/rbutilqt.cpp139
1 files changed, 138 insertions, 1 deletions
diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp
index ec06955eef..083d35d8d9 100644
--- a/rbutil/rbutilqt/rbutilqt.cpp
+++ b/rbutil/rbutilqt/rbutilqt.cpp
@@ -212,7 +212,7 @@ void RbUtilQt::downloadDone(bool error)
212 bleeding = new HttpGet(this); 212 bleeding = new HttpGet(this);
213 connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool))); 213 connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool)));
214 connect(bleeding, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool))); 214 connect(bleeding, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
215 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort())); 215 connect(qApp, SIGNAL(lastWindowClosed()), bleeding, SLOT(abort()));
216 if(RbSettings::value(RbSettings::CacheOffline).toBool()) 216 if(RbSettings::value(RbSettings::CacheOffline).toBool())
217 bleeding->setCache(true); 217 bleeding->setCache(true);
218 bleeding->setFile(&bleedingInfo); 218 bleeding->setFile(&bleedingInfo);
@@ -251,6 +251,9 @@ void RbUtilQt::downloadBleedingDone(bool error)
251 qDebug() << "[RbUtil] version map:" << versmap; 251 qDebug() << "[RbUtil] version map:" << versmap;
252 252
253 m_gotInfo = true; 253 m_gotInfo = true;
254
255 //start check for updates
256 checkUpdate();
254 } 257 }
255} 258}
256 259
@@ -1217,4 +1220,138 @@ bool RbUtilQt::chkConfig(bool warn)
1217 return error; 1220 return error;
1218} 1221}
1219 1222
1223void RbUtilQt::checkUpdate(void)
1224{
1225 QString url = RbSettings::value(RbSettings::RbutilUrl).toString();
1226#if defined(Q_OS_WIN32)
1227 url += "win32/";
1228#elif defined(Q_OS_LINUX)
1229 url += "linux/";
1230#elif defined(Q_OS_MACX)
1231 url += "macosx/";
1232#endif
1233
1234 update = new HttpGet(this);
1235 connect(update, SIGNAL(done(bool)), this, SLOT(downloadUpdateDone(bool)));
1236 connect(update, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
1237 connect(qApp, SIGNAL(lastWindowClosed()), update, SLOT(abort()));
1238 if(RbSettings::value(RbSettings::CacheOffline).toBool())
1239 update->setCache(true);
1240
1241 update->getFile(QUrl(url));
1242}
1220 1243
1244void RbUtilQt::downloadUpdateDone(bool error)
1245{
1246 if(error) {
1247 qDebug() << "[RbUtil] network error:" << update->error();
1248 }
1249 else {
1250 QString toParse(update->readAll());
1251 qDebug() << "[Checkupdate] " << toParse;
1252
1253 QRegExp searchString("<a[^>]*>(rbutilqt[^<]*)</a>");
1254 QStringList rbutilList;
1255 int pos = 0;
1256 while ((pos = searchString.indexIn(toParse, pos)) != -1)
1257 {
1258 rbutilList << searchString.cap(1);
1259 pos += searchString.matchedLength();
1260 }
1261
1262 QString newVersion ="";
1263 //check if there is a binary with higher version in this list
1264 for(int i=0; i < rbutilList.size(); i++)
1265 {
1266#if defined(Q_OS_LINUX)
1267#if defined(__amd64__)
1268 //skip if it isnt a 64bit build
1269 if( !rbutilList.at(i).contains("64bit"))
1270 continue;
1271#else
1272 //skip if it is a 64bit build
1273 if(rbutilList.at(i).contains("64bit"))
1274 continue;
1275#endif
1276#endif
1277 //check if it is newer, and remember newest
1278 if(newerVersion(VERSION,rbutilList.at(i)))
1279 {
1280 if(newVersion == "" || newerVersion(newVersion,rbutilList.at(i)))
1281 {
1282 newVersion = rbutilList.at(i);
1283 }
1284 }
1285 }
1286
1287 // if we found something newer, display info
1288 if(newVersion != "")
1289 {
1290 QString url = RbSettings::value(RbSettings::RbutilUrl).toString();
1291#if defined(Q_OS_WIN32)
1292 url += "win32/";
1293#elif defined(Q_OS_LINUX)
1294 url += "linux/";
1295#elif defined(Q_OS_MACX)
1296 url += "macosx/";
1297#endif
1298 url += newVersion;
1299
1300 QMessageBox::information(this,tr("RockboxUtility Update available"),
1301 tr("<b>New RockboxUtility Version available.</b> <br><br>"
1302 "Download it from here: <a href='%1'>%2</a>").arg(url).arg(newVersion) );
1303 }
1304 }
1305}
1306
1307bool RbUtilQt::newerVersion(QString versionOld,QString versionNew)
1308{
1309 QRegExp chars("\\d*(\\D)");
1310
1311 //strip non-number from beginning
1312 versionOld = versionOld.remove(0,versionOld.indexOf(QRegExp("\\d")));
1313 versionNew = versionNew.remove(0,versionNew.indexOf(QRegExp("\\d")));
1314
1315 // split versions by "."
1316 QStringList versionListOld = versionOld.split(".");
1317 QStringList versionListNew = versionNew.split(".");
1318
1319 QStringListIterator iteratorOld(versionListOld);
1320 QStringListIterator iteratorNew(versionListNew);
1321
1322 //check every section
1323 while(iteratorOld.hasNext() && iteratorNew.hasNext())
1324 {
1325 QString newPart = iteratorNew.next();
1326 QString oldPart = iteratorOld.next();
1327 QString newPartChar = "", oldPartChar = "";
1328 int newPartInt = 0, oldPartInt =0;
1329
1330 //convert to int, if it contains chars, put into seperated variable
1331 if(newPart.contains(chars))
1332 {
1333 newPartChar = chars.cap(1);
1334 newPart = newPart.remove(newPartChar);
1335 }
1336 newPartInt = newPart.toInt();
1337 //convert to int, if it contains chars, put into seperated variable
1338 if(oldPart.contains(chars))
1339 {
1340 oldPartChar = chars.cap(1);
1341 oldPart = oldPart.remove(oldPartChar);
1342 }
1343 oldPartInt = oldPart.toInt();
1344
1345 if(newPartInt > oldPartInt) // this section int is higher -> true
1346 return true;
1347 else if(newPartInt < oldPartInt) //this section int is lower -> false
1348 return false;
1349 else if(newPartChar > oldPartChar) //ints are the same, chars is higher -> true
1350 return true;
1351 else if(newPartChar < oldPartChar) //ints are the same, chars is lower -> false
1352 return false;
1353 //all the same, next section
1354 }
1355 // all the same -> false
1356 return false;
1357}