Cleaner way of setting online properties on song
This commit is contained in:
committed by
craig.p.drummond
parent
70d1658e0a
commit
4ade487236
@@ -113,12 +113,12 @@ bool MusicLibraryItemPodcast::load()
|
||||
s.file=url;
|
||||
s.track=++track;
|
||||
s.artist=m_itemData;
|
||||
s.id=constTrue==attributes.value(constPlayedAttribute).toString() ? 1 : 0;
|
||||
s.setPlayed(constTrue==attributes.value(constPlayedAttribute).toString());
|
||||
QString time=attributes.value(constTimeAttribute).toString();
|
||||
s.time=time.isEmpty() ? 0 : time.toUInt();
|
||||
MusicLibraryItemSong *song=new MusicLibraryItemSong(s, this);
|
||||
m_childItems.append(song);
|
||||
if (!s.id) {
|
||||
if (!s.hasbeenPlayed()) {
|
||||
m_unplayedEpisodeCount++;
|
||||
}
|
||||
}
|
||||
@@ -170,7 +170,7 @@ bool MusicLibraryItemPodcast::loadRss(QIODevice *dev)
|
||||
s.track=++track;
|
||||
s.artist=m_itemData;
|
||||
s.time=ep.duration;
|
||||
s.id=0;
|
||||
s.setPlayed(false);
|
||||
MusicLibraryItemSong *song=new MusicLibraryItemSong(s, this);
|
||||
m_childItems.append(song);
|
||||
}
|
||||
@@ -204,7 +204,7 @@ bool MusicLibraryItemPodcast::save()
|
||||
if (s.time) {
|
||||
writer.writeAttribute(constTimeAttribute, QString::number(s.time));
|
||||
}
|
||||
if (s.id) {
|
||||
if (s.hasbeenPlayed()) {
|
||||
writer.writeAttribute(constPlayedAttribute, constTrue);
|
||||
}
|
||||
writer.writeEndElement();
|
||||
@@ -327,7 +327,7 @@ void MusicLibraryItemPodcast::updateTrackNumbers()
|
||||
m_unplayedEpisodeCount=0;
|
||||
foreach (MusicLibraryItem *i, m_childItems) {
|
||||
static_cast<MusicLibraryItemSong *>(i)->setTrack(++track);
|
||||
if (!static_cast<MusicLibraryItemSong *>(i)->song().id) {
|
||||
if (!static_cast<MusicLibraryItemSong *>(i)->song().hasbeenPlayed()) {
|
||||
m_unplayedEpisodeCount++;
|
||||
}
|
||||
}
|
||||
@@ -335,8 +335,8 @@ void MusicLibraryItemPodcast::updateTrackNumbers()
|
||||
|
||||
void MusicLibraryItemPodcast::setPlayed(MusicLibraryItemSong *song)
|
||||
{
|
||||
if (!song->song().id) {
|
||||
song->setId(1);
|
||||
if (!song->song().hasbeenPlayed()) {
|
||||
song->setPlayed(true);
|
||||
m_unplayedEpisodeCount--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
void setFile(const QString &f) { m_song.file=f; }
|
||||
quint16 track() const { return m_song.track; }
|
||||
void setTrack(quint16 t) { m_song.track=t; }
|
||||
void setId(qint32 i) { m_song.id=i; }
|
||||
void setPlayed(bool p) { m_song.setPlayed(p); }
|
||||
quint16 disc() const { return m_song.disc; }
|
||||
quint32 time() const { return m_song.time; }
|
||||
const QString & genre() const { return m_song.genre; }
|
||||
|
||||
@@ -196,7 +196,7 @@ QVariant OnlineServicesModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
case Qt::DecorationRole:
|
||||
if (MusicLibraryItem::Type_Song==item->itemType() && item->parentItem() && MusicLibraryItem::Type_Podcast==item->parentItem()->itemType()) {
|
||||
if (static_cast<MusicLibraryItemSong *>(item)->song().id) {
|
||||
if (static_cast<MusicLibraryItemSong *>(item)->song().hasbeenPlayed()) {
|
||||
return Icons::self()->playedPodcastEpisodeIcon;
|
||||
}
|
||||
}
|
||||
|
||||
14
mpd/song.cpp
14
mpd/song.cpp
@@ -440,3 +440,17 @@ QString Song::basicArtist() const
|
||||
}
|
||||
return artist;
|
||||
}
|
||||
|
||||
static const quint8 constOnlineDiscId=0xEE;
|
||||
|
||||
bool Song::isFromOnlineService() const
|
||||
{
|
||||
return constOnlineDiscId==disc && file.startsWith("http://") && albumartist==album;
|
||||
}
|
||||
|
||||
void Song::setIsFromOnlineService(const QString &service)
|
||||
{
|
||||
disc=constOnlineDiscId;
|
||||
album=service;
|
||||
albumartist=service;
|
||||
}
|
||||
|
||||
@@ -123,6 +123,14 @@ struct Song
|
||||
bool isArtistImageRequest() const { return album.isEmpty() && artist.isEmpty() && !albumartist.isEmpty() && 0==size && 0==track; }
|
||||
|
||||
QString basicArtist() const;
|
||||
|
||||
// podcast functions...
|
||||
bool hasbeenPlayed() const { return 0!=id; }
|
||||
void setPlayed(bool p) { id=p ? 1 : 0; }
|
||||
|
||||
// podcast/soundcloud functions...
|
||||
void setIsFromOnlineService(const QString &service);
|
||||
bool isFromOnlineService() const;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(Song)
|
||||
|
||||
@@ -108,9 +108,7 @@ PodcastService::PodcastService(MusicModel *m)
|
||||
Song PodcastService::fixPath(const Song &orig, bool) const
|
||||
{
|
||||
Song song=orig;
|
||||
song.album=constName;
|
||||
song.albumartist=i18n("Streams");
|
||||
song.disc=0xFF;
|
||||
song.setIsFromOnlineService(constName);
|
||||
return encode(song);
|
||||
}
|
||||
|
||||
@@ -200,7 +198,7 @@ void PodcastService::jobFinished()
|
||||
foreach (MusicLibraryItem *i, orig->childItems()) {
|
||||
MusicLibraryItemSong *song=static_cast<MusicLibraryItemSong *>(i);
|
||||
origSongs.insert(song->file()+song->data());
|
||||
if (song->song().id) {
|
||||
if (song->song().hasbeenPlayed()) {
|
||||
playedSongs.insert(song->file());
|
||||
}
|
||||
}
|
||||
@@ -363,7 +361,7 @@ void PodcastService::currentMpdSong(const Song &s)
|
||||
foreach (MusicLibraryItem *i, podcast->childItems()) {
|
||||
MusicLibraryItemSong *song=static_cast<MusicLibraryItemSong *>(i);
|
||||
if (song->file()==s.file) {
|
||||
if (!song->song().id) {
|
||||
if (!song->song().hasbeenPlayed()) {
|
||||
podcast->setPlayed(song);
|
||||
emitDataChanged(createIndex(song));
|
||||
emitDataChanged(createIndex(podcast));
|
||||
|
||||
@@ -145,9 +145,7 @@ void SoundCloudService::jobFinished()
|
||||
song.genre=details["genre"].toString();
|
||||
song.year=details["release_year"].toInt();
|
||||
song.time=details["duration"].toUInt()/1000;
|
||||
song.album=constName;
|
||||
song.albumartist=i18n("Streams");
|
||||
song.disc=0xFF;
|
||||
song.setIsFromOnlineService(constName);
|
||||
if (!update) {
|
||||
update=new MusicLibraryItemRoot();
|
||||
}
|
||||
|
||||
@@ -242,10 +242,6 @@ public:
|
||||
QFontMetrics fm(f);
|
||||
int textHeight=fm.height();
|
||||
|
||||
static QString streamsTrans;
|
||||
if (streamsTrans.isEmpty()) {
|
||||
streamsTrans=i18n("Streams");
|
||||
}
|
||||
|
||||
if (isCollection) {
|
||||
title=index.data(Qt::DisplayRole).toString();
|
||||
@@ -257,7 +253,7 @@ public:
|
||||
title=song.name;
|
||||
track=streamText(song, trackTitle, false);
|
||||
} else {
|
||||
title=audiocd ? i18n("Audio CD") : streamsTrans;
|
||||
title=audiocd ? i18n("Audio CD") : i18n("Streams");
|
||||
track=streamText(song, trackTitle);
|
||||
}
|
||||
} else if (isEmpty) {
|
||||
@@ -267,7 +263,7 @@ public:
|
||||
quint16 year=Song::albumYear(song);
|
||||
|
||||
if (year>0) {
|
||||
if (0xFF==song.disc && streamsTrans==song.albumartist) {
|
||||
if (song.isFromOnlineService()) {
|
||||
title=i18nc("album (albumYear)", "%1 (%2)", song.album, year);
|
||||
} else {
|
||||
title=i18nc("artist - album (albumYear)", "%1 - %2 (%3)", song.artistOrComposer(), song.albumName(), year);
|
||||
@@ -278,7 +274,7 @@ public:
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (0xFF==song.disc && streamsTrans==song.albumartist) {
|
||||
if (song.isFromOnlineService()) {
|
||||
title=song.album;
|
||||
} else {
|
||||
title=i18nc("artist - album", "%1 - %2", song.artistOrComposer(), song.albumName());
|
||||
|
||||
Reference in New Issue
Block a user