mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-22 05:33:32 +02:00
Enable collaborative spotify playlists - Needs better nameing
This commit is contained in:
@@ -531,9 +531,9 @@ SpotifyAccount::aboutToShow( QAction* action, const playlist_ptr& playlist )
|
|||||||
// If the user is owner of current playlist, enable collaboration options
|
// If the user is owner of current playlist, enable collaboration options
|
||||||
if ( actionType == Collaborate )
|
if ( actionType == Collaborate )
|
||||||
{
|
{
|
||||||
if( found && owner && !manuallyDisabled )
|
if ( found && owner && !manuallyDisabled )
|
||||||
{
|
{
|
||||||
if( !collaborative )
|
if ( !collaborative )
|
||||||
action->setText( tr( "Enable Spotify collaborations" ) );
|
action->setText( tr( "Enable Spotify collaborations" ) );
|
||||||
else
|
else
|
||||||
action->setText( tr( "Disable Spotify collaborations" ) );
|
action->setText( tr( "Disable Spotify collaborations" ) );
|
||||||
@@ -545,7 +545,8 @@ SpotifyAccount::aboutToShow( QAction* action, const playlist_ptr& playlist )
|
|||||||
|
|
||||||
|
|
||||||
SpotifyPlaylistUpdater*
|
SpotifyPlaylistUpdater*
|
||||||
SpotifyAccount::getPlaylistUpdater( const playlist_ptr plptr ){
|
SpotifyAccount::getPlaylistUpdater( const playlist_ptr plptr )
|
||||||
|
{
|
||||||
|
|
||||||
SpotifyPlaylistUpdater* updater = 0;
|
SpotifyPlaylistUpdater* updater = 0;
|
||||||
QList<PlaylistUpdaterInterface*> updaters = plptr->updaters();
|
QList<PlaylistUpdaterInterface*> updaters = plptr->updaters();
|
||||||
@@ -559,42 +560,68 @@ SpotifyAccount::getPlaylistUpdater( const playlist_ptr plptr ){
|
|||||||
return updater;
|
return updater;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
SpotifyPlaylistUpdater*
|
||||||
SpotifyAccount::subscribeActionTriggered( bool )
|
SpotifyAccount::getPlaylistUpdater( QObject *sender )
|
||||||
{
|
{
|
||||||
const playlist_ptr playlist = playlistFromAction( qobject_cast< QAction* >( sender() ) );
|
|
||||||
|
if ( !sender )
|
||||||
|
{
|
||||||
|
tLog() << "uuh noo, null sender!";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction* senderAction = qobject_cast< QAction* >( sender );
|
||||||
|
|
||||||
|
if ( !senderAction )
|
||||||
|
{
|
||||||
|
tLog() << "uuh noo, null action!";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const playlist_ptr playlist = playlistFromAction( senderAction );
|
||||||
|
|
||||||
if ( playlist.isNull() )
|
if ( playlist.isNull() )
|
||||||
{
|
{
|
||||||
qWarning() << "Got context menu spotify subscribe action triggered, but invalid playlist payload!";
|
qWarning() << "Got context menu spotify action " << senderAction->text() << "triggered, but invalid playlist payload!";
|
||||||
Q_ASSERT( false );
|
Q_ASSERT( false );
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpotifyPlaylistUpdater *updater = getPlaylistUpdater( playlist );
|
SpotifyPlaylistUpdater* updater = 0;
|
||||||
|
QList<PlaylistUpdaterInterface*> updaters = playlist->updaters();
|
||||||
|
foreach ( PlaylistUpdaterInterface* u, updaters )
|
||||||
|
{
|
||||||
|
if ( SpotifyPlaylistUpdater* spotifyUpdater = qobject_cast< SpotifyPlaylistUpdater* >( u ) )
|
||||||
|
{
|
||||||
|
updater = spotifyUpdater;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return updater;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccount::subscribeActionTriggered( bool )
|
||||||
|
{
|
||||||
|
SpotifyPlaylistUpdater* updater = getPlaylistUpdater( sender() );
|
||||||
|
|
||||||
Q_ASSERT( updater );
|
Q_ASSERT( updater );
|
||||||
if ( !updater )
|
if ( !updater )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Q_ASSERT( updater->playlist() );
|
||||||
|
if ( !updater->playlist() )
|
||||||
|
return;
|
||||||
|
|
||||||
// Toggle subscription status
|
// Toggle subscription status
|
||||||
setSubscribedForPlaylist( playlist, !updater->subscribed() );
|
setSubscribedForPlaylist( updater->playlist(), !updater->subscribed() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyAccount::collaborateActionTriggered( bool )
|
SpotifyAccount::collaborateActionTriggered( bool )
|
||||||
{
|
{
|
||||||
const playlist_ptr playlist = playlistFromAction( qobject_cast< QAction* >( sender() ) );
|
|
||||||
|
|
||||||
if ( playlist.isNull() )
|
SpotifyPlaylistUpdater* updater = getPlaylistUpdater( sender() );
|
||||||
{
|
|
||||||
qWarning() << "Got context menu spotify collaboration action triggered, but invalid playlist payload!";
|
|
||||||
Q_ASSERT( false );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SpotifyPlaylistUpdater *updater = getPlaylistUpdater( playlist );
|
|
||||||
|
|
||||||
if ( !updater )
|
if ( !updater )
|
||||||
{
|
{
|
||||||
@@ -606,7 +633,7 @@ SpotifyAccount::collaborateActionTriggered( bool )
|
|||||||
SpotifyPlaylistInfo* info = m_allSpotifyPlaylists.value( updater->spotifyId(), 0 );
|
SpotifyPlaylistInfo* info = m_allSpotifyPlaylists.value( updater->spotifyId(), 0 );
|
||||||
Q_ASSERT( info );
|
Q_ASSERT( info );
|
||||||
|
|
||||||
if( info->isOwner )
|
if ( info->isOwner )
|
||||||
{
|
{
|
||||||
tLog() << info->name << info->isOwner << info->plid << updater->owner() << updater->collaborative();
|
tLog() << info->name << info->isOwner << info->plid << updater->owner() << updater->collaborative();
|
||||||
QVariantMap msg;
|
QVariantMap msg;
|
||||||
@@ -616,7 +643,6 @@ SpotifyAccount::collaborateActionTriggered( bool )
|
|||||||
|
|
||||||
sendMessage( msg, this );
|
sendMessage( msg, this );
|
||||||
updater->setCollaborative( !updater->collaborative() );
|
updater->setCollaborative( !updater->collaborative() );
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
tLog() << "cant set collab for this pl, not owner!?" << info->name << info->plid;
|
tLog() << "cant set collab for this pl, not owner!?" << info->name << info->plid;
|
||||||
@@ -628,7 +654,7 @@ SpotifyAccount::collaborateActionTriggered( bool )
|
|||||||
void
|
void
|
||||||
SpotifyAccount::syncActionTriggered( bool )
|
SpotifyAccount::syncActionTriggered( bool )
|
||||||
{
|
{
|
||||||
const playlist_ptr playlist = playlistFromAction( qobject_cast< QAction* >( sender() ) );
|
const playlist_ptr playlist = playlistFromAction( sender() );
|
||||||
|
|
||||||
if ( playlist.isNull() )
|
if ( playlist.isNull() )
|
||||||
{
|
{
|
||||||
@@ -637,7 +663,7 @@ SpotifyAccount::syncActionTriggered( bool )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpotifyPlaylistUpdater *updater = getPlaylistUpdater( playlist );
|
SpotifyPlaylistUpdater* updater = getPlaylistUpdater( playlist );
|
||||||
|
|
||||||
if ( !updater || updater->canSubscribe() )
|
if ( !updater || updater->canSubscribe() )
|
||||||
{
|
{
|
||||||
@@ -690,7 +716,7 @@ SpotifyAccount::syncActionTriggered( bool )
|
|||||||
void
|
void
|
||||||
SpotifyAccount::setSubscribedForPlaylist( const playlist_ptr& playlist, bool subscribed )
|
SpotifyAccount::setSubscribedForPlaylist( const playlist_ptr& playlist, bool subscribed )
|
||||||
{
|
{
|
||||||
SpotifyPlaylistUpdater *updater = getPlaylistUpdater( playlist );
|
SpotifyPlaylistUpdater* updater = getPlaylistUpdater( playlist );
|
||||||
|
|
||||||
if ( !updater )
|
if ( !updater )
|
||||||
{
|
{
|
||||||
@@ -736,14 +762,26 @@ SpotifyAccount::setSubscribedForPlaylist( const playlist_ptr& playlist, bool sub
|
|||||||
|
|
||||||
|
|
||||||
playlist_ptr
|
playlist_ptr
|
||||||
SpotifyAccount::playlistFromAction( QAction* action ) const
|
SpotifyAccount::playlistFromAction( QObject* action ) const
|
||||||
{
|
{
|
||||||
Q_ASSERT( action );
|
if ( !action )
|
||||||
|
{
|
||||||
|
tLog() << "uuh noo, null sender!";
|
||||||
|
return playlist_ptr();
|
||||||
|
}
|
||||||
|
|
||||||
if ( !action || !m_customActions.contains( action ) )
|
QAction* senderAction = qobject_cast< QAction* >( action );
|
||||||
|
|
||||||
|
if ( !senderAction )
|
||||||
|
{
|
||||||
|
tLog() << "uuh noo, null action!";
|
||||||
|
return playlist_ptr();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !senderAction || !m_customActions.contains( senderAction ) )
|
||||||
return playlist_ptr();
|
return playlist_ptr();
|
||||||
|
|
||||||
return action->property( "payload" ).value< playlist_ptr >();
|
return senderAction->property( "payload" ).value< playlist_ptr >();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -103,7 +103,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
void registerUpdaterForPlaylist( const QString& plId, SpotifyPlaylistUpdater* updater );
|
void registerUpdaterForPlaylist( const QString& plId, SpotifyPlaylistUpdater* updater );
|
||||||
void registerPlaylistInfo(const QString& name, const QString& plid, const QString &revid, const bool sync, const bool subscribed , const bool owner = false);
|
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 registerPlaylistInfo( SpotifyPlaylistInfo* info );
|
||||||
void unregisterUpdater( const QString& plid );
|
void unregisterUpdater( const QString& plid );
|
||||||
|
|
||||||
@@ -157,8 +157,9 @@ private:
|
|||||||
|
|
||||||
void createActions();
|
void createActions();
|
||||||
void removeActions();
|
void removeActions();
|
||||||
playlist_ptr playlistFromAction( QAction* action ) const;
|
playlist_ptr playlistFromAction( QObject* action ) const;
|
||||||
SpotifyPlaylistUpdater* getPlaylistUpdater( const playlist_ptr plptr);
|
SpotifyPlaylistUpdater* getPlaylistUpdater( const playlist_ptr plptr);
|
||||||
|
SpotifyPlaylistUpdater* getPlaylistUpdater( QObject* sender );
|
||||||
static SpotifyAccount* s_instance;
|
static SpotifyAccount* s_instance;
|
||||||
|
|
||||||
QWeakPointer<SpotifyAccountConfig> m_configWidget;
|
QWeakPointer<SpotifyAccountConfig> m_configWidget;
|
||||||
|
@@ -22,7 +22,6 @@
|
|||||||
#include "accounts/AccountManager.h"
|
#include "accounts/AccountManager.h"
|
||||||
#include "SpotifyAccount.h"
|
#include "SpotifyAccount.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
@@ -212,7 +211,6 @@ SpotifyPlaylistUpdater::typeIcon() const
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::setSync( bool sync )
|
SpotifyPlaylistUpdater::setSync( bool sync )
|
||||||
{
|
{
|
||||||
|
@@ -49,7 +49,6 @@ public:
|
|||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
virtual QWidget* configurationWidget() const { return 0; }
|
virtual QWidget* configurationWidget() const { return 0; }
|
||||||
|
|
||||||
virtual QPixmap typeIcon() const;
|
virtual QPixmap typeIcon() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -84,6 +84,8 @@ public:
|
|||||||
virtual bool canSubscribe() const { return false; }
|
virtual bool canSubscribe() const { return false; }
|
||||||
virtual bool subscribed() const { return false; }
|
virtual bool subscribed() const { return false; }
|
||||||
virtual void setSubscribed( bool ) {}
|
virtual void setSubscribed( bool ) {}
|
||||||
|
virtual void setCollaborative( bool ) {}
|
||||||
|
virtual bool collaborative() const { return false; }
|
||||||
|
|
||||||
// The int data value associated with each question must be unique across *all* playlist updaters,
|
// The int data value associated with each question must be unique across *all* playlist updaters,
|
||||||
// as setQuestionResults is called with all questions from all updaters.
|
// as setQuestionResults is called with all questions from all updaters.
|
||||||
|
@@ -291,6 +291,25 @@ PlaylistItem::onUpdated()
|
|||||||
emit updated();
|
emit updated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PlaylistItem::collaborative() const
|
||||||
|
{
|
||||||
|
Q_ASSERT( !m_playlist.isNull() );
|
||||||
|
|
||||||
|
if ( m_playlist->updaters().isEmpty() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool collaborative = false;
|
||||||
|
|
||||||
|
foreach ( PlaylistUpdaterInterface* updater, m_playlist->updaters() )
|
||||||
|
{
|
||||||
|
if( !updater->collaborative() )
|
||||||
|
continue;
|
||||||
|
collaborative = updater->collaborative();
|
||||||
|
}
|
||||||
|
|
||||||
|
return collaborative;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PlaylistItem::createOverlay()
|
PlaylistItem::createOverlay()
|
||||||
@@ -302,6 +321,7 @@ PlaylistItem::createOverlay()
|
|||||||
|
|
||||||
m_showSubscribed = false;
|
m_showSubscribed = false;
|
||||||
m_canSubscribe = false;
|
m_canSubscribe = false;
|
||||||
|
|
||||||
foreach ( PlaylistUpdaterInterface* updater, m_playlist->updaters() )
|
foreach ( PlaylistUpdaterInterface* updater, m_playlist->updaters() )
|
||||||
{
|
{
|
||||||
if ( updater->canSubscribe() )
|
if ( updater->canSubscribe() )
|
||||||
@@ -349,6 +369,7 @@ PlaylistItem::createOverlay()
|
|||||||
overlayRect.moveLeft( 0 );
|
overlayRect.moveLeft( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
m_overlaidIcon.addPixmap( base );
|
m_overlaidIcon.addPixmap( base );
|
||||||
|
@@ -47,6 +47,7 @@ public:
|
|||||||
bool subscribed() const { return m_showSubscribed; }
|
bool subscribed() const { return m_showSubscribed; }
|
||||||
QPixmap subscribedIcon() const { return m_showSubscribed ? m_subscribedOnIcon : m_subscribedOffIcon; }
|
QPixmap subscribedIcon() const { return m_showSubscribed ? m_subscribedOnIcon : m_subscribedOffIcon; }
|
||||||
void setSubscribed( bool subscribed );
|
void setSubscribed( bool subscribed );
|
||||||
|
bool collaborative() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void activate();
|
virtual void activate();
|
||||||
|
Reference in New Issue
Block a user