Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 2e865464 authored by Michael Pyne's avatar Michael Pyne

Last crasher bug I fixed was due to not using Playlist::clearItem() to remove...

Last crasher bug I fixed was due to not using Playlist::clearItem() to remove a PlaylistItem.  I think it
should always be possible to call delete on a PlaylistItem pointer and the Right Thing happens, so do a
bit of refactoring to ensure that what happens in clearItem() is performed from the PlaylistItem dtor instead
of running the PlaylistItem dtor from clearItem.

svn path=/trunk/KDE/kdemultimedia/juk/; revision=926748
parent 6cb4264c
......@@ -128,9 +128,9 @@ PlaylistItem *CollectionList::createItem(const FileHandle &file, Q3ListViewItem
void CollectionList::clearItems(const PlaylistItemList &items)
{
for(PlaylistItemList::ConstIterator it = items.constBegin(); it != items.constEnd(); ++it) {
Cache::instance()->remove((*it)->file());
clearItem(*it, false);
foreach(PlaylistItem *item, items) {
Cache::instance()->remove(item->file());
delete item;
}
dataChanged();
......@@ -178,7 +178,7 @@ void CollectionList::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >
if(item->file().fileInfo().exists())
item->repaint();
else
clearItem(item);
delete item;
}
}
......@@ -187,9 +187,7 @@ void CollectionList::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >
void CollectionList::slotDeleteItem(const KFileItem &item)
{
CollectionListItem *listItem = lookup(item.url().path());
if(listItem)
clearItem(listItem);
delete lookup(item.url().path());
}
////////////////////////////////////////////////////////////////////////////////
......@@ -232,7 +230,7 @@ void CollectionList::slotCheckCache()
void CollectionList::slotRemoveItem(const QString &file)
{
clearItem(m_itemsDict[file]);
delete m_itemsDict[file];
}
void CollectionList::slotRefreshItem(const QString &file)
......@@ -492,10 +490,8 @@ CollectionListItem::~CollectionListItem()
{
m_shuttingDown = true;
foreach(PlaylistItem *item, m_children) {
if(item->playlist())
item->playlist()->clearItem(item);
}
foreach(PlaylistItem *item, m_children)
delete item;
CollectionList *l = CollectionList::instance();
if(l) {
......
......@@ -579,29 +579,28 @@ void Playlist::saveAs()
}
}
void Playlist::clearItem(PlaylistItem *item, bool emitChanged)
void Playlist::updateDeletedItem(PlaylistItem *item)
{
emit signalAboutToRemove(item);
m_members.remove(item->file().absFilePath());
m_search.clearItem(item);
m_history.removeAll(item);
m_addTime.removeAll(item);
m_subtractTime.removeAll(item);
}
void Playlist::clearItem(PlaylistItem *item, bool emitChanged)
{
// Automatically updates internal structs via updateDeletedItem
delete item;
if(emitChanged)
dataChanged();
dataChanged();
}
void Playlist::clearItems(const PlaylistItemList &items)
{
m_blockDataChanged = true;
for(PlaylistItemList::ConstIterator it = items.constBegin(); it != items.constEnd(); ++it)
clearItem(*it, false);
m_blockDataChanged = false;
foreach(PlaylistItem *item, items)
delete item;
dataChanged();
}
......@@ -985,7 +984,7 @@ void Playlist::removeFromDisk(const PlaylistItemList &items)
if((!shouldDelete && KIO::NetAccess::synchronousRun(KIO::trash(removePath), this)) ||
(shouldDelete && QFile::remove(removePath)))
{
CollectionList::instance()->clearItem((*it)->collectionItem());
delete (*it)->collectionItem();
}
else
errorFiles.append((*it)->file().absFilePath());
......
......@@ -551,6 +551,13 @@ private:
void updatePlaying() const;
/**
* This function should be called when item is deleted to ensure that any
* internal bookkeeping is performed. It is automatically called by
* PlaylistItem::~PlaylistItem and by clearItem() and clearItems().
*/
void updateDeletedItem(PlaylistItem *item);
/**
* Used as a helper to implement template<> createItem(). This grabs the
* CollectionListItem for file if it exists, otherwise it creates a new one and
......@@ -645,6 +652,8 @@ private slots:
void slotPlayCurrent();
private:
friend class PlaylistItem;
PlaylistCollection *m_collection;
StringHash m_members;
......
......@@ -60,6 +60,9 @@ PlaylistItem::~PlaylistItem()
playlist()->setPlaying(0);
}
playlist()->updateDeletedItem(this);
emit playlist()->signalAboutToRemove(this);
if(m_watched)
Pointer::clear(this);
}
......
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