dialog.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. #include "dialog.h"
  2. #include "ui_dialog.h"
  3. #include <QMessageBox>
  4. #include "UserDefine.h"
  5. void CALLBACK DisConnectFunc(LLONG lLoginID, char *pchDVRIP, LONG nDVRPort, LDWORD dwUser)
  6. {
  7. Dialog * pThis = (Dialog *)dwUser;
  8. if(NULL == pThis)
  9. {
  10. return;
  11. }
  12. //deal
  13. QEvent* eventDisconnect = new QEvent(QEvent::User);
  14. QApplication::postEvent((QObject*)pThis, eventDisconnect);
  15. return;
  16. }
  17. Dialog::Dialog(QWidget *parent) :
  18. QDialog(parent),
  19. ui(new Ui::Dialog)
  20. {
  21. ui->setupUi(this);
  22. InitData();
  23. }
  24. Dialog::~Dialog()
  25. {
  26. delete ui;
  27. CLIENT_Cleanup();
  28. }
  29. bool Dialog::InitData()
  30. {
  31. CLIENT_Init(DisConnectFunc, (LDWORD)this);
  32. LOG_SET_PRINT_INFO stLogPrintInfo = {sizeof(stLogPrintInfo)};
  33. CLIENT_LogOpen(&stLogPrintInfo);
  34. installEventFilter(this);//install filter
  35. m_counter = new QTimer( this );
  36. m_lLoginHandle = 0;
  37. m_nCurDiskType = 0;
  38. memset(&m_DiskInfo, 0, sizeof(DH_HARDDISK_STATE));
  39. ui->lineEdit3->setEchoMode(QLineEdit::Password);
  40. QDate date = QDate::currentDate();
  41. QTime time = QTime::currentTime();
  42. QDateTime curDateTime(date, time);
  43. ui->DVRdateTime->setDisplayFormat("yyyy.MM.dd hh:mm:ss");
  44. ui->DVRdateTime->setDateTime(curDateTime);
  45. ui->Login->setEnabled( TRUE );
  46. ui->Logout->setEnabled( FALSE );
  47. ui->ButBoot->setEnabled( FALSE );
  48. ui->ButAlarmInStart->setEnabled( FALSE );
  49. ui->ButAlarmInStop->setEnabled( FALSE );
  50. ui->ButAlarmOutStart->setEnabled( FALSE );
  51. ui->ButAlarmOutStop->setEnabled( FALSE );
  52. ui->ButGetTime->setEnabled( FALSE );
  53. ui->ButSetTime->setEnabled( FALSE );
  54. ui->ButDiskControl->setEnabled( FALSE );
  55. return true;
  56. }
  57. bool Dialog::UnInitData()
  58. {
  59. if(m_counter)
  60. delete m_counter;
  61. CLIENT_Cleanup();
  62. return true;
  63. }
  64. void Dialog::on_Login_clicked()
  65. {
  66. QString strIp;
  67. QString strUserName;
  68. QString strDvrPort;
  69. QString strPassword;
  70. strIp = ui->lineEdit1->text();
  71. strUserName = ui->lineEdit4->text();
  72. strPassword = ui->lineEdit3->text();
  73. strDvrPort = ui->lineEdit2->text();
  74. int error = 0;
  75. //get nunber
  76. bool numok = false;
  77. long lPort = strDvrPort.toLong(&numok);
  78. if(numok)
  79. {
  80. NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY stInparam;
  81. memset(&stInparam, 0, sizeof(stInparam));
  82. stInparam.dwSize = sizeof(stInparam);
  83. strncpy(stInparam.szIP, (char*)strIp.toUtf8().data(), sizeof(stInparam.szIP) - 1);
  84. strncpy(stInparam.szPassword, (char*)strPassword.toUtf8().data(), sizeof(stInparam.szPassword) - 1);
  85. strncpy(stInparam.szUserName, (char*)strUserName.toUtf8().data(), sizeof(stInparam.szUserName) - 1);
  86. stInparam.nPort = lPort;
  87. stInparam.emSpecCap = EM_LOGIN_SPEC_CAP_TCP;
  88. NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY stOutparam;
  89. memset(&stOutparam, 0, sizeof(stOutparam));
  90. stOutparam.dwSize = sizeof(stOutparam);
  91. m_lLoginHandle = CLIENT_LoginWithHighLevelSecurity(&stInparam, &stOutparam);
  92. if(m_lLoginHandle == 0)
  93. {
  94. if(stOutparam.nError != 255)
  95. {
  96. QMessageBox::about(this, tr("Prompt"), tr("Login failed!"));
  97. }
  98. else
  99. {
  100. error = CLIENT_GetLastError();
  101. if(error ==NET_ERROR_MAC_VALIDATE_FAILED )
  102. {
  103. QMessageBox::about(this, tr("Prompt"), tr("Login failed! bad mac address"));
  104. }
  105. else if(error ==NET_ERROR_SENIOR_VALIDATE_FAILED)
  106. {
  107. QMessageBox::about(this, tr("Prompt"), tr("Login failed! senior validate failed"));
  108. }
  109. }
  110. }
  111. else
  112. {
  113. ui->Login->setEnabled( FALSE );
  114. ui->Logout->setEnabled( TRUE );
  115. ui->ButBoot->setEnabled( TRUE );
  116. ui->ButAlarmInStart->setEnabled( TRUE );
  117. ui->ButAlarmInStop->setEnabled( TRUE );
  118. ui->ButAlarmOutStart->setEnabled( TRUE );
  119. ui->ButAlarmOutStop->setEnabled( TRUE );
  120. ui->ButGetTime->setEnabled( TRUE );
  121. ui->ButSetTime->setEnabled( TRUE );
  122. ui->ButDiskControl->setEnabled( TRUE );
  123. ui->ComboxChannelIn->clear();
  124. for(int i = 1; i <= stOutparam.stuDeviceInfo.nAlarmInPortNum; i++)
  125. {
  126. QString strdata = QString::number(i, 10);
  127. int nCount = ui->ComboxChannelIn->count();
  128. ui->ComboxChannelIn->insertItem(nCount,strdata);
  129. }
  130. ui->ComboxChannelIn->setCurrentIndex(0);
  131. ui->ComboxChannelOut->clear();
  132. for(int j = 1; j <= stOutparam.stuDeviceInfo.nAlarmOutPortNum; j++)
  133. {
  134. QString strdata = QString::number(j, 10);
  135. int nCount = ui->ComboxChannelOut->count();
  136. ui->ComboxChannelOut->insertItem(nCount, strdata);
  137. }
  138. ui->ComboxChannelOut->setCurrentIndex(0);
  139. GetDiskInformation();
  140. }
  141. }
  142. else
  143. {
  144. int nRet = QMessageBox::warning(this, "Input Error",
  145. "could not convert the port to numbers!\n"
  146. "please try again!\n\n ",
  147. "Retry",
  148. "Quit",0,0,1);
  149. if (nRet == QMessageBox::Retry)
  150. {
  151. }
  152. }
  153. }
  154. void Dialog::on_Logout_clicked()
  155. {
  156. if (m_lLoginHandle != 0)
  157. {
  158. BOOL bSuccess = CLIENT_Logout(m_lLoginHandle);
  159. if(bSuccess)
  160. {
  161. m_lLoginHandle = 0;
  162. m_nCurDiskType = 0;
  163. ui->Login->setEnabled( TRUE );
  164. ui->Logout->setEnabled( FALSE );
  165. ui->ButBoot->setEnabled( FALSE );
  166. ui->ButAlarmInStart->setEnabled( FALSE );
  167. ui->ButAlarmInStop->setEnabled( FALSE );
  168. ui->ButAlarmOutStart->setEnabled( FALSE );
  169. ui->ButAlarmOutStop->setEnabled( FALSE );
  170. ui->ButGetTime->setEnabled( FALSE );
  171. ui->ButSetTime->setEnabled( FALSE );
  172. ui->ButDiskControl->setEnabled( FALSE );
  173. ui->ComboxChannelIn->clear();
  174. ui->ComboxChannelOut->clear();
  175. }
  176. else
  177. {
  178. QMessageBox::about(this, tr("Prompt"), tr("Logout failed!"));
  179. }
  180. }
  181. }
  182. /// Net Trigger Alarm In
  183. void Dialog::on_ButAlarmInStart_clicked()
  184. {
  185. if(0 != m_lLoginHandle)
  186. {
  187. ALARMCTRL_PARAM alarmParam = {0};
  188. alarmParam.dwSize = sizeof(ALARMCTRL_PARAM);
  189. alarmParam.nAction = 1;
  190. alarmParam.nAlarmNo = ui->ComboxChannelIn->currentIndex();
  191. BOOL bSuccess = CLIENT_ControlDevice(m_lLoginHandle, DH_TRIGGER_ALARM_IN, &alarmParam);
  192. if(bSuccess)
  193. {
  194. //ButAlarmInStart->setEnabled( FALSE );
  195. //ButAlarmInStop->setEnabled( TRUE );
  196. }
  197. else
  198. {
  199. QMessageBox::about(this, tr("Promt"), tr("Trigger Alarm In Failed!"));
  200. }
  201. }
  202. }
  203. void Dialog::on_ButAlarmInStop_clicked()
  204. {
  205. if(0 != m_lLoginHandle)
  206. {
  207. ALARMCTRL_PARAM alarmParam = {0};
  208. alarmParam.dwSize = sizeof(ALARMCTRL_PARAM);
  209. alarmParam.nAction = 0;
  210. alarmParam.nAlarmNo = ui->ComboxChannelIn->currentIndex();
  211. BOOL bSuccess = CLIENT_ControlDevice(m_lLoginHandle, DH_TRIGGER_ALARM_IN, &alarmParam);
  212. if(bSuccess)
  213. {
  214. //ButAlarmInStart->setEnabled( TRUE );
  215. //ButAlarmInStop->setEnabled( FALSE );
  216. }
  217. else
  218. {
  219. QMessageBox::about(this, tr("Promt"), tr("Stop Trigger Alarm In Failed!"));
  220. }
  221. }
  222. }
  223. ///Reboot
  224. void Dialog::on_ButBoot_clicked()
  225. {
  226. if(0 != m_lLoginHandle)
  227. {
  228. BOOL bSuccess = CLIENT_ControlDevice(m_lLoginHandle, DH_CTRL_REBOOT, NULL);
  229. if(bSuccess)
  230. {
  231. QMessageBox::about(this, tr("Promt"), tr("Reboot Successful!"));
  232. }
  233. else
  234. {
  235. QMessageBox::about(this, tr("Promt"), tr("Reboot Failed!"));
  236. }
  237. }
  238. }
  239. ///Calibrate DVR Time
  240. void Dialog::on_ButGetTime_clicked()
  241. {
  242. if(0 != m_lLoginHandle)
  243. {
  244. NET_TIME curDateTime;
  245. DWORD dwRet = 0;
  246. BOOL bSuccess = CLIENT_GetDevConfig(m_lLoginHandle, DH_DEV_TIMECFG, -1, &curDateTime, sizeof(NET_TIME), &dwRet);
  247. if(bSuccess && (dwRet == sizeof(NET_TIME)))
  248. {
  249. QDate date;
  250. QTime time;
  251. ConvertTimeToStr(curDateTime, &date, &time);
  252. QDateTime curDateTime(date, time);
  253. ui->DVRdateTime->setDateTime(curDateTime);
  254. }
  255. else
  256. {
  257. QMessageBox::about(this, tr("Promt"), tr("Get DateTime Failed!"));
  258. }
  259. }
  260. }
  261. void Dialog::on_ButSetTime_clicked()
  262. {
  263. if(0 != m_lLoginHandle)
  264. {
  265. NET_TIME curDateTime;
  266. ConvertTime(ui->DVRdateTime->dateTime().date(), ui->DVRdateTime->dateTime().time(), &curDateTime);
  267. BOOL bSuccess = CLIENT_SetDevConfig(m_lLoginHandle, DH_DEV_TIMECFG, -1, &curDateTime, sizeof(NET_TIME), 1500);
  268. if(bSuccess)
  269. {
  270. QMessageBox::about(this, tr("Promt"), tr("Set DateTime Successful!"));
  271. }
  272. else
  273. {
  274. QMessageBox::about(this, tr("Promt"), tr("Set DateTime Failed!"));
  275. }
  276. }
  277. }
  278. /// Net Trigger Alarm Out
  279. void Dialog::on_ButAlarmOutStart_clicked()
  280. {
  281. if(0 != m_lLoginHandle)
  282. {
  283. ALARMCTRL_PARAM alarmParam = {0};
  284. alarmParam.dwSize = sizeof(ALARMCTRL_PARAM);
  285. alarmParam.nAction = 1;
  286. alarmParam.nAlarmNo = ui->ComboxChannelOut->currentIndex();
  287. BOOL bSuccess = CLIENT_ControlDevice(m_lLoginHandle, DH_TRIGGER_ALARM_OUT, &alarmParam);
  288. if(bSuccess)
  289. {
  290. //ButAlarmOutStart->setEnabled( FALSE );
  291. //ButAlarmOutStop->setEnabled( TRUE );
  292. }
  293. else
  294. {
  295. QMessageBox::about(this, tr("Promt"), tr("Trigger Alarm Out Failed!"));
  296. }
  297. }
  298. }
  299. void Dialog::on_ButAlarmOutStop_clicked()
  300. {
  301. if(0 != m_lLoginHandle)
  302. {
  303. ALARMCTRL_PARAM alarmParam = {0};
  304. alarmParam.dwSize = sizeof(ALARMCTRL_PARAM);
  305. alarmParam.nAction = 0;
  306. alarmParam.nAlarmNo = ui->ComboxChannelOut->currentIndex();
  307. BOOL bSuccess = CLIENT_ControlDevice(m_lLoginHandle, DH_TRIGGER_ALARM_OUT, &alarmParam);
  308. if(bSuccess)
  309. {
  310. //ButAlarmOutStart->setEnabled( TRUE );
  311. //ButAlarmOutStop->setEnabled( FALSE );
  312. }
  313. else
  314. {
  315. QMessageBox::about(this, tr("Promt"), tr("Stop Trigger Alarm Out Failed!"));
  316. }
  317. }
  318. }
  319. /// Disk Control
  320. void Dialog::on_ButDiskControl_clicked()
  321. {
  322. if(0 != m_lLoginHandle)
  323. {
  324. DISKCTRL_PARAM diskParam;
  325. diskParam.dwSize = sizeof(DISKCTRL_PARAM);
  326. diskParam.nIndex = ui->ComboxDiskNo->currentIndex();
  327. BOOL bSuccess = 0;
  328. if (diskParam.nIndex >= 0 && diskParam.nIndex < m_DiskInfo.dwDiskNum)
  329. {
  330. diskParam.ctrlType = ui->ComboxOperateType->currentIndex();
  331. memcpy(&diskParam.stuDisk, &m_DiskInfo.stDisks[diskParam.nIndex], sizeof(diskParam.stuDisk));
  332. if(m_nCurDiskType == 0)
  333. {
  334. bSuccess = CLIENT_ControlDevice(m_lLoginHandle, DH_CTRL_DISK, &diskParam, 10000);
  335. }
  336. else
  337. {
  338. bSuccess = CLIENT_ControlDevice(m_lLoginHandle, DH_CTRL_SDCARD, &diskParam, 10000);
  339. }
  340. if(bSuccess)
  341. {
  342. QMessageBox::about(this, tr("Promt"), tr("Operate Successfully!"));
  343. }
  344. else
  345. {
  346. QMessageBox::about(this, tr("Promt"), tr("Operate Failed!"));
  347. }
  348. }
  349. }
  350. }
  351. void Dialog::on_ComboxDiskNo_activated(int index)
  352. {
  353. QString strdata = QString::number((int)m_DiskInfo.stDisks[index].dwVolume, 10);
  354. QString strVolume = QString("%1 %2").arg(tr("Volume:")).arg(strdata);
  355. strdata = QString::number((int)m_DiskInfo.stDisks[index].dwFreeSpace, 10);
  356. QString strFreeSpace = QString("%1 %2").arg(tr("Free Space:")).arg(strdata);
  357. QString strStatus = "";
  358. switch((int)m_DiskInfo.stDisks[index].dwStatus&0xF)
  359. {
  360. case 0:
  361. strStatus = QString("%1 %2").arg(tr("Status:")).arg(tr("Sleep"));
  362. break;
  363. case 1:
  364. strStatus = QString("%1 %2").arg(tr("Status:")).arg(tr("Active"));
  365. break;
  366. case 2:
  367. strStatus = QString("%1 %2").arg(tr("Status:")).arg(tr("Error"));
  368. break;
  369. default:
  370. break;
  371. }
  372. ui->TextDiskInfo ->setText(QString("%1 %2 %3").arg(strVolume).arg(strFreeSpace).arg(strStatus));
  373. }
  374. /// keyboard
  375. void Dialog::on_ButNUM0_clicked()
  376. {
  377. OperateKeyboard(DH_KEYBOARD_BTN0);
  378. }
  379. void Dialog::on_ButNUM1_clicked()
  380. {
  381. OperateKeyboard(DH_KEYBOARD_BTN1);
  382. }
  383. void Dialog::on_ButPower_clicked()
  384. {
  385. OperateKeyboard(DH_KEYBOARD_POWER);
  386. }
  387. void Dialog::on_ButNUM7_clicked()
  388. {
  389. OperateKeyboard(DH_KEYBOARD_BTN7);
  390. }
  391. void Dialog::on_ButNUM2_clicked()
  392. {
  393. OperateKeyboard(DH_KEYBOARD_BTN2);
  394. }
  395. void Dialog::on_ButNUM3_clicked()
  396. {
  397. OperateKeyboard(DH_KEYBOARD_BTN3);
  398. }
  399. void Dialog::on_ButNUM4_clicked()
  400. {
  401. OperateKeyboard(DH_KEYBOARD_BTN4);
  402. }
  403. void Dialog::on_ButNUM5_clicked()
  404. {
  405. OperateKeyboard(DH_KEYBOARD_BTN5);
  406. }
  407. void Dialog::on_ButNUM6_clicked()
  408. {
  409. OperateKeyboard(DH_KEYBOARD_BTN6);
  410. }
  411. void Dialog::on_ButNUM8_clicked()
  412. {
  413. OperateKeyboard(DH_KEYBOARD_BTN8);
  414. }
  415. void Dialog::on_ButEsc_clicked()
  416. {
  417. OperateKeyboard(DH_KEYBOARD_ESC);
  418. }
  419. void Dialog::on_ButNUM9_clicked()
  420. {
  421. OperateKeyboard(DH_KEYBOARD_BTN9);
  422. }
  423. void Dialog::on_ButNUM10_clicked()
  424. {
  425. OperateKeyboard(DH_KEYBOARD_BTN10);
  426. }
  427. void Dialog::on_ButNUM11_clicked()
  428. {
  429. OperateKeyboard(DH_KEYBOARD_BTN11);
  430. }
  431. void Dialog::on_ButNUM12_clicked()
  432. {
  433. OperateKeyboard(DH_KEYBOARD_BTN12);
  434. }
  435. void Dialog::on_ButNUM13_clicked()
  436. {
  437. OperateKeyboard(DH_KEYBOARD_BTN13);
  438. }
  439. void Dialog::on_ButNUM14_clicked()
  440. {
  441. OperateKeyboard(DH_KEYBOARD_BTN14);
  442. }
  443. void Dialog::on_ButNUM15_clicked()
  444. {
  445. OperateKeyboard(DH_KEYBOARD_BTN15);
  446. }
  447. void Dialog::on_ButNUM16_clicked()
  448. {
  449. OperateKeyboard(DH_KEYBOARD_BTN16);
  450. }
  451. void Dialog::on_ButFn1_clicked()
  452. {
  453. OperateKeyboard(DH_KEYBOARD_FN1);
  454. }
  455. void Dialog::on_ButRec_clicked()
  456. {
  457. OperateKeyboard(DH_KEYBOARD_REC);
  458. }
  459. void Dialog::on_ButPrew_clicked()
  460. {
  461. OperateKeyboard(DH_KEYBOARD_PREW);
  462. }
  463. void Dialog::on_ButSlow_clicked()
  464. {
  465. OperateKeyboard(DH_KEYBOARD_SLOW);
  466. }
  467. void Dialog::on_ButPlay_clicked()
  468. {
  469. OperateKeyboard(DH_KEYBOARD_PLAY);
  470. }
  471. void Dialog::on_ButFast_clicked()
  472. {
  473. OperateKeyboard(DH_KEYBOARD_FAST);
  474. }
  475. void Dialog::on_ButNext_clicked()
  476. {
  477. OperateKeyboard(DH_KEYBOARD_NEXT);
  478. }
  479. void Dialog::on_ButStop_clicked()
  480. {
  481. OperateKeyboard(DH_KEYBOARD_STOP);
  482. }
  483. void Dialog::on_ButJmpUp_clicked()
  484. {
  485. OperateKeyboard(DH_KEYBOARD_JMPUP);
  486. }
  487. void Dialog::on_ButJmpDown_clicked()
  488. {
  489. OperateKeyboard(DH_KEYBOARD_JMPDOWN);
  490. }
  491. void Dialog::on_ButFn2_clicked()
  492. {
  493. OperateKeyboard(DH_KEYBOARD_FN2);
  494. }
  495. void Dialog::on_ButUP_clicked()
  496. {
  497. OperateKeyboard(DH_KEYBOARD_UP);
  498. }
  499. void Dialog::on_ButLeft_clicked()
  500. {
  501. OperateKeyboard(DH_KEYBOARD_LEFT);
  502. }
  503. void Dialog::on_ButEnter_clicked()
  504. {
  505. OperateKeyboard(DH_KEYBOARD_ENTER);
  506. }
  507. void Dialog::on_ButRight_clicked()
  508. {
  509. OperateKeyboard(DH_KEYBOARD_RIGHT);
  510. }
  511. void Dialog::on_ButDown_clicked()
  512. {
  513. OperateKeyboard(DH_KEYBOARD_DOWN);
  514. }
  515. void Dialog::on_ButNine_clicked()
  516. {
  517. OperateKeyboard(DH_KEYBOARD_NINE);
  518. }
  519. void Dialog::on_ButOne_clicked()
  520. {
  521. OperateKeyboard(DH_KEYBOARD_ONE);
  522. }
  523. void Dialog::on_ButSplit_clicked()
  524. {
  525. OperateKeyboard(DH_KEYBOARD_SPLIT);
  526. }
  527. void Dialog::on_ButInfo_clicked()
  528. {
  529. OperateKeyboard(DH_KEYBOARD_INFO);
  530. }
  531. void Dialog::on_ButAddr_clicked()
  532. {
  533. OperateKeyboard(DH_KEYBOARD_ADDR);
  534. }
  535. void Dialog::GetDiskInformation()
  536. {
  537. if( 0 != m_lLoginHandle)
  538. {
  539. DH_HARDDISK_STATE diskInfo = {0};
  540. DH_SDCARD_STATE sdInfo = {0};
  541. int nRetLen = 0;
  542. DWORD dwDiskNum = 0;
  543. BOOL bSuccess = CLIENT_QueryDevState(m_lLoginHandle, DH_DEVSTATE_DISK, (char *)&diskInfo, sizeof(DH_HARDDISK_STATE), &nRetLen);
  544. if(bSuccess && (nRetLen == sizeof(DH_HARDDISK_STATE)))
  545. {
  546. m_nCurDiskType = 0;
  547. }
  548. else
  549. {
  550. bSuccess = CLIENT_QueryDevState(m_lLoginHandle, DH_DEVSTATE_SD_CARD, (char*)&sdInfo, sizeof(DH_SDCARD_STATE), &nRetLen, 1000);
  551. if(bSuccess && (nRetLen == sizeof(DH_HARDDISK_STATE)))
  552. {
  553. m_nCurDiskType = 1;
  554. }
  555. else
  556. {
  557. m_nCurDiskType = 0;
  558. }
  559. }
  560. if(bSuccess)
  561. {
  562. if(m_nCurDiskType == 0)
  563. {
  564. dwDiskNum = diskInfo.dwDiskNum;
  565. }
  566. else
  567. {
  568. dwDiskNum = sdInfo.dwDiskNum;
  569. }
  570. ui->ComboxDiskNo->clear();
  571. DWORD dwDiskNum = diskInfo.dwDiskNum;
  572. for(int i=0; i<(int)dwDiskNum; i++)
  573. {
  574. QString str = QString::number(i+1, 10);
  575. int nCount = ui->ComboxDiskNo->count();
  576. ui->ComboxDiskNo->insertItem(nCount, str);
  577. }
  578. ui->ComboxDiskNo->setCurrentIndex(0);
  579. memcpy(&m_DiskInfo, &diskInfo, sizeof(DH_HARDDISK_STATE));
  580. on_ComboxDiskNo_activated(0);
  581. }
  582. else
  583. {
  584. QMessageBox::about(this, tr("Promt"), tr("Fail to get disk information!"));
  585. }
  586. }
  587. }
  588. void Dialog::ConvertTime( QDate date, QTime time, NET_TIME * nettime)
  589. {
  590. NET_TIME netTime = {0};
  591. netTime.dwYear = date.year();
  592. netTime.dwMonth = date.month();
  593. netTime.dwDay = date.day();
  594. netTime.dwHour = time.hour();
  595. netTime.dwMinute = time.minute();
  596. netTime.dwSecond =time.second();
  597. *nettime = netTime;
  598. }
  599. void Dialog::ConvertTimeToStr(NET_TIME nettime, QDate *date, QTime *time)
  600. {
  601. date->setYMD(nettime.dwYear, nettime.dwMonth, nettime.dwDay);
  602. time->setHMS(nettime.dwHour, nettime.dwMinute, nettime.dwSecond);
  603. }
  604. void Dialog::OperateKeyboard( CtrlType nType)
  605. {
  606. if(0 != m_lLoginHandle)
  607. {
  608. BOOL bSuccess = CLIENT_ControlDevice(m_lLoginHandle, nType, NULL);
  609. if(!bSuccess)
  610. {
  611. QMessageBox::about(this, tr("Promt"), tr("Operate Failed!"));
  612. }
  613. }
  614. }
  615. bool Dialog::eventFilter(QObject *obj, QEvent *event)//message filter
  616. {
  617. if(event->type() == QEvent::User)
  618. {
  619. QString strDevInfo;
  620. strDevInfo.append("Disconnect!");
  621. QMessageBox::information(0, "Promt", strDevInfo);
  622. }
  623. return QWidget::eventFilter(obj, event);//don't eat event
  624. }
  625. void Dialog::on_ButBoot_2_clicked()
  626. {
  627. int nVer = CLIENT_GetSDKVersion();
  628. QString strTmpVer = QString::number(nVer, 10);
  629. QString strVer = strTmpVer.left(1) + "." + strTmpVer.right(strTmpVer.length()-1).left(2) + "." + strTmpVer.right(strTmpVer.length()-3);
  630. QMessageBox::information(0, "Promt", strVer);
  631. }