From 203dd617eb0c02be7ef28b8150f67701f9ff5884 Mon Sep 17 00:00:00 2001 From: 188080501 <188080501@qq.com> Date: Sat, 1 Apr 2017 12:24:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=AD=E6=96=87=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/ToolsGroup/JpgOptimize/cpp/jpgoptimize.cpp | 8 ++++++++ components/ToolsGroup/JpgOptimize/cpp/jpgoptimize.h | 2 ++ components/ToolsGroup/JpgOptimize/qml/JpgOptimize.qml | 7 +++---- components/ToolsGroup/PngOptimize/cpp/pngoptimize.cpp | 8 ++++++++ components/ToolsGroup/PngOptimize/cpp/pngoptimize.h | 2 ++ components/ToolsGroup/PngOptimize/qml/PngOptimize.qml | 7 +++---- lib/JQLibrary/src/JQZopfli/JQZopfli.cpp | 6 +++--- lib/JQToolsLibrary/include/JQToolsLibrary.h | 2 +- 8 files changed, 30 insertions(+), 12 deletions(-) mode change 100644 => 100755 lib/JQToolsLibrary/include/JQToolsLibrary.h 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;