func:新建文件夹成功。
This commit is contained in:
@@ -132,6 +132,16 @@ void ClientCore::handleAsk(QSharedPointer<FrameBuffer> frame)
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (msg.command == STRMSG_AC_NEW_DIR) {
|
||||
msg.command = STRMSG_AC_ANSWER_NEW_DIR;
|
||||
msg.msg = Util::NewDir(msg.fromPath);
|
||||
if (!Send<InfoMsg>(msg, FBT_MSGINFO_ANSWER, frame->fid)) {
|
||||
auto logMsg = tr("给") + frame->fid + tr("返回新建结果消息失败。");
|
||||
qCritical() << logMsg;
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 未知信息
|
||||
qWarning() << QString(tr("未知询问信息类型:%1")).arg(msg.command);
|
||||
}
|
||||
|
||||
@@ -241,17 +241,8 @@ void FileManager::SortFileInfo(SortMethod method)
|
||||
}
|
||||
}
|
||||
|
||||
void FileManager::RefreshTab()
|
||||
void FileManager::ShowFileItem(const DirFileInfo& f, int i)
|
||||
{
|
||||
userScrol_ = false;
|
||||
ui->tableWidget->clearContents();
|
||||
ui->tableWidget->setRowCount(0);
|
||||
|
||||
for (int i = 0; i < currentShowInfo_.vec.size(); ++i) {
|
||||
|
||||
ui->tableWidget->insertRow(ui->tableWidget->rowCount());
|
||||
const DirFileInfo& fileInfo = currentShowInfo_.vec[i];
|
||||
|
||||
// ***********************************************************************************
|
||||
auto* iconItem = new QTableWidgetItem("");
|
||||
iconItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
@@ -259,10 +250,10 @@ void FileManager::RefreshTab()
|
||||
ui->tableWidget->setItem(i, 0, iconItem);
|
||||
|
||||
// ***********************************************************************************
|
||||
auto* fileItem = new QTableWidgetItem(fileInfo.name);
|
||||
auto* fileItem = new QTableWidgetItem(f.name);
|
||||
fileItem->setFlags(fileItem->flags() & ~Qt::ItemIsEditable);
|
||||
ui->tableWidget->setItem(i, 1, fileItem);
|
||||
QDateTime modifyTime = QDateTime::fromMSecsSinceEpoch(fileInfo.lastModified);
|
||||
QDateTime modifyTime = QDateTime::fromMSecsSinceEpoch(f.lastModified);
|
||||
|
||||
// ***********************************************************************************
|
||||
QString timeStr = modifyTime.toString("yyyy-MM-dd hh:mm:ss");
|
||||
@@ -272,7 +263,7 @@ void FileManager::RefreshTab()
|
||||
|
||||
// ***********************************************************************************
|
||||
QString typeStr;
|
||||
switch (fileInfo.type) {
|
||||
switch (f.type) {
|
||||
case File:
|
||||
typeStr = "File";
|
||||
iconItem->setIcon(QApplication::style()->standardIcon(QStyle::SP_FileIcon));
|
||||
@@ -299,22 +290,34 @@ void FileManager::RefreshTab()
|
||||
|
||||
// ***********************************************************************************
|
||||
QString sizeStr;
|
||||
if (fileInfo.size < 1024) {
|
||||
sizeStr = QString::number(fileInfo.size) + " B";
|
||||
} else if (fileInfo.size < 1024 * 1024) {
|
||||
sizeStr = QString::number(fileInfo.size / 1024.0, 'f', 2) + " KB";
|
||||
if (f.size < 1024) {
|
||||
sizeStr = QString::number(f.size) + " B";
|
||||
} else if (f.size < 1024 * 1024) {
|
||||
sizeStr = QString::number(f.size / 1024.0, 'f', 2) + " KB";
|
||||
} else {
|
||||
sizeStr = QString::number(fileInfo.size / (1024.0 * 1024.0), 'f', 2) + " MB";
|
||||
sizeStr = QString::number(f.size / (1024.0 * 1024.0), 'f', 2) + " MB";
|
||||
}
|
||||
QTableWidgetItem* item = nullptr;
|
||||
if (fileInfo.type == File) {
|
||||
if (f.type == File) {
|
||||
item = new QTableWidgetItem(sizeStr);
|
||||
} else {
|
||||
item = new QTableWidgetItem("");
|
||||
}
|
||||
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
|
||||
ui->tableWidget->setItem(i, 4, item);
|
||||
}
|
||||
|
||||
void FileManager::RefreshTab()
|
||||
{
|
||||
userScrol_ = false;
|
||||
ui->tableWidget->clearContents();
|
||||
ui->tableWidget->setRowCount(0);
|
||||
|
||||
for (int i = 0; i < currentShowInfo_.vec.size(); ++i) {
|
||||
|
||||
ui->tableWidget->insertRow(ui->tableWidget->rowCount());
|
||||
const DirFileInfo& fileInfo = currentShowInfo_.vec[i];
|
||||
ShowFileItem(fileInfo, i);
|
||||
if (i % 50 == 0) {
|
||||
QGuiApplication::processEvents();
|
||||
}
|
||||
@@ -541,6 +544,77 @@ void FileManager::UpDown()
|
||||
|
||||
void FileManager::OperNewFolder()
|
||||
{
|
||||
QInputDialog dialog(this);
|
||||
dialog.setWindowTitle("输入");
|
||||
dialog.setLabelText("要新建的文件夹名称:");
|
||||
dialog.setOkButtonText("确定");
|
||||
dialog.setCancelButtonText("取消");
|
||||
dialog.setFixedSize(dialog.minimumSizeHint());
|
||||
|
||||
QString text;
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
text = dialog.textValue().trimmed();
|
||||
if (text.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
auto folder = Util::Join(GetRoot(), text);
|
||||
if (!isRemote_) {
|
||||
QString ret = Util::NewDir(folder);
|
||||
if (ret.isEmpty()) {
|
||||
QMessageBox::information(this, tr("提示"), tr("创建%1成功").arg(folder));
|
||||
DirFileInfo nf;
|
||||
nf.size = 0;
|
||||
nf.type = Dir;
|
||||
nf.fullPath = folder;
|
||||
nf.name = text;
|
||||
nf.lastModified = QDateTime::currentDateTime().toMSecsSinceEpoch();
|
||||
ui->tableWidget->insertRow(0);
|
||||
ShowFileItem(nf, 0);
|
||||
} else {
|
||||
QMessageBox::information(this, tr("提示"), ret);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
WaitOper oper(this);
|
||||
oper.SetClient(cliCore_);
|
||||
oper.SetType(STRMSG_AC_NEW_DIR, STRMSG_AC_ANSWER_NEW_DIR);
|
||||
oper.SetPath(folder, "", "");
|
||||
|
||||
LoadingDialog checking(this);
|
||||
checking.setTipsText("正在新建...");
|
||||
connect(&oper, &WaitOper::sigCheckOver, &checking, &LoadingDialog::cancelBtnClicked);
|
||||
connect(cliCore_, &ClientCore::sigMsgAnswer, &oper, &WaitOper::recvFrame);
|
||||
|
||||
oper.start();
|
||||
checking.exec();
|
||||
|
||||
std::shared_ptr<void> recv(nullptr, [&oper](void*) { oper.wait(); });
|
||||
|
||||
if (checking.isUserCancel()) {
|
||||
oper.interrupCheck();
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查结果
|
||||
auto msg = oper.GetMsg();
|
||||
if (msg.msg == STR_NONE || !msg.msg.isEmpty()) {
|
||||
QMessageBox::information(this, tr("提示"), QString(tr("新建失败=>%1")).arg(msg.msg));
|
||||
} else {
|
||||
QMessageBox::information(this, tr("提示"), QString(tr("新建%1成功。")).arg(folder));
|
||||
DirFileInfo nf;
|
||||
nf.size = 0;
|
||||
nf.type = Dir;
|
||||
nf.fullPath = folder;
|
||||
nf.name = text;
|
||||
nf.lastModified = QDateTime::currentDateTime().toMSecsSinceEpoch();
|
||||
ui->tableWidget->insertRow(0);
|
||||
ShowFileItem(nf, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void FileManager::OperDelete()
|
||||
@@ -640,8 +714,7 @@ void FileManager::OperRename()
|
||||
if (text.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
#include <FileTrans.h>
|
||||
#include <InfoDirFile.h>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QTableWidgetItem>
|
||||
#include <QMenu>
|
||||
#include <QMutex>
|
||||
#include <QTableWidgetItem>
|
||||
#include <QWidget>
|
||||
#include <Util.h>
|
||||
#include <map>
|
||||
@@ -72,6 +72,7 @@ private:
|
||||
void InitMenu();
|
||||
void ShowPath(const QString& path, const QVector<QString>& drivers);
|
||||
void ShowFile(const DirFileInfoVec& info);
|
||||
void ShowFileItem(const DirFileInfo& f, int i);
|
||||
void doubleClick(int row, int column);
|
||||
void SetRoot(const QString& path);
|
||||
void SortFileInfo(SortMethod method);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
| 37 | 问题 | 未连接对方客户端时,执行对照传输会崩溃。 | 待复现 | 0.2.3 | |
|
||||
| 36 | 功能 | 备份文件功能。 | | 0.2.3 | |
|
||||
| 35 | 功能 | 完善对照功能的界面其他内容。 | | 0.2.3 | |
|
||||
| 34 | 功能 | 支持删除、重命名、新建文件(夹)。 | | 0.2.3 | |
|
||||
| 34 | 功能 | 支持删除、重命名、新建文件(夹)。 | | 0.2.3 | 0.2.4 |
|
||||
| 33 | 功能 | 弹窗查看文件(夹)属性窗口。 | | 0.2.3 | 0.2.4 |
|
||||
| 32 | 功能 | 路径选择显示驱动器。 | | 0.2.2 | 0.2.3 |
|
||||
| 31 | 功能 | Server端buffer大小判断,有过多无效数据则踢出该客户端。 | | 0.2.2 | 0.2.4 |
|
||||
|
||||
@@ -280,3 +280,33 @@ QString Util::Delete(const QString& path)
|
||||
return tr("不支持的文件类型: %1").arg(path);
|
||||
}
|
||||
}
|
||||
|
||||
QString Util::NewDir(const QString& path)
|
||||
{
|
||||
if (path.isEmpty()) {
|
||||
return tr("路径不能为空");
|
||||
}
|
||||
|
||||
if (QDir(path).exists()) {
|
||||
return tr("目录已存在: %1").arg(path);
|
||||
}
|
||||
|
||||
QFileInfo pathInfo(path);
|
||||
QDir parentDir = pathInfo.absoluteDir();
|
||||
|
||||
if (!parentDir.exists()) {
|
||||
return tr("父目录不存在: %1").arg(parentDir.absolutePath());
|
||||
}
|
||||
|
||||
QFileInfo parentInfo(parentDir.absolutePath());
|
||||
if (!parentInfo.isWritable()) {
|
||||
return tr("父目录无写入权限: %1").arg(parentDir.absolutePath());
|
||||
}
|
||||
|
||||
QDir dir;
|
||||
if (dir.mkpath(path)) {
|
||||
return "";
|
||||
} else {
|
||||
return tr("创建目录失败: %1").arg(path);
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,7 @@ public:
|
||||
static bool DirExist(const QString& path, bool isFilePath);
|
||||
static QString Rename(const QString& from, const QString& to, bool isDir);
|
||||
static QString Delete(const QString& path);
|
||||
static QString NewDir(const QString& path);
|
||||
static QString UUID();
|
||||
static QVector<QString> GetLocalDrivers();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user