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

0001 /*
0002  * SPDX-FileCopyrightText: (C) 2021 Mikel Johnson <mikel5764@gmail.com>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include "imagetagsmodel.h"
0008 #include "imagestorage.h"
0009 #include "roles.h"
0010 
0011 #include <kio/copyjob.h>
0012 #include <kio/jobuidelegate.h>
0013 
0014 ImageTagsModel::ImageTagsModel(QObject *parent)
0015     : OpenFileModel({}, parent)
0016     , m_tag(QString())
0017 {
0018     connect(ImageStorage::instance(), &ImageStorage::storageModified, this, &ImageTagsModel::slotPopulate);
0019     populateTags();
0020 }
0021 
0022 QString ImageTagsModel::tag() const
0023 {
0024     return m_tag;
0025 }
0026 
0027 QStringList ImageTagsModel::tags() const
0028 {
0029     return m_tags;
0030 }
0031 
0032 void ImageTagsModel::setTag(const QString &tag)
0033 {
0034     if (m_tag == tag) {
0035         return;
0036     }
0037 
0038     m_tag = tag;
0039 
0040     emit tagChanged();
0041 
0042     slotPopulate();
0043 }
0044 
0045 void ImageTagsModel::slotPopulate()
0046 {
0047     populateTags();
0048 
0049     if (m_tag == "") {
0050         return;
0051     }
0052 
0053     beginResetModel();
0054     m_images = ImageStorage::instance()->imagesForTag(m_tag);
0055     endResetModel();
0056 }
0057 
0058 void ImageTagsModel::populateTags()
0059 {
0060     const QStringList tags = ImageStorage::instance()->tags();
0061     if (m_tags == tags) {
0062         return;
0063     }
0064 
0065     m_tags = tags;
0066     emit tagsChanged();
0067 }