1
/* 
2
   Copyright (C) 2008 Alejandro Wainzinger <aikawarazuni@gmail.com>
3
4
   This program is free software; you can redistribute it and/or
5
   modify it under the terms of the GNU General Public License
6
   as published by the Free Software Foundation; either version 2
7
   of the License, or (at your option) any later version.
8
9
   This program is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
   GNU General Public License for more details.
13
14
   You should have received a copy of the GNU General Public License
15
   along with this program; if not, write to the Free Software
16
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
17
*/
18
19
/*
20
21
Description:
22
23
The MediaDeviceMonitor connects to the MediaDeviceCache, monitoring the connection and disconnection of devices.  It tests
24
for devices known to Amarok, and if it finds them, sends a signal that the appropriate CollectionFactory is connected to,
25
which triggers the creation of the associated Collection.  Similar behaviour for when a device is disconnected.
26
27
All new MediaDeviceCollection-type classes must add the detection of their device to this class, and have their CollectionFactory
28
connect to the right signals to properly build/delete the associated Collection.  An example of this is seen in the
29
IpodCollectionFactory.
30
31
*/
32
33
#ifndef AMAROK_MEDIADEVICEMONITOR_H
34
#define AMAROK_MEDIADEVICEMONITOR_H
35
36
#include "collection/mediadevicecollection/support/MediaDeviceInfo.h"
37
38
#include "amarok_export.h"
39
40
#include <QObject>
41
42
class QStringList;
43
44
class AMAROK_EXPORT MediaDeviceMonitor : public QObject
45
{
46
    Q_OBJECT
47
48
    public:
49
50
    static MediaDeviceMonitor* instance() { return s_instance ? s_instance : new MediaDeviceMonitor(); }
51
52
    MediaDeviceMonitor();
53
    ~MediaDeviceMonitor();
54
55
    void init(); // connect to MediaDeviceCache
56
57
58
    QStringList getDevices(); // get list of devices
59
    void checkDevices(); // scans for supported devices
60
    void checkDevicesForMtp();
61
    void checkDevicesForIpod();
62
    void checkDevicesForCd();
63
64
    QString isCdPresent();
65
    void ejectCd( const QString &udi );
66
67
    QString currentCdId();
68
    void setCurrentCdId( const QString &id );
69
70
 //   void fetchDevices(); // emits device info for each device present
71
72
    signals:
73
        void deviceRemoved( const QString &udi );
74
        void ipodDetected( const QString &mountPoint, const QString &udi );
75
        void mtpDetected( const QString &serial, const QString &udi );
76
        void audioCdDetected( const QString &udi );
77
78
        void ipodReadyToConnect( const QString &mountpoint, const QString &udi );
79
        void ipodReadyToDisconnect( const QString &udi );
80
        void mtpReadyToConnect( const QString &serial, const QString &udi );
81
        void mtpReadyToDisconnect( const QString &udi );
82
83
        void deviceDetected( const MediaDeviceInfo &deviceinfo );
84
85
    public slots:
86
87
        void connectIpod( const QString &mountpoint, const QString &udi );
88
        void disconnectIpod( const QString &udi );
89
        void connectMtp( const QString &serial, const QString &udi );
90
        void disconnectMtp( const QString &udi );
91
92
93
    private slots:
94
95
96
        void deviceAdded( const QString &udi );
97
        void slotDeviceRemoved( const QString &udi );
98
        void slotAccessibilityChanged( bool accessible, const QString & udi );
99
100
101
    private:
102
103
        bool isIpod( const QString &udi );
104
        bool isMtp( const QString &udi );
105
        bool isAudioCd( const QString &udi );
106
107
        QString m_currentCdId;
108
109
        
110
111
        static MediaDeviceMonitor* s_instance;
112
113
114
};
115
116
#endif /* AMAROK_MEDIADEVICEMONITOR_H */