diff --git a/components/ToolsGroup/JpgOptimize/cpp/jpgoptimize.cpp b/components/ToolsGroup/JpgOptimize/cpp/jpgoptimize.cpp index 966e73a..3225aec 100755 --- a/components/ToolsGroup/JpgOptimize/cpp/jpgoptimize.cpp +++ b/components/ToolsGroup/JpgOptimize/cpp/jpgoptimize.cpp @@ -92,6 +92,14 @@ void Manage::startOptimize(const QString ¤tFilePath) waitOptimizeQueue_.remove( currentFilePath ); } +QString Manage::urlToLocalPngOrJpgFilePath(const QVariant &url) +{ + QFileInfo fileInfo( url.toUrl().toLocalFile() ); + if ( !fileInfo.isFile() ) { return { }; } + if ( !fileInfo.filePath().toLower().endsWith( ".png" ) && !fileInfo.filePath().toLower().endsWith( ".jpg" ) ) { return { }; } + return fileInfo.filePath(); +} + QString Manage::optimizeJpg(const bool &coverOldFile, const QStringList &filePaths) { QString targetDir; diff --git a/components/ToolsGroup/JpgOptimize/cpp/jpgoptimize.h b/components/ToolsGroup/JpgOptimize/cpp/jpgoptimize.h index d683677..5bd9557 100755 --- a/components/ToolsGroup/JpgOptimize/cpp/jpgoptimize.h +++ b/components/ToolsGroup/JpgOptimize/cpp/jpgoptimize.h @@ -51,6 +51,8 @@ public slots: void startOptimize(const QString ¤tFilePath); + QString urlToLocalPngOrJpgFilePath(const QVariant &url); + private: QString optimizeJpg(const bool &coverOldFile, const QStringList &filePaths); diff --git a/components/ToolsGroup/JpgOptimize/qml/JpgOptimize.qml b/components/ToolsGroup/JpgOptimize/qml/JpgOptimize.qml index 15e12f5..6ae88d7 100755 --- a/components/ToolsGroup/JpgOptimize/qml/JpgOptimize.qml +++ b/components/ToolsGroup/JpgOptimize/qml/JpgOptimize.qml @@ -295,12 +295,11 @@ Item { for( var index = 0; index < drop.urls.length; ++index ) { - var url = drop.urls[ index ].toString(); + var pngOrJpgFilePath = jpgOptimizeManage.urlToLocalPngOrJpgFilePath( drop.urls[ index ] ); - if ( url.indexOf( "file://" ) !== 0 ) { return; } - if ( url.toLowerCase().lastIndexOf( ".jpg" ) !== ( url.length - 4 ) ) { return; } + if ( pngOrJpgFilePath.length === 0 ) { continue; } - filePaths.push( url.substr( 7 ) ); + filePaths.push( pngOrJpgFilePath); } if ( filePaths.length === 0 ) { return; } diff --git a/components/ToolsGroup/PngOptimize/cpp/pngoptimize.cpp b/components/ToolsGroup/PngOptimize/cpp/pngoptimize.cpp index dcecf24..f1b978e 100755 --- a/components/ToolsGroup/PngOptimize/cpp/pngoptimize.cpp +++ b/components/ToolsGroup/PngOptimize/cpp/pngoptimize.cpp @@ -92,6 +92,14 @@ void Manage::startOptimize(const QString ¤tFilePath) waitOptimizeQueue_.remove( currentFilePath ); } +QString Manage::urlToLocalPngFilePath(const QVariant &url) +{ + QFileInfo fileInfo( url.toUrl().toLocalFile() ); + if ( !fileInfo.isFile() ) { return { }; } + if ( !fileInfo.filePath().toLower().endsWith( ".png" ) ) { return { }; } + return fileInfo.filePath(); +} + QString Manage::optimizePng(const bool &coverOldFile, const QStringList &filePaths) { QString targetDir; diff --git a/components/ToolsGroup/PngOptimize/cpp/pngoptimize.h b/components/ToolsGroup/PngOptimize/cpp/pngoptimize.h index 5ad44b6..8987c37 100755 --- a/components/ToolsGroup/PngOptimize/cpp/pngoptimize.h +++ b/components/ToolsGroup/PngOptimize/cpp/pngoptimize.h @@ -51,6 +51,8 @@ public slots: void startOptimize(const QString ¤tFilePath); + QString urlToLocalPngFilePath(const QVariant &url); + private: QString optimizePng(const bool &coverOldFile, const QStringList &filePaths); diff --git a/components/ToolsGroup/PngOptimize/qml/PngOptimize.qml b/components/ToolsGroup/PngOptimize/qml/PngOptimize.qml index 02aec5b..de22c40 100755 --- a/components/ToolsGroup/PngOptimize/qml/PngOptimize.qml +++ b/components/ToolsGroup/PngOptimize/qml/PngOptimize.qml @@ -295,12 +295,11 @@ Item { for( var index = 0; index < drop.urls.length; ++index ) { - var url = drop.urls[ index ].toString(); + var pngFilePath = pngOptimizeManage.urlToLocalPngFilePath( drop.urls[ index ] ); - if ( url.indexOf( "file://" ) !== 0 ) { return; } - if ( url.toLowerCase().lastIndexOf( ".png" ) !== ( url.length - 4 ) ) { return; } + if ( pngFilePath.length === 0 ) { continue; } - filePaths.push( url.substr( 7 ) ); + filePaths.push( pngFilePath); } if ( filePaths.length === 0 ) { return; } diff --git a/lib/JQLibrary/src/JQZopfli/JQZopfli.cpp b/lib/JQLibrary/src/JQZopfli/JQZopfli.cpp index aa04ac3..b56621d 100755 --- a/lib/JQLibrary/src/JQZopfli/JQZopfli.cpp +++ b/lib/JQLibrary/src/JQZopfli/JQZopfli.cpp @@ -533,7 +533,7 @@ OptimizeResult JQZopfli::optimize(const QString &originalFilePath, const QString std::vector< unsigned char > originalPng; std::vector< unsigned char > resultPng; - if ( lodepng::load_file( originalPng, originalFilePath.toUtf8().data() ) ) + if ( lodepng::load_file( originalPng, originalFilePath.toLocal8Bit().data() ) ) { qDebug() << "JQZopfli::optimize: error2"; return result; @@ -541,9 +541,9 @@ OptimizeResult JQZopfli::optimize(const QString &originalFilePath, const QString result.originalSize = originalPng.size(); - ZopfliPNGOptions png_options; + ZopfliPNGOptions pngOptions; - if ( ZopfliPNGOptimize( originalPng, png_options, png_options.verbose, &resultPng ) ) + if ( ZopfliPNGOptimize( originalPng, pngOptions, pngOptions.verbose, &resultPng ) ) { qDebug() << "JQZopfli::optimize: error3"; return result; diff --git a/lib/JQToolsLibrary/include/JQToolsLibrary.h b/lib/JQToolsLibrary/include/JQToolsLibrary.h old mode 100644 new mode 100755 index d072941..8ffff50 --- a/lib/JQToolsLibrary/include/JQToolsLibrary.h +++ b/lib/JQToolsLibrary/include/JQToolsLibrary.h @@ -17,7 +17,7 @@ #include #include -#define JQTOOLS_VERSIONSTRING "17.3.26" +#define JQTOOLS_VERSIONSTRING "17.4.1" class QQmlApplicationEngine;