1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 03:10:12 +02:00

fix setdynamicplaylistrevision from JSON

dont' save last control when not dirty
This commit is contained in:
Leo Franchi
2011-01-16 18:26:33 -05:00
parent b68d8a3529
commit d65531a2f8
6 changed files with 90 additions and 32 deletions

View File

@@ -30,6 +30,7 @@ DynamicControlList::DynamicControlList()
: AnimatedWidget() : AnimatedWidget()
, m_layout( new QVBoxLayout ) , m_layout( new QVBoxLayout )
, m_summaryWidget( 0 ) , m_summaryWidget( 0 )
, m_lastControlDirty( false )
{ {
init(); init();
} }
@@ -39,6 +40,7 @@ DynamicControlList::DynamicControlList( AnimatedSplitter* parent )
, m_isLocal( true ) , m_isLocal( true )
, m_layout( new QVBoxLayout ) , m_layout( new QVBoxLayout )
, m_summaryWidget( 0 ) , m_summaryWidget( 0 )
, m_lastControlDirty( false )
{ {
init(); init();
} }
@@ -49,6 +51,7 @@ DynamicControlList::DynamicControlList( const geninterface_ptr& generator, const
, m_isLocal( isLocal ) , m_isLocal( isLocal )
, m_layout( new QVBoxLayout ) , m_layout( new QVBoxLayout )
, m_summaryWidget( 0 ) , m_summaryWidget( 0 )
, m_lastControlDirty( false )
{ {
init(); init();
setControls( generator, controls, m_isLocal ); setControls( generator, controls, m_isLocal );
@@ -175,6 +178,10 @@ void DynamicControlList::removeControl()
void DynamicControlList::controlChanged() void DynamicControlList::controlChanged()
{ {
Q_ASSERT( sender() && qobject_cast<DynamicControlWidget*>(sender()) ); Q_ASSERT( sender() && qobject_cast<DynamicControlWidget*>(sender()) );
DynamicControlWidget* widget = qobject_cast<DynamicControlWidget*>(sender());
if( !widget->control()->input().isEmpty() )
m_lastControlDirty = true;
emit controlChanged( qobject_cast<DynamicControlWidget*>(sender())->control() ); emit controlChanged( qobject_cast<DynamicControlWidget*>(sender())->control() );
} }
@@ -183,3 +190,9 @@ void DynamicControlList::controlChanged()
void DynamicControlList::paintEvent(QPaintEvent* ) void DynamicControlList::paintEvent(QPaintEvent* )
{ {
} }
bool DynamicControlList::lastControlDirty() const
{
return m_lastControlDirty;
}

View File

@@ -46,6 +46,7 @@ public:
virtual void paintEvent(QPaintEvent* ); virtual void paintEvent(QPaintEvent* );
bool lastControlDirty() const;
signals: signals:
void controlsChanged(); void controlsChanged();
void controlChanged( const Tomahawk::dyncontrol_ptr& control ); void controlChanged( const Tomahawk::dyncontrol_ptr& control );
@@ -61,11 +62,12 @@ private:
void init(); void init();
geninterface_ptr m_generator; geninterface_ptr m_generator;
bool m_isLocal;
QVBoxLayout* m_layout; QVBoxLayout* m_layout;
QList< DynamicControlWidget* > m_controls; QList< DynamicControlWidget* > m_controls;
QWidget* m_summaryWidget; QWidget* m_summaryWidget;
bool m_isLocal;
bool m_lastControlDirty;
}; };
}; };

View File

@@ -272,6 +272,8 @@ void
DynamicWidget::controlsChanged() DynamicWidget::controlsChanged()
{ {
// save the current playlist // save the current playlist
if( m_controls->lastControlDirty() )
m_playlist->generator()->controls().removeLast();
m_playlist->createNewRevision(); m_playlist->createNewRevision();
} }

View File

@@ -110,6 +110,7 @@ DatabaseCommand::factory( const QVariant& op, const source_ptr& source )
} }
else if( name == "setdynamicplaylistrevision" ) else if( name == "setdynamicplaylistrevision" )
{ {
qDebug() << "SETDYN CONTENT:" << op;
DatabaseCommand_SetDynamicPlaylistRevision * cmd = new DatabaseCommand_SetDynamicPlaylistRevision; DatabaseCommand_SetDynamicPlaylistRevision * cmd = new DatabaseCommand_SetDynamicPlaylistRevision;
cmd->setSource( source ); cmd->setSource( source );
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd ); QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );

View File

