/src/libtomahawk/database/DatabaseCommand_LoadDynamicPlaylist.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 87 lines · 43 code · 16 blank · 28 comment · 1 complexity · ccbdb4928df43112706db4ac99affc1d MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Leo Franchi <lfranchi@kde.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_LoadDynamicPlaylist.h"
  19. #include "playlist/dynamic/DynamicPlaylist.h"
  20. #include "utils/Logger.h"
  21. #include "DatabaseImpl.h"
  22. #include "PlaylistEntry.h"
  23. #include "Source.h"
  24. #include <QSqlQuery>
  25. using namespace Tomahawk;
  26. Tomahawk::DatabaseCommand_LoadDynamicPlaylist::DatabaseCommand_LoadDynamicPlaylist( const source_ptr& s, const QString& guid, QObject* parent )
  27. : DatabaseCommand( s, parent )
  28. , m_plid( guid )
  29. {
  30. }
  31. void
  32. Tomahawk::DatabaseCommand_LoadDynamicPlaylist::exec( DatabaseImpl* dbi )
  33. {
  34. TomahawkSqlQuery query = dbi->newquery();
  35. query.exec( QString( "SELECT playlist.guid as guid, title, info, creator, createdOn, lastmodified, shared, currentrevision, dynamic_playlist.pltype, dynamic_playlist.plmode "
  36. "FROM playlist, dynamic_playlist WHERE "
  37. "source %1 "
  38. "AND (dynplaylist = 'true' OR dynplaylist = 1)"
  39. "AND playlist.guid = dynamic_playlist.guid "
  40. "AND playlist.guid = '%2'" )
  41. .arg( source()->isLocal() ? "IS NULL" : QString( "=%1" ).arg( source()->id() ) ).arg( m_plid ) );
  42. QList<dynplaylist_ptr> plists;
  43. if( query.next() )
  44. {
  45. dynplaylist_ptr p( new DynamicPlaylist( source(),
  46. query.value(7).toString(), //current rev
  47. query.value(1).toString(), //title
  48. query.value(2).toString(), //info
  49. query.value(3).toString(), //creator
  50. query.value(4).toUInt(), //createdOn
  51. query.value(8).toString(), // dynamic type
  52. static_cast<GeneratorMode>(query.value(9).toInt()), // dynamic mode
  53. query.value(6).toBool(), //shared
  54. query.value(5).toInt(), //lastmod
  55. query.value(0).toString() ) ); //GUID
  56. p->setWeakSelf( p.toWeakRef() );
  57. /*
  58. tLog() << "Loaded individual dynamic playlist:" << query.value(7).toString() //current rev
  59. << query.value(1).toString() //title
  60. << query.value(2).toString() //info
  61. << query.value(3).toString() //creator
  62. << query.value(4).toString() //createdOn
  63. << query.value(8).toString() // dynamic type
  64. << static_cast<GeneratorMode>(query.value(9).toInt()) // dynamic mode
  65. << query.value(6).toBool() //shared
  66. << query.value(5).toInt() //lastmod
  67. << query.value(0).toString(); //GUID */
  68. emit dynamicPlaylistLoaded( p );
  69. }
  70. emit done();
  71. }