/src/libtomahawk/database/DatabaseCommand_LoadAllSortedPlaylists.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 77 lines · 47 code · 13 blank · 17 comment · 4 complexity · 7b833856a22edc3dc68287929d77218d 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_LoadAllSortedPlaylists.h"
  19. #include "DatabaseImpl.h"
  20. #include "Playlist.h"
  21. #include "SourceList.h"
  22. using namespace Tomahawk;
  23. void
  24. DatabaseCommand_LoadAllSortedPlaylists::exec( DatabaseImpl* dbi )
  25. {
  26. TomahawkSqlQuery query = dbi->newquery();
  27. QString orderToken, sourceToken, ascDescToken;
  28. switch ( m_sortOrder )
  29. {
  30. case 0:
  31. break;
  32. case DatabaseCommand_LoadAllPlaylists::ModificationTime:
  33. orderToken = "playlist.createdOn";
  34. }
  35. switch ( m_sortAscDesc )
  36. {
  37. case DatabaseCommand_LoadAllPlaylists::NoOrder:
  38. break;
  39. case DatabaseCommand_LoadAllPlaylists::Ascending:
  40. ascDescToken = "ASC";
  41. break;
  42. case DatabaseCommand_LoadAllPlaylists::Descending:
  43. ascDescToken = "DESC";
  44. break;
  45. }
  46. if ( !source().isNull() )
  47. sourceToken = QString( "AND source %1 " ).arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) );
  48. query.exec( QString( "SELECT playlist.guid as guid, title, info, creator, lastmodified, shared, currentrevision, createdOn, dynplaylist, source, dynamic_playlist.pltype, dynamic_playlist.plmode "
  49. "FROM playlist "
  50. "LEFT JOIN dynamic_playlist ON playlist.guid = dynamic_playlist.guid "
  51. "%1 "
  52. "%2 %3 %4"
  53. )
  54. .arg( sourceToken )
  55. .arg( m_sortOrder > 0 ? QString( "ORDER BY %1" ).arg( orderToken ) : QString() )
  56. .arg( ascDescToken )
  57. .arg( m_limitAmount > 0 ? QString( "LIMIT 0, %1" ).arg( m_limitAmount ) : QString() ) );
  58. QList<SourcePlaylistPair> plists;
  59. while ( query.next() )
  60. {
  61. plists << QPair< int, QString >( query.value(9).toInt(), query.value(0).toString() );
  62. }
  63. emit done( plists );
  64. }