mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-02-26 21:03:31 +01:00
Undo code sharing. Since the source tree stores pointers to raw shared pointers, we can't cast them since that creates a new copy of the sharedpointer. BAH!
also fix some signal/slot connections
This commit is contained in:
parent
1a2c292124
commit
e744e57027
@ -28,7 +28,7 @@ signals:
|
||||
// used if loading an ondemand playlist
|
||||
void done( QString,
|
||||
bool,
|
||||
const QString,
|
||||
QString,
|
||||
QList< Tomahawk::dyncontrol_ptr>,
|
||||
bool );
|
||||
// used when loading a static playlist
|
||||
@ -38,7 +38,7 @@ signals:
|
||||
QString,
|
||||
QList< Tomahawk::dyncontrol_ptr>,
|
||||
bool,
|
||||
const QMap< QString, Tomahawk::plentry_ptr >,
|
||||
QMap< QString, Tomahawk::plentry_ptr >,
|
||||
bool );
|
||||
|
||||
private:
|
||||
|
@ -188,30 +188,30 @@ DynamicPlaylist::loadRevision( const QString& rev )
|
||||
if( m_generator->mode() == OnDemand ) {
|
||||
connect( cmd, SIGNAL( done( QString,
|
||||
bool,
|
||||
const QString,
|
||||
QList< dyncontrol_ptr>,
|
||||
QString,
|
||||
QList< Tomahawk::dyncontrol_ptr>,
|
||||
bool ) ),
|
||||
SLOT( setRevision( QString,
|
||||
bool,
|
||||
const QString,
|
||||
QList< dyncontrol_ptr>,
|
||||
QString,
|
||||
QList< Tomahawk::dyncontrol_ptr>,
|
||||
bool) ) );
|
||||
} else if( m_generator->mode() == Static ) {
|
||||
connect( cmd, SIGNAL( done( QString,
|
||||
QList< QString >,
|
||||
QList< QString >,
|
||||
QString,
|
||||
QList< dyncontrol_ptr>,
|
||||
QList< Tomahawk::dyncontrol_ptr>,
|
||||
bool,
|
||||
const QMap< QString, Tomahawk::plentry_ptr >,
|
||||
QMap< QString, Tomahawk::plentry_ptr >,
|
||||
bool ) ),
|
||||
SLOT( setRevision( QString,
|
||||
QList< QString >,
|
||||
QList< QString >,
|
||||
QString,
|
||||
QList< dyncontrol_ptr>,
|
||||
QList< Tomahawk::dyncontrol_ptr>,
|
||||
bool,
|
||||
const QMap< QString, Tomahawk::plentry_ptr >,
|
||||
QMap< QString, Tomahawk::plentry_ptr >,
|
||||
bool ) ) );
|
||||
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ public slots:
|
||||
const QList<QString>& neworderedguids,
|
||||
const QList<QString>& oldorderedguids,
|
||||
const QString& type,
|
||||
const QList< dyncontrol_ptr>& controls,
|
||||
const QList< Tomahawk::dyncontrol_ptr>& controls,
|
||||
bool is_newest_rev,
|
||||
const QMap< QString, Tomahawk::plentry_ptr >& addedmap,
|
||||
bool applied );
|
||||
@ -125,7 +125,7 @@ public slots:
|
||||
void setRevision( const QString& rev,
|
||||
bool is_newest_rev,
|
||||
const QString& type,
|
||||
const QList< dyncontrol_ptr>& controls,
|
||||
const QList< Tomahawk::dyncontrol_ptr>& controls,
|
||||
bool applied );
|
||||
private:
|
||||
// called from loadAllPlaylists DB cmd:
|
||||
|
@ -266,11 +266,10 @@ Playlist::setNewRevision( const QString& rev,
|
||||
bool is_newest_rev,
|
||||
const QMap< QString, Tomahawk::plentry_ptr >& addedmap )
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO << (qlonglong)this
|
||||
// << rev << neworderedguids << oldorderedguids
|
||||
// << "isnewest:" << is_newest_rev << addedmap << applied << m_entries
|
||||
// ;
|
||||
|
||||
qDebug() << Q_FUNC_INFO << (qlonglong)this
|
||||
<< rev << neworderedguids << oldorderedguids
|
||||
<< "isnewest:" << is_newest_rev << addedmap << m_entries;
|
||||
|
||||
// build up correctly ordered new list of plentry_ptrs from
|
||||
// existing ones, and the ones that have been added
|
||||
QMap<QString, plentry_ptr> entriesmap;
|
||||
@ -285,11 +284,11 @@ Playlist::setNewRevision( const QString& rev,
|
||||
//qDebug() << "counters:" << neworderedguids.count() << entriesmap.count() << addedmap.count();
|
||||
foreach( const QString& id, neworderedguids )
|
||||
{
|
||||
qDebug() << "id:" << id;
|
||||
qDebug() << "newordered:" << neworderedguids.count() << neworderedguids;
|
||||
qDebug() << "entriesmap:" << entriesmap.count() << entriesmap;
|
||||
qDebug() << "addedmap:" << addedmap.count() << addedmap;
|
||||
qDebug() << "m_entries" << m_entries;
|
||||
// qDebug() << "id:" << id;
|
||||
// qDebug() << "newordered:" << neworderedguids.count() << neworderedguids;
|
||||
// qDebug() << "entriesmap:" << entriesmap.count() << entriesmap;
|
||||
// qDebug() << "addedmap:" << addedmap.count() << addedmap;
|
||||
// qDebug() << "m_entries" << m_entries;
|
||||
|
||||
if( entriesmap.contains( id ) )
|
||||
{
|
||||
|
@ -81,114 +81,31 @@ SourceTreeItem::onOffline()
|
||||
void
|
||||
SourceTreeItem::onPlaylistsAdded( const QList<playlist_ptr>& playlists )
|
||||
{
|
||||
playlistsAdded( playlists, false );
|
||||
// const-ness is important for getting the right pointer!
|
||||
foreach( const playlist_ptr& p, playlists )
|
||||
{
|
||||
m_playlists.append( p );
|
||||
qlonglong ptr = reinterpret_cast<qlonglong>( &m_playlists.last() );
|
||||
qDebug() << "Setting playlist ptr to:" << ptr;
|
||||
|
||||
connect( p.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ),
|
||||
SLOT( onPlaylistLoaded( Tomahawk::PlaylistRevision ) ),
|
||||
Qt::QueuedConnection);
|
||||
|
||||
qDebug() << "Playlist added:" << p->title() << p->creator() << p->info() << ptr;
|
||||
|
||||
playlistAddedInternal( ptr, p, false );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SourceTreeItem::onPlaylistsDeleted( const QList<playlist_ptr>& playlists )
|
||||
{
|
||||
playlistsDeleted( playlists, false );
|
||||
}
|
||||
|
||||
void
|
||||
SourceTreeItem::onPlaylistLoaded( Tomahawk::PlaylistRevision revision )
|
||||
{
|
||||
playlistLoaded( revision, false );
|
||||
}
|
||||
|
||||
void SourceTreeItem::onDynamicPlaylistsAdded( const QList< dynplaylist_ptr >& playlists )
|
||||
{
|
||||
playlistsAdded( dynListToPlaylists( playlists ), true );
|
||||
}
|
||||
|
||||
void SourceTreeItem::onDynamicPlaylistsDeleted( const QList< dynplaylist_ptr >& playlists )
|
||||
{
|
||||
playlistsDeleted( dynListToPlaylists( playlists ), true );
|
||||
}
|
||||
|
||||
void SourceTreeItem::onDynamicPlaylistsLoaded( DynamicPlaylistRevision revision )
|
||||
{
|
||||
playlistLoaded( revision, true );
|
||||
}
|
||||
|
||||
void
|
||||
SourceTreeItem::playlistLoaded( PlaylistRevision revision, bool dynamic )
|
||||
{
|
||||
qlonglong ptr = reinterpret_cast<qlonglong>( sender() );
|
||||
//qDebug() << "sender ptr:" << ptr;
|
||||
|
||||
QStandardItem* item = m_columns.at( 0 );
|
||||
int rows = item->rowCount();
|
||||
for ( int i = 0; i < rows; i++ )
|
||||
{
|
||||
QStandardItem* pi = item->child( i );
|
||||
qlonglong piptr = pi->data( PlaylistPointer ).toLongLong();
|
||||
playlist_ptr* pl = reinterpret_cast<playlist_ptr*>(piptr);
|
||||
SourcesModel::SourceType type = static_cast<SourcesModel::SourceType>( pi->data( Type ).toInt() );
|
||||
|
||||
if ( ( type == SourcesModel::PlaylistSource || type == SourcesModel::DynamicPlaylistSource ) && ptr == qlonglong( pl->data() ) )
|
||||
{
|
||||
//qDebug() << "Found playlist!";
|
||||
pi->setEnabled( true );
|
||||
if( dynamic )
|
||||
m_current_dynamic_revisions.insert( pl->data()->guid(), revision.revisionguid );
|
||||
else
|
||||
m_current_revisions.insert( pl->data()->guid(), revision.revisionguid );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SourceTreeItem::playlistsAdded( const QList< playlist_ptr >& playlists, bool dynamic )
|
||||
{
|
||||
// const-ness is important for getting the right pointer!
|
||||
foreach( const playlist_ptr& p, playlists )
|
||||
{
|
||||
qlonglong ptr;
|
||||
if( dynamic )
|
||||
{
|
||||
m_dynplaylists.append( p.staticCast<Tomahawk::DynamicPlaylist>() );
|
||||
ptr = reinterpret_cast<qlonglong>( &m_dynplaylists.last() );
|
||||
|
||||
connect( p.staticCast<Tomahawk::DynamicPlaylist>().data(), SIGNAL( revisionLoaded( Tomahawk::DynamicPlaylistRevision ) ),
|
||||
SLOT( onDynamicPlaylistLoaded( Tomahawk::DynamicPlaylistRevision ) ),
|
||||
Qt::QueuedConnection);
|
||||
} else
|
||||
{
|
||||
m_playlists.append( p );
|
||||
ptr = reinterpret_cast<qlonglong>( &m_playlists.last() );
|
||||
|
||||
connect( p.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ),
|
||||
SLOT( onPlaylistLoaded( Tomahawk::PlaylistRevision ) ),
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
qDebug() << "Playlist added:" << p->title() << p->creator() << p->info() << ptr << dynamic;
|
||||
|
||||
|
||||
QStandardItem* subitem = new QStandardItem( p->title() );
|
||||
subitem->setIcon( QIcon( RESPATH "images/playlist-icon.png" ) );
|
||||
subitem->setEditable( false );
|
||||
subitem->setEnabled( false );
|
||||
subitem->setData( ptr, PlaylistPointer );
|
||||
subitem->setData( dynamic ? SourcesModel::DynamicPlaylistSource : SourcesModel::PlaylistSource, Type );
|
||||
subitem->setData( (qlonglong)this, SourceItemPointer );
|
||||
|
||||
m_columns.at( 0 )->appendRow( subitem );
|
||||
Q_ASSERT( qobject_cast<QTreeView*>((parent()->parent()) ) );
|
||||
qobject_cast<QTreeView*>((parent()->parent()))->expandAll();
|
||||
|
||||
p->loadRevision();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SourceTreeItem::playlistsDeleted( const QList< playlist_ptr >& playlists, bool dynamic )
|
||||
{
|
||||
// const-ness is important for getting the right pointer!
|
||||
foreach( const playlist_ptr& p, playlists )
|
||||
{
|
||||
qlonglong ptr = qlonglong( p.data() );
|
||||
qDebug() << "Playlist removed:" << p->title() << p->creator() << p->info() << ptr << dynamic;
|
||||
qDebug() << "Playlist removed:" << p->title() << p->creator() << p->info() << ptr;
|
||||
|
||||
QStandardItem* item = m_columns.at( 0 );
|
||||
int rows = item->rowCount();
|
||||
@ -199,14 +116,118 @@ SourceTreeItem::playlistsDeleted( const QList< playlist_ptr >& playlists, bool d
|
||||
playlist_ptr* pl = reinterpret_cast<playlist_ptr*>(piptr);
|
||||
SourcesModel::SourceType type = static_cast<SourcesModel::SourceType>( pi->data( Type ).toInt() );
|
||||
|
||||
if ( ( type == SourcesModel::PlaylistSource || type == SourcesModel::DynamicPlaylistSource ) && ptr == qlonglong( pl->data() ) )
|
||||
if ( type == SourcesModel::PlaylistSource && ptr == qlonglong( pl->data() ) )
|
||||
{
|
||||
if( dynamic )
|
||||
m_dynplaylists.removeAll( p.staticCast<Tomahawk::DynamicPlaylist>() );
|
||||
else
|
||||
m_playlists.removeAll( p );
|
||||
m_playlists.removeAll( p );
|
||||
item->removeRow( i );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SourceTreeItem::onPlaylistLoaded( Tomahawk::PlaylistRevision revision )
|
||||
{
|
||||
qlonglong ptr = reinterpret_cast<qlonglong>( sender() );
|
||||
qDebug() << "sender ptr:" << ptr;
|
||||
|
||||
QStandardItem* item = m_columns.at( 0 );
|
||||
int rows = item->rowCount();
|
||||
for ( int i = 0; i < rows; i++ )
|
||||
{
|
||||
QStandardItem* pi = item->child( i );
|
||||
qlonglong piptr = pi->data( PlaylistPointer ).toLongLong();
|
||||
playlist_ptr* pl = reinterpret_cast<playlist_ptr*>(piptr);
|
||||
SourcesModel::SourceType type = static_cast<SourcesModel::SourceType>( pi->data( Type ).toInt() );
|
||||
|
||||
if ( type == SourcesModel::PlaylistSource&& ptr == qlonglong( pl->data() ) )
|
||||
{
|
||||
//qDebug() << "Found playlist!";
|
||||
pi->setEnabled( true );
|
||||
m_current_revisions.insert( pl->data()->guid(), revision.revisionguid );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SourceTreeItem::onDynamicPlaylistsAdded( const QList< dynplaylist_ptr >& playlists )
|
||||
{
|
||||
// const-ness is important for getting the right pointer!
|
||||
foreach( const dynplaylist_ptr& p, playlists )
|
||||
{
|
||||
m_dynplaylists.append( p );
|
||||
qlonglong ptr = reinterpret_cast<qlonglong>( &m_dynplaylists.last() );
|
||||
qDebug() << "Setting dynamic ptr to:" << ptr;
|
||||
connect( p.data(), SIGNAL( revisionLoaded( Tomahawk::DynamicPlaylistRevision ) ),
|
||||
SLOT( onDynamicPlaylistLoaded( Tomahawk::DynamicPlaylistRevision ) ),
|
||||
Qt::QueuedConnection);
|
||||
|
||||
qDebug() << "Dynamic Playlist added:" << p->title() << p->creator() << p->info() << ptr;
|
||||
|
||||
playlistAddedInternal( ptr, p, true );
|
||||
}
|
||||
}
|
||||
|
||||
void SourceTreeItem::onDynamicPlaylistsDeleted( const QList< dynplaylist_ptr >& playlists )
|
||||
{
|
||||
// const-ness is important for getting the right pointer!
|
||||
foreach( const dynplaylist_ptr& p, playlists )
|
||||
{
|
||||
qlonglong ptr = qlonglong( p.data() );
|
||||
qDebug() << "dynamic playlist removed:" << p->title() << p->creator() << p->info() << ptr;
|
||||
|
||||
QStandardItem* item = m_columns.at( 0 );
|
||||
int rows = item->rowCount();
|
||||
for ( int i = rows - 1; i >= 0; i-- )
|
||||
{
|
||||
QStandardItem* pi = item->child( i );
|
||||
qlonglong piptr = pi->data( PlaylistPointer ).toLongLong();
|
||||
playlist_ptr* pl = reinterpret_cast<playlist_ptr*>(piptr);
|
||||
SourcesModel::SourceType type = static_cast<SourcesModel::SourceType>( pi->data( Type ).toInt() );
|
||||
|
||||
if ( type == SourcesModel::DynamicPlaylistSource && ptr == qlonglong( pl->data() ) )
|
||||
{
|
||||
m_dynplaylists.removeAll( p );
|
||||
item->removeRow( i );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SourceTreeItem::onDynamicPlaylistLoaded( DynamicPlaylistRevision revision )
|
||||
{
|
||||
qlonglong ptr = reinterpret_cast<qlonglong>( sender() );
|
||||
qDebug() << "sender ptr:" << ptr;
|
||||
|
||||
QStandardItem* item = m_columns.at( 0 );
|
||||
int rows = item->rowCount();
|
||||
for ( int i = 0; i < rows; i++ )
|
||||
{
|
||||
QStandardItem* pi = item->child( i );
|
||||
qlonglong piptr = pi->data( DynamicPlaylistPointer ).toLongLong();
|
||||
playlist_ptr* pl = reinterpret_cast<playlist_ptr*>(piptr);
|
||||
SourcesModel::SourceType type = static_cast<SourcesModel::SourceType>( pi->data( Type ).toInt() );
|
||||
|
||||
if ( type == SourcesModel::DynamicPlaylistSource && ptr == qlonglong( pl->data() ) )
|
||||
{
|
||||
//qDebug() << "Found playlist!";
|
||||
pi->setEnabled( true );
|
||||
m_current_dynamic_revisions.insert( pl->data()->guid(), revision.revisionguid );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SourceTreeItem::playlistAddedInternal( qlonglong ptr, const Tomahawk::playlist_ptr& p, bool dynamic )
|
||||
{
|
||||
QStandardItem* subitem = new QStandardItem( p->title() );
|
||||
subitem->setIcon( QIcon( RESPATH "images/playlist-icon.png" ) );
|
||||
subitem->setEditable( false );
|
||||
subitem->setEnabled( false );
|
||||
subitem->setData( ptr, dynamic ? DynamicPlaylistPointer : PlaylistPointer );
|
||||
subitem->setData( dynamic ? SourcesModel::DynamicPlaylistSource : SourcesModel::PlaylistSource, Type );
|
||||
subitem->setData( (qlonglong)this, SourceItemPointer );
|
||||
|
||||
m_columns.at( 0 )->appendRow( subitem );
|
||||
Q_ASSERT( qobject_cast<QTreeView*>((parent()->parent()) ) );
|
||||
qobject_cast<QTreeView*>((parent()->parent()))->expandAll();
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
Type = Qt::UserRole + 1, /// Value is SourcesModel::SourceType
|
||||
SourceItemPointer = Qt::UserRole + 2, /// value is the sourcetreeritem of the collection itself.
|
||||
PlaylistPointer = Qt::UserRole + 3, /// Value is the playlist_ptr.data()
|
||||
DynamicPlaylistPointer = Qt::UserRole + 4 /// Value is the playlist_ptr.data()
|
||||
DynamicPlaylistPointer = Qt::UserRole + 4 /// Value is the dynplaylist_ptr.data()
|
||||
};
|
||||
|
||||
|
||||
@ -51,11 +51,9 @@ private slots:
|
||||
|
||||
void onDynamicPlaylistsAdded( const QList<Tomahawk::dynplaylist_ptr>& playlists );
|
||||
void onDynamicPlaylistsDeleted( const QList<Tomahawk::dynplaylist_ptr>& playlists );
|
||||
void onDynamicPlaylistsLoaded( Tomahawk::DynamicPlaylistRevision revision );
|
||||
void onDynamicPlaylistLoaded( Tomahawk::DynamicPlaylistRevision revision );
|
||||
private:
|
||||
void playlistsAdded( const QList<Tomahawk::playlist_ptr>& playlists, bool dynamic );
|
||||
void playlistsDeleted( const QList<Tomahawk::playlist_ptr>& playlists, bool dynamic );
|
||||
void playlistLoaded( Tomahawk::PlaylistRevision revision, bool dynamic );
|
||||
void playlistAddedInternal( qlonglong ptr, const Tomahawk::playlist_ptr& pl, bool dynamic );
|
||||
|
||||
QList<QStandardItem*> m_columns;
|
||||
Tomahawk::source_ptr m_source;
|
||||
|
@ -289,6 +289,8 @@ TomahawkApp::registerMetaTypes()
|
||||
qRegisterMetaType< Tomahawk::source_ptr >("Tomahawk::source_ptr");
|
||||
qRegisterMetaType< QList<Tomahawk::playlist_ptr> >("QList<Tomahawk::playlist_ptr>");
|
||||
qRegisterMetaType< QList<Tomahawk::dynplaylist_ptr> >("QList<Tomahawk::dynplaylist_ptr>");
|
||||
qRegisterMetaType< QList<Tomahawk::dyncontrol_ptr> >("QList<Tomahawk::dyncontrol_ptr>");
|
||||
qRegisterMetaType< QList<Tomahawk::geninterface_ptr> >("QList<Tomahawk::geninterface_ptr>");
|
||||
qRegisterMetaType< QList<Tomahawk::plentry_ptr> >("QList<Tomahawk::plentry_ptr>");
|
||||
qRegisterMetaType< QList<Tomahawk::query_ptr> >("QList<Tomahawk::query_ptr>");
|
||||
qRegisterMetaType< QList<Tomahawk::result_ptr> >("QList<Tomahawk::result_ptr>");
|
||||
|
Loading…
x
Reference in New Issue
Block a user