From 0e4bfcea2adc78e5999db454dad23c4eaffd798e Mon Sep 17 00:00:00 2001 From: "craig.p.drummond" Date: Mon, 16 Jun 2014 19:14:18 +0000 Subject: [PATCH] Store radio station 'name' field in extra map --- context/albumview.cpp | 5 +++-- dbus/mpris.cpp | 9 ++++++--- gui/mainwindow.cpp | 2 +- gui/trayitem.cpp | 2 +- models/musiclibrarymodel.cpp | 4 ++-- models/playlistsmodel.cpp | 8 +++++++- models/playqueuemodel.cpp | 12 +++++++++--- models/searchmodel.cpp | 8 +++++++- mpd/cuefile.cpp | 7 ++++--- mpd/mpdconnection.cpp | 2 +- mpd/mpdparseutils.cpp | 18 +++++++++--------- mpd/song.cpp | 13 ++++++------- mpd/song.h | 4 +++- widgets/groupedview.cpp | 20 +++++++++++--------- 14 files changed, 70 insertions(+), 44 deletions(-) diff --git a/context/albumview.cpp b/context/albumview.cpp index b35b27466..7efa739d3 100644 --- a/context/albumview.cpp +++ b/context/albumview.cpp @@ -106,11 +106,12 @@ void AlbumView::refresh() void AlbumView::update(const Song &song, bool force) { - if (song.isStandardStream() && song.album.isEmpty() && !song.name.isEmpty() && song.name!=currentSong.name) { + QString streamName=song.isStandardStream() && song.album.isEmpty() ? song.name() : QString(); + if (!streamName.isEmpty() && streamName!=currentSong.name()) { abort(); currentSong=song; clearDetails(); - setHeader(song.name); + setHeader(streamName); needToUpdate=false; detailsReceived=All; pic=createPicTag(QImage(), CANTATA_SYS_ICONS_DIR+QLatin1String("stream.png")); diff --git a/dbus/mpris.cpp b/dbus/mpris.cpp index d4a960ef7..1c901ec10 100644 --- a/dbus/mpris.cpp +++ b/dbus/mpris.cpp @@ -123,15 +123,18 @@ void Mpris::updateCurrentSong(const Song &song) QVariantMap Mpris::Metadata() const { QVariantMap metadataMap; if (!currentSong.title.isEmpty() && !currentSong.artist.isEmpty() && - (!currentSong.album.isEmpty() || (currentSong.isStream() && !currentSong.name.isEmpty()))) { + (!currentSong.album.isEmpty() || (currentSong.isStream() && !currentSong.name().isEmpty()))) { metadataMap.insert("mpris:trackid", QVariant::fromValue(QDBusObjectPath(mprisPath.arg(currentSong.id)))); if (currentSong.time>0) { metadataMap.insert("mpris:length", convertTime(currentSong.time)); } if (!currentSong.album.isEmpty()) { metadataMap.insert("xesam:album", currentSong.album); - } else if (!currentSong.name.isEmpty()) { - metadataMap.insert("xesam:album", currentSong.name); + } else { + QString name=currentSong.name(); + if (!name.isEmpty()) { + metadataMap.insert("xesam:album", name); + } } if (!currentSong.albumartist.isEmpty() && currentSong.albumartist!=currentSong.artist) { metadataMap.insert("xesam:albumArtist", QStringList() << currentSong.albumartist); diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 53b856050..df58f91f4 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1666,7 +1666,7 @@ void MainWindow::updatePlayQueue(const QList &songs) } else if (current.isStandardStream()) { // Check to see if it has been updated... Song pqSong=playQueueModel.getSongByRow(playQueueModel.currentSongRow()); - if (pqSong.artist!=current.artist || pqSong.album!=current.album || pqSong.name!=current.name || pqSong.title!=current.title || pqSong.year!=current.year) { + if (pqSong.artist!=current.artist || pqSong.album!=current.album || pqSong.title!=current.title || pqSong.year!=current.year || pqSong.name()!=current.name() ) { updateCurrentSong(pqSong); } } diff --git a/gui/trayitem.cpp b/gui/trayitem.cpp index 6444495cd..d4ee8fded 100644 --- a/gui/trayitem.cpp +++ b/gui/trayitem.cpp @@ -187,7 +187,7 @@ void TrayItem::songChanged(const Song &song, bool isPlaying) { if (Settings::self()->showPopups() || trayItem) { bool useable=song.isStandardStream() - ? !song.title.isEmpty() && !song.name.isEmpty() + ? !song.title.isEmpty() && !song.name().isEmpty() : !song.title.isEmpty() && !song.artist.isEmpty() && !song.album.isEmpty(); if (useable) { QString text=song.describe(false); diff --git a/models/musiclibrarymodel.cpp b/models/musiclibrarymodel.cpp index a2331696f..8c8340fea 100644 --- a/models/musiclibrarymodel.cpp +++ b/models/musiclibrarymodel.cpp @@ -709,7 +709,7 @@ void MusicLibraryModel::coverLoaded(const Song &song, int size) #endif //song.isCdda() || (song.isArtistImageRequest() && !rootItem->useArtistImages()) || song.isCdda() || !song.isArtistImageRequest() || !rootItem->useArtistImages() || - song.file.startsWith("http://") || song.name.startsWith("http://")) { + song.file.startsWith("http://") || song.name().startsWith("http://")) { return; } //if (song.isArtistImageRequest()) { @@ -750,7 +750,7 @@ void MusicLibraryModel::setCover(const Song &song, const QImage &img, const QStr #else Q_UNUSED(file) if (!rootItem->useAlbumImages() || img.isNull() || MusicLibraryItemAlbum::CoverNone==MusicLibraryItemAlbum::currentCoverSize() || - song.isCdda() || song.file.startsWith("http:/") || song.name.startsWith("http:/")) { + song.isCdda() || song.file.startsWith("http:/") || song.name().startsWith("http:/")) { return; } diff --git a/models/playlistsmodel.cpp b/models/playlistsmodel.cpp index c861b471c..7195e063f 100644 --- a/models/playlistsmodel.cpp +++ b/models/playlistsmodel.cpp @@ -419,7 +419,13 @@ QVariant PlaylistsModel::data(const QModelIndex &index, int role) const case COL_ARTIST: return s->artist.isEmpty() ? Song::unknown() : s->artist; case COL_ALBUM: - return s->album.isEmpty() && !s->name.isEmpty() && s->isStream() ? s->name : s->album; + if (s->isStream() && s->album.isEmpty()) { + QString n=s->name(); + if (!n.isEmpty()) { + return n; + } + } + return s->album; case COL_LENGTH: return Utils::formatTime(s->time); case COL_YEAR: diff --git a/models/playqueuemodel.cpp b/models/playqueuemodel.cpp index 327fa6449..a20c3109c 100644 --- a/models/playqueuemodel.cpp +++ b/models/playqueuemodel.cpp @@ -534,7 +534,13 @@ QVariant PlayQueueModel::data(const QModelIndex &index, int role) const case COL_ARTIST: return song.artist.isEmpty() ? Song::unknown() : song.artist; case COL_ALBUM: - return song.album.isEmpty() && !song.name.isEmpty() && song.isStream() ? song.name : song.album; + if (song.isStream() && song.album.isEmpty()) { + QString n=song.name(); + if (!n.isEmpty()) { + return n; + } + } + return song.album; case COL_TRACK: if (song.track <= 0) { return QVariant(); @@ -978,7 +984,7 @@ void PlayQueueModel::update(const QList &songList) currentKeys.insert(s.key); #endif songs.replace(i, s); - if (s.name!=curentSongAtPos.name || s.title!=curentSongAtPos.title || s.artist!=curentSongAtPos.artist) { + if (s.title!=curentSongAtPos.title || s.artist!=curentSongAtPos.artist || s.name()!=curentSongAtPos.name()) { emit dataChanged(index(i, 0), index(i, columnCount(QModelIndex())-1)); } } @@ -1459,7 +1465,7 @@ void PlayQueueModel::updateDetails(const QList &updated) updatedSong.id=current.id; updatedSong.setKey(MPDParseUtils::Loc_PlayQueue); - if (updatedSong.name!=current.name || updatedSong.title!=current.title || updatedSong.artist!=current.artist) { + if (updatedSong.title!=current.title || updatedSong.artist!=current.artist || updatedSong.name()!=current.name()) { songs.replace(i, updatedSong); updatedRows.append(i); if (currentSongId==current.id) { diff --git a/models/searchmodel.cpp b/models/searchmodel.cpp index ff3a02e89..da479b901 100644 --- a/models/searchmodel.cpp +++ b/models/searchmodel.cpp @@ -179,7 +179,13 @@ QVariant SearchModel::data(const QModelIndex &index, int role) const case COL_ARTIST: return song->artist.isEmpty() ? Song::unknown() : song->artist; case COL_ALBUM: - return song->album.isEmpty() && !song->name.isEmpty() && song->isStream() ? song->name : song->album; + if (song->isStream() && song->album.isEmpty()) { + QString n=song->name(); + if (!n.isEmpty()) { + return n; + } + } + return song->album; case COL_LENGTH: return Utils::formatTime(song->time); case COL_DISC: diff --git a/mpd/cuefile.cpp b/mpd/cuefile.cpp index 659aa4252..1c24cfd71 100644 --- a/mpd/cuefile.cpp +++ b/mpd/cuefile.cpp @@ -380,9 +380,10 @@ bool CueFile::parse(const QString &fileName, const QString &dir, QList &so Song song; song.file=constCueProtocol+fileName+"?pos="+QString::number(i); song.track=entry.trackNo; - song.name=fileDir+entry.file; // HACK!!! - if (!files.contains(song.name)) { - files.insert(song.name); + QString songFile=fileDir+entry.file; + song.setName(songFile); // HACK!!! + if (!files.contains(songFile)) { + files.insert(songFile); } // the last TRACK for every FILE gets it's 'end' marker from the media file's // length diff --git a/mpd/mpdconnection.cpp b/mpd/mpdconnection.cpp index 27fc8c59f..8e3e89275 100644 --- a/mpd/mpdconnection.cpp +++ b/mpd/mpdconnection.cpp @@ -1514,7 +1514,7 @@ void MPDConnection::listStreams() QList songs=MPDParseUtils::parseSongs(response.data, MPDParseUtils::Loc_Streams); QList streams; foreach (const Song &song, songs) { - streams.append(Stream(song.file, song.name)); + streams.append(Stream(song.file, song.name())); } emit streamList(streams); diff --git a/mpd/mpdparseutils.cpp b/mpd/mpdparseutils.cpp index 623db40e0..a3bd97d3e 100644 --- a/mpd/mpdparseutils.cpp +++ b/mpd/mpdparseutils.cpp @@ -292,7 +292,7 @@ Song MPDParseUtils::parseSong(const QList &lines, Location location) } else if (line.startsWith(constGenreKey)) { song.addGenre(QString::fromUtf8(line.mid(constGenreKey.length()))); } else if (line.startsWith(constNameKey)) { - song.name = QString::fromUtf8(line.mid(constNameKey.length())); + song.setName(QString::fromUtf8(line.mid(constNameKey.length()))); } else if (line.startsWith(constPlaylistKey)) { song.file = QString::fromUtf8(line.mid(constPlaylistKey.length())); song.title=Utils::getFile(song.file); @@ -319,7 +319,7 @@ Song MPDParseUtils::parseSong(const QList &lines, Location location) song.guessTags(); song.fillEmptyFields(); } else if (Loc_Streams==location) { - song.name=getAndRemoveStreamName(song.file); + song.setName(getAndRemoveStreamName(song.file)); } else { QString origFile=song.file; @@ -362,9 +362,9 @@ Song MPDParseUtils::parseSong(const QList &lines, Location location) { QString name=getAndRemoveStreamName(song.file); if (!name.isEmpty()) { - song.name=name; + song.setName(name); } - if (song.title.isEmpty() && song.name.isEmpty()) { + if (song.title.isEmpty() && song.name().isEmpty()) { song.title=Utils::getFile(QUrl(song.file).path()); } } @@ -555,8 +555,8 @@ void MPDParseUtils::parseLibraryItems(const QByteArray &data, const QString &mpd bool canUseThisCueFile=true; foreach (const Song &s, cueSongs) { - if (!QFile::exists(mpdDir+s.name)) { - DBUG << QString(mpdDir+s.name) << "is referenced in cue file, but does not exist in MPD folder"; + if (!QFile::exists(mpdDir+s.name())) { + DBUG << QString(mpdDir+s.name()) << "is referenced in cue file, but does not exist in MPD folder"; canUseThisCueFile=false; break; } @@ -580,8 +580,8 @@ void MPDParseUtils::parseLibraryItems(const QByteArray &data, const QString &mpd quint32 usedAlbumTime=0; foreach (const Song &orig, cueSongs) { Song s=orig; - Song albumSong=origFiles[s.name]; - s.name=QString(); // CueFile has placed source file name here! + Song albumSong=origFiles[s.name()]; + s.setName(QString()); // CueFile has placed source file name here! if (s.artist.isEmpty() && !albumSong.artist.isEmpty()) { s.artist=albumSong.artist; DBUG << "Get artist from album" << albumSong.artist; @@ -623,7 +623,7 @@ void MPDParseUtils::parseLibraryItems(const QByteArray &data, const QString &mpd // all tracks have meta data - otherwise just fallback to listing file + cue foreach (const Song &orig, cueSongs) { Song s=orig; - s.name=QString(); // CueFile has placed source file name here! + s.setName(QString()); // CueFile has placed source file name here! if (s.artist.isEmpty() || s.album.isEmpty()) { break; } diff --git a/mpd/song.cpp b/mpd/song.cpp index bcadcf2fb..c17fa2b7f 100644 --- a/mpd/song.cpp +++ b/mpd/song.cpp @@ -172,7 +172,6 @@ Song & Song::operator=(const Song &s) priority = s.priority; year = s.year; genre = s.genre; - name = s.name; size = s.size; key = s.key; type = s.type; @@ -231,7 +230,7 @@ int Song::compareTo(const Song &o) const if (0!=compare) { return compare; } - compare=name.compare(o.name); + compare=name().compare(o.name()); if (0!=compare) { return compare; } @@ -248,7 +247,7 @@ int Song::compareTo(const Song &o) const bool Song::isEmpty() const { - return (artist.isEmpty() && album.isEmpty() && title.isEmpty() && name.isEmpty()) || file.isEmpty(); + return (artist.isEmpty() && album.isEmpty() && title.isEmpty() && name().isEmpty()) || file.isEmpty(); } void Song::guessTags() @@ -379,8 +378,8 @@ void Song::clear() disc = 0; year = 0; genre.clear(); - name.clear(); size = 0; + extra.clear(); type = Standard; } @@ -567,7 +566,7 @@ QString Song::basicArtist() const QString Song::describe(bool withMarkup) const { - QString albumText=album.isEmpty() ? name : displayAlbum(album, Song::albumYear(*this)); + QString albumText=album.isEmpty() ? name() : displayAlbum(album, Song::albumYear(*this)); return withMarkup ? title.isEmpty() @@ -597,7 +596,7 @@ QString Song::describe(bool withMarkup) const QDataStream & operator<<(QDataStream &stream, const Song &song) { stream << song.id << song.file << song.album << song.artist << song.albumartist << song.title - << song.genre << song.name << song.disc << song.priority << song.time << song.track << (quint16)song.year + << song.genre << song.disc << song.priority << song.time << song.track << (quint16)song.year << (quint16)song.type << (bool)song.guessed << song.size << song.extra; return stream; } @@ -608,7 +607,7 @@ QDataStream & operator>>(QDataStream &stream, Song &song) quint16 year; bool guessed; stream >> song.id >> song.file >> song.album >> song.artist >> song.albumartist >> song.title - >> song.genre >> song.name >> song.disc >> song.priority >> song.time >> song.track >> year + >> song.genre >> song.disc >> song.priority >> song.time >> song.track >> year >> type >> guessed >> song.size >> song.extra; song.type=(Song::Type)type; song.year=year; diff --git a/mpd/song.h b/mpd/song.h index f5a2ebfbd..1bff190a8 100644 --- a/mpd/song.h +++ b/mpd/song.h @@ -47,6 +47,7 @@ struct Song Performer, Comment, MusicBrainzAlbumId, + Name, // These are not real tags - but fields used elsewhere in the code... PodcastPublishedDate, @@ -72,7 +73,6 @@ struct Song QString albumartist; QString title; QString genre; - QString name; // quint32 pos; quint8 disc; mutable quint8 priority; @@ -127,6 +127,8 @@ struct Song QString extraField(int f) const { return extra[f]; } void setExtraField(int f, const QString &v); + QString name() const { return extraField(Name); } + void setName(const QString &v) { setExtraField(Name, v); } QString mbAlbumId() const { return extraField(MusicBrainzAlbumId); } void setMbAlbumId(const QString &v) { setExtraField(MusicBrainzAlbumId, v); } QString composer() const { return extraField(Composer); } diff --git a/widgets/groupedview.cpp b/widgets/groupedview.cpp index 67c73ad08..b70a80317 100644 --- a/widgets/groupedview.cpp +++ b/widgets/groupedview.cpp @@ -164,19 +164,21 @@ static bool isAlbumHeader(const QModelIndex &index) static QString streamText(const Song &song, const QString &trackTitle, bool useName=true) { if (song.album.isEmpty() && song.albumArtist().isEmpty()) { - return song.title.isEmpty() && song.name.isEmpty() + QString songName=song.name(); + return song.title.isEmpty() && songName.isEmpty() ? song.file - : !useName || song.name.isEmpty() + : !useName || songName.isEmpty() ? song.title : song.title.isEmpty() - ? song.name - : (song.title + " - " + song.name); + ? songName + : (song.title + " - " + songName); } else if (!song.title.isEmpty() && !song.artist.isEmpty()) { - return song.artist + " - " + (!useName || song.name.isEmpty() + QString name=song.name(); + return song.artist + " - " + (!useName || name.isEmpty() ? song.title : song.title.isEmpty() - ? song.name - : (song.title + " - " + song.name)); + ? name + : (song.title + " - " + name)); } else { return trackTitle; } @@ -324,8 +326,8 @@ public: if (stream) { QModelIndex next=index.sibling(index.row()+1, 0); quint16 nextKey=next.isValid() ? next.data(Cantata::Role_Key).toUInt() : Song::constNullKey; - if (nextKey!=song.key && !song.name.isEmpty()) { - title=song.name; + if (nextKey!=song.key && !song.name().isEmpty()) { + title=song.name(); track=streamText(song, trackTitle, false); } else { title=song.isCdda() ? i18n("Audio CD") : i18n("Streams");