File indexing completed on 2024-05-12 04:47:03
0001 #include "placesmodel.h" 0002 #include <KI18n/KLocalizedString> 0003 #include <MauiKit3/FileBrowsing/fmstatic.h> 0004 #include <MauiKit3/FileBrowsing/tagging.h> 0005 0006 PlacesModel::PlacesModel(QObject *parent) : MauiList(parent) 0007 { 0008 m_quickPlaces << QVariantMap{{"icon", "love"}, {"path", "tags:///fav"}, {"label", i18n("Favorites")}}; 0009 m_quickPlaces << QVariantMap{{"icon", "folder-download"}, {"path", FMStatic::DownloadsPath}, {"label", i18n("Downloads")}}; 0010 m_quickPlaces << QVariantMap{{"icon", "folder-documents"}, {"path", FMStatic::DocumentsPath}, {"label", i18n("Documents")}}; 0011 m_quickPlaces << QVariantMap{{"icon", "send-sms"}, {"path", "comics:///"}, {"label", i18n("Comics")}}; 0012 m_quickPlaces << QVariantMap{{"icon", "document-new"}, {"path", "documents:///"}, {"label", i18n("PDFs")}}; 0013 m_quickPlaces << QVariantMap{{"icon", "view-list-icons"}, {"path", "collection:///"}, {"label", i18n("Collection")}}; 0014 0015 connect(Tagging::getInstance(), &Tagging::tagged, [this](QVariantMap item) { 0016 Q_EMIT this->preItemAppended(); 0017 auto tag = FMH::toModel(item); 0018 tag[FMH::MODEL_KEY::TYPE] = i18n("Tags"); 0019 tag[FMH::MODEL_KEY::PATH] = QString("tags:///%1").arg(tag[FMH::MODEL_KEY::TAG]); 0020 m_list << tag; 0021 Q_EMIT this->postItemAppended(); 0022 }); 0023 } 0024 0025 QVariantList PlacesModel::quickPlaces() const 0026 { 0027 return m_quickPlaces; 0028 } 0029 0030 void PlacesModel::setList() 0031 { 0032 Q_EMIT this->preListChanged(); 0033 m_list << this->tags(); 0034 Q_EMIT this->postListChanged(); 0035 Q_EMIT this->countChanged(); 0036 } 0037 0038 FMH::MODEL_LIST PlacesModel::tags() 0039 { 0040 FMH::MODEL_LIST res; 0041 const auto tags = Tagging::getInstance()->getUrlsTags(true); 0042 0043 return std::accumulate(tags.constBegin(), tags.constEnd(), res, [this](FMH::MODEL_LIST &list, const QVariant &item) { 0044 auto tag = FMH::toModel(item.toMap()); 0045 tag[FMH::MODEL_KEY::TYPE] = i18n("Tags"); 0046 tag[FMH::MODEL_KEY::PATH] = QString("tags:///%1").arg(tag[FMH::MODEL_KEY::TAG]); 0047 m_list << tag; 0048 return list; 0049 }); 0050 } 0051 0052 0053 void PlacesModel::classBegin() 0054 { 0055 } 0056 0057 void PlacesModel::componentComplete() 0058 { 0059 this->setList(); 0060 } 0061 0062 const FMH::MODEL_LIST &PlacesModel::items() const 0063 { 0064 return m_list; 0065 }