mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-19 23:41:51 +02:00
fix setdynamicplaylistrevision from JSON
dont' save last control when not dirty
This commit is contained in:
parent
b68d8a3529
commit
d65531a2f8
@ -30,6 +30,7 @@ DynamicControlList::DynamicControlList()
|
||||
: AnimatedWidget()
|
||||
, m_layout( new QVBoxLayout )
|
||||
, m_summaryWidget( 0 )
|
||||
, m_lastControlDirty( false )
|
||||
{
|
||||
init();
|
||||
}
|
||||
@ -39,6 +40,7 @@ DynamicControlList::DynamicControlList( AnimatedSplitter* parent )
|
||||
, m_isLocal( true )
|
||||
, m_layout( new QVBoxLayout )
|
||||
, m_summaryWidget( 0 )
|
||||
, m_lastControlDirty( false )
|
||||
{
|
||||
init();
|
||||
}
|
||||
@ -49,6 +51,7 @@ DynamicControlList::DynamicControlList( const geninterface_ptr& generator, const
|
||||
, m_isLocal( isLocal )
|
||||
, m_layout( new QVBoxLayout )
|
||||
, m_summaryWidget( 0 )
|
||||
, m_lastControlDirty( false )
|
||||
{
|
||||
init();
|
||||
setControls( generator, controls, m_isLocal );
|
||||
@ -175,6 +178,10 @@ void DynamicControlList::removeControl()
|
||||
void DynamicControlList::controlChanged()
|
||||
{
|
||||
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() );
|
||||
}
|
||||
@ -183,3 +190,9 @@ void DynamicControlList::controlChanged()
|
||||
void DynamicControlList::paintEvent(QPaintEvent* )
|
||||
{
|
||||
}
|
||||
|
||||
bool DynamicControlList::lastControlDirty() const
|
||||
{
|
||||
return m_lastControlDirty;
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
|
||||
virtual void paintEvent(QPaintEvent* );
|
||||
|
||||
bool lastControlDirty() const;
|
||||
signals:
|
||||
void controlsChanged();
|
||||
void controlChanged( const Tomahawk::dyncontrol_ptr& control );
|
||||
@ -61,11 +62,12 @@ private:
|
||||
void init();
|
||||
|
||||
geninterface_ptr m_generator;
|
||||
bool m_isLocal;
|
||||
|
||||
QVBoxLayout* m_layout;
|
||||
QList< DynamicControlWidget* > m_controls;
|
||||
QWidget* m_summaryWidget;
|
||||
bool m_isLocal;
|
||||
bool m_lastControlDirty;
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -272,6 +272,8 @@ void
|
||||
DynamicWidget::controlsChanged()
|
||||
{
|
||||
// save the current playlist
|
||||
if( m_controls->lastControlDirty() )
|
||||
m_playlist->generator()->controls().removeLast();
|
||||
m_playlist->createNewRevision();
|
||||
}
|
||||
|
||||
|
@ -110,6 +110,7 @@ DatabaseCommand::factory( const QVariant& op, const source_ptr& source )
|
||||
}
|
||||
else if( name == "setdynamicplaylistrevision" )
|
||||
{
|
||||
qDebug() << "SETDYN CONTENT:" << op;
|
||||
DatabaseCommand_SetDynamicPlaylistRevision * cmd = new DatabaseCommand_SetDynamicPlaylistRevision;
|
||||
cmd->setSource( source );
|
||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||
|
@ -73,23 +73,44 @@ DatabaseCommand_SetDynamicPlaylistRevision::postCommitHook()
|
||||
qDebug() << playlistguid();
|
||||
Q_ASSERT( !playlist.isNull() );
|
||||
return;
|
||||
}
|
||||
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( !m_controlsV.isEmpty() ) {
|
||||
QList<QVariantMap> controlMap;
|
||||
foreach( const QVariant& v, m_controlsV )
|
||||
controlMap << v.toMap();
|
||||
|
||||
if( m_mode == OnDemand )
|
||||
playlist->setRevision( newrev(),
|
||||
true, // this *is* the newest revision so far
|
||||
m_type,
|
||||
controlMap,
|
||||
m_applied );
|
||||
else
|
||||
playlist->setRevision( newrev(),
|
||||
orderedentriesguids,
|
||||
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() )
|
||||
Servent::instance()->triggerDBSync();
|
||||
}
|
||||
@ -101,9 +122,16 @@ DatabaseCommand_SetDynamicPlaylistRevision::exec( DatabaseImpl* lib )
|
||||
DatabaseCommand_SetPlaylistRevision::exec( lib );
|
||||
|
||||
QVariantList newcontrols;
|
||||
foreach( const dyncontrol_ptr& control, m_controls ) {
|
||||
newcontrols << control->id();
|
||||
if( m_controlsV.isEmpty() && !m_controls.isEmpty() ) {
|
||||
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;
|
||||
const QByteArray newcontrols_data = ser.serialize( newcontrols );
|
||||
|
||||
@ -129,18 +157,32 @@ DatabaseCommand_SetDynamicPlaylistRevision::exec( DatabaseImpl* lib )
|
||||
TomahawkSqlQuery controlsQuery = lib->newquery();
|
||||
controlsQuery.prepare( "INSERT INTO dynamic_playlist_controls( id, playlist, selectedType, match, input ) "
|
||||
"VALUES( ?, ?, ?, ?, ? )" );
|
||||
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() );
|
||||
controlsQuery.addBindValue( m_playlistguid );
|
||||
controlsQuery.addBindValue( control->selectedType() );
|
||||
controlsQuery.addBindValue( control->match() );
|
||||
controlsQuery.addBindValue( control->input() );
|
||||
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() );
|
||||
controlsQuery.addBindValue( m_playlistguid );
|
||||
controlsQuery.addBindValue( control->selectedType() );
|
||||
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 )
|
||||
{
|
||||
qDebug() << "updating dynamic playlist, optimistic locking okay";
|
||||
|
@ -55,11 +55,9 @@ public:
|
||||
QVariantList controlsV();
|
||||
|
||||
QString type() const { return m_type; }
|
||||
// GeneratorMode mode() const { return m_mode; }
|
||||
int mode() const { return (int)m_mode; }
|
||||
|
||||
void setType( const QString& type ) { m_type = type; }
|
||||
// void setMode( GeneratorMode mode ) { m_mode = mode; }
|
||||
void setMode( int mode ) { m_mode = (GeneratorMode)mode; }
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user