mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-20 16:02:07 +02:00
attempt to move creation of playlist objects into the GUI thread at all times
This commit is contained in:
parent
96197e0ffa
commit
46623c09e8
@ -8,6 +8,7 @@
|
||||
#include "dynamic/GeneratorInterface.h"
|
||||
|
||||
#include "network/servent.h"
|
||||
#include "tomahawk/tomahawkapp.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@ -32,7 +33,7 @@ void
|
||||
DatabaseCommand_CreateDynamicPlaylist::exec( DatabaseImpl* lib )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
Q_ASSERT( !m_playlist.isNull() );
|
||||
Q_ASSERT( !( m_playlist.isNull() && m_v.isNull() ) );
|
||||
Q_ASSERT( !source().isNull() );
|
||||
|
||||
DatabaseCommand_CreatePlaylist::createPlaylist( lib, true );
|
||||
@ -40,26 +41,36 @@ DatabaseCommand_CreateDynamicPlaylist::exec( DatabaseImpl* lib )
|
||||
|
||||
TomahawkSqlQuery cre = lib->newquery();
|
||||
|
||||
cre.prepare( QString( "INSERT INTO dynamic_playlist( guid, pltype, plmode ) "
|
||||
"VALUES( '%1', '%2', %3 )" ).arg( m_playlist->guid() ).arg( m_playlist->type() ).arg( m_playlist->mode() ) );
|
||||
|
||||
cre.prepare( "INSERT INTO dynamic_playlist( guid, pltype, plmode ) "
|
||||
"VALUES( ?, ?, ? )" );
|
||||
|
||||
if( m_playlist.isNull() ) {
|
||||
QVariantMap m = m_v.toMap();
|
||||
cre.addBindValue( m.value( "guid" ) );
|
||||
cre.addBindValue( m.value( "type" ) );
|
||||
cre.addBindValue( m.value( "mode" ) );
|
||||
} else {
|
||||
cre.addBindValue( m_playlist->guid() );
|
||||
cre.addBindValue( m_playlist->type() );
|
||||
cre.addBindValue( m_playlist->mode() );
|
||||
}
|
||||
cre.exec();
|
||||
|
||||
// save the controls
|
||||
cre = lib->newquery();
|
||||
cre.prepare( "INSERT INTO dynamic_playlist_controls( id, selectedType, match, input) "
|
||||
"VALUES( :id, :selectedType, :match, :input )" );
|
||||
foreach( const dyncontrol_ptr& control, m_playlist->generator()->controls() ) {
|
||||
|
||||
cre.bindValue( ":id", control->id() );
|
||||
cre.bindValue( ":selectedType", control->selectedType() );
|
||||
cre.bindValue( ":match", control->match() );
|
||||
cre.bindValue( ":input", control->input() );
|
||||
|
||||
qDebug() << "CREATE DYNPLAYLIST CONTROL:" << cre.boundValues();
|
||||
|
||||
cre.exec();
|
||||
}
|
||||
// save the controls -- wait, no controls in a new playlist :P
|
||||
// cre = lib->newquery();
|
||||
// cre.prepare( "INSERT INTO dynamic_playlist_controls( id, selectedType, match, input) "
|
||||
// "VALUES( :id, :selectedType, :match, :input )" );
|
||||
// foreach( const dyncontrol_ptr& control, m_playlist->generator()->controls() ) {
|
||||
//
|
||||
// cre.bindValue( ":id", control->id() );
|
||||
// cre.bindValue( ":selectedType", control->selectedType() );
|
||||
// cre.bindValue( ":match", control->match() );
|
||||
// cre.bindValue( ":input", control->input() );
|
||||
//
|
||||
// qDebug() << "CREATE DYNPLAYLIST CONTROL:" << cre.boundValues();
|
||||
//
|
||||
// cre.exec();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@ -71,8 +82,16 @@ DatabaseCommand_CreateDynamicPlaylist::postCommitHook()
|
||||
return;
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "..reporting..";
|
||||
m_playlist->reportCreated( m_playlist );
|
||||
|
||||
if( m_playlist.isNull() ) {
|
||||
source_ptr src = source();
|
||||
QMetaObject::invokeMethod( TomahawkApp::instance()->mainWindow(),
|
||||
"createDynamicPlaylist",
|
||||
Qt::BlockingQueuedConnection,
|
||||
QGenericArgument( "Tomahawk::source_ptr", (const void*)&src ),
|
||||
Q_ARG( QVariant, m_v ) );
|
||||
} else {
|
||||
m_playlist->reportCreated( m_playlist );
|
||||
}
|
||||
if( source()->isLocal() )
|
||||
Servent::instance()->triggerDBSync();
|
||||
}
|
||||
|
@ -23,19 +23,15 @@ public:
|
||||
|
||||
QVariant playlistV() const
|
||||
{
|
||||
return QJson::QObjectHelper::qobject2qvariant( (QObject*)m_playlist.data() );
|
||||
if( m_v.isNull() )
|
||||
return QJson::QObjectHelper::qobject2qvariant( (QObject*)m_playlist.data() );
|
||||
else
|
||||
return m_v;
|
||||
}
|
||||
|
||||
void setPlaylistV( const QVariant& v )
|
||||
{
|
||||
qDebug() << "***********" << Q_FUNC_INFO << v;
|
||||
using namespace Tomahawk;
|
||||
|
||||
DynamicPlaylist* p = new DynamicPlaylist( source(), v.toMap().value( "type", QString() ).toString() );
|
||||
QJson::QObjectHelper::qvariant2qobject( v.toMap(), p );
|
||||
m_playlist = dynplaylist_ptr( p );
|
||||
|
||||
setPlaylist( m_playlist.staticCast<Tomahawk::Playlist>() );
|
||||
m_v = v;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <QSqlQuery>
|
||||
|
||||
#include "network/servent.h"
|
||||
#include "tomahawk/tomahawkapp.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@ -40,7 +41,18 @@ DatabaseCommand_CreatePlaylist::postCommitHook()
|
||||
return;
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "..reporting..";
|
||||
m_playlist->reportCreated( m_playlist );
|
||||
if( m_playlist.isNull() ) {
|
||||
source_ptr src = source();
|
||||
QMetaObject::invokeMethod( TomahawkApp::instance()->mainWindow(),
|
||||
"createPlaylist",
|
||||
Qt::BlockingQueuedConnection,
|
||||
QGenericArgument( "Tomahawk::source_ptr", (const void*)&src ),
|
||||
Q_ARG( QVariant, m_v )
|
||||
);
|
||||
} else {
|
||||
m_playlist->reportCreated( m_playlist );
|
||||
}
|
||||
|
||||
|
||||
if( source()->isLocal() )
|
||||
Servent::instance()->triggerDBSync();
|
||||
@ -50,21 +62,31 @@ void
|
||||
DatabaseCommand_CreatePlaylist::createPlaylist( DatabaseImpl* lib, bool dynamic)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
Q_ASSERT( !m_playlist.isNull() );
|
||||
Q_ASSERT( !( m_playlist.isNull() && m_v.isNull() ) );
|
||||
Q_ASSERT( !source().isNull() );
|
||||
|
||||
TomahawkSqlQuery cre = lib->newquery();
|
||||
cre.prepare( "INSERT INTO playlist( guid, source, shared, title, info, creator, lastmodified, dynplaylist) "
|
||||
"VALUES( :guid, :source, :shared, :title, :info, :creator, :lastmodified, :dynplaylist )" );
|
||||
cre.bindValue( ":guid", m_playlist->guid() );
|
||||
cre.bindValue( ":source", source()->isLocal() ? QVariant(QVariant::Int) : source()->id() );
|
||||
cre.bindValue( ":shared", m_playlist->shared() );
|
||||
cre.bindValue( ":title", m_playlist->title() );
|
||||
cre.bindValue( ":info", m_playlist->info() );
|
||||
cre.bindValue( ":creator", m_playlist->creator() );
|
||||
cre.bindValue( ":lastmodified", m_playlist->lastmodified() );
|
||||
cre.bindValue( ":dynplaylist", dynamic );
|
||||
"VALUES( :guid, :source, :shared, :title, :info, :creator, :lastmodified, :dynplaylist )" );
|
||||
|
||||
cre.bindValue( ":source", source()->isLocal() ? QVariant(QVariant::Int) : source()->id() );
|
||||
cre.bindValue( ":dynplaylist", dynamic );
|
||||
if( !m_playlist.isNull() ) {
|
||||
cre.bindValue( ":guid", m_playlist->guid() );
|
||||
cre.bindValue( ":shared", m_playlist->shared() );
|
||||
cre.bindValue( ":title", m_playlist->title() );
|
||||
cre.bindValue( ":info", m_playlist->info() );
|
||||
cre.bindValue( ":creator", m_playlist->creator() );
|
||||
cre.bindValue( ":lastmodified", m_playlist->lastmodified() );
|
||||
} else {
|
||||
QVariantMap m = m_v.toMap();
|
||||
cre.bindValue( ":guid", m.value( "guid" ) );
|
||||
cre.bindValue( ":shared", m.value( "shared" ) );
|
||||
cre.bindValue( ":title", m.value( "title" ) );
|
||||
cre.bindValue( ":info", m.value( "info" ) );
|
||||
cre.bindValue( ":creator", m.value( "creator" ) );
|
||||
cre.bindValue( ":lastmodified", m.value( "lastmodified", 0 ) );
|
||||
}
|
||||
qDebug() << "CREATE PLAYLIST:" << cre.boundValues();
|
||||
|
||||
cre.exec();
|
||||
|
@ -25,17 +25,15 @@ public:
|
||||
|
||||
QVariant playlistV() const
|
||||
{
|
||||
return QJson::QObjectHelper::qobject2qvariant( (QObject*)m_playlist.data() );
|
||||
if( m_v.isNull() )
|
||||
return QJson::QObjectHelper::qobject2qvariant( (QObject*)m_playlist.data() );
|
||||
else
|
||||
return m_v;
|
||||
}
|
||||
|
||||
void setPlaylistV( const QVariant& v )
|
||||
{
|
||||
qDebug() << "***********" << Q_FUNC_INFO << v;
|
||||
using namespace Tomahawk;
|
||||
|
||||
Playlist* p = new Playlist( source() );
|
||||
QJson::QObjectHelper::qvariant2qobject( v.toMap(), p );
|
||||
m_playlist = playlist_ptr( p );
|
||||
m_v = v;
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -44,6 +42,7 @@ protected:
|
||||
bool report() { return m_report; }
|
||||
void setPlaylist( const Tomahawk::playlist_ptr& playlist ) { m_playlist = playlist; }
|
||||
|
||||
QVariant m_v;
|
||||
private:
|
||||
Tomahawk::playlist_ptr m_playlist;
|
||||
bool m_report; // call Playlist::reportCreated?
|
||||
|
@ -374,6 +374,24 @@ TomahawkWindow::createPlaylist( bool dynamic )
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
TomahawkWindow::createPlaylist( const Tomahawk::source_ptr& src,
|
||||
const QVariant& contents)
|
||||
{
|
||||
playlist_ptr p = playlist_ptr( new Playlist( src ) );
|
||||
QJson::QObjectHelper::qvariant2qobject( contents.toMap(), p.data() );
|
||||
p->reportCreated( p );
|
||||
}
|
||||
|
||||
void
|
||||
TomahawkWindow::createDynamicPlaylist( const Tomahawk::source_ptr& src,
|
||||
const QVariant& contents)
|
||||
{
|
||||
dynplaylist_ptr p = dynplaylist_ptr( new DynamicPlaylist( src, contents.toMap().value( "type", QString() ).toString() ) );
|
||||
QJson::QObjectHelper::qvariant2qobject( contents.toMap(), p.data() );
|
||||
p->reportCreated( p );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TomahawkWindow::onPlaybackLoading( const Tomahawk::result_ptr& result )
|
||||
|
@ -47,7 +47,11 @@ public slots:
|
||||
void createPlaylist( bool dynamic = false );
|
||||
void loadSpiff();
|
||||
void showSettingsDialog();
|
||||
|
||||
|
||||
// called by the playlist creation dbcmds
|
||||
void createPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents );
|
||||
void createDynamicPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents );
|
||||
|
||||
private slots:
|
||||
void scanFinished();
|
||||
void rescanCollectionManually();
|
||||
|
Loading…
x
Reference in New Issue
Block a user