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)
// 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
// now it's more important to not load duplicate items.
if(m_itemsDict.contains(file.absFilePath()))
return 0;
return nullptr;
CollectionListItem *item = new CollectionListItem(this, file);
......@@ -157,7 +157,7 @@ CollectionListItem *CollectionList::createItem(const FileHandle &file, QTreeWidg
qCCritical(JUK_LOG) << "CollectionList::createItem() -- A valid tag was not created for \""
<< file.absFilePath() << "\"";
delete item;
return 0;
return nullptr;
}
setupItem(item);
......
......@@ -113,8 +113,7 @@ public:
CollectionListItem *lookup(const QString &file) const;
virtual CollectionListItem *createItem(const FileHandle &file,
QTreeWidgetItem * = 0,
bool = false);
QTreeWidgetItem * = nullptr);
void emitVisibleColumnsChanged() { emit signalVisibleColumnsChanged(); }
......
......@@ -47,12 +47,11 @@ HistoryPlaylist::~HistoryPlaylist()
}
HistoryPlaylistItem *HistoryPlaylist::createItem(const FileHandle &file,
QTreeWidgetItem *after, bool emitChanged)
HistoryPlaylistItem *HistoryPlaylist::createItem(const FileHandle &file, QTreeWidgetItem *after)
{
if(!after)
after = topLevelItem(topLevelItemCount() - 1);
return Playlist::createItem<HistoryPlaylistItem>(file, after, emitChanged);
return Playlist::createItem<HistoryPlaylistItem>(file, after);
}
void HistoryPlaylist::createItems(const PlaylistItemList &siblings)
......@@ -78,6 +77,7 @@ void HistoryPlaylist::slotCreateNewItem()
{
createItem(m_file);
m_file = FileHandle();
playlistItemsChanged();
}
////////////////////////////////////////////////////////////////////////////////
......@@ -133,8 +133,8 @@ QDataStream &operator>>(QDataStream &s, HistoryPlaylist &p)
if(fileName.isEmpty() || !dateTime.isValid())
throw BICStreamException();
HistoryPlaylistItem *a = p.createItem(FileHandle(fileName), after, false);
if(a) {
HistoryPlaylistItem *a = p.createItem(FileHandle(fileName), after);
if(Q_LIKELY(a)) {
after = a;
after->setDateTime(dateTime);
}
......
......@@ -42,8 +42,7 @@ public:
HistoryPlaylist(PlaylistCollection *collection);
virtual ~HistoryPlaylist();
virtual HistoryPlaylistItem *createItem(const FileHandle &file, QTreeWidgetItem *after = 0,
bool emitChanged = true);
virtual HistoryPlaylistItem *createItem(const FileHandle &file, QTreeWidgetItem *after = nullptr);
virtual void createItems(const PlaylistItemList &siblings);
virtual int columnOffset() const { return 1; }
virtual bool readOnly() const { return true; }
......
......@@ -1202,7 +1202,7 @@ void Playlist::read(QDataStream &s)
if(file.isEmpty())
throw BICStreamException();
after = createItem(FileHandle(file), after, false);
after = createItem(FileHandle(file), after);
}
m_blockDataChanged = false;
......@@ -1261,10 +1261,9 @@ void Playlist::addColumn(const QString &label, int)
setHeaderLabels(m_columns);
}
PlaylistItem *Playlist::createItem(const FileHandle &file,
QTreeWidgetItem *after, bool emitChanged)
PlaylistItem *Playlist::createItem(const FileHandle &file, QTreeWidgetItem *after)
{
return createItem<PlaylistItem>(file, after, emitChanged);
return createItem<PlaylistItem>(file, after);
}
void Playlist::createItems(const PlaylistItemList &siblings, PlaylistItem *after)
......@@ -1531,14 +1530,14 @@ void Playlist::setDynamicListsFrozen(bool frozen)
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());
if(!item) {
if(!QFile::exists(file.absFilePath())) {
qCCritical(JUK_LOG) << "File" << file.absFilePath() << "does not exist.";
return nullptr;
}
item = CollectionList::instance()->createItem(file);
}
......@@ -1632,10 +1631,8 @@ void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo)
setSortingEnabled(false);
PlaylistItem *after = 0;
PlaylistItem *after = nullptr;
m_disableColumnWidthUpdates = true;
m_blockDataChanged = true;
while(!stream.atEnd()) {
......@@ -1649,17 +1646,16 @@ void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo)
if(item.exists() && item.isFile() && item.isReadable() &&
MediaFiles::isMediaFile(item.fileName()))
{
after = createItem(FileHandle(item), after, false);
after = createItem(FileHandle(item), after);
}
}
m_blockDataChanged = false;
m_disableColumnWidthUpdates = false;
file.close();
playlistItemsChanged();
m_disableColumnWidthUpdates = false;
}
void Playlist::setPlaying(PlaylistItem *item, bool addToHistory)
......@@ -1838,8 +1834,10 @@ void Playlist::addFileHelper(FileHandleList &files, PlaylistItem **after, bool i
if(visible)
m_collection->raiseDistraction();
PlaylistItem *newAfter = *after;
foreach(const FileHandle &fileHandle, files)
*after = createItem(fileHandle, *after, false);
newAfter = createItem(fileHandle, newAfter);
*after = newAfter;
files.clear();
......
......@@ -168,8 +168,7 @@ public:
* both PlaylistItems and CollectionListItems.
*/
virtual PlaylistItem *createItem(const FileHandle &file,
QTreeWidgetItem *after = 0,
bool emitChanged = true);
QTreeWidgetItem *after = nullptr);
/**
* This is implemented as a template method to allow subclasses to
......@@ -177,10 +176,9 @@ public:
*/
template <class ItemType>
ItemType *createItem(const FileHandle &file,
QTreeWidgetItem *after = 0,
bool emitChanged = true);
QTreeWidgetItem *after = nullptr);
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
......@@ -460,14 +458,14 @@ protected:
void setDynamicListsFrozen(bool frozen);
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
* in subclasses. ItemType should be a PlaylistItem subclass.
*/
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:
void slotPopulateBackMenu() const;
......@@ -564,8 +562,8 @@ private:
/**
* Used as a helper to implement template<> createItem(). This grabs the
* 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
* found and probably nothing should be done with the FileHandle you have.
* returns that. If nullptr is returned then some kind of error occurred,
* and you should probably do nothing with the FileHandle you have.
*/
CollectionListItem *collectionListItem(const FileHandle &file);
......@@ -738,22 +736,16 @@ QDataStream &operator>>(QDataStream &s, Playlist &p);
// template method implementations
template <class ItemType>
ItemType *Playlist::createItem(const FileHandle &file, QTreeWidgetItem *after,
bool emitChanged)
ItemType *Playlist::createItem(const FileHandle &file, QTreeWidgetItem *after)
{
CollectionListItem *item = collectionListItem(file);
if(item && (!m_members.insert(file.absFilePath()) || m_allowDuplicates)) {
ItemType *i = after ? new ItemType(item, this, after) : new ItemType(item, this);
auto i = new ItemType(item, this, after);
setupItem(i);
if(emitChanged)
playlistItemsChanged();
return i;
}
else
return 0;
return nullptr;
}
template <class ItemType, class SiblingType>
......
......@@ -221,7 +221,8 @@ void UpcomingPlaylist::UpcomingSequenceIterator::setCurrent(PlaylistItem *curren
Playlist *p = currentItem->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->playlistItemsChanged();
m_playlist->slotWeightDirty();
......@@ -273,7 +274,7 @@ QDataStream &operator>>(QDataStream &s, UpcomingPlaylist &p)
if(fileName.isEmpty())
throw BICStreamException();
newItem = p.createItem(FileHandle(fileName), newItem, false);
newItem = p.createItem(FileHandle(fileName), newItem);
}
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