mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 19:30:21 +02:00
Migrate spotify config to tomahawk, and set up for playlist work
This commit is contained in:
BIN
data/images/spotifycore-logo.png
Normal file
BIN
data/images/spotifycore-logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.9 KiB |
@@ -135,6 +135,7 @@
|
||||
<file>data/images/rdio.png</file>
|
||||
<file>data/images/grooveshark.png</file>
|
||||
<file>data/images/lastfm-icon.png</file>
|
||||
<file>data/images/spotifycore-logo.png</file>
|
||||
<file>data/sql/dbmigrate-27_to_28.sql</file>
|
||||
<file>data/images/process-stop.png</file>
|
||||
</qresource>
|
||||
|
@@ -77,6 +77,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
|
||||
accounts/lastfm/lastfmplugin.cpp
|
||||
|
||||
accounts/spotify/SpotifyAccount.cpp
|
||||
accounts/spotify/SpotifyAccountConfig.cpp
|
||||
|
||||
tomahawktrayicon.cpp
|
||||
audiocontrols.cpp
|
||||
@@ -98,6 +99,7 @@ SET( tomahawkUI ${tomahawkUI}
|
||||
proxydialog.ui
|
||||
|
||||
accounts/lastfm/LastFmConfig.ui
|
||||
accounts/spotify/SpotifyAccountConfig.ui
|
||||
|
||||
audiocontrols.ui
|
||||
|
||||
|
@@ -94,5 +94,3 @@ private:
|
||||
}
|
||||
|
||||
#endif // LASTFMPLUGIN_H
|
||||
|
||||
class A;
|
||||
|
@@ -22,7 +22,8 @@
|
||||
#include "utils/tomahawkutils.h"
|
||||
#include "playlist/PlaylistUpdaterInterface.h"
|
||||
#include "sourcelist.h"
|
||||
|
||||
#include "SpotifyAccountConfig.h"
|
||||
#include "resolvers/scriptresolver.h"
|
||||
#include <QPixmap>
|
||||
|
||||
using namespace Tomahawk;
|
||||
@@ -65,14 +66,52 @@ SpotifyAccountFactory::icon() const
|
||||
SpotifyAccount::SpotifyAccount( const QString& accountId )
|
||||
: ResolverAccount( accountId )
|
||||
{
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
SpotifyAccount::SpotifyAccount( const QString& accountId, const QString& path )
|
||||
: ResolverAccount( accountId, path )
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SpotifyAccount::init()
|
||||
{
|
||||
m_spotifyResolver = dynamic_cast< ScriptResolver* >( m_resolver.data() );
|
||||
|
||||
connect( m_spotifyResolver.data(), SIGNAL( customMessage( QString,QVariantMap ) ), this, SLOT( resolverMessage( QString, QVariantMap ) ) );
|
||||
|
||||
const bool hasMigrated = configuration().value( "hasMigrated" ).toBool();
|
||||
if ( !hasMigrated )
|
||||
{
|
||||
qDebug() << "Getting credentials from spotify resolver to migrate to in-app config";
|
||||
QVariantMap msg;
|
||||
msg[ "_msgtype" ] = "getCredentials";
|
||||
m_spotifyResolver.data()->sendMessage( msg );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg )
|
||||
{
|
||||
if ( msgType == "credentials" )
|
||||
{
|
||||
QVariantHash creds = credentials();
|
||||
creds[ "username" ] = msg.value( "username" );
|
||||
creds[ "password" ] = msg.value( "password" );
|
||||
creds[ "highQuality" ] = msg.value( "highQuality" );
|
||||
setCredentials( creds );
|
||||
sync();
|
||||
|
||||
QVariantHash config = configuration();
|
||||
config[ "hasMigrated" ] = true;
|
||||
setConfiguration( config );
|
||||
sync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +125,36 @@ SpotifyAccount::icon() const
|
||||
}
|
||||
|
||||
|
||||
QWidget*
|
||||
SpotifyAccount::configurationWidget()
|
||||
{
|
||||
if ( m_configWidget.isNull() )
|
||||
m_configWidget = QWeakPointer< SpotifyAccountConfig >( new SpotifyAccountConfig( this ) );
|
||||
else
|
||||
m_configWidget.data()->loadFromConfig();
|
||||
|
||||
return static_cast< QWidget* >( m_configWidget.data() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SpotifyAccount::saveConfig()
|
||||
{
|
||||
Q_ASSERT( !m_configWidget.isNull() );
|
||||
if ( m_configWidget.isNull() )
|
||||
return;
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SpotifyAccount::addPlaylist( const QString &qid, const QString& title, QList< Tomahawk::query_ptr > tracks )
|
||||
{
|
||||
@@ -140,7 +209,7 @@ SpotifyAccount::addPlaylist( const QString &qid, const QString& title, QList< To
|
||||
|
||||
|
||||
bool
|
||||
operator==( Tomahawk::Accounts::SpotifyAccount::Sync one, Tomahawk::Accounts::SpotifyAccount::Sync two )
|
||||
operator==( Accounts::SpotifyAccount::Sync one, Accounts::SpotifyAccount::Sync two )
|
||||
{
|
||||
if( one.id_ == two.id_ )
|
||||
return true;
|
||||
|
@@ -27,12 +27,12 @@
|
||||
|
||||
class QTimer;
|
||||
|
||||
class ScriptResolver;
|
||||
|
||||
namespace Tomahawk {
|
||||
|
||||
class ExternalResolverGui;
|
||||
|
||||
namespace Accounts {
|
||||
|
||||
class SpotifyAccountConfig;
|
||||
|
||||
class SpotifyAccountFactory : public AccountFactory
|
||||
{
|
||||
@@ -64,6 +64,8 @@ public:
|
||||
virtual ~SpotifyAccount() {}
|
||||
|
||||
virtual QPixmap icon() const;
|
||||
virtual QWidget* configurationWidget();
|
||||
virtual void saveConfig();
|
||||
|
||||
virtual QWidget* aclWidget() { return 0; }
|
||||
virtual InfoSystem::InfoPlugin* infoPlugin() { return 0; }
|
||||
@@ -77,11 +79,18 @@ public:
|
||||
Tomahawk::playlist_ptr playlist;
|
||||
};
|
||||
|
||||
private:
|
||||
QList<Sync> m_syncPlaylists;
|
||||
};
|
||||
}
|
||||
private slots:
|
||||
void resolverMessage( const QString& msgType, const QVariantMap& msg );
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
QList<Sync> m_syncPlaylists;
|
||||
QWeakPointer<SpotifyAccountConfig> m_configWidget;
|
||||
QWeakPointer<ScriptResolver> m_spotifyResolver;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SpotifyAccount_H
|
||||
|
45
src/accounts/spotify/SpotifyAccountConfig.cpp
Normal file
45
src/accounts/spotify/SpotifyAccountConfig.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "SpotifyAccountConfig.h"
|
||||
|
||||
#include "SpotifyAccount.h"
|
||||
#include "ui_SpotifyAccountConfig.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
using namespace Accounts;
|
||||
|
||||
SpotifyAccountConfig::SpotifyAccountConfig( SpotifyAccount *account )
|
||||
: QWidget( 0 )
|
||||
, m_ui( new Ui::SpotifyConfig )
|
||||
, m_account( account )
|
||||
{
|
||||
m_ui->setupUi( this );
|
||||
|
||||
loadFromConfig();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SpotifyAccountConfig::loadFromConfig()
|
||||
{
|
||||
m_ui->usernameEdit->setText( m_account->credentials().value( "username" ).toString() );
|
||||
m_ui->passwordEdit->setText( m_account->credentials().value( "password" ).toString() );
|
||||
m_ui->streamingCheckbox->setChecked( m_account->credentials().value( "highQuality" ).toBool() );
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
SpotifyAccountConfig::username() const
|
||||
{
|
||||
return m_ui->usernameEdit->text().trimmed();
|
||||
}
|
||||
|
||||
QString
|
||||
SpotifyAccountConfig::password() const
|
||||
{
|
||||
return m_ui->passwordEdit->text().trimmed();
|
||||
}
|
||||
|
||||
bool
|
||||
SpotifyAccountConfig::highQuality() const
|
||||
{
|
||||
return m_ui->streamingCheckbox->isChecked();
|
||||
}
|
41
src/accounts/spotify/SpotifyAccountConfig.h
Normal file
41
src/accounts/spotify/SpotifyAccountConfig.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef SPOTIFYACCOUNTCONFIG_H
|
||||
#define SPOTIFYACCOUNTCONFIG_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class SpotifyConfig;
|
||||
}
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
namespace Accounts
|
||||
{
|
||||
|
||||
class SpotifyAccount;
|
||||
|
||||
class SpotifyAccountConfig : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SpotifyAccountConfig( SpotifyAccount* account );
|
||||
|
||||
QString username() const;
|
||||
QString password() const;
|
||||
bool highQuality() const;
|
||||
|
||||
QStringList playlistsToSync() const;
|
||||
|
||||
void loadFromConfig();
|
||||
|
||||
private:
|
||||
Ui::SpotifyConfig* m_ui;
|
||||
SpotifyAccount* m_account;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SPOTIFYACCOUNTCONFIG_H
|
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>397</width>
|
||||
<height>487</height>
|
||||
<width>457</width>
|
||||
<height>479</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@@ -20,21 +20,33 @@
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="icon">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap>spotify-logo.png</pixmap>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<property name="margin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="icon">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../../../resources.qrc">:/data/images/spotify-logo.png</pixmap>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="titleText">
|
||||
<property name="font">
|
||||
@@ -45,7 +57,7 @@
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Configure your Spotify credentials</string>
|
||||
<string>Configure your Spotify account</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
@@ -69,7 +81,10 @@
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="usernameEdit">
|
||||
<property name="text">
|
||||
<string>placeholderUsername</string>
|
||||
<string/>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Username or Facebook Email</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -83,7 +98,7 @@
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="passwordEdit">
|
||||
<property name="text">
|
||||
<string>placeholderPw</string>
|
||||
<string/>
|
||||
</property>
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
@@ -95,7 +110,7 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
@@ -113,15 +128,15 @@
|
||||
<enum>Qt::RightToLeft</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>High Quality Streaming</string>
|
||||
<string>High Quality Streams</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>STREAMING_DEFAULT</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_6">
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
@@ -135,6 +150,16 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Spotify playlists to keep in sync:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
@@ -152,11 +177,35 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="spotifyLogo">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap>spotifycore-logo.png</pixmap>
|
||||
<pixmap resource="../../../resources.qrc">:/data/images/spotifycore-logo.png</pixmap>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>9</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>This product uses SPOTIFY(R) CORE but is not endorsed, certified or otherwise approved in any way by Spotify. Spotify is the registered trade mark of the Spotify Group.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -175,25 +224,10 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>9</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>This product uses SPOTIFY(R) CORE but is not endorsed, certified or otherwise approved in any way by Spotify. Spotify is the registered trade mark of the Spotify Group.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="resources.qrc"/>
|
||||
<include location="../../../resources.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@@ -144,6 +144,13 @@ ScriptResolver::running() const
|
||||
return !m_stopped;
|
||||
}
|
||||
|
||||
void
|
||||
ScriptResolver::sendMessage( const QVariantMap& map )
|
||||
{
|
||||
QByteArray data = m_serializer.serialize( map );
|
||||
sendMsg( data );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptResolver::readStderr()
|
||||
@@ -285,6 +292,11 @@ ScriptResolver::handleMsg( const QByteArray& msg )
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unknown message, give up for custom implementations
|
||||
emit customMessage( msgtype, m );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -54,8 +54,11 @@ public:
|
||||
|
||||
virtual bool running() const;
|
||||
|
||||
void sendMessage( const QVariantMap& map );
|
||||
|
||||
signals:
|
||||
void terminated();
|
||||
void customMessage( const QString& msgType, const QVariantMap& msg );
|
||||
|
||||
public slots:
|
||||
virtual void stop();
|
||||
|
@@ -150,8 +150,3 @@ Q_DECLARE_METATYPE( QPersistentModelIndex )
|
||||
Q_DECLARE_METATYPE( PairList )
|
||||
|
||||
#endif // TOMAHAWKAPP_H
|
||||
|
||||
|
||||
struct A;
|
||||
|
||||
struct A;
|
||||
|
Reference in New Issue
Block a user