File indexing completed on 2024-05-12 15:54:50

0001 // SPDX-FileCopyrightText: 2014  Vishesh Handa <vhanda@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 #ifndef IMAGESTORAGE_H
0005 #define IMAGESTORAGE_H
0006 
0007 #include <QDataStream>
0008 #include <QDateTime>
0009 #include <QGeoAddress>
0010 #include <QGeoLocation>
0011 #include <QObject>
0012 
0013 #include <QMutex>
0014 #include <QMutexLocker>
0015 
0016 #include "koko_export.h"
0017 #include "types.h"
0018 
0019 struct ImageInfo {
0020     QString path;
0021     QGeoLocation location;
0022     QDateTime dateTime;
0023     QStringList tags;
0024     bool favorite;
0025 };
0026 
0027 class KOKO_EXPORT ImageStorage : public QObject
0028 {
0029     Q_OBJECT
0030 public:
0031     ImageStorage(QObject *parent = nullptr);
0032     virtual ~ImageStorage();
0033 
0034     Q_INVOKABLE void addImage(const ImageInfo &ii);
0035     void removeImage(const QString &filePath);
0036     bool imageExists(const QString &filePath);
0037     void commit();
0038 
0039     static ImageStorage *instance();
0040 
0041     QList<QPair<QByteArray, QString>> locations(Types::LocationGroup loca);
0042     QStringList imagesForLocation(const QByteArray &name, Types::LocationGroup loc);
0043     QString imageForLocation(const QByteArray &name, Types::LocationGroup loc);
0044 
0045     QList<QPair<QByteArray, QString>> timeTypes(Types::TimeGroup group);
0046     QStringList imagesForTime(const QByteArray &name, Types::TimeGroup group);
0047     QString imageForTime(const QByteArray &name, Types::TimeGroup group);
0048 
0049     QStringList imagesForFavorites();
0050 
0051     QStringList tags();
0052     QStringList imagesForTag(const QString &tag);
0053 
0054     QDate dateForKey(const QByteArray &key, Types::TimeGroup group);
0055 
0056     /**
0057      * Fetch all the images ordered by descending date time.
0058      */
0059     QStringList allImages(int size = -1, int offset = 0);
0060 
0061     static void reset();
0062     static bool shouldReset();
0063 
0064 signals:
0065     void storageModified();
0066 
0067 private:
0068     mutable QMutex m_mutex;
0069 };
0070 
0071 Q_DECLARE_METATYPE(ImageInfo);
0072 
0073 #endif // IMAGESTORAGE_H