|
MythTV
0.26-pre
|
00001 00006 #undef UNICODE 00007 #define _WIN32_WINNT 0x0500 00008 #include "compat.h" 00009 00010 #include "mediamonitor-windows.h" 00011 #include "mythcdrom.h" 00012 #include "mythhdd.h" 00013 #include "mythlogging.h" 00014 00015 00022 MediaMonitorWindows::MediaMonitorWindows(QObject* par, 00023 unsigned long interval, 00024 bool allowEject) 00025 : MediaMonitor(par, interval, allowEject) 00026 { 00027 char strDrives[128]; 00028 if (!::GetLogicalDriveStrings(sizeof(strDrives), strDrives)) 00029 return; 00030 00031 for (char *driveName = strDrives; *driveName; 00032 driveName += strlen(driveName) + 1) 00033 { 00034 uint type = ::GetDriveType(driveName); 00035 if (type != DRIVE_REMOVABLE && type != DRIVE_CDROM) 00036 continue; 00037 00038 MythMediaDevice *media = NULL; 00039 00040 if (type == DRIVE_CDROM) 00041 media = MythCDROM::get(this, driveName, false, allowEject); 00042 else 00043 media = MythHDD::Get(this, driveName, false, allowEject); 00044 00045 if (!media) 00046 { 00047 LOG(VB_GENERAL, LOG_ALERT, 00048 "Error. Couldn't create MythMediaDevice."); 00049 return; 00050 } 00051 00052 // We store the volume name to improve 00053 // user activities like ChooseAndEjectMedia(). 00054 char volumeName[MAX_PATH]; 00055 if (GetVolumeInformation(driveName, volumeName, MAX_PATH, 00056 NULL, NULL, NULL, NULL, NULL)) 00057 { 00058 media->setVolumeID(volumeName); 00059 } 00060 00061 AddDevice(media); 00062 } 00063 00064 LOG(VB_MEDIA, LOG_INFO, "Initial device list: " + listDevices()); 00065 } 00066 00067 bool MediaMonitorWindows::AddDevice(MythMediaDevice *pDevice) 00068 { 00069 if (!pDevice) 00070 { 00071 LOG(VB_GENERAL, LOG_ERR, "MediaMonitorWindows::AddDevice(null)"); 00072 return false; 00073 } 00074 00075 QString path = pDevice->getDevicePath(); 00076 00077 // 00078 // Check if this is a duplicate of a device we have already added 00079 // 00080 QList<MythMediaDevice*>::const_iterator itr = m_Devices.begin(); 00081 for (; itr != m_Devices.end(); ++itr) 00082 { 00083 if ((*itr)->getDevicePath() == path) 00084 { 00085 LOG(VB_MEDIA, LOG_INFO, 00086 "MediamonitorWindows::AddDevice() -- " + 00087 QString("Not adding '%1', it appears to be a duplicate.") 00088 .arg(path)); 00089 00090 return false; 00091 } 00092 } 00093 00094 // TODO - either look up the model, or leave blank 00095 pDevice->setDeviceModel(path.toLocal8Bit().constData()); 00096 00097 QMutexLocker locker(&m_DevicesLock); 00098 connect(pDevice, SIGNAL(statusChanged(MythMediaStatus, MythMediaDevice*)), 00099 this, SLOT(mediaStatusChanged(MythMediaStatus, MythMediaDevice*))); 00100 m_Devices.push_back(pDevice); 00101 m_UseCount[pDevice] = 0; 00102 00103 return true; 00104 } 00105 00106 QStringList MediaMonitorWindows::GetCDROMBlockDevices() 00107 { 00108 QStringList list; 00109 00110 char strDrives[128]; 00111 if (::GetLogicalDriveStrings(sizeof(strDrives), strDrives)) 00112 { 00113 for (char* driveName = strDrives; *driveName; 00114 driveName += strlen(driveName) + 1) 00115 { 00116 if (::GetDriveType(driveName) == DRIVE_CDROM) 00117 list.append(driveName); 00118 } 00119 } 00120 00121 return list; 00122 }
1.7.6.1