/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. #include "DatabaseCommand_RenamePlaylist.h"
  19. #include "collection/Collection.h"
  20. #include "network/Servent.h"
  21. #include "utils/Logger.h"
  22. #include "DatabaseImpl.h"
  23. #include "PlaylistEntry.h"
  24. #include "Source.h"
  25. #include <QSqlQuery>
  26. using namespace Tomahawk;
  27. DatabaseCommand_RenamePlaylist::DatabaseCommand_RenamePlaylist( const source_ptr& source, const QString& playlistguid, const QString& playlistTitle )
  28. : DatabaseCommandLoggable( source )
  29. {
  30. setPlaylistguid( playlistguid );
  31. setPlaylistTitle( playlistTitle );
  32. }
  33. void
  34. DatabaseCommand_RenamePlaylist::exec( DatabaseImpl* lib )
  35. {
  36. TomahawkSqlQuery cre = lib->newquery();
  37. QString sql = QString( "UPDATE playlist SET title = :title WHERE guid = :id AND source %1" )
  38. .arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) );
  39. cre.prepare( sql );
  40. cre.bindValue( ":id", m_playlistguid );
  41. cre.bindValue( ":title", m_playlistTitle );
  42. qDebug() << Q_FUNC_INFO << m_playlistTitle << m_playlistguid;
  43. cre.exec();
  44. }
  45. void
  46. DatabaseCommand_RenamePlaylist::postCommitHook()
  47. {
  48. playlist_ptr playlist = Playlist::get( m_playlistguid );
  49. Q_ASSERT( !playlist.isNull() );
  50. if ( !playlist )
  51. return;
  52. tDebug() << "Renaming playlist" << playlist->title() << "to" << m_playlistTitle << m_playlistguid;
  53. playlist->setTitle( m_playlistTitle );
  54. if ( source()->isLocal() )
  55. Servent::instance()->triggerDBSync();
  56. }