7070
7171static const QString DATE_TIME_FORMAT = QStringLiteral( " yyMMdd-hhmmss" );
7272static 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
7479InputUtils::InputUtils ( QObject *parent )
7580 : QObject( parent )
@@ -91,17 +96,10 @@ bool InputUtils::removeFile( const QString &filePath )
9196bool InputUtils::copyFile ( const QString &srcPath, const QString &dstPath )
9297{
9398 QString modSrcPath = srcPath;
94- #ifdef Q_OS_WIN32
95- if ( srcPath.startsWith ( " file:///" ) )
99+ if ( srcPath.startsWith ( FILE_PATH_PREFIX ) )
96100 {
97- modSrcPath = modSrcPath.replace ( " file:/// " , " " );
101+ modSrcPath = modSrcPath.replace ( FILE_PATH_PREFIX , " " );
98102 }
99- #else
100- if ( srcPath.startsWith ( " file://" ) )
101- {
102- modSrcPath = modSrcPath.replace ( " file://" , " " );
103- }
104- #endif
105103
106104 QFileInfo fi ( dstPath );
107105 if ( !InputUtils::createDirectory ( fi.absoluteDir ().path () ) )
@@ -1051,15 +1049,10 @@ QString InputUtils::resolvePath( const QString &path, const QString &homePath, c
10511049QString InputUtils::getRelativePath ( const QString &path, const QString &prefixPath )
10521050{
10531051 QString modPath = path;
1054- #ifdef Q_OS_WIN32
1055- QString filePrefix ( " file:///" );
1056- #else
1057- QString filePrefix ( " file://" );
1058- #endif
10591052
1060- if ( path.startsWith ( filePrefix ) )
1053+ if ( path.startsWith ( FILE_PATH_PREFIX ) )
10611054 {
1062- modPath = modPath.replace ( filePrefix , QString () );
1055+ modPath = modPath.replace ( FILE_PATH_PREFIX , QString () );
10631056 }
10641057
10651058 if ( prefixPath.isEmpty () ) return modPath;
@@ -1994,11 +1987,7 @@ void InputUtils::sanitizeFileName( QString &fileName )
19941987
19951988void InputUtils::sanitizePath ( QString &path )
19961989{
1997- #ifdef Q_OS_WIN32
1998- const bool pathStartsWithFileURL = path.startsWith ( " file:///" );
1999- #else
2000- const bool pathStartsWithFileURL = path.startsWith ( " file://" );
2001- #endif
1990+ const bool pathStartsWithFileURL = path.startsWith ( FILE_PATH_PREFIX );
20021991
20031992 if ( pathStartsWithFileURL )
20041993 {
@@ -2032,13 +2021,8 @@ void InputUtils::sanitizePath( QString &path )
20322021
20332022 if ( pathStartsWithFileURL )
20342023 {
2035- #ifdef Q_OS_WIN32
2036- // restore file:/// prefix for windows
2037- sanitizedPath = " file:///" + sanitizedPath;
2038- #else
20392024 // restore file:// prefix
2040- sanitizedPath = " file://" + sanitizedPath;
2041- #endif
2025+ sanitizedPath = FILE_PATH_PREFIX + sanitizedPath;
20422026 }
20432027 path = sanitizedPath;
20442028}
0 commit comments