mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 16:14:40 +02:00
properly save and load dynamic playlists
This commit is contained in:
@@ -83,10 +83,17 @@ void
|
||||
DynamicControlList::setControls( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls)
|
||||
{
|
||||
m_generator = generator;
|
||||
foreach( const dyncontrol_ptr& control, controls ) {
|
||||
m_controls << new DynamicControlWidget( control, false, false, false, this );
|
||||
if( controls.isEmpty() ) {
|
||||
m_controls << new DynamicControlWidget( generator->createControl(), false, false, false, this );
|
||||
connect( m_controls.last(), SIGNAL( addNewControl() ), this, SLOT( addNewControl() ) );
|
||||
connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) );
|
||||
} else
|
||||
{
|
||||
foreach( const dyncontrol_ptr& control, controls ) {
|
||||
m_controls << new DynamicControlWidget( control, false, false, false, this );
|
||||
connect( m_controls.last(), SIGNAL( addNewControl() ), this, SLOT( addNewControl() ) );
|
||||
connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) );
|
||||
}
|
||||
}
|
||||
onShown( this );
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ DatabaseCommand_CreateDynamicPlaylist::exec( DatabaseImpl* lib )
|
||||
Q_ASSERT( !m_playlist.isNull() );
|
||||
Q_ASSERT( !source().isNull() );
|
||||
|
||||
DatabaseCommand_CreatePlaylist::exec( lib );
|
||||
DatabaseCommand_CreatePlaylist::createPlaylist( lib, true );
|
||||
qDebug() << "Created normal playlist, now creating additional dynamic info!";
|
||||
|
||||
TomahawkSqlQuery cre = lib->newquery();
|
||||
|
@@ -28,24 +28,7 @@ DatabaseCommand_CreatePlaylist::DatabaseCommand_CreatePlaylist( const source_ptr
|
||||
void
|
||||
DatabaseCommand_CreatePlaylist::exec( DatabaseImpl* lib )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
Q_ASSERT( !m_playlist.isNull() );
|
||||
Q_ASSERT( !source().isNull() );
|
||||
|
||||
TomahawkSqlQuery cre = lib->newquery();
|
||||
cre.prepare( "INSERT INTO playlist( guid, source, shared, title, info, creator, lastmodified) "
|
||||
"VALUES( :guid, :source, :shared, :title, :info, :creator, :lastmodified )" );
|
||||
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() );
|
||||
|
||||
qDebug() << "CREATE PLAYLIST:" << cre.boundValues();
|
||||
|
||||
cre.exec();
|
||||
createPlaylist(lib, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,3 +45,27 @@ DatabaseCommand_CreatePlaylist::postCommitHook()
|
||||
if( source()->isLocal() )
|
||||
Servent::instance()->triggerDBSync();
|
||||
}
|
||||
|
||||
void
|
||||
DatabaseCommand_CreatePlaylist::createPlaylist( DatabaseImpl* lib, bool dynamic)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
Q_ASSERT( !m_playlist.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 );
|
||||
|
||||
qDebug() << "CREATE PLAYLIST:" << cre.boundValues();
|
||||
|
||||
cre.exec();
|
||||
}
|
||||
|
@@ -39,6 +39,8 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void createPlaylist( DatabaseImpl* lib, bool dynamic = false );
|
||||
|
||||
bool report() { return m_report; }
|
||||
|
||||
private:
|
||||
|
@@ -28,7 +28,7 @@ void DatabaseCommand_LoadAllDynamicPlaylists::exec( DatabaseImpl* dbi )
|
||||
TomahawkSqlQuery query = dbi->newquery();
|
||||
|
||||
query.exec( QString( "SELECT playlist.guid as guid, title, info, creator, lastmodified, shared, currentrevision, dynamic_playlist.pltype, dynamic_playlist.plmode "
|
||||
"FROM playlist, dynamic_playlist WHERE source %1 AND dynplaylist AND playlist.guid = dynamic_playlist.guid" )
|
||||
"FROM playlist, dynamic_playlist WHERE source %1 AND dynplaylist = 'true' AND playlist.guid = dynamic_playlist.guid" )
|
||||
.arg( source()->isLocal() ? "IS NULL" :
|
||||
QString( "=%1" ).arg( source()->id() )
|
||||
) );
|
||||
|
@@ -13,7 +13,7 @@ void DatabaseCommand_LoadAllPlaylists::exec( DatabaseImpl* dbi )
|
||||
TomahawkSqlQuery query = dbi->newquery();
|
||||
|
||||
query.exec( QString( "SELECT guid, title, info, creator, lastmodified, shared, currentrevision "
|
||||
"FROM playlist WHERE source %1 AND NOT dynplaylist" )
|
||||
"FROM playlist WHERE source %1 AND dynplaylist = 'false'" )
|
||||
.arg( source()->isLocal() ? "IS NULL" :
|
||||
QString( "=%1" ).arg( source()->id() )
|
||||
) );
|
||||
|
@@ -298,10 +298,8 @@ DynamicPlaylist::setRevision( const QString& rev,
|
||||
m_generator->setControls( controls );
|
||||
m_generator->setMode( Static );
|
||||
|
||||
PlaylistRevision pr = setNewRevision( rev, neworderedguids, oldorderedguids, is_newest_rev, addedmap );
|
||||
pr.applied = applied;
|
||||
|
||||
DynamicPlaylistRevision dpr = pr;
|
||||
DynamicPlaylistRevision dpr = setNewRevision( rev, neworderedguids, oldorderedguids, is_newest_rev, addedmap );
|
||||
dpr.applied = applied;
|
||||
dpr.controls = controls;
|
||||
dpr.type = type;
|
||||
dpr.mode = Static;
|
||||
@@ -309,9 +307,7 @@ DynamicPlaylist::setRevision( const QString& rev,
|
||||
if( applied )
|
||||
setCurrentrevision( rev );
|
||||
|
||||
qDebug() << "EMITTING REVISION LOADED 1!";
|
||||
// meh :-( emit both, one for PlaylistModel, the other for DynamicWidget
|
||||
// emit revisionLoaded( pr );
|
||||
// qDebug() << "EMITTING REVISION LOADED 1!";
|
||||
emit dynamicRevisionLoaded( dpr );
|
||||
}
|
||||
|
||||
@@ -342,16 +338,14 @@ DynamicPlaylist::setRevision( const QString& rev,
|
||||
m_generator->setControls( controls );
|
||||
m_generator->setMode( OnDemand );
|
||||
|
||||
PlaylistRevision pr;
|
||||
pr.oldrevisionguid = currentrevision();
|
||||
pr.revisionguid = rev;
|
||||
DynamicPlaylistRevision dpr = pr;
|
||||
DynamicPlaylistRevision dpr;
|
||||
dpr.oldrevisionguid = currentrevision();
|
||||
dpr.revisionguid = rev;
|
||||
dpr.controls = controls;
|
||||
dpr.type = type;
|
||||
dpr.mode = OnDemand;
|
||||
|
||||
qDebug() << "EMITTING REVISION LOADED 2!";
|
||||
// emit revisionLoaded( pr );
|
||||
emit revisionLoaded( dpr );
|
||||
// qDebug() << "EMITTING REVISION LOADED 2!";
|
||||
emit dynamicRevisionLoaded( dpr );
|
||||
}
|
||||
|
||||
|
@@ -140,9 +140,9 @@ SourceTreeItem::onPlaylistLoaded( Tomahawk::PlaylistRevision revision )
|
||||
playlist_ptr* pl = reinterpret_cast<playlist_ptr*>(piptr);
|
||||
SourcesModel::SourceType type = static_cast<SourcesModel::SourceType>( pi->data( Type ).toInt() );
|
||||
|
||||
if ( type == SourcesModel::PlaylistSource&& ptr == qlonglong( pl->data() ) )
|
||||
if ( type == SourcesModel::PlaylistSource && ptr == qlonglong( pl->data() ) )
|
||||
{
|
||||
//qDebug() << "Found playlist!";
|
||||
qDebug() << "Found normal playlist!";
|
||||
pi->setEnabled( true );
|
||||
m_current_revisions.insert( pl->data()->guid(), revision.revisionguid );
|
||||
}
|
||||
@@ -161,7 +161,7 @@ void SourceTreeItem::onDynamicPlaylistsAdded( const QList< dynplaylist_ptr >& pl
|
||||
SLOT( onDynamicPlaylistLoaded( Tomahawk::DynamicPlaylistRevision ) ),
|
||||
Qt::QueuedConnection);
|
||||
|
||||
qDebug() << "Dynamic Playlist added:" << p->title() << p->creator() << p->info() << ptr;
|
||||
// qDebug() << "Dynamic Playlist added:" << p->title() << p->creator() << p->info() << p->currentrevision() << ptr;
|
||||
|
||||
playlistAddedInternal( ptr, p, true );
|
||||
}
|
||||
@@ -196,7 +196,6 @@ void SourceTreeItem::onDynamicPlaylistsDeleted( const QList< dynplaylist_ptr >&
|
||||
void SourceTreeItem::onDynamicPlaylistLoaded( DynamicPlaylistRevision revision )
|
||||
{
|
||||
qlonglong ptr = reinterpret_cast<qlonglong>( sender() );
|
||||
qDebug() << "sender ptr:" << ptr;
|
||||
|
||||
QStandardItem* item = m_columns.at( 0 );
|
||||
int rows = item->rowCount();
|
||||
@@ -206,7 +205,7 @@ void SourceTreeItem::onDynamicPlaylistLoaded( DynamicPlaylistRevision revision )
|
||||
qlonglong piptr = pi->data( DynamicPlaylistPointer ).toLongLong();
|
||||
playlist_ptr* pl = reinterpret_cast<playlist_ptr*>(piptr);
|
||||
SourcesModel::SourceType type = static_cast<SourcesModel::SourceType>( pi->data( Type ).toInt() );
|
||||
|
||||
// qDebug() << "found dynamic playlist:" << (*pl)->title() << type;
|
||||
if ( type == SourcesModel::DynamicPlaylistSource && ptr == qlonglong( pl->data() ) )
|
||||
{
|
||||
//qDebug() << "Found playlist!";
|
||||
|
@@ -36,6 +36,7 @@
|
||||
#include "tomahawksettings.h"
|
||||
#include "tomahawktrayicon.h"
|
||||
#include "widgetdragfilter.h"
|
||||
#include "dynamic/GeneratorInterface.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@@ -345,7 +346,11 @@ TomahawkWindow::createPlaylist( bool dynamic )
|
||||
QString id = uuid();
|
||||
QString info = ""; // FIXME
|
||||
QString creator = "someone"; // FIXME
|
||||
DynamicPlaylist::create( author, id, name, info, creator, false );
|
||||
dynplaylist_ptr playlist = DynamicPlaylist::create( author, id, name, info, creator, false );
|
||||
if( playlist->mode() == OnDemand )
|
||||
playlist->createNewRevision( uuid(), playlist->currentrevision(), playlist->type(), playlist->generator()->controls() );
|
||||
else
|
||||
playlist->createNewRevision( uuid(), playlist->currentrevision(), playlist->type(), playlist->generator()->controls(), playlist->entries() );
|
||||
} else
|
||||
{
|
||||
playlistManager()->show( new NewPlaylistWidget() );
|
||||
|
Reference in New Issue
Block a user