mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Work on the tomahawk side of spotify syncing. bugfixes and new UI indicators
This commit is contained in:
@@ -368,10 +368,14 @@ void
|
|||||||
SpotifyAccount::sendMessage( const QVariantMap &m, QObject* obj, const QString& slot )
|
SpotifyAccount::sendMessage( const QVariantMap &m, QObject* obj, const QString& slot )
|
||||||
{
|
{
|
||||||
QVariantMap msg = m;
|
QVariantMap msg = m;
|
||||||
|
|
||||||
|
if ( obj )
|
||||||
|
{
|
||||||
const QString qid = QUuid::createUuid().toString().replace( "{", "" ).replace( "}", "" );
|
const QString qid = QUuid::createUuid().toString().replace( "{", "" ).replace( "}", "" );
|
||||||
|
|
||||||
m_qidToSlotMap[ qid ] = qMakePair( obj, slot );
|
m_qidToSlotMap[ qid ] = qMakePair( obj, slot );
|
||||||
msg[ "qid" ] = qid;
|
msg[ "qid" ] = qid;
|
||||||
|
}
|
||||||
|
|
||||||
m_spotifyResolver.data()->sendMessage( msg );
|
m_spotifyResolver.data()->sendMessage( msg );
|
||||||
}
|
}
|
||||||
@@ -413,9 +417,13 @@ SpotifyAccount::stopPlaylistSync( SpotifyPlaylistInfo* playlist )
|
|||||||
|
|
||||||
m_spotifyResolver.data()->sendMessage( msg );
|
m_spotifyResolver.data()->sendMessage( msg );
|
||||||
|
|
||||||
if ( deleteOnUnsync() && m_updaters.contains( playlist->plid ) )
|
if ( m_updaters.contains( playlist->plid ) )
|
||||||
|
{
|
||||||
|
SpotifyPlaylistUpdater* updater = m_updaters[ playlist->plid ];
|
||||||
|
updater->setSync( false );
|
||||||
|
|
||||||
|
if ( deleteOnUnsync() )
|
||||||
{
|
{
|
||||||
SpotifyPlaylistUpdater* updater = m_updaters.take( playlist->plid );
|
|
||||||
playlist_ptr tomahawkPl = updater->playlist();
|
playlist_ptr tomahawkPl = updater->playlist();
|
||||||
|
|
||||||
if ( !tomahawkPl.isNull() )
|
if ( !tomahawkPl.isNull() )
|
||||||
@@ -424,6 +432,9 @@ SpotifyAccount::stopPlaylistSync( SpotifyPlaylistInfo* playlist )
|
|||||||
updater->deleteLater();
|
updater->deleteLater();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updater->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -436,3 +447,18 @@ SpotifyAccount::loadPlaylists()
|
|||||||
msg[ "_msgtype" ] = "getAllPlaylists";
|
msg[ "_msgtype" ] = "getAllPlaylists";
|
||||||
sendMessage( msg, this, "allPlaylistsLoaded" );
|
sendMessage( msg, this, "allPlaylistsLoaded" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccount::setSyncForPlaylist( const QString& spotifyPlaylistId, bool sync )
|
||||||
|
{
|
||||||
|
foreach ( SpotifyPlaylistInfo* info, m_allSpotifyPlaylists )
|
||||||
|
{
|
||||||
|
if( info->plid == spotifyPlaylistId )
|
||||||
|
info->sync = sync;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !m_configWidget.isNull() )
|
||||||
|
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists );
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -85,7 +85,7 @@ public:
|
|||||||
virtual InfoSystem::InfoPlugin* infoPlugin() { return 0; }
|
virtual InfoSystem::InfoPlugin* infoPlugin() { return 0; }
|
||||||
virtual SipPlugin* sipPlugin() { return 0; }
|
virtual SipPlugin* sipPlugin() { return 0; }
|
||||||
|
|
||||||
void sendMessage( const QVariantMap& msg, QObject* receiver, const QString& slot );
|
void 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 );
|
||||||
@@ -105,6 +105,7 @@ private:
|
|||||||
void stopPlaylistSync( SpotifyPlaylistInfo* playlist );
|
void stopPlaylistSync( SpotifyPlaylistInfo* playlist );
|
||||||
void fetchFullPlaylist( SpotifyPlaylistInfo* playlist );
|
void fetchFullPlaylist( SpotifyPlaylistInfo* playlist );
|
||||||
|
|
||||||
|
void setSyncForPlaylist( const QString& spotifyPlaylistId, bool sync );
|
||||||
|
|
||||||
QWeakPointer<SpotifyAccountConfig> m_configWidget;
|
QWeakPointer<SpotifyAccountConfig> m_configWidget;
|
||||||
QWeakPointer<ScriptResolver> m_spotifyResolver;
|
QWeakPointer<ScriptResolver> m_spotifyResolver;
|
||||||
@@ -115,6 +116,7 @@ private:
|
|||||||
QList< SpotifyPlaylistInfo* > m_allSpotifyPlaylists;
|
QList< SpotifyPlaylistInfo* > m_allSpotifyPlaylists;
|
||||||
QHash< QString, SpotifyPlaylistUpdater* > m_updaters;
|
QHash< QString, SpotifyPlaylistUpdater* > m_updaters;
|
||||||
|
|
||||||
|
friend class ::SpotifyPlaylistUpdater;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -20,10 +20,15 @@
|
|||||||
|
|
||||||
#include "accounts/AccountManager.h"
|
#include "accounts/AccountManager.h"
|
||||||
#include "SpotifyAccount.h"
|
#include "SpotifyAccount.h"
|
||||||
|
#include "utils/tomahawkutils.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
using namespace Accounts;
|
using namespace Accounts;
|
||||||
|
|
||||||
|
#ifndef ENABLE_HEADLESS
|
||||||
|
QPixmap* SpotifyPlaylistUpdater::s_typePixmap = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
Tomahawk::PlaylistUpdaterInterface*
|
Tomahawk::PlaylistUpdaterInterface*
|
||||||
SpotifyUpdaterFactory::create( const Tomahawk::playlist_ptr& pl, const QString &key )
|
SpotifyUpdaterFactory::create( const Tomahawk::playlist_ptr& pl, const QString &key )
|
||||||
{
|
{
|
||||||
@@ -87,6 +92,17 @@ SpotifyPlaylistUpdater::~SpotifyPlaylistUpdater()
|
|||||||
{
|
{
|
||||||
if ( !m_spotify.isNull() )
|
if ( !m_spotify.isNull() )
|
||||||
{
|
{
|
||||||
|
if ( m_sync )
|
||||||
|
{
|
||||||
|
QVariantMap msg;
|
||||||
|
msg[ "_msgtype" ] = "removeFromSyncList";
|
||||||
|
msg[ "playlistid" ] = m_spotifyId;
|
||||||
|
|
||||||
|
m_spotify.data()->sendMessage( msg );
|
||||||
|
|
||||||
|
m_spotify.data()->setSyncForPlaylist( m_spotifyId, false );
|
||||||
|
}
|
||||||
|
|
||||||
m_spotify.data()->unregisterUpdater( m_spotifyId );
|
m_spotify.data()->unregisterUpdater( m_spotifyId );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,10 +133,33 @@ SpotifyPlaylistUpdater::type() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef ENABLE_HEADLESS
|
||||||
|
QPixmap
|
||||||
|
SpotifyPlaylistUpdater::typeIcon() const
|
||||||
|
{
|
||||||
|
if ( !s_typePixmap )
|
||||||
|
{
|
||||||
|
QPixmap pm( RESPATH "images/spotify-logo.png" );
|
||||||
|
s_typePixmap = new QPixmap( pm.scaled( 32, 32, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !m_sync )
|
||||||
|
return QPixmap();
|
||||||
|
|
||||||
|
return *s_typePixmap;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::setSync( bool sync )
|
SpotifyPlaylistUpdater::setSync( bool sync )
|
||||||
{
|
{
|
||||||
|
if ( m_sync == sync )
|
||||||
|
return;
|
||||||
|
|
||||||
m_sync = sync;
|
m_sync = sync;
|
||||||
|
|
||||||
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#define SPOTIFYPLAYLISTUPDATER_H
|
#define SPOTIFYPLAYLISTUPDATER_H
|
||||||
|
|
||||||
#include "playlist/PlaylistUpdaterInterface.h"
|
#include "playlist/PlaylistUpdaterInterface.h"
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
namespace Tomahawk {
|
namespace Tomahawk {
|
||||||
@@ -43,6 +44,8 @@ public:
|
|||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
virtual QWidget* configurationWidget() const { return 0; }
|
virtual QWidget* configurationWidget() const { return 0; }
|
||||||
|
|
||||||
|
virtual QPixmap typeIcon() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool sync() const;
|
bool sync() const;
|
||||||
@@ -78,6 +81,10 @@ private:
|
|||||||
|
|
||||||
bool m_blockUpdatesForNextRevision;
|
bool m_blockUpdatesForNextRevision;
|
||||||
bool m_sync;
|
bool m_sync;
|
||||||
|
|
||||||
|
#ifndef ENABLE_HEADLESS
|
||||||
|
static QPixmap* s_typePixmap;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -255,7 +255,7 @@ Playlist::setTitle( const QString& title )
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const QString oldTitle = m_title;
|
const QString oldTitle = m_title;
|
||||||
m_title = title;
|
// m_title = title;
|
||||||
|
|
||||||
emit changed();
|
emit changed();
|
||||||
emit renamed( m_title, oldTitle );
|
emit renamed( m_title, oldTitle );
|
||||||
@@ -282,6 +282,19 @@ Playlist::reportDeleted( const Tomahawk::playlist_ptr& self )
|
|||||||
emit deleted( self );
|
emit deleted( self );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Playlist::setUpdater( PlaylistUpdaterInterface* pluinterface )
|
||||||
|
{
|
||||||
|
if ( m_updater )
|
||||||
|
disconnect( m_updater, SIGNAL( changed() ), this, SIGNAL( changed() ) );
|
||||||
|
|
||||||
|
m_updater = pluinterface;
|
||||||
|
|
||||||
|
connect( m_updater, SIGNAL( changed() ), this, SIGNAL( changed() ), Qt::UniqueConnection );
|
||||||
|
|
||||||
|
emit changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Playlist::loadRevision( const QString& rev )
|
Playlist::loadRevision( const QString& rev )
|
||||||
|
@@ -188,7 +188,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
QList<plentry_ptr> entriesFromQueries( const QList<Tomahawk::query_ptr>& queries, bool clearFirst = false );
|
QList<plentry_ptr> entriesFromQueries( const QList<Tomahawk::query_ptr>& queries, bool clearFirst = false );
|
||||||
void setUpdater( PlaylistUpdaterInterface* pluinterface ) { m_updater = pluinterface; }
|
void setUpdater( PlaylistUpdaterInterface* pluinterface );
|
||||||
PlaylistUpdaterInterface* updater() const { return m_updater; }
|
PlaylistUpdaterInterface* updater() const { return m_updater; }
|
||||||
|
|
||||||
Tomahawk::playlistinterface_ptr playlistInterface();
|
Tomahawk::playlistinterface_ptr playlistInterface();
|
||||||
|
@@ -65,12 +65,12 @@ PlaylistUpdaterInterface::PlaylistUpdaterInterface( const playlist_ptr& pl )
|
|||||||
|
|
||||||
m_playlist->setUpdater( this );
|
m_playlist->setUpdater( this );
|
||||||
|
|
||||||
QTimer::singleShot( 0, this, SLOT( doSave() ) );
|
QTimer::singleShot( 0, this, SLOT( save() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistUpdaterInterface::doSave()
|
PlaylistUpdaterInterface::save()
|
||||||
{
|
{
|
||||||
TomahawkSettings* s = TomahawkSettings::instance();
|
TomahawkSettings* s = TomahawkSettings::instance();
|
||||||
const QString key = QString( "playlistupdaters/%1" ).arg( m_playlist->guid() );
|
const QString key = QString( "playlistupdaters/%1" ).arg( m_playlist->guid() );
|
||||||
|
@@ -26,6 +26,10 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
|
||||||
|
#ifndef ENABLE_HEADLESS
|
||||||
|
#include <QPixmap>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -50,6 +54,10 @@ public:
|
|||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
// Small widget to show in playlist header that configures the updater
|
// Small widget to show in playlist header that configures the updater
|
||||||
virtual QWidget* configurationWidget() const = 0;
|
virtual QWidget* configurationWidget() const = 0;
|
||||||
|
|
||||||
|
// Small overlay over playlist icon in the sidebar to indicate that it has this updater type
|
||||||
|
// Should be around 16x16 or something
|
||||||
|
virtual QPixmap typeIcon() const { return QPixmap(); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void remove();
|
void remove();
|
||||||
@@ -61,11 +69,14 @@ public:
|
|||||||
static PlaylistUpdaterInterface* loadForPlaylist( const playlist_ptr& pl );
|
static PlaylistUpdaterInterface* loadForPlaylist( const playlist_ptr& pl );
|
||||||
|
|
||||||
static void registerUpdaterFactory( PlaylistUpdaterFactory* f );
|
static void registerUpdaterFactory( PlaylistUpdaterFactory* f );
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void changed();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void updateNow() {}
|
virtual void updateNow() {}
|
||||||
|
|
||||||
private slots:
|
void save();
|
||||||
void doSave();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void saveToSettings( const QString& group ) const = 0;
|
virtual void saveToSettings( const QString& group ) const = 0;
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#include "playlistitems.h"
|
#include "playlistitems.h"
|
||||||
|
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
#include "viewmanager.h"
|
#include "viewmanager.h"
|
||||||
@@ -44,12 +45,15 @@ PlaylistItem::PlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, const pla
|
|||||||
connect( pl.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ),
|
connect( pl.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ),
|
||||||
SLOT( onPlaylistLoaded( Tomahawk::PlaylistRevision ) ), Qt::QueuedConnection );
|
SLOT( onPlaylistLoaded( Tomahawk::PlaylistRevision ) ), Qt::QueuedConnection );
|
||||||
connect( pl.data(), SIGNAL( changed() ),
|
connect( pl.data(), SIGNAL( changed() ),
|
||||||
SIGNAL( updated() ), Qt::QueuedConnection );
|
SLOT( onUpdated() ), Qt::QueuedConnection );
|
||||||
|
|
||||||
m_icon = QIcon( RESPATH "images/playlist-icon.png" );
|
m_icon = QIcon( RESPATH "images/playlist-icon.png" );
|
||||||
|
|
||||||
if( ViewManager::instance()->pageForPlaylist( pl ) )
|
if( ViewManager::instance()->pageForPlaylist( pl ) )
|
||||||
model()->linkSourceItemToPage( this, ViewManager::instance()->pageForPlaylist( pl ) );
|
model()->linkSourceItemToPage( this, ViewManager::instance()->pageForPlaylist( pl ) );
|
||||||
|
|
||||||
|
if ( m_playlist->updater() && !m_playlist->updater()->typeIcon().isNull() )
|
||||||
|
createOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -244,9 +248,53 @@ PlaylistItem::parsedDroppedTracks( const QList< query_ptr >& tracks )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistItem::onUpdated()
|
||||||
|
{
|
||||||
|
if ( m_playlist->updater() && !m_playlist->updater()->typeIcon().isNull() &&
|
||||||
|
m_overlaidIcon.isNull() ) // create overlay
|
||||||
|
{
|
||||||
|
createOverlay();
|
||||||
|
}
|
||||||
|
else if ( !m_playlist->updater() || m_playlist->updater()->typeIcon().isNull() &&
|
||||||
|
!m_overlaidIcon.isNull() )
|
||||||
|
{
|
||||||
|
// No longer an updater with an icon
|
||||||
|
m_overlaidIcon = QIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
emit updated();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistItem::createOverlay()
|
||||||
|
{
|
||||||
|
Q_ASSERT( !m_playlist.isNull() );
|
||||||
|
Q_ASSERT( m_playlist->updater() );
|
||||||
|
Q_ASSERT( !m_playlist->updater()->typeIcon().isNull() );
|
||||||
|
|
||||||
|
m_overlaidIcon = QIcon();
|
||||||
|
|
||||||
|
QPixmap base = m_icon.pixmap( 48, 48 );
|
||||||
|
const QPixmap overlay = m_playlist->updater()->typeIcon();
|
||||||
|
|
||||||
|
QPainter p( &base );
|
||||||
|
const int w = base.width() / 2;
|
||||||
|
const QRect overlayRect( base.rect().right() - w, base.rect().height() - w, w, w );
|
||||||
|
p.drawPixmap( overlayRect, overlay );
|
||||||
|
p.end();
|
||||||
|
|
||||||
|
m_overlaidIcon.addPixmap( base );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QIcon
|
QIcon
|
||||||
PlaylistItem::icon() const
|
PlaylistItem::icon() const
|
||||||
{
|
{
|
||||||
|
if ( !m_overlaidIcon.isNull() )
|
||||||
|
return m_overlaidIcon;
|
||||||
|
else
|
||||||
return m_icon;
|
return m_icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,10 +54,13 @@ private slots:
|
|||||||
void onPlaylistChanged();
|
void onPlaylistChanged();
|
||||||
void parsedDroppedTracks( const QList<Tomahawk::query_ptr>& tracks );
|
void parsedDroppedTracks( const QList<Tomahawk::query_ptr>& tracks );
|
||||||
|
|
||||||
|
void onUpdated();
|
||||||
private:
|
private:
|
||||||
|
void createOverlay();
|
||||||
|
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
Tomahawk::playlist_ptr m_playlist;
|
Tomahawk::playlist_ptr m_playlist;
|
||||||
QIcon m_icon;
|
QIcon m_icon, m_overlaidIcon;
|
||||||
};
|
};
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(PlaylistItem::DropTypes)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(PlaylistItem::DropTypes)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user