1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-15 10:33:59 +02:00

Revert "Enable Subscribing on SpotifyPlaylists"

Looks fine but holding off until post-0.5.0 is tagged as I would like to test it quite thoroughly :)

This reverts commit 8401befe6b.
This commit is contained in:
Leo Franchi
2012-06-12 23:26:13 +02:00
parent 8401befe6b
commit d18439b4ae
6 changed files with 24 additions and 180 deletions

View File

@@ -47,7 +47,6 @@ using namespace Accounts;
static QPixmap* s_icon = 0; static QPixmap* s_icon = 0;
SpotifyAccount* SpotifyAccount::s_instance = 0;
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
static QString s_resolverId = "spotify-osx"; static QString s_resolverId = "spotify-osx";
@@ -82,10 +81,10 @@ SpotifyAccount::SpotifyAccount( const QString& accountId )
: CustomAtticaAccount( accountId ) : CustomAtticaAccount( accountId )
, m_preventEnabling( false ) , m_preventEnabling( false )
{ {
s_instance = this;
init(); init();
} }
SpotifyAccount::~SpotifyAccount() SpotifyAccount::~SpotifyAccount()
{ {
clearUser(); clearUser();
@@ -347,12 +346,9 @@ SpotifyAccount::aboutToShow( QAction* action, const playlist_ptr& playlist )
if ( !m_customActions.contains( action ) ) if ( !m_customActions.contains( action ) )
return; return;
// If it's not being synced, allow the option to sync // If it's not being synced, allow the option to sync
bool found = false; bool found = false;
bool manuallyDisabled = false; bool manuallyDisabled = false;
bool canSubscribe = false;
bool isSubscribed = false;
QList<PlaylistUpdaterInterface*> updaters = playlist->updaters(); QList<PlaylistUpdaterInterface*> updaters = playlist->updaters();
foreach ( PlaylistUpdaterInterface* updater, updaters ) foreach ( PlaylistUpdaterInterface* updater, updaters )
{ {
@@ -362,44 +358,23 @@ SpotifyAccount::aboutToShow( QAction* action, const playlist_ptr& playlist )
if ( !spotifyUpdater->sync() ) if ( !spotifyUpdater->sync() )
manuallyDisabled = true; manuallyDisabled = true;
canSubscribe = spotifyUpdater->canSubscribe();
isSubscribed = spotifyUpdater->subscribed();
qDebug() << "canSub " << canSubscribe << " is Sub " << isSubscribed << "isSibb " << spotifyUpdater->subscribed();
} }
} }
if ( !found ) if ( !found )
{ {
action->setText( tr( "Sync with Spotify" ) ); action->setText( tr( "Sync with Spotify" ) );
action->setProperty( "type", Sync );
} }
else if ( manuallyDisabled )
else if ( manuallyDisabled && !canSubscribe )
{ {
action->setText( tr( "Re-enable syncing with Spotify" ) ); action->setText( tr( "Re-enable syncing with Spotify" ) );
action->setProperty( "type", Sync );
}
else if ( canSubscribe && !isSubscribed )
{
action->setText( tr( "Subscribe with Spotify" ) );
action->setProperty( "type", Subscribe );
}
else
{
if ( canSubscribe )
{
action->setText( tr( "Stop Subscribing with Spotify" ) );
action->setProperty( "type", UnSubscribe);
} }
else else
{ {
action->setText( tr( "Stop syncing with Spotify" ) ); action->setText( tr( "Stop syncing with Spotify" ) );
action->setProperty( "type", UnSync);
} }
} }
}
void void
SpotifyAccount::syncActionTriggered( bool checked ) SpotifyAccount::syncActionTriggered( bool checked )
@@ -456,95 +431,21 @@ SpotifyAccount::syncActionTriggered( bool checked )
} }
} }
if ( info )
{
qDebug() << "Found info!";
info->sync = !updater->sync();
info->subscribe = !updater->sync();
}
else if( action->property("type").toInt() == Subscribe | UnSubscribe )
{
qDebug() << "ADDING PLAYLIST INFO!";
info = new SpotifyPlaylistInfo( playlist->title(), updater->spotifyId(), updater->spotifyId(), true, false );
}
Q_ASSERT( info ); Q_ASSERT( info );
if ( info )
info->sync = !updater->sync();
if ( m_configWidget.data() ) if ( m_configWidget.data() )
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists ); m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists );
if ( !updater->sync() )
switch( action->property("type").toInt() )
{ {
case Sync:
startPlaylistSync( info ); startPlaylistSync( info );
break; }
case UnSync: else
{
stopPlaylistSync( info, true ); stopPlaylistSync( info, true );
break;
case Subscribe:
qDebug() << "Got subscribe!";
startPlaylistSubscribe( info );
break;
case UnSubscribe:
qDebug() << "Got UNsubscribe!";
stopPlaylistSubscribe( info );
break;
default:
qDebug() << "I DONNO WHAT TO DO";
break;
} }
}
}
void
SpotifyAccount::stopPlaylistSubscribe( SpotifyPlaylistInfo* playlist )
{
qDebug() << Q_FUNC_INFO;
if ( !playlist )
return;
QVariantMap msg;
msg[ "_msgtype" ] = "setSubscription";
msg[ "playlistid" ] = playlist->plid;
msg[ "subscribed" ] = false;
sendMessage( msg, 0, "setSubscription" );
if ( m_updaters.contains( playlist->plid ) )
{
SpotifyPlaylistUpdater* updater = m_updaters[ playlist->plid ];
updater->setSubscribe( false );
updater->save();
}
}
void
SpotifyAccount::startPlaylistSubscribe( SpotifyPlaylistInfo* playlist )
{
qDebug() << Q_FUNC_INFO;
if ( !playlist )
return;
QVariantMap msg;
msg[ "_msgtype" ] = "setSubscription";
msg[ "playlistid" ] = playlist->plid;
msg[ "subscribed" ] = true;
sendMessage( msg, 0, "setSubscription" );
if ( m_updaters.contains( playlist->plid ) )
{
SpotifyPlaylistUpdater* updater = m_updaters[ playlist->plid ];
updater->setSubscribe( true );
updater->save();
} }
} }
@@ -594,13 +495,13 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
const QString plid = plMap.value( "id" ).toString(); const QString plid = plMap.value( "id" ).toString();
const QString revid = plMap.value( "revid" ).toString(); const QString revid = plMap.value( "revid" ).toString();
const bool sync = plMap.value( "sync" ).toBool(); const bool sync = plMap.value( "sync" ).toBool();
const bool subscribe = plMap.value( "subscribe" ).toBool();
if ( name.isNull() || plid.isNull() || revid.isNull() ) if ( name.isNull() || plid.isNull() || revid.isNull() )
{ {
qDebug() << "Did not get name and plid and revid for spotify playlist:" << name << plid << revid << plMap; qDebug() << "Did not get name and plid and revid for spotify playlist:" << name << plid << revid << plMap;
continue; continue;
} }
m_allSpotifyPlaylists << new SpotifyPlaylistInfo( name, plid, revid, sync, subscribe ); m_allSpotifyPlaylists << new SpotifyPlaylistInfo( name, plid, revid, sync );
} }
if ( !m_configWidget.isNull() ) if ( !m_configWidget.isNull() )
@@ -895,6 +796,7 @@ SpotifyAccount::startPlaylistSync( SpotifyPlaylistInfo* playlist )
sendMessage( msg, this, "startPlaylistSyncWithPlaylist" ); sendMessage( msg, this, "startPlaylistSyncWithPlaylist" );
} }
void void
SpotifyAccount::startPlaylistSyncWithPlaylist( const QString& msgType, const QVariantMap& msg ) SpotifyAccount::startPlaylistSyncWithPlaylist( const QString& msgType, const QVariantMap& msg )
{ {

View File

@@ -42,13 +42,13 @@ class SpotifyAccountConfig;
// metadata for a playlist // metadata for a playlist
struct SpotifyPlaylistInfo { struct SpotifyPlaylistInfo {
QString name, plid, revid; QString name, plid, revid;
bool sync, changed, subscribe; bool sync, changed;
SpotifyPlaylistInfo( const QString& nname, const QString& pid, const QString& rrevid, bool ssync, bool ssubscribe ) SpotifyPlaylistInfo( const QString& nname, const QString& pid, const QString& rrevid, bool ssync )
: name( nname ), plid( pid ), revid( rrevid ), sync( ssync ), changed( false ), subscribe( ssubscribe ) {} : name( nname ), plid( pid ), revid( rrevid ), sync( ssync ), changed( false ) {}
SpotifyPlaylistInfo() : sync( false ), changed( false ), subscribe( false ) {} SpotifyPlaylistInfo() : sync( false ), changed( false ) {}
}; };
@@ -78,10 +78,6 @@ public:
SpotifyAccount( const QString& accountId, const QString& path ); SpotifyAccount( const QString& accountId, const QString& path );
virtual ~SpotifyAccount(); virtual ~SpotifyAccount();
static SpotifyAccount* instance() {
return s_instance;
}
virtual QPixmap icon() const; virtual QPixmap icon() const;
virtual QWidget* configurationWidget(); virtual QWidget* configurationWidget();
virtual QWidget* aboutWidget(); virtual QWidget* aboutWidget();
@@ -98,9 +94,12 @@ public:
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() ); 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 );
bool deleteOnUnsync() const; bool deleteOnUnsync() const;
void setManualResolverPath( const QString& resolverPath ); void setManualResolverPath( const QString& resolverPath );
public slots: public slots:
@@ -134,21 +133,9 @@ private:
void startPlaylistSync( SpotifyPlaylistInfo* playlist ); void startPlaylistSync( SpotifyPlaylistInfo* playlist );
void stopPlaylistSync( SpotifyPlaylistInfo* playlist, bool forceDontDelete = false ); void stopPlaylistSync( SpotifyPlaylistInfo* playlist, bool forceDontDelete = false );
void fetchFullPlaylist( SpotifyPlaylistInfo* playlist ); void fetchFullPlaylist( SpotifyPlaylistInfo* playlist );
void setSyncForPlaylist( const QString& spotifyPlaylistId, bool sync ); void setSyncForPlaylist( const QString& spotifyPlaylistId, bool sync );
void stopPlaylistSubscribe( SpotifyPlaylistInfo* playlist );
void startPlaylistSubscribe( SpotifyPlaylistInfo* playlist );
enum Actions{
None = 0x01,
Subscribe = 0x02,
Sync = 0x04,
UnSubscribe = 0x06,
UnSync = 0x08
};
Actions m_action;
void createActions(); void createActions();
void removeActions(); void removeActions();
@@ -168,8 +155,6 @@ private:
SmartPointerList< QAction > m_customActions; SmartPointerList< QAction > m_customActions;
friend class ::SpotifyPlaylistUpdater; friend class ::SpotifyPlaylistUpdater;
static SpotifyAccount* s_instance;
}; };
} }

