pans
2016-12-15 87e3ee273b2f84081ac45926be9d8e5be3166eaa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
 
#include <QMessageBox>
#include "cadvancednetparams.h"
#include "DemoPublic.h"
#include "publicfuc.h"
 
#ifndef HPR_OK
#define HPR_OK 0
#endif
 
#ifndef HPR_ERROR
#define HPR_ERROR -1
#endif
 
CAdvancedNetParams::CAdvancedNetParams(QWidget *parent)
    : QDialog(parent), m_ui(new Ui::CAdvancedNetParamsClass)
{
    m_ui->setupUi(this);
    m_lUserID = -1;
    m_lChannel = 1;
    QStringList strings;
    strings << "Hikvision DNS" << "Dyndns"<<"PeanutHull"<<"No-IP";
    m_ui->comboDDNSType->addItems(strings);
 
    strings.clear();
    strings<<"2s"<<"3s"<<"4s"<<"5s";
    m_ui->comboBoEmailInterval->addItems(strings);
 
    //checkbox
    connect(m_ui->checkBoPPPoE, SIGNAL(clicked()), this, SLOT(clickPPPoE()));
    connect(m_ui->checkBoNTP, SIGNAL(clicked()), this, SLOT(clickNTP()));
    connect(m_ui->checkBoDDNS, SIGNAL(clicked()), this, SLOT(clickDDNS()));
 
    //btn
    connect(m_ui->btnSaveParams, SIGNAL(clicked()), this, SLOT(saveParams()));
    connect(m_ui->btnRefresh, SIGNAL(clicked()), this, SLOT(refreshParams()));
 
    //table
    //connect(m_ui->tabWEmail, SIGNAL(cellChanged(int,int)), this, SLOT(updateTable(int, int)));
 
    //table
    m_ui->tabWEmail->setColumnCount(2);
    m_ui->tabWEmail->setRowCount(3);
 
    //set the size of the table
    m_ui->tabWEmail->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
 
    strings.clear();
    strings<<"receiver name"<<"Email";
    m_ui->tabWEmail->setHorizontalHeaderLabels(strings);
}
 
CAdvancedNetParams::~CAdvancedNetParams()
{
    int i,j; // i is row;  j is  column
 
    //delete the table item.
    for(i = 0;  i <3; i++ )
    {
        for(j=0; j<2; j++)
        {
            delete m_ui->tabWEmail->takeItem(0,0);
        }
        m_ui->tabWEmail->removeRow(i);
    }
    delete m_ui;
}
 
void CAdvancedNetParams::showEvent ( QShowEvent * event )
{
    //disable warning
    if(event == NULL)
    {
    }
    if(m_lUserID < 0)
    {
        //QMessageBox::information(this, tr("Please login firstly!"), tr("Please login firstly!."));
        return;
    }
    getPPPoEInfo();
    getNTPInfo();
    getDDNSInfo();
}
 
int CAdvancedNetParams::getPPPoEInfo()
{
    NET_DVR_NETCFG_V30 netParams;
    QString qstrTemp;
    DWORD paramsLen;
    char strTemp[100];
    int iRet;
 
    memset(&netParams, 0, sizeof(NET_DVR_NETCFG_V30));
    iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_NETCFG_V30, m_lChannel, &netParams, sizeof(NET_DVR_NETCFG_V30), &paramsLen);
    if(iRet == 0)
    {
        QMessageBox::information(this, tr("Please check!"), tr("Get PPPoE information unsuccessfully! error:%1").arg(iRet));
        return HPR_ERROR;
    }
 
    //PPPoE UserName
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%s", netParams.struPPPoE.sPPPoEUser);
    m_ui->editPPPoEUserName->setText(QString(QLatin1String(strTemp)));
    //PPPoE  Passwd
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%s", netParams.struPPPoE.sPPPoEPassword);
    m_ui->editPPPoEPasswd->setText(QString(QLatin1String(strTemp)));
    //PPPoE IP address
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%s", netParams.struPPPoE.struPPPoEIP.sIpV4);
    m_ui->editPPPoEIP->setText(QString(QLatin1String(strTemp)));
 
    m_ui->editPPPoEPass2->setText(QString(QLatin1String("")));
    //whether  PPPoE is set
    if(netParams.struPPPoE.dwPPPOE == 0)
    {
        m_ui->editPPPoEUserName->setEnabled(FALSE);
        m_ui->editPPPoEPasswd->setEnabled(FALSE);
        m_ui->editPPPoEIP->setEnabled(FALSE);
        m_ui->editPPPoEPass2->setEnabled(FALSE);
        m_ui->checkBoPPPoE->setCheckState(Qt::Unchecked);
    }
    if(netParams.struPPPoE.dwPPPOE == 1)
    {
        m_ui->editPPPoEUserName->setEnabled(TRUE);
        m_ui->editPPPoEPasswd->setEnabled(TRUE);
        m_ui->editPPPoEIP->setEnabled(FALSE);
        m_ui->editPPPoEPass2->setEnabled(TRUE);
        m_ui->checkBoPPPoE->setCheckState(Qt::Checked);
    }
 
    return HPR_OK;
}
 
//get NTP information
int CAdvancedNetParams::getNTPInfo()
{
    NET_DVR_NTPPARA NTPParams;
    DWORD uiParamsLen;
    int iRet;
    char strTemp[100];
 
    memset(&NTPParams, 0, sizeof(NET_DVR_NTPPARA));
    iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_NTPCFG, m_lChannel, &NTPParams, sizeof(NET_DVR_NTPPARA),  &uiParamsLen);
    if(iRet == 0)
    {
        KIT_DisplayErrorInfo("Get NTP", KIT_ERRPR_DIS_TYPE);
        //QMessageBox::information(this, tr("Please check!"), tr(".Get NTP information unsuccessfully!"));
        return HPR_ERROR;
    }
 
    //NTP Address
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%s", NTPParams.sNTPServer);
    m_ui->editNTPAddr->setText(QString(QLatin1String(strTemp)));
 
    //NTP Port
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%d", NTPParams.wNtpPort);
    m_ui->editNTPPort->setText(QString(QLatin1String(strTemp)));
 
    //interval time
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%d", NTPParams.wInterval);
    m_ui->editNTFInterval->setText(QString(QLatin1String(strTemp)));
 
    //different time hour
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%d", NTPParams.cTimeDifferenceH);
    m_ui->editTimeDifH->setText(QString(QLatin1String(strTemp)));
    //different tine mimute
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%d", NTPParams.cTimeDifferenceM);
    m_ui->editTimeDifM->setText(QString(QLatin1String(strTemp)));
 
    if(NTPParams.byEnableNTP == 0)
    {
        m_ui->editNTPAddr->setEnabled(FALSE);
        m_ui->editNTPPort->setEnabled(FALSE);
        m_ui->editNTFInterval->setEnabled(FALSE);
        m_ui->editTimeDifH->setEnabled(FALSE);
        m_ui->editTimeDifM->setEnabled(FALSE);
        m_ui->checkBoNTP->setCheckState(Qt::Unchecked);
    }
 
    if(NTPParams.byEnableNTP == 1)
    {
          m_ui->editNTPAddr->setEnabled(TRUE);
          m_ui->editNTPPort->setEnabled(TRUE);
          m_ui->editNTFInterval->setEnabled(TRUE);
          m_ui->editTimeDifH->setEnabled(TRUE);
          m_ui->editTimeDifM->setEnabled(TRUE);
          m_ui->checkBoNTP->setCheckState(Qt::Checked);
    }
    return HPR_OK;
}
 
//set NTP information
int CAdvancedNetParams::setNTPInfo()
{
    NET_DVR_NTPPARA NTPParams;
    DWORD uiParamsLen;
    int iRet;
    int iTemp;
 
    memset(&NTPParams, 0, sizeof(NET_DVR_NTPPARA));
    iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_NTPCFG, m_lChannel, &NTPParams, sizeof(NET_DVR_NTPPARA),  &uiParamsLen);
    if(iRet == 0)
    {
        KIT_DisplayErrorInfo("Get NTP", KIT_ERRPR_DIS_TYPE);
        //QMessageBox::information(this, tr("Please check!"), tr(".Get NTP information unsuccessfully!"));
        return HPR_ERROR;
    }
 
    if(m_ui->checkBoNTP->isChecked())
    {
        NTPParams.byEnableNTP = 1;
                KIT_editToStr(m_ui->editNTPAddr, (BYTE *)&(NTPParams.sNTPServer), 64);
        KIT_editToInt(m_ui->editNTFInterval, &iTemp);   //time
        NTPParams.wInterval = iTemp;
        KIT_editToInt(m_ui->editTimeDifH, &iTemp);       //hour
        NTPParams.cTimeDifferenceH = iTemp;
        KIT_editToInt(m_ui->editTimeDifM, &iTemp);      //minute
        NTPParams.cTimeDifferenceM = iTemp;
        KIT_editToInt(m_ui->editNTPPort, &iTemp);        //port
        NTPParams.wNtpPort = iTemp;
    }
    else
    {
        NTPParams.byEnableNTP = 0;
    }
 
    iRet = NET_DVR_SetDVRConfig(m_lUserID, NET_DVR_SET_NTPCFG, m_lChannel, &NTPParams, sizeof(NET_DVR_NTPPARA));
    if(iRet == 0)
    {
        iRet = NET_DVR_GetLastError();
        QMessageBox::information(this, tr("Set Net fail!"), tr("Set Net fail. \"%1\"").arg(iRet));
        return HPR_ERROR;
    }
 
    return HPR_OK;
}
 
//get DDNS information
int CAdvancedNetParams::getDDNSInfo()
{
    NET_DVR_DDNSPARA_V30 DDNSParams;
    DWORD uiParamsLen;
    int iRet;
    char strTemp[100];
 
    memset(&DDNSParams, 0, sizeof(NET_DVR_DDNSPARA_V30));
    iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_DDNSCFG_V30, m_lChannel, &DDNSParams, sizeof(NET_DVR_DDNSPARA_V30),  &uiParamsLen);
    if(iRet == 0)
    {
        KIT_DisplayErrorInfo("Get DDNS", KIT_ERRPR_DIS_TYPE);
        //QMessageBox::information(this, tr("Please check!"), tr(".Get NTP information unsuccessfully!"));
        return HPR_ERROR;
    }
 
    //DDNS Server Type
        if( /*DDNSParams.byHostIndex >= 0 &&*/ DDNSParams.byHostIndex <= 3)
    {
        m_ui->comboDDNSType->setCurrentIndex((int)(DDNSParams.byHostIndex));
    }
 
    //DDNS Server Name
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%s", DDNSParams.struDDNS[int(DDNSParams.byHostIndex)].sServerName);
    m_ui->editDDNSServerName->setText(QString(QLatin1String(strTemp)));
 
    //DDNS Domain
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%s", DDNSParams.struDDNS[int(DDNSParams.byHostIndex)].sDomainName);
    m_ui->editDDNSDomainName->setText(QString(QLatin1String(strTemp)));
 
    //DDNS port
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%d", DDNSParams.struDDNS[int(DDNSParams.byHostIndex)].wDDNSPort);
    m_ui->editDDNSPort->setText(QString(QLatin1String(strTemp)));
 
    //DDNS User Name
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%s", DDNSParams.struDDNS[int(DDNSParams.byHostIndex)].sUsername);
    m_ui->editDDNSUserName->setText(QString(QLatin1String(strTemp)));
 
    //DDNS User passwd
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%s", DDNSParams.struDDNS[int(DDNSParams.byHostIndex)].sPassword);
    m_ui->editDDNSPasswd->setText(QString(QLatin1String(strTemp)));
 
    //whether DDNS is set
   if(DDNSParams.byEnableDDNS == 0)
   {
       m_ui->editDDNSDomainName->setEnabled(FALSE);
       m_ui->editDDNSServerName->setEnabled(FALSE);
       m_ui->editDDNSPasswd->setEnabled(FALSE);
       m_ui->editDDNSPort->setEnabled(FALSE);
       m_ui->editDDNSUserName->setEnabled(FALSE);
       m_ui->editDDNSpasswd2->setEnabled(FALSE);
       m_ui->comboDDNSType->setEnabled(FALSE);
       m_ui->checkBoDDNS->setCheckState(Qt::Unchecked);
   }
   else
   {
       if(DDNSParams.byEnableDDNS == 1)
       {
           m_ui->editDDNSDomainName->setEnabled(TRUE);
           m_ui->editDDNSServerName->setEnabled(TRUE);
           m_ui->editDDNSPasswd->setEnabled(TRUE);
           m_ui->editDDNSPort->setEnabled(TRUE);
           m_ui->editDDNSUserName->setEnabled(TRUE);
           m_ui->editDDNSpasswd2->setEnabled(TRUE);
           m_ui->comboDDNSType->setEnabled(TRUE);
           m_ui->checkBoDDNS->setCheckState(Qt::Checked);
       }
       else
       {
           QMessageBox::information(this, tr("Device params error!"), tr("Device params error!"));
       }
   }
    return HPR_OK;
}
 
