Skip to content

Commit 3bea34e

Browse files
committed
Filter out cloud projects that are not tied to the current QFieldCloud user from the recent projects list
1 parent f56b263 commit 3bea34e

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/core/recentprojectlistmodel.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void RecentProjectListModel::reloadModel()
4646
mRecentProjects.clear();
4747

4848
QSettings settings;
49+
4950
mRecentProjects = recentProjects( true );
5051

5152
const bool sampleProjectsAdded = settings.value( QStringLiteral( "QField/recentProjectsAdded" ), false ).toBool();
@@ -146,11 +147,14 @@ void RecentProjectListModel::removeRecentProject( const QString &path )
146147
}
147148
}
148149

149-
QList<RecentProjectListModel::RecentProject> RecentProjectListModel::recentProjects( bool skipNonExistent )
150+
QList<RecentProjectListModel::RecentProject> RecentProjectListModel::recentProjects( bool skipNonAvailable )
150151
{
151-
QSettings settings;
152152
QList<RecentProject> projects;
153153

154+
QSettings settings;
155+
const QString qfieldCloudUsername = QSettings().value( QStringLiteral( "/QFieldCloud/username" ) ).toString();
156+
const QString qdieldCloudLocalDirectory = QFieldCloudUtils::localCloudDirectory();
157+
154158
settings.beginGroup( "/qgis/recentProjects" );
155159

156160
const QStringList projectKeysList = settings.childGroups();
@@ -167,9 +171,15 @@ QList<RecentProjectListModel::RecentProject> RecentProjectListModel::recentProje
167171
const QString path = settings.value( QStringLiteral( "path" ) ).toString();
168172
const QFileInfo fi( path );
169173

174+
bool skip = false;
170175
ProjectType type = LocalDataset;
171-
if ( path.startsWith( QFieldCloudUtils::localCloudDirectory() ) )
176+
if ( path.startsWith( qdieldCloudLocalDirectory ) )
172177
{
178+
if ( skipNonAvailable && ( !fi.exists() || !path.startsWith( QStringLiteral( "%1%2%3%2" ).arg( qdieldCloudLocalDirectory, QDir::separator(), qfieldCloudUsername ) ) ) )
179+
{
180+
skip = true;
181+
}
182+
173183
type = CloudProject;
174184
}
175185
else if ( path.startsWith( "http://", Qt::CaseInsensitive ) || path.startsWith( "https://", Qt::CaseInsensitive ) )
@@ -178,14 +188,24 @@ QList<RecentProjectListModel::RecentProject> RecentProjectListModel::recentProje
178188
}
179189
else if ( SUPPORTED_PROJECT_EXTENSIONS.contains( fi.suffix() ) )
180190
{
191+
if ( skipNonAvailable && !fi.exists() )
192+
{
193+
skip = true;
194+
}
195+
181196
type = LocalProject;
182197
}
183198
else
184199
{
200+
if ( skipNonAvailable && !fi.exists() )
201+
{
202+
skip = true;
203+
}
204+
185205
type = LocalDataset;
186206
}
187207

188-
if ( !skipNonExistent || type == LinkProject || fi.exists() )
208+
if ( !skip )
189209
{
190210
projects.append( RecentProject( type,
191211
settings.value( QStringLiteral( "title" ) ).toString(),

src/core/recentprojectlistmodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class RecentProjectListModel : public QAbstractListModel
7676

7777
Q_INVOKABLE static void removeRecentProject( const QString &path );
7878

79-
static QList<RecentProject> recentProjects( bool skipNonExistent = false );
79+
static QList<RecentProject> recentProjects( bool skipNonAvailable = false );
8080

8181
static void saveRecentProjects( const QList<RecentProject> &projects );
8282

src/qml/qgismobileapp.qml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5028,6 +5028,8 @@ ApplicationWindow {
50285028
if (cloudProjectId) {
50295029
projectInfo.cloudUserInformation = userInformation;
50305030
}
5031+
// Reload recent projects to insure only current user projects are visible
5032+
recentProjectListModel.reloadModel();
50315033
}
50325034
previousStatus = cloudConnection.status;
50335035
}

0 commit comments

Comments
 (0)