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
/************************************************************************
 *        Copyright 2009-2011 Hikvision Digital Technology Co., Ltd.
 *        FileName                      :   remoteupdate.cpp
 *        Description                   :   remote update 
 *        Modification History          :   none
 *        Version                       :   V1.0
 *        Time                          :   2009-11,12
 *        Author                        :   wanggongpu
 *        Descrp                        :   
*************************************************************************/
#include "remoteupdate.h"
#include <QString>
#include <QMessageBox>
#include <QFileDialog>
#include <QDir>
#include <QByteArray>
 
/************************************************************************
 *        Function            :  RemoteUpdate
 *        Description         :  instructor
 *        Input               :  none
 *        Output              :  none
 *        Return              :  none
*************************************************************************/
RemoteUpdate::RemoteUpdate(int* userid,  QWidget *parent)
    : QDialog(parent)
    , m_timer (NULL)
    , m_hUpgrade(-1)
{
    ui.setupUi(this);
    m_updateuserid = userid;
    ui.horizontalScrollBar->setRange(0, 100);
    setUpdatesEnabled ( TRUE );
    update();
    repaint();
    m_updatenetworktype =0;
}
 
/************************************************************************
 *        Function            :  ~RemoteUpdate
 *        Description         :  destructor
 *        Input               :  none
 *        Output              :  none
 *        Return              :  none
*************************************************************************/
RemoteUpdate::~RemoteUpdate()
{
 
}
 
/************************************************************************
 *        Function            :  on_comboBox_currentIndexChanged
 *        Description         :  set network environment
 *        Input               :  index 0 LAN 1 WAN
 *        Output              :  none
 *        Return              :  none
*************************************************************************/
void RemoteUpdate::on_comboBox_currentIndexChanged (int  index)
{
    m_updatenetworktype = index;
}
 
/************************************************************************
 *        Function            :  on_pushButton_setnetworktype_clicked
 *        Description         :  browse
 *        Input               :  none
 *        Output              :  none
 *        Return              :  none
*************************************************************************/
void RemoteUpdate::on_pushButton_setnetworktype_clicked()
{
    if (!NET_DVR_SetNetworkEnvironment(m_updatenetworktype))
    {
        QMessageBox::information(this, tr("setnetworktype failed"), 
            tr("errorno=%1").arg(NET_DVR_GetLastError()));
    }
    else
    {
        QMessageBox::information(this, tr("setnetworktype success"), 
            tr("setnetworktype success."));
    }
    return ;
}
 
/************************************************************************
 *        Function            :  on_pushButton_browse_clicked
 *        Description         :  browse
 *        Input               :  none
 *        Output              :  none
 *        Return              :  none
*************************************************************************/
void RemoteUpdate::on_pushButton_browse_clicked()
{
     QString directory = QFileDialog::getOpenFileName(this,\
           tr("Find Update Files DIR and Filename"), QDir::currentPath());
     if (!directory.isEmpty()) 
     {
         ui.lineEdit->insert(directory);
     }
     return;
}
 
 
void RemoteUpdate::OnTimer()
{
    int iProcess = 0;
 
    iProcess = NET_DVR_GetUpgradeProgress(m_hUpgrade);
    qDebug("update progress:[%d]", iProcess);
 
    ui.horizontalScrollBar->setValue(iProcess);
    //ui.pushButton_setnetworktype_2->setText(tr(tmp));
    if (iProcess >= 100)
    {
        QMessageBox::information(this, tr("Update success"), tr("NET_DVR_Upgrade"));
        if (NET_DVR_CloseUpgradeHandle(m_hUpgrade))
        {
            m_hUpgrade = -1;
        }
 
        if (m_timer)
        {
            m_timer->stop();
            delete m_timer;
            m_timer = NULL;
        }
    }
}
 
/************************************************************************
 *        Function            :  on_pushButton_update_clicked
 *        Description         :  update
 *        Input               :  none
 *        Output              :  none
 *        Return              :  none
*************************************************************************/
void RemoteUpdate::on_pushButton_update_clicked()
{
    int nRet = 2;
 
    m_updatefilepath  = ui.lineEdit->text();
    m_hUpgrade = NET_DVR_Upgrade(*m_updateuserid, m_updatefilepath.toLatin1().data());
    if (m_hUpgrade < 0)
    {
        QMessageBox::information(this, tr("Update failed"), \
            tr("\"%1\" is return value of     NET_DVR_Upgrade.").arg(m_hUpgrade));
        return;
    }
 
    startTimer( 0 );                            // run continuous timer
    m_timer = new QTimer( this );
    connect( m_timer, SIGNAL(timeout()), this, SLOT(OnTimer()));
    m_timer->start(1000);  //every 1 second
 
    return;
}
 
/************************************************************************
 *        Function            :  on_pushButton_cancel_clicked
 *        Description         :  cancel update 
 *        Input               :  none
 *        Output              :  none
 *        Return              :  none
*************************************************************************/
void RemoteUpdate::on_pushButton_cancel_clicked()
{
    if (m_hUpgrade >= 0)
    {
        int nRet = NET_DVR_CloseUpgradeHandle(m_hUpgrade);
        if (nRet == 1)
        {
            QMessageBox::information(this, tr("Update success"), tr("Update has success."));
        }
        else
        {
            QMessageBox::information(this, tr("Update failed"), \
                tr("\"%1\" is return value of     NET_DVR_GetUpgradeState.").arg(nRet));
        }
    }
    
    if (m_timer != NULL)
    {
        m_timer->stop();
        delete m_timer;
    }
    close();
    
}
 
/************************************************************************
 *        Function            :  on_lineEdit_textChanged
 *        Description         :  file path 
 *        Input               :  none
 *        Output              :  none
 *        Return              :  none
*************************************************************************/
void RemoteUpdate::on_lineEdit_textChanged()
{
    QString path = ui.lineEdit->text();
    m_updatefilepath = path;
    return ;
}