Skip to content

Commit f2de1d0

Browse files
Modified the file prefix for windows
1 parent fed97d3 commit f2de1d0

File tree

7 files changed

+38
-15
lines changed

7 files changed

+38
-15
lines changed

app/inpututils.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070

7171
static const QString DATE_TIME_FORMAT = QStringLiteral( "yyMMdd-hhmmss" );
7272
static const QString INVALID_DATETIME_STR = QStringLiteral( "Invalid datetime" );
73+
#ifdef Q_OS_WIN32
74+
static const QString FILE_PATH_PREFIX = QStringLiteral( "file:///" );
75+
#else
76+
static const QString FILE_PATH_PREFIX = QStringLiteral( "file://" );
77+
#endif
7378

7479
InputUtils::InputUtils( QObject *parent )
7580
: QObject( parent )
@@ -91,9 +96,9 @@ bool InputUtils::removeFile( const QString &filePath )
9196
bool InputUtils::copyFile( const QString &srcPath, const QString &dstPath )
9297
{
9398
QString modSrcPath = srcPath;
94-
if ( srcPath.startsWith( "file://" ) )
99+
if ( srcPath.startsWith( FILE_PATH_PREFIX ) )
95100
{
96-
modSrcPath = modSrcPath.replace( "file://", "" );
101+
modSrcPath = modSrcPath.replace( FILE_PATH_PREFIX, "" );
97102
}
98103

99104
QFileInfo fi( dstPath );
@@ -1044,11 +1049,10 @@ QString InputUtils::resolvePath( const QString &path, const QString &homePath, c
10441049
QString InputUtils::getRelativePath( const QString &path, const QString &prefixPath )
10451050
{
10461051
QString modPath = path;
1047-
QString filePrefix( "file://" );
10481052

1049-
if ( path.startsWith( filePrefix ) )
1053+
if ( path.startsWith( FILE_PATH_PREFIX ) )
10501054
{
1051-
modPath = modPath.replace( filePrefix, QString() );
1055+
modPath = modPath.replace( FILE_PATH_PREFIX, QString() );
10521056
}
10531057

10541058
if ( prefixPath.isEmpty() ) return modPath;
@@ -1983,7 +1987,7 @@ void InputUtils::sanitizeFileName( QString &fileName )
19831987

19841988
void InputUtils::sanitizePath( QString &path )
19851989
{
1986-
const bool pathStartsWithFileURL = path.startsWith( "file://" );
1990+
const bool pathStartsWithFileURL = path.startsWith( FILE_PATH_PREFIX );
19871991

19881992
if ( pathStartsWithFileURL )
19891993
{
@@ -2018,9 +2022,8 @@ void InputUtils::sanitizePath( QString &path )
20182022
if ( pathStartsWithFileURL )
20192023
{
20202024
// restore file:// prefix
2021-
sanitizedPath = "file://" + sanitizedPath;
2025+
sanitizedPath = FILE_PATH_PREFIX + sanitizedPath;
20222026
}
2023-
20242027
path = sanitizedPath;
20252028
}
20262029

app/inpututils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ class InputUtils: public QObject
367367

368368
/**
369369
* Returns relative path of the file to given prefixPath. If prefixPath does not match a path parameter,
370-
* returns an empty string. If a path starts with "file://", this prefix is ignored.
370+
* returns an empty string. If a path starts with "file://" or "file:///" (only on Windows), this prefix is ignored.
371371
* \param path Absolute path to file
372372
* \param prefixPath
373373
*/

app/qml/form/editors/MMFormGalleryEditor.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ MMPrivateComponents.MMBaseInput {
5757
let absolutePath = model.PhotoPath
5858

5959
if ( absolutePath !== '' && __inputUtils.fileExists( absolutePath ) ) {
60-
return "file://" + absolutePath
60+
return Qt.os.platform === "windows" ? "file:///" + absolutePath : "file://" + absolutePath
6161
}
6262
return ''
6363
}

app/qml/form/editors/MMFormPhotoEditor.qml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ MMFormPhotoViewer {
173173
target: root.sketchingController
174174

175175
function onTempPhotoSourceChanged( newPath ){
176-
if ( internal.tempSketchedImageSource === "file://" + newPath ) {
176+
if ( internal.tempSketchedImageSource === getPhotoUrlPrefix() + newPath ) {
177177
internal.tempSketchedImageSource = ""
178178
}
179-
internal.tempSketchedImageSource = "file://" + newPath
179+
internal.tempSketchedImageSource = getPhotoUrlPrefix() + newPath
180180
}
181181

182182
function onSketchesSavingError(){
@@ -269,7 +269,7 @@ MMFormPhotoViewer {
269269

270270
if ( __inputUtils.fileExists( absolutePath ) ) {
271271
root.photoState = "valid"
272-
resolvedImageSource = "file://" + absolutePath
272+
resolvedImageSource = getPhotoUrlPrefix() + absolutePath
273273
tempSketchedImageSource = ""
274274
}
275275
else if ( __inputUtils.isValidUrl( absolutePath ) ) {
@@ -402,5 +402,11 @@ MMFormPhotoViewer {
402402
}
403403
}
404404
}
405+
406+
// Function that returns the photo URL path prefix, based on the platform
407+
function getPhotoUrlPrefix()
408+
{
409+
return Qt.platform.os === "windows" ? "file:///" : "file://"
410+
}
405411
}
406412
}

app/qml/form/editors/MMFormPhotoViewer.qml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ MMPrivateComponents.MMBaseInput {
7575
visible: photoStateGroup.state !== "notSet"
7676

7777
photoUrl: root.photoUrl
78-
isLocalFile: root.photoUrl.startsWith( "file://" )
78+
isLocalFile: isPhotoUrlStartingWithPrefix()
7979
cache: false
8080

8181
fillMode: Image.PreserveAspectCrop
@@ -125,7 +125,7 @@ MMPrivateComponents.MMBaseInput {
125125
iconSource: __style.drawIcon
126126
iconColor: __style.forestColor
127127

128-
visible: root.editState === "enabled" && photoStateGroup.state !== "notSet" && __activeProject.photoSketchingEnabled && root.photoUrl.startsWith("file://")
128+
visible: root.editState === "enabled" && photoStateGroup.state !== "notSet" && __activeProject.photoSketchingEnabled && isPhotoUrlStartingWithPrefix()
129129

130130
onClicked: {
131131
sketchingLoader.active = true
@@ -185,4 +185,10 @@ MMPrivateComponents.MMBaseInput {
185185
}
186186
}
187187
}
188+
189+
// Function that returns boolean value if the photo URL path starts with a prefix, based on the platform
190+
function isPhotoUrlStartingWithPrefix(){
191+
let filePrefix = Qt.platform.os === "windows" ? "file:///" : "file://"
192+
return root.photoUrl.startsWith( filePrefix )
193+
}
188194
}

app/test/testsketching.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ void TestSketching::testLoadBackupSketch()
169169
sketchingController.mPhotoSource = path;
170170
sketchingController.mProjectName = QStringLiteral( "/this/is/long/path/to/image/test_sketching" );
171171
sketchingController.prepareController();
172+
#ifdef Q_OS_WIN32
173+
QCOMPARE( sketchingController.mPhotoSource, "file:///" + QDir::tempPath() + QStringLiteral( "/test_sketching" ) + QStringLiteral( "/MM_test_image.jpg" ) );
174+
#else
172175
QCOMPARE( sketchingController.mPhotoSource, "file://" + QDir::tempPath() + QStringLiteral( "/test_sketching" ) + QStringLiteral( "/MM_test_image.jpg" ) );
176+
#endif
173177
QCOMPARE( sketchingController.mOriginalPhotoSource, QUrl( path ).toLocalFile() );
174178
QCOMPARE( spy.count(), 1 );
175179
auto signalArgs = spy.takeLast();

app/test/testutilsfunctions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,11 @@ void TestUtilsFunctions::getRelativePath()
274274
QString relativePath2 = mUtils->getRelativePath( path2, prefixPath );
275275
QCOMPARE( fileName2, relativePath2 );
276276

277+
#ifdef Q_OS_WIN32
278+
QString path3 = QStringLiteral( "file:///" ) + path2;
279+
#else
277280
QString path3 = QStringLiteral( "file://" ) + path2;
281+
#endif
278282
QString relativePath3 = mUtils->getRelativePath( path3, prefixPath );
279283
QCOMPARE( fileName2, relativePath3 );
280284

0 commit comments

Comments
 (0)