//set DDNS inforamtion
 int CAdvancedNetParams::setDDNSInfo()
 {
     NET_DVR_DDNSPARA_V30 DDNSParams;
     DWORD uiParamsLen;
     int iIntTemp;
     int iRet;
 
     //firstly, get the DDNS
    memset(&DDNSParams, 0, sizeof(NET_DVR_DDNSPARA_V30));
    iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_DDNSCFG_V30, m_lChannel, &DDNSParams, sizeof(NET_DVR_DDNSPARA_V30),  &uiParamsLen);
    if(iRet == 0)
     {
        KIT_DisplayErrorInfo("Get DDNS", KIT_ERRPR_DIS_TYPE);
         //QMessageBox::information(this, tr("Please check!"), tr(".Get NTP information unsuccessfully!"));
         return HPR_ERROR;
     }
 
    //secondly, set the DDNS
    if(m_ui->checkBoDDNS->isChecked())
    {
        if((m_ui->editDDNSPasswd->text()) != (m_ui->editDDNSpasswd2->text()))
        {
            QMessageBox::information(this, tr("Double DDNS passwd is not equal!"), tr("Please check!"));
            return HPR_ERROR;
         }
         DDNSParams.byEnableDDNS = 1;
         DDNSParams.byHostIndex = (m_ui->comboDDNSType->currentIndex());
         //Domain Name
         KIT_editToStr(m_ui->editDDNSDomainName,  DDNSParams.struDDNS[(int)DDNSParams.byHostIndex].sDomainName, MAX_DOMAIN_NAME);
         //Server Name
         KIT_editToStr(m_ui->editDDNSServerName,  DDNSParams.struDDNS[(int)DDNSParams.byHostIndex].sServerName, MAX_DOMAIN_NAME);
         //User Name
         KIT_editToStr(m_ui->editDDNSUserName,  DDNSParams.struDDNS[(int)DDNSParams.byHostIndex].sUsername, NAME_LEN);
         //Passward
         KIT_editToStr(m_ui->editDDNSPasswd,  DDNSParams.struDDNS[(int)DDNSParams.byHostIndex].sPassword, PASSWD_LEN);
 
         KIT_editToInt(m_ui->editDDNSPort, &iIntTemp);
         DDNSParams.struDDNS[(int)DDNSParams.byHostIndex].wDDNSPort = iIntTemp;
    }
    else
    {
        DDNSParams.byEnableDDNS = 0;
    }
 
    iRet = NET_DVR_SetDVRConfig(m_lUserID, NET_DVR_SET_DDNSCFG_V30, m_lChannel, &DDNSParams, sizeof(NET_DVR_DDNSPARA_V30));
    if(iRet == 0)
    {
        iRet = NET_DVR_GetLastError();
        QMessageBox::information(this, tr("Set DDNS fail!"), tr("Set DDNS fail. \"%1\"").arg(iRet));
        return HPR_ERROR;
    }
 
     return HPR_OK;
 }
 
//refresh params
void CAdvancedNetParams::refreshParams()
{
    if(m_lUserID < 0)
    {
        QMessageBox::information(this, tr("Please check."), tr("User ID is wrong!"));
        return;
    }
    getNTPInfo();
    getPPPoEInfo();
    getDDNSInfo();
    getEmailInfo();
    //delete m_ui->tabWEmail->takeItem(0,0);
}
 
