mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-05 00:22:31 +02:00
Enable collaboratives
This commit is contained in:
parent
7e8c1d0ef5
commit
0f331a525b
@ -66,7 +66,8 @@ static QString s_resolverId = "spotify-unknown";
|
||||
namespace {
|
||||
enum ActionType {
|
||||
Sync = 0,
|
||||
Subscribe
|
||||
Subscribe = 1,
|
||||
Collaborate
|
||||
};
|
||||
}
|
||||
|
||||
@ -445,6 +446,9 @@ SpotifyAccount::aboutToShow( QAction* action, const playlist_ptr& playlist )
|
||||
bool isSubscribed = false;
|
||||
bool manuallyDisabled = false;
|
||||
bool sync = false;
|
||||
bool owner = false;
|
||||
bool collaborative = false;
|
||||
|
||||
action->setVisible( true );
|
||||
|
||||
QList<PlaylistUpdaterInterface*> updaters = playlist->updaters();
|
||||
@ -456,6 +460,8 @@ SpotifyAccount::aboutToShow( QAction* action, const playlist_ptr& playlist )
|
||||
|
||||
canSubscribe = spotifyUpdater->canSubscribe();
|
||||
isSubscribed = spotifyUpdater->subscribed();
|
||||
owner = spotifyUpdater->owner();
|
||||
collaborative = spotifyUpdater->collaborative();
|
||||
|
||||
if ( !canSubscribe && !spotifyUpdater->sync() )
|
||||
manuallyDisabled = true;
|
||||
@ -521,9 +527,38 @@ SpotifyAccount::aboutToShow( QAction* action, const playlist_ptr& playlist )
|
||||
action->setVisible( false );
|
||||
}
|
||||
}
|
||||
|
||||
// If the user is owner of current playlist, enable collaboration options
|
||||
if ( actionType == Collaborate )
|
||||
{
|
||||
if( found && owner && !manuallyDisabled )
|
||||
{
|
||||
if( !collaborative )
|
||||
action->setText( tr( "Enable Spotify collaborations" ) );
|
||||
else
|
||||
action->setText( tr( "Disable Spotify collaborations" ) );
|
||||
}
|
||||
else
|
||||
action->setVisible( false );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SpotifyPlaylistUpdater*
|
||||
SpotifyAccount::getPlaylistUpdater( const playlist_ptr plptr ){
|
||||
|
||||
SpotifyPlaylistUpdater* updater = 0;
|
||||
QList<PlaylistUpdaterInterface*> updaters = plptr->updaters();
|
||||
foreach ( PlaylistUpdaterInterface* u, updaters )
|
||||
{
|
||||
if ( SpotifyPlaylistUpdater* spotifyUpdater = qobject_cast< SpotifyPlaylistUpdater* >( u ) )
|
||||
{
|
||||
updater = spotifyUpdater;
|
||||
}
|
||||
}
|
||||
return updater;
|
||||
}
|
||||
|
||||
void
|
||||
SpotifyAccount::subscribeActionTriggered( bool )
|
||||
{
|
||||
@ -531,21 +566,12 @@ SpotifyAccount::subscribeActionTriggered( bool )
|
||||
|
||||
if ( playlist.isNull() )
|
||||
{
|
||||
qWarning() << "Got context menu spotify sync action triggered, but invalid playlist payload!";
|
||||
qWarning() << "Got context menu spotify subscribe action triggered, but invalid playlist payload!";
|
||||
Q_ASSERT( false );
|
||||
return;
|
||||
}
|
||||
|
||||
SpotifyPlaylistUpdater* updater = 0;
|
||||
QList<PlaylistUpdaterInterface*> updaters = playlist->updaters();
|
||||
foreach ( PlaylistUpdaterInterface* u, updaters )
|
||||
{
|
||||
if ( SpotifyPlaylistUpdater* spotifyUpdater = qobject_cast< SpotifyPlaylistUpdater* >( u ) )
|
||||
{
|
||||
updater = spotifyUpdater;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SpotifyPlaylistUpdater *updater = getPlaylistUpdater( playlist );
|
||||
|
||||
Q_ASSERT( updater );
|
||||
if ( !updater )
|
||||
@ -556,6 +582,49 @@ SpotifyAccount::subscribeActionTriggered( bool )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SpotifyAccount::collaborateActionTriggered( bool )
|
||||
{
|
||||
const playlist_ptr playlist = playlistFromAction( qobject_cast< QAction* >( sender() ) );
|
||||
|
||||
if ( playlist.isNull() )
|
||||
{
|
||||
qWarning() << "Got context menu spotify collaboration action triggered, but invalid playlist payload!";
|
||||
Q_ASSERT( false );
|
||||
return;
|
||||
}
|
||||
|
||||
SpotifyPlaylistUpdater *updater = getPlaylistUpdater( playlist );
|
||||
|
||||
if ( !updater )
|
||||
{
|
||||
tLog() << "No SpotifyPlaylistUpdater in payload slot of triggered action! Uh oh!!";
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
SpotifyPlaylistInfo* info = m_allSpotifyPlaylists.value( updater->spotifyId(), 0 );
|
||||
Q_ASSERT( info );
|
||||
|
||||
if( info->isOwner )
|
||||
{
|
||||
tLog() << info->name << info->isOwner << info->plid << updater->owner() << updater->collaborative();
|
||||
QVariantMap msg;
|
||||
msg[ "_msgtype" ] = "setCollaborative";
|
||||
msg[ "collaborative" ] = !updater->collaborative();
|
||||
msg[ "playlistid" ] = info->plid;
|
||||
|
||||
sendMessage( msg, this );
|
||||
updater->setCollaborative( !updater->collaborative() );
|
||||
|
||||
}
|
||||
else
|
||||
tLog() << "cant set collab for this pl, not owner!?" << info->name << info->plid;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SpotifyAccount::syncActionTriggered( bool )
|
||||
{
|
||||
@ -568,15 +637,7 @@ SpotifyAccount::syncActionTriggered( bool )
|
||||
return;
|
||||
}
|
||||
|
||||
SpotifyPlaylistUpdater* updater = 0;
|
||||
QList<PlaylistUpdaterInterface*> updaters = playlist->updaters();
|
||||
foreach ( PlaylistUpdaterInterface* u, updaters )
|
||||
{
|
||||
if ( SpotifyPlaylistUpdater* spotifyUpdater = qobject_cast< SpotifyPlaylistUpdater* >( u ) )
|
||||
{
|
||||
updater = spotifyUpdater;
|
||||
}
|
||||
}
|
||||
SpotifyPlaylistUpdater *updater = getPlaylistUpdater( playlist );
|
||||
|
||||
if ( !updater || updater->canSubscribe() )
|
||||
{
|
||||
@ -629,16 +690,7 @@ SpotifyAccount::syncActionTriggered( bool )
|
||||
void
|
||||
SpotifyAccount::setSubscribedForPlaylist( const playlist_ptr& playlist, bool subscribed )
|
||||
{
|
||||
SpotifyPlaylistUpdater* updater = 0;
|
||||
QList<PlaylistUpdaterInterface*> updaters = playlist->updaters();
|
||||
foreach ( PlaylistUpdaterInterface* u, updaters )
|
||||
{
|
||||
if ( SpotifyPlaylistUpdater* spotifyUpdater = qobject_cast< SpotifyPlaylistUpdater* >( u ) )
|
||||
{
|
||||
updater = spotifyUpdater;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SpotifyPlaylistUpdater *updater = getPlaylistUpdater( playlist );
|
||||
|
||||
if ( !updater )
|
||||
{
|
||||
@ -752,6 +804,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
|
||||
const QString name = plMap.value( "name" ).toString();
|
||||
const QString plid = plMap.value( "id" ).toString();
|
||||
const QString revid = plMap.value( "revid" ).toString();
|
||||
const bool isOwner = plMap.value( "owner" ).toBool();
|
||||
const bool sync = plMap.value( "sync" ).toBool();
|
||||
const bool subscribed = plMap.value( "subscribed" ).toBool();
|
||||
|
||||
@ -761,7 +814,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
|
||||
continue;
|
||||
}
|
||||
|
||||
registerPlaylistInfo( new SpotifyPlaylistInfo( name, plid, revid, sync, subscribed ) );
|
||||
registerPlaylistInfo( new SpotifyPlaylistInfo( name, plid, revid, sync, subscribed, isOwner ) );
|
||||
}
|
||||
|
||||
if ( !m_configWidget.isNull() )
|
||||
@ -1095,10 +1148,12 @@ void
|
||||
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!!";
|
||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Got full spotify playlist body, creating a tomahawk playlist and enabling sync!!";
|
||||
const QString id = msg.value( "id" ).toString();
|
||||
const QString name = msg.value( "name" ).toString();
|
||||
const QString revid = msg.value( "revid" ).toString();
|
||||
const bool collaborative = msg.value( "collaborative" ).toBool();
|
||||
const bool owner = msg.value( "owner" ).toBool();
|
||||
|
||||
qDebug() << "Starting sync with pl:" << id << name;
|
||||
QVariantList tracks = msg.value( "tracks" ).toList();
|
||||
@ -1134,6 +1189,8 @@ SpotifyAccount::startPlaylistSyncWithPlaylist( const QString& msgType, const QVa
|
||||
|
||||
SpotifyPlaylistUpdater* updater = new SpotifyPlaylistUpdater( this, revid, id, plPtr );
|
||||
updater->setSync( true );
|
||||
updater->setOwner( owner );
|
||||
updater->setCollaborative( collaborative );
|
||||
m_updaters[ id ] = updater;
|
||||
}
|
||||
}
|
||||
@ -1228,9 +1285,9 @@ SpotifyAccount::registerUpdaterForPlaylist( const QString& plId, SpotifyPlaylist
|
||||
}
|
||||
|
||||
void
|
||||
SpotifyAccount::registerPlaylistInfo( const QString& name, const QString& plid, const QString &revid, const bool sync, const bool subscribed )
|
||||
SpotifyAccount::registerPlaylistInfo( const QString& name, const QString& plid, const QString &revid, const bool sync, const bool subscribed, const bool owner )
|
||||
{
|
||||
m_allSpotifyPlaylists[ plid ] = new SpotifyPlaylistInfo( name, plid, revid, sync, subscribed );
|
||||
m_allSpotifyPlaylists[ plid ] = new SpotifyPlaylistInfo( name, plid, revid, sync, subscribed, owner );
|
||||
}
|
||||
|
||||
void
|
||||
@ -1339,6 +1396,13 @@ SpotifyAccount::createActions()
|
||||
subscribeAction->setData( Subscribe );
|
||||
m_customActions.append( subscribeAction );
|
||||
|
||||
QAction* collaborateAction = new QAction( 0 );
|
||||
collaborateAction->setIcon( QIcon( RESPATH "images/spotify-logo.png" ) );
|
||||
connect( collaborateAction, SIGNAL( triggered( bool ) ), this, SLOT( collaborateActionTriggered( bool ) ) );
|
||||
ActionCollection::instance()->addAction( ActionCollection::LocalPlaylists, collaborateAction, this );
|
||||
collaborateAction->setData( Collaborate );
|
||||
m_customActions.append( collaborateAction );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,11 +50,11 @@ class SpotifyAccountConfig;
|
||||
// metadata for a playlist
|
||||
struct SpotifyPlaylistInfo {
|
||||
QString name, plid, revid;
|
||||
bool sync, subscribed, changed;
|
||||
bool sync, subscribed, changed, isOwner;
|
||||
|
||||
|
||||
SpotifyPlaylistInfo( const QString& nname, const QString& pid, const QString& rrevid, bool ssync, bool ssubscribed )
|
||||
: name( nname ), plid( pid ), revid( rrevid ), sync( ssync ), subscribed( ssubscribed ), changed( false ) {}
|
||||
SpotifyPlaylistInfo( const QString& nname, const QString& pid, const QString& rrevid, bool ssync, bool ssubscribed, bool isowner = false )
|
||||
: name( nname ), plid( pid ), revid( rrevid ), sync( ssync ), subscribed( ssubscribed ), isOwner( isowner ), changed( false ) {}
|
||||
|
||||
SpotifyPlaylistInfo() : sync( false ), changed( false ) {}
|
||||
};
|
||||
@ -103,7 +103,7 @@ public:
|
||||
|
||||
|
||||
void registerUpdaterForPlaylist( const QString& plId, SpotifyPlaylistUpdater* updater );
|
||||
void registerPlaylistInfo( const QString& name, const QString& plid, const QString &revid, const bool sync, const bool subscribed );
|
||||
void registerPlaylistInfo(const QString& name, const QString& plid, const QString &revid, const bool sync, const bool subscribed , const bool owner = false);
|
||||
void registerPlaylistInfo( SpotifyPlaylistInfo* info );
|
||||
void unregisterUpdater( const QString& plid );
|
||||
|
||||
@ -120,6 +120,7 @@ public slots:
|
||||
void syncActionTriggered( bool );
|
||||
void subscribeActionTriggered( bool );
|
||||
void atticaLoaded(Attica::Content::List);
|
||||
void collaborateActionTriggered( bool );
|
||||
|
||||
private slots:
|
||||
void resolverChanged();
|
||||
@ -157,7 +158,7 @@ private:
|
||||
void createActions();
|
||||
void removeActions();
|
||||
playlist_ptr playlistFromAction( QAction* action ) const;
|
||||
|
||||
SpotifyPlaylistUpdater* getPlaylistUpdater( const playlist_ptr plptr);
|
||||
static SpotifyAccount* s_instance;
|
||||
|
||||
QWeakPointer<SpotifyAccountConfig> m_configWidget;
|
||||
|
@ -55,17 +55,20 @@ SpotifyUpdaterFactory::create( const Tomahawk::playlist_ptr& pl, const QVariantH
|
||||
}
|
||||
|
||||
// Register the updater with the account
|
||||
const QString spotifyId = settings.value( "spotifyId" ).toString();
|
||||
const QString latestRev = settings.value( "latestrev" ).toString();
|
||||
const bool sync = settings.value( "sync" ).toBool();
|
||||
const bool canSubscribe = settings.value( "canSubscribe" ).toBool();
|
||||
const bool isSubscribed = settings.value( "subscribed" ).toBool();
|
||||
|
||||
const QString spotifyId = settings.value( "spotifyId" ).toString();
|
||||
const QString latestRev = settings.value( "latestrev" ).toString();
|
||||
const bool sync = settings.value( "sync" ).toBool();
|
||||
const bool canSubscribe = settings.value( "canSubscribe" ).toBool();
|
||||
const bool isSubscribed = settings.value( "subscribed" ).toBool();
|
||||
const bool isOwner = settings.value( "isOwner" ).toBool();
|
||||
const bool isCollaborative = settings.value( "collaborative" ).toBool();
|
||||
Q_ASSERT( !spotifyId.isEmpty() );
|
||||
SpotifyPlaylistUpdater* updater = new SpotifyPlaylistUpdater( m_account.data(), latestRev, spotifyId, pl );
|
||||
updater->setSync( sync );
|
||||
updater->setCanSubscribe( canSubscribe );
|
||||
updater->setSubscribedStatus( isSubscribed );
|
||||
updater->setOwner( isOwner );
|
||||
updater->setCollaborative( isCollaborative );
|
||||
m_account.data()->registerUpdaterForPlaylist( spotifyId, updater );
|
||||
|
||||
return updater;
|
||||
@ -81,6 +84,8 @@ SpotifyPlaylistUpdater::SpotifyPlaylistUpdater( SpotifyAccount* acct, const QStr
|
||||
, m_sync( false )
|
||||
, m_canSubscribe( false )
|
||||
, m_subscribed( false )
|
||||
, m_isOwner( false )
|
||||
, m_collaborative( false )
|
||||
{
|
||||
init();
|
||||
}
|
||||
@ -177,7 +182,8 @@ SpotifyPlaylistUpdater::saveToSettings()
|
||||
s[ "canSubscribe" ] = m_canSubscribe;
|
||||
s[ "subscribed" ] = m_subscribed;
|
||||
s[ "spotifyId" ] = m_spotifyId;
|
||||
|
||||
s[ "isOwner" ] = m_isOwner;
|
||||
s[ "collaborative" ] = m_collaborative;
|
||||
saveSettings( s );
|
||||
}
|
||||
|
||||
@ -226,6 +232,41 @@ SpotifyPlaylistUpdater::sync() const
|
||||
return m_sync;
|
||||
}
|
||||
|
||||
void
|
||||
SpotifyPlaylistUpdater::setOwner( bool owner )
|
||||
{
|
||||
if ( m_isOwner == owner )
|
||||
return;
|
||||
|
||||
m_isOwner = owner;
|
||||
|
||||
saveToSettings();
|
||||
emit changed();
|
||||
}
|
||||
|
||||
bool
|
||||
SpotifyPlaylistUpdater::owner() const
|
||||
{
|
||||
return m_isOwner;
|
||||
}
|
||||
|
||||
void
|
||||
SpotifyPlaylistUpdater::setCollaborative( bool collab )
|
||||
{
|
||||
if ( m_collaborative == collab )
|
||||
return;
|
||||
|
||||
m_collaborative = collab;
|
||||
|
||||
saveToSettings();
|
||||
emit changed();
|
||||
}
|
||||
|
||||
bool
|
||||
SpotifyPlaylistUpdater::collaborative() const
|
||||
{
|
||||
return m_collaborative;
|
||||
}
|
||||
|
||||
void
|
||||
SpotifyPlaylistUpdater::setSubscribedStatus( bool subscribed )
|
||||
|
@ -62,6 +62,12 @@ public:
|
||||
void setSubscribedStatus( bool subscribed );
|
||||
bool canSubscribe() const;
|
||||
void setCanSubscribe( bool canSub );
|
||||
// Collaborative actions
|
||||
void setOwner( bool owner );
|
||||
bool owner() const;
|
||||
bool collaborative() const;
|
||||
void setCollaborative( bool collaborative );
|
||||
|
||||
QString spotifyId() const { return m_spotifyId; }
|
||||
|
||||
virtual bool hasCustomDeleter() const { return true; }
|
||||
@ -110,6 +116,9 @@ private:
|
||||
bool m_sync;
|
||||
bool m_subscribed;
|
||||
bool m_canSubscribe;
|
||||
bool m_isOwner;
|
||||
bool m_collaborative;
|
||||
|
||||
QQueue<_detail::Closure*> m_queuedOps;
|
||||
#ifndef ENABLE_HEADLESS
|
||||
static QPixmap* s_typePixmap;
|
||||
|
@ -45,6 +45,7 @@ SpotifyParser::SpotifyParser( const QStringList& Urls, bool createNewPlaylist, Q
|
||||
, m_limit ( 40 )
|
||||
, m_single( false )
|
||||
, m_trackMode( true )
|
||||
, m_collaborative( false )
|
||||
, m_createNewPlaylist( createNewPlaylist )
|
||||
, m_browseJob( 0 )
|
||||
|
||||
@ -59,6 +60,7 @@ SpotifyParser::SpotifyParser( const QString& Url, bool createNewPlaylist, QObjec
|
||||
, m_limit ( 40 )
|
||||
, m_single( true )
|
||||
, m_trackMode( true )
|
||||
, m_collaborative( false )
|
||||
, m_createNewPlaylist( createNewPlaylist )
|
||||
, m_browseJob( 0 )
|
||||
{
|
||||
@ -328,6 +330,7 @@ SpotifyParser::playlistListingResult( const QString& msgType, const QVariantMap&
|
||||
m_title = msg.value( "name" ).toString();
|
||||
m_single = false;
|
||||
m_creator = msg.value( "creator" ).toString();
|
||||
m_collaborative = msg.value( "collaborative" ).toBool();
|
||||
|
||||
const QVariantList tracks = msg.value( "tracks" ).toList();
|
||||
foreach ( const QVariant& blob, tracks )
|
||||
@ -390,13 +393,17 @@ SpotifyParser::checkBrowseFinished()
|
||||
// If the user isnt dropping a playlist the he owns, its subscribeable
|
||||
if ( !m_browseUri.contains( spotifyUsername ) )
|
||||
updater->setCanSubscribe( true );
|
||||
else
|
||||
updater->setOwner( true );
|
||||
|
||||
updater->setCollaborative( m_collaborative );
|
||||
|
||||
// Just register the infos
|
||||
Accounts::SpotifyAccount::instance()->registerPlaylistInfo( m_title, m_browseUri, m_browseUri, false, false );
|
||||
Accounts::SpotifyAccount::instance()->registerPlaylistInfo( m_title, m_browseUri, m_browseUri, false, false, updater->owner() );
|
||||
Accounts::SpotifyAccount::instance()->registerUpdaterForPlaylist( m_browseUri, updater );
|
||||
|
||||
|
||||
Accounts::SpotifyAccount::instance()->setSubscribedForPlaylist( m_playlist, true );
|
||||
// On default, set the playlist as subscribed
|
||||
if( !updater->owner() )
|
||||
Accounts::SpotifyAccount::instance()->setSubscribedForPlaylist( m_playlist, true );
|
||||
|
||||
}
|
||||
return;
|
||||
|
@ -85,6 +85,7 @@ private:
|
||||
bool m_single;
|
||||
bool m_trackMode;
|
||||
bool m_createNewPlaylist;
|
||||
bool m_collaborative;
|
||||
QList< query_ptr > m_tracks;
|
||||
QSet< QNetworkReply* > m_queries;
|
||||
QString m_title, m_info, m_creator;
|
||||
|
Loading…
x
Reference in New Issue
Block a user