Commit 894e87d6 authored by Michael Pyne's avatar Michael Pyne

Remove the 'emitChanged' hack in Playlist::createItem<>

Whichever code is creating these items is in the best spot to know
whether there will be one or many of these items and when the best time
is to permit the playlist to sync up afterwards.  This permits the
createItem functions to focus more on just that function.
parent 18bcbe92
...@@ -143,13 +143,13 @@ void CollectionList::initialize(PlaylistCollection *collection) ...@@ -143,13 +143,13 @@ void CollectionList::initialize(PlaylistCollection *collection)
// public methods // public methods
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CollectionListItem *CollectionList::createItem(const FileHandle &file, QTreeWidgetItem *, bool) CollectionListItem *CollectionList::createItem(const FileHandle &file, QTreeWidgetItem *)
{ {
// It's probably possible to optimize the line below away, but, well, right // It's probably possible to optimize the line below away, but, well, right
// now it's more important to not load duplicate items. // now it's more important to not load duplicate items.
if(m_itemsDict.contains(file.absFilePath())) if(m_itemsDict.contains(file.absFilePath()))
return 0; return nullptr;
CollectionListItem *item = new CollectionListItem(this, file); CollectionListItem *item = new CollectionListItem(this, file);
...@@ -157,7 +157,7 @@ CollectionListItem *CollectionList::createItem(const FileHandle &file, QTreeWidg ...@@ -157,7 +157,7 @@ CollectionListItem *CollectionList::createItem(const FileHandle &file, QTreeWidg
qCCritical(JUK_LOG) << "CollectionList::createItem() -- A valid tag was not created for \"" qCCritical(JUK_LOG) << "CollectionList::createItem() -- A valid tag was not created for \""
<< file.absFilePath() << "\""; << file.absFilePath() << "\"";
delete item; delete item;
return 0; return nullptr;
} }
setupItem(item); setupItem(item);
......
...@@ -113,8 +113,7 @@ public: ...@@ -113,8 +113,7 @@ public:
CollectionListItem *lookup(const QString &file) const; CollectionListItem *lookup(const QString &file) const;
virtual CollectionListItem *createItem(const FileHandle &file, virtual CollectionListItem *createItem(const FileHandle &file,
QTreeWidgetItem * = 0, QTreeWidgetItem * = nullptr);
bool = false);
void emitVisibleColumnsChanged() { emit signalVisibleColumnsChanged(); } void emitVisibleColumnsChanged() { emit signalVisibleColumnsChanged(); }
......
...@@ -47,12 +47,11 @@ HistoryPlaylist::~HistoryPlaylist() ...@@ -47,12 +47,11 @@ HistoryPlaylist::~HistoryPlaylist()
} }
HistoryPlaylistItem *HistoryPlaylist::createItem(const FileHandle &file, HistoryPlaylistItem *HistoryPlaylist::createItem(const FileHandle &file, QTreeWidgetItem *after)
QTreeWidgetItem *after, bool emitChanged)
{ {
if(!after) if(!after)
after = topLevelItem(topLevelItemCount() - 1); after = topLevelItem(topLevelItemCount() - 1);
return Playlist::createItem<HistoryPlaylistItem>(file, after, emitChanged); return Playlist::createItem<HistoryPlaylistItem>(file, after);
} }
void HistoryPlaylist::createItems(const PlaylistItemList &siblings) void HistoryPlaylist::createItems(const PlaylistItemList &siblings)
...@@ -78,6 +77,7 @@ void HistoryPlaylist::slotCreateNewItem() ...@@ -78,6 +77,7 @@ void HistoryPlaylist::slotCreateNewItem()
{ {
createItem(m_file); createItem(m_file);
m_file = FileHandle(); m_file = FileHandle();
playlistItemsChanged();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -133,8 +133,8 @@ QDataStream &operator>>(QDataStream &s, HistoryPlaylist &p) ...@@ -133,8 +133,8 @@ QDataStream &operator>>(QDataStream &s, HistoryPlaylist &p)
if(fileName.isEmpty() || !dateTime.isValid()) if(fileName.isEmpty() || !dateTime.isValid())
throw BICStreamException(); throw BICStreamException();
HistoryPlaylistItem *a = p.createItem(FileHandle(fileName), after, false); HistoryPlaylistItem *a = p.createItem(FileHandle(fileName), after);
if(a) { if(Q_LIKELY(a)) {
after = a; after = a;
after->setDateTime(dateTime); after->setDateTime(dateTime);
} }
......
...@@ -42,8 +42,7 @@ public: ...@@ -42,8 +42,7 @@ public:
HistoryPlaylist(PlaylistCollection *collection); HistoryPlaylist(PlaylistCollection *collection);
virtual ~HistoryPlaylist(); virtual ~HistoryPlaylist();
virtual HistoryPlaylistItem *createItem(const FileHandle &file, QTreeWidgetItem *after = 0, virtual HistoryPlaylistItem *createItem(const FileHandle &file, QTreeWidgetItem *after = nullptr);
bool emitChanged = true);
virtual void createItems(const PlaylistItemList &siblings); virtual void createItems(const PlaylistItemList &siblings);
virtual int columnOffset() const { return 1; } virtual int columnOffset() const { return 1; }
virtual bool readOnly() const { return true; } virtual bool readOnly() const { return true; }
......
...@@ -1202,7 +1202,7 @@ void Playlist::read(QDataStream &s) ...@@ -1202,7 +1202,7 @@ void Playlist::read(QDataStream &s)
if(file.isEmpty()) if(file.isEmpty())
throw BICStreamException(); throw BICStreamException();
after = createItem(FileHandle(file), after, false); after = createItem(FileHandle(file), after);
} }
m_blockDataChanged = false; m_blockDataChanged = false;
...@@ -1261,10 +1261,9 @@ void Playlist::addColumn(const QString &label, int) ...@@ -1261,10 +1261,9 @@ void Playlist::addColumn(const QString &label, int)
setHeaderLabels(m_columns); setHeaderLabels(m_columns);
} }
PlaylistItem *Playlist::createItem(const FileHandle &file, PlaylistItem *Playlist::createItem(const FileHandle &file, QTreeWidgetItem *after)
QTreeWidgetItem *after, bool emitChanged)
{ {
return createItem<PlaylistItem>(file, after, emitChanged); return createItem<PlaylistItem>(file, after);
} }
void Playlist::createItems(const PlaylistItemList &siblings, PlaylistItem *after) void Playlist::createItems(const PlaylistItemList &siblings, PlaylistItem *after)
...@@ -1531,14 +1530,14 @@ void Playlist::setDynamicListsFrozen(bool frozen) ...@@ -1531,14 +1530,14 @@ void Playlist::setDynamicListsFrozen(bool frozen)
CollectionListItem *Playlist::collectionListItem(const FileHandle &file) CollectionListItem *Playlist::collectionListItem(const FileHandle &file)
{ {
if(!QFile::exists(file.absFilePath())) {
qCCritical(JUK_LOG) << "File" << file.absFilePath() << "does not exist.";
return 0;
}
CollectionListItem *item = CollectionList::instance()->lookup(file.absFilePath()); CollectionListItem *item = CollectionList::instance()->lookup(file.absFilePath());
if(!item) { if(!item) {
if(!QFile::exists(file.absFilePath())) {
qCCritical(JUK_LOG) << "File" << file.absFilePath() << "does not exist.";
return nullptr;
}
item = CollectionList::instance()->createItem(file); item = CollectionList::instance()->createItem(file);
} }
...@@ -1632,10 +1631,8 @@ void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo) ...@@ -1632,10 +1631,8 @@ void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo)
setSortingEnabled(false); setSortingEnabled(false);
PlaylistItem *after = 0; PlaylistItem *after = nullptr;
m_disableColumnWidthUpdates = true; m_disableColumnWidthUpdates = true;
m_blockDataChanged = true; m_blockDataChanged = true;
while(!stream.atEnd()) { while(!stream.atEnd()) {
...@@ -1649,17 +1646,16 @@ void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo) ...@@ -1649,17 +1646,16 @@ void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo)
if(item.exists() && item.isFile() && item.isReadable() && if(item.exists() && item.isFile() && item.isReadable() &&
MediaFiles::isMediaFile(item.fileName())) MediaFiles::isMediaFile(item.fileName()))
{ {
after = createItem(FileHandle(item), after, false); after = createItem(FileHandle(item), after);
} }
} }
m_blockDataChanged = false; m_blockDataChanged = false;
m_disableColumnWidthUpdates = false;
file.close(); file.close();
playlistItemsChanged(); playlistItemsChanged();
m_disableColumnWidthUpdates = false;
} }
void Playlist::setPlaying(PlaylistItem *item, bool addToHistory) void Playlist::setPlaying(PlaylistItem *item, bool addToHistory)
...@@ -1838,8 +1834,10 @@ void Playlist::addFileHelper(FileHandleList &files, PlaylistItem **after, bool i ...@@ -1838,8 +1834,10 @@ void Playlist::addFileHelper(FileHandleList &files, PlaylistItem **after, bool i
if(visible) if(visible)
m_collection->raiseDistraction(); m_collection->raiseDistraction();
PlaylistItem *newAfter = *after;
foreach(const FileHandle &fileHandle, files) foreach(const FileHandle &fileHandle, files)
*after = createItem(fileHandle, *after, false); newAfter = createItem(fileHandle, newAfter);
*after = newAfter;
files.clear(); files.clear();
......
...@@ -168,8 +168,7 @@ public: ...@@ -168,8 +168,7 @@ public:
* both PlaylistItems and CollectionListItems. * both PlaylistItems and CollectionListItems.
*/ */
virtual PlaylistItem *createItem(const FileHandle &file, virtual PlaylistItem *createItem(const FileHandle &file,
QTreeWidgetItem *after = 0, QTreeWidgetItem *after = nullptr);
bool emitChanged = true);
/** /**
* This is implemented as a template method to allow subclasses to * This is implemented as a template method to allow subclasses to
...@@ -177,10 +176,9 @@ public: ...@@ -177,10 +176,9 @@ public:
*/ */
template <class ItemType> template <class ItemType>
ItemType *createItem(const FileHandle &file, ItemType *createItem(const FileHandle &file,
QTreeWidgetItem *after = 0, QTreeWidgetItem *after = nullptr);
bool emitChanged = true);
virtual void createItems(const PlaylistItemList &siblings, PlaylistItem *after = 0); virtual void createItems(const PlaylistItemList &siblings, PlaylistItem *after = nullptr);
/** /**
* This handles adding files of various types -- music, playlist or directory * This handles adding files of various types -- music, playlist or directory
...@@ -460,14 +458,14 @@ protected: ...@@ -460,14 +458,14 @@ protected:
void setDynamicListsFrozen(bool frozen); void setDynamicListsFrozen(bool frozen);
template <class ItemType, class SiblingType> template <class ItemType, class SiblingType>
ItemType *createItem(SiblingType *sibling, ItemType *after = 0); ItemType *createItem(SiblingType *sibling, ItemType *after = nullptr);
/** /**
* As a template this allows us to use the same code to initialize the items * As a template this allows us to use the same code to initialize the items
* in subclasses. ItemType should be a PlaylistItem subclass. * in subclasses. ItemType should be a PlaylistItem subclass.
*/ */
template <class ItemType, class SiblingType> template <class ItemType, class SiblingType>
void createItems(const QList<SiblingType *> &siblings, ItemType *after = 0); void createItems(const QList<SiblingType *> &siblings, ItemType *after = nullptr);
protected slots: protected slots:
void slotPopulateBackMenu() const; void slotPopulateBackMenu() const;
...@@ -564,8 +562,8 @@ private: ...@@ -564,8 +562,8 @@ private:
/** /**
* Used as a helper to implement template<> createItem(). This grabs the * Used as a helper to implement template<> createItem(). This grabs the
* CollectionListItem for file if it exists, otherwise it creates a new one and * CollectionListItem for file if it exists, otherwise it creates a new one and
* returns that. If 0 is returned then some kind of error occurred, such as file not * returns that. If nullptr is returned then some kind of error occurred,
* found and probably nothing should be done with the FileHandle you have. * and you should probably do nothing with the FileHandle you have.
*/ */
CollectionListItem *collectionListItem(const FileHandle &file); CollectionListItem *collectionListItem(const FileHandle &file);
...@@ -738,22 +736,16 @@ QDataStream &operator>>(QDataStream &s, Playlist &p); ...@@ -738,22 +736,16 @@ QDataStream &operator>>(QDataStream &s, Playlist &p);
// template method implementations // template method implementations
template <class ItemType> template <class ItemType>
ItemType *Playlist::createItem(const FileHandle &file, QTreeWidgetItem *after, ItemType *Playlist::createItem(const FileHandle &file, QTreeWidgetItem *after)
bool emitChanged)
{ {
CollectionListItem *item = collectionListItem(file); CollectionListItem *item = collectionListItem(file);
if(item && (!m_members.insert(file.absFilePath()) || m_allowDuplicates)) { if(item && (!m_members.insert(file.absFilePath()) || m_allowDuplicates)) {
auto i = new ItemType(item, this, after);
ItemType *i = after ? new ItemType(item, this, after) : new ItemType(item, this);
setupItem(i); setupItem(i);
if(emitChanged)
playlistItemsChanged();
return i; return i;
} }
else else
return 0; return nullptr;
} }
template <class ItemType, class SiblingType> template <class ItemType, class SiblingType>
......
...@@ -221,7 +221,8 @@ void UpcomingPlaylist::UpcomingSequenceIterator::setCurrent(PlaylistItem *curren ...@@ -221,7 +221,8 @@ void UpcomingPlaylist::UpcomingSequenceIterator::setCurrent(PlaylistItem *curren
Playlist *p = currentItem->playlist(); Playlist *p = currentItem->playlist();
if(p != m_playlist) { if(p != m_playlist) {
PlaylistItem *i = m_playlist->createItem(currentItem, (PlaylistItem *) 0); PlaylistItem *i = m_playlist->createItem(currentItem,
static_cast<PlaylistItem*>(nullptr));
m_playlist->playlistIndex().insert(i, p); m_playlist->playlistIndex().insert(i, p);
m_playlist->playlistItemsChanged(); m_playlist->playlistItemsChanged();
m_playlist->slotWeightDirty(); m_playlist->slotWeightDirty();
...@@ -273,7 +274,7 @@ QDataStream &operator>>(QDataStream &s, UpcomingPlaylist &p) ...@@ -273,7 +274,7 @@ QDataStream &operator>>(QDataStream &s, UpcomingPlaylist &p)
if(fileName.isEmpty()) if(fileName.isEmpty())
throw BICStreamException(); throw BICStreamException();
newItem = p.createItem(FileHandle(fileName), newItem, false); newItem = p.createItem(FileHandle(fileName), newItem);
} }
return s; return s;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment