/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. #include "DatabaseCommand_DeleteDynamicPlaylist.h"
  19. #include "playlist/dynamic/DynamicPlaylist.h"
  20. #include "network/Servent.h"
  21. #include "utils/Logger.h"
  22. #include <QSqlQuery>
  23. using namespace Tomahawk;
  24. DatabaseCommand_DeleteDynamicPlaylist::DatabaseCommand_DeleteDynamicPlaylist( const source_ptr& source, const QString& playlistguid )
  25. : DatabaseCommand_DeletePlaylist( source, playlistguid )
  26. {
  27. }
  28. void
  29. DatabaseCommand_DeleteDynamicPlaylist::exec( DatabaseImpl* lib )
  30. {
  31. qDebug() << Q_FUNC_INFO << "Deleting dynamic playlist:" << m_playlistguid;
  32. DatabaseCommand_DeletePlaylist::exec( lib );
  33. TomahawkSqlQuery cre = lib->newquery();
  34. cre.prepare( "DELETE FROM dynamic_playlist WHERE guid = :id" );
  35. cre.bindValue( ":id", m_playlistguid );
  36. cre.exec();
  37. }
  38. void
  39. DatabaseCommand_DeleteDynamicPlaylist::postCommitHook()
  40. {
  41. tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Reporting:" << m_playlistguid;
  42. if ( !source() || !source()->dbCollection() )
  43. {
  44. Q_ASSERT( false );
  45. return;
  46. }
  47. dynplaylist_ptr playlist = DynamicPlaylist::get( m_playlistguid );
  48. if ( playlist )
  49. {
  50. playlist->reportDeleted( playlist );
  51. }
  52. else
  53. {
  54. tLog() << "ERROR: Just tried to load playlist for deletion:" << m_playlistguid << "Did we get a null one?" << playlist.isNull();
  55. }
  56. if ( source()->isLocal() )
  57. Servent::instance()->triggerDBSync();
  58. }