1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

Beginning of a bad spotifyAccount

This commit is contained in:
Hugo Lindström 2012-02-24 16:53:33 +01:00
parent d0b6d09255
commit 6a6f5dba7a
5 changed files with 188 additions and 3 deletions

@ -310,6 +310,7 @@ set( libSources
accounts/ResolverAccount.cpp
accounts/LastFmAccount.cpp
accounts/LastFmConfig.cpp
accounts/SpotifyAccount.cpp
sip/SipPlugin.cpp
sip/SipHandler.cpp
@ -454,7 +455,7 @@ set( libHeaders
accounts/ResolverAccount.h
accounts/LastFmAccount.h
accounts/LastFmConfig.h
accounts/SpotifyAccount.h
EchonestCatalogSynchronizer.h
sip/SipPlugin.h

@ -0,0 +1,93 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SpotifyAccount.h"
#include "playlist.h"
#include "utils/tomahawkutils.h"
#include "PlaylistUpdaterInterface.h"
#include "sourcelist.h"
using namespace Tomahawk;
using namespace Accounts;
SpotifyResolverAccount::SpotifyResolverAccount()
{
qDebug() << Q_FUNC_INFO;
}
SpotifyResolverAccount::~SpotifyResolverAccount()
{
qDebug() << Q_FUNC_INFO;
}
void
SpotifyResolverAccount::addPlaylist(const QString &qid, const QString& title, QList< Tomahawk::query_ptr > tracks)
{
Sync sync;
sync.id_ = qid;
int index = m_syncPlaylists.indexOf( sync );
if( !m_syncPlaylists.contains( sync ) )
{
qDebug() << Q_FUNC_INFO << "Adding playlist to sync" << qid;
playlist_ptr pl;
pl = Tomahawk::Playlist::create( SourceList::instance()->getLocal(),
uuid(),
title,
QString(),
QString(),
false,
tracks );
sync.playlist = pl;
sync.uuid = pl->guid();
m_syncPlaylists.append( sync );
}
else{
qDebug() << Q_FUNC_INFO << "Found playlist";
if( index != -1 && !tracks.isEmpty())
{
qDebug() << Q_FUNC_INFO << "Got pl" << m_syncPlaylists[ index ].playlist->guid();
QList< query_ptr > currTracks;
foreach ( const plentry_ptr ple, m_syncPlaylists[ index ].playlist->entries() )
currTracks << ple->query();
qDebug() << Q_FUNC_INFO << "tracks" << currTracks;
QList< query_ptr > mergedTracks = TomahawkUtils::mergePlaylistChanges( currTracks, tracks );
QList<Tomahawk::plentry_ptr> el = m_syncPlaylists[ index ].playlist->entriesFromQueries( mergedTracks, true );
m_syncPlaylists[ index ].playlist->createNewRevision( uuid(), m_syncPlaylists[ index ].playlist->currentrevision(), el );
}
}
}
bool operator==(SpotifyResolverAccount::Sync one, SpotifyResolverAccount::Sync two)
{
if(one.id_ == two.id_)
return true;
return false;
}

@ -0,0 +1,67 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SpotifyAccount_H
#define SpotifyAccount_H
#include "playlist.h"
#include "utils/tomahawkutils.h"
#include "sourcelist.h"
#include "ResolverAccount.h"
class QTimer;
namespace Tomahawk {
class ExternalResolverGui;
namespace Accounts {
class SpotifyResolverAccount : public QObject // : public AccountFactory
{
Q_OBJECT
public:
SpotifyResolverAccount();
virtual ~SpotifyResolverAccount();
/*virtual Account* createAccount(const QString& accountId = QString());
virtual QString description() const { return tr( "Play and sync your playlists with Spotify" ); }
virtual QString factoryId() const { return "spotifyaccount"; }
virtual QString prettyName() const { return "Spotify"; }
virtual AccountTypes types() const { return AccountTypes( ResolverType ); }
virtual bool allowUserCreation() const { return false; }
virtual QPixmap icon() const { return m_icon; }
virtual bool isUnique() const { return true; }
*/
void addPlaylist(const QString &qid, const QString& title, QList< Tomahawk::query_ptr > tracks);
struct Sync {
QString id_;
QString uuid;
Tomahawk::playlist_ptr playlist;
};
private:
QList<Sync> m_syncPlaylists;
int m_sCount;
};
}
}
#endif // SpotifyAccount_H

@ -55,6 +55,7 @@ ScriptResolver::ScriptResolver( const QString& exe )
// set the name to the binary, if we launch properly we'll get the name the resolver reports
m_name = QFileInfo( filePath() ).baseName();
m_account = new Tomahawk::Accounts::SpotifyResolverAccount();
}
@ -228,7 +229,7 @@ ScriptResolver::handleMsg( const QByteArray& msg )
return;
}
if ( msgtype == "results" )
else if ( msgtype == "results" )
{
const QString qid = m.value( "qid" ).toString();
QList< Tomahawk::result_ptr > results;
@ -265,6 +266,28 @@ ScriptResolver::handleMsg( const QByteArray& msg )
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;
}
if(m_account)
m_account->addPlaylist( qid, title, tracks);
}
}
}

@ -27,7 +27,7 @@
#include "query.h"
#include "ExternalResolverGui.h"
#include "accounts/SpotifyAccount.h"
#include "dllmacro.h"
class QWidget;
@ -90,6 +90,7 @@ private:
QJson::Parser m_parser;
QJson::Serializer m_serializer;
Tomahawk::Accounts::SpotifyResolverAccount *m_account;
};
#endif // SCRIPTRESOLVER_H