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
/*
 * Copyright(C) 2010,Hikvision Digital Technology Co., Ltd 
 * 
 * ÎļþÃû³Æ£ºcconfigureparams.cpp
 * Ãè    Êö£º
 * µ±Ç°°æ±¾£º1.0
 * ×÷    ÕߣºÅËÑǶ«
 * ´´½¨ÈÕÆÚ£º2010Äê2ÔÂ1ÈÕ
 * Ð޸ļǼ£º
 */
 
#include "cconfigureparams.h"
#include "ui_cconfigureparams.h"
#include <QPushButton>
#include <new>
#include "DemoPublic.h"
#include <stdio.h>
 
/*******************************************************************
      Function:   CConfigureParams::CConfigureParams
   Description:   ¹¹Ô캯Êý
     Parameter:   (IN)   QWidget *parent ¸¸´°¿Ú 
        Return:   0--³É¹¦£¬-1--ʧ°Ü¡£   
**********************************************************************/
CConfigureParams::CConfigureParams(QWidget *parent): QWidget(parent), ui(new Ui::CConfigureParams)
{
    ui->setupUi(this);
    m_lUserID = -1;
 
    m_pRemoteparams = NULL; 
    m_pIPParams = NULL;
    m_pCurrentWidget = NULL;
    m_pHardDiskParams = NULL;
 
   connect(ui->btnRemoteParams, SIGNAL(clicked()), this, SLOT(loadRemoteParams()));
   connect(ui->btnLogin, SIGNAL(clicked()), this, SLOT(GetDVRUserID()));
   connect(ui->btnLogout, SIGNAL(clicked()), qApp, SLOT(quit()));
 
   ui->btnLogin->hide();
   ui->btnLogout->hide();
   ui->btnLocalParams->hide();
}
 
/*******************************************************************
      Function:   CConfigureParams::~CConfigureParams
   Description:   Îö¹¹º¯Êý
     Parameter:   (IN)   ÎÞ²ÎÊý  
        Return:   ÎÞ
**********************************************************************/
CConfigureParams::~CConfigureParams()
{
    if(m_pRemoteparams != NULL)
    {
        delete m_pRemoteparams;
    }
    if(m_pIPParams != NULL)
    {
        delete m_pIPParams;
    }
    delete m_pHardDiskParams;   //ɾ³ýÓ²ÅÌÅäÖÃ
 
    delete ui;
}
 
/*******************************************************************
      Function:   CConfigureParams::loadRemoteParams
   Description:   load the remot params form!
     Parameter:   (IN)   ÎÞ²ÎÊý  
        Return:   0--³É¹¦£¬-1--ʧ°Ü¡£   
**********************************************************************/
void CConfigureParams::loadRemoteParams()
{
    if(NULL == m_pRemoteparams)
    {
        m_pRemoteparams = new(std::nothrow) CRemoteParams;
        if(NULL == m_pRemoteparams)
        {
            m_MessageBox.setText("addWidget error!");
            m_MessageBox.exec();
            return ;
        }
    }
 
    if(m_pCurrentWidget != NULL) //Òþ²Øµ±Ç°´°¿Ú
    {
        m_pCurrentWidget->hide();
    }
    m_pCurrentWidget = m_pRemoteparams;
    m_pRemoteparams->setUserID(m_lUserID);
    ui->vLayParamForm->addWidget(m_pCurrentWidget);
    m_pCurrentWidget->show();
}
 
/*******************************************************************
      Function:   CConfigureParams::on_btnIPParams_clicked
   Description:   ip½ÓÈëÅäÖÃ
     Parameter:   (IN)   ÎÞ²ÎÊý  
        Return:   0--³É¹¦£¬-1--ʧ°Ü¡£   
**********************************************************************/
void CConfigureParams::on_btnIPParams_clicked()
{
    if(NULL == m_pIPParams)
    {
        m_pIPParams = new(std::nothrow) CIPParams;
        if(NULL == m_pIPParams)
        {
            m_MessageBox.setText("addWidget error!");
            m_MessageBox.exec();
            return ;
        }
    }
    //Òþ²Øµ±Ç°´°¿Ú
    if(m_pCurrentWidget != NULL)
    {
        m_pCurrentWidget->hide();
    }
    m_pIPParams->setUserID(m_lUserID);
    m_pCurrentWidget = m_pIPParams;
    ui->vLayParamForm->addWidget(m_pCurrentWidget);
    m_pCurrentWidget->show();
}
 
