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