If Cantata detects that an album, or artist, has new songs after updating MPD's DB, then the artist and album are drawn with bold text.

This commit is contained in:
craig.p.drummond
2014-03-26 19:37:26 +00:00
parent 0f0b371a59
commit ca8c6020a2
6 changed files with 54 additions and 10 deletions

View File

@@ -71,6 +71,8 @@
TagLib crashes.
45. Add -DUSE_OLD_DBUS_TYPEDEF=ON to CMake options. This can be used to force
usage of OLD dbus XML files.
46. If Cantata detects that an album, or artist, has new songs after updating
MPD's DB, then the artist and album are drawn with bold text.
1.3.3
-----

View File

@@ -219,6 +219,13 @@ QVariant AlbumsModel::data(const QModelIndex &index, int role) const
Plurals::tracksWithDuration(al->trackCount(), Utils::formatTime(al->totalTime(), true)));
case Qt::DisplayRole:
return al->album;
case Qt::FontRole:
if (dbUpdateVer && al->dbUpdateVer==dbUpdateVer) {
QFont f=ActionModel::data(index, role).value<QFont>();
f.setBold(true);
return f;
}
break;
case ItemView::Role_MainText:
if (Sort_ArtistYearAlbum==sortAlbums) {
return al->albumDisplay();
@@ -343,6 +350,7 @@ void AlbumsModel::update(const MusicLibraryItemRoot *root)
return;
}
dbUpdateVer=root->dbUpdateVersion();
bool changesMade=false;
bool resettingModel=items.isEmpty() || 0==root->childCount();
if (resettingModel) {
@@ -387,6 +395,13 @@ void AlbumsModel::update(const MusicLibraryItemRoot *root)
(*it)->genres=albumItem->genres();
(*it)->updated=true;
found=true;
if ((*it)->dbUpdateVer!=albumItem->dbUpdateVersion()) {
(*it)->dbUpdateVer=albumItem->dbUpdateVersion();
if (!resettingModel) {
QModelIndex albumIndex=index(items.indexOf(*it), 0, QModelIndex());
emit dataChanged(albumIndex, albumIndex);
}
}
break;
}
}
@@ -398,6 +413,7 @@ void AlbumsModel::update(const MusicLibraryItemRoot *root)
a->genres=albumItem->genres();
a->updated=true;
a->type=albumItem->songType();
a->dbUpdateVer=albumItem->dbUpdateVersion();
if (!resettingModel) {
beginInsertRows(QModelIndex(), items.count(), items.count());
}

View File

@@ -98,6 +98,7 @@ public:
quint32 numTracks;
quint32 time;
Song coverSong;
quint32 dbUpdateVer;
};
static AlbumsModel * self();
@@ -132,6 +133,7 @@ private:
bool enabled;
// bool coversRequested;
mutable QList<AlbumItem *> items;
quint32 dbUpdateVer;
};
#endif

View File

