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

« back to all changes in this revision

Viewing changes to src/Helper/mediadevicewatcher.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
 *      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
#ifndef MEDIADEVICE_H
 
23
#define MEDIADEVICE_H
 
24
 
 
25
#include "interfaces/MediaDeviceInterface.h"
 
26
 
 
27
#include <QThread>
 
28
#include <QSqlDatabase>
 
29
#include <QFileSystemWatcher>
 
30
#include <QMutex>
 
31
 
 
32
#include "TrackInfo.h"
 
33
 
 
34
#ifdef Q_WS_MAC
 
35
    #include "CocoaWatcher.h"
 
36
    #include <CoreFoundation/CoreFoundation.h>
 
37
    #include <Carbon/Carbon.h>
 
38
#endif
 
39
 
 
40
class CocoaThread;
 
41
 
 
42
 
 
43
class MediaDeviceWatcher : public QObject
 
44
{
 
45
    Q_OBJECT
 
46
 
 
47
public:
 
48
    MediaDeviceWatcher();
 
49
    ~MediaDeviceWatcher();
 
50
 
 
51
public slots:
 
52
    void forceDetection( const QString& path );
 
53
 
 
54
  #ifdef Q_WS_MAC
 
55
    void startWithiTunes();
 
56
  #endif
 
57
 
 
58
private slots:
 
59
    void deviceAdded( const QString& uid );
 
60
    void deviceChangeStart( const QString& uid, QDateTime lastItunesUpdateTime );
 
61
    void deviceChangeEnd( const QString& uid );
 
62
 
 
63
    void trackChanged( const TrackInfo& track, int playCounter );
 
64
 
 
65
    void shutdownHelper( const QString& path );
 
66
 
 
67
private:
 
68
    MediaDeviceInterface* m_gpod;
 
69
    QString m_savePath;
 
70
    QDomDocument m_newsubdoc;
 
71
    QDomElement m_submitQueue;
 
72
    QString m_runPath;
 
73
 
 
74
    // DRY function, builds m_subdoc domtree
 
75
    void buildDomTree( const QList<TrackInfo>& );
 
76
 
 
77
  #ifdef Q_WS_MAC
 
78
    CocoaThread* m_cthread;
 
79
  #endif
 
80
 
 
81
    bool updateTrack( TrackInfo track, bool autoScrobble = false );
 
82
    QList<TrackInfo> readQueue( const QString& uid );
 
83
};
 
84
 
 
85
 
 
86
#ifdef Q_WS_MAC
 
87
 
 
88
class CocoaThread : public QThread
 
89
{
 
90
    public:
 
91
    CocoaThread( MediaDeviceWatcher* parent ) : QThread( parent ), m_parent( parent ), m_itunesRunning( false )
 
92
    {
 
93
        start();
 
94
    }
 
95
 
 
96
    ~CocoaThread() { m_run = false; }
 
97
 
 
98
    protected:
 
99
        void run();
 
100
 
 
101
    private:
 
102
        CocoaWatcher* m_cocoa;
 
103
        MediaDeviceWatcher* m_parent;
 
104
        bool m_run;
 
105
        bool m_itunesRunning;
 
106
 
 
107
        bool isITunesRunning();
 
108
};
 
109
 
 
110
 
 
111
#endif // end Q_WS_MAC
 
112
 
 
113
#endif