PageRenderTime 237ms CodeModel.GetById 91ms app.highlight 43ms RepoModel.GetById 98ms app.codeStats 0ms

/src/libtomahawk/database/DatabaseCommand_DeletePlaylist.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 72 lines | 39 code | 16 blank | 17 comment | 4 complexity | c25df4f09628d408fa66068ec8b2de66 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_DeletePlaylist.h"
20
21#include <QSqlQuery>
22
23#include "collection/Collection.h"
24#include "network/Servent.h"
25#include "utils/Logger.h"
26
27#include "Playlist.h"
28
29using namespace Tomahawk;
30
31
32DatabaseCommand_DeletePlaylist::DatabaseCommand_DeletePlaylist( const source_ptr& source, const QString& playlistguid )
33    : DatabaseCommandLoggable( source )
34{
35    setPlaylistguid( playlistguid );
36}
37
38
39void
40DatabaseCommand_DeletePlaylist::exec( DatabaseImpl* lib )
41{
42    qDebug() << Q_FUNC_INFO;
43
44    TomahawkSqlQuery cre = lib->newquery();
45
46    QString sql = QString( "DELETE FROM playlist WHERE guid = :id AND source %1" )
47                  .arg( source()->isLocal() ? "IS NULL" : QString("= %1").arg( source()->id() ) );
48    cre.prepare( sql );
49    cre.bindValue( ":id", m_playlistguid );
50
51    cre.exec();
52}
53
54
55void
56DatabaseCommand_DeletePlaylist::postCommitHook()
57{
58    qDebug() << Q_FUNC_INFO << "..reporting..";
59    if ( source().isNull() || source()->dbCollection().isNull() )
60    {
61        qDebug() << "Source has gone offline, not emitting to GUI.";
62        return;
63    }
64
65    playlist_ptr playlist = source()->dbCollection()->playlist( m_playlistguid );
66    Q_ASSERT( !playlist.isNull() );
67    if ( playlist )
68        playlist->reportDeleted( playlist );
69
70    if( source()->isLocal() )
71        Servent::instance()->triggerDBSync();
72}