git repos / SagoImageBrowser

blame: src/thumbnailcache.h

normal view · raw

14cf904f Poul Sander 2026-06-22 18:18 1
/*
14cf904f Poul Sander 2026-06-22 18:18 2
MIT License
14cf904f Poul Sander 2026-06-22 18:18 3
14cf904f Poul Sander 2026-06-22 18:18 4
Copyright (c) 2026 Poul Sander
14cf904f Poul Sander 2026-06-22 18:18 5
14cf904f Poul Sander 2026-06-22 18:18 6
Permission is hereby granted, free of charge, to any person obtaining a copy
14cf904f Poul Sander 2026-06-22 18:18 7
of this software and associated documentation files (the "Software"), to deal
14cf904f Poul Sander 2026-06-22 18:18 8
in the Software without restriction, including without limitation the rights
14cf904f Poul Sander 2026-06-22 18:18 9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14cf904f Poul Sander 2026-06-22 18:18 10
copies of the Software, and to permit persons to whom the Software is
14cf904f Poul Sander 2026-06-22 18:18 11
furnished to do so, subject to the following conditions:
14cf904f Poul Sander 2026-06-22 18:18 12
14cf904f Poul Sander 2026-06-22 18:18 13
The above copyright notice and this permission notice shall be included in all
14cf904f Poul Sander 2026-06-22 18:18 14
copies or substantial portions of the Software.
14cf904f Poul Sander 2026-06-22 18:18 15
14cf904f Poul Sander 2026-06-22 18:18 16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14cf904f Poul Sander 2026-06-22 18:18 17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14cf904f Poul Sander 2026-06-22 18:18 18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14cf904f Poul Sander 2026-06-22 18:18 19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14cf904f Poul Sander 2026-06-22 18:18 20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
14cf904f Poul Sander 2026-06-22 18:18 21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
14cf904f Poul Sander 2026-06-22 18:18 22
SOFTWARE.
14cf904f Poul Sander 2026-06-22 18:18 23
14cf904f Poul Sander 2026-06-22 18:18 24
*/
14cf904f Poul Sander 2026-06-22 18:18 25
ac476ca8 Poul Sander 2026-05-18 16:47 26
#pragma once
ac476ca8 Poul Sander 2026-05-18 16:47 27
80a9926d Poul Sander 2026-05-19 20:28 28
#include <QByteArray>
ac476ca8 Poul Sander 2026-05-18 16:47 29
#include <QString>
ac476ca8 Poul Sander 2026-05-18 16:47 30
#include <QImage>
ac476ca8 Poul Sander 2026-05-18 16:47 31
ac476ca8 Poul Sander 2026-05-18 16:47 32
class ThumbnailCache
ac476ca8 Poul Sander 2026-05-18 16:47 33
{
ac476ca8 Poul Sander 2026-05-18 16:47 34
public:
ac476ca8 Poul Sander 2026-05-18 16:47 35
    enum class Size
ac476ca8 Poul Sander 2026-05-18 16:47 36
    {
ac476ca8 Poul Sander 2026-05-18 16:47 37
        Normal = 128,
ac476ca8 Poul Sander 2026-05-18 16:47 38
        Large = 256,
ac476ca8 Poul Sander 2026-05-18 16:47 39
    };
ac476ca8 Poul Sander 2026-05-18 16:47 40
ac476ca8 Poul Sander 2026-05-18 16:47 41
    // Returns a non-null QImage if a valid cached thumbnail exists for sourcePath
80a9926d Poul Sander 2026-05-19 20:28 42
    // at the requested size. sourcePath must be the raw native OS byte string.
80a9926d Poul Sander 2026-05-19 20:28 43
    static QImage load(const QByteArray &sourcePath, Size size);
ac476ca8 Poul Sander 2026-05-18 16:47 44
ac476ca8 Poul Sander 2026-05-18 16:47 45
    // Atomically writes thumbImage to the cache with the required Freedesktop
80a9926d Poul Sander 2026-05-19 20:28 46
    // tEXt chunks. sourcePath must be the raw native OS byte string.
80a9926d Poul Sander 2026-05-19 20:28 47
    static void save(const QByteArray &sourcePath, Size size, const QImage &thumbImage);
ac476ca8 Poul Sander 2026-05-18 16:47 48
ac476ca8 Poul Sander 2026-05-18 16:47 49
    static QString cacheRoot();
ac476ca8 Poul Sander 2026-05-18 16:47 50
    static QString subdirFor(Size size);
80a9926d Poul Sander 2026-05-19 20:28 51
    // Canonical file:// URI built from raw byte path (correct percent-encoding)
80a9926d Poul Sander 2026-05-19 20:28 52
    static QByteArray canonicalUri(const QByteArray &absPath);
80a9926d Poul Sander 2026-05-19 20:28 53
    static QString hashedName(const QByteArray &canonicalUri);
80a9926d Poul Sander 2026-05-19 20:28 54
    static bool isInsideCache(const QByteArray &absPath);
ac476ca8 Poul Sander 2026-05-18 16:47 55
};
1970-01-01 00:00 56