1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-12 09:04:33 +02:00

Fetch subscribers and collaboration changes

This commit is contained in:
Hugo Lindström
2012-08-21 23:46:38 +02:00
parent 02a1296101
commit 10208a8efd
9 changed files with 64 additions and 6 deletions

View File

@@ -639,9 +639,7 @@ SpotifyAccount::collaborateActionTriggered( QAction* action )
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;
@@ -906,7 +904,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
updater->spotifyTracksMoved( tracksList, newStartPos, newRev, oldRev );
}
else if ( msgType == "playlistRenamed" )
else if ( msgType == "playlistMetadataChanged" )
{
const QString plid = msg.value( "id" ).toString();
// We should already be syncing this playlist if we get updates for it
@@ -919,12 +917,30 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
SpotifyPlaylistUpdater* updater = m_updaters[ plid ];
Q_ASSERT( updater->sync() );
qDebug() << "Playlist renamed fetched in tomahawk";
const QString title = msg.value( "name" ).toString();
const QString newRev = msg.value( "revid" ).toString();
const QString oldRev = msg.value( "oldRev" ).toString();
const bool collaborative = msg.value( "collaborative" ).toBool();
const int subscribers = msg.value( "subscribers" ).toInt();
updater->spotifyPlaylistRenamed( title, newRev, oldRev );
SpotifyPlaylistInfo* info = m_allSpotifyPlaylists[ plid ];
if( info && info->name != title )
{
qDebug() << "Playlist renamed fetched in tomahawk";
updater->spotifyPlaylistRenamed( title, newRev, oldRev );
}
if( updater->collaborative() != collaborative )
{
tLog() << "Setting collaborative!" << collaborative;
updater->setCollaborative( collaborative );
}
if( updater->subscribers() != subscribers )
{
tLog() << "Updateing number of subscribers" << subscribers;
updater->setSubscribers( subscribers );
}
}
else if ( msgType == "spotifyError" )
{

View File

@@ -61,6 +61,7 @@ SpotifyUpdaterFactory::create( const Tomahawk::playlist_ptr& pl, const QVariantH
const bool isSubscribed = settings.value( "subscribed" ).toBool();
const bool isOwner = settings.value( "isOwner" ).toBool();
const bool isCollaborative = settings.value( "collaborative" ).toBool();
const bool subscribers = settings.value( "subscribers" ).toInt();
Q_ASSERT( !spotifyId.isEmpty() );
SpotifyPlaylistUpdater* updater = new SpotifyPlaylistUpdater( m_account.data(), latestRev, spotifyId, pl );
updater->setSync( sync );
@@ -68,6 +69,7 @@ SpotifyUpdaterFactory::create( const Tomahawk::playlist_ptr& pl, const QVariantH
updater->setSubscribedStatus( isSubscribed );
updater->setOwner( isOwner );
updater->setCollaborative( isCollaborative );
updater->setSubscribers( subscribers );
m_account.data()->registerUpdaterForPlaylist( spotifyId, updater );
return updater;
@@ -85,6 +87,7 @@ SpotifyPlaylistUpdater::SpotifyPlaylistUpdater( SpotifyAccount* acct, const QStr
, m_subscribed( false )
, m_isOwner( false )
, m_collaborative( false )
, m_subscribers( 0 )
{
init();
}
@@ -315,6 +318,17 @@ SpotifyPlaylistUpdater::canSubscribe() const
return m_canSubscribe;
}
void
SpotifyPlaylistUpdater::setSubscribers( int numSubscribers )
{
if ( m_subscribers == numSubscribers )
return;
m_subscribers = numSubscribers;
saveToSettings();
emit changed();
}
PlaylistDeleteQuestions
SpotifyPlaylistUpdater::deleteQuestions() const

View File

@@ -61,6 +61,8 @@ public:
void setSubscribedStatus( bool subscribed );
bool canSubscribe() const;
void setCanSubscribe( bool canSub );
void setSubscribers( int numSubscribers );
int subscribers() const { return m_subscribers; }
// Collaborative actions
void setOwner( bool owner );
bool owner() const;
@@ -117,6 +119,7 @@ private:
bool m_canSubscribe;
bool m_isOwner;
bool m_collaborative;
int m_subscribers;
QQueue<_detail::Closure*> m_queuedOps;
#ifndef ENABLE_HEADLESS

View File

@@ -86,6 +86,8 @@ public:
virtual void setSubscribed( bool ) {}
virtual void setCollaborative( bool ) {}
virtual bool collaborative() const { return false; }
virtual void setSubscribers( int ) {}
virtual int subscribers() const { return 0; }
// 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.

View File

@@ -48,6 +48,7 @@ SpotifyParser::SpotifyParser( const QStringList& Urls, bool createNewPlaylist, Q
, m_collaborative( false )
, m_createNewPlaylist( createNewPlaylist )
, m_browseJob( 0 )
, m_subscribers( 0 )
{
foreach ( const QString& url, Urls )
@@ -63,6 +64,7 @@ SpotifyParser::SpotifyParser( const QString& Url, bool createNewPlaylist, QObjec
, m_collaborative( false )
, m_createNewPlaylist( createNewPlaylist )
, m_browseJob( 0 )
, m_subscribers( 0 )
{
lookupUrl( Url );
}
@@ -331,6 +333,7 @@ SpotifyParser::playlistListingResult( const QString& msgType, const QVariantMap&
m_single = false;
m_creator = msg.value( "creator" ).toString();
m_collaborative = msg.value( "collaborative" ).toBool();
m_subscribers = msg.value( "subscribers" ).toInt();
const QVariantList tracks = msg.value( "tracks" ).toList();
foreach ( const QVariant& blob, tracks )
@@ -397,7 +400,7 @@ SpotifyParser::checkBrowseFinished()
updater->setOwner( true );
updater->setCollaborative( m_collaborative );
updater->setSubscribers( m_subscribers );
// Just register the infos
Accounts::SpotifyAccount::instance()->registerPlaylistInfo( m_title, m_browseUri, m_browseUri, false, false, updater->owner() );
Accounts::SpotifyAccount::instance()->registerUpdaterForPlaylist( m_browseUri, updater );

View File

@@ -86,6 +86,7 @@ private:
bool m_trackMode;
bool m_createNewPlaylist;
bool m_collaborative;
int m_subscribers;
QList< query_ptr > m_tracks;
QSet< QNetworkReply* > m_queries;
QString m_title, m_info, m_creator;

View File

@@ -569,6 +569,7 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
const QRect subRect( o.rect.right() - padding - imgWidth, o.rect.top() + padding, imgWidth, imgWidth );
painter->drawPixmap( subRect, icon );
}
if ( plItem->collaborative() )
{
const int imgWidth = m_collaborativeOn.size().width();

View File

@@ -311,6 +311,22 @@ PlaylistItem::collaborative() const
return collaborative;
}
int
PlaylistItem::subscribers() const
{
Q_ASSERT( !m_playlist.isNull() );
if ( m_playlist->updaters().isEmpty() )
return false;
foreach ( PlaylistUpdaterInterface* updater, m_playlist->updaters() )
{
if( updater->subscribers() )
return updater->subscribers();
}
return 0;
}
bool
PlaylistItem::createOverlay()
{

View File

@@ -48,6 +48,8 @@ public:
QPixmap subscribedIcon() const { return m_showSubscribed ? m_subscribedOnIcon : m_subscribedOffIcon; }
void setSubscribed( bool subscribed );
bool collaborative() const;
void setSubscribers( int numSubscribers );
int subscribers() const;
public slots:
virtual void activate();