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

« back to all changes in this revision

Viewing changes to src/libLastFmTools/WebService/RadioMetaDataRequest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2007-12-31 09:49:54 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20071231094954-ix1amvcsj9pk61ya
Tags: 1:1.4.1.57486.dfsg-1ubuntu1
* Merge from Debian unstable (LP: #180254), remaining changes:
  - debian/rules;
    - Added dh_icons
  - Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2005 - 2007 by                                          *
3
 
 *      Max Howell, Last.fm Ltd <max@last.fm>                              *
4
 
 *                                                                         *
5
 
 *   This program 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 2 of the License, or     *
8
 
 *   (at your option) any later version.                                   *
9
 
 *                                                                         *
10
 
 *   This program 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 this program; if not, write to the                         *
17
 
 *   Free Software Foundation, Inc.,                                       *
18
 
 *   51 Franklin Steet, Fifth Floor, Boston, MA  02111-1307, USA.          *
19
 
 ***************************************************************************/
20
 
 
21
 
#include "last.fm.h"
22
 
#include "Request.h"
23
 
#include "XmlRpc.h"
24
 
 
25
 
 
26
 
RadioMetaDataRequest::RadioMetaDataRequest()
27
 
        : Request( TypeRadioMetaData, "RadioMetaData" )
28
 
        , m_retry_timeout( 0 )
29
 
{
30
 
    m_retry_timer.setSingleShot( true );
31
 
    
32
 
    connect( &m_retry_timer, SIGNAL(timeout()), SLOT(start()) );
33
 
}
34
 
 
35
 
void
36
 
RadioMetaDataRequest::start()
37
 
{
38
 
    get( basePath() + "/np.php?session=" + session() );
39
 
}
40
 
 
41
 
void
42
 
RadioMetaDataRequest::success( QByteArray data )
43
 
{
44
 
    MetaData track;
45
 
    QString stationName;
46
 
 
47
 
    //TODO mxcl I need to be careful here, check usage before refactoring
48
 
 
49
 
    if ( data.size() <= 0 )
50
 
    {
51
 
        LOGL( 3, "Get metadata for radio failed" );
52
 
        m_track.populate( The::currentMetaData() );
53
 
        
54
 
        //TODO mxcl error handling
55
 
    }
56
 
    else {
57
 
        QString result( data );
58
 
        //LOGL( 4, "result: " << result );
59
 
 
60
 
        track.setArtist( parameter( "artist", result ) );
61
 
        track.setAlbum( parameter( "album", result ) );
62
 
        track.setTrack( parameter( "track", result ) );
63
 
        track.setAlbumPicUrl( parameter( "albumcover_medium", result ) );
64
 
        track.setArtistPageUrl( parameter( "artist_url", result ) );
65
 
        track.setAlbumPageUrl( parameter( "album_url", result ) );
66
 
        track.setTrackPageUrl( parameter( "track_url", result ) );
67
 
        track.setDuration( parameter( "trackduration", result ).toInt() );
68
 
        track.setSource( MetaData::Radio );
69
 
 
70
 
        int errCode = parameter( "error", result ).toInt(); //FIXME: check for possible error codes
71
 
        bool discovery = parameter( "discovery", result ) != "-1";
72
 
        m_stationFeed = parameter( "stationfeed", result );
73
 
        
74
 
        stationName = parameter( "station", result );
75
 
        
76
 
        Q_UNUSED( errCode );
77
 
        Q_UNUSED( discovery );
78
 
    }
79
 
 
80
 
    if (track.sameAs( The::currentMetaData() ))
81
 
    {
82
 
        LOGL( 3, "Re-requesting metadata" );
83
 
        
84
 
        tryAgain();
85
 
    }
86
 
    else
87
 
    {
88
 
        LOGL(3, "got new track, populating The::webService()->currentTrack()" );
89
 
        
90
 
        m_stationName = stationName;
91
 
        m_track.populate( track );
92
 
    }
93
 
}