/*******************************************************************
      Function:   CConfigureParams::on_btnHardDiskParams_clicked
   Description:   Ó²ÅÌÅäÖÃ
     Parameter:   (IN)   ÎÞ²ÎÊý  
        Return:   0--³É¹¦£¬-1--ʧ°Ü¡£   
**********************************************************************/
void CConfigureParams::on_btnHardDiskParams_clicked()
{
    if(NULL == m_pHardDiskParams)
    {
        m_pHardDiskParams = new(std::nothrow) CHardDiskParams;
        if(NULL == m_pHardDiskParams)
        {
            m_MessageBox.setText("addWidget error!");
            m_MessageBox.exec();
            return ;
        }
    }
    //Òþ²Øµ±Ç°´°¿Ú
    if(m_pCurrentWidget != NULL)
    {
        m_pCurrentWidget->hide();
    }
    m_pHardDiskParams->setUserID(m_lUserID);
    m_pCurrentWidget = m_pHardDiskParams;
    ui->vLayParamForm->addWidget(m_pCurrentWidget);
    m_pCurrentWidget->show();
}
 
/*******************************************************************
      Function:   CConfigureParams::GetDVRUserID
   Description:   Get the user ID.
     Parameter:   (IN)   ÎÞ²ÎÊý  
        Return:   ÎÞ   
**********************************************************************/
void CConfigureParams::GetDVRUserID()
{
    //1.m_lUserID =lUerID;
 
    //2.login the divice
    char *m_serverIP = "172.7.39.111";
    NET_DVR_DEVICEINFO m_devInfo;
    int iRet;
    int iError;
    iRet = NET_DVR_Init();
    iError = NET_DVR_GetLastError();
 
    m_lUserID = NET_DVR_Login(m_serverIP, 8000, "admin", "091103", &m_devInfo);
     if(m_lUserID < 0)
     {
         iError = NET_DVR_GetLastError();
        printf( "Login DVR failed ... LastError[%d]\n", NET_DVR_GetLastError());
        QMessageBox::information(this, tr("Login failed"), tr("\"%1\" is return value of net_dvr_login.").arg(m_lUserID));
        NET_DVR_Cleanup();
        return ;
     }
     else
     {
         ui->btnLogin->setEnabled(FALSE);
     }
 
}
 
/*******************************************************************
      Function:   CConfigureParams::SetDVRUserID
   Description:   Set User ID to this class.
     Parameter:   (IN)   long lUserID  
        Return:   none   
**********************************************************************/
void CConfigureParams::SetDVRUserID(long lUserID)
{
    if(lUserID >= 0)
    {
        m_lUserID = lUserID;
    }
}
 
/*******************************************************************
      Function:   CConfigureParams::showEvent
   Description:   show event
     Parameter:   (IN)   QShowEvent * event  
        Return:   bone   
**********************************************************************/
void CConfigureParams::showEvent ( QShowEvent * event )
{
    if(m_lUserID < 0)
    {
        return;
    }
 
    //QMessageBox::information(this, tr("Login failed"), tr(" is return value of net_dvr_login."));
    if(NULL != m_pRemoteparams)
    {
        m_pRemoteparams->setUserID(m_lUserID);
    }
 
    if(NULL != m_pIPParams)
    {
        m_pIPParams->setUserID(m_lUserID);
    }
 
    if(NULL != m_pHardDiskParams)
    {
        m_pHardDiskParams->setUserID(m_lUserID);
    }
}
 
/*******************************************************************
      Function:   CConfigureParams::showLoginBtn
   Description:   Show buttons.
     Parameter:   (IN)   ÎÞ²ÎÊý  
        Return:   none   
**********************************************************************/
void CConfigureParams::showLoginBtn()
{
    ui->btnLogin->show();
    ui->btnLogout->show();
}