diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index 21006bbb..c356b4e4 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -479,18 +479,44 @@ void UBApplicationController::showSankoreEditor() void UBApplicationController::checkUpdate() { - networkAccessManager->get (QNetworkRequest (QUrl ("http://getuniboard.com/dl/sankore/update.json"))); + mFtp = new QFtp(this); + connect(mFtp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool))); + + mFtp->connectToHost("91.121.248.138",21); + mFtp->login("anonymous", "anonymous"); + mFtp->get("update.json",0); +} + +void UBApplicationController::ftpCommandFinished(int id, bool error) +{ + if (error){ + qWarning() << "ftp command id" << id << "return the error: " << mFtp->errorString(); + mFtp->close(); + } + else{ + // 3 stand for the third command we have sent + // in our case + // 1->connect + // 2->login + // 3->get + if (id == 3){ + QString updateString = QString(mFtp->readAll()); + mFtp->close(); + downloadJsonFinished(updateString); + } + } } -void UBApplicationController::downloadJsonFinished(QNetworkReply* pReply) + + +void UBApplicationController::downloadJsonFinished(QString currentJson) { - QString currentJson = pReply->readAll(); QScriptValue scriptValue; QScriptEngine scriptEngine; scriptValue = scriptEngine.evaluate ("(" + currentJson + ")"); - UBVersion installedVersion (qApp->applicationVersion()); - UBVersion jsonVersion (scriptValue.property("version").toString()); + UBVersion installedVersion (qApp->applicationVersion().left(4)); + UBVersion jsonVersion (scriptValue.property("version").toString().left(4)); if (installedVersion.isValid() && jsonVersion.isValid() && jsonVersion > installedVersion) { QMessageBox msgBox; @@ -511,7 +537,8 @@ void UBApplicationController::downloadJsonFinished(QNetworkReply* pReply) // should never be reached break; } - } else { + } + else { if (isNoUpdateDisplayed) { QMessageBox msgBox; msgBox.setText (tr ("No update available")); diff --git a/src/core/UBApplicationController.h b/src/core/UBApplicationController.h index 4e0cdc89..caa46d09 100644 --- a/src/core/UBApplicationController.h +++ b/src/core/UBApplicationController.h @@ -3,6 +3,7 @@ #define UBAPPLICATIONCONTROLLER_H_ #include +#include class UBBoardView; class UBDocumentProxy; @@ -16,6 +17,7 @@ class UBSoftwareUpdate; class QNetworkAccessManager; class QNetworkReply; + class UBApplicationController : public QObject { Q_OBJECT; @@ -117,7 +119,9 @@ class UBApplicationController : public QObject void checkUpdateRequest(); void checkUpdateAtLaunch(); - void downloadJsonFinished(QNetworkReply* pReply); + + private slots: + void ftpCommandFinished(int id, bool error); protected: @@ -134,6 +138,7 @@ class UBApplicationController : public QObject UBScreenMirror* mMirror; int mInitialHScroll, mInitialVScroll; + QFtp* mFtp; private: @@ -151,6 +156,8 @@ class UBApplicationController : public QObject bool isNoUpdateDisplayed; void checkUpdate (); QNetworkAccessManager *networkAccessManager; + + void downloadJsonFinished(QString updateString); }; #endif /* UBAPPLICATIONCONTROLLER_H_ */