Commit 7a3fdac0e0161dffd5a95799e8f262a6f956b947

Authored by 고영탁
1 parent 7dd7d47be4
Exists in master and in 2 other branches fhd, fhd-demo

설정 프로그램 다운로드 기능 개발

- 설정 프로그램 다운로드 기능 개발 완료
app/gui/oven_control/fileprocessdlg.cpp
... ... @@ -14,6 +14,185 @@
14 14 #define ERROR_LOG_FILE_TOTAL "/TotalError.csv"
15 15 #define SERVICE_DATA_FILE "/ServiceData.csv"
16 16  
  17 +
  18 +ProgramCopyWorker::ProgramCopyWorker(){
  19 + m_bStop = false;
  20 +}
  21 +
  22 +
  23 +ProgramCopyWorker::ProgramCopyWorker(QString strDest){
  24 + m_strDestDir = strDest;
  25 +}
  26 +
  27 +void ProgramCopyWorker::setDestPath(QString strDest){
  28 + m_strDestDir = strDest;
  29 +}
  30 +
  31 +void ProgramCopyWorker::workerMain(){
  32 + quint64 nTotalFileSize=0;
  33 + quint64 nCpyFileSize=0;
  34 + uint16_t nCurProgress=0;
  35 + int nRemainSec = 0;
  36 + QStringList strdirlist;
  37 + QStringList strFilelist;
  38 + QString srcFilepath;
  39 + QString destFilePath;
  40 +
  41 + int i;
  42 +
  43 + //make destination folder
  44 + QDir destdir(m_strDestDir);
  45 + if(!destdir.isRoot() && destdir.exists()==false){
  46 + destdir.mkpath(m_strDestDir);
  47 + }
  48 + qDebug() << "Target Path is " << m_strDestDir;
  49 +
  50 +
  51 + foreach(QString filepath, m_arrSrcFileList){
  52 + QFileInfo finfo(filepath);
  53 + nTotalFileSize+= finfo.size();
  54 + }
  55 +
  56 + foreach(QString srcpath, m_arrSrcDirList){
  57 + nTotalFileSize += FileProcessor::getDirSize(srcpath);
  58 + }
  59 + qDebug()<<"Total Size : " << nTotalFileSize;
  60 +
  61 + foreach(QString filepath, m_arrSrcFileList){
  62 + QFileInfo finfo(filepath);
  63 + srcFilepath = filepath;
  64 + destFilePath = QString("%1/%2").arg(m_strDestDir).arg(finfo.fileName());
  65 + if(QFile::exists(destFilePath)){
  66 + QFile::rename(destFilePath, QString("%1.bak").arg(destFilePath));
  67 + }
  68 + QFile::copy(srcFilepath,destFilePath);
  69 + nCpyFileSize += finfo.size();
  70 + nCurProgress = (nCpyFileSize *100) / nTotalFileSize;
  71 + nRemainSec = (nTotalFileSize-nCpyFileSize)/200000;
  72 + emit progressed(nCurProgress,nRemainSec);
  73 + if(QThread::currentThread()->isInterruptionRequested()){
  74 + sync();
  75 + emit finished();
  76 + QThread::currentThread()->quit();
  77 + break;
  78 + }
  79 + QThread::currentThread()->msleep(10);
  80 + }
  81 +
  82 + if(QThread::currentThread()->isInterruptionRequested() == false){
  83 + foreach(QString srcpath, m_arrSrcDirList){
  84 + qDebug() << "src dir : " << srcpath;
  85 +
  86 + QDir srcdir(srcpath);
  87 + strdirlist.append(srcpath);
  88 + FileProcessor::getAllDirList(srcdir, strdirlist);
  89 + qDebug() << "dir size : " <<strdirlist.size();
  90 +
  91 + QString targetpath =QString("%1%2").arg(m_strDestDir).arg(srcpath.mid(srcpath.lastIndexOf('/')));
  92 + qDebug() << "target dir : " << targetpath;
  93 +
  94 + QDir destDir(targetpath);
  95 + if(destDir.exists()) {
  96 + qDebug() << "remove target path";
  97 + QDir().rename(targetpath, QString("%1_").arg(targetpath));
  98 + }
  99 +
  100 + foreach(QString strDir, strdirlist){
  101 + QDir srcItem(strDir);
  102 + srcItem.mkpath( QString(strDir).replace(srcpath,targetpath));
  103 + qDebug() << "make path : " << QString(strDir).replace(srcpath,targetpath);
  104 + strFilelist = srcItem.entryList(QDir::NoDotAndDotDot | QDir::Files );
  105 + foreach(QString filename, strFilelist){
  106 + srcFilepath = QString("%1/%2").arg(strDir).arg(filename);
  107 + destFilePath = QString("%1/%2").arg(QString(strDir).replace(srcpath,targetpath)).arg(filename);
  108 + QFile::copy(srcFilepath, destFilePath);
  109 + qDebug() << srcFilepath << destFilePath;
  110 + QFileInfo finfo(srcFilepath);
  111 + nCpyFileSize += finfo.size();
  112 + nCurProgress = (nCpyFileSize *100) / nTotalFileSize;
  113 + nRemainSec = (nTotalFileSize-nCpyFileSize)/200000;
  114 + emit progressed(nCurProgress,nRemainSec);
  115 + if(QThread::currentThread()->isInterruptionRequested()){
  116 + sync();
  117 + emit finished();
  118 + break;
  119 + }
  120 + QThread::currentThread()->msleep(100);
  121 + }
  122 + if(QThread::currentThread()->isInterruptionRequested()) break;
  123 + }
  124 + strdirlist.clear();
  125 + if(QThread::currentThread()->isInterruptionRequested()) break;
  126 + }
  127 + }
  128 +
  129 + if(QThread::currentThread()->isInterruptionRequested()){
  130 + foreach(QString filepath, m_arrSrcFileList){
  131 + QFileInfo finfo(filepath);
  132 + srcFilepath = filepath;
  133 + destFilePath = QString("%1/%2").arg(m_strDestDir).arg(finfo.fileName());
  134 + if(QFile::exists( QString("%1.bak").arg(destFilePath))){
  135 + QFile::remove(destFilePath);
  136 + QFile::rename(QString("%1.bak").arg(destFilePath), destFilePath);
  137 + nCpyFileSize -= finfo.size();
  138 + nCurProgress = (nCpyFileSize *100) / nTotalFileSize;
  139 + emit progressed(nCurProgress, nRemainSec);
  140 + }
  141 + QThread::currentThread()->msleep(1);
  142 + }
  143 + foreach(QString srcpath, m_arrSrcDirList){
  144 + qDebug() << "src dir : " << srcpath;
  145 +
  146 + QDir srcdir(srcpath);
  147 + QString targetpath =QString("%1%2").arg(m_strDestDir).arg(srcpath.mid(srcpath.lastIndexOf('/')));
  148 + qDebug() << "target dir : " << targetpath;
  149 +
  150 + QDir destDir(targetpath);
  151 + QDir renameDir(QString("%1_").arg(targetpath));
  152 + if(renameDir.exists()) {
  153 + qDebug() << "remove target path";
  154 + destDir.removeRecursively();
  155 + QDir().rename(QString("%1_").arg(targetpath), targetpath);
  156 + }
  157 + emit progressed(0, 0);
  158 + }
  159 + }
  160 + else{
  161 + foreach(QString srcpath, m_arrSrcDirList){
  162 + qDebug() << "src dir : " << srcpath;
  163 +
  164 + QDir srcdir(srcpath);
  165 +
  166 + QString targetpath =QString("%1%2").arg(m_strDestDir).arg(srcpath.mid(srcpath.lastIndexOf('/')));
  167 + qDebug() << "target dir : " << targetpath;
  168 +
  169 + QDir destDir(targetpath);
  170 + QDir renameDir(QString("%1_").arg(targetpath));
  171 + if(renameDir.exists()) {
  172 + renameDir.removeRecursively();
  173 + }
  174 + emit progressed(0, 0);
  175 + }
  176 + }
  177 + sync();
  178 + emit finished();
  179 +}
  180 +
  181 +void ProgramCopyWorker::addSrcDir(QString strDirPath){
  182 + m_arrSrcDirList.append(strDirPath);
  183 +}
  184 +
  185 +void ProgramCopyWorker::addSrcFile(QString strfilename){
  186 + m_arrSrcFileList.append(strfilename);
  187 +}
  188 +
  189 +void ProgramCopyWorker::workerStop(){
  190 + //QMutexLocker locker(&m_mutex);
  191 + // qDebug() << "stop thread";
  192 + m_bStop = true;
  193 +}
  194 +
  195 +
