Browse Source

v1.0.2

增加文件删除、打开目录功能
master
tianzhendong 2 years ago
parent
commit
fc0badaa19
  1. 13
      README.md
  2. BIN
      resources/demo.gif
  3. BIN
      resources/img.png
  4. 23
      src/DuplicateFiles.cpp
  5. 6
      src/DuplicateFiles.h
  6. 52
      src/widget.cpp
  7. 7
      src/widget.h
  8. 6
      src/widget.ui

13
README.md

@ -1,9 +1,20 @@
# 重复文件检测工具
windeploy目录下的文件可以直接运行
![](resources/img.png)
![](resources/demo.gif)
## 环境
- Clion 2022.1.2
- qt 5.14.2
## 功能
- 单个文件计算md5
- 文件夹内重复文件检测
## 更新记录
### 20220619 v1.0.2
- [x] 增加打开文件目录功能
- [x] 增加删除文件功能

BIN
resources/demo.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 KiB

BIN
resources/img.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

23
src/DuplicateFiles.cpp

@ -1,7 +1,9 @@
//
// Created by 12038 on 2022/6/16.
//
#include <QProcess>
#include "DuplicateFiles.h"
#include <QUrl>
DuplicateFiles::DuplicateFiles(QObject *) {
@ -73,3 +75,24 @@ QStringList DuplicateFiles::getFiles(const QString &filesDirPath) {
return files;
}
void DuplicateFiles::getTextSlot(const QString &text) {
qDebug()<<"widget_2当前的text为:"<< text;
currentText = text;
}
void DuplicateFiles::openDirSlot() {
QFileInfo fileInfo(currentText);
QString filePath = fileInfo.absolutePath();
qDebug()<<"filePath"<<filePath;
QString path = filePath.replace("/", "\\");
qDebug()<<"path"<<path;
QProcess::startDetached("explorer " + path);
}
void DuplicateFiles::delActionTriggeredSlot() {
QFile file(currentText);
qDebug()<<"即将删除:"<<currentText;
emit delActionFeedbackSignal(file.remove());
qDebug()<<"删除成功";
}

6
src/DuplicateFiles.h

@ -24,16 +24,22 @@ signals:
void filesSignal(const QStringList &);
void process(const int &, const int &);
void duplicateFilesSignal(const QHash<QByteArray, QStringList> &);
void delActionFeedbackSignal(bool delFlag);
public slots:
void getFilesSlot(const QString & filesDirPath);
void calMd5Slot(const QString &filePath);
void getTextSlot(const QString &);
void openDirSlot();
void delActionTriggeredSlot();
private:
QByteArray calMd5(const QString &filePath);
QStringList getFiles(const QString &);
QHash<QByteArray, QStringList> duplicateFiles;
QString currentText = "";
};

52
src/widget.cpp

@ -4,6 +4,7 @@
// You may need to build the project (run Qt uic code generator) to get "ui_Widget.h" resolved
#include <QProcess>
#include "widget.h"
#include "ui_widget.h"
@ -61,6 +62,24 @@ Widget::Widget(QWidget *parent)
this, SLOT(duplicateFilesSlot(const QHash<QByteArray, QStringList> &)));
connect(ui->listWidget, SIGNAL(currentTextChanged(const QString &)),
this, SLOT(currentTextChangedSlot(const QString &)));
connect(ui->listWidget_2, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(on_listWidget_customContextMenuRequested(const QPoint &)));
ui->listWidget_2->setContextMenuPolicy(Qt::CustomContextMenu);
delAction = new QAction();
delAction->setText("删除文件");
openAction = new QAction();
openAction->setText("打开文件目录");
connect(delAction, SIGNAL(triggered(bool)),
duplicateFiles, SLOT(delActionTriggeredSlot()));
connect(ui->listWidget_2, SIGNAL(currentTextChanged(const QString &)),
duplicateFiles, SLOT(getTextSlot(const QString &)));
connect(openAction, SIGNAL(triggered(bool)),
duplicateFiles, SLOT(openDirSlot()));
connect(duplicateFiles, SIGNAL(delActionFeedbackSignal(bool)),
this, SLOT(delActionFeedbackSlot(bool)));
}
Widget::~Widget()
@ -68,6 +87,7 @@ Widget::~Widget()
duplicateFiles->deleteLater();
myThread->exit();
myThread->wait(10 * 1000);
delete ui;
}
@ -175,4 +195,36 @@ void Widget::currentTextChangedSlot(const QString &currentText) {
ui->listWidget_2->addItems(this->duplicateResults[currentText.toLocal8Bit()]);
}
void Widget::on_listWidget_customContextMenuRequested(const QPoint &pos)
{
// ui->listWidget_2->currentTextChanged()
QMenu *menu = new QMenu(this);
// menu->addAction(ui->actionAdd);
// menu->addAction(ui->actionClear);
// menu->addAction(ui->actionDelete);
// menu->addAction(ui->actionInsert);
menu->addAction(this->delAction);
menu->addAction(this->openAction);
menu->addSeparator();
// menu->addAction(ui->actionInit);
// menu->addSeparator();
// menu->addAction(ui->actionSelAll);
// menu->addAction(ui->actionSelInv);
// menu->addAction(ui->actionSelNone);
// menu->addAction(ui->actionSelPopMenu);
menu->exec(QCursor::pos());
delete menu;
}
void Widget::delActionFeedbackSlot(bool flag) {
if(flag){
qDebug()<<"remove item";
QListWidgetItem * item = ui->listWidget_2->currentItem();
qDebug()<<item;
ui->listWidget_2->removeItemWidget(item);
delete item;
}
}

7
src/widget.h

@ -15,6 +15,7 @@
#include <QDebug>
#include <QThread>
#include <QFileDialog>
#include <QMenu>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
@ -45,6 +46,7 @@ public slots:
void processSlot(const int &, const int &);
void duplicateFilesSlot(const QHash<QByteArray, QStringList> &);
void currentTextChangedSlot(const QString &);
void delActionFeedbackSlot(bool flag);
private slots:
void btnMaxClickedSlot();
@ -53,6 +55,8 @@ private slots:
void calMd5ofFileSlot();
void selectDirSlot();
void on_listWidget_customContextMenuRequested(const QPoint &pos);
private:
Ui::Widget *ui;
DuplicateFiles * duplicateFiles;
@ -61,6 +65,9 @@ private:
QPoint mousePosInWindow = QPoint();
QHash<QByteArray, QStringList> duplicateResults;
QAction *delAction;
QAction *openAction;
};

6
src/widget.ui

@ -386,7 +386,11 @@
<widget class="QListWidget" name="listWidget"/>
</item>
<item>
<widget class="QListWidget" name="listWidget_2"/>
<widget class="QListWidget" name="listWidget_2">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
</layout>
</item>

Loading…
Cancel
Save