1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-13 20:39:57 +01:00

Hook up "delete tomahawk playlist when stopping sync" option

This commit is contained in:
Leo Franchi 2012-04-06 22:44:09 -04:00
parent d154c141fb
commit 662ee55514
5 changed files with 51 additions and 12 deletions

View File

@ -257,8 +257,6 @@ SpotifyAccount::configurationWidget()
m_configWidget = QWeakPointer< SpotifyAccountConfig >( new SpotifyAccountConfig( this ) );
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists );
}
else
m_configWidget.data()->loadFromConfig();
return static_cast< QWidget* >( m_configWidget.data() );
}
@ -280,7 +278,6 @@ SpotifyAccount::saveConfig()
creds[ "password" ] = m_configWidget.data()->password();
creds[ "highQuality" ] = m_configWidget.data()->highQuality();
setCredentials( creds );
sync();
// Send the result to the resolver
QVariantMap msg;
@ -292,6 +289,11 @@ SpotifyAccount::saveConfig()
m_spotifyResolver.data()->sendMessage( msg );
}
QVariantHash config = configuration();
config[ "deleteOnUnsync" ] = m_configWidget.data()->deleteOnUnsync();
qDebug() << "Saved deleteOnUnsync to:" << m_configWidget.data()->deleteOnUnsync();
setConfiguration( config );
m_configWidget.data()->saveSettings();
foreach ( SpotifyPlaylistInfo* pl, m_allSpotifyPlaylists )
{
@ -313,6 +315,7 @@ SpotifyAccount::saveConfig()
stopPlaylistSync( pl );
}
}
sync();
}
@ -389,6 +392,13 @@ SpotifyAccount::fetchFullPlaylist( SpotifyPlaylistInfo* playlist )
}
bool
SpotifyAccount::deleteOnUnsync() const
{
qDebug() << "READ deleteOnUnsync:" << configuration().value( "deleteOnUnsync", false ).toBool();
return configuration().value( "deleteOnUnsync", false ).toBool();
}
void
SpotifyAccount::stopPlaylistSync( SpotifyPlaylistInfo* playlist )
{
@ -397,6 +407,18 @@ SpotifyAccount::stopPlaylistSync( SpotifyPlaylistInfo* playlist )
msg[ "playlistid" ] = playlist->plid;
m_spotifyResolver.data()->sendMessage( msg );
if ( deleteOnUnsync() )
{
SpotifyPlaylistUpdater* updater = m_updaters.take( playlist->plid );
playlist_ptr tomahawkPl = updater->playlist();
if ( !tomahawkPl.isNull() )
Playlist::remove( tomahawkPl );
updater->deleteLater();
}
}

View File

@ -84,16 +84,11 @@ public:
virtual QWidget* aclWidget() { return 0; }
virtual InfoSystem::InfoPlugin* infoPlugin() { return 0; }
virtual SipPlugin* sipPlugin() { return 0; }
/*
struct Sync {
QString id_;
QString uuid;
Tomahawk::playlist_ptr playlist;
};*/
void sendMessage( const QVariantMap& msg, QObject* receiver, const QString& slot );
void registerUpdaterForPlaylist( const QString& plId, SpotifyPlaylistUpdater* updater );
bool deleteOnUnsync() const;
private slots:
void resolverMessage( const QString& msgType, const QVariantMap& msg );
@ -106,10 +101,9 @@ private:
void loadPlaylists();
void stopPlaylistSync( SpotifyPlaylistInfo* playlist );
void fetchFullPlaylist( SpotifyPlaylistInfo* playlist );
// QList<Sync> m_syncPlaylists;
QWeakPointer<SpotifyAccountConfig> m_configWidget;
QWeakPointer<ScriptResolver> m_spotifyResolver;

View File

@ -23,6 +23,7 @@
#include <QListWidget>
#include <QListWidgetItem>
#include <QShowEvent>
using namespace Tomahawk;
using namespace Accounts;
@ -42,7 +43,13 @@ SpotifyAccountConfig::SpotifyAccountConfig( SpotifyAccount *account )
connect( &m_resetTimer, SIGNAL( timeout() ), this, SLOT( resetVerifyButton() ) );
connect( m_ui->usernameEdit, SIGNAL( textChanged( QString ) ), this, SLOT( clearVerifyButton() ) );
connect( m_ui->passwordEdit, SIGNAL( textChanged( QString ) ), this, SLOT( clearVerifyButton() ) );
loadFromConfig();
}
void
SpotifyAccountConfig::showEvent( QShowEvent *event )
{
loadFromConfig();
}
@ -53,6 +60,9 @@ 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() );
qDebug() << "Loaded deleteOnUnsync:" << m_account->deleteOnUnsync();
m_ui->deleteOnUnsync->setChecked( m_account->deleteOnUnsync() );
}
void
@ -92,6 +102,13 @@ SpotifyAccountConfig::highQuality() const
}
bool
SpotifyAccountConfig::deleteOnUnsync() const
{
return m_ui->deleteOnUnsync->isChecked();
}
void
SpotifyAccountConfig::setPlaylists( const QList<SpotifyPlaylistInfo *>& playlists )
{

View File

@ -23,6 +23,8 @@
#include <QVariantMap>
#include <QTimer>
class QShowEvent;
namespace Ui
{
class SpotifyConfig;
@ -45,6 +47,7 @@ public:
QString username() const;
QString password() const;
bool highQuality() const;
bool deleteOnUnsync() const;
void setPlaylists( const QList< SpotifyPlaylistInfo* >& playlists );
@ -54,6 +57,9 @@ public:
public slots:
void verifyResult( const QString& msgType, const QVariantMap& msg );
protected:
void showEvent( QShowEvent* event );
private slots:
void verifyLogin();
void resetVerifyButton();

View File

@ -174,7 +174,7 @@
<item>
<widget class="QCheckBox" name="deleteOnUnsync">
<property name="text">
<string>Delete Tomahawk playlist when removing Spotify sync</string>
<string>Delete Tomahawk playlist when removing synchronization</string>
</property>
</widget>
</item>