Skip to content

Commit

Permalink
Merge pull request #5098 from opengisch/autopush_delay_fix
Browse files Browse the repository at this point in the history
Fix autopush timer interval value
  • Loading branch information
nirvn committed Mar 19, 2024
2 parents a3ce2fc + 53d5a89 commit 52355fe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
24 changes: 13 additions & 11 deletions src/core/qfieldcloudprojectsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,26 @@ QString QFieldCloudProjectsModel::currentProjectId() const

void QFieldCloudProjectsModel::setCurrentProjectId( const QString &currentProjectId )
{
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();
}
Expand Down Expand Up @@ -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();
Expand All @@ -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<int>() << StatusRole );
emit dataChanged( projectIndex, projectIndex, QVector<int>() << StatusRole << ModificationRole << LastLocalPushDeltasRole );
emit pushFinished( projectId, false );
projectRefreshData( projectId, ProjectRefreshReason::DeltaUploaded );
}
Expand Down
36 changes: 18 additions & 18 deletions src/qml/QFieldCloudPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand Down

1 comment on commit 52355fe

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.