@@ -73,23 +73,44 @@ DatabaseCommand_SetDynamicPlaylistRevision::postCommitHook()
qDebug() << playlistguid(); qDebug() << playlistguid();
Q_ASSERT( !playlist.isNull() ); Q_ASSERT( !playlist.isNull() );
return; return;
} }
if( m_mode == OnDemand ) if( !m_controlsV.isEmpty() ) {
playlist->setRevision( newrev(), QList<QVariantMap> controlMap;
true, // this *is* the newest revision so far foreach( const QVariant& v, m_controlsV )
m_type, controlMap << v.toMap();
m_controls,
m_applied ); if( m_mode == OnDemand )
else playlist->setRevision( newrev(),
playlist->setRevision( newrev(), true, // this *is* the newest revision so far
orderedentriesguids, m_type,
m_previous_rev_orderedguids, controlMap,
m_type, m_applied );
m_controls, else
true, // this *is* the newest revision so far playlist->setRevision( newrev(),
m_addedmap, orderedentriesguids,
m_applied ); m_previous_rev_orderedguids,
m_type,
controlMap,
true, // this *is* the newest revision so far
m_addedmap,
m_applied );
} else {
if( m_mode == OnDemand )
playlist->setRevision( newrev(),
true, // this *is* the newest revision so far
m_type,
m_controls,
m_applied );
else
playlist->setRevision( newrev(),
orderedentriesguids,
m_previous_rev_orderedguids,
m_type,
m_controls,
true, // this *is* the newest revision so far
m_addedmap,
m_applied );
}
if( source()->isLocal() ) if( source()->isLocal() )
Servent::instance()->triggerDBSync(); Servent::instance()->triggerDBSync();
} }
@@ -101,9 +122,16 @@ DatabaseCommand_SetDynamicPlaylistRevision::exec( DatabaseImpl* lib )
DatabaseCommand_SetPlaylistRevision::exec( lib ); DatabaseCommand_SetPlaylistRevision::exec( lib );
QVariantList newcontrols; QVariantList newcontrols;
foreach( const dyncontrol_ptr& control, m_controls ) { if( m_controlsV.isEmpty() && !m_controls.isEmpty() ) {
newcontrols << control->id(); foreach( const dyncontrol_ptr& control, m_controls ) {
newcontrols << control->id();
}
} else if( !m_controlsV.isEmpty() ) {
foreach( const QVariant& v, m_controlsV ) {
newcontrols << v.toMap().value( "id" );
}
} }
QJson::Serializer ser; QJson::Serializer ser;
const QByteArray newcontrols_data = ser.serialize( newcontrols ); const QByteArray newcontrols_data = ser.serialize( newcontrols );
@@ -129,18 +157,32 @@ DatabaseCommand_SetDynamicPlaylistRevision::exec( DatabaseImpl* lib )
TomahawkSqlQuery controlsQuery = lib->newquery(); TomahawkSqlQuery controlsQuery = lib->newquery();
controlsQuery.prepare( "INSERT INTO dynamic_playlist_controls( id, playlist, selectedType, match, input ) " controlsQuery.prepare( "INSERT INTO dynamic_playlist_controls( id, playlist, selectedType, match, input ) "
"VALUES( ?, ?, ?, ?, ? )" ); "VALUES( ?, ?, ?, ?, ? )" );
foreach( const dyncontrol_ptr& control, m_controls ) if( m_controlsV.isEmpty() && !m_controls.isEmpty() ) {
{ foreach( const dyncontrol_ptr& control, m_controls )
qDebug() << "inserting dynamic control:" << control->id() << m_playlistguid << control->selectedType() << control->match() << control->input(); {
controlsQuery.addBindValue( control->id() ); qDebug() << "inserting dynamic control:" << control->id() << m_playlistguid << control->selectedType() << control->match() << control->input();
controlsQuery.addBindValue( m_playlistguid ); controlsQuery.addBindValue( control->id() );
controlsQuery.addBindValue( control->selectedType() ); controlsQuery.addBindValue( m_playlistguid );
controlsQuery.addBindValue( control->match() ); controlsQuery.addBindValue( control->selectedType() );
controlsQuery.addBindValue( control->input() ); controlsQuery.addBindValue( control->match() );
controlsQuery.addBindValue( control->input() );
controlsQuery.exec();
}
} else {
foreach( const QVariant& v, m_controlsV ) {
QVariantMap control = v.toMap();
qDebug() << "inserting dynamic control from JSON:" << control.value( "id" ) << m_playlistguid << control.value( "selectedType" ) << control.value( "match" ) << control.value( "input" );
controlsQuery.addBindValue( control.value( "id" ) );
controlsQuery.addBindValue( m_playlistguid );
controlsQuery.addBindValue( control.value( "selectedType" ) );
controlsQuery.addBindValue( control.value( "match" ) );
controlsQuery.addBindValue( control.value( "input" ) );
controlsQuery.exec();
}
controlsQuery.exec();
} }
if( m_applied ) if( m_applied )
{ {
qDebug() << "updating dynamic playlist, optimistic locking okay"; qDebug() << "updating dynamic playlist, optimistic locking okay";

View File

@@ -55,11 +55,9 @@ public:
QVariantList controlsV(); QVariantList controlsV();
QString type() const { return m_type; } QString type() const { return m_type; }
// GeneratorMode mode() const { return m_mode; }
int mode() const { return (int)m_mode; } int mode() const { return (int)m_mode; }
void setType( const QString& type ) { m_type = type; } void setType( const QString& type ) { m_type = type; }
// void setMode( GeneratorMode mode ) { m_mode = mode; }
void setMode( int mode ) { m_mode = (GeneratorMode)mode; } void setMode( int mode ) { m_mode = (GeneratorMode)mode; }
private: private: