#include "cuserparams.h" #include "publicfuc.h" #include CUserParams::CUserParams(QWidget *parent) : QDialog(parent) { ui.setupUi(this); m_lUserID = -1; m_iStartChan = 0; m_iSimChannelNum = 0; int i; for (i = 0; i < MAX_CHANNUM_V30; i++) { m_iArryChannel[i] = -1; m_pcheckLocalChannel[i] = NULL; m_pcheckRemoteChannel[i] = NULL; } for (i = 0; i < MAX_RIGHT; i++) { m_pcheckLocalRight[i] = NULL; m_pcheckRemoteRight[i] = NULL; } ui.checkRemoteRight11->hide(); QStringList strings; strings<<"Local playback"<<"Local record"<<"PTZ local control"<<"Local backup"; ui.comboLocalRight->addItems(strings); strings.clear(); strings<<"Remote preview"<<"Remote playback"<<"Remote record"<<"PTZ remote control"; ui.comboNetRight->addItems(strings); //Óû§ strings.clear(); strings<<"Administrator"; strings<<"User1"<<"User2"<<"User3"<<"User4"<<"User5"<<"User6"<<"User7"; strings<<"User8"<<"User9"<<"User10"<<"User11"<<"User12"<<"User13"<<"User14"; strings<<"User15"<<"User16"<<"User17"<<"User18"<<"User19"<<"User20"<<"User21"; strings<<"User22"<<"User23"<<"User24"<<"User25"<<"User26"<<"User27"<<"User28"; strings<<"User29"<<"User30"<<"User31"; ui.comboUserNo->addItems(strings); ui.tableLocalChannel->horizontalHeader()->setResizeMode(QHeaderView::Stretch); ui.tableLocalChannel->setColumnCount(1); ui.tableRemoteChannel->horizontalHeader()->setResizeMode(QHeaderView::Stretch); ui.tableRemoteChannel->setColumnCount(1); connect(ui.comboUserNo, SIGNAL(activated(int)), this, SLOT( userIDChanged(int ))); connect(ui.comboLocalRight, SIGNAL(activated(int)), this, SLOT(localRightTypeChanged(int))); connect(ui.comboNetRight, SIGNAL(activated(int)), this, SLOT(remoteRightTypeChanged(int))); //ÓÅÏȼ¶ connectArrayAndWidget(); } CUserParams::~CUserParams() { } //Óû§ID±ä»¯ void CUserParams::userIDChanged(int iUserID) { if(m_lUserID < 0) { return ; } NET_DVR_USER_V30 struUser; int iRet; DWORD uiReturnLen; //»ñÈ¡É豸µÄ²ÎÊýÖµ iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_USERCFG_V30, -1, &struUser, sizeof(NET_DVR_USER_V30), &uiReturnLen); if(iRet == 0) { iRet = NET_DVR_GetLastError(); QMessageBox::information(this, tr("Please check!"), tr("Get User parameters error! \"%1\"").arg(iRet)); return ; } //ÉèÖÃÓû§²ÎÊýµ½¿Ø¼þÖÐÈ¥ ui.editUserName->setText((char*)struUser.struUser[iUserID].sUserName); ui.editPassword->setText((char*)struUser.struUser[iUserID].sPassword); ui.editPassword2->setText((char*)struUser.struUser[iUserID].sPassword); //ÓÅÏȼ¶ QStringList strings; if(struUser.struUser[iUserID].byPriority == (BYTE)0xff) { ui.comboPriority->setEnabled(FALSE); } else { ui.comboPriority->setEnabled(TRUE); ui.comboPriority->clear(); if(struUser.struUser[iUserID].byPriority == 2) { strings<<"Administrator"; ui.comboPriority->addItems(strings); ui.comboPriority->setCurrentIndex(0); } else { strings<<"Normal user"<<"Operator"; ui.comboPriority->addItems(strings); ui.comboPriority->setCurrentIndex((int)(unsigned int)(struUser.struUser[iUserID].byPriority)); } } //±¾µØºÍÔ¶³Ì²Ù×÷ȨÏÞ int i; for(i = 0; i < MAX_RIGHT; i++) { if(m_pcheckLocalRight[i] != NULL) { m_pcheckLocalRight[i]->setChecked(struUser.struUser[iUserID].byLocalRight[i]); } if(m_pcheckRemoteRight[i] != NULL) { m_pcheckRemoteRight[i]->setChecked(struUser.struUser[iUserID].byRemoteRight[i]); } } //±¾µØºÍÔ¶³ÌͨµÀȨÏÞ localRightTypeChanged(0); remoteRightTypeChanged(0); //IPµØÖ· ui.editUserIP->setText(struUser.struUser[iUserID].struUserIP.sIpV4); //MACµØÖ· char strMAC[100] = {0}; for(i = 0; i < MACADDR_LEN; i++) { sprintf(strMAC, "%02x", struUser.struUser[iUserID].byMACAddr[i]); m_pEditMAC[i]->setText(strMAC); } } //±¾µØÍ¨µÀȨÏÞ·½Ê½¸Ä±ä void CUserParams::localRightTypeChanged(int iLocalRightType) { if(m_lUserID < 0) { return ; } //QMessageBox::information(this, tr("Please check!"), tr("Changed error!")); int iUserNo;//Óû§µÄÐòºÅ iUserNo = ui.comboUserNo->currentIndex(); NET_DVR_USER_V30 struUser; int iRet; DWORD uiReturnLen; //»ñÈ¡É豸µÄ²ÎÊýÖµ iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_USERCFG_V30, -1, &struUser, sizeof(NET_DVR_USER_V30), &uiReturnLen); if(iRet == 0) { iRet = NET_DVR_GetLastError(); QMessageBox::information(this, tr("Please check!"), tr("Get User parameters error! \"%1\"").arg(iRet)); return ; } //ÉèÖÃȨÏÞµÄͨµÀ int i; BYTE *pRight; //ÒÀ¾ÝȨÏÞ²ÎÊýÔڽṹÌåÖÐλÖÃÆ«ÒÆ pRight = struUser.struUser[iUserNo].byLocalPlaybackRight + iLocalRightType*2*MAX_CHANNUM_V30; for(i = 0; i < MAX_CHANNUM_V30; i++) { if(m_pcheckLocalChannel[i] != NULL) { if(pRight[i] == (BYTE)0xff) //µÍ°æ±¾É豸²»Ö§³Ö¸Ã²ÎÊý()£¬¸ÃÖµSDKÉèΪ-1 { m_pcheckLocalChannel[i]->setChecked(FALSE); } else //Õý³£Çé¿öÏÂλ0£¬1 { m_pcheckLocalChannel[i]->setChecked(pRight[i]); } } } } //±¾µØÍ¨µÀȨÏÞ·½Ê½¸Ä±ä void CUserParams::remoteRightTypeChanged(int iRemoteRightType) { if(m_lUserID < 0) { return ; } //QMessageBox::information(this, tr("Please check!"), tr("Changed error!")); int iUserNo;//Óû§µÄÐòºÅ iUserNo = ui.comboUserNo->currentIndex(); NET_DVR_USER_V30 struUser; int iRet; DWORD uiReturnLen; //»ñÈ¡É豸µÄ²ÎÊýÖµ iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_USERCFG_V30, -1, &struUser, sizeof(NET_DVR_USER_V30), &uiReturnLen); if(iRet == 0) { iRet = NET_DVR_GetLastError(); QMessageBox::information(this, tr("Please check!"), tr("Get User parameters error! \"%1\"").arg(iRet)); return ; } //ÉèÖÃȨÏÞµÄͨµÀ int i; BYTE *pRight; //ÒÀ¾ÝȨÏÞ²ÎÊýÔڽṹÌåÖÐλÖÃÆ«ÒÆ pRight = struUser.struUser[iUserNo].byNetPreviewRight + iRemoteRightType*2*MAX_CHANNUM_V30; for(i = 0; i < MAX_CHANNUM_V30; i++) { if(m_pcheckRemoteChannel[i] != NULL) { if(pRight[i] == (BYTE)0xff) //µÍ°æ±¾É豸²»Ö§³Ö¸Ã²ÎÊý()£¬¸ÃÖµSDKÉèΪ-1 { m_pcheckRemoteChannel[i]->setChecked(FALSE); } else //Õý³£Çé¿öÏÂλ0£¬1 { m_pcheckRemoteChannel[i]->setChecked(pRight[i]); } } } } //»ñȡʵ¼Ê¿ÉÓÃͨµÀÁÐ±í£¬²¢Ð´ÈëtablewidgetÖÐ int CUserParams::getChannelNum() { if(m_lUserID < 0) { return HPR_ERROR; } NET_DVR_DEVICECFG struDeviceParams; DWORD paramsLen; int iRet; //***1.Get the channel number and IP channel number.***// iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_DEVICECFG, -1, &struDeviceParams, sizeof(NET_DVR_DEVICECFG), ¶msLen); if (iRet == 0) { iRet = NET_DVR_GetLastError(); QMessageBox::information(this, tr("Please check!"), tr("Get device parameters error!")); return HPR_ERROR; } m_iStartChan = (int) (struDeviceParams.byStartChan); //***2.Get the channel which is enabled.***// //iRetµÄÖµÓÃÓÚÅжÏÊÇ·ñÖ§³ÖIPͨµÀ NET_DVR_IPPARACFG struIPParams; iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_IPPARACFG, -1, &struIPParams, sizeof(NET_DVR_IPPARACFG), ¶msLen); int i, j; j = 0; if (iRet != 0)//if support ip channel { //Ä£ÄâͨµÀ for (i = 0; i < MAX_ANALOG_CHANNUM; i++) { if (struIPParams.byAnalogChanEnable[i]) { m_iArryChannel[j] = i + m_iStartChan; j++; } } m_iSimChannelNum = j; //IPͨµÀ for (i = 0; i < MAX_IP_CHANNEL; i++) { if (struIPParams.struIPChanInfo[i].byIPID != 0) { m_iArryChannel[j] = i + m_iStartChan + MAX_ANALOG_CHANNUM; j++; } } } else//if not support ip channel { //simulate channel for (i = 0; (i < MAX_ANALOG_CHANNUM) && (i < struDeviceParams.byChanNum); i++) { m_iArryChannel[j] = i + m_iStartChan; j++; } m_iSimChannelNum = j; } //ʵ¼Ê¿ÉÓõÄ×î´óͨµÀÊýÄ¿ int iMaxChannelNo; for(i = 0; i < MAX_CHANNUM_V30; i++) { if(m_iArryChannel[i] < 0) { break; } } iMaxChannelNo = i; int iRow = 0; //±í¸ñµÄÐÐ //ɾ³ýÉϴεÄÐÐÊý iRow = ui.tableLocalChannel->rowCount(); for(i = 0; i < iRow; i++) { ui.tableLocalChannel->removeRow(i); ui.tableRemoteChannel->removeRow(i); } //Çå³ýÉϴμÓÈëµÄÄÚÈÝ£¬×¢Òâtablewidget»á×Ô¼ºÊͷŵôÄڴ棬¼´Ê¹²»ÊÇnew³öÀ´µÄ ui.tableLocalChannel->clear(); ui.tableRemoteChannel->clear(); for (i = 0; i < MAX_CHANNUM_V30; i++) { m_pcheckLocalChannel[i] = NULL; m_pcheckRemoteChannel[i] = NULL; } //ÉèÖÃеĺ¯ÊýºÍtableÍ· ui.tableLocalChannel->setRowCount(iMaxChannelNo); ui.tableRemoteChannel->setRowCount(iMaxChannelNo); QStringList strings; strings<<"Local channel"; ui.tableLocalChannel->setHorizontalHeaderLabels(strings); strings.clear(); strings<<"Remote channel"; ui.tableRemoteChannel->setHorizontalHeaderLabels(strings); //***3. Add check items to table.***// char strTemp[100] = { 0 }; iRow = 0; for (i = 0; i < MAX_CHANNUM_V30; i++) { if (m_iArryChannel[i] >= 0)//·¢ÏÖÒ»¸öͨµÀ { if (m_iArryChannel[i] < MAX_ANALOG_CHANNUM) //Ä£ÄâͨµÀ { sprintf(strTemp, "Camora%d", m_iArryChannel[i]); } else//IP channel { if (iRet != 0)//supprot IP channel { sprintf(strTemp, "IPCamora%d", (m_iArryChannel[i] - MAX_ANALOG_CHANNUM)); } } //new³öÀ´Ò»¸öеıäÁ¿ m_pcheckLocalChannel[m_iArryChannel[i] - m_iStartChan] = new QCheckBox(); m_pcheckRemoteChannel[m_iArryChannel[i] - m_iStartChan] = new QCheckBox(); m_pcheckLocalChannel[m_iArryChannel[i] - m_iStartChan]->setText(strTemp); m_pcheckRemoteChannel[m_iArryChannel[i] - m_iStartChan]->setText(strTemp); ui.tableLocalChannel->setCellWidget(iRow, 0, (m_pcheckLocalChannel[m_iArryChannel[i] - m_iStartChan])); ui.tableRemoteChannel->setCellWidget(iRow, 0, (m_pcheckRemoteChannel[m_iArryChannel[i] - m_iStartChan])); iRow++; } } return HPR_OK; } //ÉèÖþä±úÖµ int CUserParams::setUserID(long lUserID) { if(lUserID < 0) { return HPR_ERROR; } m_lUserID = lUserID; return HPR_OK; } //»ñÈ¡²ÎÊý£¬Ð´Èë¿Ø¼þÖÐÈ¥ int CUserParams::getAllInfo() { if(m_lUserID < 0) { return HPR_ERROR; } //ÉèÖõ±Ç°µÄÓû§ÎªNOΪ0 ui.comboUserNo->setCurrentIndex(0); //ÉèÖÃÓû§²ÎÊýµ½¿Ø¼þÖÐÈ¥ userIDChanged(0); return HPR_OK; } int CUserParams::setAllInfo() { if(m_lUserID < 0) { return HPR_ERROR; } NET_DVR_USER_V30 struUser; int iRet; DWORD uiReturnLen; //»ñÈ¡Óû§µÄ²ÎÊýÖµ iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_USERCFG_V30, -1, &struUser, sizeof(NET_DVR_USER_V30), &uiReturnLen); if(iRet == 0) { iRet = NET_DVR_GetLastError(); QMessageBox::information(this, tr("Please check!"), tr("Get User parameters error! \"%1\"").arg(iRet)); return HPR_ERROR; } //ÉèÖÃÓû§Ãû:ÏȱȽÏÃÜÂëÊÇ·ñÏàͬ if(ui.editPassword->text() != ui.editPassword2->text()) { QMessageBox::information(this, tr("Please check!"), tr("password is not equal error! ")); return HPR_ERROR; } //»ñÈ¡µ±Ç°Óû§ºÅ int iUserNo; iUserNo = ui.comboUserNo->currentIndex(); //IPµØÖ· iRet = KIT_editToIP(ui.editUserIP, (BYTE *)struUser.struUser[iUserNo].struUserIP.sIpV4, 16); if(iRet == HPR_ERROR) { QMessageBox::information(this, tr("Please check!"), tr("ip is error! ")); return HPR_ERROR; } //MACµØÖ· char strMAC[100] = {0}; int iMAC; int i; for(i = 0; i < MACADDR_LEN; i++) { memset(strMAC, 0, 100); KIT_editToStr(m_pEditMAC[i], (BYTE *)strMAC, 3); sscanf(strMAC, "%02x", &iMAC); struUser.struUser[iUserNo].byMACAddr[i] = (BYTE)iMAC; } KIT_editToStr(ui.editUserName, struUser.struUser[iUserNo].sUserName, NAME_LEN); //ÉèÖÃÃÜÂë KIT_editToStr(ui.editPassword, struUser.struUser[iUserNo].sPassword, PASSWD_LEN); //ÉèÖÃÔ¶³ÌºÍ±¾µØÈ¨ÏÞ for(i = 0; i < MAX_RIGHT; i++) { if(m_pcheckLocalRight[i] != NULL)//±¾µØÈ¨ÏÞ { struUser.struUser[iUserNo].byLocalRight[i] = (BYTE)m_pcheckLocalRight[i]->isChecked(); } if(m_pcheckRemoteRight[i] != NULL) { struUser.struUser[iUserNo].byRemoteRight[i] = (BYTE)m_pcheckRemoteRight[i]->isChecked(); } } //ÓÅÏȼ¶ if(ui.comboPriority->isEnabled()) { if(ui.comboPriority->count() == 2) { struUser.struUser[iUserNo].byPriority = ui.comboPriority->currentIndex(); } else { struUser.struUser[iUserNo].byPriority = 2; } } else { struUser.struUser[iUserNo].byPriority = (BYTE)0xff; } //ͨµÀȨÏÞ //µÃµ½µ±Ç°Í¨µÀȨÏÞÀàÐÍ int iLocalRightType; int iRemoteRightType; iLocalRightType = ui.comboLocalRight->currentIndex(); iRemoteRightType = ui.comboNetRight->currentIndex(); BYTE *pLocalRight; BYTE *pRemoteRight; //ÒÀ¾ÝȨÏÞ²ÎÊýÔڽṹÌåÖÐλÖÃÆ«ÒÆ pLocalRight = struUser.struUser[iUserNo].byLocalPlaybackRight + iLocalRightType*2*MAX_CHANNUM_V30; pRemoteRight = struUser.struUser[iUserNo].byNetPreviewRight + iRemoteRightType*2*MAX_CHANNUM_V30; for(i = 0; i < MAX_CHANNUM_V30; i++) { //±¾µØÍ¨µÀ if(m_pcheckLocalChannel[i] != NULL) { if(pLocalRight[i] != (BYTE)0xff) //¸ÃÉ豸°æ±¾²»µÍʱ { pLocalRight[i] = m_pcheckLocalChannel[i]->isChecked(); } } //Ô¶³ÌͨµÀ if(m_pcheckRemoteChannel[i] != NULL)//¸ÃÉ豸°æ±¾²»µÍʱ { if(pRemoteRight[i] != (BYTE)0xff) { pRemoteRight[i] = m_pcheckRemoteChannel[i]->isChecked(); } } } //±£´æµ½É豸 iRet = NET_DVR_SetDVRConfig(m_lUserID, NET_DVR_SET_USERCFG_V30, -1, &struUser, sizeof(NET_DVR_USER_V30)); if(0 == iRet) { iRet = NET_DVR_GetLastError(); QMessageBox::information(this, tr("Please check!"), tr("Set User parameters error! \"%1\"").arg(iRet)); return HPR_ERROR; } return HPR_OK; } void CUserParams::connectArrayAndWidget() { //±¾µØÈ¨ÏÞ m_pcheckLocalRight[0] = ui.checkLocalRight0; m_pcheckLocalRight[1] = ui.checkLocalRight1; m_pcheckLocalRight[2] = ui.checkLocalRight2; m_pcheckLocalRight[3] = ui.checkLocalRight3; m_pcheckLocalRight[4] = ui.checkLocalRight4; m_pcheckLocalRight[5] = ui.checkLocalRight5; m_pcheckLocalRight[6] = ui.checkLocalRight6; m_pcheckLocalRight[7] = ui.checkLocalRight7; m_pcheckLocalRight[8] = ui.checkLocalRight8; m_pcheckLocalRight[9] = ui.checkLocalRight9; //Ô¶³ÌȨÏÞ m_pcheckRemoteRight[0] = ui.checkRemoteRight0; m_pcheckRemoteRight[1] = ui.checkRemoteRight1; m_pcheckRemoteRight[2] = ui.checkRemoteRight2; m_pcheckRemoteRight[3] = ui.checkRemoteRight3; m_pcheckRemoteRight[4] = ui.checkRemoteRight4; m_pcheckRemoteRight[5] = ui.checkRemoteRight5; m_pcheckRemoteRight[6] = ui.checkRemoteRight6; m_pcheckRemoteRight[7] = ui.checkRemoteRight7; m_pcheckRemoteRight[8] = ui.checkRemoteRight8; m_pcheckRemoteRight[9] = ui.checkRemoteRight9; m_pcheckRemoteRight[10] = ui.checkRemoteRight10; m_pcheckRemoteRight[11] = ui.checkRemoteRight11; m_pcheckRemoteRight[12] = ui.checkRemoteRight12; m_pcheckRemoteRight[13] = ui.checkRemoteRight13; //MACµØÖ· m_pEditMAC[0] = ui.editMACAddr1; m_pEditMAC[1] = ui.editMACAddr2; m_pEditMAC[2] = ui.editMACAddr3; m_pEditMAC[3] = ui.editMACAddr4; m_pEditMAC[4] = ui.editMACAddr5; m_pEditMAC[5] = ui.editMACAddr6; } //event void CUserParams::showEvent ( QShowEvent * event ) { if(NULL == event) { } getChannelNum(); //»ñȡͨµÀºÅ getAllInfo(); }