void CAdvancedNetParams::on_btnExit_clicked()
{
    close();
}
 
//save params
void CAdvancedNetParams::saveParams()
{
    if(m_lUserID < 0)
    {
        QMessageBox::information(this, tr("Please check."), tr("User ID is wrong!"));
        return;
    }
    //set PPPoE
    setPPPoEInfo();
    //set NTP
    setNTPInfo();
    //set DDNS
    setDDNSInfo();
    //set Email
    setEmailInfo();
 
}
 
int CAdvancedNetParams::setPPPoEInfo()
{
    NET_DVR_NETCFG_V30 netParams;
    QString qstrTemp;
    DWORD paramsLen;
    int iRet;
 
    //get the params
    memset(&netParams, 0, sizeof(NET_DVR_NETCFG_V30));
    iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_NETCFG_V30, m_lChannel, &netParams, sizeof(NET_DVR_NETCFG_V30), &paramsLen);
 
    //set the parms
    if(m_ui->checkBoPPPoE->isChecked())
    {
        if((m_ui->editPPPoEPasswd->text()) != (m_ui->editPPPoEPass2->text()))
        {
            QMessageBox::information(this, tr("Double is net equal!"), tr("Please check!"));
            return HPR_ERROR;
        }
        netParams.struPPPoE.dwPPPOE = 1;
        //user name
        KIT_editToStr(m_ui->editPPPoEUserName, (BYTE *)(&(netParams.struPPPoE.sPPPoEUser)), NAME_LEN);
        //pass word
        KIT_editToStr(m_ui->editPPPoEPasswd, (BYTE *)&(netParams.struPPPoE.sPPPoEPassword), PASSWD_LEN);
        //PPPoE IP Addess
        //KIT_editToIP(m_ui->editPPPoEIP, (char *)&(netParams.struPPPoE.struPPPoEIP.sIpV4), 16);
    }
    else
    {
        netParams.struPPPoE.dwPPPOE = 0;
    }
 
    iRet = NET_DVR_SetDVRConfig(m_lUserID, NET_DVR_SET_NETCFG_V30, m_lChannel, &netParams, sizeof(NET_DVR_NETCFG_V30));
    if(iRet == 0)
    {
        iRet = NET_DVR_GetLastError();
        QMessageBox::information(this, tr("Set Net fail!"), tr("Set Net fail. \"%1\"").arg(iRet));
        return HPR_ERROR;
    }
 
    return HPR_OK;
}
 
