1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-01-18 06:48:23 +01:00

* Protect remote playlists from being renamed.

This commit is contained in:
Christian Muehlhaeuser 2010-10-27 08:21:37 +02:00
parent c0551612a8
commit 8e110af480

View File

@ -53,10 +53,12 @@ SourcesModel::flags( const QModelIndex& index ) const
if ( index.isValid() ) if ( index.isValid() )
{ {
QModelIndex idx = index.model()->index( index.row(), 0, index.parent() ); if ( indexType( index ) == 1 )
int type = idx.data( Qt::UserRole + 1 ).toInt(); {
if ( type == 1 ) playlist_ptr playlist = indexToPlaylist( index );
if ( !playlist.isNull() && playlist->author()->isLocal() )
defaultFlags |= Qt::ItemIsEditable; defaultFlags |= Qt::ItemIsEditable;
}
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags; return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
} }
@ -173,10 +175,9 @@ SourcesModel::indexToPlaylist( const QModelIndex& index )
if ( !index.isValid() ) if ( !index.isValid() )
return res; return res;
QModelIndex idx = index.model()->index( index.row(), 0, index.parent() ); if ( indexType( index ) == 1 )
int type = idx.data( Qt::UserRole + 1 ).toInt();
if ( type == 1 )
{ {
QModelIndex idx = index.model()->index( index.row(), 0, index.parent() );
qlonglong pptr = idx.data( Qt::UserRole + 3 ).toLongLong(); qlonglong pptr = idx.data( Qt::UserRole + 3 ).toLongLong();
playlist_ptr* playlist = reinterpret_cast<playlist_ptr*>(pptr); playlist_ptr* playlist = reinterpret_cast<playlist_ptr*>(pptr);
if ( playlist ) if ( playlist )
@ -193,10 +194,10 @@ SourcesModel::indexToTreeItem( const QModelIndex& index )
if ( !index.isValid() ) if ( !index.isValid() )
return 0; return 0;
QModelIndex idx = index.model()->index( index.row(), 0, index.parent() ); int type = indexType( index );
int type = idx.data( Qt::UserRole + 1 ).toInt();
if ( type == 0 || type == 1 ) if ( type == 0 || type == 1 )
{ {
QModelIndex idx = index.model()->index( index.row(), 0, index.parent() );
qlonglong pptr = idx.data( Qt::UserRole + 2 ).toLongLong(); qlonglong pptr = idx.data( Qt::UserRole + 2 ).toLongLong();
SourceTreeItem* item = reinterpret_cast<SourceTreeItem*>(pptr); SourceTreeItem* item = reinterpret_cast<SourceTreeItem*>(pptr);
if ( item ) if ( item )
@ -215,15 +216,12 @@ SourcesModel::setData( const QModelIndex& index, const QVariant& value, int role
if ( !index.isValid() ) if ( !index.isValid() )
return false; return false;
QModelIndex idx = index.model()->index( index.row(), 0, index.parent() ); if ( indexType( index ) == 1 )
int type = idx.data( Qt::UserRole + 1 ).toInt();
if ( type == 1 )
{ {
qlonglong pptr = idx.data( Qt::UserRole + 3 ).toLongLong(); playlist_ptr playlist = indexToPlaylist( index );
playlist_ptr* playlist = reinterpret_cast<playlist_ptr*>(pptr); if ( !playlist.isNull() )
if ( playlist )
{ {
playlist->data()->rename( value.toString() ); playlist->rename( value.toString() );
QStandardItemModel::setData( index, value, Qt::DisplayRole ); QStandardItemModel::setData( index, value, Qt::DisplayRole );
} }