Reload playlist items in the background after editing

This commit is contained in:
David Sansome 2010-08-08 12:36:07 +00:00
parent 49da0eee27
commit d81db5f255
4 changed files with 27 additions and 3 deletions

View File

@ -253,12 +253,24 @@ void Playlist::SongSaveComplete() {
watcher->deleteLater();
const QPersistentModelIndex& index = watcher->index();
if (index.isValid()) {
item_at(index.row())->Reload();
emit dataChanged(index, index);
QFuture<void> future = item_at(index.row())->BackgroundReload();
ModelFutureWatcher<void>* watcher = new ModelFutureWatcher<void>(index, this);
watcher->setFuture(future);
connect(watcher, SIGNAL(finished()), SLOT(ItemReloadComplete()));
emit EditingFinished(index);
}
}
void Playlist::ItemReloadComplete() {
ModelFutureWatcher<void>* watcher = static_cast<ModelFutureWatcher<void>*>(sender());
watcher->deleteLater();
const QPersistentModelIndex& index = watcher->index();
if (index.isValid()) {
emit dataChanged(index, index);
}
}
int Playlist::current_index() const {
return current_item_index_.isValid() ? current_item_index_.row() : -1;
}

View File

@ -203,6 +203,7 @@ class Playlist : public QAbstractListModel {
void TracksEnqueued(const QModelIndex&, int begin, int end);
void QueueLayoutChanged();
void SongSaveComplete();
void ItemReloadComplete();
void ItemsLoaded();
private:

View File

@ -20,6 +20,7 @@
#include "radio/magnatuneplaylistitem.h"
#include "radio/radioplaylistitem.h"
#include <QtConcurrentRun>
#include <QtDebug>
PlaylistItem::SpecialLoadResult::SpecialLoadResult(
@ -62,4 +63,12 @@ void PlaylistItem::ClearTemporaryMetadata() {
temp_metadata_ = Song();
}
static void ReloadPlaylistItem(boost::shared_ptr<PlaylistItem> item) {
item->Reload();
}
QFuture<void> PlaylistItem::BackgroundReload() {
return QtConcurrent::run(ReloadPlaylistItem, shared_from_this());
}

View File

@ -20,13 +20,14 @@
#include <QStandardItem>
#include <QUrl>
#include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp>
#include "core/song.h"
class SqlRow;
class PlaylistItem {
class PlaylistItem : public boost::enable_shared_from_this<PlaylistItem> {
public:
PlaylistItem(const QString& type) : type_(type) {}
virtual ~PlaylistItem() {}
@ -92,6 +93,7 @@ class PlaylistItem {
virtual bool InitFromQuery(const SqlRow& query) = 0;
void BindToQuery(QSqlQuery* query) const;
virtual void Reload() {}
QFuture<void> BackgroundReload();
virtual Song Metadata() const = 0;
virtual QUrl Url() const = 0;