@@ -75,7 +75,7 @@ protected:
class MusicLibraryItemContainer : public MusicLibraryItem
{
public:
MusicLibraryItemContainer(const QString &data, MusicLibraryItemContainer *parent) : MusicLibraryItem(data, parent), m_rowsSet(false) { }
MusicLibraryItemContainer(const QString &data, MusicLibraryItemContainer *parent) : MusicLibraryItem(data, parent), dbUpdateVer(0), m_rowsSet(false) { }
virtual ~MusicLibraryItemContainer() { clear(); }
virtual void append(MusicLibraryItem *i) { m_childItems.append(i); }
@@ -92,8 +92,11 @@ public:
void resetRows();
void clear();
int indexOf(MusicLibraryItem *c) const { return m_childItems.indexOf(c); }
void setDbUpdateVersion(quint32 v) { dbUpdateVer=v; }
quint32 dbUpdateVersion() const { return dbUpdateVer; }
protected:
quint32 dbUpdateVer;
friend class MusicLibraryItem;
QList<MusicLibraryItem *> m_childItems;
QSet<QString> m_genres;

View File

@@ -780,6 +780,10 @@ bool MusicLibraryItemRoot::update(const QSet<Song> &songs)
QSet<Song> added=updateSongs-currentSongs;
bool updatedSongs=added.count()||removed.count();
if (updatedSongs) {
dbUpdateVer++;
}
foreach (const Song &s, removed) {
removeSongFromList(s);
}
@@ -918,7 +922,7 @@ void MusicLibraryItemRoot::addSongToList(const Song &s)
}
MusicLibraryItemAlbum *albumItem = artistItem->album(s, false);
if (!albumItem) {
m_model->beginInsertRows(m_model->createIndex(childItems().indexOf(artistItem), 0, artistItem), artistItem->childCount(), artistItem->childCount());
m_model->beginInsertRows(m_model->createIndex(artistItem->row(), 0, artistItem), artistItem->childCount(), artistItem->childCount());
albumItem = artistItem->createAlbum(s);
m_model->endInsertRows();
}
@@ -930,12 +934,18 @@ void MusicLibraryItemRoot::addSongToList(const Song &s)
}
}
m_model->beginInsertRows(m_model->createIndex(artistItem->childItems().indexOf(albumItem), 0, albumItem), albumItem->childCount(), albumItem->childCount());
m_model->beginInsertRows(m_model->createIndex(albumItem->row(), 0, albumItem), albumItem->childCount(), albumItem->childCount());
MusicLibraryItemSong *songItem = new MusicLibraryItemSong(s, albumItem);
albumItem->append(songItem);
m_model->endInsertRows();
if (year!=albumItem->year()) {
QModelIndex idx=m_model->createIndex(artistItem->childItems().indexOf(albumItem), 0, albumItem);
if (artistItem->dbUpdateVersion()!=dbUpdateVer) {
artistItem->setDbUpdateVersion(dbUpdateVer);
QModelIndex idx=m_model->createIndex(artistItem->row(), 0, artistItem);
emit m_model->dataChanged(idx, idx);
}
if (albumItem->dbUpdateVersion()!=dbUpdateVer || year!=albumItem->year()) {
albumItem->setDbUpdateVersion(dbUpdateVer);
QModelIndex idx=m_model->createIndex(albumItem->row(), 0, albumItem);
emit m_model->dataChanged(idx, idx);
}
}
@@ -969,7 +979,7 @@ void MusicLibraryItemRoot::removeSongFromList(const Song &s)
if (1==artistItem->childCount() && 1==albumItem->childCount()) {
// 1 album with 1 song - so remove whole artist
int row=m_childItems.indexOf(artistItem);
int row=artistItem->row();
m_model->beginRemoveRows(index(), row, row);
remove(artistItem);
m_model->endRemoveRows();
@@ -978,20 +988,20 @@ void MusicLibraryItemRoot::removeSongFromList(const Song &s)
if (1==albumItem->childCount()) {
// multiple albums, but this album only has 1 song - remove album
int row=artistItem->childItems().indexOf(albumItem);
m_model->beginRemoveRows(m_model->createIndex(childItems().indexOf(artistItem), 0, artistItem), row, row);
int row=albumItem->row();
m_model->beginRemoveRows(m_model->createIndex(artistItem->row(), 0, artistItem), row, row);
artistItem->remove(albumItem);
m_model->endRemoveRows();
return;
}
// Just remove particular song
m_model->beginRemoveRows(m_model->createIndex(artistItem->childItems().indexOf(albumItem), 0, albumItem), songRow, songRow);
m_model->beginRemoveRows(m_model->createIndex(albumItem->row(), 0, albumItem), songRow, songRow);
quint32 year=albumItem->year();
albumItem->remove(songRow);
m_model->endRemoveRows();
if (year!=albumItem->year()) {
QModelIndex idx=m_model->createIndex(artistItem->childItems().indexOf(albumItem), 0, albumItem);
QModelIndex idx=m_model->createIndex(albumItem->row(), 0, albumItem);
emit m_model->dataChanged(idx, idx);
}
}

View File

@@ -210,6 +210,17 @@ QVariant MusicLibraryModel::data(const QModelIndex &index, int role) const
if (checkable && Qt::CheckStateRole==role) {
return static_cast<MusicLibraryItem *>(index.internalPointer())->checkState();
}
if (!checkable && Qt::FontRole==role) {
MusicLibraryItem *item = static_cast<MusicLibraryItem *>(index.internalPointer());
if (rootItem->dbUpdateVersion() &&
(MusicLibraryItem::Type_Album==item->itemType() || MusicLibraryItem::Type_Artist==item->itemType()) &&
static_cast<MusicLibraryItemContainer *>(item)->dbUpdateVersion()==rootItem->dbUpdateVersion()) {
QFont f=MusicModel::data(index, role).value<QFont>();
f.setBold(true);
return f;
}
}
return MusicModel::data(index, role);
}