File indexing completed on 2025-01-05 03:59:46

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2011-08-03
0007  * Description : digital camera thumbnails controller
0008  *
0009  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_CAMERA_THUMBS_CTRL_H
0016 #define DIGIKAM_CAMERA_THUMBS_CTRL_H
0017 
0018 // Qt includes
0019 
0020 #include <QWidget>
0021 #include <QString>
0022 #include <QImage>
0023 #include <QPixmap>
0024 #include <QUrl>
0025 
0026 // Local includes
0027 
0028 #include "camiteminfo.h"
0029 #include "digikam_export.h"
0030 
0031 namespace Digikam
0032 {
0033 
0034 class CameraController;
0035 
0036 typedef QPair<CamItemInfo, QPixmap> CachedItem;
0037 
0038 class DIGIKAM_GUI_EXPORT CameraThumbsCtrl : public QObject
0039 {
0040     Q_OBJECT
0041 
0042 public:
0043 
0044     explicit CameraThumbsCtrl(CameraController* const ctrl, QWidget* const parent);
0045     ~CameraThumbsCtrl()                                                override;
0046 
0047     /**
0048      * Fill item with relevant information.
0049      * if item is not in cache, return false and information will be dispatched later through signalThumbInfoReady(),
0050      * else return true and information is available immediately.
0051      */
0052     bool getThumbInfo(const CamItemInfo& info, CachedItem& item) const;
0053 
0054     void setCacheSize(int numberOfItems);
0055     void clearCache();
0056 
0057     /**
0058      * Force controller to update info from device in cache.
0059      */
0060     void updateThumbInfoFromCache(const CamItemInfo& info);
0061 
0062     /**
0063      * Return camera controller instance.
0064      */
0065     CameraController* cameraController()                         const;
0066 
0067 Q_SIGNALS:
0068 
0069     void signalThumbInfoReady(const CamItemInfo&);
0070 
0071 private Q_SLOTS:
0072 
0073     void slotThumbInfo(const QString&, const QString&, const CamItemInfo&, const QImage&);
0074     void slotThumbInfoFailed(const QString&, const QString&, const CamItemInfo&);
0075 
0076 private:
0077 
0078     /// Cache management methods.
0079     void removeItemFromCache(const QUrl& url);
0080     void putItemToCache(const QUrl& url, const CamItemInfo&, const QPixmap& thumb);
0081     bool hasItemFromCache(const QUrl& url)                       const;
0082     const CachedItem* retrieveItemFromCache(const QUrl& url)     const;
0083 
0084 private:
0085 
0086     class Private;
0087     const QScopedPointer<Private> d;
0088 };
0089 
0090 } // namespace Digikam
0091 
0092 #endif // DIGIKAM_CAMERA_THUMBS_CTRL_H