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