|
@@ -3,6 +3,8 @@
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
+#include <QFileDialog>
|
|
|
+
|
|
|
#include <QDateTime>
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
@@ -15,10 +17,13 @@ MainWindow::MainWindow(QWidget *parent)
|
|
|
mpdbclient->start();
|
|
|
connect(mpdbclient,SIGNAL(reqres(int)),this,SLOT(onreqres(int)));
|
|
|
connect(mpdbclient,SIGNAL(datareqres(int)),this,SLOT(ondatareqres(int)));
|
|
|
+ connect(mpdbclient,SIGNAL(filereqres(int)),this,SLOT(onfilereqres(int)));
|
|
|
|
|
|
mpitemmodel = new QStandardItemModel(this);
|
|
|
|
|
|
ui->listView->setModel(mpitemmodel);
|
|
|
+ ui->progressBar->setVisible(false);
|
|
|
+ ui->progressBar->setRange(0,100);
|
|
|
|
|
|
setWindowTitle("Query grpcdb");
|
|
|
}
|
|
@@ -166,6 +171,8 @@ void MainWindow::on_pushButton_DownLoad_clicked()
|
|
|
|
|
|
mpdbclient->requestfilename(nrecordid,strvehid);
|
|
|
|
|
|
+ ui->pushButton_DownLoad->setEnabled(false);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
void MainWindow::ondatareqres(int nres)
|
|
@@ -180,5 +187,110 @@ void MainWindow::ondatareqres(int nres)
|
|
|
|
|
|
mpdbclient->getdatareply(xdatareply);
|
|
|
|
|
|
+ mstrfilename = xdatareply.strfilename();
|
|
|
+
|
|
|
qDebug("file name is %s, size is %d",xdatareply.strfilename().data(),xdatareply.nfilesize());
|
|
|
+
|
|
|
+ QString str = QFileDialog::getSaveFileName(this,"Save ivd",".","*.ivd");
|
|
|
+
|
|
|
+ if(str.isEmpty())
|
|
|
+ {
|
|
|
+ mpdbclient->requestfiledata(mstrfilename,-1,0);
|
|
|
+ ui->pushButton_DownLoad->setEnabled(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(str.indexOf(".ivd")<0)str = str + ".ivd";
|
|
|
+
|
|
|
+ mFileIVD.setFileName(str);
|
|
|
+
|
|
|
+ if(!mFileIVD.open(QIODevice::ReadWrite))
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,"Warning","Can't Save IVD File.",QMessageBox::YesAll);
|
|
|
+ mpdbclient->requestfiledata(mstrfilename,-1,0);
|
|
|
+ ui->pushButton_DownLoad->setEnabled(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ mbFileIVD = true;
|
|
|
+
|
|
|
+ mnFilePos = 0;
|
|
|
+
|
|
|
+ ui->progressBar->setVisible(true);
|
|
|
+ ui->progressBar->setValue(0);
|
|
|
+
|
|
|
+ qint64 npos = 0;
|
|
|
+ qint64 nsize = 5000000;
|
|
|
+ if((npos + nsize)>((qint64)xdatareply.nfilesize()))
|
|
|
+ {
|
|
|
+ nsize = ((qint64)xdatareply.nfilesize()) - npos;
|
|
|
+ }
|
|
|
+
|
|
|
+ mpdbclient->requestfiledata(mstrfilename,(int)npos,(int)nsize);
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::onfilereqres(int nres)
|
|
|
+{
|
|
|
+ if(nres == -1)
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,"Warning","Download File Fail.",QMessageBox::YesAll);
|
|
|
+ ui->pushButton_DownLoad->setEnabled(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ iv::db::FiledbReply xfilereply;
|
|
|
+
|
|
|
+ mpdbclient->getfilereply(xfilereply);
|
|
|
+
|
|
|
+ if(xfilereply.nfilesize() == 0)
|
|
|
+ {
|
|
|
+ ui->progressBar->setVisible(false);
|
|
|
+ ui->pushButton_DownLoad->setEnabled(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(xfilereply.nfilesize() > 0)
|
|
|
+ {
|
|
|
+ qint64 nProg = ((mnFilePos + xfilereply.nsize())*100/xfilereply.nfilesize());
|
|
|
+ ui->progressBar->setValue(nProg);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(xfilereply.nsize()>0)
|
|
|
+ {
|
|
|
+ if(mbFileIVD)
|
|
|
+ {
|
|
|
+ mFileIVD.write(xfilereply.xdata().data(),xfilereply.xdata().size());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if((mnFilePos + xfilereply.nsize())>= xfilereply.nfilesize())
|
|
|
+ {
|
|
|
+ QMessageBox::information(this,"Info","SuccessFully DownLoad File.",QMessageBox::YesAll);
|
|
|
+ ui->progressBar->setVisible(false);
|
|
|
+ ui->pushButton_DownLoad->setEnabled(true);
|
|
|
+
|
|
|
+ if(mbFileIVD)
|
|
|
+ {
|
|
|
+ mFileIVD.close();
|
|
|
+ mbFileIVD = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ mpdbclient->requestfiledata(mstrfilename,-1,0);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ mnFilePos = mnFilePos + xfilereply.nsize();
|
|
|
+ qint64 npos = mnFilePos ;
|
|
|
+ qint64 nsize = 5000000;
|
|
|
+ if((npos + nsize)>((qint64)xfilereply.nfilesize()))
|
|
|
+ {
|
|
|
+ nsize = ((qint64)xfilereply.nfilesize()) - npos;
|
|
|
+ }
|
|
|
+
|
|
|
+ mpdbclient->requestfiledata(mstrfilename,(int)npos,(int)nsize);
|
|
|
+
|
|
|
+ }
|
|
|
}
|