You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
329 lines
11 KiB
C++
329 lines
11 KiB
C++
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
/*
|
|
* File: dialog_filetran.cpp
|
|
* Author: shjd
|
|
*
|
|
* Created on 2018年1月10日, 上午10:32
|
|
*/
|
|
|
|
#include "dialog_filetran.h"
|
|
#include "gui_srv.h"
|
|
#include <QMessageBox>
|
|
|
|
|
|
extern gui_srv * w;
|
|
dialog_filetran *dlg_filetran;
|
|
|
|
|
|
typedef ST_INT(*ac_get_srvm_num_type)();
|
|
typedef ST_CHAR* (*ac_get_srvm_name_type)(ST_INT);
|
|
typedef AI_IED_CTRL * (*ac_get_srvm_ied_type)(ST_INT);
|
|
typedef ST_RET (*ac_get_file_attr_type)(ST_INT srv_id, AC_GETFAV_REQ_INFO *getfav_info, ST_INT time_out, AC_REQ_CTRL **req_ctrl_out);
|
|
typedef ST_RET (*ac_delete_file_type)(ST_INT srv_id, AC_DELF_REQ_INFO *delf_info, ST_INT time_out, AC_REQ_CTRL **req_ctrl_out);
|
|
typedef ST_RET (*ac_get_file_type)(ST_INT srv_id, AC_GETF_REQ_INFO *getf_info,ST_INT time_out, AC_REQ_CTRL **req_ctrl_out);
|
|
typedef ST_RET (*ac_set_file_type)(ST_INT srv_id, AC_SETF_REQ_INFO *setf_info,ST_INT time_out, AC_REQ_CTRL **req_ctrl_out);
|
|
typedef ST_VOID(*ac_destroy_reqCtrl_type)(AC_REQ_CTRL *reqCtrl);
|
|
typedef ST_RET (*UtcValsToString_type) (char *dest, ST_UINT32 secs, ST_UINT32 fraction,ST_UINT32 qflags);
|
|
|
|
extern ac_get_srvm_num_type ac_get_srvm_num_ad;
|
|
extern ac_get_srvm_name_type ac_get_srvm_name_ad;
|
|
extern ac_get_srvm_ied_type ac_get_srvm_ied_ad;
|
|
extern ac_get_file_attr_type ac_get_file_attr_ad;
|
|
extern ac_destroy_reqCtrl_type ac_destroy_reqCtrl_ad;
|
|
extern UtcValsToString_type UtcValsToString_ad;
|
|
extern ac_delete_file_type ac_delete_file_ad;
|
|
extern ac_get_file_type ac_get_file_ad;
|
|
extern ac_set_file_type ac_set_file_ad;
|
|
|
|
dialog_filetran::dialog_filetran() {
|
|
widget.setupUi(this);
|
|
tbmodel = new QStandardItemModel;
|
|
widget.tV_file->setModel(tbmodel);
|
|
QStandardItem *tbitem1 = new QStandardItem(tr("文件名"));
|
|
QStandardItem *tbitem2 = new QStandardItem(tr("大小(K)"));
|
|
QStandardItem *tbitem3 = new QStandardItem(tr("修改日期"));
|
|
tbmodel-> setHorizontalHeaderItem(0, tbitem1);
|
|
tbmodel-> setHorizontalHeaderItem(1, tbitem2);
|
|
tbmodel-> setHorizontalHeaderItem(2, tbitem3);
|
|
widget.tV_file->setColumnWidth(0,350);
|
|
widget.tV_file->setColumnWidth(1,100);
|
|
widget.tV_file->setColumnWidth(2,200);
|
|
//widget.tV_file->verticalHeader()->setVisible(false); //设置行表头不显示
|
|
widget.tV_file->setEditTriggers(QAbstractItemView::NoEditTriggers); //设置表格只读属性
|
|
ST_INT i;
|
|
int srvnum = ac_get_srvm_num_ad();
|
|
ST_CHAR *pstr = NULL;
|
|
for (i=0;i<srvnum;i++)
|
|
{
|
|
pstr = ac_get_srvm_name_ad(i);
|
|
widget.cB_server->insertItem(i,pstr,i);
|
|
}
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CDlgFileTrans message handlers
|
|
void dialog_filetran::OnGetFileListParse(AC_GETFAV_REQ_CTRL *getfav)
|
|
{
|
|
int i;
|
|
tbmodel->clear();
|
|
for (i =0; i<getfav->file_num; i++)
|
|
{
|
|
//qDebug()<< QString::fromLatin1(getfav->file_attrs[1].file_name);
|
|
tbmodel->setItem(i,0,new QStandardItem(getfav->file_attrs[i].file_name));
|
|
tbmodel->setItem(i,1,new QStandardItem(QString::number(getfav->file_attrs[i].file_size)));
|
|
tbmodel->setItem(i,2,new QStandardItem(QDateTime::fromTime_t(getfav->file_attrs[i].last_modified.secs).toString("yyyy-MM-dd hh:mm:ss")));
|
|
}
|
|
}
|
|
|
|
|
|
static ST_VOID _delete_handle(AC_REQ_CTRL * req_ctrl)
|
|
{
|
|
if (req_ctrl->result==SD_SUCCESS)
|
|
{
|
|
dlg_filetran->OnFreshfiledirectory();
|
|
w->out_put("删除文件成功!!!");
|
|
}
|
|
else
|
|
w->out_put("删除文件失败!!!");
|
|
}
|
|
|
|
|
|
|
|
static ST_VOID _get_handle(AC_REQ_CTRL * req_ctrl)
|
|
{
|
|
if (req_ctrl->result==SD_SUCCESS)
|
|
{
|
|
w->out_put("文件上载成功!!!");
|
|
}
|
|
else
|
|
w->out_put("文件上载失败!!!");
|
|
}
|
|
|
|
|
|
|
|
static ST_VOID _set_handle(AC_REQ_CTRL *req_ctrl)
|
|
{
|
|
if (req_ctrl->result==SD_SUCCESS)
|
|
{
|
|
dlg_filetran->OnFreshfiledirectory();
|
|
w->out_put("下装文件成功!!!");
|
|
}
|
|
else
|
|
w->out_put("下装文件失败!!!");
|
|
}
|
|
|
|
void dialog_filetran::OnFreshfiledirectory()
|
|
{
|
|
on_pB_getfilelist_clicked();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static ST_VOID _getf_handle(AC_REQ_CTRL * req_ctrl)
|
|
{
|
|
|
|
|
|
if (req_ctrl->result==SD_SUCCESS)
|
|
{
|
|
dlg_filetran->OnGetFileListParse(&req_ctrl->u.getfavCtrl);
|
|
w->out_put("获取文件列表成功!!!");
|
|
|
|
}
|
|
else
|
|
{
|
|
w->out_put("获取文件列表失败!!!");
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
/* 删除文件 */
|
|
|
|
/************************************************************************/
|
|
void dialog_filetran::on_pB_filedel_clicked() {
|
|
AC_DELF_REQ_INFO * del_info =(AC_DELF_REQ_INFO *)malloc(sizeof(AC_DELF_REQ_INFO));
|
|
AC_REQ_CTRL *req_ctrl = NULL;
|
|
ST_INT timeout = 30;
|
|
ST_RET ret = SD_FAILURE;
|
|
ST_CHAR fname[MAX_FILE_NAME_LENGTH + 1] = {0};
|
|
ST_INT len;
|
|
ST_INT srv_id = -1;
|
|
srv_id = widget.cB_server->currentIndex();
|
|
int row = widget.tV_file->currentIndex().row();
|
|
if (row < 0) {
|
|
QMessageBox::warning(NULL, "warning", "未选择要删除的文件,请选择要删除的文件!", QMessageBox::Yes);
|
|
return;
|
|
}
|
|
QString strname = tbmodel->data(tbmodel->index(row, 0)).toString(); //第n行第1列的内容
|
|
len = strname.length();
|
|
if (len < 1)
|
|
{
|
|
QMessageBox::warning(NULL, "错误", "要删除的文件名称为空!", QMessageBox::Yes);
|
|
return;
|
|
}
|
|
strcpy(fname,strname.toLatin1().data());
|
|
del_info->file_name = fname;
|
|
del_info->u_getf_done = _delete_handle;
|
|
ret = ac_delete_file_ad(srv_id, del_info, timeout, &req_ctrl);
|
|
if (ret == SD_FAILURE)
|
|
{
|
|
QMessageBox::warning(NULL, "warning", "删除文件失败!", QMessageBox::Yes);
|
|
}
|
|
|
|
}
|
|
|
|
////////
|
|
///文件上载
|
|
/////
|
|
void dialog_filetran::on_pB_fileupload_clicked()
|
|
{
|
|
AC_GETF_REQ_INFO *getf_info=(AC_GETF_REQ_INFO *)malloc(sizeof(AC_GETF_REQ_INFO));
|
|
AC_REQ_CTRL *req_ctrl = NULL;
|
|
ST_INT timeout = 300; /*默认300秒*/
|
|
ST_RET ret = SD_FAILURE;
|
|
ST_CHAR fname[MAX_FILE_NAME_LENGTH+1] = {0};
|
|
ST_CHAR fname2[MAX_FILE_NAME_LENGTH+1] = {0};
|
|
FILE *filep = NULL;
|
|
ST_INT len;
|
|
ST_CHAR srv_name[MAX_FILE_NAME_LENGTH + 1] = {0};
|
|
ST_CHAR *chr;
|
|
ST_INT srv_id;
|
|
ST_CHAR src_name[MAX_FILE_NAME_LENGTH + 1] = {0};
|
|
ST_CHAR dest_name[MAX_FILE_NAME_LENGTH + 1] = {0};
|
|
ST_CHAR *filename=NULL ;
|
|
srv_id = widget.cB_server->currentIndex();
|
|
int row = widget.tV_file->currentIndex().row();
|
|
if (row < 0) {
|
|
QMessageBox::warning(NULL, "上载文件", "未选择要上载的文件,请选择要上载的文件!", QMessageBox::Yes);
|
|
return;
|
|
}
|
|
QString strname = tbmodel->data(tbmodel->index(row, 0)).toString(); //第n行第1列的内容
|
|
len = strname.length();
|
|
if (len < 1)
|
|
{
|
|
QMessageBox::warning(NULL, "上载文件", "要上载的文件名称为空!", QMessageBox::Yes);
|
|
return;
|
|
}
|
|
strcpy(fname,strname.toLatin1().data());
|
|
strcpy(fname2, fname);
|
|
chr = strchr(fname2, '/');
|
|
if (chr)
|
|
{
|
|
*chr = '_';
|
|
}
|
|
strcpy(src_name, fname2);
|
|
strcpy(dest_name, fname2);
|
|
getf_info->src_fname = src_name;
|
|
getf_info->dest_fname = dest_name;
|
|
filename=strrchr(getf_info->dest_fname,'/');
|
|
if (filename)
|
|
{
|
|
getf_info->dest_fname=filename+1;
|
|
}
|
|
getf_info->u_getf_done=_get_handle;
|
|
ret= ac_get_file_ad(srv_id,getf_info,timeout,&req_ctrl);
|
|
if (ret == SD_FAILURE)
|
|
{
|
|
QMessageBox::warning(NULL, "上载文件", "上载文件失败!", QMessageBox::Yes);
|
|
}
|
|
else
|
|
{
|
|
QMessageBox::warning(NULL, "上载文件", "上载文件成功!", QMessageBox::Yes);
|
|
}
|
|
}
|
|
|
|
/************************************************************************/
|
|
/* 获得文件列表 */
|
|
/************************************************************************/
|
|
void dialog_filetran::on_pB_getfilelist_clicked()
|
|
{
|
|
AC_GETFAV_REQ_INFO getfav_info;
|
|
AC_REQ_CTRL *req_ctrl = NULL;
|
|
ST_INT timeout = 30;
|
|
ST_RET ret = SD_FAILURE;
|
|
ST_INT srv_id ;
|
|
ST_CHAR file_name[MAX_FILE_NAME_LENGTH + 1] = {0};
|
|
srv_id = widget.cB_server->currentIndex();
|
|
strcpy(file_name, widget.lE_path->text().toLatin1().data());
|
|
getfav_info.file_name = file_name;
|
|
getfav_info.u_getf_done=_getf_handle;
|
|
ret=ac_get_file_attr_ad(srv_id,&getfav_info,timeout,&req_ctrl);
|
|
if (ret == SD_FAILURE)
|
|
{
|
|
QMessageBox::warning(NULL, "warning", "获取文件列表失败!", QMessageBox::Yes);
|
|
}
|
|
}
|
|
|
|
///************************************************************************/
|
|
///* 文件选择路径 */
|
|
///************************************************************************/
|
|
void dialog_filetran::on_pB_filebrowser_clicked()
|
|
{
|
|
QString file_name = QFileDialog::getOpenFileName(this,
|
|
tr("Open File"),
|
|
"",
|
|
"",
|
|
0);
|
|
if (!file_name.isNull())
|
|
{
|
|
widget.lE_downfilename->setText(file_name);
|
|
widget.lE_filename->setText(file_name.mid(file_name.lastIndexOf("/")+1));
|
|
}
|
|
}
|
|
|
|
///************************************************************************/
|
|
///* 文件下装 */
|
|
///************************************************************************/
|
|
void dialog_filetran::on_pB_filedown_clicked()
|
|
{
|
|
|
|
AC_SETF_REQ_INFO *set_info=(AC_SETF_REQ_INFO *)malloc(sizeof(AC_SETF_REQ_INFO));
|
|
FILE *flocal = NULL;
|
|
ST_UINT32 max_read_file = 0;
|
|
AC_REQ_CTRL *req_ctrl = NULL;
|
|
ST_INT timeout = 300;
|
|
ST_RET ret = SD_FAILURE;
|
|
ST_CHAR srv_name[MAX_FILE_NAME_LENGTH + 1] = {0};
|
|
ST_INT srv_id;
|
|
ST_CHAR src_fname[MAX_FILE_NAME_LENGTH + 1] = {0};
|
|
ST_CHAR dest_fname[MAX_FILE_NAME_LENGTH + 1] = {0};
|
|
srv_id = widget.cB_server->currentIndex();
|
|
if ((widget.lE_downfilename->text().length()<=0) || (widget.lE_filename->text().length() <= 0))
|
|
{
|
|
return;
|
|
}
|
|
strcpy(src_fname, widget.lE_downfilename->text().toLatin1().data());
|
|
strcpy(dest_fname, widget.lE_filename->text().toLatin1().data());
|
|
set_info->dest_fname = dest_fname;
|
|
set_info->src_fname = src_fname;
|
|
set_info->u_setf_done=_set_handle;
|
|
ret=ac_set_file_ad(srv_id,set_info,timeout,&req_ctrl);
|
|
if (ret == SD_FAILURE)
|
|
{
|
|
QMessageBox::warning(NULL, "下装文件", "下装文件失败!", QMessageBox::Yes);
|
|
}
|
|
else
|
|
{
|
|
QMessageBox::warning(NULL, "下装文件", "下装文件成功!", QMessageBox::Yes);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
dialog_filetran::~dialog_filetran() {
|
|
}
|