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 d64a8e68 authored by Michael Pyne's avatar Michael Pyne

Fix JuK bug where deleting playlists subclassed from Playlist (basically,

anything besides the Normal Playlist) would eventually cause a crash if that
Playlist contained the currently playing file.

I took the lead of the code that detects this in the normal playlists and
left the player going when this happens.

svn path=/trunk/kdemultimedia/juk/; revision=333128
parent aca58b12
......@@ -109,6 +109,14 @@ public:
*/
virtual void clearItems(const PlaylistItemList &items);
/**
* Accessor function to return a pointer to the currently playing file.
*
* @return 0 if no file is playing, otherwise a pointer to the PlaylistItem
* of the track that is currently playing.
*/
PlaylistItem *playingItem() const { return m_playingItem; }
/**
* All of the (media) files in the list.
*/
......
......@@ -14,11 +14,13 @@
***************************************************************************/
#include <kdebug.h>
#include <kaction.h>
#include "playlistitem.h"
#include "collectionlist.h"
#include "musicbrainzquery.h"
#include "tag.h"
#include "actioncollection.h"
static void startMusicBrainzQuery(const FileHandle &file)
{
......@@ -35,6 +37,14 @@ static void startMusicBrainzQuery(const FileHandle &file)
PlaylistItem::~PlaylistItem()
{
// Although this isn't the most efficient way to accomplish the task of
// stopping playback when deleting the item being played, it has the
// stark advantage of working reliably. I'll tell anyone who tries to
// optimize this, the timing issues can be *hard*. -- mpyne
if(playlist()->playingItem() == this)
playlist()->setPlaying(0);
m_collectionItem->removeChildItem(this);
}
......@@ -55,7 +65,7 @@ QString PlaylistItem::text(int column) const
if(!d->fileHandle.tag())
return QString::null;
int offset = static_cast<Playlist *>(listView())->columnOffset();
int offset = playlist()->columnOffset();
switch(column - offset) {
case TrackColumn:
......@@ -92,7 +102,7 @@ QString PlaylistItem::text(int column) const
void PlaylistItem::setText(int column, const QString &text)
{
int offset = static_cast<Playlist *>(listView())->columnOffset();
int offset = playlist()->columnOffset();
if(column - offset >= 0 && column + offset <= lastColumn()) {
KListViewItem::setText(column, QString::null);
return;
......@@ -104,7 +114,7 @@ void PlaylistItem::setText(int column, const QString &text)
void PlaylistItem::setSelected(bool selected)
{
static_cast<Playlist *>(listView())->markItemSelected(this, selected);
playlist()->markItemSelected(this, selected);
KListViewItem::setSelected(selected);
}
......@@ -160,7 +170,7 @@ void PlaylistItem::refreshFromDisk()
void PlaylistItem::clear()
{
static_cast<Playlist *>(listView())->clearItem(this);
playlist()->clearItem(this);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -219,7 +229,7 @@ int PlaylistItem::compare(QListViewItem *item, int column, bool ascending) const
{
// reimplemented from QListViewItem
int offset = static_cast<Playlist *>(listView())->columnOffset();
int offset = playlist()->columnOffset();
if(!item)
return 0;
......@@ -239,11 +249,10 @@ int PlaylistItem::compare(QListViewItem *item, int column, bool ascending) const
// Loop through the columns doing comparisons until something is differnt.
// If all else is the same, compare the track name.
Playlist *p = static_cast<Playlist *>(listView());
int last = p->isColumnVisible(AlbumColumn + offset) ? TrackNumberColumn : ArtistColumn;
int last = playlist()->isColumnVisible(AlbumColumn + offset) ? TrackNumberColumn : ArtistColumn;
for(int i = ArtistColumn; i <= last; i++) {
if(p->isColumnVisible(i + offset)) {
if(playlist()->isColumnVisible(i + offset)) {
c = compare(this, playlistItem, i, ascending);
if(c != 0)
return c;
......@@ -255,7 +264,7 @@ int PlaylistItem::compare(QListViewItem *item, int column, bool ascending) const
int PlaylistItem::compare(const PlaylistItem *firstItem, const PlaylistItem *secondItem, int column, bool) const
{
int offset = static_cast<Playlist *>(listView())->columnOffset();
int offset = playlist()->columnOffset();
if(column < 0 || column > lastColumn() + offset)
return 0;
......
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