DevInitDlg.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. #include <stdio.h>
  2. #include "DevInitDlg.h"
  3. #include "ui_DevInitDlg.h"
  4. #include "InitializeDevDlg.h"
  5. #include "GetIPDlg.h"
  6. #include <QMessageBox>
  7. #include <QStandardItemModel>
  8. #include <QKeyEvent>
  9. #include "dhnetsdk.h"
  10. #include "NetCardInfo.h"
  11. //defines NEW operator to prevent an exception from bing throw when new fails ,causing the return value to be invalid
  12. #pragma warning(disable:4996)
  13. #define BUFFER_SIZE 16
  14. CDevInitDlg::CDevInitDlg(QWidget *parent) :
  15. QDialog(parent),
  16. ui(NEW Ui::CDevInitDlg)
  17. {
  18. ui->setupUi(this);
  19. m_Model = NEW QStandardItemModel();
  20. connect(this,SIGNAL(SearchDevices(DEVICE_NET_INFO_EX2*)), this, SLOT(OnSearchDevices(DEVICE_NET_INFO_EX2*)), Qt::QueuedConnection);
  21. connect(this,SIGNAL(SearchDevicesByIP(const QString&, const QString&)), this, SLOT(OnSearchDevicesByIP(const QString&, const QString&)), Qt::QueuedConnection);
  22. m_pNetCardInfo = new CNetCardInfo;
  23. //初始化
  24. Init();
  25. m_DevNetInfo.reserve(MAX_DEV_INFO_COUNT);
  26. m_nDeviceCount = 0;
  27. m_lpSearch = 0;
  28. m_dwStartIP = 0;
  29. m_dwEndIP = 0;
  30. m_nSelected = 0;
  31. m_strPwdResetWay = "";
  32. }
  33. CDevInitDlg::~CDevInitDlg()
  34. {
  35. //结束搜索
  36. StopSearchDevice();
  37. CLIENT_Cleanup();
  38. //释放内存
  39. for(std::vector<DEVICE_NET_INFO_EX2*>::iterator it = m_DevNetInfo.begin(); it != m_DevNetInfo.end(); it++)
  40. {
  41. if(NULL != *it)
  42. {
  43. delete *it;
  44. *it = NULL;
  45. }
  46. }
  47. m_DevNetInfo.clear();
  48. delete m_Model;
  49. delete ui;
  50. }
  51. void CDevInitDlg::Init()
  52. {
  53. InitListView(); //初始化设备搜索List列表
  54. InitNetSDK(); //初始化SDK
  55. m_pNetCardInfo->Init();//初始化多网卡搜索
  56. }
  57. void CDevInitDlg::InitListView()
  58. {
  59. //设置表头
  60. //m_Model->setHorizontalHeaderItem(0, new QStandardItem(QObject::tr("No.")));
  61. m_Model->setHorizontalHeaderItem(LISTCOLUMN_STATUS, NEW QStandardItem(QObject::tr("Status")));
  62. m_Model->setHorizontalHeaderItem(LISTCOLUMN_IPVERSION, NEW QStandardItem(QObject::tr("IPVersion")));
  63. m_Model->setHorizontalHeaderItem(LISTCOLUMN_IPADDRESS, NEW QStandardItem(QObject::tr("IP Address")));
  64. m_Model->setHorizontalHeaderItem(LISTCOLUMN_PORT, NEW QStandardItem(QObject::tr("Port")));
  65. m_Model->setHorizontalHeaderItem(LISTCOLUMN_SUBNETMASK, NEW QStandardItem(QObject::tr("Subnet Mask")));
  66. m_Model->setHorizontalHeaderItem(LISTCOLUMN_GATEWAY, NEW QStandardItem(QObject::tr("Gateway")));
  67. m_Model->setHorizontalHeaderItem(LISTCOLUMN_MACADDRESS, NEW QStandardItem(QObject::tr("Mac Address")));
  68. m_Model->setHorizontalHeaderItem(LISTCOLUMN_DEVTYPE, NEW QStandardItem(QObject::tr("Dev Type")));
  69. m_Model->setHorizontalHeaderItem(LISTCOLUMN_DETAILTYPE, NEW QStandardItem(QObject::tr("DetailType")));
  70. m_Model->setHorizontalHeaderItem(LISTCOLUMN_HTTP, NEW QStandardItem(QObject::tr("Http")));
  71. ui->tableView->setModel(m_Model);
  72. //设置表头宽度
  73. //ui->tableView->setColumnWidth(0, 40);
  74. ui->tableView->setColumnWidth(LISTCOLUMN_STATUS, 80);
  75. ui->tableView->setColumnWidth(LISTCOLUMN_IPVERSION, 80);
  76. ui->tableView->setColumnWidth(LISTCOLUMN_IPADDRESS, 150);
  77. ui->tableView->setColumnWidth(LISTCOLUMN_PORT, 50);
  78. ui->tableView->setColumnWidth(LISTCOLUMN_SUBNETMASK, 110);
  79. ui->tableView->setColumnWidth(LISTCOLUMN_GATEWAY, 100);
  80. ui->tableView->setColumnWidth(LISTCOLUMN_MACADDRESS, 120);
  81. ui->tableView->setColumnWidth(LISTCOLUMN_DEVTYPE, 70);
  82. ui->tableView->setColumnWidth(LISTCOLUMN_DETAILTYPE, 70);
  83. ui->tableView->setColumnWidth(LISTCOLUMN_HTTP, 50);
  84. ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
  85. ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
  86. ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
  87. }
  88. void CDevInitDlg::InitNetSDK()
  89. {
  90. BOOL bRet = CLIENT_Init(NULL, NULL);
  91. if (!bRet)
  92. {
  93. QMessageBox::about(NULL,tr("Prompt"),tr("Initialize SDK Failed with Error"));
  94. }
  95. else
  96. {
  97. LOG_SET_PRINT_INFO stLogPrintInfo = {sizeof(stLogPrintInfo)};
  98. CLIENT_LogOpen(&stLogPrintInfo);
  99. CLIENT_SetAutoReconnect(NULL, NULL);
  100. }
  101. /*****************************Linux Log
  102. LOG_SET_PRINT_INFO logPrintInfo = {0};
  103. logPrintInfo.dwSize = sizeof(LOG_SET_PRINT_INFO);
  104. logPrintInfo.bSetFilePath = TRUE;
  105. strncpy(logPrintInfo.szLogFilePath, "/home/wu_fengping/DevInit/sdk_log/log.log", sizeof(logPrintInfo.szLogFilePath));
  106. bRet = CLIENT_LogOpen(&logPrintInfo);
  107. if (!bRet)
  108. {
  109. printf("CLIENT_LogOpen failed!\r\n");
  110. }
  111. else
  112. {
  113. printf("CLIENT_LogOpen %s success\r\n", logPrintInfo.szLogFilePath);
  114. }
  115. ***********************************/
  116. }
  117. void CDevInitDlg::on_InitializeDevice_Button_clicked()
  118. {
  119. m_nSelected = ui->tableView->currentIndex().row();//获取当前选中行
  120. if( -1 == m_nSelected)
  121. {
  122. QMessageBox::about(NULL,tr("Prompt"),tr("Please select device to initialize"));
  123. return;
  124. }
  125. BOOL bRet=GetInitStatus(m_DevNetInfo[m_nSelected]->stuDevInfo.byInitStatus);
  126. if(bRet)
  127. {
  128. QMessageBox::about(NULL,tr("Prompt"),tr("Please select uninitialized device"));
  129. return;
  130. }
  131. GetPwdRestWay(m_DevNetInfo[m_nSelected]->stuDevInfo.byPwdResetWay);//获取重置方式
  132. CInitializeDevDlg dlg; //初始化界面
  133. dlg.setWindowFlags(dlg.windowFlags()&~Qt::WindowContextHelpButtonHint);//隐藏帮助按钮
  134. dlg.SetRetWay(m_strPwdResetWay);
  135. int nRet = dlg.exec();
  136. if(nRet != QDialog::Accepted)
  137. {
  138. return;
  139. }
  140. QDialog::repaint();//界面刷新,去除阻塞窗口的阴影
  141. QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);//处理未完成的事件
  142. QString strUserName = dlg.GetUser();
  143. QString strPwd = dlg.GetPwd();
  144. QString strResetWay = dlg.GetPwdRestWay();
  145. NET_IN_INIT_DEVICE_ACCOUNT sInitAccountIn = {0};
  146. NET_OUT_INIT_DEVICE_ACCOUNT sInitAccountOut = {0};
  147. sInitAccountIn.dwSize = sizeof(sInitAccountIn);
  148. sInitAccountOut.dwSize = sizeof(sInitAccountOut);
  149. DWORD dwWaitTime = 5000;
  150. //password reset way
  151. sInitAccountIn.byPwdResetWay = m_DevNetInfo[m_nSelected]->stuDevInfo.byPwdResetWay;
  152. strncpy(sInitAccountIn.szMac, m_DevNetInfo[m_nSelected]->stuDevInfo.szMac, sizeof(m_DevNetInfo[m_nSelected]->stuDevInfo.szMac) - 1);
  153. strncpy(sInitAccountIn.szUserName, strUserName.toLatin1().data(), sizeof(sInitAccountIn.szUserName) - 1);
  154. strncpy(sInitAccountIn.szPwd, strPwd.toLatin1().data(), sizeof(sInitAccountIn.szPwd) - 1);
  155. if (1 == (m_DevNetInfo[m_nSelected]->stuDevInfo.byPwdResetWay & 1))
  156. {
  157. // cell phone
  158. strncpy(sInitAccountIn.szCellPhone, strResetWay.toLatin1().data(), sizeof(sInitAccountIn.szCellPhone) - 1);
  159. }
  160. else if(1 ==(m_DevNetInfo[m_nSelected]->stuDevInfo.byPwdResetWay>>1 & 1))
  161. {
  162. // email
  163. strncpy(sInitAccountIn.szMail, strResetWay.toLatin1().data(), sizeof(sInitAccountIn.szMail) - 1);
  164. }
  165. //Initialize device
  166. nRet = CLIENT_InitDevAccount(&sInitAccountIn, &sInitAccountOut, dwWaitTime, NULL);
  167. if( FALSE == nRet)
  168. {
  169. QMessageBox::about(NULL,tr("Prompt"),tr("Initialize Failed"));
  170. return;
  171. }
  172. QMessageBox::about(NULL,tr("Prompt"),tr("Initialize Success"));
  173. //Modify initialize information
  174. m_DevNetInfo[m_nSelected]->stuDevInfo.byInitStatus = 2;
  175. QString strStatus = tr("Initialize");
  176. m_Model->item(m_nSelected,0)->setText(strStatus);
  177. //设置已初始化设备背景色
  178. for(int column = 0; column < LISTCOLUMN_COUNT; column++)
  179. {
  180. QModelIndex qModeIndex = m_Model->index(m_nSelected,column);
  181. m_Model->setData(qModeIndex,QVariant(Qt::GlobalColor(Qt::white)),Qt::BackgroundColorRole);
  182. }
  183. }
  184. void CDevInitDlg::on_ByIPSearchButton_clicked()
  185. {
  186. CGetIPDlg dlg(NULL,this); //IP搜索界面
  187. dlg.setWindowFlags(dlg.windowFlags()&~Qt::WindowContextHelpButtonHint);//隐藏帮助按钮
  188. int nRet = dlg.exec();
  189. if(nRet == QDialog::Accepted)
  190. {
  191. QDialog::repaint();//界面刷新,去除阻塞窗口的阴影
  192. QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);//处理未完成的事件
  193. dlg.setWindowFlags(Qt::Dialog);
  194. QString strStartIP = dlg.GetStartIP();
  195. QString strEndIP = dlg.GetEndIP();
  196. StartSearchDeviceByIP(strStartIP, strEndIP);
  197. }
  198. }
  199. //CLIENT_StartSearchDevicesEx回调函数
  200. void CALLBACK cbSearchDevicesEx(LLONG lSearchHandle,DEVICE_NET_INFO_EX2 *pDevNetInfo, void* pUserData)
  201. {
  202. if(pDevNetInfo != NULL)
  203. {
  204. CDevInitDlg *dlg = (CDevInitDlg *)pUserData;
  205. DEVICE_NET_INFO_EX2 *pData = NEW DEVICE_NET_INFO_EX2;
  206. if(pData == NULL)
  207. {
  208. return;
  209. }
  210. memcpy(pData, pDevNetInfo, sizeof(DEVICE_NET_INFO_EX2));
  211. emit dlg->SearchDevices(pData);
  212. }
  213. }
  214. //CLIENT_StartSearchDevices回调函数
  215. void CALLBACK cbSearchDevices(DEVICE_NET_INFO_EX *pDevNetInfo, void* pUserData)
  216. {
  217. if(pDevNetInfo != NULL)
  218. {
  219. CDevInitDlg *dlg = (CDevInitDlg *)pUserData;
  220. DEVICE_NET_INFO_EX2 *pData = NEW DEVICE_NET_INFO_EX2;
  221. if(pData == NULL)
  222. {
  223. return;
  224. }
  225. pData->szLocalIP[0] = '\0';
  226. pData->stuDevInfo = *pDevNetInfo;
  227. emit dlg->SearchDevices(pData);
  228. }
  229. }
  230. void CDevInitDlg::on_Broadcast_Button_clicked()
  231. {
  232. StopSearchDevice();
  233. //清空搜索列表
  234. m_Model->removeRows(0,m_nDeviceCount);
  235. //清除vector
  236. m_DevNetInfo.clear();
  237. m_nDeviceCount = 0;
  238. m_pNetCardInfo->Init();
  239. std::set<std::string> IPVector;
  240. m_pNetCardInfo->GetNetCardIp(IPVector);
  241. for (std::set<std::string>::iterator it = IPVector.begin(); it != IPVector.end(); ++it)
  242. {
  243. std::string strLocalIP = *it;
  244. NET_IN_STARTSERACH_DEVICE pInBuf = { 0 };
  245. NET_OUT_STARTSERACH_DEVICE pOutBuf = { 0 };
  246. LLONG seachHandle = 0;
  247. pInBuf.dwSize = sizeof(NET_IN_STARTSERACH_DEVICE);
  248. pInBuf.cbSearchDevices = cbSearchDevicesEx;
  249. pInBuf.pUserData = this;
  250. strncpy(pInBuf.szLocalIp, strLocalIP.c_str(), sizeof(pInBuf.szLocalIp) - 1);
  251. pOutBuf.dwSize = sizeof(NET_OUT_STARTSERACH_DEVICE);
  252. seachHandle = CLIENT_StartSearchDevicesEx(&pInBuf, &pOutBuf);
  253. if (seachHandle)
  254. {
  255. m_searchVecotr.push_back(seachHandle);
  256. }
  257. /*if(!seachHandle)
  258. {
  259. MessageBox(ConvertString("Search by multicast and broadcast failed"),ConvertString("Prompt"));
  260. return;
  261. }
  262. m_searchVecotr.push_back(seachHandle);*/
  263. }
  264. }
  265. void CDevInitDlg::OnSearchDevices(DEVICE_NET_INFO_EX2* pDevNetInfo)
  266. {
  267. if (NULL == pDevNetInfo)
  268. {
  269. return;
  270. }
  271. if (m_nDeviceCount >= MAX_DEV_INFO_COUNT)
  272. {
  273. delete pDevNetInfo;
  274. return;
  275. }
  276. for (int i = 0; i < m_nDeviceCount; i++)
  277. {
  278. if (0 == strcmp(m_DevNetInfo[i]->stuDevInfo.szMac, pDevNetInfo->stuDevInfo.szMac))
  279. {
  280. delete pDevNetInfo;
  281. return;
  282. }
  283. }
  284. m_DevNetInfo.push_back(pDevNetInfo);
  285. m_nDeviceCount++;
  286. int nIndex = m_Model->rowCount();
  287. QString strIPiIPVersion;
  288. strIPiIPVersion = QString::number(pDevNetInfo->stuDevInfo.iIPVersion);
  289. QString strIP;
  290. strIP = QString(QLatin1String(pDevNetInfo->stuDevInfo.szIP));
  291. QString strPort;
  292. strPort = QString::number(pDevNetInfo->stuDevInfo.nPort);
  293. QString strSubnetMask;
  294. strSubnetMask = QString(QLatin1String(pDevNetInfo->stuDevInfo.szSubmask));
  295. QString strGateWay;
  296. strGateWay = QString(QLatin1String(pDevNetInfo->stuDevInfo.szGateway));
  297. QString strMacAddress;
  298. strMacAddress = QString(QLatin1String(pDevNetInfo->stuDevInfo.szMac));
  299. QString strDevType;
  300. strDevType = QString(QLatin1String(pDevNetInfo->stuDevInfo.szDeviceType));
  301. QString strDetailType;
  302. strDetailType = QString(QLatin1String(pDevNetInfo->stuDevInfo.szNewDetailType));
  303. QString strHttp;
  304. strHttp = QString::number(pDevNetInfo->stuDevInfo.nHttpPort);
  305. QString strInitStatus;
  306. BOOL bRet = GetInitStatus(pDevNetInfo->stuDevInfo.byInitStatus);
  307. if(FALSE == bRet)
  308. {
  309. strInitStatus = tr("Uninitialize");
  310. }
  311. else
  312. {
  313. strInitStatus = tr("Initialize");
  314. }
  315. m_Model->setItem(nIndex,LISTCOLUMN_STATUS,NEW QStandardItem(strInitStatus.toCaseFolded()));
  316. m_Model->setItem(nIndex,LISTCOLUMN_IPVERSION,NEW QStandardItem(strIPiIPVersion.toCaseFolded()));
  317. m_Model->setItem(nIndex,LISTCOLUMN_IPADDRESS,NEW QStandardItem(strIP.toCaseFolded()));
  318. m_Model->setItem(nIndex,LISTCOLUMN_PORT,NEW QStandardItem(strPort.toCaseFolded()));
  319. m_Model->setItem(nIndex,LISTCOLUMN_SUBNETMASK,NEW QStandardItem(strSubnetMask.toCaseFolded()));
  320. m_Model->setItem(nIndex,LISTCOLUMN_GATEWAY,NEW QStandardItem(strGateWay.toCaseFolded()));
  321. m_Model->setItem(nIndex,LISTCOLUMN_MACADDRESS,NEW QStandardItem(strMacAddress.toCaseFolded()));
  322. m_Model->setItem(nIndex,LISTCOLUMN_DEVTYPE,NEW QStandardItem(strDevType.toCaseFolded()));
  323. m_Model->setItem(nIndex,LISTCOLUMN_DETAILTYPE,NEW QStandardItem(strDetailType.toCaseFolded()));
  324. m_Model->setItem(nIndex,LISTCOLUMN_HTTP,NEW QStandardItem(strHttp.toCaseFolded()));
  325. //未初始化设备行标红
  326. if(FALSE == bRet)
  327. {
  328. for(int column = 0; column < LISTCOLUMN_COUNT; column++)
  329. {
  330. QModelIndex qModeIndex = m_Model->index(nIndex,column);
  331. m_Model->setData(qModeIndex,QVariant(Qt::GlobalColor(Qt::red)),Qt::BackgroundColorRole);
  332. }
  333. }
  334. }
  335. //Get the state of the device initialization
  336. BOOL CDevInitDlg::GetInitStatus(BYTE initStatus)
  337. {
  338. int result = initStatus & 1;
  339. //Uninitialize
  340. if (result == 1 )
  341. {
  342. return FALSE;
  343. }
  344. //Initialize (include new device that initialize and old device that default initialize )
  345. else
  346. {
  347. return TRUE;
  348. }
  349. }
  350. void CDevInitDlg::StartSearchDeviceByIP(const QString& strStartIP, const QString& strEndIP)
  351. {
  352. emit SearchDevicesByIP(strStartIP, strEndIP);
  353. }
  354. void CDevInitDlg::OnSearchDevicesByIP(const QString& strStartIP, const QString& strEndIP)
  355. {
  356. StopSearchDevice();
  357. BOOL bRet = CheckIP(strStartIP,strEndIP);
  358. if(!bRet)
  359. {
  360. return;
  361. }
  362. //清空搜索列表
  363. m_Model->removeRows(0,m_nDeviceCount);
  364. //清除vector
  365. m_DevNetInfo.clear();
  366. m_nDeviceCount = 0;
  367. m_pNetCardInfo->Init();
  368. DEVICE_IP_SEARCH_INFO DevIpSearchInfo = {0};
  369. char buf[BUFFER_SIZE] = {0};
  370. DevIpSearchInfo.dwSize = sizeof(DEVICE_IP_SEARCH_INFO);
  371. DevIpSearchInfo.nIpNum = m_dwEndIP - m_dwStartIP + 1;
  372. DWORD dwIPs = m_dwStartIP;
  373. for(int i = 0 ;i < DevIpSearchInfo.nIpNum; i ++)
  374. {
  375. IPtoStr(dwIPs, buf, BUFFER_SIZE);
  376. strncpy(DevIpSearchInfo.szIP[i], buf, sizeof(DevIpSearchInfo.szIP[i]) - 1);
  377. dwIPs++;
  378. }
  379. bRet = CLIENT_SearchDevicesByIPs(&DevIpSearchInfo, cbSearchDevices, (LDWORD)this, NULL, 5000);
  380. if(!bRet)
  381. {
  382. QMessageBox::about(NULL,tr("Prompt"),tr("Search by point to point failed"));
  383. }
  384. return;
  385. }
  386. BOOL CDevInitDlg::CheckIP(const QString& strStartIP, const QString& strEndIP)
  387. {
  388. if(strStartIP == NULL || strEndIP == NULL)
  389. {
  390. QMessageBox::about(NULL,tr("Prompt"),tr("please input StartIP or EndIP"));
  391. return FALSE;
  392. }
  393. BYTE btStartIP[4] = {0};
  394. QString strStartIP_First;
  395. QString strStartIP_Two;
  396. QString strStartIP_Three;
  397. QString strStartIP_Four;
  398. strStartIP_First = strStartIP.section(".",0,0);
  399. strStartIP_Two = strStartIP.section(".",1,1);
  400. strStartIP_Three = strStartIP.section(".",2,2);
  401. strStartIP_Four = strStartIP.section(".",3,3);
  402. btStartIP[3] = strStartIP_First.toInt();
  403. btStartIP[2] = strStartIP_Two.toInt();
  404. btStartIP[1] = strStartIP_Three.toInt();
  405. btStartIP[0] = strStartIP_Four.toInt();
  406. memcpy(&m_dwStartIP,btStartIP,4);
  407. BYTE btEndIP[4] = {0};
  408. QString strEndIP_First;
  409. QString strEndIP_Two;
  410. QString strEndIP_Three;
  411. QString strEndIP_Four;
  412. strEndIP_First = strEndIP.section(".",0,0);
  413. strEndIP_Two = strEndIP.section(".",1,1);
  414. strEndIP_Three = strEndIP.section(".",2,2);
  415. strEndIP_Four = strEndIP.section(".",3,3);
  416. btEndIP[3] = strEndIP_First.toInt();
  417. btEndIP[2] = strEndIP_Two.toInt();
  418. btEndIP[1] = strEndIP_Three.toInt();
  419. btEndIP[0] = strEndIP_Four.toInt();
  420. memcpy(&m_dwEndIP,btEndIP,4);
  421. if(NULL == strStartIP_First || NULL == strStartIP_Two || NULL == strStartIP_Three || NULL == strStartIP_Four ||
  422. NULL == strEndIP_First || NULL == strEndIP_Two || NULL == strEndIP_Three || NULL == strEndIP_Four)
  423. {
  424. QMessageBox::about(NULL,tr("Prompt"),tr("please input the correct IP"));
  425. return FALSE;
  426. }
  427. if(strStartIP_First.toInt() >= 256 || strStartIP_Two.toInt() >= 256 || strStartIP_Three.toInt() >= 256 || strStartIP_Four.toInt() >= 256 ||
  428. strEndIP_First.toInt() >= 256 || strEndIP_Two.toInt() >= 256 || strEndIP_Three.toInt() >= 256 || strEndIP_Four.toInt() >= 256 )
  429. {
  430. QMessageBox::about(NULL,tr("Prompt"),tr("please input the correct IP"));
  431. return FALSE;
  432. }
  433. if(m_dwEndIP < m_dwStartIP)
  434. {
  435. QMessageBox::about(NULL,tr("Prompt"),tr("Illegal IP format"));
  436. return FALSE;
  437. }
  438. if(m_dwEndIP - m_dwStartIP + 1 > 256)
  439. {
  440. QMessageBox::about(NULL,tr("Prompt"),tr("IP amount exceed 256"));
  441. return FALSE;
  442. }
  443. return TRUE;
  444. }
  445. void CDevInitDlg::IPtoStr(DWORD ip, char* buf, unsigned int nBufferSize)
  446. {
  447. memset(buf,0,nBufferSize);
  448. unsigned short add1,add2,add3,add4;
  449. add1 = (unsigned short)(ip&255);
  450. add2 = (unsigned short)((ip>>8)&255);
  451. add3 = (unsigned short)((ip>>16)&255);
  452. add4 = (unsigned short)((ip>>24)&255);
  453. sprintf(buf,"%d.%d.%d.%d",add4,add3,add2,add1);
  454. }
  455. void CDevInitDlg::GetPwdRestWay(BYTE pwdRestWay)
  456. {
  457. if(1 == (pwdRestWay & 1))
  458. {
  459. m_strPwdResetWay = tr("Cell Phone");
  460. }
  461. else if(1 == (pwdRestWay>>1 & 1))
  462. {
  463. m_strPwdResetWay = tr("Mail Box");
  464. }
  465. }
  466. void CDevInitDlg::keyPressEvent(QKeyEvent *event)
  467. {
  468. switch(event->key())
  469. {
  470. case Qt::Key_Escape:
  471. break;
  472. default:
  473. QDialog::keyPressEvent(event);
  474. }
  475. }
  476. void CDevInitDlg::StopSearchDevice()
  477. {
  478. for (int i = 0; i < m_searchVecotr.size(); i++)
  479. {
  480. if (0 != m_searchVecotr[i])
  481. {
  482. BOOL bSuccess = CLIENT_StopSearchDevices(m_searchVecotr[i]);
  483. if(!bSuccess)
  484. {
  485. QMessageBox::about(NULL,tr("Prompt"),tr("Stop search failed!"));
  486. }
  487. else
  488. {
  489. m_searchVecotr[i] = 0;
  490. }
  491. }
  492. }
  493. m_searchVecotr.clear();
  494. }