mainwindow.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QByteArray>
  4. #include <iostream>
  5. using namespace std;
  6. #ifndef NEW
  7. #define NEW new(std::nothrow)
  8. #endif
  9. #ifdef WIN32
  10. #include <windows.h>
  11. typedef DWORD (WINAPI *LPTHREAD_START_ROUTINE)(LPVOID lpThreadParameter);
  12. #endif
  13. void * RoutineLoginThread(LPVOID lpPara);
  14. DEVICE_LIST g_DeviceList;
  15. DHMutex g_csDevice;
  16. bool g_bExit = false;
  17. void ConvertLoginError2String(int nErrorCode , QString &strErrorCode)
  18. {
  19. switch(nErrorCode)
  20. {
  21. case 0:
  22. strErrorCode = "Login Success";
  23. break;
  24. case 1:
  25. strErrorCode = "Account or Password Incorrect";
  26. break;
  27. case 2:
  28. strErrorCode = "User Is Not Exist";
  29. break;
  30. case 3:
  31. strErrorCode = "Login Timeout";
  32. break;
  33. case 4:
  34. strErrorCode = "Repeat Login";
  35. break;
  36. case 5:
  37. strErrorCode = "User Account is Locked";
  38. break;
  39. case 6:
  40. strErrorCode = "User In Blocklist";
  41. break;
  42. case 7:
  43. strErrorCode = "Device Busy";
  44. break;
  45. case 8:
  46. strErrorCode = "Sub Connect Failed";
  47. break;
  48. case 9:
  49. strErrorCode = "Host Connect Failed";
  50. break;
  51. case 10 :
  52. strErrorCode = "Max Connect";
  53. break;
  54. case 11:
  55. strErrorCode = "Support Protocol3 Only";
  56. break;
  57. case 12:
  58. strErrorCode = "UKey Info Error";
  59. break;
  60. case 13:
  61. strErrorCode = "No Authorized";
  62. break;
  63. case 18:
  64. strErrorCode = "Device Account isn't Initialized";
  65. break;
  66. default:
  67. strErrorCode = "Unknown Error";
  68. break;
  69. }
  70. }
  71. void InitDeviceInfo(DH_Device_Info &stDeviceInfo)
  72. {
  73. stDeviceInfo.lLoginHandle = 0UL;
  74. stDeviceInfo.nChannelCount = 0;
  75. stDeviceInfo.bOnline = FALSE;
  76. stDeviceInfo.strErrorCode = "";
  77. stDeviceInfo.nPort = 0;
  78. stDeviceInfo.nBelongThread = 0;
  79. stDeviceInfo.nIndex = 0;
  80. stDeviceInfo.nTimeCount = 0L;
  81. memset(&stDeviceInfo.szDevIp , 0 , sizeof(stDeviceInfo.szDevIp));
  82. memset(&stDeviceInfo.szUserName , 0 , sizeof(stDeviceInfo.szUserName));
  83. memset(&stDeviceInfo.szPassWord , 0 , sizeof(stDeviceInfo.szPassWord));
  84. memset(&stDeviceInfo.channel , 0 , sizeof(stDeviceInfo.channel));
  85. }
  86. void CALLBACK RealDataCallBackEx(LLONG lRealHandle, DWORD dwDataType, BYTE *pBuffer, DWORD dwBufSize, LLONG param, LDWORD dwUser)
  87. {
  88. DH_Channel_Info* pChannelInfo = (DH_Channel_Info*)dwUser;
  89. if(NULL == pChannelInfo)
  90. {
  91. return;
  92. }
  93. pChannelInfo->dwStatistic = dwBufSize;
  94. }
  95. void CALLBACK DisConnectFunc(LLONG lLoginID, char *pchDVRIP, LONG nDVRPort, LDWORD dwUser)
  96. {
  97. MainWindow * pThis = (MainWindow *)dwUser;
  98. if(NULL == pThis)
  99. {
  100. return;
  101. }
  102. g_csDevice.Lock();
  103. DEVICE_LIST::iterator it = g_DeviceList.begin();
  104. while (it != g_DeviceList.end())
  105. {
  106. DH_Device_Info *pDeviceInfo = (*it);
  107. if (pDeviceInfo != NULL)
  108. {
  109. if (pDeviceInfo->lLoginHandle == lLoginID)
  110. {
  111. pDeviceInfo->bOnline = FALSE;
  112. pDeviceInfo->strErrorCode = "Device Disconnected";
  113. int nMinCount = pDeviceInfo->nChannelCount > 16?16:pDeviceInfo->nChannelCount;
  114. for(int i = 0; i < nMinCount; i++)
  115. {
  116. pDeviceInfo->channel[i].dwStatistic = 0;
  117. }
  118. break;
  119. }
  120. }
  121. it++;
  122. }
  123. g_csDevice.UnLock();
  124. return;
  125. }
  126. /**************************************************************************************
  127. * Funcname: HaveReConnectFunc
  128. * Purpose:断线重连函数,CLIENT_SetAutoReconnect函数调用
  129. * OutputParam: LLONG :lLoginID // 登录ID
  130. * OutputParam: char* :pchDVRIP // 登陆设备IP
  131. * OutputParam: LONG :nDVRPort // 登陆设备端口
  132. * OutputParam: LDWORD :dwUser // 用户自定义字段
  133. * Return: void
  134. * Created: %2016%:%05%:%16%
  135. * Revision Record: date:author:modify sth
  136. **************************************************************************************/
  137. void CALLBACK HaveReConnectFunc(LLONG lLoginID, char *pchDVRIP, LONG nDVRPort, LDWORD dwUser)
  138. {
  139. if( pchDVRIP == NULL)
  140. return ;
  141. g_csDevice.Lock();
  142. NET_DEVICEINFO deviceInfo = {0};
  143. DEVICE_LIST::iterator it = g_DeviceList.begin();
  144. while (it != g_DeviceList.end())
  145. {
  146. DH_Device_Info *pDeviceInfo = (*it);
  147. if (pDeviceInfo == NULL)
  148. {
  149. it++;
  150. continue;
  151. }
  152. if (lLoginID == pDeviceInfo->lLoginHandle)
  153. {
  154. pDeviceInfo->bOnline = TRUE;
  155. pDeviceInfo->strErrorCode = "Login Success";
  156. break;
  157. }
  158. it++;
  159. }
  160. g_csDevice.UnLock();
  161. return;
  162. }
  163. void * RoutineLoginThread(LPVOID lpPara)
  164. {
  165. // return 0;
  166. long nThreadID = (long)lpPara;
  167. if(nThreadID < 0)
  168. {
  169. return 0;
  170. }
  171. g_csDevice.Lock();
  172. DEVICE_LIST::iterator it = g_DeviceList.begin();
  173. while (it != g_DeviceList.end())
  174. {
  175. if(g_bExit == true)
  176. {
  177. break;
  178. }
  179. DH_Device_Info *pDeviceInfo = (*it);
  180. if (pDeviceInfo == NULL)
  181. {
  182. it++;
  183. continue;
  184. }
  185. if (pDeviceInfo->nBelongThread == nThreadID)
  186. {
  187. NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY stInparam;
  188. memset(&stInparam, 0, sizeof(stInparam));
  189. stInparam.dwSize = sizeof(stInparam);
  190. strncpy(stInparam.szIP, pDeviceInfo->szDevIp, sizeof(stInparam.szIP) - 1);
  191. strncpy(stInparam.szPassword, pDeviceInfo->szPassWord, sizeof(stInparam.szPassword) - 1);
  192. strncpy(stInparam.szUserName, pDeviceInfo->szUserName, sizeof(stInparam.szUserName) - 1);
  193. stInparam.nPort = pDeviceInfo->nPort;
  194. stInparam.emSpecCap = EM_LOGIN_SPEC_CAP_TCP;
  195. NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY stOutparam;
  196. memset(&stOutparam, 0, sizeof(stOutparam));
  197. stOutparam.dwSize = sizeof(stOutparam);
  198. pDeviceInfo->lLoginHandle = CLIENT_LoginWithHighLevelSecurity(&stInparam, &stOutparam);
  199. ConvertLoginError2String(stOutparam.nError , pDeviceInfo->strErrorCode);
  200. if (pDeviceInfo->lLoginHandle == 0)
  201. {
  202. if(stOutparam.nError != 255)
  203. {
  204. printf("Login failed! error = %d", stOutparam.nError);
  205. }
  206. else
  207. {
  208. stOutparam.nError = CLIENT_GetLastError();
  209. if(stOutparam.nError ==NET_ERROR_MAC_VALIDATE_FAILED )
  210. {
  211. printf("Login failed! bad mac address");
  212. }
  213. else if(stOutparam.nError ==NET_ERROR_SENIOR_VALIDATE_FAILED)
  214. {
  215. printf("Login failed! senior validate failed");
  216. }
  217. }
  218. pDeviceInfo->bOnline = FALSE;
  219. it++;
  220. continue;
  221. }
  222. else
  223. {
  224. int nRetLen = 0;
  225. NET_DEV_CHN_COUNT_INFO stuChn = {sizeof(NET_DEV_CHN_COUNT_INFO)};
  226. stuChn.stuVideoIn.dwSize = sizeof(stuChn.stuVideoIn);
  227. stuChn.stuVideoOut.dwSize = sizeof(stuChn.stuVideoOut);
  228. if(CLIENT_QueryDevState(pDeviceInfo->lLoginHandle, DH_DEVSTATE_DEV_CHN_COUNT, (char*)&stuChn, stuChn.dwSize, &nRetLen))
  229. {
  230. pDeviceInfo->nChannelCount = stuChn.stuVideoIn.nMaxTotal;
  231. }
  232. else
  233. {
  234. pDeviceInfo->nChannelCount = stOutparam.stuDeviceInfo.nChanNum;
  235. }
  236. }
  237. pDeviceInfo->bOnline = TRUE;
  238. // pDeviceInfo->nChannelCount = deviceInfo.nChanNum;
  239. int nLoopCount = pDeviceInfo->nChannelCount;
  240. if(nLoopCount > 16)
  241. {
  242. nLoopCount = 16;
  243. }
  244. for (int i = 0; i < nLoopCount; i++)
  245. {
  246. pDeviceInfo->channel[i].lRealPlayHandle = CLIENT_RealPlay(pDeviceInfo->lLoginHandle,i, NULL);
  247. if (pDeviceInfo->channel[i].lRealPlayHandle != 0)
  248. {
  249. CLIENT_SetRealDataCallBackEx2(pDeviceInfo->channel[i].lRealPlayHandle, RealDataCallBackEx, (LDWORD)&(pDeviceInfo->channel[i]), 0x0f);
  250. }
  251. else
  252. {
  253. printf("loginid = %ld;real play failed!\n", pDeviceInfo->lLoginHandle);
  254. }
  255. }
  256. }
  257. it++;
  258. }
  259. g_csDevice.UnLock();
  260. return 0;
  261. }
  262. void MainWindow::addRowData(QAbstractItemModel *model, QStringList rowDataList)
  263. {
  264. int row = model->rowCount();
  265. model->insertRow(row);
  266. int nCount = rowDataList.size ();
  267. int nIndex = 0;
  268. for( nIndex= 0; nIndex < nCount; nIndex++)
  269. {
  270. QString string = static_cast<QString>(rowDataList.at (nIndex));
  271. model->setData(model->index(row, nIndex), string);
  272. }
  273. }
  274. QStandardItemModel *MainWindow::createListModel()
  275. {
  276. QStandardItemModel *model = NEW QStandardItemModel(0, 21, this);
  277. if (model == NULL)
  278. {
  279. return NULL;
  280. }
  281. model->setHeaderData(0, Qt::Horizontal, QObject::tr("NO"));
  282. model->setHeaderData(1, Qt::Horizontal, QObject::tr("IP"));
  283. model->setHeaderData(2, Qt::Horizontal, QObject::tr("On Line"));
  284. model->setHeaderData(3 ,Qt::Horizontal, QObject::tr("Device Status"));
  285. model->setHeaderData(4, Qt::Horizontal, QObject::tr("Channel count"));
  286. model->setHeaderData(5, Qt::Horizontal, QObject::tr("1"));
  287. model->setHeaderData(6, Qt::Horizontal, QObject::tr("2"));
  288. model->setHeaderData(7, Qt::Horizontal, QObject::tr("3"));
  289. model->setHeaderData(8, Qt::Horizontal, QObject::tr("4"));
  290. model->setHeaderData(9, Qt::Horizontal, QObject::tr("5"));
  291. model->setHeaderData(10, Qt::Horizontal, QObject::tr("6"));
  292. model->setHeaderData(11, Qt::Horizontal, QObject::tr("7"));
  293. model->setHeaderData(12, Qt::Horizontal, QObject::tr("8"));
  294. model->setHeaderData(13, Qt::Horizontal, QObject::tr("9"));
  295. model->setHeaderData(14, Qt::Horizontal, QObject::tr("10"));
  296. model->setHeaderData(15, Qt::Horizontal, QObject::tr("11"));
  297. model->setHeaderData(16, Qt::Horizontal, QObject::tr("12"));
  298. model->setHeaderData(17, Qt::Horizontal, QObject::tr("13"));
  299. model->setHeaderData(18, Qt::Horizontal, QObject::tr("14"));
  300. model->setHeaderData(19, Qt::Horizontal, QObject::tr("15"));
  301. model->setHeaderData(20, Qt::Horizontal, QObject::tr("16"));
  302. return model;
  303. }
  304. MainWindow::MainWindow(QWidget *parent) :
  305. QMainWindow(parent),
  306. ui(NEW Ui::MainWindow)
  307. {
  308. ui->setupUi(this);
  309. //创建ListView
  310. standardItemModel = createListModel();
  311. ui->listView1->setModel(standardItemModel);
  312. ui->listView1->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
  313. ui->listView1->setEditTriggers(QAbstractItemView::EditKeyPressed/*NoEditTriggers*/);
  314. ui->listView1->setColumnWidth (0,60);
  315. ui->listView1->verticalHeader()->setVisible(false);
  316. ui->listView1->verticalHeader()->setDefaultSectionSize(20);
  317. ui->listView1->horizontalHeader()->setStretchLastSection(true);
  318. ui->listView1->setSelectionBehavior(QAbstractItemView::SelectRows);
  319. ui->listView1->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
  320. // 数据初始化
  321. InitData();
  322. }
  323. MainWindow::~MainWindow()
  324. {
  325. UnInitData();
  326. delete ui;
  327. }
  328. bool MainWindow::InitData()
  329. {
  330. CLIENT_Init(DisConnectFunc, (LDWORD)this);
  331. LOG_SET_PRINT_INFO stLogPrintInfo = {sizeof(stLogPrintInfo)};
  332. CLIENT_LogOpen(&stLogPrintInfo);
  333. CLIENT_SetAutoReconnect(HaveReConnectFunc, 0);
  334. installEventFilter(this);//install filter
  335. m_lLoginHandle = 0;
  336. ui->pushButStopALL->setEnabled(false);
  337. m_counter = NULL;
  338. m_counter = NEW QTimer( this );
  339. g_DeviceList.clear();
  340. if(m_counter == NULL)
  341. {
  342. return false;
  343. }
  344. connect(m_counter, SIGNAL(timeout()), this, SLOT(UpdataListview()));
  345. return true;
  346. }
  347. bool MainWindow::UnInitData()
  348. {
  349. CLIENT_Cleanup();
  350. if(m_counter)
  351. delete m_counter;
  352. if(standardItemModel)
  353. delete standardItemModel;
  354. return true;
  355. }
  356. void MainWindow::UpdataListview()
  357. {
  358. QList<QStandardItem *> itemsfind;
  359. QStandardItem * item = NULL;
  360. QString name = "";
  361. QString strdata = "";
  362. g_csDevice.Lock();
  363. DEVICE_LIST::iterator it = g_DeviceList.begin();
  364. while (it != g_DeviceList.end())
  365. {
  366. DH_Device_Info *pDeviceInfo = (*it);
  367. if (pDeviceInfo == NULL)
  368. {
  369. it++;
  370. continue;
  371. }
  372. name = QString::number(pDeviceInfo->nIndex, 10);
  373. itemsfind = standardItemModel->findItems(name);
  374. if (itemsfind.size () == 0)
  375. {
  376. QStringList strList;
  377. strdata = QString::number(pDeviceInfo->nIndex, 10);
  378. strList.append(strdata);
  379. strdata = pDeviceInfo->szDevIp;
  380. strList.append(strdata);
  381. strdata = QString::number(pDeviceInfo->bOnline , 10);
  382. strList.append(strdata);
  383. strList.append(pDeviceInfo->strErrorCode);
  384. strdata = QString::number(pDeviceInfo->nChannelCount , 10);
  385. strList.append(strdata);
  386. addRowData(standardItemModel, strList);
  387. }
  388. else
  389. {
  390. int nIndex = 0;
  391. for(nIndex = 0; nIndex < itemsfind.size (); nIndex++)
  392. {
  393. item = static_cast<QStandardItem *>(itemsfind.at(nIndex));
  394. QModelIndex curIndex = standardItemModel->indexFromItem(item);
  395. int rowIndex = curIndex.row ();
  396. int colIndex = curIndex.column ();
  397. colIndex++; //IP不变
  398. strdata = QString::number(pDeviceInfo->bOnline , 10) ;
  399. colIndex++;
  400. standardItemModel->setData(standardItemModel->index(rowIndex, colIndex), strdata);
  401. colIndex++;
  402. standardItemModel->setData(standardItemModel->index(rowIndex, colIndex), pDeviceInfo->strErrorCode);
  403. colIndex++;
  404. strdata = QString::number(pDeviceInfo->nChannelCount , 10);
  405. standardItemModel->setData(standardItemModel->index(rowIndex, colIndex), strdata);
  406. pDeviceInfo->nTimeCount += 1;
  407. int nMinCount = pDeviceInfo->nChannelCount > 16 ? 16:pDeviceInfo->nChannelCount;
  408. for(int i = 0; i < nMinCount; i++)
  409. {
  410. strdata = tr("0");
  411. if(pDeviceInfo->bOnline > 0)//online
  412. {
  413. strdata = QString::number(pDeviceInfo->channel[i].dwStatistic, 10);
  414. }
  415. colIndex++;
  416. standardItemModel->setData(standardItemModel->index(rowIndex, colIndex), strdata);
  417. }
  418. }
  419. }
  420. it++;
  421. }
  422. g_csDevice.UnLock();
  423. }
  424. int MainWindow::LoadConfig(int * nThreadNum)
  425. {
  426. char szSection[128] = {0};
  427. char ip[64] = {0};
  428. char port[8]= {0};
  429. char username[16] = {0};
  430. char password[16] = {0};
  431. char connect_num[8] = {0};
  432. char thread_num[8] ={0};
  433. QFileDialog * fDialog = NEW QFileDialog(this);
  434. if(fDialog == NULL)
  435. {
  436. return 0;
  437. }
  438. g_csDevice.Lock();
  439. DEVICE_LIST::iterator it = g_DeviceList.begin();
  440. while (it != g_DeviceList.end())
  441. {
  442. DH_Device_Info *pDeviceInfo = (*it);
  443. if (pDeviceInfo != NULL)
  444. {
  445. delete pDeviceInfo;
  446. pDeviceInfo = NULL;
  447. }
  448. it++;
  449. }
  450. g_DeviceList.clear();
  451. g_csDevice.UnLock ();
  452. m_FileName = fDialog->getOpenFileName(this,
  453. "open file dialog",
  454. "./",
  455. "config (*.ini *.txt )");
  456. if(fDialog)
  457. {
  458. delete fDialog;
  459. }
  460. if(m_FileName.isNull() == TRUE)
  461. {
  462. return 0;
  463. }
  464. QByteArray byt = m_FileName.toUtf8();
  465. char *p = byt.data();
  466. CProfile::GetPrivateProfileString("thread", "threadnum", "", thread_num, 8, p);
  467. *nThreadNum = atoi(thread_num);
  468. int nIndexCount = 0;
  469. for(int i = 0; i < *nThreadNum; i++)
  470. {
  471. for(int j = 0; ; j++)
  472. {
  473. sprintf(szSection, "thread%d.device%d", i, j);
  474. QByteArray byt = m_FileName.toUtf8();
  475. char *p = byt.data();
  476. int nSize = CProfile::GetPrivateProfileString(szSection, "IP", "", ip, 64, p);
  477. if(strcmp(ip, "") == 0)
  478. {
  479. break;
  480. }
  481. nSize = CProfile::GetPrivateProfileString(szSection, "Port", "", port, 8, p);
  482. nSize = CProfile::GetPrivateProfileString(szSection, "Username", "", username, 16, p);
  483. nSize = CProfile::GetPrivateProfileString(szSection, "Password", "", password, 16, p);
  484. nSize = CProfile::GetPrivateProfileString(szSection, "ConnectNum", "", connect_num, 8, p);
  485. int nConnectCount = atoi(connect_num);
  486. for(int k = 0; k < nConnectCount; k++)
  487. {
  488. DH_Device_Info* device_info = NEW DH_Device_Info;
  489. if(NULL == device_info)
  490. {
  491. continue;
  492. }
  493. InitDeviceInfo(*device_info);
  494. strncpy(device_info->szDevIp, ip, sizeof(device_info->szDevIp)-1);
  495. device_info->nPort = atoi(port);
  496. strncpy(device_info->szUserName, username, sizeof(device_info->szUserName)-1);
  497. strncpy(device_info->szPassWord, password, sizeof(device_info->szPassWord)-1);
  498. device_info->nBelongThread = i;
  499. device_info->nIndex = nIndexCount;
  500. device_info->nTimeCount = 0;
  501. g_csDevice.Lock();
  502. g_DeviceList.push_back(device_info);
  503. g_csDevice.UnLock ();
  504. nIndexCount++;
  505. }
  506. }
  507. }
  508. return 1;
  509. }
  510. void MainWindow::Logindev(int nThreadNum)
  511. {
  512. if(nThreadNum < 0)
  513. {
  514. return;
  515. }
  516. for(int i = 0; i< nThreadNum; i++)
  517. {
  518. int ret = pthread_create(&m_thread, 0, RoutineLoginThread, (void*)i);
  519. if (ret != 0)
  520. {
  521. m_thread = 0;
  522. }
  523. }
  524. }
  525. void MainWindow::on_pushButLoad_clicked()
  526. {
  527. standardItemModel->removeRows(0, standardItemModel->rowCount ());//all item delete
  528. int nThreadNum = 0;
  529. int nRet = LoadConfig(&nThreadNum);
  530. if(1 == nRet)
  531. {
  532. Logindev(nThreadNum);
  533. m_counter ->start(1000);
  534. ui->pushButLoad->setEnabled(false);
  535. ui->pushButStopALL->setEnabled(true);
  536. }
  537. }
  538. void MainWindow::on_pushButPlay_clicked()
  539. {
  540. QModelIndex curIndex = ui->listView1->currentIndex ();
  541. int nRow = curIndex.row ();
  542. QModelIndex rowNOIndex = standardItemModel->index (nRow, 0);
  543. QString strItemData = standardItemModel->data (rowNOIndex).toString ();
  544. bool numok = false;
  545. int nItem = strItemData.toLong(&numok);
  546. if(numok)
  547. {
  548. g_csDevice.Lock();
  549. DEVICE_LIST::iterator it;
  550. for(it = g_DeviceList.begin(); it != g_DeviceList.end(); it++)
  551. {
  552. DH_Device_Info* pDeviceInfo = *it;
  553. if(pDeviceInfo->nIndex == nItem && pDeviceInfo->lLoginHandle != 0 && pDeviceInfo->bOnline)
  554. {
  555. int nLoopCount = pDeviceInfo->nChannelCount>16?16:pDeviceInfo->nChannelCount;
  556. for(int i = 0; i < nLoopCount; i++)
  557. {
  558. if(pDeviceInfo->channel[i].lRealPlayHandle == 0)
  559. {
  560. pDeviceInfo->channel[i].lRealPlayHandle = CLIENT_RealPlay(pDeviceInfo->lLoginHandle,i, NULL);
  561. if (pDeviceInfo->channel[i].lRealPlayHandle != 0)
  562. {
  563. CLIENT_SetRealDataCallBackEx2(pDeviceInfo->channel[i].lRealPlayHandle, RealDataCallBackEx, (LDWORD)&(pDeviceInfo->channel[i]), 0x0f);
  564. pDeviceInfo->nTimeCount = 0;
  565. }
  566. }
  567. }
  568. }
  569. }
  570. g_csDevice.UnLock();
  571. }
  572. }
  573. void MainWindow::on_pushButStopALL_clicked()
  574. {
  575. //kill the timer
  576. m_counter->stop();
  577. g_bExit = true;
  578. g_csDevice.Lock();
  579. DEVICE_LIST::iterator it;
  580. for(it = g_DeviceList.begin(); it != g_DeviceList.end(); it++)
  581. {
  582. DH_Device_Info* pDeviceInfo = *it;
  583. if(pDeviceInfo->lLoginHandle != 0)
  584. {
  585. int nCount = pDeviceInfo->nChannelCount;
  586. if(nCount > 16)
  587. {
  588. nCount = 16;
  589. }
  590. for(int i = 0; i < nCount; i++)
  591. {
  592. CLIENT_StopRealPlay(pDeviceInfo->channel[i].lRealPlayHandle);
  593. }
  594. CLIENT_Logout(pDeviceInfo->lLoginHandle);
  595. }
  596. delete pDeviceInfo;
  597. pDeviceInfo = NULL;
  598. }
  599. g_DeviceList.clear();
  600. g_csDevice.UnLock();
  601. int nRows = standardItemModel->rowCount ();
  602. standardItemModel->removeRows (0,nRows);
  603. g_bExit = false;
  604. ui->pushButLoad->setEnabled(true);
  605. }
  606. void MainWindow::on_pushButStop_clicked()
  607. {
  608. QModelIndex curIndex = ui->listView1->currentIndex ();
  609. int nRow = curIndex.row ();
  610. QModelIndex rowNOIndex = standardItemModel->index (nRow, 0);
  611. QString strItemData = standardItemModel->data (rowNOIndex).toString ();
  612. bool numok = false;
  613. int nItem = strItemData.toLong(&numok);
  614. if(numok)
  615. {
  616. g_csDevice.Lock();
  617. DEVICE_LIST::iterator it;
  618. for(it = g_DeviceList.begin(); it != g_DeviceList.end(); it++)
  619. {
  620. DH_Device_Info* pDeviceInfo = *it;
  621. if(pDeviceInfo->nIndex == nItem && pDeviceInfo->lLoginHandle != 0)
  622. {
  623. int nCount = pDeviceInfo->nChannelCount;
  624. if(nCount > 16)
  625. {
  626. nCount = 16;
  627. }
  628. for(int i = 0; i < nCount; i++)
  629. {
  630. if(pDeviceInfo->channel[i].lRealPlayHandle != 0)
  631. {
  632. CLIENT_StopRealPlay(pDeviceInfo->channel[i].lRealPlayHandle);
  633. pDeviceInfo->channel[i].lRealPlayHandle = 0;
  634. pDeviceInfo->channel[i].dwStatistic = 0;
  635. }
  636. pDeviceInfo->nTimeCount = 0;
  637. }
  638. // CLIENT_Logout(pDeviceInfo->lLoginHandle);
  639. }
  640. }
  641. g_csDevice.UnLock();
  642. }
  643. }