You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
177 lines
5.8 KiB
177 lines
5.8 KiB
3 years ago
|
//
|
||
3 years ago
|
// Created by 12038 on 2022/6/20.
|
||
3 years ago
|
//
|
||
|
|
||
3 years ago
|
// You may need to build the project (run Qt uic code generator) to get "ui_MainWindow.h" resolved
|
||
3 years ago
|
|
||
3 years ago
|
#include "mainwindow.h"
|
||
|
#include "ui_MainWindow.h"
|
||
3 years ago
|
#include <QProcess>
|
||
3 years ago
|
|
||
3 years ago
|
MainWindow::MainWindow(QWidget *parent) :
|
||
|
QMainWindow(parent), ui(new Ui::MainWindow) {
|
||
3 years ago
|
ui->setupUi(this);
|
||
3 years ago
|
this->setWindowTitle("重复文件检测工具-byTianZD");
|
||
3 years ago
|
|
||
|
duplicateFiles = new DuplicateFiles();
|
||
|
myThread = new QThread();
|
||
|
duplicateFiles->moveToThread(myThread);
|
||
|
myThread->start();
|
||
|
connect(duplicateFiles, SIGNAL(destroyed(QObject *)),
|
||
|
myThread, SLOT(deleteLater()));
|
||
|
|
||
|
connect(ui->btnSelectFile, SIGNAL(clicked(bool)), this, SLOT(calMd5ofFileSlot()));
|
||
|
connect(ui->btnSelectDir, SIGNAL(clicked(bool)), this, SLOT(selectDirSlot()));
|
||
|
connect(this, SIGNAL(calFileMd5Signal(const QString &)),
|
||
|
duplicateFiles, SLOT(calMd5Slot(const QString &)));
|
||
|
connect(duplicateFiles, SIGNAL(md5Signal(const QByteArray &)),
|
||
|
this, SLOT(showFileMd5Slot(const QByteArray &)));
|
||
|
connect(this, SIGNAL(getFilesSignal(const QString &)),
|
||
|
duplicateFiles, SLOT(getFilesSlot(const QString &)));
|
||
|
connect(duplicateFiles, SIGNAL(filesSignal(const QStringList &)),
|
||
|
this, SLOT(filesSlot(const QStringList &)));
|
||
|
|
||
|
connect(duplicateFiles, SIGNAL(process(const int &, const int &)),
|
||
|
this, SLOT(processSlot(const int &, const int &)));
|
||
|
connect(duplicateFiles, SIGNAL(duplicateFilesSignal(const QHash<QByteArray, QStringList> &)),
|
||
|
this, SLOT(duplicateFilesSlot(const QHash<QByteArray, QStringList> &)));
|
||
|
connect(ui->listWidget, SIGNAL(currentTextChanged(const QString &)),
|
||
|
this, SLOT(currentTextChangedSlot(const QString &)));
|
||
3 years ago
|
|
||
|
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)));
|
||
3 years ago
|
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
MainWindow::~MainWindow() {
|
||
3 years ago
|
duplicateFiles->deleteLater();
|
||
|
myThread->exit();
|
||
|
myThread->wait(10 * 1000);
|
||
3 years ago
|
delAction->deleteLater();
|
||
|
openAction->deleteLater();
|
||
3 years ago
|
delete ui;
|
||
|
}
|
||
|
|
||
3 years ago
|
void MainWindow::closeEvent(QCloseEvent *event)
|
||
3 years ago
|
{
|
||
|
QMessageBox::StandardButton button;
|
||
|
button=QMessageBox::question(this,tr("退出程序"),QString(tr("确认退出程序?")),QMessageBox::Yes|QMessageBox::No);
|
||
|
if(button==QMessageBox::No)
|
||
|
{
|
||
|
event->ignore(); // 忽略退出信号,程序继续进行
|
||
|
}
|
||
|
else if(button==QMessageBox::Yes)
|
||
|
{
|
||
|
event->accept(); // 接受退出信号,程序退出
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
void MainWindow::btnMaxClickedSlot()
|
||
3 years ago
|
{
|
||
|
if(this->isMaximized()){
|
||
|
this->showNormal();
|
||
|
}
|
||
|
else{
|
||
|
this->showMaximized();
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
void MainWindow::btnMinClickedSlot()
|
||
3 years ago
|
{
|
||
|
this->showMinimized();
|
||
|
}
|
||
|
|
||
3 years ago
|
void MainWindow::btnCloseClickedSlot()
|
||
3 years ago
|
{
|
||
|
this->close();
|
||
|
}
|
||
|
|
||
3 years ago
|
void MainWindow::calMd5ofFileSlot() {
|
||
3 years ago
|
QString path = QFileDialog::getOpenFileName(
|
||
|
this, "选择文件",
|
||
|
"./",
|
||
|
"");
|
||
|
emit calFileMd5Signal(path);
|
||
|
}
|
||
|
|
||
3 years ago
|
void MainWindow::showFileMd5Slot(const QByteArray & md5) {
|
||
3 years ago
|
ui->leMd5Show->setText("");
|
||
|
ui->leMd5Show->setText(md5);
|
||
|
}
|
||
|
|
||
3 years ago
|
void MainWindow::selectDirSlot() {
|
||
3 years ago
|
ui->progressBar->setValue(0);
|
||
|
QString dirPathUrl = QFileDialog::getExistingDirectory(this, "选择文件夹", "./");
|
||
|
ui->lineDIrShow->setText(dirPathUrl);
|
||
|
emit getFilesSignal(dirPathUrl);
|
||
|
}
|
||
|
|
||
3 years ago
|
void MainWindow::filesSlot(const QStringList &files) {
|
||
3 years ago
|
ui->listWidget_2->clear();
|
||
|
ui->listWidget_2->addItems(files);
|
||
|
}
|
||
|
|
||
3 years ago
|
void MainWindow::processSlot(const int &now, const int &total) {
|
||
3 years ago
|
ui->progressBar->setMaximum(total);
|
||
|
ui->progressBar->setValue(now);
|
||
|
}
|
||
|
|
||
3 years ago
|
void MainWindow::duplicateFilesSlot(const QHash<QByteArray, QStringList> &duplicateFiles) {
|
||
3 years ago
|
ui->listWidget->clear();
|
||
|
this->duplicateResults = duplicateFiles;
|
||
|
for(QHash<QByteArray, QStringList>::const_iterator itr = duplicateFiles.begin(); itr != duplicateFiles.end(); itr++){
|
||
|
ui->listWidget->addItem(itr.key());
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
void MainWindow::currentTextChangedSlot(const QString ¤tText) {
|
||
3 years ago
|
ui->listWidget_2->clear();
|
||
|
ui->listWidget_2->addItems(this->duplicateResults[currentText.toLocal8Bit()]);
|
||
|
}
|
||
|
|
||
3 years ago
|
void MainWindow::on_listWidget_customContextMenuRequested(const QPoint &pos)
|
||
3 years ago
|
{
|
||
|
// 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;
|
||
|
}
|
||
|
|
||
3 years ago
|
void MainWindow::delActionFeedbackSlot(bool flag) {
|
||
3 years ago
|
if(flag){
|
||
|
qDebug()<<"remove item";
|
||
|
QListWidgetItem * item = ui->listWidget_2->currentItem();
|
||
|
qDebug()<<item;
|
||
|
ui->listWidget_2->removeItemWidget(item);
|
||
|
delete item;
|
||
|
}
|
||
3 years ago
|
}
|