1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
3
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
5
* Tomahawk is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* Tomahawk is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
19
#include "DatabaseCommand_CreatePlaylist.h"
24
#include "DatabaseImpl.h"
25
#include "TomahawkSqlQuery.h"
26
#include "network/Servent.h"
27
#include "utils/Logger.h"
29
#ifndef ENABLE_HEADLESS
30
#include "ViewManager.h"
33
using namespace Tomahawk;
36
DatabaseCommand_CreatePlaylist::DatabaseCommand_CreatePlaylist( QObject* parent )
37
: DatabaseCommandLoggable( parent )
43
DatabaseCommand_CreatePlaylist::DatabaseCommand_CreatePlaylist( const source_ptr& author,
44
const playlist_ptr& playlist )
45
: DatabaseCommandLoggable( author )
46
, m_playlist( playlist )
47
, m_report( false ) //this ctor used when creating locally, reporting done elsewhere
51
DatabaseCommand_CreatePlaylist::~DatabaseCommand_CreatePlaylist()
55
DatabaseCommand_CreatePlaylist::exec( DatabaseImpl* lib )
57
createPlaylist( lib, false );
61
DatabaseCommand_CreatePlaylist::playlistV() const
64
return QJson::QObjectHelper::qobject2qvariant( (QObject*)m_playlist.data() );
71
DatabaseCommand_CreatePlaylist::postCommitHook()
73
qDebug() << Q_FUNC_INFO;
75
if ( source()->isLocal() )
76
Servent::instance()->triggerDBSync();
78
if ( m_report == false )
81
tDebug() << Q_FUNC_INFO << "reporting...";
82
if ( m_playlist.isNull() )
84
source_ptr src = source();
85
#ifndef ENABLE_HEADLESS
86
QMetaObject::invokeMethod( ViewManager::instance(),
88
Qt::BlockingQueuedConnection,
89
QGenericArgument( "Tomahawk::source_ptr", (const void*)&src ),
90
Q_ARG( QVariant, m_v ) );
95
m_playlist->reportCreated( m_playlist );
101
DatabaseCommand_CreatePlaylist::createPlaylist( DatabaseImpl* lib, bool dynamic)
103
Q_ASSERT( !( m_playlist.isNull() && m_v.isNull() ) );
104
Q_ASSERT( !source().isNull() );
107
if ( m_playlist.isNull() )
109
now = m_v.toMap()[ "createdon" ].toUInt();
113
now = QDateTime::currentDateTime().toTime_t();
114
m_playlist->setCreatedOn( now );
117
TomahawkSqlQuery cre = lib->newquery();
118
cre.prepare( "INSERT INTO playlist( guid, source, shared, title, info, creator, lastmodified, dynplaylist, createdOn ) "
119
"VALUES( :guid, :source, :shared, :title, :info, :creator, :lastmodified, :dynplaylist, :createdOn )" );
121
cre.bindValue( ":source", source()->isLocal() ? QVariant(QVariant::Int) : source()->id() );
122
cre.bindValue( ":dynplaylist", dynamic );
123
cre.bindValue( ":createdOn", now );
124
if ( !m_playlist.isNull() )
126
cre.bindValue( ":guid", m_playlist->guid() );
127
cre.bindValue( ":shared", m_playlist->shared() );
128
cre.bindValue( ":title", m_playlist->title() );
129
cre.bindValue( ":info", m_playlist->info() );
130
cre.bindValue( ":creator", m_playlist->creator() );
131
cre.bindValue( ":lastmodified", m_playlist->lastmodified() );
135
QVariantMap m = m_v.toMap();
136
cre.bindValue( ":guid", m.value( "guid" ) );
137
cre.bindValue( ":shared", m.value( "shared" ) );
138
cre.bindValue( ":title", m.value( "title" ) );
139
cre.bindValue( ":info", m.value( "info" ) );
140
cre.bindValue( ":creator", m.value( "creator" ) );
141
cre.bindValue( ":lastmodified", m.value( "lastmodified", 0 ) );