diff --git a/src/core/qfieldcloudprojectsmodel.cpp b/src/core/qfieldcloudprojectsmodel.cpp index a54dffacec..355d0af9a0 100644 --- a/src/core/qfieldcloudprojectsmodel.cpp +++ b/src/core/qfieldcloudprojectsmodel.cpp @@ -154,26 +154,26 @@ QString QFieldCloudProjectsModel::currentProjectId() const void QFieldCloudProjectsModel::setCurrentProjectId( const QString ¤tProjectId ) { - if ( mCurrentProjectId == currentProjectId ) - return; - - mCurrentProjectId = currentProjectId; - - if ( mCurrentProjectId != QString() ) + if ( currentProjectId != QString() ) { const bool forceAutoPush = mProject->readBoolEntry( QStringLiteral( "qfieldsync" ), QStringLiteral( "forceAutoPush" ), false ); if ( forceAutoPush ) { - projectSetForceAutoPush( mCurrentProjectId, true ); - projectSetAutoPushEnabled( mCurrentProjectId, true ); - projectSetAutoPushIntervalMins( mCurrentProjectId, mProject->readNumEntry( QStringLiteral( "qfieldsync" ), QStringLiteral( "forceAutoPushIntervalMins" ) ) ); + projectSetForceAutoPush( currentProjectId, true ); + projectSetAutoPushEnabled( currentProjectId, true ); + projectSetAutoPushIntervalMins( currentProjectId, mProject->readNumEntry( QStringLiteral( "qfieldsync" ), QStringLiteral( "forceAutoPushIntervalMins" ) ) ); } else { - projectSetForceAutoPush( mCurrentProjectId, false ); + projectSetForceAutoPush( currentProjectId, false ); } } + if ( mCurrentProjectId == currentProjectId ) + return; + + mCurrentProjectId = currentProjectId; + emit currentProjectIdChanged(); emit currentProjectDataChanged(); } @@ -1410,6 +1410,8 @@ void QFieldCloudProjectsModel::projectUpload( const QString &projectId, const bo { project->status = ProjectStatus::Idle; project->modification ^= LocalModification; + project->lastLocalPushDeltas = QDateTime::currentDateTimeUtc().toString( Qt::ISODate ); + QFieldCloudUtils::setProjectSetting( projectId, QStringLiteral( "lastLocalPushDeltas" ), project->lastLocalPushDeltas ); DeltaFileWrapper *deltaFileWrapper = mLayerObserver->deltaFileWrapper(); deltaFileWrapper->reset(); @@ -1419,7 +1421,7 @@ void QFieldCloudProjectsModel::projectUpload( const QString &projectId, const bo if ( !deltaFileWrapper->toFile() ) QgsMessageLog::logMessage( QStringLiteral( "Failed to reset delta file after delta push. %1" ).arg( deltaFileWrapper->errorString() ) ); - emit dataChanged( projectIndex, projectIndex, QVector() << StatusRole ); + emit dataChanged( projectIndex, projectIndex, QVector() << StatusRole << ModificationRole << LastLocalPushDeltasRole ); emit pushFinished( projectId, false ); projectRefreshData( projectId, ProjectRefreshReason::DeltaUploaded ); } diff --git a/src/qml/QFieldCloudPopup.qml b/src/qml/QFieldCloudPopup.qml index 20e524a4bc..cd9d558347 100644 --- a/src/qml/QFieldCloudPopup.qml +++ b/src/qml/QFieldCloudPopup.qml @@ -509,7 +509,7 @@ Popup { Timer { id: autoPushTimer running: !!cloudProjectsModel.currentProjectData.AutoPushEnabled - interval: (!cloudProjectsModel.currentProjectData.AutoPushIntervalMins - 0) * 60 * 1000 + interval: (cloudProjectsModel.currentProjectData.AutoPushIntervalMins) * 60 * 1000 repeat: true onRunningChanged: { @@ -539,43 +539,43 @@ Popup { color: Theme.secondaryTextColor text: { var exportText = '' - var dt = cloudProjectsModel.currentProjectData.LastLocalExportedAt + var exportDt = cloudProjectsModel.currentProjectData.LastLocalExportedAt var timeDeltaMinutes = null - if (dt) { - dt = new Date(dt) - timeDeltaMinutes = parseInt( Math.max( new Date() - dt, 0 ) / (60 * 1000) ); + if (exportDt) { + exportDt = new Date(exportDt) + timeDeltaMinutes = parseInt( Math.max( new Date() - exportDt, 0 ) / (60 * 1000) ) if ( timeDeltaMinutes < 1) exportText = qsTr( 'Last synchronized just now' ) else if (timeDeltaMinutes < 60) exportText = qsTr( 'Last synchronized %1 minutes ago' ).arg( timeDeltaMinutes ) - else if (dt.toLocaleDateString() === new Date().toLocaleDateString()) - exportText = qsTr( 'Last synchronized at %1' ).arg( dt.toLocaleTimeString() ) + else if (exportDt.toLocaleDateString() === new Date().toLocaleDateString()) + exportText = qsTr( 'Last synchronized at %1' ).arg( exportDt.toLocaleTimeString() ) else - exportText = qsTr( 'Last synchronized on %1' ).arg( dt.toLocaleString() ) + exportText = qsTr( 'Last synchronized on %1' ).arg( exportDt.toLocaleString() ) } var pushText = '' - dt = cloudProjectsModel.currentProjectData.LastLocalPushDeltas + var pushDt = cloudProjectsModel.currentProjectData.LastLocalPushDeltas - if (dt) { - dt = new Date(dt) - timeDeltaMinutes = parseInt( Math.max( new Date() - dt, 0 ) / (60 * 1000) ); + if (pushDt) { + pushDt = new Date(pushDt) + timeDeltaMinutes = parseInt( Math.max( new Date() - pushDt, 0 ) / (60 * 1000) ) if ( timeDeltaMinutes < 1 ) - exportText = qsTr( 'Last changes pushed just now' ) + pushText = qsTr( 'Last changes pushed just now' ) else if (timeDeltaMinutes < 60) - exportText = qsTr( 'Last changes pushed %1 minutes ago' ).arg( timeDeltaMinutes ) - else if (dt.toLocaleDateString() === new Date().toLocaleDateString()) - pushText = qsTr( 'Last changes pushed at %1' ).arg( dt.toLocaleTimeString() ) + pushText = qsTr( 'Last changes pushed %1 minutes ago' ).arg( timeDeltaMinutes ) + else if (pushDt.toLocaleDateString() === new Date().toLocaleDateString()) + pushText = qsTr( 'Last changes pushed at %1' ).arg( pushDt.toLocaleTimeString() ) else - pushText = qsTr( 'Last changes pushed on %1' ).arg( dt.toLocaleString() ) + pushText = qsTr( 'Last changes pushed on %1' ).arg( pushDt.toLocaleString() ) } else { pushText = qsTr( 'No changes pushed yet' ) } - return exportText + '\n' + pushText + return pushDt > exportDt ? pushText + '\n' + exportText : exportText + '\n' + pushText } wrapMode: Text.WordWrap horizontalAlignment: Text.AlignHCenter