View File

@@ -74,7 +74,6 @@ SpotifyPlaylistUpdater::SpotifyPlaylistUpdater( SpotifyAccount* acct, const QStr
, m_spotifyId( spotifyId ) , m_spotifyId( spotifyId )
, m_blockUpdatesForNextRevision( false ) , m_blockUpdatesForNextRevision( false )
, m_sync( false ) , m_sync( false )
, m_subscribe( false )
{ {
init(); init();
} }
@@ -195,7 +194,6 @@ SpotifyPlaylistUpdater::type() const
QPixmap QPixmap
SpotifyPlaylistUpdater::typeIcon() const SpotifyPlaylistUpdater::typeIcon() const
{ {
if ( !s_typePixmap ) if ( !s_typePixmap )
{ {
QPixmap pm( RESPATH "images/spotify-logo.png" ); QPixmap pm( RESPATH "images/spotify-logo.png" );
@@ -222,17 +220,6 @@ SpotifyPlaylistUpdater::setSync( bool sync )
emit changed(); emit changed();
} }
void
SpotifyPlaylistUpdater::setSubscribe( bool sub )
{
if ( m_subscribe == sub )
return;
m_subscribe = sub;
saveToSettings();
emit changed();
}
bool bool
SpotifyPlaylistUpdater::sync() const SpotifyPlaylistUpdater::sync() const
@@ -240,14 +227,6 @@ SpotifyPlaylistUpdater::sync() const
return m_sync; return m_sync;
} }
bool
SpotifyPlaylistUpdater::canSubscribe()
{
qDebug() << " canSubscribe " << m_spotify.data()->credentials().value( "username" ).toString() << m_spotifyId;
return !m_spotifyId.contains( m_spotify.data()->credentials().value( "username" ).toString() );
}
void void
SpotifyPlaylistUpdater::spotifyTracksAdded( const QVariantList& tracks, const QString& startPosId, const QString& newRev, const QString& oldRev ) SpotifyPlaylistUpdater::spotifyTracksAdded( const QVariantList& tracks, const QString& startPosId, const QString& newRev, const QString& oldRev )

View File

@@ -53,9 +53,6 @@ public:
bool sync() const; bool sync() const;
void setSync( bool sync ); void setSync( bool sync );
bool canSubscribe();
void setSubscribe( bool sub );
bool subscribed() { return m_subscribe; }
QString spotifyId() const { return m_spotifyId; } QString spotifyId() const { return m_spotifyId; }
@@ -102,8 +99,6 @@ private:
bool m_blockUpdatesForNextRevision; bool m_blockUpdatesForNextRevision;
bool m_sync; bool m_sync;
bool m_subscribe;
bool m_canSubscribe;
QQueue<_detail::Closure*> m_queuedOps; QQueue<_detail::Closure*> m_queuedOps;
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS

View File

@@ -116,7 +116,6 @@ SpotifyParser::lookupSpotifyBrowse( const QString& linkRaw )
type = DropJob::Track; type = DropJob::Track;
QUrl url; QUrl url;
m_browseId = browseUri;
if( type != DropJob::Artist ) if( type != DropJob::Artist )
url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/browse/%1" ).arg( browseUri ) ); url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/browse/%1" ).arg( browseUri ) );
@@ -303,8 +302,6 @@ SpotifyParser::checkBrowseFinished()
if( m_createNewPlaylist && !m_tracks.isEmpty() ) if( m_createNewPlaylist && !m_tracks.isEmpty() )
{ {
m_playlist = Playlist::create( SourceList::instance()->getLocal(), m_playlist = Playlist::create( SourceList::instance()->getLocal(),
uuid(), uuid(),
m_title, m_title,
@@ -312,18 +309,6 @@ SpotifyParser::checkBrowseFinished()
m_creator, m_creator,
false, false,
m_tracks ); m_tracks );
if( Tomahawk::Accounts::SpotifyAccount::instance() != 0 )
{
qDebug() << "FOUND SPOTIFY ACCOUNT!!" << Tomahawk::Accounts::SpotifyAccount::instance()->credentials().value("username") << Tomahawk::Accounts::SpotifyAccount::instance()->isAuthenticated();
SpotifyPlaylistUpdater* updater = new SpotifyPlaylistUpdater( Tomahawk::Accounts::SpotifyAccount::instance(), m_browseId, m_browseId, m_playlist );
updater->setSync( true );
updater->setSubscribe( false );
Tomahawk::Accounts::SpotifyAccount::instance()->registerUpdaterForPlaylist( m_browseId, updater);
}
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) ); connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) );
return; return;
} }

View File

@@ -28,8 +28,6 @@
#include <QObject> #include <QObject>
#include <QSet> #include <QSet>
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include "accounts/spotify/SpotifyAccount.h"
#include "accounts/spotify/SpotifyPlaylistUpdater.h"
#define SPOTIFY_PLAYLIST_API_URL "http://spotikea.tomahawk-player.org" #define SPOTIFY_PLAYLIST_API_URL "http://spotikea.tomahawk-player.org"
@@ -86,7 +84,7 @@ private:
QString m_title, m_info, m_creator; QString m_title, m_info, m_creator;
Tomahawk::playlist_ptr m_playlist; Tomahawk::playlist_ptr m_playlist;
DropJobNotifier* m_browseJob; DropJobNotifier* m_browseJob;
QString m_browseId;
static QPixmap* s_pixmap; static QPixmap* s_pixmap;
}; };