Skip to content

Commit

Permalink
#1 approach to invalid file setting
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasMizera committed May 28, 2020
1 parent ed34e37 commit 63fba04
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
27 changes: 20 additions & 7 deletions app/localprojectsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <QDir>
#include <QDirIterator>

static QString findQgisProjectFile( const QString &projectDir )
static QString findQgisProjectFile( const QString &projectDir, QString &err )
{
QList<QString> foundProjectFiles;
QDirIterator it( projectDir, QStringList() << QStringLiteral( "*.qgs" ) << QStringLiteral( "*.qgz" ), QDir::Files, QDirIterator::Subdirectories );
Expand All @@ -28,10 +28,17 @@ static QString findQgisProjectFile( const QString &projectDir )
{
return foundProjectFiles.first();
}
else if ( foundProjectFiles.count() > 1 ) // multiple projects
return QString( "ERR_MULTIPLE_PROJECTS" );
else // no projects
return QString( "ERR_NO_PROJECTS" );
else if ( foundProjectFiles.count() > 1 )
{
// error: multiple project files found
err = QString( "ERR_MULTIPLE_PROJECTS" );
}
else
{
// no projects
err = QString( "ERR_NO_PROJECTS" );
}
return QString();
}


Expand All @@ -42,8 +49,11 @@ LocalProjectsManager::LocalProjectsManager( const QString &dataDir )
for ( QString folderName : entryList )
{
LocalProjectInfo info;
QString err;
info.projectDir = mDataDir + "/" + folderName;
info.qgisProjectFilePath = findQgisProjectFile( info.projectDir );
info.qgisProjectFilePath = findQgisProjectFile( info.projectDir, err );
if ( !err.isEmpty() )
info.setprojectFileError( err );

MerginProjectMetadata metadata = MerginProjectMetadata::fromCachedJson( info.projectDir + "/" + MerginApi::sMetadataFile );
if ( metadata.isValid() )
Expand Down Expand Up @@ -112,8 +122,11 @@ void LocalProjectsManager::updateProjectStatus( const QString &projectDir )
void LocalProjectsManager::addMerginProject( const QString &projectDir, const QString &projectNamespace, const QString &projectName )
{
LocalProjectInfo project;
QString err;
project.projectDir = projectDir;
project.qgisProjectFilePath = findQgisProjectFile( projectDir );
project.qgisProjectFilePath = findQgisProjectFile( projectDir, err );
if ( !err.isEmpty() )
project.setprojectFileError( err );
project.projectNamespace = projectNamespace;
project.projectName = projectName;
// version info and status should be updated afterwards
Expand Down
7 changes: 7 additions & 0 deletions app/localprojectsmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ struct LocalProjectInfo
{
bool isValid() const { return !projectDir.isEmpty(); }

void setprojectFileError( const QString error ) { projectError = error; }

bool isShowable() const { return projectError.isEmpty(); }

QString projectDir; //!< full path to the project directory

QString qgisProjectFilePath; //!< path to the .qgs/.qgz file (or empty if not have exactly one such file)

QString projectError; //!< If project is invalid, projectError carry more information why
// TODO: reset when project is synchronized

//
// mergin-specific project info (may be empty)
//
Expand Down
2 changes: 1 addition & 1 deletion app/positiondirection.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


/**
* Utility class containing infortmation about the direction. Note that depends on availibility of sensors and their data.
* Utility class containing information about the direction. Note that depends on availibility of sensors and their data.
*
* Updates direction periodicly according timer while filtering small difference values between old and new direction angle.
* Uses ground speed (in m/s) to select which direction source will be used - compass for smaller speed whereas positionKit direction
Expand Down
12 changes: 6 additions & 6 deletions app/projectsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ void ProjectModel::findProjectFiles()
projectFile.folderName = dir.dirName();
projectFile.projectName = project.projectName;
projectFile.projectNamespace = project.projectNamespace;
projectFile.isValid = project.isShowable();
QDateTime created = fi.created().toUTC(); // TODO: why UTC ???
if ( !project.qgisProjectFilePath.startsWith( "ERR" ) )
if ( projectFile.isValid )
{
projectFile.info = QString( created.toString() );
projectFile.isValid = true;
}
else
{
if ( project.qgisProjectFilePath.contains( "ERR_NO_PROJECTS" ) )
if ( project.projectError.contains( "ERR_NO_PROJECTS" ) )
projectFile.info = tr( "Error: Missing QGIS project file" );
else if ( project.qgisProjectFilePath.contains( "ERR_MULTIPLE_PROJECTS" ) )
else if ( project.projectError.contains( "ERR_MULTIPLE_PROJECTS" ) )
projectFile.info = tr( "Error: Multiple QGIS project files" );

projectFile.isValid = false;
else
projectFile.info = tr("Invalid project");
}
mProjectFiles << projectFile;
}
Expand Down

3 comments on commit 63fba04

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

ios-1.4.200528110733 (SDK: ios-4)

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

signed apk: arm64-v8a (SDK: android-13)

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

signed apk: armeabi-v7a (SDK: android-13)

Please sign in to comment.