17 196 FileProcessDlg::FileProcessDlg(QWidget *parent, ConfigType type, bool isDown) :
18 197 QDialog(parent),
19 198 ui(new Ui::FileProcessDlg)
... ... @@ -64,7 +243,10 @@ FileProcessDlg::~FileProcessDlg()
64 243  
65 244 void FileProcessDlg::on_ctrBtnCancel_clicked()
66 245 {
67   - close();
  246 +
  247 + //emit stopcopy();
  248 + programCopyThd.requestInterruption();
  249 + //close();
68 250 }
69 251  
70 252 void FileProcessDlg::saveHistoryLineData(QTextStream &out, uint16_t i, uint16_t fired_cnt, time_t first_fired, time_t last_fried){
... ... @@ -115,6 +297,8 @@ void FileProcessDlg::saveHistoryTotalData(QTextStream &amp;out){
115 297  
116 298 }
117 299  
  300 +
  301 +
118 302 void FileProcessDlg::infodataDownload(){
119 303 QString strUsbPath;
120 304 QString strFile;
... ... @@ -346,7 +530,49 @@ void FileProcessDlg::servicedataDownload(){
346 530 }
347 531  
348 532 void FileProcessDlg::programDownload(){
  533 + QString strDescPath;
  534 + QString strSrcPath;
  535 +
  536 + if(FileProcessor::detectUSB(strDescPath)){
  537 + worker.setDestPath(QString("%1").arg(strDescPath));
  538 + worker.addSrcDir("/prime/cookbook");
  539 + worker.moveToThread(&programCopyThd);
  540 +
  541 + connect(&programCopyThd,SIGNAL(started()), &worker, SLOT(workerMain()));
  542 + connect(&worker, SIGNAL(progressed(int,int)), this, SLOT(onProgressed(int,int)));
  543 + connect(this, SIGNAL(stopcopy()), &worker, SLOT(workerStop()));
  544 + connect(&worker, SIGNAL(finished()), &programCopyThd,SLOT(quit()));
  545 + connect(&programCopyThd, SIGNAL(finished()), this, SLOT(onProgressFinished()));
  546 + //connect(ui->ctrBtnCancel, SIGNAL(clicked(bool)), &worker, SLOT(workerStop()));
  547 +
  548 + programCopyThd.start();
  549 + qDebug() << "thread start";
  550 + }
  551 + else{
  552 + ui->ctrLbRemainTime->setText(tr("USB 인식을 실패하였습니다."));
  553 + QTimer::singleShot(1000,this,SLOT(close()));
  554 + }
  555 +}
349 556  
  557 +void FileProcessDlg::onProgressFinished(){
  558 + ui->ctrLbRemainTime->setText(tr("완료"));
  559 + QTimer::singleShot(1000,this, SLOT(close()));
  560 +}
  561 +
  562 +void FileProcessDlg::onProgressed(int progress, int sec){
  563 + int min, _sec;
  564 + QString strTemp;
  565 + ui->ctrWjProcess->setValue(progress);
  566 + min = sec/60;
  567 + _sec = sec%60;
  568 + if(min >0){
  569 + strTemp.sprintf("남은 예상 시간 : %d분 %d초", min, _sec);
  570 + ui->ctrLbRemainTime->setText(strTemp);
  571 + }
  572 + else{
  573 + strTemp.sprintf("남은 예상 시간 : %d초", sec);
  574 + ui->ctrLbRemainTime->setText(strTemp);
  575 + }
350 576 }
351 577  
352 578 void FileProcessDlg::programUpload(){
... ...
app/gui/oven_control/fileprocessdlg.h
... ... @@ -4,6 +4,9 @@
4 4 #include <QDialog>
5 5 #include <QFile>
6 6 #include <QTextStream>
  7 +#include <QThread>
  8 +#include <QList>
  9 +#include <QMutex>
7 10 #include "config.h"
8 11 #include "servicedata.h"
9 12 #include "historylistwindow.h"
... ... @@ -16,6 +19,31 @@ namespace Ui {
16 19 class FileProcessDlg;
17 20 }
18 21  
  22 +class ProgramCopyWorker : public QObject{
  23 + Q_OBJECT
  24 + QString m_strDestDir;
  25 + QList<QString> m_arrSrcFileList;
  26 + QList<QString> m_arrSrcDirList;
  27 + QMutex m_mutex;
  28 + bool m_bStop;
  29 +public:
  30 + explicit ProgramCopyWorker(QString strDest);
  31 + explicit ProgramCopyWorker();
  32 + void setDestPath(QString strDest);
  33 + void addSrcFile(QString strfilename);
  34 + void addSrcDir(QString strDirPath);
  35 +
  36 +
  37 +public slots:
  38 + void workerMain();
  39 + void workerStop();
  40 +
  41 +
  42 +signals:
  43 + void finished();
  44 + void progressed(int progress, int sec);
  45 +};
  46 +
19 47 class FileProcessDlg : public QDialog
20 48 {
21 49 Q_OBJECT
... ... @@ -37,10 +65,18 @@ private slots:
37 65 void configDownload();
38 66 void configUpload();
39 67  
  68 +signals:
  69 + void stopcopy();
  70 +
  71 +public slots:
  72 + void onProgressed(int progress,int sec);
  73 + void onProgressFinished();
40 74  
41 75 private:
42 76 Ui::FileProcessDlg *ui;
43 77 ConfigType m_nCfgtype;
  78 + QThread programCopyThd;
  79 + ProgramCopyWorker worker;
44 80 };
45 81  
46 82 #endif // FILEPROCESSDLG_H
... ...
app/gui/oven_control/fileprocessor.cpp
... ... @@ -39,3 +39,36 @@ bool FileProcessor::detectUSB(QString &amp;usbPath){
39 39 qDebug() << "usb detect fail";
40 40 return false;
41 41 }
  42 +
  43 +
  44 +void FileProcessor::getAllDirList(QDir d, QStringList &list){
  45 + QStringList qsl = d.entryList(QDir::NoDotAndDotDot | QDir::Dirs);
  46 + foreach(QString strdir, qsl){
  47 + strdir.prepend(d.absolutePath().append("/"));
  48 + list.append(strdir);
  49 + QDir dir(strdir);
  50 + getAllDirList(dir,list);
  51 + }
  52 +}
  53 +
  54 +quint64 FileProcessor::getDirSize(const QString &str){
  55 + qint64 sizex = 0;
  56 + QFileInfo str_info(str);
  57 + if(str_info.isDir()){
  58 + QDir dir(str);
  59 + QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
  60 + for (int i = 0; i < list.size(); ++i)
  61 + {
  62 + QFileInfo fileInfo = list.at(i);
  63 + if(fileInfo.isDir())
  64 + {
  65 + sizex += getDirSize(fileInfo.absoluteFilePath());
  66 + }
  67 + else{
  68 + qDebug() << fileInfo.absoluteFilePath() << fileInfo.size();
  69 + sizex += fileInfo.size();
  70 + }
  71 + }
  72 + }
  73 + return sizex;
  74 +}
... ...
app/gui/oven_control/fileprocessor.h
... ... @@ -10,7 +10,8 @@ public:
10 10 static bool folderExist(const QString &path);
11 11 static bool fileExist(const QString &path_file);
12 12 static bool detectUSB(QString &usbpath);
13   -
  13 +static void getAllDirList(QDir d, QStringList &list);
  14 +static quint64 getDirSize(const QString &str);
14 15 };
15 16  
16 17 #endif // FILEPROCESSOR_H
... ...