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

« back to all changes in this revision

Viewing changes to src/mediadevices/ipod/IpodDevice.h

  • 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
 *      Last.fm Ltd <client@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  02110-1301, USA.          *
 
19
 ***************************************************************************/
 
20
 
 
21
#ifndef IPOD_DEVICE_H
 
22
#define IPOD_DEVICE_H
 
23
 
 
24
#include "TrackInfo.h"
 
25
#include <QSqlDatabase>
 
26
 
 
27
typedef struct _Itdb_iTunesDB Itdb_iTunesDB;
 
28
typedef struct _Itdb_Track Itdb_Track;
 
29
typedef struct _Itdb_Playlist Itdb_Playlist;
 
30
 
 
31
 
 
32
/**
 
33
 * Currently all MediaDevice plugins are instantiated on startup.
 
34
 * In the future it would be better that we only create them as needed
 
35
 */
 
36
class MyMediaDeviceInterface : public QObject
 
37
{
 
38
    Q_OBJECT
 
39
 
 
40
protected:
 
41
    QString m_error;
 
42
    QString m_uid;
 
43
    QString m_mountPath;
 
44
 
 
45
public:
 
46
    /** if you need a persistent sqlite store, use this db
 
47
      * ensure your table name is unique eg ClassNameTracks */
 
48
    QSqlDatabase database() const;
 
49
 
 
50
    /** this must be set or you're going to get database table conflicts among
 
51
      * other things */
 
52
    QString const uniqueId() const { return m_uid; }
 
53
    // because we suck currently, can't be in ctor due to QPlugin restriction but must be set
 
54
    void setUniqueId( const QString& uid ) { m_uid = uid; }
 
55
 
 
56
    /** should be controlled by higher object */
 
57
    void setMountPath( const QString& path ) { m_mountPath = path; }
 
58
 
 
59
    /** return tracks that should be scrobbled, next time this is called you
 
60
      * should return tracks played since then, so you are expected to commit
 
61
      * to the database (or whatever storage solution you choose) before you
 
62
      * return
 
63
      * set m_error if there was an unrecoverable error */
 
64
    virtual QList<TrackInfo> tracksToScrobble() = 0;
 
65
 
 
66
    /** a suggested unique table name */
 
67
    QString tableName() const { return "a" + m_uid; }
 
68
 
 
69
    /** the controlling code will check this if you return an empty track list
 
70
      * above. If the track list is empty and there is no error it will say
 
71
      * "nothing to scrobble", else it will show the error message */
 
72
    QString error() const { return m_error; }
 
73
};
 
74
 
 
75
Q_DECLARE_INTERFACE( MyMediaDeviceInterface, "fm.last.MyMediaDevice/1.0" );
 
76
 
 
77
 
 
78
/** NOTE this means a manually synced ipod */
 
79
class IpodDevice : public MyMediaDeviceInterface
 
80
{
 
81
    Q_OBJECT
 
82
    Q_INTERFACES( MyMediaDeviceInterface );
 
83
 
 
84
public:
 
85
    IpodDevice();
 
86
    ~IpodDevice();
 
87
 
 
88
    virtual QList<TrackInfo> tracksToScrobble();
 
89
 
 
90
private:
 
91
    QDateTime previousPlayTime( Itdb_Track* ) const;
 
92
    uint previousPlayCount( Itdb_Track* ) const;
 
93
 
 
94
    /** to the database */
 
95
    void commit( const TrackInfo& );
 
96
 
 
97
    /** opens the db, allocates a LOT of memory, call after setting m_mountPath */
 
98
    void open();
 
99
 
 
100
private:
 
101
    Itdb_iTunesDB* m_itdb;
 
102
    Itdb_Playlist* m_mpl;
 
103
};
 
104
 
 
105
#endif