mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-13 09:34:53 +02:00
WIP
This commit is contained in:
@@ -108,105 +108,43 @@ DatabaseCommand_SetDynamicPlaylistRevision::postCommitHook()
|
|||||||
void
|
void
|
||||||
DatabaseCommand_SetDynamicPlaylistRevision::exec( DatabaseImpl* lib )
|
DatabaseCommand_SetDynamicPlaylistRevision::exec( DatabaseImpl* lib )
|
||||||
{
|
{
|
||||||
/*using namespace Tomahawk;
|
DatabaseCommand_SetPlaylistRevision::exec( lib );
|
||||||
|
|
||||||
QString currentrevision;
|
QVariantList newcontrols;
|
||||||
|
foreach( const dyncontrol_ptr& control, m_controls ) {
|
||||||
// get the current revision for this playlist
|
newcontrols << control->id();
|
||||||
// this also serves to check the playlist exists.
|
|
||||||
TomahawkSqlQuery chkq = lib->newquery();
|
|
||||||
chkq.prepare("SELECT currentrevision FROM playlist WHERE guid = ?");
|
|
||||||
chkq.addBindValue( m_playlistguid );
|
|
||||||
if( chkq.exec() && chkq.next() )
|
|
||||||
{
|
|
||||||
currentrevision = chkq.value( 0 ).toString();
|
|
||||||
//qDebug() << Q_FUNC_INFO << "pl guid" << m_playlistguid << " curr rev" << currentrevision;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw "No such playlist, WTF?";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariantList vlist = m_orderedguids;
|
|
||||||
QJson::Serializer ser;
|
QJson::Serializer ser;
|
||||||
const QByteArray entries = ser.serialize( vlist );
|
const QByteArray newcontrols_data = ser.serialize( newcontrols );
|
||||||
|
|
||||||
// add any new items:
|
|
||||||
TomahawkSqlQuery adde = lib->newquery();
|
|
||||||
|
|
||||||
QString sql = "INSERT INTO playlist_item( guid, playlist, trackname, artistname, albumname, "
|
|
||||||
"annotation, duration, addedon, addedby, result_hint ) "
|
|
||||||
"VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
|
|
||||||
adde.prepare( sql );
|
|
||||||
|
|
||||||
qDebug() << "Num new playlist_items to add:" << m_addedentries.length();
|
|
||||||
foreach( const plentry_ptr& e, m_addedentries )
|
|
||||||
{
|
|
||||||
m_addedmap.insert( e->guid(), e ); // needed in postcommithook
|
|
||||||
|
|
||||||
adde.bindValue( 0, e->guid() );
|
|
||||||
adde.bindValue( 1, m_playlistguid );
|
|
||||||
adde.bindValue( 2, e->query()->track() );
|
|
||||||
adde.bindValue( 3, e->query()->artist() );
|
|
||||||
adde.bindValue( 4, e->query()->album() );
|
|
||||||
adde.bindValue( 5, e->annotation() );
|
|
||||||
adde.bindValue( 6, (int) e->duration() );
|
|
||||||
adde.bindValue( 7, e->lastmodified() );
|
|
||||||
adde.bindValue( 8, source()->isLocal() ? QVariant(QVariant::Int) : source()->id() );
|
|
||||||
adde.bindValue( 9, "" );
|
|
||||||
adde.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
// add the new revision:
|
|
||||||
//qDebug() << "Adding new playlist revision, guid:" << m_newrev
|
|
||||||
// << entries;
|
|
||||||
TomahawkSqlQuery query = lib->newquery();
|
TomahawkSqlQuery query = lib->newquery();
|
||||||
sql = "INSERT INTO playlist_revision(guid, playlist, entries, author, timestamp, previous_revision) "
|
QString sql = "INSERT INTO dynamic_playlist_revision (guid, controls, plmode, pltype) "
|
||||||
"VALUES(?, ?, ?, ?, ?, ?)";
|
"VALUES(?, ?, ?, ?)";
|
||||||
|
|
||||||
query.prepare( sql );
|
query.prepare( sql );
|
||||||
query.addBindValue( m_newrev );
|
query.addBindValue( m_newrev );
|
||||||
query.addBindValue( m_playlistguid );
|
query.addBindValue( newcontrols_data );
|
||||||
query.addBindValue( entries );
|
query.addBindValue( QString::number( (int) m_mode ) );
|
||||||
query.addBindValue( source()->isLocal() ? QVariant(QVariant::Int) : source()->id() );
|
query.addBindValue( m_type );
|
||||||
query.addBindValue( 0 ); //ts
|
|
||||||
query.addBindValue( m_oldrev.isEmpty() ? QVariant(QVariant::String) : m_oldrev );
|
|
||||||
query.exec();
|
query.exec();
|
||||||
|
|
||||||
qDebug() << "Currentrevision:" << currentrevision << "oldrev:" << m_oldrev;
|
// delete all the old controls, replace with new onws
|
||||||
// if optimistic locking is ok, update current revision to this new one
|
TomahawkSqlQuery delQuery = lib->newquery();
|
||||||
if( currentrevision == m_oldrev )
|
delQuery.prepare( "DELETE * FROM dynamic_playlist_controls" );
|
||||||
|
delQuery.exec();
|
||||||
|
|
||||||
|
TomahawkSqlQuery controlsQuery = lib->newquery();
|
||||||
|
controlsQuery.prepare( "INSERT INTO dynamic_playlist_controls( id, playlist, selectedType, match, input ) "
|
||||||
|
"VALUES( ?, ?, ?, ?, ?" );
|
||||||
|
foreach( const dyncontrol_ptr& control, m_controls )
|
||||||
{
|
{
|
||||||
TomahawkSqlQuery query2 = lib->newquery();
|
controlsQuery.addBindValue( control->id() );
|
||||||
qDebug() << "updating current revision, optimistic locking ok";
|
controlsQuery.addBindValue( m_playlistguid );
|
||||||
query2.prepare("UPDATE playlist SET currentrevision = ? WHERE guid = ?");
|
controlsQuery.addBindValue( control->selectedType() );
|
||||||
query2.bindValue( 0, m_newrev );
|
controlsQuery.addBindValue( control->match() );
|
||||||
query2.bindValue( 1, m_playlistguid );
|
controlsQuery.addBindValue( control->input() );
|
||||||
query2.exec();
|
|
||||||
|
|
||||||
m_applied = true;
|
controlsQuery.exec();
|
||||||
|
|
||||||
// load previous revision entries, which we need to pass on
|
|
||||||
// so the change can be diffed
|
|
||||||
TomahawkSqlQuery query_entries = lib->newquery();
|
|
||||||
query_entries.prepare( "SELECT entries, playlist, author, timestamp, previous_revision "
|
|
||||||
"FROM playlist_revision "
|
|
||||||
"WHERE guid = :guid" );
|
|
||||||
query_entries.bindValue( ":guid", m_oldrev );
|
|
||||||
query_entries.exec();
|
|
||||||
if( query_entries.next() )
|
|
||||||
{
|
|
||||||
// entries should be a list of strings:
|
|
||||||
bool ok;
|
|
||||||
QJson::Parser parser;
|
|
||||||
QVariant v = parser.parse( query_entries.value(0).toByteArray(), &ok );
|
|
||||||
Q_ASSERT( ok && v.type() == QVariant::List ); //TODO
|
|
||||||
m_previous_rev_orderedguids = v.toStringList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug() << "Not updating current revision, optimistic locking fail";
|
|
||||||
} */
|
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@ class DatabaseCommand_SetDynamicPlaylistRevision : public DatabaseCommand_SetPla
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY( QString type READ type WRITE setType )
|
Q_PROPERTY( QString type READ type WRITE setType )
|
||||||
Q_PROPERTY( GeneratorMode mode READ mode WRITE setMode )
|
Q_PROPERTY( int mode READ mode WRITE setMode )
|
||||||
Q_PROPERTY( QVariantList controls READ controlsV WRITE setControlsV )
|
Q_PROPERTY( QVariantList controls READ controlsV WRITE setControlsV )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -53,10 +53,12 @@ public:
|
|||||||
QVariantList controlsV();
|
QVariantList controlsV();
|
||||||
|
|
||||||
QString type() const { return m_type; }
|
QString type() const { return m_type; }
|
||||||
GeneratorMode mode() const { return m_mode; }
|
// GeneratorMode mode() const { return 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( GeneratorMode mode ) { m_mode = mode; }
|
||||||
|
void setMode( int mode ) { m_mode = (GeneratorMode)mode; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_type;
|
QString m_type;
|
||||||
|
@@ -65,7 +65,7 @@ DatabaseCommand_SetPlaylistRevision::exec( DatabaseImpl* lib )
|
|||||||
{
|
{
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
QString currentrevision;
|
QString m_currentRevision;
|
||||||
|
|
||||||
// get the current revision for this playlist
|
// get the current revision for this playlist
|
||||||
// this also serves to check the playlist exists.
|
// this also serves to check the playlist exists.
|
||||||
@@ -74,7 +74,7 @@ DatabaseCommand_SetPlaylistRevision::exec( DatabaseImpl* lib )
|
|||||||
chkq.addBindValue( m_playlistguid );
|
chkq.addBindValue( m_playlistguid );
|
||||||
if( chkq.exec() && chkq.next() )
|
if( chkq.exec() && chkq.next() )
|
||||||
{
|
{
|
||||||
currentrevision = chkq.value( 0 ).toString();
|
m_currentRevision = chkq.value( 0 ).toString();
|
||||||
//qDebug() << Q_FUNC_INFO << "pl guid" << m_playlistguid << " curr rev" << currentrevision;
|
//qDebug() << Q_FUNC_INFO << "pl guid" << m_playlistguid << " curr rev" << currentrevision;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -129,9 +129,9 @@ DatabaseCommand_SetPlaylistRevision::exec( DatabaseImpl* lib )
|
|||||||
query.addBindValue( m_oldrev.isEmpty() ? QVariant(QVariant::String) : m_oldrev );
|
query.addBindValue( m_oldrev.isEmpty() ? QVariant(QVariant::String) : m_oldrev );
|
||||||
query.exec();
|
query.exec();
|
||||||
|
|
||||||
qDebug() << "Currentrevision:" << currentrevision << "oldrev:" << m_oldrev;
|
qDebug() << "Currentrevision:" << m_currentRevision << "oldrev:" << m_oldrev;
|
||||||
// if optimistic locking is ok, update current revision to this new one
|
// if optimistic locking is ok, update current revision to this new one
|
||||||
if( currentrevision == m_oldrev )
|
if( m_currentRevision == m_oldrev )
|
||||||
{
|
{
|
||||||
TomahawkSqlQuery query2 = lib->newquery();
|
TomahawkSqlQuery query2 = lib->newquery();
|
||||||
qDebug() << "updating current revision, optimistic locking ok";
|
qDebug() << "updating current revision, optimistic locking ok";
|
||||||
|
@@ -72,11 +72,12 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
bool m_applied;
|
bool m_applied;
|
||||||
QStringList m_previous_rev_orderedguids;
|
QStringList m_previous_rev_orderedguids;
|
||||||
QMap<QString, Tomahawk::plentry_ptr> m_addedmap;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_playlistguid;
|
QString m_playlistguid;
|
||||||
QString m_newrev, m_oldrev;
|
QString m_newrev, m_oldrev;
|
||||||
|
QMap<QString, Tomahawk::plentry_ptr> m_addedmap;
|
||||||
|
|
||||||
|
QString m_currentRevision;
|
||||||
|
private:
|
||||||
QVariantList m_orderedguids;
|
QVariantList m_orderedguids;
|
||||||
QList<Tomahawk::plentry_ptr> m_addedentries;
|
QList<Tomahawk::plentry_ptr> m_addedentries;
|
||||||
};
|
};
|
||||||
|
@@ -264,16 +264,15 @@ void DynamicPlaylist::addEntry(const Tomahawk::query_ptr& query, const QString&
|
|||||||
addEntries( queries, oldrev );
|
addEntries( queries, oldrev );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// static version
|
// static version
|
||||||
void
|
void
|
||||||
DynamicPlaylist::setRevision( const QString& rev,
|
DynamicPlaylist::setRevision( const QString& rev,
|
||||||
const QList< QString >& neworderedguids,
|
const QList< QString >& neworderedguids,
|
||||||
const QList< QString >& oldorderedguids,
|
const QList< QString >& oldorderedguids,
|
||||||
const QString& type,
|
const QString& type,
|
||||||
const QList< dyncontrol_ptr>& controls,
|
const QList< Tomahawk::dyncontrol_ptr>& controls,
|
||||||
bool is_newest_rev,
|
bool is_newest_rev,
|
||||||
const QMap< QString, plentry_ptr >& addedmap,
|
const QMap< QString, Tomahawk::plentry_ptr >& addedmap,
|
||||||
bool applied )
|
bool applied )
|
||||||
{
|
{
|
||||||
// we're probably being called by a database worker thread
|
// we're probably being called by a database worker thread
|
||||||
@@ -282,13 +281,13 @@ DynamicPlaylist::setRevision( const QString& rev,
|
|||||||
QMetaObject::invokeMethod( this,
|
QMetaObject::invokeMethod( this,
|
||||||
"setRevision",
|
"setRevision",
|
||||||
Qt::BlockingQueuedConnection,
|
Qt::BlockingQueuedConnection,
|
||||||
Q_ARG( QString, rev ),
|
Q_ARG( QString, rev ),
|
||||||
Q_ARG( QList<QString>, neworderedguids ),
|
Q_ARG( QList<QString> , neworderedguids ),
|
||||||
Q_ARG( QList<QString>, oldorderedguids ),
|
Q_ARG( QList<QString> , oldorderedguids ),
|
||||||
Q_ARG( QString, type ),
|
Q_ARG( QString , type ),
|
||||||
QGenericArgument( "QList< dyncontrol_ptr >" , (const void*)&controls ),
|
QGenericArgument( "QList< Tomahawk::dyncontrol_ptr > " , (const void*)&controls ),
|
||||||
Q_ARG( bool, is_newest_rev ),
|
Q_ARG( bool, is_newest_rev ),
|
||||||
QGenericArgument( "QMap< QString,Tomahawk::plentry_ptr >" , (const void*)&addedmap ),
|
QGenericArgument( "QMap< QString,Tomahawk::plentry_ptr > " , (const void*)&addedmap ),
|
||||||
Q_ARG( bool, applied ) );
|
Q_ARG( bool, applied ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -316,7 +315,7 @@ void
|
|||||||
DynamicPlaylist::setRevision( const QString& rev,
|
DynamicPlaylist::setRevision( const QString& rev,
|
||||||
bool is_newest_rev,
|
bool is_newest_rev,
|
||||||
const QString& type,
|
const QString& type,
|
||||||
const QList< dyncontrol_ptr>& controls,
|
const QList< Tomahawk::dyncontrol_ptr>& controls,
|
||||||
bool applied )
|
bool applied )
|
||||||
{
|
{
|
||||||
if( QThread::currentThread() != thread() )
|
if( QThread::currentThread() != thread() )
|
||||||
@@ -327,7 +326,7 @@ DynamicPlaylist::setRevision( const QString& rev,
|
|||||||
Q_ARG( QString, rev ),
|
Q_ARG( QString, rev ),
|
||||||
Q_ARG( bool, is_newest_rev ),
|
Q_ARG( bool, is_newest_rev ),
|
||||||
Q_ARG( QString, type ),
|
Q_ARG( QString, type ),
|
||||||
QGenericArgument( "QList< dyncontrol_ptr >" , (const void*)&controls ),
|
QGenericArgument( "QList< Tomahawk::dyncontrol_ptr >" , (const void*)&controls ),
|
||||||
Q_ARG( bool, applied ) );
|
Q_ARG( bool, applied ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,8 @@ class GeneratorInterface : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY( QString type READ type )
|
Q_PROPERTY( QString type READ type )
|
||||||
Q_PROPERTY( GeneratorMode mode READ mode WRITE setMode );
|
Q_PROPERTY( GeneratorMode mode READ mode WRITE setMode )
|
||||||
|
Q_ENUMS( GeneratorMode )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// can't inline constructors/destructors for forward declared shared pointer types
|
// can't inline constructors/destructors for forward declared shared pointer types
|
||||||
|
@@ -284,11 +284,11 @@ Playlist::setNewRevision( const QString& rev,
|
|||||||
//qDebug() << "counters:" << neworderedguids.count() << entriesmap.count() << addedmap.count();
|
//qDebug() << "counters:" << neworderedguids.count() << entriesmap.count() << addedmap.count();
|
||||||
foreach( const QString& id, neworderedguids )
|
foreach( const QString& id, neworderedguids )
|
||||||
{
|
{
|
||||||
// qDebug() << "id:" << id;
|
qDebug() << "id:" << id;
|
||||||
// qDebug() << "newordered:" << neworderedguids.count() << neworderedguids;
|
qDebug() << "newordered:" << neworderedguids.count() << neworderedguids;
|
||||||
// qDebug() << "entriesmap:" << entriesmap.count() << entriesmap;
|
qDebug() << "entriesmap:" << entriesmap.count() << entriesmap;
|
||||||
// qDebug() << "addedmap:" << addedmap.count() << addedmap;
|
qDebug() << "addedmap:" << addedmap.count() << addedmap;
|
||||||
// qDebug() << "m_entries" << m_entries;
|
qDebug() << "m_entries" << m_entries;
|
||||||
|
|
||||||
if( entriesmap.contains( id ) )
|
if( entriesmap.contains( id ) )
|
||||||
{
|
{
|
||||||
|
@@ -284,6 +284,7 @@ TomahawkApp::registerMetaTypes()
|
|||||||
qRegisterMetaType< QHash< QString, QMap<quint32, quint16> > >("QHash< QString, QMap<quint32, quint16> >");
|
qRegisterMetaType< QHash< QString, QMap<quint32, quint16> > >("QHash< QString, QMap<quint32, quint16> >");
|
||||||
|
|
||||||
qRegisterMetaType< GeneratorMode>("GeneratorMode");
|
qRegisterMetaType< GeneratorMode>("GeneratorMode");
|
||||||
|
qRegisterMetaType<Tomahawk::GeneratorMode>("Tomahawk::GeneratorMode");
|
||||||
// Extra definition for namespaced-versions of signals/slots required
|
// Extra definition for namespaced-versions of signals/slots required
|
||||||
qRegisterMetaType< Tomahawk::collection_ptr >("Tomahawk::collection_ptr");
|
qRegisterMetaType< Tomahawk::collection_ptr >("Tomahawk::collection_ptr");
|
||||||
qRegisterMetaType< Tomahawk::result_ptr >("Tomahawk::result_ptr");
|
qRegisterMetaType< Tomahawk::result_ptr >("Tomahawk::result_ptr");
|
||||||
|
Reference in New Issue
Block a user