[gwenview] /: Optionally use images' embedded thumbnails for greater performance, even if they're too small
Nate Graham
null at kde.org
Fri May 24 17:36:53 BST 2019
Git commit 081efe6e15471fc19d3c72c6f8a4cc3a1b8c312a by Nate Graham, on behalf of Tom Moebert.
Committed on 24/05/2019 at 16:36.
Pushed by ngraham into branch 'master'.
Optionally use images' embedded thumbnails for greater performance, even if they're too small
Summary: Only generate high resolution thumbs if the user cares to not throw them away when closing gwenview, that is when deleteThumbnailCacheOnExit() is set to false. If set to true, prefer speed over quality: always use the embedded thumbnail regardless of its size.
Reviewers: #gwenview, ngraham
Reviewed By: #gwenview, ngraham
Subscribers: yurchor, kde-doc-english, ngraham, #gwenview
Tags: #gwenview, #documentation
Differential Revision: https://phabricator.kde.org/D21330
M +2 -2 app/advancedconfigpage.ui
M +1 -1 doc/index.docbook
M +5 -1 lib/thumbnailprovider/thumbnailgenerator.cpp
M +8 -2 tests/auto/thumbnailprovidertest.cpp
https://commits.kde.org/gwenview/081efe6e15471fc19d3c72c6f8a4cc3a1b8c312a
diff --git a/app/advancedconfigpage.ui b/app/advancedconfigpage.ui
index 096cef08..e6eb2515 100644
--- a/app/advancedconfigpage.ui
+++ b/app/advancedconfigpage.ui
@@ -26,7 +26,7 @@
<item>
<widget class="QCheckBox" name="kcfg_DeleteThumbnailCacheOnExit">
<property name="text">
- <string>Delete thumbnail cache folder on exit</string>
+ <string>Low resource usage mode</string>
</property>
</widget>
</item>
@@ -48,7 +48,7 @@
<item row="1" column="1">
<widget class="QLabel" name="cacheHelpLabel">
<property name="text">
- <string>Enable this option if you do not have a lot of disk space.<br/><br/><em>Be careful:</em> this will delete the folder named <filename>.thumbnails</filename> in your home folder, deleting all thumbnails previously generated by Gwenview and other applications.</string>
+ <string>Enable this option if you do not have a lot of disk space. This will avoid storing thumbnails on disk and will prefer embedded thumbnails of lower quality that are faster to load, if available.<br/><br/><em>Be careful:</em> this will delete the folder named <filename>.thumbnails</filename> in your home folder, deleting all thumbnails previously generated by Gwenview and other applications.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
diff --git a/doc/index.docbook b/doc/index.docbook
index ca7cde00..dc6d3bd3 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -846,7 +846,7 @@ Link an image.</para></listitem>
<varlistentry>
<term><guilabel>Cache</guilabel></term>
<listitem>
- <para>Enable the <guilabel>Delete thumbnail cache folder on exit</guilabel> option if you do not have a lot of disk space.</para>
+ <para>Enable the <guilabel>Low resource usage mode</guilabel> option if you do not have a lot of disk space. This will avoid storing thumbnails on disk and will prefer embedded thumbnails of lower quality that are faster to load, if available.</para>
<para>Be careful: This will delete the folder named <filename>.thumbnails</filename> in your home folder, deleting all thumbnails previously generated by &gwenview; and other applications.</para>
</listitem>
</varlistentry>
diff --git a/lib/thumbnailprovider/thumbnailgenerator.cpp b/lib/thumbnailprovider/thumbnailgenerator.cpp
index 26402cf2..de2061d1 100644
--- a/lib/thumbnailprovider/thumbnailgenerator.cpp
+++ b/lib/thumbnailprovider/thumbnailgenerator.cpp
@@ -116,7 +116,11 @@ bool ThumbnailContext::load(const QString &pixPath, int pixelSize)
if (!content.rawData().isEmpty()) {
QImage thumbnail = content.thumbnail();
- if (qMax(thumbnail.width(), thumbnail.height()) >= pixelSize) {
+ // If the user does not care about the generated thumbnails (by deleting them on exit), use ANY
+ // embedded thumnail, even if it's too small.
+ if (!thumbnail.isNull() &&
+ (GwenviewConfig::deleteThumbnailCacheOnExit() || qMax(thumbnail.width(), thumbnail.height()) >= pixelSize)
+ ) {
mImage = std::move(thumbnail);
mOriginalWidth = content.size().width();
mOriginalHeight = content.size().height();
diff --git a/tests/auto/thumbnailprovidertest.cpp b/tests/auto/thumbnailprovidertest.cpp
index 958165eb..cb895c54 100644
--- a/tests/auto/thumbnailprovidertest.cpp
+++ b/tests/auto/thumbnailprovidertest.cpp
@@ -34,6 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Local
#include "../lib/thumbnailprovider/thumbnailprovider.h"
#include "testutils.h"
+#include "gwenviewconfig.h"
// libc
#include <errno.h>
@@ -212,7 +213,8 @@ void ThumbnailProviderTest::testUseEmbeddedOrNot()
QVERIFY(TestUtils::imageCompare(expectedThumbnail, thumbnailPix.toImage()));
}
- // Loading a large thumbnail should bring the red one
+ // Loading a large thumbnail should bring the red one, unless thumbnails are deleted on exit,
+ // which should bring the white one
{
ThumbnailProvider provider;
provider.setThumbnailGroup(ThumbnailGroup::Large);
@@ -221,7 +223,11 @@ void ThumbnailProviderTest::testUseEmbeddedOrNot()
syncRun(&provider);
QCOMPARE(spy.count(), 1);
- expectedThumbnail = createColoredImage(256, 128, QColor(254, 0, 0));
+ if (GwenviewConfig::deleteThumbnailCacheOnExit()) {
+ expectedThumbnail = createColoredImage(128, 64, Qt::white);
+ } else {
+ expectedThumbnail = createColoredImage(256, 128, QColor(254, 0, 0));
+ }
thumbnailPix = qvariant_cast<QPixmap>(spy.at(0).at(1));
QVERIFY(TestUtils::imageCompare(expectedThumbnail, thumbnailPix.toImage()));
}
More information about the kde-doc-english
mailing list