PageRenderTime 130ms CodeModel.GetById 50ms app.highlight 6ms RepoModel.GetById 24ms app.codeStats 0ms

/src/libtomahawk/database/DatabaseCommand_RenamePlaylist.cpp

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