1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
#include <QDebug>
#include "qhimddetection.h"
void QHiMDDetection::clearDeviceList()
{
QMDDevice * mddev;
QNetMDDevice * nmddev;
int i = 0;
while( i < dlist.count() )
{
mddev = dlist.at(i);
if(mddev->deviceType() == NETMD_DEVICE)
{
nmddev = static_cast<QNetMDDevice *>(mddev);
if(nmddev->isOpen())
nmddev->close();
delete nmddev;
nmddev = NULL;
dlist.removeAt(i);
continue;
}
else if(mddev->deviceType() == HIMD_DEVICE)
{
remove_himddevice(mddev->path()); // uses platform dependent function if available
continue;
}
}
if(!dlist.isEmpty())
dlist.clear();
emit deviceListChanged(dlist);
}
QHiMDDetection::QHiMDDetection(QObject *parent) :
QObject(parent)
{
}
QHiMDDetection::~QHiMDDetection()
{
clearDeviceList();
cleanup_netmd_list();
}
void QHiMDDetection::cleanup_netmd_list()
{
if(dev_list != NULL)
netmd_clean(&dev_list);
}
void QHiMDDetection::rescan_netmd_devices()
{
QNetMDDevice * dev;
int i = 0;
// find and remove netmd devices
while(i < dlist.count())
{
if(dlist.at(i)->deviceType() != NETMD_DEVICE)
{
i++;
continue;
}
dev = static_cast<QNetMDDevice *>(dlist.at(i));
if(dev->isOpen())
dev->close();
delete dev;
dev = NULL;
dlist.removeAt(i);
}
netmd_clean(&dev_list);
dev_list = NULL;
emit deviceListChanged(dlist);
scan_for_netmd_devices();
}
void QHiMDDetection::scan_for_minidisc_devices()
{
/* create device entry for disc images first */
QHiMDDevice * mddev = new QHiMDDevice();
mddev->setMdInserted(true);
mddev->setName("disc image");
dlist.append(mddev);
emit deviceListChanged(dlist);
scan_for_himd_devices();
scan_for_netmd_devices();
}
void QHiMDDetection::remove_himddevice(QString path)
{
QHiMDDevice * dev = static_cast<QHiMDDevice *>(find_by_path(path));
int i = dlist.indexOf(find_by_path(path));
if(i < 0)
return;
if(dev->isOpen())
dev->close();
delete dev;
dev = NULL;
dlist.removeAt(i);
}
void QHiMDDetection::scan_for_netmd_devices()
{
netmd_device * md;
netmd_error error = netmd_init(&dev_list);
struct libusb_device_descriptor desc;
QNetMDDevice * mddev;
if (error != NETMD_NO_ERROR)
return;
md = dev_list; // pick first device
while( md != NULL) {
libusb_get_device_descriptor(md->usb_dev, &desc);
mddev = new QNetMDDevice();
mddev->setName(identify_usb_device(desc.idVendor, desc.idProduct));
mddev->setUsbDevice(md);
dlist.append(mddev);
emit deviceListChanged(dlist);
md = md->link; // pick next device
}
}
QMDDevice *QHiMDDetection::find_by_path(QString path)
{
QMDDevice * mddev;
foreach(mddev, dlist)
{
if(mddev->path() == path)
return mddev;
}
return NULL;
}
QMDDevice *QHiMDDetection::find_by_name(QString name)
{
QMDDevice * mddev;
foreach(mddev, dlist)
{
if(mddev->name() == name)
return mddev;
}
return NULL;
}
const char * identify_usb_device(int vid, int pid)
{
if(vid == SHARP)
{
switch(pid)
{
case IM_MT880H:
return "SHARP IM-MT880H / IM-MT899H (NetMD)";
case IM_DR400:
return "SHARP IM-DR400 / IM-DR410 (NetMD)";
case IM_DR80:
return "SHARP IM-DR80 / IM-DR420/ IM-DR580 or KENWOOD DMC-S9NET (NetMD)";
}
}
if (vid != SONY)
return NULL;
switch (pid)
{
case MZ_NH1_HIMD:
return "SONY MZ-NH1";
case MZ_NH3D_HIMD:
return "SONY MZ-NH3D";
case MZ_NH900_HIMD:
return "SONY MZ-NH900";
case MZ_NH700_HIMD:
return "SONY MZ-NH700 / MZ-NH800";
case MZ_NH600_HIMD:
return "SONY MZ-NH600(D)";
case LAM_3_HIMD:
return "SONY LAM-3";
case MZ_DH10P_HIMD:
return "SONY MZ-DH10P";
case MZ_RH10_HIMD:
return "SONY MZ-RH10";
case MZ_RH910_HIMD:
return "SONY MZ-RH910";
case CMT_AH10_HIMD:
return "SONY CMT-AH10";
case DS_HMD1_HIMD:
return "SONY DS-HMD1";
case MZ_RH1_HIMD:
return "SONY MZ-RH1";
case PCLK_XX:
return "SONY PCLK-XX (NetMD)";
case UNKNOWN_A:
return "SONY (unknown model, NetMD)";
case MZ_N1:
return "SONY MZ-N1 (NetMD)";
case UNKNOWN_B:
return "SONY (unknown model, NetMD)";
case LAM_1:
return "Sony LAM-1 (NetMD)";
case MDS_JE780:
return "SONY MDS-JE780 / MDS-JE980 (NetMD)";
case MZ_N505:
return "SONY MZ-N505 (NetMD)";
case MZ_S1:
return "SONY MZ-S1 (NetMD)";
case MZ_N707:
return "SONY MZ-N707 (NetMD)";
case CMT_C7NT:
return "SONY CMT-C7NT (NetMD)";
case PCGA_MDN1:
return "SONY PCGA-MDN1 (NetMD)";
case CMT_L7HD:
return "SONY CMT-L7HD (NetMD)";
case MZ_N10:
return "SONY MZ-N10 (NetMD)";
case MZ_N910:
return "SONY MZ-N910 (NetMD)";
case MZ_N710:
return "SONY MZ-N710 / MZ-NE810 / MZ-NF810 (NetMD)";
case MZ_N510:
return "SONY MZ-N510 (NetMD)";
case MZ_NE410:
return "SONY MZ-NE410 / MZ-DN430 / MZ-NF520 (NetMD)";
case MZ_NE810:
return "SONY MZ-NE810 / MZ-NE910 (NetMD)";
case CMT_M333NT:
return "SONY CMT-M333NT / CMT_M373NT (NetMD)";
case LAM_10:
return "SONY LAM-10 (NetMD)";
case AIWA_AM_NX1:
return "AIWA AM-NX1 (NetMD)";
case AIWA_AM_NX9:
return "AIWA AM-NX9 (NetMD)";
case MZ_NH1:
return "SONY MZ-NH1 (NetMD)";
case MZ_NH3D:
return "SONY MZ-NH3D (NetMD)";
case MZ_NH900:
return "SONY MZ-NH900 (NetMD)";
case MZ_NH700:
return "SONY MZ-NH700 / MZ-NH800 (NetMD)";
case MZ_NH600:
return "SONY MZ-NH600 / MZ-NH600D (NetMD)";
case MZ_N920:
return "SONY MZ-N920 (NetMD)";
case LAM_3:
return "SONY LAM-3 (NetMD)";
case MZ_DH10P:
return "SONY MZ-DH10P (NetMD)";
case MZ_RH10:
return "SONY MZ-RH10 (NetMD)";
case MZ_RH910:
return "SONY MZ-RH910 (NetMD)";
case CMT_AH10_A:
return "SONY CMT-AH10 (NetMD)";
case CMT_AH10_B:
return "SONY CMT-AH10 (NetMD)";
case DS_HMD1:
return "SONY DS-HMD1 (NetMD)";
case MZ_RH1:
return "SONY MZ-RH1 (NetMD)";
}
return NULL;
}
|