From b2612f918971643b89e12923ec76a437d4241bfb Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sun, 18 Mar 2012 14:56:38 -0400 Subject: [PATCH] some further work --- src/accounts/spotify/SpotifyAccount.cpp | 47 +++++++++++++++---- src/accounts/spotify/SpotifyAccount.h | 15 +++--- src/accounts/spotify/SpotifyAccountConfig.cpp | 25 +++++++++- src/accounts/spotify/SpotifyAccountConfig.h | 20 +++++++- 4 files changed, 91 insertions(+), 16 deletions(-) diff --git a/src/accounts/spotify/SpotifyAccount.cpp b/src/accounts/spotify/SpotifyAccount.cpp index cf2de46d5..52f07c37b 100644 --- a/src/accounts/spotify/SpotifyAccount.cpp +++ b/src/accounts/spotify/SpotifyAccount.cpp @@ -110,13 +110,16 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg creds[ "password" ] = msg.value( "password" ); creds[ "highQuality" ] = msg.value( "highQuality" ); setCredentials( creds ); - sync(); + + qDebug() << "Set creds:" << creds.value( "username" ) << creds.value( "password" ) << msg.value( "username" ) << msg.value( "password" ); QVariantHash config = configuration(); config[ "hasMigrated" ] = true; setConfiguration( config ); sync(); + qDebug() << "SET SPOTIFY CREDS:" << credentials().value( "username" ) << credentials().value( "password" ); + return; } @@ -226,6 +229,19 @@ SpotifyAccount::saveConfig() m_spotifyResolver.data()->sendMessage( msg ); } + + m_configWidget.data()->saveSettings(); + foreach ( SpotifyPlaylist* pl, m_allSpotifyPlaylists ) + { + if ( pl->changed ) + { + pl->changed = false; + if ( pl->sync ) + startPlaylistSync( pl ); + else + stopPlaylistSync( pl ); + } + } } @@ -295,6 +311,21 @@ SpotifyAccount::sendMessage( const QVariantMap &m, const QString& slot ) } +void +SpotifyAccount::startPlaylistSync( SpotifyPlaylist* playlist ) +{ + +} + + +void +SpotifyAccount::stopPlaylistSync( SpotifyPlaylist* playlist ) +{ + +} + + + void SpotifyAccount::loadPlaylists() { @@ -305,10 +336,10 @@ SpotifyAccount::loadPlaylists() } -bool -operator==( Accounts::SpotifyAccount::Sync one, Accounts::SpotifyAccount::Sync two ) -{ - if( one.id_ == two.id_ ) - return true; - return false; -} +// bool +// operator==( Accounts::SpotifyAccount::Sync one, Accounts::SpotifyAccount::Sync two ) +// { +// if( one.id_ == two.id_ ) +// return true; +// return false; +// } diff --git a/src/accounts/spotify/SpotifyAccount.h b/src/accounts/spotify/SpotifyAccount.h index 2086c17f8..1badb2f49 100644 --- a/src/accounts/spotify/SpotifyAccount.h +++ b/src/accounts/spotify/SpotifyAccount.h @@ -36,12 +36,12 @@ class SpotifyAccountConfig; struct SpotifyPlaylist { QString name, plid, revid; - bool sync; + bool sync, changed; SpotifyPlaylist( const QString& nname, const QString& pid, const QString& rrevid, bool ssync ) - : name( nname ), plid( pid ), revid( rrevid ), sync( ssync ) {} + : name( nname ), plid( pid ), revid( rrevid ), sync( ssync ), changed( false ) {} - SpotifyPlaylist() : sync( false ) {} + SpotifyPlaylist() : sync( false ), changed( false ) {} }; class SpotifyAccountFactory : public AccountFactory @@ -82,12 +82,12 @@ public: virtual SipPlugin* sipPlugin() { return 0; } void addPlaylist( const QString &qid, const QString& title, QList< Tomahawk::query_ptr > tracks ); - +/* struct Sync { QString id_; QString uuid; Tomahawk::playlist_ptr playlist; - }; + };*/ private slots: void resolverMessage( const QString& msgType, const QVariantMap& msg ); @@ -99,7 +99,10 @@ private: void loadPlaylists(); void sendMessage( const QVariantMap& msg, const QString& slot ); - QList m_syncPlaylists; + void startPlaylistSync( SpotifyPlaylist* playlist ); + void stopPlaylistSync( SpotifyPlaylist* playlist ); + +// QList m_syncPlaylists; QWeakPointer m_configWidget; QWeakPointer m_spotifyResolver; diff --git a/src/accounts/spotify/SpotifyAccountConfig.cpp b/src/accounts/spotify/SpotifyAccountConfig.cpp index 1afed75b0..4403e2b9e 100644 --- a/src/accounts/spotify/SpotifyAccountConfig.cpp +++ b/src/accounts/spotify/SpotifyAccountConfig.cpp @@ -1,3 +1,21 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, Leo Franchi + * + * 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 . + */ + #include "SpotifyAccountConfig.h" #include "SpotifyAccount.h" @@ -35,7 +53,12 @@ SpotifyAccountConfig::saveSettings() { const QListWidgetItem* item = m_ui->playlistList->itemAt( i, 0 ); SpotifyPlaylist* pl = item->data( Qt::UserRole ).value< SpotifyPlaylist* >(); - pl->sync = ( item->checkState() == Qt::Checked ); + const bool toSync = ( item->checkState() == Qt::Checked ); + if ( pl->sync != toSync ) + { + pl->changed = true; + pl->sync = toSync; + } } } diff --git a/src/accounts/spotify/SpotifyAccountConfig.h b/src/accounts/spotify/SpotifyAccountConfig.h index 5ecf04c41..35f9ed559 100644 --- a/src/accounts/spotify/SpotifyAccountConfig.h +++ b/src/accounts/spotify/SpotifyAccountConfig.h @@ -1,3 +1,21 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, Leo Franchi + * + * 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 . + */ + #ifndef SPOTIFYACCOUNTCONFIG_H #define SPOTIFYACCOUNTCONFIG_H @@ -34,7 +52,7 @@ public: private: Ui::SpotifyConfig* m_ui; SpotifyAccount* m_account; - + }; }