extragear/multimedia/amarok/src
Seb Ruiz
ruiz at kde.org
Fri Apr 3 13:13:35 CEST 2009
SVN commit 948614 by seb:
Fake implementation of the MemoryQueryMaker COUNT function. This is an
incomplete and incorrect solution which I have written because I did not
know how to correctly implement the MemoryQueryMaker CUSTOM type. Any
advice on writing this would be appreciated (Max?).
MQM currently assumes all Custom types to want to apply a function on
all tracks. This lets us count the number of tracks in a MQM, and shows
track counts correctly for ipod/daap/mtp devices.
CCMAIL: amarok-devel at kde.org
M +12 -5 browsers/CollectionTreeItem.cpp
M +1 -0 browsers/CollectionTreeItem.h
M +42 -25 collection/support/MemoryQueryMaker.cpp
--- trunk/extragear/multimedia/amarok/src/browsers/CollectionTreeItem.cpp #948613:948614
@@ -1,6 +1,7 @@
/******************************************************************************
* Copyright (c) 2007 Alexandre Pereira de Oliveira <aleprj at gmail.com> *
* (c) 2007 Maximilian Kossick <maximilian.kossick at googlemail.com> *
+ * (c) 2009 Seb Ruiz <ruiz at kde.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@@ -20,7 +21,6 @@
#include "CollectionTreeView.h"
#include "amarokconfig.h"
-#include "Debug.h"
#include <KLocale>
@@ -32,6 +32,7 @@
, m_childrenLoaded( false )
, m_isVariousArtistsNode( false )
, m_trackCount( -1 )
+ , m_isCounting( false )
{
if ( m_parent )
m_parent->appendChild( this );
@@ -44,6 +45,7 @@
, m_childrenLoaded( false )
, m_isVariousArtistsNode( false )
, m_trackCount( -1 )
+ , m_isCounting( false )
{
if ( m_parent )
m_parent->appendChild( this );
@@ -56,6 +58,7 @@
, m_childrenLoaded( true )
, m_isVariousArtistsNode( true )
, m_trackCount( -1 )
+ , m_isCounting( false )
{
if( m_parent )
m_parent->m_childItems.insert( 0, this );
@@ -162,8 +165,13 @@
return m_parentCollection->icon();
else if( role == CustomRoles::ByLineRole )
{
+ static const QString counting = i18n( "Counting" );
+ if( m_isCounting )
+ return counting;
if( m_trackCount < 0 )
{
+ m_isCounting = true;
+
QueryMaker *qm = m_parentCollection->queryMaker();
connect( qm, SIGNAL( newResultReady(QString, QStringList) ), SLOT( tracksCounted(QString, QStringList) ) );
@@ -172,7 +180,7 @@
->addReturnFunction( QueryMaker::Count, Meta::valUrl )
->run();
- return i18n( "Counting" );
+ return counting;
}
return i18np( "1 track", "%1 tracks", m_trackCount );
@@ -185,13 +193,12 @@
void
CollectionTreeItem::tracksCounted( QString collectionId, QStringList res )
{
- DEBUG_BLOCK
Q_UNUSED( collectionId );
if( !res.isEmpty() )
m_trackCount = res.first().toInt();
else
- m_trackCount = -1;
- debug() << "Track count for " << data( Qt::DisplayRole ).toString() << " is: " << m_trackCount;
+ m_trackCount = 0;
+ m_isCounting = false;
emit dataUpdated();
}
--- trunk/extragear/multimedia/amarok/src/browsers/CollectionTreeItem.h #948613:948614
@@ -97,6 +97,7 @@
bool m_childrenLoaded;
bool m_isVariousArtistsNode;
int m_trackCount;
+ mutable bool m_isCounting;
};
#endif
--- trunk/extragear/multimedia/amarok/src/collection/support/MemoryQueryMaker.cpp #948613:948614
@@ -25,6 +25,8 @@
#include <threadweaver/Job.h>
#include <threadweaver/ThreadWeaver.h>
+#include <QList>
+#include <QPair>
#include <QSet>
#include <QStack>
@@ -62,6 +64,7 @@
QueryJob *job;
int maxsize;
QStack<ContainerMemoryFilter*> containerFilters;
+ QPair<ReturnFunction, qint64> returnFunction;
bool usingFilters;
bool randomize;
KRandomSequence sequence; //do not reset
@@ -97,6 +100,7 @@
delete d->containerFilters.first();
d->containerFilters.clear();
d->containerFilters.push( new AndContainerMemoryFilter() );
+ d->returnFunction = QPair<ReturnFunction, qint64>();
d->usingFilters = false;
d->randomize = false;
return this;
@@ -112,7 +116,6 @@
{
//the worker thread seems to be running
//TODO: wait or job to complete
-
}
else
{
@@ -167,10 +170,39 @@
template <class PointerType, class ListType>
void MemoryQueryMaker::emitProperResult( ListType& list )
{
+ DEBUG_BLOCK
+ bool returnFuncApplied = true;
+
+ int val = -1;
+ switch( d->returnFunction.first )
+ {
+ case QueryMaker::Count :
+ val = list.size();
+ break;
+
+ case QueryMaker::Sum :
+ case QueryMaker::Max :
+ case QueryMaker::Min :
+ // TODO
+ AMAROK_NOTIMPLEMENTED;
+
+ default:
+ returnFuncApplied = false;
+ return;
+ }
+ if( returnFuncApplied )
+ {
+ QStringList res;
+ res << QString::number( val );
+ emit newResultReady( m_collection->collectionId(), res );
+ return;
+ }
+
if( d->randomize )
d->sequence.randomize<PointerType>( list );
- if ( d->returnDataPtrs ) {
+ if( d->returnDataPtrs )
+ {
DataList data;
foreach( PointerType p, list )
data << DataPtr::staticCast( p );
@@ -187,6 +219,9 @@
//this gets called when we want to return all values for the given query type
switch( d->type )
{
+ case QueryMaker::Custom :
+ AMAROK_NOTIMPLEMENTED
+ warning() << "MemoryQueryMaker CustomType not fully implemented, falling back to all tracks";
case QueryMaker::Track :
{
TrackList tracks = m_collection->trackMap().values();
@@ -235,9 +270,6 @@
emitProperResult<YearPtr, YearList>( years );
break;
}
- case QueryMaker::Custom :
- //TODO stub, fix this
- break;
case QueryMaker::None :
//nothing to do
break;
@@ -249,6 +281,8 @@
{
switch( d->type )
{
+ case QueryMaker::Custom :
+ AMAROK_NOTIMPLEMENTED
case QueryMaker::Track :
{
TrackList newResult;
@@ -325,9 +359,6 @@
emitProperResult<YearPtr, YearList>( list );
break;
}
- case QueryMaker::Custom :
- //hmm, not sure if this makes sense
- break;
case QueryMaker::None:
//should never happen, but handle error anyway
break;
@@ -369,7 +400,7 @@
return this;
case QueryMaker::Custom:
- if ( d->type == QueryMaker::Custom )
+ if ( d->type == QueryMaker::None )
d->type = QueryMaker::Custom;
return this;
case QueryMaker::None:
@@ -396,22 +427,8 @@
QueryMaker*
MemoryQueryMaker::addReturnFunction( ReturnFunction function, qint64 value )
{
- Q_UNUSED( value )
- switch( function )
- {
- case QueryMaker::Count:
- //TODO
- break;
- case QueryMaker::Sum:
- //TODO
- break;
- case QueryMaker::Min:
- //TODO
- break;
- case QueryMaker::Max:
- //TODO
- break;
- }
+ d->returnFunction.first = function;
+ d->returnFunction.second = value;
return this;
}
More information about the Amarok-devel
mailing list