DeviceWatcher.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. #include "DeviceWatcher.h"
  2. #include "DiskScanner/DiskScanner.h"
  3. #include "DiskDetach/DiskDetach.h"
  4. #include "RunnableThread.h"
  5. #include <QDebug>
  6. //#include "Detach.h"
  7. #include <QDir>
  8. #include <QRegExp>
  9. #include <sys/stat.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <strings.h>
  14. #include <ctype.h>
  15. #include <sys/un.h>
  16. #include <sys/ioctl.h>
  17. #include <sys/socket.h>
  18. #include <linux/types.h>
  19. #include <linux/netlink.h>
  20. #include <errno.h>
  21. #include <unistd.h>
  22. #include <arpa/inet.h>
  23. #include <netinet/in.h>
  24. #include <sys/prctl.h>
  25. #include <sys/mount.h>
  26. #include <pthread.h>
  27. #include <stdbool.h>
  28. #include<unistd.h>
  29. #include<fcntl.h>
  30. #include <sys/mman.h>
  31. #include <sys/types.h>
  32. #include <QTimer>
  33. #ifdef ENABLE_ARKN141_CAMERA
  34. #include "libusb.h"
  35. #endif
  36. #define USB_MOUNT_POINT "/media/udisk"
  37. #define USB_MOUNT_DATA "fmask=0133,utf8,errors=continue"
  38. #define USB_MOUNT_FLAG (MS_NODEV | MS_NOSUID | MS_DIRSYNC)
  39. #define USB_MOUNT_FORMAT "vfat"
  40. #define USB_MOUNT_FORMAT_EXFAT "-t exfat"
  41. #define SD_MOUNT_POINT "/media/sdisk"
  42. #define SD_MOUNT_FROMAT "vfat"
  43. #define SD_MOUNT_FROMAT_EXFAT "-t exfat"
  44. #define SD_MOUNT_FLAG (MS_NODEV | MS_NOSUID | MS_DIRSYNC)
  45. #define SD_MOUNT_DATA "fmask=0133,utf8,errors=continue"
  46. static const QString mountUSBPath("/media/udisk");
  47. static const QString mountSDPath("/media/sdisk");
  48. class DeviceWatcherPrivate
  49. {
  50. Q_DISABLE_COPY(DeviceWatcherPrivate)
  51. public:
  52. explicit DeviceWatcherPrivate(DeviceWatcher *parent);
  53. ~DeviceWatcherPrivate();
  54. void initialize();
  55. void connectAllSlots();
  56. void diskDeviceAdd(const QString &path);
  57. void diskDeviceRemove(const QString &path);
  58. void usbDiskScan(const QString &path);
  59. void usbDiskCancelScan(const QString &path);
  60. void sdDiskScan(const QString &path);
  61. void sdDiskCancelScan(const QString &path);
  62. bool regExpUSBPath(const QString& path);
  63. bool regExpSDPath(const QString& path);
  64. bool usbSpecialDeviceDetach(const QString &device, const DiskDeviceWatcher::Action action);
  65. QString outDeviceInfo(QString device);
  66. #ifdef ENABLE_ARKN141_CAMERA
  67. int usbArkn141CameraDetach(const QString &path);
  68. #endif
  69. bool m_UsbSpecialDeviceDetach;
  70. DiskScanner* m_USBDiskScanner;
  71. DiskScanner* m_SDDiskScanner;
  72. DiskDetach* m_DiskDetach;
  73. QString m_USBDiskPath;
  74. QString m_SDDiskPath;
  75. DeviceWatcherStatus m_USBDiskStatus;
  76. DeviceWatcherStatus m_SDDiskStatus;
  77. bool m_InitDetach;
  78. private:
  79. DeviceWatcher* m_Parent;
  80. };
  81. DeviceWatcher::DeviceWatcher(QObject *parent)
  82. : QObject(parent)
  83. , m_Private(new DeviceWatcherPrivate(this))
  84. {
  85. }
  86. DeviceWatcher::~DeviceWatcher()
  87. {
  88. }
  89. void DeviceWatcher::onDiskDeviceChangeHandler(const QString &device, const DiskDeviceWatcher::Action action)
  90. {
  91. m_Private->m_DiskDetach->onDiskDeviceChange(device, action);
  92. }
  93. void DeviceWatcher::synchronize()
  94. {
  95. deviceWatcherCheckStatus(DWT_SDDisk);
  96. deviceWatcherCheckStatus(DWT_USBDisk);
  97. }
  98. void DeviceWatcher::deviceWatcherCheckStatus(const int type)
  99. {
  100. switch (type) {
  101. case DWT_SDDisk: {
  102. emit onDeviceWatcherStatus(DWT_SDDisk, m_Private->m_SDDiskStatus);
  103. break;
  104. }
  105. case DWT_USBDisk: {
  106. emit onDeviceWatcherStatus(DWT_USBDisk, m_Private->m_USBDiskStatus);
  107. break;
  108. }
  109. default: {
  110. break;
  111. }
  112. }
  113. }
  114. void DeviceWatcher::timerEvent(QTimerEvent *event)
  115. {
  116. killTimer(event->timerId());
  117. QDir dir("/dev/");
  118. dir.setFilter(QDir::System | QDir::NoDotAndDotDot);
  119. QFileInfoList fileInfoList = dir.entryInfoList();
  120. bool sdExsits(false);
  121. bool usbExists(false);
  122. for (QFileInfoList::iterator fileIter = fileInfoList.begin(); fileIter != fileInfoList.end(); ++fileIter) {
  123. if ((!sdExsits) && (m_Private->regExpSDPath(fileIter->filePath()))) {
  124. sdExsits = true;
  125. onDiskDeviceChangeHandler(fileIter->filePath(), DiskDeviceWatcher::A_Add);
  126. } else if ((!usbExists) && (m_Private->regExpUSBPath(fileIter->filePath()))) {
  127. usbExists = true;
  128. if (0 == QString(qgetenv("PROTOCOL_ID")).compare(QString("yaoxi"))) {
  129. system("echo otg > /sys/devices/platform/musb-ark1680.1/musb-hdrc.1/mode");
  130. } else {
  131. onDiskDeviceChangeHandler(fileIter->filePath(), DiskDeviceWatcher::A_Add);
  132. }
  133. } else if (sdExsits && usbExists) {
  134. break;
  135. }
  136. }
  137. //}
  138. QObject::timerEvent(event);
  139. }
  140. DeviceWatcherPrivate::DeviceWatcherPrivate(DeviceWatcher *parent)
  141. : m_Parent(parent)
  142. {
  143. m_USBDiskScanner = NULL;
  144. m_SDDiskScanner = NULL;
  145. m_DiskDetach = NULL;
  146. m_USBDiskStatus = DWS_Empty;
  147. m_SDDiskStatus = DWS_Empty;
  148. //m_InitDetach = false;
  149. m_UsbSpecialDeviceDetach = false;
  150. initialize();
  151. connectAllSlots();
  152. m_Parent->startTimer(0);
  153. }
  154. DeviceWatcherPrivate::~DeviceWatcherPrivate()
  155. {
  156. // if (m_InitDetach) {
  157. // uninitDetach();
  158. // m_InitDetach = false;
  159. // }
  160. }
  161. void DeviceWatcherPrivate::initialize()
  162. {
  163. QStringList m_MusicSuffix;
  164. m_MusicSuffix.clear();
  165. m_MusicSuffix.append(QString(".MP2"));
  166. m_MusicSuffix.append(QString(".MP3"));
  167. m_MusicSuffix.append(QString(".WMA"));
  168. m_MusicSuffix.append(QString(".M4A"));
  169. m_MusicSuffix.append(QString(".M4R"));
  170. m_MusicSuffix.append(QString(".MMF"));
  171. m_MusicSuffix.append(QString(".FLAC"));
  172. m_MusicSuffix.append(QString(".APE"));
  173. m_MusicSuffix.append(QString(".OGG"));
  174. m_MusicSuffix.append(QString(".AC3"));
  175. m_MusicSuffix.append(QString(".AAC"));
  176. m_MusicSuffix.append(QString(".WAV"));
  177. m_MusicSuffix.append(QString(".AMR"));
  178. m_MusicSuffix.append(QString(".RA"));
  179. m_MusicSuffix.append(QString(".AU"));
  180. m_MusicSuffix.append(QString(".MMF"));
  181. // m_MusicSuffix.append(QString(".AIFF"));
  182. QStringList m_ImageSuffix;
  183. m_ImageSuffix.clear();
  184. m_ImageSuffix.append(QString(".JPG"));
  185. m_ImageSuffix.append(QString(".BMP"));
  186. m_ImageSuffix.append(QString(".JPEG"));
  187. m_ImageSuffix.append(QString(".PNG"));
  188. m_ImageSuffix.append(QString(".GIF"));
  189. m_ImageSuffix.append(QString(".TIF"));
  190. m_ImageSuffix.append(QString(".TIFF"));
  191. m_ImageSuffix.append(QString(".PCX"));
  192. m_ImageSuffix.append(QString(".ICO"));
  193. QStringList m_VideoSuffix;
  194. m_VideoSuffix.clear();
  195. m_VideoSuffix.append(QString(".AVI"));
  196. m_VideoSuffix.append(QString(".MP4"));
  197. m_VideoSuffix.append(QString(".MPG"));
  198. m_VideoSuffix.append(QString(".M4V"));
  199. m_VideoSuffix.append(QString(".MKV"));
  200. m_VideoSuffix.append(QString(".3GP"));
  201. m_VideoSuffix.append(QString(".ASF"));
  202. m_VideoSuffix.append(QString(".MOV"));
  203. m_VideoSuffix.append(QString(".MPEG"));
  204. m_VideoSuffix.append(QString(".VOB"));
  205. m_VideoSuffix.append(QString(".TS"));
  206. m_VideoSuffix.append(QString(".WMV"));
  207. m_VideoSuffix.append(QString(".RM"));
  208. m_VideoSuffix.append(QString(".RMVB"));
  209. m_VideoSuffix.append(QString(".DIVX"));
  210. m_VideoSuffix.append(QString(".FLV"));
  211. m_VideoSuffix.append(QString(".SWF"));
  212. m_VideoSuffix.append(QString(".OGM"));
  213. //m_VideoSuffix.append(QString(".DAT"));
  214. m_USBDiskScanner = new DiskScanner(m_Parent);
  215. m_USBDiskScanner->setMinimumScanTime(1500);
  216. QMap<int, QStringList> map;
  217. map.insert(0, m_MusicSuffix);
  218. map.insert(1, m_ImageSuffix);
  219. map.insert(2, m_VideoSuffix);
  220. m_USBDiskScanner->setScannerSuffixMap(map);
  221. m_SDDiskScanner = new DiskScanner(m_Parent);
  222. m_SDDiskScanner->setMinimumScanTime(1500);
  223. map.insert(0, m_MusicSuffix);
  224. map.insert(1, m_ImageSuffix);
  225. map.insert(2, m_VideoSuffix);
  226. m_SDDiskScanner->setScannerSuffixMap(map);
  227. m_USBDiskPath.clear();
  228. m_SDDiskPath.clear();
  229. m_DiskDetach = new DiskDetach(m_Parent);
  230. }
  231. void DeviceWatcherPrivate::connectAllSlots()
  232. {
  233. Qt::ConnectionType type = static_cast<Qt::ConnectionType>(Qt::UniqueConnection | Qt::AutoConnection);
  234. QObject::connect(m_USBDiskScanner, SIGNAL(filePath(const QString &, const int)),
  235. m_Parent, SLOT(onUSBFilePath(const QString &, const int)),
  236. type);
  237. QObject::connect(m_USBDiskScanner, SIGNAL(finish()),
  238. m_Parent, SLOT(onFinish()),
  239. type);
  240. QObject::connect(m_SDDiskScanner, SIGNAL(filePath(const QString &, const int)),
  241. m_Parent, SLOT(onSDFilePath(const QString &, const int)),
  242. type);
  243. QObject::connect(m_SDDiskScanner, SIGNAL(finish()),
  244. m_Parent, SLOT(onFinish()),
  245. type);
  246. QObject::connect(m_DiskDetach, SIGNAL(diskPartition(const QString &, const DiskDeviceWatcher::Action)),
  247. m_Parent, SLOT(onDiskDeviceChange(const QString &, const DiskDeviceWatcher::Action)),
  248. type);
  249. }
  250. QString DeviceWatcherPrivate::outDeviceInfo(QString device)
  251. {
  252. QString cmdString = "fdisk -l | grep ";
  253. QString cmdOut = "";
  254. char buf[1024] = {0};
  255. int fd[2];
  256. int backfd;
  257. pipe(fd);
  258. backfd = dup(STDOUT_FILENO);
  259. dup2(fd[1],STDOUT_FILENO);
  260. cmdString = cmdString + device;
  261. system(cmdString.toLocal8Bit());
  262. fcntl(fd[0],F_SETFL,O_NONBLOCK);
  263. usleep(100*1000);
  264. read(fd[0],buf,1024);
  265. dup2(backfd,STDOUT_FILENO);
  266. cmdOut = QString(buf);
  267. return cmdOut;
  268. }
  269. void DeviceWatcherPrivate::diskDeviceAdd(const QString &path)
  270. {
  271. if (regExpUSBPath(path)) {
  272. if (m_USBDiskPath.isEmpty()
  273. && QFile::exists(path)) {
  274. if (!QFile::exists(mountUSBPath)) {
  275. system("mkdir -p /media/udisk");
  276. }
  277. QString temp = outDeviceInfo(path);
  278. if (temp.contains(QString("NTFS"))) {
  279. umount(USB_MOUNT_POINT);
  280. QString command = QString("mount -t exfat ") + path + " "+ mountUSBPath;
  281. int ret = system(command.toLocal8Bit().constData());
  282. qDebug()<<"========ret=========="<<ret;
  283. if (0 == ret) {
  284. m_USBDiskPath = path;
  285. usbDiskScan(mountUSBPath);
  286. }
  287. else
  288. {
  289. umount(USB_MOUNT_POINT);
  290. QString command = QString("mount -t ntfs-3g ") + path + " "+ mountUSBPath;
  291. qDebug()<<"+++++command_usb+++++"<<command;
  292. system(command.toLocal8Bit().constData());
  293. m_USBDiskPath = path;
  294. usbDiskScan(mountUSBPath);
  295. }
  296. }
  297. else{
  298. umount(USB_MOUNT_POINT);
  299. int ret = mount(path.toLocal8Bit().data(), USB_MOUNT_POINT, USB_MOUNT_FORMAT, USB_MOUNT_FLAG, USB_MOUNT_DATA);
  300. if (0 == ret) {
  301. m_USBDiskPath = path;
  302. usbDiskScan(mountUSBPath);
  303. }
  304. else
  305. {
  306. qDebug() << "mount usb-fat32 failed!!!!!";
  307. }
  308. }
  309. }
  310. } else if (regExpSDPath(path)) {
  311. if (m_SDDiskPath.isEmpty()
  312. && QFile::exists(path)) {
  313. if (!QFile::exists(mountSDPath)) {
  314. system("mkdir -p /media/sdisk");
  315. }
  316. QString temp = outDeviceInfo(path);
  317. if (temp.contains(QString("NTFS"))) {
  318. umount(SD_MOUNT_POINT);
  319. QString command = QString("mount -t exfat ") + path + " "+ mountSDPath;
  320. int ret = system(command.toLocal8Bit().constData());
  321. qDebug()<<"========ret=========="<<ret;
  322. if (0 == ret) {
  323. m_SDDiskPath = path;
  324. sdDiskScan(mountSDPath);
  325. }
  326. else{
  327. umount(SD_MOUNT_POINT);
  328. QString command = QString("mount -t ntfs-3g ") + path + " "+ mountSDPath;
  329. qDebug()<<"+++++command_sd+++++"<<command;
  330. system(command.toLocal8Bit().constData());
  331. m_USBDiskPath = path;
  332. usbDiskScan(mountSDPath);
  333. }
  334. }
  335. else
  336. {
  337. umount(SD_MOUNT_POINT);
  338. int ret = mount(path.toLocal8Bit().data(), SD_MOUNT_POINT, SD_MOUNT_FROMAT, SD_MOUNT_FLAG, SD_MOUNT_DATA);
  339. if (0 == ret) {
  340. m_SDDiskPath = path;
  341. sdDiskScan(mountSDPath);
  342. }
  343. else
  344. {
  345. qDebug() << "mount sd-fat32 failed!!!!!";
  346. }
  347. }
  348. }
  349. } else {
  350. qDebug() << "add other device!";
  351. }
  352. }
  353. void DeviceWatcherPrivate::diskDeviceRemove(const QString &path)
  354. {
  355. if (m_USBDiskPath == path) {
  356. if (DWS_Unsupport == m_USBDiskStatus) {
  357. m_USBDiskStatus = DWS_Remove;
  358. m_USBDiskPath.clear();
  359. emit m_Parent->onDeviceWatcherStatus(DWT_USBDisk, m_USBDiskStatus);
  360. m_USBDiskStatus = DWS_Empty;
  361. return ;
  362. }
  363. usbDiskCancelScan(mountUSBPath);
  364. QString command = QString(" umount -l ") + mountUSBPath;
  365. int ret = system(command.toLocal8Bit().constData());
  366. if (0 == ret) {
  367. } else {
  368. qDebug() << "umount usb failed!!!!";
  369. }
  370. } else if (m_SDDiskPath == path) {
  371. if (DWS_Unsupport == m_SDDiskStatus) {
  372. m_SDDiskStatus = DWS_Remove;
  373. m_SDDiskPath.clear();
  374. emit m_Parent->onDeviceWatcherStatus(DWT_SDDisk, m_SDDiskStatus);
  375. m_SDDiskStatus = DWS_Empty;
  376. return ;
  377. }
  378. sdDiskCancelScan(mountSDPath);
  379. QString command = QString(" umount -l ") + mountSDPath;
  380. int ret = system(command.toLocal8Bit().constData());
  381. if (0 == ret) {
  382. } else {
  383. qDebug() << "umount sd failed!!!!";
  384. }
  385. } else {
  386. //modify by wandz at20190506
  387. qDebug() << "remove other device!" << path << m_SDDiskPath << m_USBDiskPath;
  388. if (DWS_Unsupport == m_SDDiskStatus) {
  389. m_SDDiskStatus = DWS_Remove;
  390. m_SDDiskPath.clear();
  391. emit m_Parent->onDeviceWatcherStatus(DWT_SDDisk, m_SDDiskStatus);
  392. m_SDDiskStatus = DWS_Empty;
  393. return ;
  394. }
  395. if (DWS_Unsupport == m_USBDiskStatus) {
  396. m_USBDiskStatus = DWS_Remove;
  397. m_USBDiskPath.clear();
  398. emit m_Parent->onDeviceWatcherStatus(DWT_USBDisk, m_USBDiskStatus);
  399. m_USBDiskStatus = DWS_Empty;
  400. return ;
  401. }
  402. }
  403. }
  404. void DeviceWatcherPrivate::usbDiskScan(const QString &path)
  405. {
  406. m_USBDiskStatus = DWS_Busy;
  407. m_USBDiskScanner->startScanner(path);
  408. emit m_Parent->onDeviceWatcherStatus(DWT_USBDisk, m_USBDiskStatus);
  409. }
  410. void DeviceWatcherPrivate::usbDiskCancelScan(const QString &path)
  411. {
  412. m_USBDiskStatus = DWS_Remove;
  413. m_USBDiskPath.clear();
  414. m_USBDiskScanner->stopScanner();
  415. emit m_Parent->onDeviceWatcherStatus(DWT_USBDisk, m_USBDiskStatus);
  416. m_USBDiskStatus = DWS_Empty;
  417. }
  418. void DeviceWatcherPrivate::sdDiskScan(const QString &path)
  419. {
  420. m_SDDiskStatus = DWS_Busy;
  421. m_SDDiskScanner->startScanner(path);
  422. emit m_Parent->onDeviceWatcherStatus(DWT_SDDisk, m_SDDiskStatus);
  423. }
  424. void DeviceWatcherPrivate::sdDiskCancelScan(const QString &path)
  425. {
  426. m_SDDiskStatus = DWS_Remove;
  427. m_SDDiskPath.clear();
  428. m_SDDiskScanner->stopScanner();
  429. emit m_Parent->onDeviceWatcherStatus(DWT_SDDisk, m_SDDiskStatus);
  430. m_SDDiskStatus = DWS_Empty;
  431. }
  432. bool DeviceWatcherPrivate::regExpUSBPath(const QString &path)
  433. {
  434. return path.startsWith(QString("/dev/sd"));
  435. }
  436. bool DeviceWatcherPrivate::regExpSDPath(const QString &path)
  437. {
  438. return (path.startsWith(QString("/dev/mmcblk1")));
  439. }
  440. #ifdef ENABLE_ARKN141_CAMERA
  441. int DeviceWatcherPrivate::usbArkn141CameraDetach(const QString &path)
  442. {
  443. libusb_context *usb_video_context = NULL;
  444. libusb_device_handle *usb_video_handle = NULL;
  445. unsigned int vid = 0x18EC;
  446. unsigned int pid = 0x0141;
  447. int r = -1;
  448. if(regExpUSBPath(path)) {
  449. r = libusb_init(&usb_video_context);
  450. if (r < 0) {
  451. qDebug()<<"### usbArkn141CameraDetach failed, libusb_init NG";
  452. return r;
  453. }
  454. usb_video_handle = libusb_open_device_with_vid_pid(usb_video_context, vid, pid);
  455. if(usb_video_handle) {
  456. libusb_close(usb_video_handle);
  457. usb_video_handle = NULL;
  458. } else {
  459. r = -1;
  460. qDebug()<<"### usbArkn141CameraDetach failed, open_device_with_vid_pid NG";
  461. }
  462. if(usb_video_context) {
  463. libusb_exit(usb_video_context);
  464. usb_video_context = NULL;
  465. }
  466. }
  467. return r;
  468. }
  469. #endif
  470. bool DeviceWatcherPrivate::usbSpecialDeviceDetach(const QString &device, const DiskDeviceWatcher::Action action)
  471. {
  472. bool ret;
  473. switch (action) {
  474. case DiskDeviceWatcher::A_Add: {
  475. if (0) { }
  476. #ifdef ENABLE_ARKN141_CAMERA
  477. else if(usbArkn141CameraDetach(device) == 0) {
  478. m_UsbSpecialDeviceDetach = true;
  479. //Handler(device, DiskDeviceWatcher::A_Remove);
  480. emit m_Parent->onDeviceWatcherStatus(DWT_USBDisk+10, DWS_Ready);
  481. }
  482. #endif
  483. else {
  484. m_UsbSpecialDeviceDetach = false;
  485. }
  486. break;
  487. }
  488. case DiskDeviceWatcher::A_Remove: {
  489. if(m_UsbSpecialDeviceDetach) {
  490. m_UsbSpecialDeviceDetach = false;
  491. #ifdef ENABLE_ARKN141_CAMERA
  492. emit m_Parent->onDeviceWatcherStatus(DWT_USBDisk+10, DWS_Remove);
  493. #endif
  494. return true;
  495. }
  496. break;
  497. }
  498. default: {
  499. m_UsbSpecialDeviceDetach = false;
  500. break;
  501. }
  502. }
  503. return m_UsbSpecialDeviceDetach;
  504. }
  505. void DeviceWatcher::onDiskDeviceChange(const QString &device, const DiskDeviceWatcher::Action action)
  506. {
  507. switch (action) {
  508. case DiskDeviceWatcher::A_Add: {
  509. if(m_Private->usbSpecialDeviceDetach(device, action) == false) {
  510. m_Private->diskDeviceAdd(device);
  511. }
  512. break;
  513. }
  514. case DiskDeviceWatcher::A_Remove: {
  515. if(m_Private->usbSpecialDeviceDetach(device, action) == false) {
  516. m_Private->diskDeviceRemove(device);
  517. }
  518. break;
  519. }
  520. default: {
  521. break;
  522. }
  523. }
  524. }
  525. void DeviceWatcher::onUSBFilePath(const QString &path, const int index)
  526. {
  527. switch(index) {
  528. case 0: {
  529. emit onMusicFilePath(path, DWT_USBDisk);
  530. break;
  531. }
  532. case 1: {
  533. emit onImageFilePath(path, DWT_USBDisk);
  534. break;
  535. }
  536. case 2: {
  537. emit onVideoFilePath(path, DWT_USBDisk);
  538. break;
  539. }
  540. default: {
  541. break;
  542. }
  543. }
  544. }
  545. void DeviceWatcher::onSDFilePath(const QString &path, const int index)
  546. {
  547. switch(index) {
  548. case 0: {
  549. emit onMusicFilePath(path, DWT_SDDisk);
  550. break;
  551. }
  552. case 1: {
  553. emit onImageFilePath(path, DWT_SDDisk);
  554. break;
  555. }
  556. case 2: {
  557. emit onVideoFilePath(path, DWT_SDDisk);
  558. break;
  559. }
  560. default: {
  561. break;
  562. }
  563. }
  564. }
  565. void DeviceWatcher::onFinish()
  566. {
  567. QObject* ptr = sender();
  568. if (ptr == m_Private->m_USBDiskScanner) {
  569. qDebug() << "USB::onFinish";
  570. m_Private->m_USBDiskStatus = DWS_Ready;
  571. emit onDeviceWatcherStatus(DWT_USBDisk, m_Private->m_USBDiskStatus);
  572. } else if (ptr == m_Private->m_SDDiskScanner) {
  573. qDebug() << "SD::onFinish";
  574. m_Private->m_SDDiskStatus = DWS_Ready;
  575. emit onDeviceWatcherStatus(DWT_SDDisk, m_Private->m_SDDiskStatus);
  576. }
  577. }