DeviceWatcher.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. #include "DeviceWatcher.h"
  2. #include "DiskDetach/DiskDetach.h"
  3. #include "RunnableThread.h"
  4. #include "configUtils.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_LastUSBDiskStatus;
  77. DeviceWatcherStatus m_SDDiskStatus;
  78. bool m_InitDetach;
  79. private:
  80. DeviceWatcher* m_Parent;
  81. };
  82. DeviceWatcher::DeviceWatcher(QObject *parent)
  83. : QObject(parent)
  84. , m_Private(new DeviceWatcherPrivate(this))
  85. {
  86. }
  87. DeviceWatcher::~DeviceWatcher()
  88. {
  89. }
  90. void DeviceWatcher::onDiskDeviceChangeHandler(const QString &device, const DiskDeviceWatcher::Action action)
  91. {
  92. m_Private->m_DiskDetach->onDiskDeviceChange(device, action);
  93. }
  94. void DeviceWatcher::synchronize()
  95. {
  96. deviceWatcherCheckStatus(DWT_SDDisk);
  97. deviceWatcherCheckStatus(DWT_USBDisk);
  98. }
  99. void DeviceWatcher::deviceWatcherCheckStatus(const int type)
  100. {
  101. switch (type) {
  102. case DWT_SDDisk: {
  103. emit onDeviceWatcherStatus(DWT_SDDisk, m_Private->m_SDDiskStatus);
  104. break;
  105. }
  106. case DWT_USBDisk: {
  107. emit onDeviceWatcherStatus(DWT_USBDisk, m_Private->m_USBDiskStatus);
  108. break;
  109. }
  110. default: {
  111. break;
  112. }
  113. }
  114. }
  115. void DeviceWatcher::timerEvent(QTimerEvent *event)
  116. {
  117. //printf("==================%s:%d\n",__func__,__LINE__);
  118. killTimer(event->timerId());
  119. QDir dir("/dev/");
  120. dir.setFilter(QDir::System | QDir::NoDotAndDotDot);
  121. QFileInfoList fileInfoList = dir.entryInfoList();
  122. bool sdExsits(false);
  123. bool usbExists(false);
  124. CHECK_SYSTEM("echo host > /sys/devices/platform/soc/40000000.usb/usb_role/40000000.usb-role-switch/role");
  125. CHECK_SYSTEM("echo host > /sys/devices/platform/soc/40c00000.usb/usb_role/40c00000.usb-role-switch/role");
  126. for (QFileInfoList::iterator fileIter = fileInfoList.begin(); fileIter != fileInfoList.end(); ++fileIter) {
  127. if ((!sdExsits) && (m_Private->regExpSDPath(fileIter->filePath()))) {
  128. sdExsits = true;
  129. onDiskDeviceChangeHandler(fileIter->filePath(), DiskDeviceWatcher::A_Add);
  130. } else if ((!usbExists) && (m_Private->regExpUSBPath(fileIter->filePath()))) {
  131. usbExists = true;
  132. onDiskDeviceChangeHandler(fileIter->filePath(), DiskDeviceWatcher::A_Add);
  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_LastUSBDiskStatus = DWS_Empty;
  148. m_SDDiskStatus = DWS_Empty;
  149. //m_InitDetach = false;
  150. m_UsbSpecialDeviceDetach = false;
  151. initialize();
  152. connectAllSlots();
  153. m_Parent->startTimer(0);
  154. }
  155. DeviceWatcherPrivate::~DeviceWatcherPrivate()
  156. {
  157. // if (m_InitDetach) {
  158. // uninitDetach();
  159. // m_InitDetach = false;
  160. // }
  161. }
  162. void DeviceWatcherPrivate::initialize()
  163. {
  164. QStringList m_MusicSuffix;
  165. m_MusicSuffix.clear();
  166. m_MusicSuffix.append(QString(".MP2"));
  167. m_MusicSuffix.append(QString(".MP3"));
  168. m_MusicSuffix.append(QString(".WMA"));
  169. m_MusicSuffix.append(QString(".M4A"));
  170. m_MusicSuffix.append(QString(".M4R"));
  171. m_MusicSuffix.append(QString(".MMF"));
  172. m_MusicSuffix.append(QString(".FLAC"));
  173. m_MusicSuffix.append(QString(".APE"));
  174. m_MusicSuffix.append(QString(".OGG"));
  175. m_MusicSuffix.append(QString(".AC3"));
  176. m_MusicSuffix.append(QString(".AAC"));
  177. m_MusicSuffix.append(QString(".WAV"));
  178. m_MusicSuffix.append(QString(".AMR"));
  179. m_MusicSuffix.append(QString(".RA"));
  180. m_MusicSuffix.append(QString(".AU"));
  181. m_MusicSuffix.append(QString(".MMF"));
  182. // m_MusicSuffix.append(QString(".AIFF"));
  183. QStringList m_ImageSuffix;
  184. m_ImageSuffix.clear();
  185. m_ImageSuffix.append(QString(".JPG"));
  186. m_ImageSuffix.append(QString(".BMP"));
  187. m_ImageSuffix.append(QString(".JPEG"));
  188. m_ImageSuffix.append(QString(".PNG"));
  189. m_ImageSuffix.append(QString(".GIF"));
  190. m_ImageSuffix.append(QString(".TIF"));
  191. m_ImageSuffix.append(QString(".TIFF"));
  192. m_ImageSuffix.append(QString(".PCX"));
  193. m_ImageSuffix.append(QString(".ICO"));
  194. QStringList m_VideoSuffix;
  195. m_VideoSuffix.clear();
  196. m_VideoSuffix.append(QString(".AVI"));
  197. m_VideoSuffix.append(QString(".MP4"));
  198. m_VideoSuffix.append(QString(".MPG"));
  199. m_VideoSuffix.append(QString(".M4V"));
  200. m_VideoSuffix.append(QString(".MKV"));
  201. m_VideoSuffix.append(QString(".3GP"));
  202. m_VideoSuffix.append(QString(".ASF"));
  203. m_VideoSuffix.append(QString(".MOV"));
  204. m_VideoSuffix.append(QString(".MPEG"));
  205. m_VideoSuffix.append(QString(".VOB"));
  206. m_VideoSuffix.append(QString(".TS"));
  207. m_VideoSuffix.append(QString(".WMV"));
  208. m_VideoSuffix.append(QString(".RM"));
  209. m_VideoSuffix.append(QString(".RMVB"));
  210. m_VideoSuffix.append(QString(".DIVX"));
  211. m_VideoSuffix.append(QString(".FLV"));
  212. m_VideoSuffix.append(QString(".SWF"));
  213. m_VideoSuffix.append(QString(".OGM"));
  214. //m_VideoSuffix.append(QString(".DAT"));
  215. m_USBDiskScanner = new DiskScanner(m_Parent);
  216. m_USBDiskScanner->setMinimumScanTime(1500);
  217. QMap<int, QStringList> map;
  218. map.insert(0, m_MusicSuffix);
  219. map.insert(1, m_ImageSuffix);
  220. map.insert(2, m_VideoSuffix);
  221. m_USBDiskScanner->setScannerSuffixMap(map);
  222. m_SDDiskScanner = new DiskScanner(m_Parent);
  223. m_SDDiskScanner->setMinimumScanTime(1500);
  224. map.insert(0, m_MusicSuffix);
  225. map.insert(1, m_ImageSuffix);
  226. map.insert(2, m_VideoSuffix);
  227. m_SDDiskScanner->setScannerSuffixMap(map);
  228. m_USBDiskPath.clear();
  229. m_SDDiskPath.clear();
  230. m_DiskDetach = new DiskDetach(m_Parent);
  231. }
  232. void DeviceWatcherPrivate::connectAllSlots()
  233. {
  234. Qt::ConnectionType type = static_cast<Qt::ConnectionType>(Qt::UniqueConnection | Qt::AutoConnection);
  235. QObject::connect(m_USBDiskScanner, SIGNAL(filePath(const QString &, const int)),
  236. m_Parent, SLOT(onUSBFilePath(const QString &, const int)),
  237. type);
  238. QObject::connect(m_USBDiskScanner, SIGNAL(finish()),
  239. m_Parent, SLOT(onFinish()),
  240. type);
  241. QObject::connect(m_SDDiskScanner, SIGNAL(filePath(const QString &, const int)),
  242. m_Parent, SLOT(onSDFilePath(const QString &, const int)),
  243. type);
  244. QObject::connect(m_SDDiskScanner, SIGNAL(finish()),
  245. m_Parent, SLOT(onFinish()),
  246. type);
  247. QObject::connect(m_DiskDetach, SIGNAL(diskPartition(const QString &, const DiskDeviceWatcher::Action)),
  248. m_Parent, SLOT(onDiskDeviceChange(const QString &, const DiskDeviceWatcher::Action)),
  249. type);
  250. }
  251. QString DeviceWatcherPrivate::outDeviceInfo(QString device)
  252. {
  253. QString cmdString = "fdisk -l | grep ";
  254. QString cmdOut = "";
  255. char buf[1024] = {0};
  256. int fd[2];
  257. int backfd;
  258. if(pipe(fd) == -1) {
  259. perror("pipe");
  260. }
  261. backfd = dup(STDOUT_FILENO);
  262. dup2(fd[1],STDOUT_FILENO);
  263. cmdString = cmdString + device;
  264. CHECK_SYSTEM(cmdString.toLocal8Bit().data());
  265. fcntl(fd[0],F_SETFL,O_NONBLOCK);
  266. usleep(100*1000);
  267. if(read(fd[0],buf,1024) == -1) {
  268. perror("read");
  269. }
  270. dup2(backfd,STDOUT_FILENO);
  271. cmdOut = QString(buf);
  272. close(fd[0]);
  273. close(fd[1]);
  274. return cmdOut;
  275. }
  276. void DeviceWatcherPrivate::diskDeviceAdd(const QString &path)
  277. {
  278. if (regExpUSBPath(path)) {
  279. if (m_USBDiskPath.isEmpty()
  280. && QFile::exists(path)) {
  281. if (!QFile::exists(mountUSBPath)) {
  282. CHECK_SYSTEM("mount -o remount,rw /");
  283. CHECK_SYSTEM("mkdir -p /media/udisk");
  284. CHECK_SYSTEM("mount -o remount,ro /");
  285. }
  286. QString temp = outDeviceInfo(path);
  287. if(temp.contains(QString("NTFS"))){
  288. umount(USB_MOUNT_POINT);
  289. QString command = QString("mount -t exfat ") + path + " "+ mountUSBPath;
  290. int ret = system(command.toLocal8Bit().constData());
  291. //qDebug()<<"========ret=========="<<ret;
  292. if (0 == ret) {
  293. m_USBDiskPath = path;
  294. usbDiskScan(mountUSBPath);
  295. }
  296. else
  297. {
  298. umount(USB_MOUNT_POINT);
  299. QString command = QString("mount -t ntfs-3g ") + path + " "+ mountUSBPath;
  300. qDebug()<<"+++++command_usb+++++"<<command;
  301. CHECK_SYSTEM(command.toLocal8Bit().constData());
  302. m_USBDiskPath = path;
  303. usbDiskScan(mountUSBPath);
  304. }
  305. }
  306. else{
  307. umount(USB_MOUNT_POINT);
  308. int ret = mount(path.toLocal8Bit().data(), USB_MOUNT_POINT, USB_MOUNT_FORMAT, USB_MOUNT_FLAG, USB_MOUNT_DATA);
  309. if (0 == ret) {
  310. m_USBDiskPath = path;
  311. usbDiskScan(mountUSBPath);
  312. }
  313. else
  314. {
  315. qDebug() << "mount usb-fat32 failed!!!!!";
  316. }
  317. }
  318. }
  319. } else if (regExpSDPath(path)) {
  320. if (m_SDDiskPath.isEmpty()
  321. && QFile::exists(path)) {
  322. if (!QFile::exists(mountSDPath)) {
  323. CHECK_SYSTEM("mount -o remount,rw /");
  324. CHECK_SYSTEM("mkdir -p /media/sdisk");
  325. CHECK_SYSTEM("mount -o remount,ro /");
  326. }
  327. QString temp = outDeviceInfo(path);
  328. if (temp.contains(QString("NTFS"))) {
  329. umount(SD_MOUNT_POINT);
  330. QString command = QString("mount -t exfat ") + path + " "+ mountSDPath;
  331. int ret = system(command.toLocal8Bit().constData());
  332. qDebug()<<"========ret=========="<<ret;
  333. if (0 == ret) {
  334. m_SDDiskPath = path;
  335. sdDiskScan(mountSDPath);
  336. }
  337. else{
  338. umount(SD_MOUNT_POINT);
  339. QString command = QString("mount -t ntfs-3g ") + path + " "+ mountSDPath;
  340. qDebug()<<"+++++command_sd+++++"<<command;
  341. CHECK_SYSTEM(command.toLocal8Bit().constData());
  342. m_USBDiskPath = path;
  343. usbDiskScan(mountSDPath);
  344. }
  345. }
  346. else
  347. {
  348. umount(SD_MOUNT_POINT);
  349. int ret = mount(path.toLocal8Bit().data(), SD_MOUNT_POINT, SD_MOUNT_FROMAT, SD_MOUNT_FLAG, SD_MOUNT_DATA);
  350. if (0 == ret) {
  351. m_SDDiskPath = path;
  352. sdDiskScan(mountSDPath);
  353. }
  354. else
  355. {
  356. qDebug() << "mount sd-fat32 failed!!!!!";
  357. }
  358. }
  359. }
  360. } else {
  361. qDebug() << "add other device!";
  362. }
  363. }
  364. void DeviceWatcherPrivate::diskDeviceRemove(const QString &path)
  365. {
  366. if (m_USBDiskPath == path) {
  367. if (DWS_Unsupport == m_USBDiskStatus) {
  368. m_USBDiskStatus = DWS_Remove;
  369. m_LastUSBDiskStatus = DWS_Remove;
  370. m_USBDiskPath.clear();
  371. emit m_Parent->onDeviceWatcherStatus(DWT_USBDisk, m_USBDiskStatus);
  372. m_USBDiskStatus = DWS_Empty;
  373. return ;
  374. }
  375. usbDiskCancelScan(mountUSBPath);
  376. QString command = QString(" umount -l ") + mountUSBPath;
  377. int ret = system(command.toLocal8Bit().constData());
  378. if (0 == ret) {
  379. } else {
  380. qDebug() << "umount usb failed!!!!";
  381. }
  382. } else if (m_SDDiskPath == path) {
  383. if (DWS_Unsupport == m_SDDiskStatus) {
  384. m_SDDiskStatus = DWS_Remove;
  385. m_SDDiskPath.clear();
  386. emit m_Parent->onDeviceWatcherStatus(DWT_SDDisk, m_SDDiskStatus);
  387. m_SDDiskStatus = DWS_Empty;
  388. return ;
  389. }
  390. sdDiskCancelScan(mountSDPath);
  391. QString command = QString(" umount -l ") + mountSDPath;
  392. int ret = system(command.toLocal8Bit().constData());
  393. if (0 == ret) {
  394. } else {
  395. qDebug() << "umount sd failed!!!!";
  396. }
  397. } else {
  398. //modify by wandz at20190506
  399. qDebug() << "remove other device!" << path << m_SDDiskPath << m_USBDiskPath;
  400. if (DWS_Unsupport == m_SDDiskStatus) {
  401. m_SDDiskStatus = DWS_Remove;
  402. m_SDDiskPath.clear();
  403. emit m_Parent->onDeviceWatcherStatus(DWT_SDDisk, m_SDDiskStatus);
  404. m_SDDiskStatus = DWS_Empty;
  405. return ;
  406. }
  407. if (DWS_Unsupport == m_USBDiskStatus) {
  408. m_USBDiskStatus = DWS_Remove;
  409. m_LastUSBDiskStatus = DWS_Remove;
  410. m_USBDiskPath.clear();
  411. emit m_Parent->onDeviceWatcherStatus(DWT_USBDisk, m_USBDiskStatus);
  412. m_USBDiskStatus = DWS_Empty;
  413. return ;
  414. }
  415. }
  416. }
  417. void DeviceWatcherPrivate::usbDiskScan(const QString &path)
  418. {
  419. m_USBDiskStatus = DWS_Busy;
  420. m_LastUSBDiskStatus = DWS_Busy;
  421. m_USBDiskScanner->startScanner(path);
  422. emit m_Parent->onDeviceWatcherStatus(DWT_USBDisk, m_USBDiskStatus);
  423. }
  424. void DeviceWatcherPrivate::usbDiskCancelScan(const QString &path)
  425. {
  426. Q_UNUSED(path);
  427. m_USBDiskStatus = DWS_Remove;
  428. m_LastUSBDiskStatus = DWS_Remove;
  429. m_USBDiskPath.clear();
  430. //m_USBDiskScanner->stopScanner();
  431. emit m_Parent->onDeviceWatcherStatus(DWT_USBDisk, m_USBDiskStatus);
  432. m_USBDiskStatus = DWS_Empty;
  433. }
  434. void DeviceWatcherPrivate::sdDiskScan(const QString &path)
  435. {
  436. m_SDDiskStatus = DWS_Busy;
  437. m_SDDiskScanner->startScanner(path);
  438. emit m_Parent->onDeviceWatcherStatus(DWT_SDDisk, m_SDDiskStatus);
  439. }
  440. void DeviceWatcherPrivate::sdDiskCancelScan(const QString &path)
  441. {
  442. Q_UNUSED(path);
  443. m_SDDiskStatus = DWS_Remove;
  444. m_SDDiskPath.clear();
  445. // m_SDDiskScanner->stopScanner();
  446. emit m_Parent->onDeviceWatcherStatus(DWT_SDDisk, m_SDDiskStatus);
  447. m_SDDiskStatus = DWS_Empty;
  448. }
  449. bool DeviceWatcherPrivate::regExpUSBPath(const QString &path)
  450. {
  451. return path.startsWith(QString("/dev/sd"));
  452. }
  453. bool DeviceWatcherPrivate::regExpSDPath(const QString &path)
  454. {
  455. return (path.startsWith(QString("/dev/mmcblk1")));
  456. }
  457. #ifdef ENABLE_ARKN141_CAMERA
  458. int DeviceWatcherPrivate::usbArkn141CameraDetach(const QString &path)
  459. {
  460. libusb_context *usb_video_context = NULL;
  461. libusb_device_handle *usb_video_handle = NULL;
  462. unsigned int vid = 0x18EC;
  463. unsigned int pid = 0x0141;
  464. int r = -1;
  465. if(regExpUSBPath(path)) {
  466. r = libusb_init(&usb_video_context);
  467. if (r < 0) {
  468. qDebug()<<"### usbArkn141CameraDetach failed, libusb_init NG";
  469. return r;
  470. }
  471. usb_video_handle = libusb_open_device_with_vid_pid(usb_video_context, vid, pid);
  472. if(usb_video_handle) {
  473. libusb_close(usb_video_handle);
  474. usb_video_handle = NULL;
  475. } else {
  476. r = -1;
  477. qDebug()<<"### usbArkn141CameraDetach failed, open_device_with_vid_pid NG";
  478. }
  479. if(usb_video_context) {
  480. libusb_exit(usb_video_context);
  481. usb_video_context = NULL;
  482. }
  483. }
  484. return r;
  485. }
  486. #endif
  487. bool DeviceWatcherPrivate::usbSpecialDeviceDetach(const QString &device, const DiskDeviceWatcher::Action action)
  488. {
  489. //bool ret;
  490. Q_UNUSED(device);
  491. switch (action) {
  492. case DiskDeviceWatcher::A_Add: {
  493. if (0) { }
  494. #ifdef ENABLE_ARKN141_CAMERA
  495. else if(usbArkn141CameraDetach(device) == 0) {
  496. m_UsbSpecialDeviceDetach = true;
  497. //Handler(device, DiskDeviceWatcher::A_Remove);
  498. emit m_Parent->onDeviceWatcherStatus(DWT_USBDisk+10, DWS_Ready);
  499. }
  500. #endif
  501. else {
  502. m_UsbSpecialDeviceDetach = false;
  503. }
  504. break;
  505. }
  506. case DiskDeviceWatcher::A_Remove: {
  507. if(m_UsbSpecialDeviceDetach) {
  508. m_UsbSpecialDeviceDetach = false;
  509. #ifdef ENABLE_ARKN141_CAMERA
  510. emit m_Parent->onDeviceWatcherStatus(DWT_USBDisk+10, DWS_Remove);
  511. #endif
  512. return true;
  513. }
  514. break;
  515. }
  516. default: {
  517. m_UsbSpecialDeviceDetach = false;
  518. break;
  519. }
  520. }
  521. return m_UsbSpecialDeviceDetach;
  522. }
  523. void DeviceWatcher::onDiskDeviceChange(const QString &device, const DiskDeviceWatcher::Action action)
  524. {
  525. switch (action) {
  526. case DiskDeviceWatcher::A_Add: {
  527. if(m_Private->usbSpecialDeviceDetach(device, action) == false) {
  528. m_Private->m_LastUSBDiskStatus = DWS_Empty;
  529. m_Private->diskDeviceAdd(device);
  530. }
  531. break;
  532. }
  533. case DiskDeviceWatcher::A_Remove: {
  534. if(m_Private->usbSpecialDeviceDetach(device, action) == false) {
  535. m_Private->diskDeviceRemove(device);
  536. }
  537. break;
  538. }
  539. default: {
  540. break;
  541. }
  542. }
  543. }
  544. void DeviceWatcher::onUSBFilePath(const QString &path, const int index)
  545. {
  546. switch(index) {
  547. case 0: {
  548. emit onMusicFilePath(path, DWT_USBDisk);
  549. break;
  550. }
  551. case 1: {
  552. emit onImageFilePath(path, DWT_USBDisk);
  553. break;
  554. }
  555. case 2: {
  556. emit onVideoFilePath(path, DWT_USBDisk);
  557. break;
  558. }
  559. default: {
  560. break;
  561. }
  562. }
  563. }
  564. void DeviceWatcher::onSDFilePath(const QString &path, const int index)
  565. {
  566. switch(index) {
  567. case 0: {
  568. emit onMusicFilePath(path, DWT_SDDisk);
  569. break;
  570. }
  571. case 1: {
  572. emit onImageFilePath(path, DWT_SDDisk);
  573. break;
  574. }
  575. case 2: {
  576. emit onVideoFilePath(path, DWT_SDDisk);
  577. break;
  578. }
  579. default: {
  580. break;
  581. }
  582. }
  583. }
  584. void DeviceWatcher::onFinish()
  585. {
  586. QObject* ptr = sender();
  587. if (ptr == m_Private->m_USBDiskScanner) {
  588. qDebug() << "USB::onFinish";
  589. if(m_Private->m_LastUSBDiskStatus == DWS_Remove) {
  590. return;
  591. }
  592. m_Private->m_USBDiskStatus = DWS_Ready;
  593. m_Private->m_LastUSBDiskStatus = DWS_Ready;
  594. emit onDeviceWatcherStatus(DWT_USBDisk, m_Private->m_USBDiskStatus);
  595. } else if (ptr == m_Private->m_SDDiskScanner) {
  596. qDebug() << "SD::onFinish";
  597. m_Private->m_SDDiskStatus = DWS_Ready;
  598. emit onDeviceWatcherStatus(DWT_SDDisk, m_Private->m_SDDiskStatus);
  599. }
  600. }
  601. void DeviceWatcher::stopUsbScanner(){
  602. if(m_Private->m_USBDiskScanner != NULL){
  603. m_Private->m_USBDiskScanner->stopScanner();
  604. }
  605. }
  606. void DeviceWatcher::stopSdScanner(){
  607. if(m_Private->m_SDDiskScanner != NULL){
  608. m_Private->m_SDDiskScanner->stopScanner();
  609. }
  610. }
  611. void DeviceWatcher::multimediaServiceStart()
  612. {
  613. qDebug() << "*****************************************\n"
  614. "** **\n"
  615. "** multimediaServiceStart **\n"
  616. "** **\n"
  617. "******************************************";
  618. }
  619. QString DeviceWatcher::getUsbDiskPath()
  620. {
  621. return m_Private->m_USBDiskPath;
  622. }