mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 15:47:38 +02:00
More work towards playlists
This commit is contained in:
@@ -80,6 +80,8 @@ SpotifyAccount::SpotifyAccount( const QString& accountId, const QString& path )
|
|||||||
void
|
void
|
||||||
SpotifyAccount::init()
|
SpotifyAccount::init()
|
||||||
{
|
{
|
||||||
|
qRegisterMetaType< Tomahawk::Accounts::SpotifyPlaylist* >( "Tomahawk::Accounts::SpotifyPlaylist*" );
|
||||||
|
|
||||||
m_spotifyResolver = dynamic_cast< ScriptResolver* >( m_resolver.data() );
|
m_spotifyResolver = dynamic_cast< ScriptResolver* >( m_resolver.data() );
|
||||||
|
|
||||||
connect( m_spotifyResolver.data(), SIGNAL( customMessage( QString,QVariantMap ) ), this, SLOT( resolverMessage( QString, QVariantMap ) ) );
|
connect( m_spotifyResolver.data(), SIGNAL( customMessage( QString,QVariantMap ) ), this, SLOT( resolverMessage( QString, QVariantMap ) ) );
|
||||||
@@ -92,6 +94,9 @@ SpotifyAccount::init()
|
|||||||
msg[ "_msgtype" ] = "getCredentials";
|
msg[ "_msgtype" ] = "getCredentials";
|
||||||
m_spotifyResolver.data()->sendMessage( msg );
|
m_spotifyResolver.data()->sendMessage( msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO add caching
|
||||||
|
loadPlaylists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -111,6 +116,63 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
|
|||||||
config[ "hasMigrated" ] = true;
|
config[ "hasMigrated" ] = true;
|
||||||
setConfiguration( config );
|
setConfiguration( config );
|
||||||
sync();
|
sync();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const QString qid = msg.value( "qid" ).toString();
|
||||||
|
if ( m_qidToSlotMap.contains( qid ) )
|
||||||
|
{
|
||||||
|
const QString& slot = m_qidToSlotMap[ qid ];
|
||||||
|
m_qidToSlotMap.remove( qid );
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod( this, slot.toLatin1(), Q_ARG( QString, msgType ), Q_ARG( QVariantMap, msg ) );
|
||||||
|
}
|
||||||
|
else if ( msgType == "allPlaylists" )
|
||||||
|
{
|
||||||
|
const QVariantList playlists = msg.value( "playlists" ).toList();
|
||||||
|
qDeleteAll( m_allSpotifyPlaylists );
|
||||||
|
m_allSpotifyPlaylists.clear();
|
||||||
|
|
||||||
|
foreach ( const QVariant& playlist, playlists )
|
||||||
|
{
|
||||||
|
const QVariantMap plMap = playlist.toMap();
|
||||||
|
const QString name = plMap.value( "name" ).toString();
|
||||||
|
const QString plid = plMap.value( "id" ).toString();
|
||||||
|
const QString revid = plMap.value( "revid" ).toString();
|
||||||
|
const bool sync = plMap.value( "map" ).toBool();
|
||||||
|
|
||||||
|
if ( name.isNull() || plid.isNull() || revid.isNull() )
|
||||||
|
{
|
||||||
|
qDebug() << "Did not get name and plid and revid for spotify playlist:" << name << plid << revid << plMap;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
m_allSpotifyPlaylists << new SpotifyPlaylist( name, plid, revid, sync );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !m_configWidget.isNull() )
|
||||||
|
{
|
||||||
|
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( msgType == "playlists" )
|
||||||
|
{
|
||||||
|
// QList< Tomahawk::query_ptr > tracks;
|
||||||
|
// const QString qid = m.value( "qid" ).toString();
|
||||||
|
// const QString title = m.value( "identifier" ).toString();
|
||||||
|
// const QVariantList reslist = m.value( "playlist" ).toList();
|
||||||
|
|
||||||
|
// if( !reslist.isEmpty() )
|
||||||
|
// {
|
||||||
|
// foreach( const QVariant& rv, reslist )
|
||||||
|
// {
|
||||||
|
// QVariantMap m = rv.toMap();
|
||||||
|
// qDebug() << "Found playlist result:" << m;
|
||||||
|
// Tomahawk::query_ptr q = Tomahawk::Query::get( m.value( "artist" ).toString() , m.value( "track" ).toString() , QString(), uuid(), false );
|
||||||
|
// tracks << q;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,14 +206,26 @@ SpotifyAccount::saveConfig()
|
|||||||
if ( m_configWidget.isNull() )
|
if ( m_configWidget.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Send the result to the resolver
|
QVariantHash creds = credentials();
|
||||||
QVariantMap msg;
|
if ( creds.value( "username" ).toString() != m_configWidget.data()->username() ||
|
||||||
msg[ "_msgtype" ] = "saveSettings";
|
creds.value( "password" ).toString() != m_configWidget.data()->password() ||
|
||||||
msg[ "username" ] = m_configWidget.data()->username();
|
creds.value( "highQuality" ).toBool() != m_configWidget.data()->highQuality() )
|
||||||
msg[ "password" ] = m_configWidget.data()->password();
|
{
|
||||||
msg[ "highQuality" ] = m_configWidget.data()->highQuality();
|
creds[ "username" ] = m_configWidget.data()->username();
|
||||||
|
creds[ "password" ] = m_configWidget.data()->password();
|
||||||
|
creds[ "highQuality" ] = m_configWidget.data()->highQuality();
|
||||||
|
setCredentials( creds );
|
||||||
|
sync();
|
||||||
|
|
||||||
m_spotifyResolver.data()->sendMessage( msg );
|
// Send the result to the resolver
|
||||||
|
QVariantMap msg;
|
||||||
|
msg[ "_msgtype" ] = "saveSettings";
|
||||||
|
msg[ "username" ] = m_configWidget.data()->username();
|
||||||
|
msg[ "password" ] = m_configWidget.data()->password();
|
||||||
|
msg[ "highQuality" ] = m_configWidget.data()->highQuality();
|
||||||
|
|
||||||
|
m_spotifyResolver.data()->sendMessage( msg );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -208,6 +282,29 @@ SpotifyAccount::addPlaylist( const QString &qid, const QString& title, QList< To
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccount::sendMessage( const QVariantMap &m, const QString& slot )
|
||||||
|
{
|
||||||
|
QVariantMap msg = m;
|
||||||
|
const QString qid = QUuid::createUuid().toString().replace( "{", "" ).replace( "}", "" );
|
||||||
|
|
||||||
|
m_qidToSlotMap[ qid ] = slot;
|
||||||
|
msg[ "qid" ] = qid;
|
||||||
|
|
||||||
|
m_spotifyResolver.data()->sendMessage( msg );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccount::loadPlaylists()
|
||||||
|
{
|
||||||
|
// TODO cache this and only get changed?
|
||||||
|
QVariantMap msg;
|
||||||
|
msg[ "_msgtype" ] = "getAllPlaylists";
|
||||||
|
sendMessage( msg, "allPlaylistsLoaded" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
operator==( Accounts::SpotifyAccount::Sync one, Accounts::SpotifyAccount::Sync two )
|
operator==( Accounts::SpotifyAccount::Sync one, Accounts::SpotifyAccount::Sync two )
|
||||||
{
|
{
|
||||||
|
@@ -34,6 +34,16 @@ namespace Accounts {
|
|||||||
|
|
||||||
class SpotifyAccountConfig;
|
class SpotifyAccountConfig;
|
||||||
|
|
||||||
|
struct SpotifyPlaylist {
|
||||||
|
QString name, plid, revid;
|
||||||
|
bool sync;
|
||||||
|
|
||||||
|
SpotifyPlaylist( const QString& nname, const QString& pid, const QString& rrevid, bool ssync )
|
||||||
|
: name( nname ), plid( pid ), revid( rrevid ), sync( ssync ) {}
|
||||||
|
|
||||||
|
SpotifyPlaylist() : sync( false ) {}
|
||||||
|
};
|
||||||
|
|
||||||
class SpotifyAccountFactory : public AccountFactory
|
class SpotifyAccountFactory : public AccountFactory
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -82,15 +92,25 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void resolverMessage( const QString& msgType, const QVariantMap& msg );
|
void resolverMessage( const QString& msgType, const QVariantMap& msg );
|
||||||
|
|
||||||
|
// SpotifyResolver message handlers, all take msgtype, msg as argument
|
||||||
|
// void <here>( const QString& msgType, const QVariantMap& msg );
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
|
void loadPlaylists();
|
||||||
|
void sendMessage( const QVariantMap& msg, const QString& slot );
|
||||||
|
|
||||||
QList<Sync> m_syncPlaylists;
|
QList<Sync> m_syncPlaylists;
|
||||||
QWeakPointer<SpotifyAccountConfig> m_configWidget;
|
QWeakPointer<SpotifyAccountConfig> m_configWidget;
|
||||||
QWeakPointer<ScriptResolver> m_spotifyResolver;
|
QWeakPointer<ScriptResolver> m_spotifyResolver;
|
||||||
|
|
||||||
|
QMap<QString, QString> m_qidToSlotMap;
|
||||||
|
|
||||||
|
QList< SpotifyPlaylist* > m_allSpotifyPlaylists;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE( Tomahawk::Accounts::SpotifyPlaylist* );
|
||||||
|
|
||||||
#endif // SpotifyAccount_H
|
#endif // SpotifyAccount_H
|
||||||
|
@@ -3,6 +3,9 @@
|
|||||||
#include "SpotifyAccount.h"
|
#include "SpotifyAccount.h"
|
||||||
#include "ui_SpotifyAccountConfig.h"
|
#include "ui_SpotifyAccountConfig.h"
|
||||||
|
|
||||||
|
#include <QListWidget>
|
||||||
|
#include <QListWidgetItem>
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
using namespace Accounts;
|
using namespace Accounts;
|
||||||
|
|
||||||
@@ -25,6 +28,17 @@ SpotifyAccountConfig::loadFromConfig()
|
|||||||
m_ui->streamingCheckbox->setChecked( m_account->credentials().value( "highQuality" ).toBool() );
|
m_ui->streamingCheckbox->setChecked( m_account->credentials().value( "highQuality" ).toBool() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccountConfig::saveSettings()
|
||||||
|
{
|
||||||
|
for( int i = 0; i < m_ui->playlistList->count(); i++ )
|
||||||
|
{
|
||||||
|
const QListWidgetItem* item = m_ui->playlistList->itemAt( i, 0 );
|
||||||
|
SpotifyPlaylist* pl = item->data( Qt::UserRole ).value< SpotifyPlaylist* >();
|
||||||
|
pl->sync = ( item->checkState() == Qt::Checked );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
SpotifyAccountConfig::username() const
|
SpotifyAccountConfig::username() const
|
||||||
@@ -43,3 +57,17 @@ SpotifyAccountConfig::highQuality() const
|
|||||||
{
|
{
|
||||||
return m_ui->streamingCheckbox->isChecked();
|
return m_ui->streamingCheckbox->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccountConfig::setPlaylists( const QList<SpotifyPlaylist *>& playlists )
|
||||||
|
{
|
||||||
|
m_ui->playlistList->clear();
|
||||||
|
foreach ( SpotifyPlaylist* pl, playlists )
|
||||||
|
{
|
||||||
|
QListWidgetItem* item = new QListWidgetItem( pl->name, m_ui->playlistList );
|
||||||
|
item->setData( Qt::UserRole, QVariant::fromValue< SpotifyPlaylist* >( pl ) );
|
||||||
|
item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled );
|
||||||
|
item->setCheckState( pl->sync ? Qt::Checked : Qt::Unchecked );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -14,6 +14,7 @@ namespace Accounts
|
|||||||
{
|
{
|
||||||
|
|
||||||
class SpotifyAccount;
|
class SpotifyAccount;
|
||||||
|
struct SpotifyPlaylist;
|
||||||
|
|
||||||
class SpotifyAccountConfig : public QWidget
|
class SpotifyAccountConfig : public QWidget
|
||||||
{
|
{
|
||||||
@@ -25,9 +26,10 @@ public:
|
|||||||
QString password() const;
|
QString password() const;
|
||||||
bool highQuality() const;
|
bool highQuality() const;
|
||||||
|
|
||||||
QStringList playlistsToSync() const;
|
void setPlaylists( const QList< SpotifyPlaylist* >& playlists );
|
||||||
|
|
||||||
void loadFromConfig();
|
void loadFromConfig();
|
||||||
|
void saveSettings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::SpotifyConfig* m_ui;
|
Ui::SpotifyConfig* m_ui;
|
||||||
|
@@ -158,7 +158,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListWidget" name="listWidget"/>
|
<widget class="QListWidget" name="playlistList"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
@@ -273,25 +273,6 @@ ScriptResolver::handleMsg( const QByteArray& msg )
|
|||||||
|
|
||||||
Tomahawk::Pipeline::instance()->reportResults( qid, results );
|
Tomahawk::Pipeline::instance()->reportResults( qid, results );
|
||||||
}
|
}
|
||||||
else if ( msgtype == "playlist" )
|
|
||||||
{
|
|
||||||
|
|
||||||
QList< Tomahawk::query_ptr > tracks;
|
|
||||||
const QString qid = m.value( "qid" ).toString();
|
|
||||||
const QString title = m.value( "identifier" ).toString();
|
|
||||||
const QVariantList reslist = m.value( "playlist" ).toList();
|
|
||||||
|
|
||||||
if( !reslist.isEmpty() )
|
|
||||||
{
|
|
||||||
foreach( const QVariant& rv, reslist )
|
|
||||||
{
|
|
||||||
QVariantMap m = rv.toMap();
|
|
||||||
qDebug() << "Found playlist result:" << m;
|
|
||||||
Tomahawk::query_ptr q = Tomahawk::Query::get( m.value( "artist" ).toString() , m.value( "track" ).toString() , QString(), uuid(), false );
|
|
||||||
tracks << q;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Unknown message, give up for custom implementations
|
// Unknown message, give up for custom implementations
|
||||||
|
Reference in New Issue
Block a user