|
MythTV
0.26-pre
|
00001 #ifndef MYTH_MEDIA_H 00002 #define MYTH_MEDIA_H 00003 00004 #include <QObject> 00005 #include <QMap> 00006 #include <QString> 00007 #include <QEvent> 00008 #include <QPointer> 00009 00010 #include "mythbaseexp.h" 00011 00012 typedef enum { 00013 MEDIASTAT_ERROR, 00014 MEDIASTAT_UNKNOWN, 00015 MEDIASTAT_UNPLUGGED, 00016 MEDIASTAT_OPEN, 00017 MEDIASTAT_NODISK, 00018 MEDIASTAT_UNFORMATTED, 00019 MEDIASTAT_USEABLE, 00020 MEDIASTAT_NOTMOUNTED, 00021 MEDIASTAT_MOUNTED 00022 } MythMediaStatus; 00023 00024 typedef enum { 00025 MEDIATYPE_UNKNOWN = 0x0001, 00026 MEDIATYPE_DATA = 0x0002, 00027 MEDIATYPE_MIXED = 0x0004, 00028 MEDIATYPE_AUDIO = 0x0008, 00029 MEDIATYPE_DVD = 0x0010, 00030 MEDIATYPE_VCD = 0x0020, 00031 MEDIATYPE_MMUSIC = 0x0040, 00032 MEDIATYPE_MVIDEO = 0x0080, 00033 MEDIATYPE_MGALLERY = 0x0100, 00034 MEDIATYPE_BD = 0x0200, 00035 MEDIATYPE_END = 0x0400, 00036 } MythMediaType; 00037 // MediaType conflicts with a definition within OSX Quicktime Libraries. 00038 00039 typedef enum { 00040 MEDIAERR_OK, 00041 MEDIAERR_FAILED, 00042 MEDIAERR_UNSUPPORTED 00043 } MythMediaError; 00044 00045 typedef QMap<QString,uint> ext_cnt_t; 00046 typedef QMap<QString,uint> ext_to_media_t; 00047 00048 class MBASE_PUBLIC MythMediaDevice : public QObject 00049 { 00050 Q_OBJECT 00051 friend class MediaMonitorDarwin; // So these can call setStatus(), 00052 friend class MonitorThreadDarwin; // and trigger posting of MythMediaEvents 00053 00054 public: 00055 MythMediaDevice(QObject* par, const char* DevicePath, bool SuperMount, 00056 bool AllowEject); 00057 00058 const QString& getMountPath() const { return m_MountPath; } 00059 void setMountPath(const char *path) { m_MountPath = path; } 00060 00061 const QString& getDevicePath() const { return m_DevicePath; } 00062 00063 const QString& getRealDevice() const 00064 { return m_RealDevice.length() ? m_RealDevice : m_DevicePath; } 00065 00066 00067 const QString& getDeviceModel() const { return m_DeviceModel; } 00068 void setDeviceModel(const char *model) { m_DeviceModel = model; } 00069 00070 MythMediaStatus getStatus() const { return m_Status; } 00071 00072 const QString& getVolumeID() const { return m_VolumeID; } 00073 void setVolumeID(const char *vol) { m_VolumeID = vol; } 00074 00075 const QString& getKeyID() const { return m_KeyID; } 00076 00077 bool getAllowEject() const { return m_AllowEject; } 00078 00079 bool getLocked() const { return m_Locked; } 00080 00081 bool isDeviceOpen() const; 00082 00084 bool isUsable() const 00085 { 00086 return m_Status == MEDIASTAT_USEABLE 00087 || m_Status == MEDIASTAT_MOUNTED 00088 || m_Status == MEDIASTAT_NOTMOUNTED; 00089 } 00090 00091 MythMediaType getMediaType() const { return m_MediaType; } 00092 00093 bool isSuperMount() const { return m_SuperMount; } 00094 00095 virtual MythMediaError testMedia() { return MEDIAERR_UNSUPPORTED; } 00096 virtual bool openDevice(); 00097 virtual bool closeDevice(); 00098 virtual bool isSameDevice(const QString &path); 00099 virtual void setSpeed(int speed); 00100 virtual MythMediaStatus checkMedia() = 0;// Derived classes MUST implement this. 00101 virtual MythMediaError eject(bool open_close = true); 00102 virtual MythMediaError lock(); 00103 virtual MythMediaError unlock(); 00104 virtual bool performMountCmd( bool DoMount ); 00105 00106 bool mount() { return performMountCmd(true); } 00107 bool unmount() { return performMountCmd(false); } 00108 00109 bool isMounted(bool bVerify = true); 00110 bool findMountPath(); 00111 00112 void RegisterMediaExtensions(uint mediatype, 00113 const QString& extensions); 00114 00115 00116 static const char* MediaStatusStrings[]; 00117 static const char* MediaErrorStrings[]; 00118 00119 void clearData(); 00120 00121 const char* MediaTypeString(); 00122 00123 static const char* MediaTypeString(MythMediaType type); 00124 00125 signals: 00126 void statusChanged(MythMediaStatus oldStatus, MythMediaDevice* pMedia); 00127 00128 protected: 00129 virtual ~MythMediaDevice() {} // use deleteLater... 00130 00132 virtual void onDeviceMounted(void) 00133 { 00134 MythMediaType type = DetectMediaType(); 00135 if (type != MEDIATYPE_UNKNOWN) 00136 m_MediaType = type; 00137 } 00138 00140 virtual void onDeviceUnmounted() {}; 00141 00142 MythMediaType DetectMediaType(void); 00143 bool ScanMediaType(const QString &directory, ext_cnt_t &counts); 00144 00145 MythMediaStatus setStatus(MythMediaStatus newStat, bool CloseIt=false); 00146 00147 QString m_DeviceModel; 00148 QString m_DevicePath; 00149 00150 QString m_KeyID; 00151 00152 QString m_MountPath; 00153 00154 QString m_RealDevice; 00155 00156 QString m_VolumeID; 00157 00158 MythMediaStatus m_Status; 00159 00160 MythMediaType m_MediaType; 00161 00162 bool m_AllowEject; 00163 bool m_Locked; 00164 bool m_SuperMount; 00165 00166 int m_DeviceHandle; 00167 00168 00169 00170 private: 00171 ext_to_media_t m_ext_to_media; 00172 }; 00173 00174 class MBASE_PUBLIC MythMediaEvent : public QEvent 00175 { 00176 public: 00177 MythMediaEvent(MythMediaStatus oldStatus, MythMediaDevice *pDevice) : 00178 QEvent(kEventType), m_OldStatus(oldStatus), m_Device(pDevice) {} 00179 00180 MythMediaStatus getOldStatus(void) const { return m_OldStatus; } 00181 MythMediaDevice* getDevice(void) { return m_Device; } 00182 00183 static Type kEventType; 00184 00185 protected: 00186 MythMediaStatus m_OldStatus; 00187 QPointer<MythMediaDevice> m_Device; 00188 }; 00189 00190 #endif
1.7.6.1