/src/libtomahawk/database/DatabaseCommand_LoadAllStations.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 85 lines · 53 code · 15 blank · 17 comment · 3 complexity · 5d2755e7a125a32d6dff90943dd1b1a9 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_LoadAllStations.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. void
  27. DatabaseCommand_LoadAllStations::exec( DatabaseImpl* dbi )
  28. {
  29. TomahawkSqlQuery query = dbi->newquery();
  30. QString orderToken, sourceToken;
  31. switch ( m_sortOrder )
  32. {
  33. case 0:
  34. break;
  35. case DatabaseCommand_LoadAllPlaylists::ModificationTime:
  36. orderToken = "playlist.createdOn";
  37. }
  38. if ( !source().isNull() )
  39. sourceToken = QString( "AND source %1 " ).arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) );
  40. query.exec( QString( "SELECT playlist.guid as guid, title, info, creator, createdOn, lastmodified, shared, currentrevision, dynamic_playlist.pltype, dynamic_playlist.plmode "
  41. "FROM playlist, dynamic_playlist WHERE "
  42. "(dynplaylist = 'true' OR dynplaylist = 1) "
  43. "AND playlist.guid = dynamic_playlist.guid "
  44. "AND dynamic_playlist.plmode = %1 "
  45. "AND (dynamic_playlist.autoload = 'true' OR dynamic_playlist.autoload = 1) "
  46. "%2"
  47. "%3 %4 %5"
  48. )
  49. .arg( OnDemand )
  50. .arg( sourceToken )
  51. .arg( m_sortOrder > 0 ? QString( "ORDER BY %1" ).arg( orderToken ) : QString() )
  52. .arg( m_sortDescending ? "DESC" : QString() )
  53. .arg( m_limitAmount > 0 ? QString( "LIMIT 0, %1" ).arg( m_limitAmount ) : QString() ) );
  54. QList<dynplaylist_ptr> plists;
  55. while ( query.next() )
  56. {
  57. QVariantList data = QVariantList() << query.value(7).toString() //current rev
  58. << query.value(1).toString() //title
  59. << query.value(2).toString() //info
  60. << query.value(3).toString() //creator
  61. << query.value(4).toString() //createdOn
  62. << query.value(8).toString() // dynamic type
  63. << static_cast<GeneratorMode>(query.value(9).toInt()) // dynamic mode
  64. << query.value(6).toBool() //shared
  65. << query.value(5).toInt() //lastmod
  66. << query.value(0).toString(); //GUID
  67. emit stationLoaded( source(), data );
  68. }
  69. emit done();
  70. }