Warning, file /maui/mauikit-filebrowsing/src/code/tagslist.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #include "tagslist.h" 0002 #include "tagging.h" 0003 0004 TagsList::TagsList(QObject *parent) 0005 : MauiList(parent) {} 0006 0007 void TagsList::setList() 0008 { 0009 Q_EMIT this->preListChanged(); 0010 0011 if (this->m_urls.isEmpty()) { 0012 this->list = FMH::toModelList(Tagging::getInstance()->getAllTags(this->strict)); 0013 0014 } else if(this->m_urls.size() > 1) { 0015 this->list.clear(); 0016 0017 } else { 0018 this->list.clear(); 0019 this->list = std::accumulate(this->m_urls.constBegin(), this->m_urls.constEnd(), FMH::MODEL_LIST(), [this](FMH::MODEL_LIST &list, const QString &url) { 0020 list << FMH::toModelList(Tagging::getInstance()->getUrlTags(url, this->strict)); 0021 return list; 0022 }); 0023 } 0024 0025 Q_EMIT this->tagsChanged(); 0026 Q_EMIT this->postListChanged(); 0027 } 0028 0029 void TagsList::refresh() 0030 { 0031 this->setList(); 0032 } 0033 0034 bool TagsList::insert(const QString &tag) 0035 { 0036 if (Tagging::getInstance()->tag(tag.trimmed())) 0037 return true; 0038 0039 return false; 0040 } 0041 0042 void TagsList::insertToUrls(const QString &tag) 0043 { 0044 if (m_urls.isEmpty()) 0045 return; 0046 0047 for (const auto &url : std::as_const(this->m_urls)) 0048 Tagging::getInstance()->tagUrl(url, tag); 0049 0050 this->refresh(); 0051 } 0052 0053 void TagsList::updateToUrls(const QStringList &tags) //if there is only one url update the tags if there are more than one url then add the new tags 0054 { 0055 if (this->m_urls.isEmpty()) 0056 return; 0057 0058 if(this->m_urls.size() == 1) 0059 { 0060 Tagging::getInstance()->updateUrlTags(this->m_urls.first(), tags); 0061 }else 0062 { 0063 for (const auto &url : std::as_const(this->m_urls)) 0064 { 0065 for(const auto &tag : tags) 0066 { 0067 Tagging::getInstance()->tagUrl(url, tag); 0068 } 0069 } 0070 } 0071 0072 this->refresh(); 0073 } 0074 0075 void TagsList::removeFromUrls(const int &index) 0076 { 0077 if (index >= this->list.size() || index < 0) 0078 return; 0079 0080 if (this->m_urls.isEmpty()) 0081 return; 0082 0083 const auto tag = this->list[index][FMH::MODEL_KEY::TAG]; 0084 0085 for (const auto &url : std::as_const(m_urls)) 0086 { 0087 Tagging::getInstance()->removeUrlTag(url, tag); 0088 } 0089 0090 this->remove(index); 0091 } 0092 0093 void TagsList::removeFromUrls(const QString &tag) 0094 { 0095 const auto index = indexOf(FMH::MODEL_KEY::TAG, tag); 0096 removeFromUrls(index); 0097 } 0098 0099 bool TagsList::remove(const int &index) 0100 { 0101 if (index >= this->list.size() || index < 0) 0102 return false; 0103 0104 Q_EMIT this->preItemRemoved(index); 0105 this->list.removeAt(index); 0106 Q_EMIT this->tagsChanged(); 0107 Q_EMIT this->postItemRemoved(); 0108 0109 return true; 0110 } 0111 0112 void TagsList::removeFrom(const int &index, const QString &url) 0113 { 0114 if (index >= this->list.size() || index < 0) 0115 return; 0116 0117 if (Tagging::getInstance()->removeUrlTag(url, this->list[index][FMH::MODEL_KEY::TAG])) 0118 this->remove(index); 0119 } 0120 0121 void TagsList::erase(const int &index) 0122 { 0123 Q_UNUSED(index) 0124 } 0125 0126 const FMH::MODEL_LIST &TagsList::items() const 0127 { 0128 return this->list; 0129 } 0130 0131 bool TagsList::getStrict() const 0132 { 0133 return this->strict; 0134 } 0135 0136 void TagsList::setStrict(const bool &value) 0137 { 0138 if (this->strict == value) 0139 return; 0140 0141 this->strict = value; 0142 Q_EMIT this->strictChanged(); 0143 } 0144 0145 QStringList TagsList::getTags() const 0146 { 0147 return FMH::modelToList(this->list, FMH::MODEL_KEY::TAG); 0148 } 0149 0150 QStringList TagsList::getUrls() const 0151 { 0152 return this->m_urls; 0153 } 0154 0155 void TagsList::setUrls(const QStringList &value) 0156 { 0157 if (this->m_urls == value) 0158 return; 0159 0160 this->m_urls = value; 0161 Q_EMIT this->urlsChanged(); 0162 } 0163 0164 void TagsList::append(const QString &tag) 0165 { 0166 this->append(FMH::MODEL {{FMH::MODEL_KEY::TAG, tag}}); 0167 } 0168 0169 void TagsList::appendItem(const QVariantMap &tag) 0170 { 0171 this->append(FMH::toModel(tag)); 0172 } 0173 0174 void TagsList::append(const FMH::MODEL &tag) 0175 { 0176 if (this->exists(FMH::MODEL_KEY::TAG, tag[FMH::MODEL_KEY::TAG])) 0177 return; 0178 0179 Q_EMIT this->preItemAppended(); 0180 this->list << tag; 0181 Q_EMIT this->postItemAppended(); 0182 Q_EMIT this->tagsChanged(); 0183 } 0184 0185 void TagsList::append(const QStringList &tags) 0186 { 0187 for (const auto &tag : std::as_const(tags)) 0188 { 0189 this->append(tag); 0190 } 0191 } 0192 0193 bool TagsList::contains(const QString &tag) 0194 { 0195 return this->exists(FMH::MODEL_KEY::TAG, tag); 0196 } 0197 0198 void TagsList::componentComplete() 0199 { 0200 connect(Tagging::getInstance(), &Tagging::tagged, this, &TagsList::appendItem); 0201 connect(Tagging::getInstance(), &Tagging::tagRemoved, this, &TagsList::refresh); 0202 0203 connect(this, &TagsList::urlsChanged, this, &TagsList::setList); 0204 connect(this, &TagsList::strictChanged, this, &TagsList::setList); 0205 0206 this->setList(); 0207 }