~ubuntu-branches/ubuntu/lucid/amarok/lucid-backports

« back to all changes in this revision

Viewing changes to src/dynamic/biases/EchoNest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2011-03-03 10:27:39 UTC
  • mfrom: (114.1.20 natty)
  • Revision ID: james.westby@ubuntu.com-20110303102739-ar67wpa6mllo59n2
Tags: 2:2.4.0-0ubuntu4~lucid1
* Source backport to lucid (LP: #728447)
  - Drop version requirement on libindicate-qt-dev build-dep

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
#include "EchoNest.h"
18
18
 
19
 
#include "Collection.h"
20
 
#include "CollectionManager.h"
21
 
#include "Debug.h"
 
19
#include "core/collections/Collection.h"
 
20
#include "core-impl/collections/support/CollectionManager.h"
 
21
#include "core/support/Debug.h"
22
22
#include "EngineController.h"
23
 
#include "Meta.h"
24
 
#include "QueryMaker.h"
 
23
#include "core/meta/Meta.h"
 
24
#include "core/collections/QueryMaker.h"
25
25
#include "playlist/PlaylistModelStack.h"
26
26
 
27
27
#include <kio/job.h>
37
37
Dynamic::EchoNestBiasFactory::EchoNestBiasFactory()
38
38
: CustomBiasEntryFactory()
39
39
{
40
 
 
41
40
}
42
41
 
43
42
Dynamic::EchoNestBiasFactory::~EchoNestBiasFactory()
44
43
{
45
 
 
46
44
}
47
45
 
48
46
QString
81
79
 
82
80
Dynamic::EchoNestBias::EchoNestBias()
83
81
    : Dynamic::CustomBiasEntry()
84
 
    , EngineObserver( The::engineController() )
85
82
    , m_artistSuggestedQuery( 0 )
86
83
    , m_qm( 0 )
87
84
    , m_currentOnly( true )
88
85
{
89
 
    DEBUG_BLOCK
90
 
    engineNewTrackPlaying(); // kick it into gear if a track is already playnig. if not, it's harmless
 
86
    DEBUG_BLOCK;
 
87
 
 
88
    EngineController *engine = The::engineController();
 
89
 
 
90
    connect( engine, SIGNAL( trackPlaying( Meta::TrackPtr ) ),
 
91
             this, SLOT( trackPlaying( Meta::TrackPtr ) ) );
 
92
 
 
93
    trackPlaying( engine->currentTrack() ); // kick it into gear if a track is already playing. if not, it's harmless
 
94
 
91
95
}
92
96
 
93
97
Dynamic::EchoNestBias::~EchoNestBias()
128
132
}
129
133
 
130
134
void
131
 
Dynamic::EchoNestBias::engineNewTrackPlaying()
 
135
Dynamic::EchoNestBias::trackPlaying( Meta::TrackPtr track )
132
136
{
133
137
    DEBUG_BLOCK
134
 
    Meta::TrackPtr track = The::engineController()->currentTrack();
135
138
 
136
139
    if( track && track->artist() && !track->artist()->name().isEmpty() )
137
140
    {
155
158
            { // mode is set to whole playlist, so check if any tracks in the playlist aren't saved as Ids yet and query those
156
159
                QList< Meta::TrackPtr > playlist;
157
160
                m_currentPlaylist.clear(); // for searching in later
158
 
                for( int i = 0; i < The::playlist()->rowCount(); i++ )
 
161
                for( int i = 0; i < The::playlist()->qaim()->rowCount(); i++ )
159
162
                {
160
163
                    Meta::TrackPtr t = The::playlist()->trackAt( i );
161
164
                    playlist << t;
248
251
        if( ! m_currentOnly )
249
252
        {
250
253
            // check our map, see if there are any we are still waiting for. if not, do the query
251
 
            foreach( const QString &result, m_artistIds.values() )
 
254
            foreach( const QString &result, m_artistIds )
252
255
            {
253
256
                if( result == "-1" ) // still waiting
254
257
                {
258
261
                    return;
259
262
                }
260
263
            }
261
 
            foreach( const QString &key, m_artistIds.keys() )
 
264
            const QStringList keys = m_artistIds.keys();
 
265
            foreach( const QString &key, keys )
262
266
                toQuery << key;
263
267
            // ok we're not, update our list and do it!
264
268
        } else
316
320
    if( !m_qm ) // maybe this is during startup and we don't have a QM for some reason yet
317
321
        return;
318
322
 
319
 
    //  debug() << "got similar artists:" << similar.values();
 
323
    //debug() << "got similar artists:" << similar.values();
320
324
 
321
325
    m_qm->beginOr();
322
326
    QDomNodeList rel = similar.childNodes();
324
328
    {
325
329
        QDomNode n = rel.at( i );
326
330
        QString artistname = n.firstChildElement( "name" ).text();
327
 
        debug() << "addng related artist:" << artistname;
 
331
        debug() << "Adding related artist:" << artistname;
328
332
        m_qm->addFilter( Meta::valArtist, artistname, true, true );
329
333
 
330
334
    }
331
335
    m_qm->endAndOr();
332
336
 
333
 
    m_qm->setQueryType( QueryMaker::Custom );
 
337
    m_qm->setQueryType( Collections::QueryMaker::Custom );
334
338
    m_qm->addReturnValue( Meta::valUniqueId );
335
339
    m_qm->orderByRandom(); // as to not affect the amortized time
336
340
 
366
370
    Q_UNUSED(collectionId)
367
371
    QMutexLocker locker( &m_mutex );
368
372
 
369
 
    int protocolLength =
370
 
    ( QString( m_collection->uidUrlProtocol() ) + "://" ).length();
 
373
    const int protocolLength = QString( m_collection->uidUrlProtocol() + "://" ).length();
371
374
 
372
375
    QString key;
373
376
    if( m_currentOnly )
522
525
        m_currentOnly = false;
523
526
    else
524
527
        m_currentOnly = true;
525
 
    engineNewTrackPlaying(); // refresh
526
528
 
 
529
    EngineController *engine = The::engineController();
 
530
    trackPlaying( engine->currentTrack() ); // refresh
527
531
}
528
532
 
529
533