File indexing completed on 2024-04-21 04:48:57

0001 /*
0002    SPDX-FileCopyrightText: 2016 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>
0003    SPDX-FileCopyrightText: 2019 (c) Alexander Stippich <a.stippich@gmx.net>
0004 
0005    SPDX-License-Identifier: LGPL-3.0-or-later
0006  */
0007 
0008 #ifndef DATATYPES_H
0009 #define DATATYPES_H
0010 
0011 #include "elisaLib_export.h"
0012 
0013 #include "elisautils.h"
0014 
0015 #include <QObject>
0016 #include <QString>
0017 #include <QList>
0018 #include <QVariant>
0019 #include <QUrl>
0020 #include <QDateTime>
0021 #include <QMap>
0022 
0023 class ELISALIB_EXPORT DataTypes : public QObject
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028 
0029     enum ColumnsRoles {
0030         TitleRole = Qt::UserRole + 1,
0031         SecondaryTextRole,
0032         ImageUrlRole,
0033         ShadowForImageRole,
0034         ChildModelRole,
0035         DurationRole,
0036         StringDurationRole,
0037         ArtistRole,
0038         AllArtistsRole,
0039         HighestTrackRating,
0040         AlbumRole,
0041         AlbumArtistRole,
0042         IsValidAlbumArtistRole,
0043         TrackNumberRole,
0044         DiscNumberRole,
0045         RatingRole,
0046         GenreRole,
0047         LyricistRole,
0048         ComposerRole,
0049         CommentRole,
0050         YearRole,
0051         ChannelsRole,
0052         BitRateRole,
0053         SampleRateRole,
0054         ResourceRole,
0055         IdRole,
0056         ParentIdRole,
0057         DatabaseIdRole,
0058         IsSingleDiscAlbumRole,
0059         ContainerDataRole,
0060         IsPartialDataRole,
0061         AlbumIdRole,
0062         HasEmbeddedCover,
0063         FileModificationTime,
0064         FirstPlayDate,
0065         LastPlayDate,
0066         PlayCounter,
0067         ElementTypeRole,
0068         LyricsRole,
0069         FullDataRole,
0070         IsDirectoryRole,
0071         IsPlayListRole,
0072         FilePathRole,
0073         HasChildrenRole,
0074         MultipleImageUrlsRole,
0075     };
0076 
0077     Q_ENUM(ColumnsRoles)
0078 
0079     using DataType = QMap<ColumnsRoles, QVariant>;
0080 
0081 public:
0082 
0083     class MusicDataType : public DataType
0084     {
0085     public:
0086         using DataType::DataType;
0087 
0088         [[nodiscard]] bool hasDatabaseId() const
0089         {
0090             return find(key_type::DatabaseIdRole) != end();
0091         }
0092 
0093         [[nodiscard]] qulonglong databaseId() const
0094         {
0095             return operator[](key_type::DatabaseIdRole).toULongLong();
0096         }
0097 
0098         [[nodiscard]] bool hasElementType() const
0099         {
0100             return find(key_type::ElementTypeRole) != end();
0101         }
0102 
0103         [[nodiscard]] ElisaUtils::PlayListEntryType elementType() const
0104         {
0105             return operator[](key_type::ElementTypeRole).value<ElisaUtils::PlayListEntryType>();
0106         }
0107     };
0108 
0109     class TrackDataType : public MusicDataType
0110     {
0111     public:
0112 
0113         using MusicDataType::MusicDataType;
0114 
0115         TrackDataType(bool aValid, QString aId, QString aParentId, QString aTitle, QString aArtist, QString aAlbumName,
0116                       QString aAlbumArtist, int aTrackNumber, int aDiscNumber, QTime aDuration, QUrl aResourceURI,
0117                       const QDateTime &fileModificationTime, QUrl aAlbumCover, int rating, bool aIsSingleDiscAlbum,
0118                       QString aGenre, QString aComposer, QString aLyricist, bool aHasEmbeddedCover)
0119             : MusicDataType({{key_type::TitleRole, std::move(aTitle)}, {key_type::AlbumRole, std::move(aAlbumName)},
0120                              {key_type::ArtistRole, std::move(aArtist)}, {key_type::AlbumArtistRole, std::move(aAlbumArtist)},
0121                              {key_type::IdRole, std::move(aId)}, {key_type::ParentIdRole, std::move(aParentId)},
0122                              {key_type::TrackNumberRole, aTrackNumber}, {key_type::DiscNumberRole, aDiscNumber},
0123                              {key_type::DurationRole, aDuration}, {key_type::ResourceRole, std::move(aResourceURI)},
0124                              {key_type::FileModificationTime, fileModificationTime}, {key_type::ImageUrlRole, std::move(aAlbumCover)},
0125                              {key_type::RatingRole, rating}, {key_type::IsSingleDiscAlbumRole, aIsSingleDiscAlbum},
0126                              {key_type::GenreRole, std::move(aGenre)}, {key_type::ComposerRole, std::move(aComposer)},
0127                              {key_type::LyricistRole, std::move(aLyricist)}, {key_type::HasEmbeddedCover, aHasEmbeddedCover},
0128                              {key_type::ElementTypeRole, ElisaUtils::Track},})
0129         {
0130             Q_UNUSED(aValid)
0131         }
0132 
0133         [[nodiscard]] bool isValid() const
0134         {
0135             return !isEmpty() && duration().isValid();
0136         }
0137 
0138         [[nodiscard]] QString title() const
0139         {
0140             return operator[](key_type::TitleRole).toString();
0141         }
0142 
0143         [[nodiscard]] QString artist() const
0144         {
0145             return operator[](key_type::ArtistRole).toString();
0146         }
0147 
0148         [[nodiscard]] bool hasArtist() const
0149         {
0150             return find(key_type::ArtistRole) != end();
0151         }
0152 
0153         [[nodiscard]] qulonglong albumId() const
0154         {
0155             return operator[](key_type::AlbumIdRole).toULongLong();
0156         }
0157 
0158         [[nodiscard]] bool hasAlbum() const
0159         {
0160             return find(key_type::AlbumRole) != end();
0161         }
0162 
0163         [[nodiscard]] QString album() const
0164         {
0165             return operator[](key_type::AlbumRole).toString();
0166         }
0167 
0168         [[nodiscard]] QString albumArtist() const
0169         {
0170             return operator[](key_type::AlbumArtistRole).toString();
0171         }
0172 
0173         [[nodiscard]] bool hasAlbumArtist() const
0174         {
0175             return find(key_type::AlbumArtistRole) != end();
0176         }
0177 
0178         [[nodiscard]] bool hasTrackNumber() const
0179         {
0180             return find(key_type::TrackNumberRole) != end();
0181         }
0182 
0183         [[nodiscard]] int trackNumber() const
0184         {
0185             return operator[](key_type::TrackNumberRole).toInt();
0186         }
0187 
0188         [[nodiscard]] bool hasDiscNumber() const
0189         {
0190             return find(key_type::DiscNumberRole) != end();
0191         }
0192 
0193         [[nodiscard]] int discNumber() const
0194         {
0195             return operator[](key_type::DiscNumberRole).toInt();
0196         }
0197 
0198         [[nodiscard]] QTime duration() const
0199         {
0200             return operator[](key_type::DurationRole).toTime();
0201         }
0202 
0203         [[nodiscard]] QUrl resourceURI() const
0204         {
0205             return operator[](key_type::ResourceRole).toUrl();
0206         }
0207 
0208         [[nodiscard]] QUrl albumCover() const
0209         {
0210             return operator[](key_type::ImageUrlRole).toUrl();
0211         }
0212 
0213         [[nodiscard]] bool isSingleDiscAlbum() const
0214         {
0215             return operator[](key_type::IsSingleDiscAlbumRole).toBool();
0216         }
0217 
0218         [[nodiscard]] int rating() const
0219         {
0220             return operator[](key_type::RatingRole).toInt();
0221         }
0222 
0223         [[nodiscard]] QString genre() const
0224         {
0225             return operator[](key_type::GenreRole).toString();
0226         }
0227 
0228         [[nodiscard]] bool hasGenre() const
0229         {
0230             return find(key_type::GenreRole) != end();
0231         }
0232 
0233         [[nodiscard]] QString composer() const
0234         {
0235             return operator[](key_type::ComposerRole).toString();
0236         }
0237 
0238         [[nodiscard]] bool hasComposer() const
0239         {
0240             return find(key_type::ComposerRole) != end();
0241         }
0242 
0243         [[nodiscard]] QString lyricist() const
0244         {
0245             return operator[](key_type::LyricistRole).toString();
0246         }
0247 
0248         [[nodiscard]] bool hasLyricist() const
0249         {
0250             return find(key_type::LyricistRole) != end();
0251         }
0252 
0253         [[nodiscard]] QString lyrics() const
0254         {
0255             return operator[](key_type::LyricsRole).toString();
0256         }
0257 
0258         [[nodiscard]] bool hasLyrics() const
0259         {
0260             return find(key_type::LyricsRole) != end();
0261         }
0262 
0263         [[nodiscard]] QString comment() const
0264         {
0265             return operator[](key_type::CommentRole).toString();
0266         }
0267 
0268         [[nodiscard]] bool hasComment() const
0269         {
0270             return find(key_type::CommentRole) != end();
0271         }
0272 
0273         [[nodiscard]] int year() const
0274         {
0275             return operator[](key_type::YearRole).toInt();
0276         }
0277 
0278         [[nodiscard]] bool hasYear() const
0279         {
0280             return find(key_type::YearRole) != end();
0281         }
0282 
0283         [[nodiscard]] int channels() const
0284         {
0285             return operator[](key_type::ChannelsRole).toInt();
0286         }
0287 
0288         [[nodiscard]] bool hasChannels() const
0289         {
0290             return find(key_type::ChannelsRole) != end();
0291         }
0292 
0293         [[nodiscard]] int bitRate() const
0294         {
0295             return operator[](key_type::BitRateRole).toInt();
0296         }
0297 
0298         [[nodiscard]] bool hasBitRate() const
0299         {
0300             return find(key_type::BitRateRole) != end();
0301         }
0302 
0303         [[nodiscard]] int sampleRate() const
0304         {
0305             return operator[](key_type::SampleRateRole).toInt();
0306         }
0307 
0308         [[nodiscard]] bool hasSampleRate() const
0309         {
0310             return find(key_type::SampleRateRole) != end();
0311         }
0312 
0313 
0314         [[nodiscard]] bool hasEmbeddedCover() const
0315         {
0316             return operator[](key_type::HasEmbeddedCover).toBool();
0317         }
0318 
0319         [[nodiscard]] QDateTime fileModificationTime() const
0320         {
0321             return operator[](key_type::FileModificationTime).toDateTime();
0322         }
0323 
0324         [[nodiscard]] bool albumInfoIsSame(const TrackDataType &other) const;
0325 
0326         [[nodiscard]] bool isSameTrack(const TrackDataType &other) const;
0327     };
0328 
0329     using ListTrackDataType = QList<TrackDataType>;
0330 
0331     using ListRadioDataType = QList<TrackDataType>;
0332 
0333     class AlbumDataType : public MusicDataType
0334     {
0335     public:
0336 
0337         using MusicDataType::MusicDataType;
0338 
0339         [[nodiscard]] QString title() const
0340         {
0341             return operator[](key_type::TitleRole).toString();
0342         }
0343 
0344         [[nodiscard]] QString artist() const
0345         {
0346             return operator[](key_type::ArtistRole).toString();
0347         }
0348 
0349         [[nodiscard]] bool isValidArtist() const
0350         {
0351             const auto &artistData = operator[](key_type::ArtistRole);
0352             return artistData.isValid() && !artistData.toString().isEmpty();
0353         }
0354 
0355         [[nodiscard]] QStringList genres() const
0356         {
0357             return operator[](key_type::GenreRole).toStringList();
0358         }
0359 
0360         [[nodiscard]] QUrl albumArtURI() const
0361         {
0362             return operator[](key_type::ImageUrlRole).toUrl();
0363         }
0364 
0365         [[nodiscard]] bool isSingleDiscAlbum() const
0366         {
0367             return operator[](key_type::IsSingleDiscAlbumRole).toBool();
0368         }
0369 
0370         [[nodiscard]] bool isValid() const
0371         {
0372             return !isEmpty();
0373         }
0374 
0375     };
0376 
0377     using ListAlbumDataType = QList<AlbumDataType>;
0378 
0379     class ArtistDataType : public MusicDataType
0380     {
0381     public:
0382 
0383         using MusicDataType::MusicDataType;
0384 
0385         [[nodiscard]] QString name() const
0386         {
0387             return operator[](key_type::TitleRole).toString();
0388         }
0389 
0390         [[nodiscard]] qulonglong databaseId() const
0391         {
0392             return operator[](key_type::DatabaseIdRole).toULongLong();
0393         }
0394 
0395        [[nodiscard]] QUrl artistArtURI() const
0396         {
0397             return operator[](key_type::ImageUrlRole).toUrl();
0398         }
0399     };
0400 
0401     using ListArtistDataType = QList<ArtistDataType>;
0402 
0403     class GenreDataType : public MusicDataType
0404     {
0405     public:
0406 
0407         using MusicDataType::MusicDataType;
0408 
0409         [[nodiscard]] QString title() const
0410         {
0411             return operator[](key_type::TitleRole).toString();
0412         }
0413 
0414     };
0415 
0416     using ListGenreDataType = QList<GenreDataType>;
0417 
0418     using EntryData = std::tuple<MusicDataType, QString, QUrl>;
0419     using EntryDataList = QList<EntryData>;
0420 
0421 };
0422 
0423 Q_DECLARE_METATYPE(DataTypes::MusicDataType)
0424 Q_DECLARE_METATYPE(DataTypes::TrackDataType)
0425 Q_DECLARE_METATYPE(DataTypes::AlbumDataType)
0426 Q_DECLARE_METATYPE(DataTypes::ArtistDataType)
0427 Q_DECLARE_METATYPE(DataTypes::GenreDataType)
0428 
0429 Q_DECLARE_METATYPE(DataTypes::ListTrackDataType)
0430 Q_DECLARE_METATYPE(DataTypes::ListAlbumDataType)
0431 Q_DECLARE_METATYPE(DataTypes::ListArtistDataType)
0432 Q_DECLARE_METATYPE(DataTypes::ListGenreDataType)
0433 
0434 Q_DECLARE_METATYPE(DataTypes::EntryData)
0435 Q_DECLARE_METATYPE(DataTypes::EntryDataList)
0436 
0437 #endif // DATATYPES_H