//get the email information
int  CAdvancedNetParams::getEmailInfo()
{
    NET_DVR_EMAILCFG_V30 EmailParams;
    DWORD uiParamsLen;
    int iRet;
    char strTemp[100];
 
    memset(&EmailParams, 0, sizeof(NET_DVR_EMAILCFG_V30));
    iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_EMAILCFG_V30, m_lChannel, &EmailParams, sizeof(NET_DVR_EMAILCFG_V30),  &uiParamsLen);
    if(iRet == 0)
    {
        QMessageBox::information(this, tr("Please check!"), tr(".Get Email information unsuccessfully!"));
        return HPR_ERROR;
    }
 
    //user name
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%s", EmailParams.sAccount);
    m_ui->editEmailAccount->setText(QString(QLatin1String(strTemp)));
 
    //Email pass word
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%s", EmailParams.sPassword);
    m_ui->editEmailPasswd->setText(QString(QLatin1String(strTemp)));
 
    //Email sender name
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%s", EmailParams.struSender.sName);
    m_ui->editEmailSenderName->setText(QString(QLatin1String(strTemp)));
 
    //Email sender address
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%s", EmailParams.struSender.sAddress);
    m_ui->editEmailSenderAddr->setText(QString(QLatin1String(strTemp)));
 
    //smtp
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%s", EmailParams.sSmtpServer);
    m_ui->editEmailSMTP->setText(QString(QLatin1String(strTemp)));
 
    //pop3
    memset(strTemp, 0, 100);
    sprintf(strTemp, "%s", EmailParams.sPop3Server);
    m_ui->editEmailPop3->setText(QString(QLatin1String(strTemp)));
 
    //interval time
        if(/*EmailParams.byMailInterval >= 0 && */ EmailParams.byMailInterval <= 3)
    {
        m_ui->comboBoEmailInterval->setCurrentIndex((int)(EmailParams.byMailInterval));
    }
 
    //whether need to verify
    if(EmailParams.bySmtpServerVerify == 0)
    {
        m_ui->checkBoEmailsmtp->setCheckState(Qt::Unchecked);
    }
    else
    {
        m_ui->checkBoEmailsmtp->setCheckState(Qt::Checked);
    }
 
    if(EmailParams.byAttachment == 0)
    {
        m_ui->checkBoEmailAttach->setCheckState(Qt::Unchecked);
    }
    else
    {
        m_ui->checkBoEmailAttach->setCheckState(Qt::Checked);
    }
 
    //delete the table
    int i,j;
    for(i = 0;  i <3; i++ )
    {
        for(j=0; j<2; j++)
        {
            delete m_ui->tabWEmail->takeItem(0,0);
        }
        //m_ui->tabWEmail->removeRow(i);
    }
 
    //write data to the table widget
    for(i = 0;  i <3; i++ )
    {
                m_ui->tabWEmail->setItem(i, 0, new QTableWidgetItem((char *)EmailParams.struReceiver[i].sName));
                m_ui->tabWEmail->setItem(i, 1, new QTableWidgetItem((char *)EmailParams.struReceiver[i].sAddress));
    }
 
    //repait the table
    m_ui->tabWEmail->hide();
    m_ui->tabWEmail->show();
 
    return HPR_OK;
}
 
//set the email information
int  CAdvancedNetParams::setEmailInfo()
{
    NET_DVR_EMAILCFG_V30 EmailParams;
    DWORD uiParamsLen;
    int iRet;
 
    memset(&EmailParams, 0, sizeof(NET_DVR_EMAILCFG_V30));
    iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_EMAILCFG_V30, m_lChannel, &EmailParams, sizeof(NET_DVR_EMAILCFG_V30),  &uiParamsLen);
    if(iRet == 0)
    {
        QMessageBox::information(this, tr("Please check!"), tr(".Get Email information unsuccessfully!"));
        return HPR_ERROR;
    }
    if(m_ui->editEmailPasswd->text() != m_ui->editEmailPasswd2->text())
    {
        QMessageBox::information(this, tr("Double Email passwd is net equal!"), tr("Please check!"));
        return HPR_ERROR;
    }
    KIT_editToStr(m_ui->editEmailAccount, EmailParams.sAccount, NAME_LEN);
    KIT_editToStr(m_ui->editEmailPasswd, EmailParams.sPassword, MAX_EMAIL_PWD_LEN);
    KIT_editToStr(m_ui->editEmailSenderName, EmailParams.struSender.sName, NAME_LEN);
    KIT_editToStr(m_ui->editEmailSenderAddr, EmailParams.struSender.sAddress, MAX_EMAIL_ADDR_LEN);
 
    KIT_editToStr(m_ui->editEmailSMTP, EmailParams.sSmtpServer, MAX_EMAIL_ADDR_LEN);
    KIT_editToStr(m_ui->editEmailPop3, EmailParams.sPop3Server, MAX_EMAIL_ADDR_LEN);
 
    if(m_ui->checkBoEmailAttach->isChecked())
    {
        EmailParams.byAttachment = 1;
    }
    else
    {
        EmailParams.byAttachment = 0;
    }
 
    if(m_ui->checkBoEmailsmtp->isChecked())
    {
        EmailParams.bySmtpServerVerify =1;
    }
    else
    {
        EmailParams.bySmtpServerVerify = 0;
    }
 
    //interval time
    EmailParams.byMailInterval = m_ui->comboBoEmailInterval->currentIndex();
 
    //receiver
    QTableWidgetItem *pItemTemp;
    int i;
    for(i = 0;  i <3; i++ )
    {
        pItemTemp = m_ui->tabWEmail->item(i, 0);
        if(pItemTemp !=NULL)
        {
            //KIT_qstringToStr(&(pItemTemp->text()), EmailParams.struReceiver[i].sName, NAME_LEN);
        }
        else
        {
            memset(EmailParams.struReceiver[i].sName, 0, NAME_LEN);
        }
 
        pItemTemp = m_ui->tabWEmail->item(i, 1);
        if(pItemTemp !=NULL)
        {
            //KIT_qstringToStr(&(pItemTemp->text()), EmailParams.struReceiver[i].sAddress, MAX_EMAIL_ADDR_LEN);
        }
        else
        {
            memset(EmailParams.struReceiver[i].sAddress, 0, MAX_EMAIL_ADDR_LEN);
        }
   }
 
    iRet = NET_DVR_SetDVRConfig(m_lUserID, NET_DVR_SET_EMAILCFG_V30, m_lChannel, &EmailParams, sizeof(NET_DVR_EMAILCFG_V30));
    if(iRet == 0)
    {
           iRet = NET_DVR_GetLastError();
           QMessageBox::information(this, tr("Set Email fail!"), tr("Set Email fail. \"%1\"").arg(iRet));
           return HPR_ERROR;
    }
 
    return HPR_OK;
}
 
