File indexing completed on 2024-04-21 04:47:52
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Alejandro Wainzinger <aikawarazuni@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 /* 0018 0019 Description: 0020 0021 The MediaDeviceMonitor connects to the MediaDeviceCache, monitoring the connection and disconnection of devices. It tests 0022 for devices known to Amarok, and if it finds them, sends a signal that the appropriate CollectionFactory is connected to, 0023 which triggers the creation of the associated Collection. Similar behaviour for when a device is disconnected. 0024 0025 All new MediaDeviceCollection-type classes must register their ConnectionAssistant of their device with this class, and have 0026 it connect to the right signals to properly build/delete the associated Collection. An example of this is seen in the 0027 IpodCollectionFactory. 0028 0029 */ 0030 0031 #ifndef AMAROK_MEDIADEVICEMONITOR_H 0032 #define AMAROK_MEDIADEVICEMONITOR_H 0033 0034 #include "amarok_export.h" 0035 0036 #include <QHash> 0037 #include <QList> 0038 #include <QObject> 0039 0040 class ConnectionAssistant; 0041 class MediaDeviceInfo; 0042 0043 class QStringList; 0044 0045 class AMAROK_EXPORT MediaDeviceMonitor : public QObject 0046 { 0047 Q_OBJECT 0048 0049 public: 0050 0051 static MediaDeviceMonitor* instance() { return s_instance ? s_instance : new MediaDeviceMonitor(); } 0052 0053 MediaDeviceMonitor(); 0054 ~MediaDeviceMonitor() override; 0055 0056 void init(); // connect to MediaDeviceCache 0057 0058 QStringList getDevices(); // get list of devices 0059 0060 /// Get assistant for a given udi 0061 ConnectionAssistant *getUdiAssistant( const QString &udi ) 0062 { 0063 return m_udiAssistants[ udi ]; 0064 } 0065 0066 /** 0067 0068 registerDeviceType adds the device type described by @param assistant to the list 0069 of known device types by the MDM, and then checks the list of known devices 0070 for a match with this type 0071 0072 */ 0073 void registerDeviceType( ConnectionAssistant *assistant ); 0074 0075 public Q_SLOTS: 0076 0077 /** 0078 0079 checkDevice checks if @p udi is a known device 0080 and if so attempts to connect it 0081 0082 checkOneDevice runs an identify check using the given 0083 assistant and udi 0084 0085 checkDevicesFor checks if the device type described 0086 by @p assistant matches any of the udi's in the 0087 MediaDeviceCache, and if so, attempts to connect to 0088 it 0089 0090 */ 0091 0092 void checkDevice( const QString &udi ); 0093 void checkOneDevice( ConnectionAssistant* assistant, const QString& udi ); 0094 void checkDevicesFor( ConnectionAssistant* assistant ); 0095 0096 0097 Q_SIGNALS: 0098 void deviceDetected( const MediaDeviceInfo &deviceinfo ); 0099 void deviceRemoved( const QString &udi ); 0100 0101 0102 private Q_SLOTS: 0103 0104 void deviceAdded( const QString &udi ); 0105 void slotDeviceRemoved( const QString &udi ); 0106 void slotAccessibilityChanged( bool accessible, const QString & udi ); 0107 0108 void slotDequeueWaitingAssistant(); 0109 0110 0111 private: 0112 static MediaDeviceMonitor *s_instance; 0113 0114 // keeps track of which CA to contact for which udi 0115 QHash<QString,ConnectionAssistant*> m_udiAssistants; 0116 // holds all registered assistants 0117 QList<ConnectionAssistant*> m_assistants; 0118 // holds all waiting assistants 0119 QList<ConnectionAssistant*> m_waitingassistants; 0120 // holds index of next waiting assistant to check 0121 // devices with, during initialization of device 0122 // factories 0123 int m_nextassistant; 0124 }; 0125 0126 #endif /* AMAROK_MEDIADEVICEMONITOR_H */ 0127