mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
Call sendMessage() with a QueuedConnection as it's cross-thread
This commit is contained in:
@@ -564,8 +564,12 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
|
|||||||
QObject* receiver = m_qidToSlotMap[ qid ].first;
|
QObject* receiver = m_qidToSlotMap[ qid ].first;
|
||||||
QString slot = m_qidToSlotMap[ qid ].second;
|
QString slot = m_qidToSlotMap[ qid ].second;
|
||||||
m_qidToSlotMap.remove( qid );
|
m_qidToSlotMap.remove( qid );
|
||||||
|
|
||||||
|
QVariant extraData;
|
||||||
|
if ( m_qidToExtraData.contains( qid ) )
|
||||||
|
extraData = m_qidToExtraData.take( qid );
|
||||||
|
|
||||||
QMetaObject::invokeMethod( receiver, slot.toLatin1(), Q_ARG( QString, msgType ), Q_ARG( QVariantMap, msg ) );
|
QMetaObject::invokeMethod( receiver, slot.toLatin1(), Q_ARG( QString, msgType ), Q_ARG( QVariantMap, msg ), Q_ARG( QVariant, extraData ) );
|
||||||
}
|
}
|
||||||
else if ( msgType == "allPlaylists" )
|
else if ( msgType == "allPlaylists" )
|
||||||
{
|
{
|
||||||
@@ -911,7 +915,7 @@ SpotifyAccount::startPlaylistSync( SpotifyPlaylistInfo* playlist )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyAccount::startPlaylistSyncWithPlaylist( const QString& msgType, const QVariantMap& msg )
|
SpotifyAccount::startPlaylistSyncWithPlaylist( const QString& msgType, const QVariantMap& msg, const QVariant& )
|
||||||
{
|
{
|
||||||
Q_UNUSED( msgType );
|
Q_UNUSED( msgType );
|
||||||
qDebug() << Q_FUNC_INFO << "Got full spotify playlist body, creating a tomahawk playlist and enabling sync!!";
|
qDebug() << Q_FUNC_INFO << "Got full spotify playlist body, creating a tomahawk playlist and enabling sync!!";
|
||||||
@@ -959,7 +963,7 @@ SpotifyAccount::startPlaylistSyncWithPlaylist( const QString& msgType, const QVa
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyAccount::playlistCreated( const QString& msgType, const QVariantMap& msg )
|
SpotifyAccount::playlistCreated( const QString& msgType, const QVariantMap& msg, const QVariant& )
|
||||||
{
|
{
|
||||||
Q_UNUSED( msgType );
|
Q_UNUSED( msgType );
|
||||||
|
|
||||||
@@ -990,20 +994,20 @@ SpotifyAccount::playlistCreated( const QString& msgType, const QVariantMap& msg
|
|||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
SpotifyAccount::sendMessage( const QVariantMap &m, QObject* obj, const QString& slot )
|
SpotifyAccount::sendMessage( const QVariantMap &m, QObject* obj, const QString& slot, const QVariant& extraData )
|
||||||
{
|
{
|
||||||
QVariantMap msg = m;
|
QVariantMap msg = m;
|
||||||
QString qid;
|
const QString qid = uuid();
|
||||||
|
|
||||||
if ( obj )
|
if ( obj )
|
||||||
{
|
{
|
||||||
qid = QUuid::createUuid().toString().replace( "{", "" ).replace( "}", "" );
|
|
||||||
|
|
||||||
m_qidToSlotMap[ qid ] = qMakePair( obj, slot );
|
m_qidToSlotMap[ qid ] = qMakePair( obj, slot );
|
||||||
msg[ "qid" ] = qid;
|
msg[ "qid" ] = qid;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_qidToExtraData[ qid ] = extraData;
|
||||||
|
|
||||||
m_spotifyResolver.data()->sendMessage( msg );
|
m_spotifyResolver.data()->sendMessage( msg );
|
||||||
|
|
||||||
return qid;
|
return qid;
|
||||||
|
@@ -99,7 +99,6 @@ public:
|
|||||||
virtual SipPlugin* sipPlugin() { return 0; }
|
virtual SipPlugin* sipPlugin() { return 0; }
|
||||||
virtual bool preventEnabling() const { return m_preventEnabling; }
|
virtual bool preventEnabling() const { return m_preventEnabling; }
|
||||||
|
|
||||||
QString sendMessage( const QVariantMap& msg, QObject* receiver = 0, const QString& slot = QString() );
|
|
||||||
|
|
||||||
void registerUpdaterForPlaylist( const QString& plId, SpotifyPlaylistUpdater* updater );
|
void registerUpdaterForPlaylist( const QString& plId, SpotifyPlaylistUpdater* updater );
|
||||||
void unregisterUpdater( const QString& plid );
|
void unregisterUpdater( const QString& plid );
|
||||||
@@ -111,6 +110,8 @@ public:
|
|||||||
bool loggedIn() const;
|
bool loggedIn() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
QString sendMessage( const QVariantMap& msg, QObject* receiver = 0, const QString& slot = QString(), const QVariant& extraData = QVariant() );
|
||||||
|
|
||||||
void aboutToShow( QAction* action, const Tomahawk::playlist_ptr& playlist );
|
void aboutToShow( QAction* action, const Tomahawk::playlist_ptr& playlist );
|
||||||
void syncActionTriggered( bool );
|
void syncActionTriggered( bool );
|
||||||
void atticaLoaded(Attica::Content::List);
|
void atticaLoaded(Attica::Content::List);
|
||||||
@@ -125,9 +126,9 @@ private slots:
|
|||||||
void logout();
|
void logout();
|
||||||
|
|
||||||
// SpotifyResolver message handlers, all take msgtype, msg as argument
|
// SpotifyResolver message handlers, all take msgtype, msg as argument
|
||||||
// void <here>( const QString& msgType, const QVariantMap& msg );
|
// void <here>( const QString& msgType, const QVariantMap& msg, const QVariant& extraData );
|
||||||
void startPlaylistSyncWithPlaylist( const QString& msgType, const QVariantMap& msg );
|
void startPlaylistSyncWithPlaylist( const QString& msgType, const QVariantMap& msg, const QVariant& extraData );
|
||||||
void playlistCreated( const QString& msgType, const QVariantMap& msg );
|
void playlistCreated( const QString& msgType, const QVariantMap& msg, const QVariant& extraData );
|
||||||
|
|
||||||
void delayedInit();
|
void delayedInit();
|
||||||
void hookupAfterDeletion( bool autoEnable );
|
void hookupAfterDeletion( bool autoEnable );
|
||||||
@@ -156,6 +157,7 @@ private:
|
|||||||
QWeakPointer< InfoSystem::SpotifyInfoPlugin > m_infoPlugin;
|
QWeakPointer< InfoSystem::SpotifyInfoPlugin > m_infoPlugin;
|
||||||
|
|
||||||
QMap<QString, QPair<QObject*, QString> > m_qidToSlotMap;
|
QMap<QString, QPair<QObject*, QString> > m_qidToSlotMap;
|
||||||
|
QMap<QString, QVariant > m_qidToExtraData;
|
||||||
|
|
||||||
// List of synced spotify playlists in config UI
|
// List of synced spotify playlists in config UI
|
||||||
QList< SpotifyPlaylistInfo* > m_allSpotifyPlaylists;
|
QList< SpotifyPlaylistInfo* > m_allSpotifyPlaylists;
|
||||||
|
@@ -103,9 +103,10 @@ SpotifyInfoPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
|
|||||||
message[ "artist" ] = artist;
|
message[ "artist" ] = artist;
|
||||||
message[ "album" ] = album;
|
message[ "album" ] = album;
|
||||||
|
|
||||||
const QString qid = m_account.data()->sendMessage( message, this, "albumListingResult" );
|
QMetaObject::invokeMethod( m_account.data(), "sendMessage", Qt::QueuedConnection, Q_ARG( QVariantMap, message ),
|
||||||
|
Q_ARG( QObject*, this ),
|
||||||
m_waitingForResults[ qid ] = requestData;
|
Q_ARG( QString, "albumListingResult" ),
|
||||||
|
Q_ARG( QVariant, QVariant::fromValue< InfoRequestData >( requestData ) ) );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -119,15 +120,12 @@ SpotifyInfoPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyInfoPlugin::albumListingResult( const QString& msgType, const QVariantMap& msg )
|
SpotifyInfoPlugin::albumListingResult( const QString& msgType, const QVariantMap& msg, const QVariant& extraData )
|
||||||
{
|
{
|
||||||
Q_ASSERT( msg.contains( "qid" ) );
|
Q_ASSERT( msg.contains( "qid" ) );
|
||||||
Q_ASSERT( m_waitingForResults.contains( msg.value( "qid" ).toString() ) );
|
Q_ASSERT( extraData.canConvert< InfoRequestData >() );
|
||||||
|
|
||||||
if ( !msg.contains( "qid" ) || !m_waitingForResults.contains( msg.value( "qid" ).toString() ) )
|
const InfoRequestData requestData = extraData.value< InfoRequestData >();
|
||||||
return;
|
|
||||||
|
|
||||||
const InfoRequestData requestData = m_waitingForResults.take( msg.value( "qid" ).toString() );
|
|
||||||
|
|
||||||
QVariantList tracks = msg.value( "tracks" ).toList();
|
QVariantList tracks = msg.value( "tracks" ).toList();
|
||||||
QStringList trackNameList;
|
QStringList trackNameList;
|
||||||
|
@@ -46,7 +46,7 @@ public:
|
|||||||
virtual ~SpotifyInfoPlugin();
|
virtual ~SpotifyInfoPlugin();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void albumListingResult( const QString& msgType, const QVariantMap& msg );
|
void albumListingResult( const QString& msgType, const QVariantMap& msg, const QVariant& extraData );
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void init() {}
|
virtual void init() {}
|
||||||
@@ -62,8 +62,6 @@ private:
|
|||||||
void dataError( InfoRequestData );
|
void dataError( InfoRequestData );
|
||||||
void trackListResult( const QStringList& trackNameList, const Tomahawk::InfoSystem::InfoRequestData& requestData );
|
void trackListResult( const QStringList& trackNameList, const Tomahawk::InfoSystem::InfoRequestData& requestData );
|
||||||
|
|
||||||
QHash< QString, InfoRequestData > m_waitingForResults;
|
|
||||||
|
|
||||||
QWeakPointer< Tomahawk::Accounts::SpotifyAccount > m_account;
|
QWeakPointer< Tomahawk::Accounts::SpotifyAccount > m_account;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -353,6 +353,8 @@ SpotifyPlaylistUpdater::tomahawkPlaylistRenamed(const QString &newT, const QStri
|
|||||||
msg[ "newTitle" ] = newT;
|
msg[ "newTitle" ] = newT;
|
||||||
msg[ "oldTitle" ] = oldT;
|
msg[ "oldTitle" ] = oldT;
|
||||||
msg[ "playlistid" ] = m_spotifyId;
|
msg[ "playlistid" ] = m_spotifyId;
|
||||||
|
|
||||||
|
// TODO check return value
|
||||||
m_spotify.data()->sendMessage( msg, this, "onPlaylistRename" );
|
m_spotify.data()->sendMessage( msg, this, "onPlaylistRename" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -493,7 +495,7 @@ SpotifyPlaylistUpdater::plentryToVariant( const QList< plentry_ptr >& entries )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::onTracksInsertedReturn( const QString& msgType, const QVariantMap& msg )
|
SpotifyPlaylistUpdater::onTracksInsertedReturn( const QString& msgType, const QVariantMap& msg, const QVariant& )
|
||||||
{
|
{
|
||||||
const bool success = msg.value( "success" ).toBool();
|
const bool success = msg.value( "success" ).toBool();
|
||||||
|
|
||||||
@@ -577,7 +579,7 @@ SpotifyPlaylistUpdater::tomahawkTracksRemoved( const QList< query_ptr >& tracks
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::onTracksRemovedReturn( const QString& msgType, const QVariantMap& msg )
|
SpotifyPlaylistUpdater::onTracksRemovedReturn( const QString& msgType, const QVariantMap& msg, const QVariant& )
|
||||||
{
|
{
|
||||||
const bool success = msg.value( "success" ).toBool();
|
const bool success = msg.value( "success" ).toBool();
|
||||||
|
|
||||||
@@ -626,7 +628,7 @@ SpotifyPlaylistUpdater::tomahawkTracksMoved( const QList< plentry_ptr >& tracks,
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::onTracksMovedReturn( const QString& msgType, const QVariantMap& msg )
|
SpotifyPlaylistUpdater::onTracksMovedReturn( const QString& msgType, const QVariantMap& msg, const QVariant& )
|
||||||
{
|
{
|
||||||
const bool success = msg.value( "success" ).toBool();
|
const bool success = msg.value( "success" ).toBool();
|
||||||
|
|
||||||
|
@@ -74,9 +74,9 @@ protected:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
// SpotifyResolver message handlers, all take msgtype, msg as argument
|
// SpotifyResolver message handlers, all take msgtype, msg as argument
|
||||||
void onTracksInsertedReturn( const QString& msgType, const QVariantMap& msg );
|
void onTracksInsertedReturn( const QString& msgType, const QVariantMap& msg, const QVariant& extraData );
|
||||||
void onTracksRemovedReturn( const QString& msgType, const QVariantMap& msg );
|
void onTracksRemovedReturn( const QString& msgType, const QVariantMap& msg, const QVariant& extraData );
|
||||||
void onTracksMovedReturn( const QString& msgType, const QVariantMap& msg );
|
void onTracksMovedReturn( const QString& msgType, const QVariantMap& msg, const QVariant& extraData );
|
||||||
|
|
||||||
void checkDeleteDialog() const;
|
void checkDeleteDialog() const;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user