00001 #ifndef MYTH_MEDIA_H
00002 #define MYTH_MEDIA_H
00003
00004 #include <qobject.h>
00005 #include <qstring.h>
00006 #include <qstringlist.h>
00007
00008 #include "mythexp.h"
00009
00010 typedef enum {
00011 MEDIASTAT_ERROR,
00012 MEDIASTAT_UNKNOWN,
00013 MEDIASTAT_UNPLUGGED,
00014 MEDIASTAT_OPEN,
00015 MEDIASTAT_NODISK,
00016 MEDIASTAT_UNFORMATTED,
00017 MEDIASTAT_USEABLE,
00018 MEDIASTAT_NOTMOUNTED,
00019 MEDIASTAT_MOUNTED
00020 } MediaStatus;
00021
00022 typedef enum {
00023 MEDIATYPE_UNKNOWN = 0x0001,
00024 MEDIATYPE_DATA = 0x0002,
00025 MEDIATYPE_MIXED = 0x0004,
00026 MEDIATYPE_AUDIO = 0x0008,
00027 MEDIATYPE_DVD = 0x0010,
00028 MEDIATYPE_VCD = 0x0020,
00029 MEDIATYPE_MMUSIC = 0x0040,
00030 MEDIATYPE_MVIDEO = 0x0080,
00031 MEDIATYPE_MGALLERY = 0x0100,
00032 MEDIATYPE_END = 0x0200,
00033 } MediaType;
00034
00035 typedef enum {
00036 MEDIAERR_OK,
00037 MEDIAERR_FAILED,
00038 MEDIAERR_UNSUPPORTED
00039 } MediaError;
00040
00041 typedef QMap<QString,uint> ext_cnt_t;
00042 typedef QMap<QString,uint> ext_to_media_t;
00043
00044 class MPUBLIC MythMediaDevice : public QObject
00045 {
00046 Q_OBJECT
00047 friend class MediaMonitorDarwin;
00048 friend class MonitorThreadDarwin;
00049
00050 public:
00051 MythMediaDevice(QObject* par, const char* DevicePath, bool SuperMount,
00052 bool AllowEject);
00053
00054 const QString& getMountPath() const { return m_MountPath; }
00055 void setMountPath(const char *path) { m_MountPath = path; }
00056
00057 const QString& getDevicePath() const { return m_DevicePath; }
00058
00059 const QString& getRealDevice() const
00060 { return m_RealDevice.length() ? m_RealDevice : m_DevicePath; }
00061
00062
00063 const QString& getDeviceModel() const { return m_DeviceModel; }
00064 void setDeviceModel(const char *model) { m_DeviceModel = model; }
00065
00066 MediaStatus getStatus() const { return m_Status; }
00067
00068 const QString& getVolumeID() const { return m_VolumeID; }
00069 void setVolumeID(const char *vol) { m_VolumeID = vol; }
00070
00071 const QString& getKeyID() const { return m_KeyID; }
00072
00073 bool getAllowEject() const { return m_AllowEject; }
00074
00075 bool getLocked() const { return m_Locked; }
00076
00077 bool isDeviceOpen() const;
00078
00080 bool isUsable() const
00081 {
00082 return m_Status == MEDIASTAT_USEABLE
00083 || m_Status == MEDIASTAT_MOUNTED
00084 || m_Status == MEDIASTAT_NOTMOUNTED;
00085 }
00086
00087 MediaType getMediaType() const { return m_MediaType; }
00088
00089 bool isSuperMount() const { return m_SuperMount; }
00090
00091 virtual MediaError testMedia() { return MEDIAERR_UNSUPPORTED; }
00092 virtual bool openDevice();
00093 virtual bool closeDevice();
00094 virtual bool isSameDevice(const QString &path);
00095 virtual void setSpeed(int speed);
00096 virtual MediaStatus checkMedia() = 0;
00097 virtual MediaError eject(bool open_close = true);
00098 virtual MediaError lock();
00099 virtual MediaError unlock();
00100 virtual bool performMountCmd( bool DoMount );
00101
00102 bool mount() { return performMountCmd(true); }
00103 bool unmount() { return performMountCmd(false); }
00104 bool isMounted(bool bVerify = false);
00105
00106 void RegisterMediaExtensions(uint mediatype,
00107 const QString& extensions);
00108
00109
00110 static const char* MediaStatusStrings[];
00111 static const char* MediaErrorStrings[];
00112
00113 void clearData();
00114
00115 const char* MediaTypeString();
00116
00117 static const char* MediaTypeString(MediaType type);
00118
00119 signals:
00120 void statusChanged(MediaStatus oldStatus, MythMediaDevice* pMedia);
00121
00122 protected:
00123 virtual ~MythMediaDevice() {}
00124
00126 virtual void onDeviceMounted(void)
00127 {
00128 MediaType type = DetectMediaType();
00129 if (type != MEDIATYPE_UNKNOWN)
00130 m_MediaType = type;
00131 }
00132
00134 virtual void onDeviceUnmounted() {};
00135
00136 MediaType DetectMediaType(void);
00137 bool ScanMediaType(const QString &directory, ext_cnt_t &counts);
00138
00139 MediaStatus setStatus(MediaStatus newStat, bool CloseIt=false);
00140
00141 QString m_DeviceModel;
00142 QString m_DevicePath;
00143
00144 QString m_KeyID;
00145
00146 QString m_MountPath;
00147
00148 QString m_RealDevice;
00149
00150 QString m_VolumeID;
00151
00152 MediaStatus m_Status;
00153
00154 MediaType m_MediaType;
00155
00156 bool m_AllowEject;
00157 bool m_Locked;
00158 bool m_SuperMount;
00159
00160 int m_DeviceHandle;
00161
00162
00163
00164 private:
00165 ext_to_media_t m_ext_to_media;
00166 };
00167
00168 #endif