1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-23 01:09:42 +01:00

* Prevent creating a new revision while already updating a playlist.

This commit is contained in:
Christian Muehlhaeuser 2011-05-19 02:19:55 +02:00
parent 7b154fbc12
commit 0d23934200
7 changed files with 73 additions and 38 deletions

View File

@ -32,13 +32,15 @@ DatabaseCommand_SetPlaylistRevision::DatabaseCommand_SetPlaylistRevision(
const QStringList& orderedguids,
const QList<plentry_ptr>& addedentries,
const QList<plentry_ptr>& entries )
: DatabaseCommandLoggable( s )
: DatabaseCommandLoggable( s )
, m_applied( false )
, m_newrev( newrev )
, m_oldrev( oldrev )
, m_addedentries( addedentries )
, m_entries( entries )
{
Q_ASSERT( !newrev.isEmpty() );
Q_ASSERT( !oldrev.isEmpty() );
m_localOnly = ( newrev == oldrev );
setPlaylistguid( playlistguid );
@ -70,7 +72,6 @@ DatabaseCommand_SetPlaylistRevision::postCommitHook()
// private, but we are a friend. will recall itself in its own thread:
playlist_ptr playlist = source()->collection()->playlist( m_playlistguid );
if ( playlist.isNull() )
{
qDebug() << m_playlistguid;

View File

@ -113,6 +113,7 @@ Playlist::Playlist( const source_ptr& src,
, m_lastmodified( lastmod )
, m_createdOn( createdOn )
, m_shared( shared )
, m_busy( false )
{
// qDebug() << Q_FUNC_INFO << "1";
init();
@ -134,6 +135,7 @@ Playlist::Playlist( const source_ptr& author,
, m_lastmodified( 0 )
, m_createdOn( 0 ) // will be set by db command
, m_shared( shared )
, m_busy( false )
{
qDebug() << Q_FUNC_INFO << "2";
init();
@ -266,11 +268,16 @@ Playlist::loadRevision( const QString& rev )
void
Playlist::createNewRevision( const QString& newrev, const QString& oldrev, const QList< plentry_ptr >& entries )
{
// qDebug() << "m_entries guids:";
qDebug() << Q_FUNC_INFO << newrev << oldrev << entries.count();
Q_ASSERT( !busy() );
if ( newrev != oldrev )
setBusy( true );
// calc list of newly added entries:
QList<plentry_ptr> added = newEntries( entries );
QStringList orderedguids;
foreach( plentry_ptr p, entries )
foreach( const plentry_ptr& p, entries )
orderedguids << p->guid();
// source making the change (local user in this case)
@ -283,8 +290,8 @@ Playlist::createNewRevision( const QString& newrev, const QString& oldrev, const
oldrev,
orderedguids,
added,
entries
);
entries );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
@ -316,7 +323,8 @@ Playlist::setRevision( const QString& rev,
PlaylistRevision pr = setNewRevision( rev, neworderedguids, oldorderedguids, is_newest_rev, addedmap );
if( applied )
Q_ASSERT( applied );
if ( applied )
m_currentrevision = rev;
pr.applied = applied;
@ -326,18 +334,21 @@ Playlist::setRevision( const QString& rev,
SLOT( onResultsFound( QList<Tomahawk::result_ptr> ) ), Qt::UniqueConnection );
}
setBusy( false );
emit revisionLoaded( pr );
}
PlaylistRevision
Playlist::setNewRevision( const QString& rev,
const QList<QString>& neworderedguids,
const QList<QString>& oldorderedguids,
bool is_newest_rev,
const QMap< QString, Tomahawk::plentry_ptr >& addedmap )
const QList<QString>& neworderedguids,
const QList<QString>& oldorderedguids,
bool is_newest_rev,
const QMap< QString, Tomahawk::plentry_ptr >& addedmap )
{
qDebug() << Q_FUNC_INFO << rev << is_newest_rev << m_title << addedmap.count() << neworderedguids.count() << oldorderedguids.count();
// build up correctly ordered new list of plentry_ptrs from
// existing ones, and the ones that have been added
QMap<QString, plentry_ptr> entriesmap;
@ -461,8 +472,6 @@ Playlist::addEntry( const query_ptr& query, const QString& oldrev )
void
Playlist::addEntries( const QList<query_ptr>& queries, const QString& oldrev )
{
//qDebug() << Q_FUNC_INFO;
QList<plentry_ptr> el = addEntriesInternal( queries );
QString newrev = uuid();
@ -522,3 +531,10 @@ Playlist::tracks()
return queries;
}
void
Playlist::setBusy( bool b )
{
m_busy = b;
emit changed();
}

View File

@ -143,6 +143,8 @@ public:
unsigned int lastmodified() const { return m_lastmodified; }
uint createdOn() const { return m_createdOn; }
bool busy() const { return m_busy; }
const QList< plentry_ptr >& entries() { return m_entries; }
virtual void addEntry( const Tomahawk::query_ptr& query, const QString& oldrev );
virtual void addEntries( const QList<Tomahawk::query_ptr>& queries, const QString& oldrev );
@ -248,6 +250,8 @@ private:
Playlist();
void init();
void setBusy( bool b );
source_ptr m_source;
QString m_currentrevision;
QString m_guid, m_title, m_info, m_creator;
@ -257,7 +261,7 @@ private:
QList< plentry_ptr > m_entries;
bool m_locallyChanged;
bool m_busy;
};
};

View File

@ -216,6 +216,7 @@ PlaylistModel::insert( unsigned int row, const Tomahawk::query_ptr& query )
onTracksInserted( row, ql );
}
void
PlaylistModel::trackResolved( bool )
{
@ -296,16 +297,19 @@ PlaylistModel::onRevisionLoaded( Tomahawk::PlaylistRevision revision )
loadPlaylist( m_playlist );
}
QMimeData*
PlaylistModel::mimeData( const QModelIndexList& indexes ) const
{
// Add the playlist id to the mime data so that we can detect dropping on ourselves
QMimeData* d = TrackModel::mimeData( indexes );
d->setData( "application/tomahawk.playlist.id", m_playlist->guid().toLatin1() );
if ( !m_playlist.isNull() )
d->setData( "application/tomahawk.playlist.id", m_playlist->guid().toLatin1() );
return d;
}
bool
PlaylistModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent )
{

View File

@ -41,6 +41,7 @@ WelcomePlaylistModel::WelcomePlaylistModel( QObject* parent )
void
WelcomePlaylistModel::loadFromSettings()
{
qDebug() << Q_FUNC_INFO;
if( !m_waitingForSome )
return;
@ -79,7 +80,6 @@ WelcomePlaylistModel::data( const QModelIndex& index, int role ) const
if( !index.isValid() || !hasIndex( index.row(), index.column(), index.parent() ) )
return QVariant();
playlist_ptr pl = m_recplaylists[index.row()];
switch( role )
{

View File

@ -40,12 +40,14 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
QList< dynplaylist_ptr > autoplaylists = source->collection()->autoPlaylists();
QList< dynplaylist_ptr > stations = source->collection()->stations();
if( !playlists.isEmpty() || !autoplaylists.isEmpty() || source->isLocal() ) {
if ( !playlists.isEmpty() || !autoplaylists.isEmpty() || source->isLocal() )
{
m_playlists = new CategoryItem( model(), this, SourcesModel::PlaylistsCategory, source->isLocal() );
onPlaylistsAdded( playlists );
onAutoPlaylistsAdded( autoplaylists );
}
if( !stations.isEmpty() || source->isLocal() ) {
if ( !stations.isEmpty() || source->isLocal() )
{
m_stations = new CategoryItem( model(), this, SourcesModel::StationsCategory, source->isLocal() );
onStationsAdded( stations );
}
@ -63,19 +65,19 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
connect( source.data(), SIGNAL( online() ), this, SIGNAL( updated() ) );
connect( source->collection().data(), SIGNAL( playlistsAdded( QList<Tomahawk::playlist_ptr> ) ),
SLOT( onPlaylistsAdded( QList<Tomahawk::playlist_ptr> ) ), Qt::QueuedConnection );
SLOT( onPlaylistsAdded( QList<Tomahawk::playlist_ptr> ) ), Qt::QueuedConnection );
connect( source->collection().data(), SIGNAL( playlistsDeleted( QList<Tomahawk::playlist_ptr> ) ),
SLOT( onPlaylistsDeleted( QList<Tomahawk::playlist_ptr> ) ), Qt::QueuedConnection );
SLOT( onPlaylistsDeleted( QList<Tomahawk::playlist_ptr> ) ), Qt::QueuedConnection );
connect( source->collection().data(), SIGNAL( autoPlaylistsAdded( QList< Tomahawk::dynplaylist_ptr > ) ),
SLOT( onAutoPlaylistsAdded( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
SLOT( onAutoPlaylistsAdded( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
connect( source->collection().data(), SIGNAL( autoPlaylistsDeleted( QList<Tomahawk::dynplaylist_ptr> ) ),
SLOT( onAutoPlaylistsDeleted( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
SLOT( onAutoPlaylistsDeleted( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
connect( source->collection().data(), SIGNAL( stationsAdded( QList<Tomahawk::dynplaylist_ptr> ) ),
SLOT( onStationsAdded( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
SLOT( onStationsAdded( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
connect( source->collection().data(), SIGNAL( stationsDeleted( QList<Tomahawk::dynplaylist_ptr> ) ),
SLOT( onStationsDeleted( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
SLOT( onStationsDeleted( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
}
@ -108,13 +110,13 @@ CollectionItem::peerSortValue() const
void
CollectionItem::activate()
{
if( source().isNull() ) {
ViewPage* p = ViewManager::instance()->showSuperCollection();
model()->linkSourceItemToPage( this, p );
} else {
ViewPage* p = ViewManager::instance()->show( source()->collection() );
model()->linkSourceItemToPage( this, p );
}
ViewPage* p = 0;
if ( source().isNull() )
p = ViewManager::instance()->showSuperCollection();
else
p = ViewManager::instance()->show( source()->collection() );
model()->linkSourceItemToPage( this, p );
}
@ -176,7 +178,9 @@ CollectionItem::onPlaylistsAdded( const QList< playlist_ptr >& playlists )
if( playlists.isEmpty() )
return;
if( !m_playlists ) { // add the category too
if( !m_playlists )
{
// add the category too
int cur = children().count();
beginRowsAdded( cur, cur );
m_playlists = new CategoryItem( model(), this, SourcesModel::PlaylistsCategory, source()->isLocal() );

View File

@ -82,14 +82,20 @@ Qt::ItemFlags
PlaylistItem::flags() const
{
Qt::ItemFlags flags = SourceTreeItem::flags();
if( !m_loaded )
flags &= !Qt::ItemIsEnabled;
flags |= Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
if( playlist()->author()->isLocal() )
if ( !m_loaded )
flags &= !Qt::ItemIsEnabled;
if ( playlist()->author()->isLocal() )
flags |= Qt::ItemIsEditable;
if ( playlist()->busy() )
{
flags &= !Qt::ItemIsEnabled;
flags &= !Qt::ItemIsEditable;
flags &= !Qt::ItemIsDropEnabled;
}
return flags;
}
@ -166,7 +172,7 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
if ( queries.count() && !m_playlist.isNull() && m_playlist->author()->isLocal() )
{
qDebug() << "on playlist:" << m_playlist->title() << m_playlist->guid();
qDebug() << "on playlist:" << m_playlist->title() << m_playlist->guid() << m_playlist->currentrevision();
// TODO do we need to use this in the refactor?
// QString rev = item->currentlyLoadedPlaylistRevision( playlist->guid() );