Skip to content

Commit

Permalink
Enforce auto-push settings coming from the project file
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Feb 28, 2024
1 parent 60bfd8e commit a5f1e82
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/core/qfieldcloudprojectsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1961,12 +1961,25 @@ void QFieldCloudProjectsModel::projectSetAutoPushEnabled( const QString &project
if ( projectIndex.isValid() )
{
CloudProject *project = mProjects[projectIndex.row()];
project->autoPushEnabled = !project->autoPushEnabled;
project->autoPushEnabled = enabled;
QFieldCloudUtils::setProjectSetting( project->id, QStringLiteral( "autoPushEnabled" ), project->autoPushEnabled );
emit dataChanged( projectIndex, projectIndex, QVector<int>() << AutoPushEnabledRole );
}
}

void QFieldCloudProjectsModel::projectSetAutoPushIntervalMins( const QString &projectId, int minutes )
{
const QModelIndex projectIndex = findProjectIndex( projectId );

if ( projectIndex.isValid() )
{
CloudProject *project = mProjects[projectIndex.row()];
project->autoPushIntervalMins = minutes;
QFieldCloudUtils::setProjectSetting( project->id, QStringLiteral( "autoPushIntervalMins" ), project->autoPushIntervalMins );
emit dataChanged( projectIndex, projectIndex, QVector<int>() << AutoPushIntervalMinsRole );
}
}

void QFieldCloudProjectsModel::reload( const QJsonArray &remoteProjects )
{
beginResetModel();
Expand Down
3 changes: 3 additions & 0 deletions src/core/qfieldcloudprojectsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ class QFieldCloudProjectsModel : public QAbstractListModel
//! Toggles the cloud project auto-push enabled state
Q_INVOKABLE void projectSetAutoPushEnabled( const QString &projectId, bool enabled );

//! Sets the interval in \a minutes between which the project will auto-push changes
Q_INVOKABLE void projectSetAutoPushIntervalMins( const QString &projectId, int minutes );

signals:
void cloudConnectionChanged();
void layerObserverChanged();
Expand Down
28 changes: 26 additions & 2 deletions src/qml/QFieldCloudPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,19 @@ Popup {
bottomPadding: 10
font: Theme.tipFont
wrapMode: Text.WordWrap
color: autoPush.checked ? Theme.mainTextColor : Theme.secondaryTextColor
color: autoPush.checked || autoPush.forceAutoPush ? Theme.mainTextColor : Theme.secondaryTextColor

text: qsTr('Automatically push changes every %n minute(s)','',0 + cloudProjectsModel.currentProjectData.AutoPushIntervalMins)

MouseArea {
anchors.fill: parent
onClicked: cloudProjectsModel.projectSetAutoPushEnabled(cloudProjectsModel.currentProjectId, !autoPush.checked)
onClicked: {
if (autoPush.forceAutoPush) {
displayToast(qsTr('The current project does not allow for auto-push to be turned off'))
} else {
cloudProjectsModel.projectSetAutoPushEnabled(cloudProjectsModel.currentProjectId, !autoPush.checked)
}
}
}
}

Expand All @@ -493,7 +499,9 @@ Popup {
width: implicitContentWidth
small: true

property bool forceAutoPush: false
checked: !!cloudProjectsModel.currentProjectData.AutoPushEnabled

onClicked: {
cloudProjectsModel.projectSetAutoPushEnabled(cloudProjectsModel.currentProjectId, checked)
}
Expand Down Expand Up @@ -721,4 +729,20 @@ Popup {
cloudProjectsModel.discardLocalChangesFromCurrentProject(cloudProjectsModel.currentProjectId)
cloudProjectsModel.downloadProject(cloudProjectsModel.currentProjectId, true)
}

function applyAutoPushProjectSettings() {
if (cloudProjectsModel.currentProjectId !== '') {
const forceAutoPush = iface.readProjectBoolEntry("qfieldsync", "forceAutoPush", false)
if (forceAutoPush) {
autoPush.forceAutoPush = true
autoPush.enabled = false
const forceAutoPushIntervalMins = iface.readProjectNumEntry("qfieldsync", "forceAutoPushIntervalMins", 30)
cloudProjectsModel.projectSetAutoPushEnabled(cloudProjectsModel.currentProjectId, true)
cloudProjectsModel.projectSetAutoPushIntervalMins(cloudProjectsModel.currentProjectId, forceAutoPushIntervalMins)
} else {
autoPush.forceAutoPush = false
autoPush.enabled = true
}
}
}
}
4 changes: 3 additions & 1 deletion src/qml/qgismobileapp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3377,7 +3377,7 @@ ApplicationWindow {

recentProjectListModel.reloadModel()

var cloudProjectId = QFieldCloudUtils.getProjectId(qgisProject.fileName)
const cloudProjectId = QFieldCloudUtils.getProjectId(qgisProject.fileName)
cloudProjectsModel.currentProjectId = cloudProjectId
cloudProjectsModel.refreshProjectModification(cloudProjectId)
if (cloudProjectId !== '') {
Expand Down Expand Up @@ -3411,6 +3411,8 @@ ApplicationWindow {
if (cloudConnection.status === QFieldCloudConnection.LoggedIn) {
cloudProjectsModel.refreshProjectFileOutdatedStatus(cloudProjectId)
}

cloudPopup.applyAutoPushProjectSettings();
} else {
projectInfo.hasInsertRights = true
projectInfo.hasEditRights = true
Expand Down

0 comments on commit a5f1e82

Please sign in to comment.