1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-15 18:44:30 +02:00

Pimple LoadAllPlaylists

This commit is contained in:
Uwe L. Korn
2013-07-20 13:35:28 +02:00
parent 30db29c564
commit c502f6ac08
3 changed files with 72 additions and 15 deletions

View File

@@ -17,7 +17,7 @@
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "DatabaseCommand_LoadAllPlaylists.h"
#include "DatabaseCommand_LoadAllPlaylists_p.h"
#include "DatabaseImpl.h"
#include "Playlist.h"
@@ -30,20 +30,19 @@ using namespace Tomahawk;
DatabaseCommand_LoadAllPlaylists::DatabaseCommand_LoadAllPlaylists( const source_ptr& s, QObject* parent )
: DatabaseCommand( s, parent )
, m_limitAmount( 0 )
, m_sortOrder( None )
, m_sortDescending( false )
: DatabaseCommand( parent, new DatabaseCommand_LoadAllPlaylistsPrivate( this, s ) )
{
}
void
DatabaseCommand_LoadAllPlaylists::exec( DatabaseImpl* dbi )
{
Q_D( DatabaseCommand_LoadAllPlaylists );
TomahawkSqlQuery query = dbi->newquery();
QString orderToken, sourceToken;
switch ( m_sortOrder )
switch ( d->sortOrder )
{
case 0:
break;
@@ -62,9 +61,9 @@ DatabaseCommand_LoadAllPlaylists::exec( DatabaseImpl* dbi )
"%2 %3 %4"
)
.arg( sourceToken )
.arg( m_sortOrder > 0 ? QString( "ORDER BY %1" ).arg( orderToken ) : QString() )
.arg( m_sortDescending ? "DESC" : QString() )
.arg( m_limitAmount > 0 ? QString( "LIMIT 0, %1" ).arg( m_limitAmount ) : QString() ) );
.arg( d->sortOrder > 0 ? QString( "ORDER BY %1" ).arg( orderToken ) : QString() )
.arg( d->sortDescending ? "DESC" : QString() )
.arg( d->limitAmount > 0 ? QString( "LIMIT 0, %1" ).arg( d->limitAmount ) : QString() ) );
QList<playlist_ptr> plists;
while ( query.next() )
@@ -90,20 +89,23 @@ DatabaseCommand_LoadAllPlaylists::exec( DatabaseImpl* dbi )
void
DatabaseCommand_LoadAllPlaylists::setLimit( unsigned int limit )
{
m_limitAmount = limit;
Q_D( DatabaseCommand_LoadAllPlaylists );
d->limitAmount = limit;
}
void
DatabaseCommand_LoadAllPlaylists::setSortOrder( DatabaseCommand_LoadAllPlaylists::SortOrder order )
{
m_sortOrder = order;
Q_D( DatabaseCommand_LoadAllPlaylists );
d->sortOrder = order;
}
void
DatabaseCommand_LoadAllPlaylists::setSortDescending( bool descending )
{
m_sortDescending = descending;
Q_D( DatabaseCommand_LoadAllPlaylists );
d->sortDescending = descending;
}

View File

@@ -2,6 +2,7 @@
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,6 +18,7 @@
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef DATABASECOMMAND_LOADALLPLAYLIST_H
#define DATABASECOMMAND_LOADALLPLAYLIST_H
@@ -31,6 +33,8 @@
namespace Tomahawk
{
class DatabaseCommand_LoadAllPlaylistsPrivate;
class DLLEXPORT DatabaseCommand_LoadAllPlaylists : public DatabaseCommand
{
Q_OBJECT
@@ -60,9 +64,7 @@ signals:
void done( const QList<Tomahawk::playlist_ptr>& playlists );
private:
unsigned int m_limitAmount;
SortOrder m_sortOrder;
bool m_sortDescending;
Q_DECLARE_PRIVATE( DatabaseCommand_LoadAllPlaylists )
};
} // namespace Tomahawk

View File

@@ -0,0 +1,53 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef DATABASECOMMAND_LOADALLPLAYLISTS_P_H
#define DATABASECOMMAND_LOADALLPLAYLISTS_P_H
#include "DatabaseCommand_LoadAllPlaylists.h"
#include "DatabaseCommand_p.h"
namespace Tomahawk
{
class DatabaseCommand_LoadAllPlaylistsPrivate: public DatabaseCommandPrivate
{
public:
DatabaseCommand_LoadAllPlaylistsPrivate( DatabaseCommand_LoadAllPlaylists* q, const source_ptr& s )
: DatabaseCommandPrivate( q, s )
, limitAmount( 0 )
, sortOrder( DatabaseCommand_LoadAllPlaylists::None )
, sortDescending( false )
{
}
Q_DECLARE_PUBLIC( DatabaseCommand_LoadAllPlaylists )
private:
unsigned int limitAmount;
DatabaseCommand_LoadAllPlaylists::SortOrder sortOrder;
bool sortDescending;
};
}
#endif // DATABASECOMMAND_LOADALLPLAYLISTS_P_H