569 lines
16 KiB
C++
569 lines
16 KiB
C++
#include "CFileSyncDialog.h"
|
|
#include "ui_CFileSyncDialog.h"
|
|
#include "CConfirmDialog.h"
|
|
#include "../include/public/pub_utility_api/I18N.h"
|
|
#include <QTranslator>
|
|
#include <QTextCodec>
|
|
#include <QDir>
|
|
#include <QFileDialog>
|
|
#include <QMessageBox>
|
|
|
|
#ifdef CODEC_EXECUTE
|
|
#pragma execution_character_set("utf-8")
|
|
#endif
|
|
|
|
CFileSyncDialog::CFileSyncDialog(QDialog *parent) :
|
|
QDialog(parent),
|
|
ui(new Ui::CFileSyncDialog)
|
|
{
|
|
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8"));
|
|
|
|
if(iot_public::getCurLanguage() == "en")
|
|
{
|
|
QTranslator * sysTranslator = new QTranslator(this);
|
|
sysTranslator->load(":/fileSync_en.qm");
|
|
QApplication::installTranslator(sysTranslator);
|
|
}
|
|
|
|
ui->setupUi(this);
|
|
|
|
m_FileTypeList << "docx" << "txt" << "glx" << "ilx" << "qss" << "xml" << "json" << "png" << "jpg";
|
|
m_ptrSysFileSync = new CSysFileSyncApi();
|
|
|
|
ui->m_filePathComb->setEditable(true);
|
|
initFileTable();
|
|
initMenu();
|
|
initComb();
|
|
}
|
|
|
|
CFileSyncDialog::~CFileSyncDialog()
|
|
{
|
|
if(m_ptrSysFileSync)
|
|
{
|
|
delete m_ptrSysFileSync;
|
|
m_ptrSysFileSync = NULL;
|
|
}
|
|
delete ui;
|
|
}
|
|
|
|
void CFileSyncDialog::getFileNameByPath(const QStringList& path, QStringList &name)
|
|
{
|
|
for(int i=0; i<path.length(); ++i)
|
|
{
|
|
QString onePath = path.at(i);
|
|
#ifdef WIN32
|
|
QStringList list = onePath.split("\\");
|
|
#else
|
|
QStringList list = onePath.split("/");
|
|
#endif
|
|
|
|
name.append(list.last());
|
|
}
|
|
}
|
|
|
|
void CFileSyncDialog::webPublish(const QStringList &pathList, bool& isSuccess, QString &errStr)
|
|
{
|
|
QStringList commitList;
|
|
|
|
QMap<QString, stFileStatus> statusMap;
|
|
for(int i=0; i<pathList.length(); ++i)
|
|
{
|
|
getSvnFile(pathList.at(i), statusMap, errStr);
|
|
if(errStr != "")
|
|
{
|
|
isSuccess = false;
|
|
return;
|
|
}
|
|
}
|
|
|
|
QMap<QString, stFileStatus>::const_iterator iter = statusMap.constBegin();
|
|
for(;iter != statusMap.constEnd(); ++iter)
|
|
{
|
|
if(iter.value().itemChange == FIRST_ADD
|
|
|| iter.value().itemChange == FIRST_DELETED
|
|
|| iter.value().itemChange == FIRST_MODIFIED
|
|
|| iter.value().itemChange == FIRST_REPLACED)
|
|
{
|
|
commitList.append(QString::fromStdString(iter.value().strFilePath));
|
|
}
|
|
}
|
|
if(commitList.length() == 0)
|
|
{
|
|
isSuccess = true;
|
|
return;
|
|
}
|
|
|
|
QString strOutPut;
|
|
int ret = m_ptrSysFileSync->exeCommit(commitList, strOutPut, errStr,
|
|
"", "", "web发布");
|
|
|
|
if(ret == 0)
|
|
{
|
|
isSuccess = true;
|
|
}
|
|
else
|
|
{
|
|
isSuccess = false;
|
|
}
|
|
}
|
|
|
|
void CFileSyncDialog::slot_add()
|
|
{
|
|
QString strOutPut;
|
|
QString strError;
|
|
|
|
stSelectedPath st;
|
|
st.isAllSelect = false;
|
|
st.action = ACTION_ADD;
|
|
getSelectsPath(st);
|
|
QStringList& path = st.path;
|
|
|
|
QStringList nameList;
|
|
getFileNameByPath(path, nameList);
|
|
if(nameList.length() == 0)
|
|
{
|
|
QMessageBox::information(this,tr("提示"),tr("无需添加"),QMessageBox::Ok);
|
|
return;
|
|
}
|
|
|
|
QString text;
|
|
for(int i=0;i<nameList.length();++i)
|
|
{
|
|
text += nameList.at(i) + "\n";
|
|
}
|
|
int comfirmRet = QMessageBox::information(this,tr("确认添加"),text,QMessageBox::Ok|QMessageBox::Cancel);
|
|
if(comfirmRet == QMessageBox::Ok)
|
|
{
|
|
int ret = m_ptrSysFileSync->exeAdd(path, strOutPut, strError);
|
|
if(ret != 0)
|
|
{
|
|
QMessageBox::information(this,tr("提示"),tr("添加失败: ") + QString("%1").arg(strError),QMessageBox::Ok);
|
|
return;
|
|
}
|
|
emit ui->m_filePathComb->editTextChanged(ui->m_filePathComb->currentText());
|
|
}
|
|
}
|
|
|
|
void CFileSyncDialog::slot_commit()
|
|
{
|
|
stSelectedPath st;
|
|
st.isAllSelect = false;
|
|
st.action = ACTION_COMMIT;
|
|
getSelectsPath(st);
|
|
commit(st.path);
|
|
}
|
|
|
|
void CFileSyncDialog::slot_delete()
|
|
{
|
|
QString strOutPut;
|
|
QString strError;
|
|
|
|
stSelectedPath st;
|
|
st.isAllSelect = false;
|
|
st.action = ACTION_DELETE;
|
|
getSelectsPath(st);
|
|
QStringList& path = st.path;
|
|
|
|
QStringList nameList;
|
|
getFileNameByPath(path, nameList);
|
|
if(nameList.length() == 0)
|
|
{
|
|
QMessageBox::information(this,tr("提示"),tr("无需删除"),QMessageBox::Ok);
|
|
return;
|
|
}
|
|
|
|
QString text;
|
|
for(int i=0;i<nameList.length();++i)
|
|
{
|
|
text += nameList.at(i) + "\n";
|
|
}
|
|
int comfirmRet = QMessageBox::information(this,tr("确认删除"),text,QMessageBox::Ok|QMessageBox::Cancel);
|
|
if(comfirmRet == QMessageBox::Ok)
|
|
{
|
|
int ret = m_ptrSysFileSync->exeDelete(path, strOutPut, strError);
|
|
if(ret != 0)
|
|
{
|
|
QMessageBox::information(this,tr("提示"),tr("删除失败: ") + QString("%1").arg(strError),QMessageBox::Ok);
|
|
return;
|
|
}
|
|
emit ui->m_filePathComb->editTextChanged(ui->m_filePathComb->currentText());
|
|
}
|
|
}
|
|
|
|
void CFileSyncDialog::slot_allCommit()
|
|
{
|
|
stSelectedPath st;
|
|
st.isAllSelect = true;
|
|
st.action = ACTION_COMMIT;
|
|
getSelectsPath(st);
|
|
commit(st.path);
|
|
}
|
|
|
|
void CFileSyncDialog::on_m_filePathComb_editTextChanged(const QString &arg1)
|
|
{
|
|
QString path = ui->m_filePathComb->currentText();
|
|
if(path == "")
|
|
{
|
|
return;
|
|
}
|
|
QFileInfoList list;
|
|
QMap<QString, stFileStatus> svnMap;
|
|
QString strError = QString();
|
|
getFileInfos(arg1, list);
|
|
getSvnFile(path, svnMap, strError);
|
|
updatFileTable(list, svnMap);
|
|
}
|
|
|
|
void CFileSyncDialog::on_m_selectFileBtn_clicked()
|
|
{
|
|
QString fileName = QFileDialog::getExistingDirectory(this,tr("选择文件"),"../../data");
|
|
if(fileName == "")
|
|
{
|
|
return;
|
|
}
|
|
|
|
ui->m_filePathComb->setCurrentText(fileName);
|
|
}
|
|
|
|
void CFileSyncDialog::on_m_reloadBtn_clicked()
|
|
{
|
|
emit ui->m_filePathComb->editTextChanged(ui->m_filePathComb->currentText());
|
|
}
|
|
|
|
void CFileSyncDialog::on_m_fileTextTable_customContextMenuRequested(const QPoint &pos)
|
|
{
|
|
if(ui->m_fileTextTable->itemAt(pos))
|
|
{
|
|
m_menu->addAction(ui->m_actionAdd);
|
|
m_menu->addAction(ui->m_actionDelete);
|
|
m_menu->addAction(ui->m_actionCommit);
|
|
m_menu->removeAction(ui->m_actionAllCommit);
|
|
}
|
|
else
|
|
{
|
|
m_menu->addAction(ui->m_actionAllCommit);
|
|
m_menu->removeAction(ui->m_actionAdd);
|
|
m_menu->removeAction(ui->m_actionDelete);
|
|
m_menu->removeAction(ui->m_actionCommit);
|
|
}
|
|
m_menu->exec(QCursor::pos());
|
|
}
|
|
|
|
void CFileSyncDialog::initFileTable()
|
|
{
|
|
ui->m_fileTextTable->setColumnCount(3);
|
|
ui->m_fileTextTable->setColumnWidth(0,350);
|
|
ui->m_fileTextTable->hideColumn(1);
|
|
ui->m_fileTextTable->verticalHeader()->hide();
|
|
ui->m_fileTextTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
|
|
ui->m_fileTextTable->setHorizontalHeaderLabels(QStringList() << tr("名称") << tr("修改日期") << tr("状态"));
|
|
ui->m_fileTextTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
ui->m_fileTextTable->setEditTriggers(0);
|
|
}
|
|
|
|
void CFileSyncDialog::initMenu()
|
|
{
|
|
m_menu = new QMenu(this);
|
|
|
|
connect(ui->m_actionAdd,SIGNAL(triggered(bool)),this,SLOT(slot_add()));
|
|
connect(ui->m_actionCommit,SIGNAL(triggered(bool)),this,SLOT(slot_commit()));
|
|
connect(ui->m_actionDelete,SIGNAL(triggered(bool)),this,SLOT(slot_delete()));
|
|
connect(ui->m_actionAllCommit,SIGNAL(triggered(bool)),this,SLOT(slot_allCommit()));
|
|
}
|
|
|
|
void CFileSyncDialog::initComb()
|
|
{
|
|
QDir dir = QDir::current();
|
|
dir.cdUp();
|
|
dir.cdUp();
|
|
ui->m_filePathComb->addItem(dir.path() + "/data/pic");
|
|
ui->m_filePathComb->addItem(dir.path() + "/data/icon");
|
|
}
|
|
|
|
void CFileSyncDialog::getFileInfos(const QString &path, QFileInfoList &list)
|
|
{
|
|
QDir dir(path);
|
|
QStringList nameFilters;
|
|
list = dir.entryInfoList(nameFilters, QDir::Files|QDir::Readable, QDir::Name|QDir::Time|QDir::Type|QDir::Size);
|
|
}
|
|
|
|
void CFileSyncDialog::getSvnFile(const QString &path, QMap<QString, stFileStatus> &name, QString& error)
|
|
{
|
|
QVector<iot_sys::stFileStatus> vecFileStatus;
|
|
|
|
QStringList list;
|
|
list.append(path);
|
|
int ret = m_ptrSysFileSync->exeStatus(list, vecFileStatus, error);
|
|
if(ret == 0)
|
|
{
|
|
for(int i=0; i<vecFileStatus.size(); ++i)
|
|
{
|
|
//qDebug() << QString::fromStdString(vecFileStatus.at(i).strFilePath);
|
|
|
|
#ifdef WIN32
|
|
QString str = QString::fromStdString(vecFileStatus.at(i).strFilePath).split("\\").last();
|
|
#else
|
|
QString str = QString::fromStdString(vecFileStatus.at(i).strFilePath).split("/").last();
|
|
#endif
|
|
|
|
if(m_FileTypeList.indexOf(str.split(".").last()) == -1)
|
|
{
|
|
continue;
|
|
}
|
|
//enFirstColums status = vecFileStatus.at(i).itemChange;
|
|
name.insert(str, vecFileStatus.at(i));
|
|
}
|
|
}
|
|
}
|
|
|
|
QString CFileSyncDialog::getTimeStr(const QDateTime &time)
|
|
{
|
|
QString ret = QString("%1/%2/%3 %4:%5")
|
|
.arg(time.date().year())
|
|
.arg(time.date().month())
|
|
.arg(time.date().day())
|
|
.arg(time.time().hour())
|
|
.arg(time.time().minute());
|
|
|
|
return ret;
|
|
}
|
|
|
|
void CFileSyncDialog::updatFileTable(QFileInfoList &list, const QMap<QString, stFileStatus>& svnMap)
|
|
{
|
|
fileFilter(list, svnMap); //< 过滤出无修改的文件
|
|
int rowCount = list.length() + svnMap.size();
|
|
ui->m_fileTextTable->clearContents();
|
|
ui->m_fileTextTable->setRowCount(rowCount);
|
|
QIcon icon(":/icon/NormalIcon.ico");
|
|
|
|
QMap<QString, stFileStatus>::const_iterator it = svnMap.begin();
|
|
for(int j=0;it!=svnMap.end();++it,++j)
|
|
{
|
|
const stFileStatus& st = it.value();
|
|
QTableWidgetItem *name = new QTableWidgetItem(QIcon(getIconByState(st.itemChange)),it.key());
|
|
QTableWidgetItem *status = new QTableWidgetItem(getStatusStr(st));
|
|
ui->m_fileTextTable->setItem(j, 0, name);
|
|
ui->m_fileTextTable->setItem(j, 2, status);
|
|
ui->m_fileTextTable->item(j,0)->setData(5,int(st.itemChange));
|
|
}
|
|
|
|
for(int i=svnMap.size(); i<rowCount; ++i)
|
|
{
|
|
int index = i - svnMap.size();
|
|
QTableWidgetItem *fileName = new QTableWidgetItem(icon,list.at(index).fileName());
|
|
QTableWidgetItem *lastModify = new QTableWidgetItem(getTimeStr(list.at(index).lastModified()));
|
|
QTableWidgetItem *normalStatus = new QTableWidgetItem(CConfirmDialog::getStrByState(FIRST_NO_CHANGED));
|
|
ui->m_fileTextTable->setItem(i, 0, fileName);
|
|
ui->m_fileTextTable->setItem(i, 1, lastModify);
|
|
ui->m_fileTextTable->setItem(i, 2, normalStatus);
|
|
ui->m_fileTextTable->item(i,0)->setData(5,1); //test changed
|
|
}
|
|
}
|
|
|
|
void CFileSyncDialog::fileFilter(QFileInfoList &list, const QMap<QString, stFileStatus>& svnMap)
|
|
{
|
|
for(int i=0;i<list.length();++i)
|
|
{
|
|
if(m_FileTypeList.indexOf(list.at(i).fileName().split(".").last()) == -1)
|
|
{
|
|
list.removeAt(i);
|
|
--i;
|
|
continue;
|
|
}
|
|
|
|
QMap<QString, stFileStatus>::const_iterator it = svnMap.find(list.at(i).fileName());
|
|
if(it != svnMap.end())
|
|
{
|
|
list.removeAt(i);
|
|
--i;
|
|
}
|
|
}
|
|
}
|
|
|
|
QString CFileSyncDialog::getStatusStr(const stFileStatus &st)
|
|
{
|
|
QString ret = CConfirmDialog::getStrByState(st.itemChange);
|
|
if((st.propertiesChange != SECOND_NO_CHANGED)
|
|
|| (st.workingCopyLocked != THIRD_NOT_LOCKED)
|
|
|| (st.commitContainHistory != FOURTH_NOT_HISTORY)
|
|
|| (st.SwitchOrExternalRefer != FIFTH_NORMAL)
|
|
|| (st.versionLocked != SIXTH_NOT_LOCKED)
|
|
|| (st.projectConflict != SEVENTH_NORMAL))
|
|
{
|
|
ret += tr(" (异常) ");
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
QString CFileSyncDialog::getIconByState(enFirstColums status)
|
|
{
|
|
QString ret;
|
|
switch (status) {
|
|
case FIRST_NO_CHANGED:
|
|
{
|
|
ret = ":/icon/NormalIcon.ico";
|
|
break;
|
|
}
|
|
case FIRST_ADD:
|
|
{
|
|
ret = ":/icon/AddedIcon.ico";
|
|
break;
|
|
}
|
|
case FIRST_CONFLICTED:
|
|
{
|
|
ret = ":/icon/ConflictIcon.ico";
|
|
break;
|
|
}
|
|
case FIRST_DELETED:
|
|
{
|
|
ret = ":/icon/DeletedIcon.ico";
|
|
break;
|
|
}
|
|
case FIRST_IGNORED:
|
|
{
|
|
ret = ":/icon/IgnoredIcon.ico";
|
|
break;
|
|
}
|
|
case FIRST_MODIFIED:
|
|
case FIRST_REPLACED:
|
|
{
|
|
ret = ":/icon/ModifiedIcon.ico";
|
|
break;
|
|
}
|
|
case FIRST_EXTERNALS_DEFINE:
|
|
case FIRST_NOT_VERSION_CONTROL:
|
|
{
|
|
ret = ":/icon/UnversionedIcon.ico";
|
|
break;
|
|
}
|
|
case FIRST_MISS:
|
|
{
|
|
ret = "";
|
|
break;
|
|
}
|
|
case FIRST_OBSTRUCTED:
|
|
{
|
|
ret = "";
|
|
break;
|
|
}
|
|
case FIRST_ILLEGAL:
|
|
{
|
|
ret = "";
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void CFileSyncDialog::getSelectsPath(stSelectedPath &stPath)
|
|
{
|
|
QList<QTableWidgetSelectionRange> list = ui->m_fileTextTable->selectedRanges();
|
|
if(stPath.isAllSelect)
|
|
{
|
|
QTableWidgetSelectionRange range(0, 0, ui->m_fileTextTable->rowCount()-1, ui->m_fileTextTable->columnCount()-1);
|
|
list.clear();
|
|
list.append(range);
|
|
}
|
|
for(int i=0;i<list.length();++i)
|
|
{
|
|
for(int row=0; row<list.at(i).rowCount(); ++row)
|
|
{
|
|
if(!checkIsNeedAppend(row+list.at(i).topRow(), stPath.action))
|
|
{
|
|
continue;
|
|
}
|
|
#ifdef WIN32
|
|
stPath.path.append(ui->m_filePathComb->currentText() + "\\" + ui->m_fileTextTable->item(row+list.at(i).topRow(),0)->text());
|
|
#else
|
|
stPath.path.append(ui->m_filePathComb->currentText() + "/" + ui->m_fileTextTable->item(row+list.at(i).topRow(),0)->text());
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
|
|
bool CFileSyncDialog::checkIsNeedAppend(int row, enOptAction action)
|
|
{
|
|
bool ret = false;
|
|
int current = ui->m_fileTextTable->item(row,0)->data(5).toInt();
|
|
switch (action) {
|
|
case ACTION_ADD:
|
|
{
|
|
if(current == FIRST_EXTERNALS_DEFINE || current == FIRST_NOT_VERSION_CONTROL)
|
|
{
|
|
ret = true;
|
|
}
|
|
break;
|
|
}
|
|
case ACTION_DELETE:
|
|
{
|
|
if(current == FIRST_NO_CHANGED)
|
|
{
|
|
ret = true;
|
|
}
|
|
break;
|
|
}
|
|
case ACTION_COMMIT:
|
|
{
|
|
if(current == FIRST_ADD || current == FIRST_DELETED || current == FIRST_MODIFIED || current == FIRST_REPLACED)
|
|
{
|
|
ret = true;
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
ret = true;
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void CFileSyncDialog::commit(const QStringList &path)
|
|
{
|
|
QString strOutPut;
|
|
QString strError;
|
|
|
|
QStringList nameList;
|
|
getFileNameByPath(path, nameList);
|
|
if(nameList.length() == 0)
|
|
{
|
|
QMessageBox::information(this,tr("提示"),tr("无需提交"),QMessageBox::Ok);
|
|
return;
|
|
}
|
|
QMap<QString,QString> map;
|
|
getCommitMap(nameList, map);
|
|
CConfirmDialog dialog(this);
|
|
dialog.setNameMap(map);
|
|
dialog.setRootPath(ui->m_filePathComb->currentText());
|
|
if(dialog.exec())
|
|
{
|
|
QStringList allPath;
|
|
dialog.getAllPath(allPath);
|
|
QString message = dialog.getMessage();
|
|
int ret = m_ptrSysFileSync->exeCommit(allPath, strOutPut, strError,
|
|
"","",message);
|
|
if(ret != 0)
|
|
{
|
|
QMessageBox::information(this,tr("提示"),tr("提交失败: ") + QString("%1").arg(strError),QMessageBox::Ok);
|
|
return;
|
|
}
|
|
emit ui->m_filePathComb->editTextChanged(ui->m_filePathComb->currentText());
|
|
}
|
|
}
|
|
|
|
void CFileSyncDialog::getCommitMap(const QStringList &name, QMap<QString, QString> &map)
|
|
{
|
|
for(int i=0;i<name.length();++i)
|
|
{
|
|
for(int row=0;row<ui->m_fileTextTable->rowCount();++row)
|
|
{
|
|
if(name.at(i) == ui->m_fileTextTable->item(row,0)->text())
|
|
{
|
|
map.insert(name.at(i), ui->m_fileTextTable->item(row,2)->text());
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|