Fix crash when deleting streams.
This commit is contained in:
@@ -14,8 +14,9 @@
|
||||
9. When playing, centre on current track.
|
||||
10. Use correct value for transcoder parameter.
|
||||
11. When saving cache file, if a track is filed under 'single artists' then
|
||||
store its acutal album name in the cache file. Then when cache is loaded,
|
||||
store its actual album name in the cache file. Then when cache is loaded,
|
||||
we have the correct album to use for the tag editor.
|
||||
12. Fix crash when deleting streams.
|
||||
|
||||
0.4.0
|
||||
-----
|
||||
|
||||
@@ -330,23 +330,36 @@ void StreamsPage::removeItems()
|
||||
#endif
|
||||
|
||||
// Ensure that if we have a category selected, we dont also try to remove one of its children
|
||||
QSet<StreamsModel::Item *> selectedCategories;
|
||||
QSet<StreamsModel::CategoryItem *> removeCategories;
|
||||
QList<StreamsModel::StreamItem *> removeStreams;
|
||||
QModelIndexList remove;
|
||||
//..obtain catagories to remove...
|
||||
foreach(QModelIndex index, selected) {
|
||||
QModelIndex idx=proxy.mapToSource(index);
|
||||
StreamsModel::Item *item=static_cast<StreamsModel::Item *>(idx.internalPointer());
|
||||
|
||||
if (item->isCategory()) {
|
||||
selectedCategories.insert(item);
|
||||
remove.append(idx);
|
||||
} else if (!selectedCategories.contains(static_cast<StreamsModel::StreamItem*>(item)->parent)) {
|
||||
remove.append(idx);
|
||||
removeCategories.insert(static_cast<StreamsModel::CategoryItem *>(item));
|
||||
}
|
||||
}
|
||||
// Obtain streams in non-selected categories...
|
||||
foreach(QModelIndex index, selected) {
|
||||
QModelIndex idx=proxy.mapToSource(index);
|
||||
StreamsModel::Item *item=static_cast<StreamsModel::Item *>(idx.internalPointer());
|
||||
|
||||
if (!item->isCategory()) {
|
||||
removeStreams.append(static_cast<StreamsModel::StreamItem *>(item));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (const QModelIndex &idx, remove) {
|
||||
model.remove(idx);
|
||||
foreach (StreamsModel::CategoryItem *i, removeCategories) {
|
||||
model.removeCategory(i);
|
||||
}
|
||||
|
||||
foreach (StreamsModel::StreamItem *i, removeStreams) {
|
||||
model.removeStream(i);
|
||||
}
|
||||
model.updateGenres();
|
||||
exportAction->setEnabled(model.rowCount()>0);
|
||||
}
|
||||
|
||||
|
||||
@@ -416,7 +416,7 @@ void StreamsModel::remove(const QModelIndex &index)
|
||||
if (row<items.count()) {
|
||||
CategoryItem *old=items.at(row);
|
||||
beginRemoveRows(QModelIndex(), row, row);
|
||||
items.removeAt(index.row());
|
||||
items.removeAt(row);
|
||||
delete old;
|
||||
endRemoveRows();
|
||||
modified=true;
|
||||
@@ -436,7 +436,7 @@ void StreamsModel::remove(const QModelIndex &index)
|
||||
endRemoveRows();
|
||||
} else*/ {
|
||||
beginRemoveRows(createIndex(items.indexOf(cat), 0, cat), row, row);
|
||||
cat->streams.removeAt(index.row());
|
||||
cat->streams.removeAt(row);
|
||||
cat->itemMap.remove(old->url.toString());
|
||||
endRemoveRows();
|
||||
delete old;
|
||||
@@ -449,6 +449,38 @@ void StreamsModel::remove(const QModelIndex &index)
|
||||
save();
|
||||
}
|
||||
|
||||
void StreamsModel::removeCategory(CategoryItem *cat)
|
||||
{
|
||||
int row=items.indexOf(cat);
|
||||
if (-1==row) {
|
||||
return;
|
||||
}
|
||||
beginRemoveRows(QModelIndex(), row, row);
|
||||
items.removeAt(row);
|
||||
delete cat;
|
||||
endRemoveRows();
|
||||
modified=true;
|
||||
}
|
||||
|
||||
void StreamsModel::removeStream(StreamItem *stream)
|
||||
{
|
||||
int parentRow=items.indexOf(stream->parent);
|
||||
if (-1==parentRow) {
|
||||
return;
|
||||
}
|
||||
CategoryItem *cat=stream->parent;
|
||||
int row=cat->streams.indexOf(stream);
|
||||
if (-1==row) {
|
||||
return;
|
||||
}
|
||||
beginRemoveRows(createIndex(parentRow, 0, cat), row, row);
|
||||
cat->streams.removeAt(row);
|
||||
cat->itemMap.remove(stream->url.toString());
|
||||
endRemoveRows();
|
||||
delete stream;
|
||||
modified=true;
|
||||
}
|
||||
|
||||
StreamsModel::CategoryItem * StreamsModel::getCategory(const QString &name, bool create, bool signal)
|
||||
{
|
||||
foreach (CategoryItem *c, items) {
|
||||
|
||||
@@ -87,6 +87,8 @@ public:
|
||||
void editCategory(const QModelIndex &index, const QString &name, const QString &icon);
|
||||
void editStream(const QModelIndex &index, const QString &oldCat, const QString &newCat, const QString &name, const QString &genre, const QString &icon, const QString &url);
|
||||
void remove(const QModelIndex &index);
|
||||
void removeCategory(CategoryItem *cat);
|
||||
void removeStream(StreamItem *stream);
|
||||
QString name(const QString &cat, const QString &url) { return name(getCategory(cat), url); }
|
||||
bool entryExists(const QString &cat, const QString &name, const QUrl &url=QUrl()) { return entryExists(getCategory(cat), name, url); }
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
@@ -94,6 +96,7 @@ public:
|
||||
QStringList filenames(const QModelIndexList &indexes) const;
|
||||
QMimeData * mimeData(const QModelIndexList &indexes) const;
|
||||
void mark(const QList<int> &rows, bool f);
|
||||
void updateGenres();
|
||||
|
||||
const QSet<QString> & urlHandlers() const {
|
||||
return handlers;
|
||||
@@ -103,7 +106,6 @@ Q_SIGNALS:
|
||||
void updateGenres(const QSet<QString> &genres);
|
||||
|
||||
private:
|
||||
void updateGenres();
|
||||
void clearCategories();
|
||||
bool load(const QString &filename, bool isInternal);
|
||||
CategoryItem * getCategory(const QString &name, bool create=false, bool signal=false);
|
||||
|
||||
Reference in New Issue
Block a user