void CAdvancedNetParams::clickPPPoE()
{
    if(m_ui->checkBoPPPoE->isChecked())
    {
         m_ui->editPPPoEUserName->setEnabled(TRUE);
         m_ui->editPPPoEPasswd->setEnabled(TRUE);
         m_ui->editPPPoEIP->setEnabled(FALSE);
         m_ui->editPPPoEPass2->setEnabled(TRUE);
 
     }
     else
     {
         m_ui->editPPPoEUserName->setEnabled(FALSE);
         m_ui->editPPPoEPasswd->setEnabled(FALSE);
         m_ui->editPPPoEIP->setEnabled(FALSE);
         m_ui->editPPPoEPass2->setEnabled(FALSE);
      }
}
 
void CAdvancedNetParams::clickNTP()
{
    if(m_ui->checkBoNTP->isChecked())
    {
        m_ui->editNTPAddr->setEnabled(TRUE);
        m_ui->editNTPPort->setEnabled(TRUE);
        m_ui->editNTFInterval->setEnabled(TRUE);
        m_ui->editTimeDifH->setEnabled(TRUE);
        m_ui->editTimeDifM->setEnabled(TRUE);
    }
    else
    {
        m_ui->editNTPAddr->setEnabled(FALSE);
        m_ui->editNTPPort->setEnabled(FALSE);
        m_ui->editNTFInterval->setEnabled(FALSE);
        m_ui->editTimeDifH->setEnabled(FALSE);
        m_ui->editTimeDifM->setEnabled(FALSE);
    }
}
 
//whether choose DDNS
void CAdvancedNetParams::clickDDNS()
{
    if(m_ui->checkBoDDNS->isChecked())
    {
        m_ui->editDDNSDomainName->setEnabled(TRUE);
        m_ui->editDDNSServerName->setEnabled(TRUE);
        m_ui->editDDNSPasswd->setEnabled(TRUE);
        m_ui->editDDNSPort->setEnabled(TRUE);
        m_ui->editDDNSUserName->setEnabled(TRUE);
        m_ui->editDDNSpasswd2->setEnabled(TRUE);
        m_ui->comboDDNSType->setEnabled(TRUE);
 
    }
    else
    {
        m_ui->editDDNSDomainName->setEnabled(FALSE);
        m_ui->editDDNSServerName->setEnabled(FALSE);
        m_ui->editDDNSPasswd->setEnabled(FALSE);
        m_ui->editDDNSPort->setEnabled(FALSE);
        m_ui->editDDNSUserName->setEnabled(FALSE);
        m_ui->editDDNSpasswd2->setEnabled(FALSE);
        m_ui->comboDDNSType->setEnabled(FALSE);
    }
 
}
 
int CAdvancedNetParams::setUserIDAndChannel(long lUserID, long lChannel)
{
    m_lUserID = lUserID;
    m_lChannel = lChannel;
 
    return HPR_OK;
}