~ubuntu-branches/ubuntu/lucid/lastfm/lucid

« back to all changes in this revision

Viewing changes to src/Scrobbler-1.2.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Devid Filoni
  • Date: 2008-07-14 16:46:20 UTC
  • mfrom: (1.1.7 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080714164620-67hoz9fs177wpgmr
Tags: 1:1.5.1.31879.dfsg-1ubuntu1
* Merge from Debian unstable (LP: #248100), remaining changes:
  - debian/rules: add dh_icons call
  + debian/control:
    - switch iceweasel to firefox in Recommends field
    - modify debhelper version to >= 5.0.51~
    - modify Maintainer to Ubuntu MOTU Developers

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
 
78
78
    Scrobbler* scrobbler = scrobblerForUser( init.username );
79
79
 
80
 
    if (!scrobbler) {
 
80
    if (!scrobbler)
 
81
    {
81
82
        scrobbler = new Scrobbler( init );
82
83
 
83
84
        connect( scrobbler, SIGNAL(handshaken( Scrobbler* )), SLOT(onHandshaken( Scrobbler* )) );
88
89
 
89
90
        emit status( Scrobbler::Connecting );
90
91
    }
 
92
    else
 
93
        emit status( Scrobbler::Handshaken, init.username );
 
94
 
 
95
    //TODO push the scrobbler to handshake again if exists already
91
96
}
92
97
 
93
98
 
273
278
}
274
279
 
275
280
 
276
 
ScrobbleCache //static
277
 
ScrobbleCache::mediaDeviceCache( const QString& username )
278
 
{
279
 
    ScrobbleCache cache = fromFile( username + "_mediadevice.xml" );
280
 
    cache.m_username = username;
281
 
    return cache;
282
 
}
283
 
 
284
 
 
285
281
ScrobbleCache //static private
286
282
ScrobbleCache::fromFile( const QString& filename )
287
283
{
389
385
    {
390
386
        TrackInfo& cachedtrack = i.next();
391
387
 
 
388
        //HACK we can have multiple tracks at the same time for iPod scrobbling
 
389
        // and they don't have rating characters
 
390
        if (track.source() == TrackInfo::MediaDevice)
 
391
            continue;
 
392
        //HACK
 
393
 
392
394
        if (track.sameAs( cachedtrack ) && track.timeStamp() == cachedtrack.timeStamp())
393
395
        {
394
396
            // This will make sure no information gets lost
431
433
 
432
434
 
433
435
///////////////////////////////////////////////////////////////////////////////>
434
 
ItunesScrobbleHistory::ItunesScrobbleHistory()
435
 
{
436
 
    m_path = MooseUtils::savePath( "iTunesScrobbleHistory.xml" );
437
 
    read();
438
 
}
439
 
 
440
 
 
441
 
void
442
 
ItunesScrobbleHistory::append( const TrackInfo& candidate )
443
 
{
444
 
    QMutableListIterator<TrackInfo> i( m_tracks );
445
 
    while (i.hasNext())
446
 
    {
447
 
        TrackInfo& track = i.next();
448
 
        if (track.sameAs( candidate )) 
449
 
        {
450
 
            int n = track.playCount() + 1;
451
 
 
452
 
            track = candidate; //thus timestamp is set
453
 
            track.setPlayCount( n );
454
 
            write();
455
 
            return;
456
 
        }
457
 
    }
458
 
 
459
 
    // if we get here then that track isn't in the itunes history file
460
 
 
461
 
    ScrobbleCache::append( candidate );
462
 
}
463
 
 
464
 
 
465
 
void
466
 
ItunesScrobbleHistory::prune( const time_t remove_if_before )
467
 
{
468
 
    QMutableListIterator<TrackInfo> i( m_tracks );
469
 
    while (i.hasNext())
470
 
        if (i.next().timeStamp() < remove_if_before)
471
 
            i.remove();
472
 
 
473
 
    write();
474
 
}
475
 
///////////////////////////////////////////////////////////////////////////////>
476
 
 
477
 
 
478
 
///////////////////////////////////////////////////////////////////////////////>
479
436
Scrobbler::Scrobbler( const Scrobbler::Init& init )
480
437
{
481
438
    m_lastError = Scrobbler::ErrorNotInitialized;
619
576
        data += "&a[" + N + "]=" + e(i.artist()) +
620
577
                "&t[" + N + "]=" + e(i.track()) +
621
578
                "&i[" + N + "]=" + QString::number( i.timeStamp() ) +
622
 
                "&o[" + N + "]=" + i.sourceString() + i.authCode() +
 
579
                "&o[" + N + "]=" + i.sourceString() +
623
580
                "&r[" + N + "]=" + i.ratingCharacter() +
624
581
                "&l[" + N + "]=" + e(QString::number( i.duration() )) +
625
582
                "&b[" + N + "]=" + e(i.album()) +