Commit 081efe6e authored by Tom Moebert's avatar Tom Moebert Committed by Nate Graham
Browse files

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
parent a51ff704
......@@ -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.&lt;br/&gt;&lt;br/&gt;&lt;em&gt;Be careful:&lt;/em&gt; this will delete the folder named &lt;filename&gt;.thumbnails&lt;/filename&gt; 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.&lt;br/&gt;&lt;br/&gt;&lt;em&gt;Be careful:&lt;/em&gt; this will delete the folder named &lt;filename&gt;.thumbnails&lt;/filename&gt; in your home folder, deleting all thumbnails previously generated by Gwenview and other applications.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
......
......@@ -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>
......
......@@ -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();
......
......@@ -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()));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment