Index: sources/cloudsync/CloudSyncController.cpp =================================================================== diff -u -r3f60b9a1c0b3a43ec1c5c72955dce0d80354e35c -r1c23a7f4c576dd70c2bfb94a85af470b7d641f1e --- sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision 3f60b9a1c0b3a43ec1c5c72955dce0d80354e35c) +++ sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision 1c23a7f4c576dd70c2bfb94a85af470b7d641f1e) @@ -92,6 +92,8 @@ this , SLOT( onActionReceive (GuiActionType , const QVariantList &))); connect(&_TreatmentLog , SIGNAL(didTreatmentLogSave(const QString &, const QString &, const QString &)), this , SLOT( onTreatmentLogSave(const QString &, const QString &, const QString &))); + connect(this , SIGNAL(didInitComplete ()), + this , SLOT( onInitComplete ()),Qt::QueuedConnection); // it has to be queued connection, don't remove it. } /*! @@ -144,6 +146,28 @@ } /*! + * \brief CloudSyncController::event + * \details The override method of QObject event to handle the ThreadChange. + * \param vEvent - the QObject event + * \return true if the event e was recognized and processed + */ +bool CloudSyncController::event(QEvent *vEvent) { + if (vEvent->type() == QEvent::ThreadChange) { + emit didInitComplete(); + } + // Make sure the rest of events are handled + return QObject::event(vEvent); +} + +/*! + * \brief CloudSyncController::onInitComplete + * \details The slot to be called when the CloudSync initialization is complete, to call the testDeviceRegister. + */ +void CloudSyncController::onInitComplete() { + testDeviceRegister(); +} + +/*! * \brief CloudSyncController::onWatchFileChange * \details This slot will be called when the Device Controller identifies any changes in the watched files. * \param vFile - watched file @@ -294,6 +318,7 @@ case eError_CredentialMake : text = tr( "CS The credentials folder make failed." ) ; break; case eError_CredentialCopy : text = tr( "CS The credentials file copy failed." ) ; break; case eError_CredentialRemove: text = tr( "CS The credentials file remove failed." ) ; break; + case eError_CredentialEmpty : text = tr( "CS The credentials folder is empty." ) ; break; } return text; } @@ -311,7 +336,7 @@ // It means it is designed to not throw out of bound error and just use "~" as a missing info argument. auto item = [=](uint i) { return vInfoItems.value(i,"~").toString(); }; - QString info = QString( "[%1]" ).arg( vErrorID ) ; + QString info = QString( "[%1]" ).arg( vErrorID ) ; switch (vErrorID) { case eError_Unknown : ; break; case eError_OutFileEmpty : ; break; @@ -331,6 +356,7 @@ case eError_CredentialMake : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; case eError_CredentialCopy : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; case eError_CredentialRemove: info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_CredentialEmpty : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; } return info; } @@ -604,6 +630,7 @@ { // reset factory has not been implemented yet. bool ok = true; + // TODO: call the UI Software Reset Factory here when it has implemented. LOG_DEBUG("CloudSync Reset factory request has not been implemented yet."); return ok; } @@ -615,11 +642,12 @@ */ bool CloudSyncController::sendResetFactory() { + enum { eSucceed, eFailed }; bool ok = false; ok = doResetFactory(); // if ( ! ok ) { } /* Not defined */ qint32 messageID = UI2CS(eMessageID_ResetFactory); - ok = sendUIBuff(QString("%1,0,0").arg( messageID )); + ok = sendUIBuff(QString("%1,1,%2").arg( messageID ).arg( ok ? eSucceed : eFailed )); return ok; } @@ -693,8 +721,15 @@ */ bool CloudSyncController::testDeviceRegister() { - // the device registration request condition needs to be discussed. - return false; + QString source = QString(Storage::CloudSync_Base_Path_Name) + Storage::CloudSync_Credentials_Folder_Name; + QFileInfoList fileInfos = QDir(source).entryInfoList(QDir::NoDotAndDotDot|QDir::Files); + if( ! fileInfos.isEmpty() ) { + sendDeviceRegister(); + } else { + toLog(eError_CredentialEmpty,{}); // It is intentional that the vault folder path has not been sent to the log. + } + + return true; // for now always true. } /*!