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

« back to all changes in this revision

Viewing changes to src/mediadevices/gpod/gpoddevice.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Devid Filoni
  • Date: 2008-07-14 16:46:20 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20080714164620-cattx7c83ihhnk4l
Tags: upstream-1.5.1.31879.dfsg
ImportĀ upstreamĀ versionĀ 1.5.1.31879.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2005 - 2007 by                                          *
3
 
 *      Christian Muehlhaeuser, Last.fm Ltd <chris@last.fm>                *
4
 
 *      Erik Jaelevik, Last.fm Ltd <erik@last.fm>                          *
5
 
 *                                                                         *
6
 
 *   This program is free software; you can redistribute it and/or modify  *
7
 
 *   it under the terms of the GNU General Public License as published by  *
8
 
 *   the Free Software Foundation; either version 2 of the License, or     *
9
 
 *   (at your option) any later version.                                   *
10
 
 *                                                                         *
11
 
 *   This program is distributed in the hope that it will be useful,       *
12
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 
 *   GNU General Public License for more details.                          *
15
 
 *                                                                         *
16
 
 *   You should have received a copy of the GNU General Public License     *
17
 
 *   along with this program; if not, write to the                         *
18
 
 *   Free Software Foundation, Inc.,                                       *
19
 
 *   51 Franklin Steet, Fifth Floor, Boston, MA  02110-1301, USA.          *
20
 
 ***************************************************************************/
21
 
 
22
 
#include "gpoddevice.h"
23
 
#include <containerutils.h>
24
 
#include <Loqqer.h>
25
 
 
26
 
 
27
 
GPodDevice::GPodDevice()
28
 
    : m_itdb( 0 )
29
 
{
30
 
    gLogger.Init( savePath( "gpod.log" ), false );
31
 
    gLogger.SetLevel( 4 );
32
 
 
33
 
    LOGL( 3, "Initialising GPod" );
34
 
 
35
 
    m_itdb = itdb_new();
36
 
    if ( !m_itdb )
37
 
        LOGL( 3, "Could not find iPod" );
38
 
 
39
 
    itdb_set_mountpoint( m_itdb, QFile::encodeName( "/home/muesli/last.fm/client/Audioscrobbler/ipodData.new" ) );
40
 
    Itdb_Playlist *mpl = itdb_playlist_new( "iPod", false );
41
 
    itdb_playlist_set_mpl( mpl );
42
 
 
43
 
    GError* err = 0;
44
 
    m_itdb = itdb_parse( QFile::encodeName( "/home/muesli/last.fm/client/Audioscrobbler/ipodData.new" ), &err );
45
 
    if ( err )
46
 
    {
47
 
        g_error_free( err );
48
 
        if ( m_itdb )
49
 
        {
50
 
            itdb_free( m_itdb );
51
 
            m_itdb = 0;
52
 
            return;
53
 
        }
54
 
    }
55
 
}
56
 
 
57
 
 
58
 
QList<TrackInfo>
59
 
GPodDevice::tracks()
60
 
{
61
 
    QList<TrackInfo> tl;
62
 
    if ( !m_itdb )
63
 
        return tl;
64
 
 
65
 
    GList *cur;
66
 
    for ( cur = m_itdb->tracks; cur; cur = cur->next )
67
 
    {
68
 
        Itdb_Track *track = (Itdb_Track *)cur->data;
69
 
 
70
 
        QDateTime dt;
71
 
        if ( track )
72
 
            dt.setTime_t( itdb_time_mac_to_host( track->time_played ) );
73
 
 
74
 
        TrackInfo t;
75
 
        t.setArtist( track->artist );
76
 
        t.setAlbum( track->album );
77
 
        t.setTrack( track->title );
78
 
        t.setPath( track->ipod_path );
79
 
        t.setTimeStamp( dt.toString( "yyyy-MM-dd hh:mm:ss" ) );
80
 
        t.setDuration( track->tracklen / 1000 );
81
 
        t.setPlayCount( track->playcount );
82
 
 
83
 
        if ( dt.toString() != "Thu Jan 1 01:00:00 1970" )
84
 
            tl << t;
85
 
    }
86
 
 
87
 
    return tl;
88
 
}
89
 
 
90
 
Q_EXPORT_PLUGIN2( mediadevice, GPodDevice )