File indexing completed on 2024-12-22 04:31:17
0001 #include "placesmodel.h" 0002 0003 #include <KI18n/KLocalizedString> 0004 #include <MauiKit3/FileBrowsing/fmstatic.h> 0005 #include <MauiKit3/FileBrowsing/tagging.h> 0006 0007 #include "pix.h" 0008 #include "models/gallery/gallery.h" 0009 0010 #include <MauiKit3/ImageTools/cities.h> 0011 #include <MauiKit3/ImageTools/city.h> 0012 0013 PlacesModel::PlacesModel(QObject *parent) : MauiList(parent) 0014 { 0015 m_quickPlaces << QVariantMap{{"icon", "love"}, {"path", "tags:///fav"}, {"label", i18n("Favorites")}}; 0016 m_quickPlaces << QVariantMap{{"icon", "folder-download"}, {"path", FMStatic::DownloadsPath}, {"label", i18n("Downloads")}}; 0017 m_quickPlaces << QVariantMap{{"icon", "folder-pictures"}, {"path", FMStatic::PicturesPath}, {"label", i18n("Pictures")}}; 0018 m_quickPlaces << QVariantMap{{"icon", "org.gnome.Screenshot-symbolic"}, {"path", Pix::screenshotsPath().toString()}, {"label", i18n("Screenshots")}}; 0019 m_quickPlaces << QVariantMap{{"icon", "camera-web"}, {"path", Pix::cameraPath().toString()}, {"label", i18n("Camera")}}; 0020 m_quickPlaces << QVariantMap{{"icon", "view-list-icons"}, {"path", "collection:///"}, {"label", i18n("Collection")}}; 0021 } 0022 0023 QVariantList PlacesModel::quickPlaces() const 0024 { 0025 return m_quickPlaces; 0026 } 0027 0028 void PlacesModel::setList() 0029 { 0030 Q_EMIT this->preListChanged(); 0031 m_list.clear(); 0032 m_list << this->tags(); 0033 m_list << this->collectionPaths(); 0034 m_list << this->locations(); 0035 m_list << this->categories(); 0036 Q_EMIT this->postListChanged(); 0037 Q_EMIT this->countChanged(); 0038 } 0039 0040 FMH::MODEL_LIST PlacesModel::tags() 0041 { 0042 FMH::MODEL_LIST res; 0043 const auto tags = Tagging::getInstance()->getUrlsTags(true); 0044 0045 return std::accumulate(tags.constBegin(), tags.constEnd(), res, [this](FMH::MODEL_LIST &list, const QVariant &item) { 0046 auto tag = FMH::toModel(item.toMap()); 0047 tag[FMH::MODEL_KEY::TYPE] = i18n("Tags"); 0048 tag[FMH::MODEL_KEY::NAME] = tag[FMH::MODEL_KEY::TAG]; 0049 tag[FMH::MODEL_KEY::PATH] = QString("tags:///%1").arg(tag[FMH::MODEL_KEY::TAG]); 0050 list << tag; 0051 return list; 0052 }); 0053 } 0054 0055 FMH::MODEL_LIST PlacesModel::collectionPaths() 0056 { 0057 FMH::MODEL_LIST res; 0058 const auto paths = Pix::getSourcePaths(); 0059 0060 return std::accumulate(paths.constBegin(), paths.constEnd(), res, [this](FMH::MODEL_LIST &list, const QString &path) { 0061 auto item = FMStatic::getFileInfoModel(path); 0062 item[FMH::MODEL_KEY::TYPE] = i18n("Places"); 0063 list << item; 0064 return list; 0065 }); 0066 } 0067 0068 FMH::MODEL_LIST PlacesModel::locations() 0069 { 0070 FMH::MODEL_LIST res; 0071 0072 if(!Pix::instance()->allImagesModel()->activeGeolocationTags()) 0073 return res; 0074 0075 auto cities = Pix::instance()->allImagesModel()->cities(); 0076 auto db = Cities::getInstance(); 0077 0078 0079 return std::accumulate(cities.constBegin(), cities.constEnd(), res, [this, &db](FMH::MODEL_LIST &list, const QString &id) { 0080 FMH::MODEL item; 0081 0082 City city = db->city(id); 0083 0084 item[FMH::MODEL_KEY::ICON] = "gps"; 0085 item[FMH::MODEL_KEY::TYPE] = i18n("Locations"); 0086 item[FMH::MODEL_KEY::PATH] = "collection:///"+id; 0087 item[FMH::MODEL_KEY::KEY] = id; 0088 0089 item[FMH::MODEL_KEY::COUNTRY] = city.country(); 0090 item[FMH::MODEL_KEY::ID] = city.id(); 0091 item[FMH::MODEL_KEY::NAME] = city.name(); 0092 0093 list << item; 0094 return list; 0095 }); 0096 0097 } 0098 0099 FMH::MODEL_LIST PlacesModel::categories() 0100 { 0101 FMH::MODEL_LIST res; 0102 0103 res << FMH::MODEL {{FMH::MODEL_KEY::ICON, "media-playback-start"}, {FMH::MODEL_KEY::PATH, "collection:///animated"}, {FMH::MODEL_KEY::NAME, i18n("Animated")}, {FMH::MODEL_KEY::KEY, QStringLiteral("gif,avif")}, {FMH::MODEL_KEY::TYPE, i18n("Categories")}}; 0104 0105 res << FMH::MODEL {{FMH::MODEL_KEY::ICON, "monitor"}, {FMH::MODEL_KEY::PATH, "collection:///screenshots"}, {FMH::MODEL_KEY::NAME, i18n("Screenshots")}, {FMH::MODEL_KEY::KEY, QStringLiteral("screenshot,screen")}, {FMH::MODEL_KEY::TYPE, i18n("Categories")}}; 0106 0107 res << FMH::MODEL {{FMH::MODEL_KEY::ICON, "image"}, {FMH::MODEL_KEY::PATH, "collection:///png"}, {FMH::MODEL_KEY::NAME, i18n("PNG")}, {FMH::MODEL_KEY::KEY, QStringLiteral(".png")}, {FMH::MODEL_KEY::TYPE, i18n("Categories")}}; 0108 0109 res << FMH::MODEL {{FMH::MODEL_KEY::ICON, "image"}, {FMH::MODEL_KEY::PATH, "collection:///psd"}, {FMH::MODEL_KEY::NAME, i18n("PSD")}, {FMH::MODEL_KEY::KEY, QStringLiteral(".psd")}, {FMH::MODEL_KEY::TYPE, i18n("Categories")}}; 0110 0111 res << FMH::MODEL {{FMH::MODEL_KEY::ICON, "draw-arrow"}, {FMH::MODEL_KEY::PATH, "collection:///vectors"}, {FMH::MODEL_KEY::NAME, i18n("Vectors")}, {FMH::MODEL_KEY::KEY, QStringLiteral(".svg,.eps")}, {FMH::MODEL_KEY::TYPE, i18n("Categories")}}; 0112 0113 res << FMH::MODEL {{FMH::MODEL_KEY::ICON, "draw-brush"}, {FMH::MODEL_KEY::PATH, "collection:///paintings"}, {FMH::MODEL_KEY::NAME, i18n("Paintings")}, {FMH::MODEL_KEY::KEY, QStringLiteral(".xcf,.kra")}, {FMH::MODEL_KEY::TYPE, i18n("Categories")}}; 0114 0115 return res; 0116 } 0117 0118 void PlacesModel::classBegin() 0119 { 0120 } 0121 0122 void PlacesModel::componentComplete() 0123 { 0124 connect(Tagging::getInstance(), &Tagging::tagged, [this](QVariantMap item) { 0125 Q_EMIT this->preItemAppended(); 0126 auto tag = FMH::toModel(item); 0127 tag[FMH::MODEL_KEY::TYPE] = i18n("Tags"); 0128 tag[FMH::MODEL_KEY::PATH] = QString("tags:///%1").arg(tag[FMH::MODEL_KEY::TAG]); 0129 m_list << tag; 0130 Q_EMIT this->postItemAppended(); 0131 }); 0132 0133 connect(Pix::instance(), &Pix::sourcesChanged, this, &PlacesModel::setList); 0134 connect(Pix::instance()->allImagesModel(), &Gallery::citiesChanged, this, &PlacesModel::setList); 0135 0136 this->setList(); 0137 0138 } 0139 0140 const FMH::MODEL_LIST &PlacesModel::items() const 0141 { 0142 return m_list; 0143 }