PageRenderTime 57ms CodeModel.GetById 33ms app.highlight 6ms RepoModel.GetById 16ms app.codeStats 0ms

/src/libtomahawk/database/DatabaseCommand_DeleteDynamicPlaylist.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 73 lines | 41 code | 15 blank | 17 comment | 4 complexity | 28016b82a1dfd0bebc49cdfbe49729b1 MD5 | raw file
 1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 2 *
 3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
 4 *
 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.
 9 *
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.
14 *
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/>.
17 */
18
19#include "DatabaseCommand_DeleteDynamicPlaylist.h"
20
21#include "playlist/dynamic/DynamicPlaylist.h"
22#include "network/Servent.h"
23#include "utils/Logger.h"
24
25#include <QSqlQuery>
26
27
28using namespace Tomahawk;
29
30
31DatabaseCommand_DeleteDynamicPlaylist::DatabaseCommand_DeleteDynamicPlaylist( const source_ptr& source, const QString& playlistguid )
32    : DatabaseCommand_DeletePlaylist( source, playlistguid )
33{
34}
35
36
37void
38DatabaseCommand_DeleteDynamicPlaylist::exec( DatabaseImpl* lib )
39{
40    qDebug() << Q_FUNC_INFO << "Deleting dynamic playlist:" << m_playlistguid;
41    DatabaseCommand_DeletePlaylist::exec( lib );
42    TomahawkSqlQuery cre = lib->newquery();
43
44    cre.prepare( "DELETE FROM dynamic_playlist WHERE guid = :id" );
45    cre.bindValue( ":id", m_playlistguid );
46
47    cre.exec();
48}
49
50
51void
52DatabaseCommand_DeleteDynamicPlaylist::postCommitHook()
53{
54    tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Reporting:" << m_playlistguid;
55    if ( !source() || !source()->dbCollection() )
56    {
57        Q_ASSERT( false );
58        return;
59    }
60
61    dynplaylist_ptr playlist = DynamicPlaylist::get( m_playlistguid );
62    if ( playlist )
63    {
64        playlist->reportDeleted( playlist );
65    }
66    else
67    {
68        tLog() << "ERROR: Just tried to load playlist for deletion:" << m_playlistguid << "Did we get a null one?" << playlist.isNull();
69    }
70
71    if ( source()->isLocal() )
72        Servent::instance()->triggerDBSync();
73}