Skip to content

Commit

Permalink
Merge branch 'main' of https://gitee.com/opguess/QSyncUi
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipper209 committed Jul 10, 2024
2 parents 62401d1 + 09ac17d commit 76e290f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 34 deletions.
11 changes: 1 addition & 10 deletions filefunc.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#include "filefunc.h"


//用多线程遍历本地文件夹
void Filefunc::readDirectory(const QString &path)
{
// 清空之前的文件列表
fileInfoList.clear();

// 递归读取文件夹和子文件夹
recursiveRead(path);

// 发出文件列表更新信号
emit fileListUpdated(path, fileInfoList);
}

void Filefunc::recursiveRead(const QString &path)
Expand All @@ -30,11 +28,4 @@ void Filefunc::recursiveRead(const QString &path)
}
}

bool Filefunc::comparetime(QDateTime localtime,QString cloudtimestr){
//QString localtime=info.metadataChangeTime().toMSecsSinceEpoch();
// 使用QString的fromString方法和Qt的ISODate格式来解析时间字符串
QDateTime cloudtime=QDateTime::fromString(cloudtimestr, Qt::ISODate);
return localtime>=cloudtime;
}


28 changes: 8 additions & 20 deletions filefunc.h
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
#ifndef FILEFUNC_H
#define FILEFUNC_H

#include "qthread.h"
#include <QObject>
#include <QDir>
#include <QFileInfoList>
#include <QFileInfo>
#include <QDateTime>
#include <QString>

class Filefunc : public QObject
class Filefunc : public QThread
{
Q_OBJECT

public:
explicit Filefunc(QObject *parent = nullptr) : QObject(parent) {}

public slots:
// 读取文件夹及其子文件夹中的所有文件
QString path;
Filefunc(QString path):path(path){};
void run() override
{
readDirectory(path);
}
void readDirectory(const QString &path);

private slots:
// 递归遍历文件夹和子文件夹
void recursiveRead(const QString &path);

private:
// 存储文件信息列表
QFileInfoList fileInfoList;

signals:
void fileListUpdated(const QString &path, const QFileInfoList &list);

public:
// 获取文件信息列表
QFileInfoList getFileInfoList() const { return fileInfoList; }
bool comparetime(QDateTime localtime,QString cloudtimestr);//比较两端文件时间,若本地文件时间新则返回真
};


Expand Down
9 changes: 9 additions & 0 deletions linknewfolder_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ linkNewFolder_window::linkNewFolder_window(QWidget *parent)
QStringList comboList{"仅上传", "仅下载", "同步上传与下载"};
_comboBox->addItems(comboList);
_comboBox->setFixedWidth(140);
// 创建一个映射,将文本选项映射到数字
QMap<QString, int> comboOptionToNumber;
comboOptionToNumber["仅上传"] = 0;
comboOptionToNumber["仅下载"] = 1;
comboOptionToNumber["同步上传与下载"] = 2;

QWidget* buttonArea = new QWidget();
buttonArea->setWindowFlags(Qt::FramelessWindowHint); // 去除窗口边框
Expand Down Expand Up @@ -129,6 +134,10 @@ linkNewFolder_window::linkNewFolder_window(QWidget *parent)
// 如果输入符合要求,执行后续操作
this->hide();
ElaMessageBar::success(ElaMessageBarType::TopRight,"链接成功", "新文件夹链接成功。", 2000);
qDebug() << "本地文件夹地址:" << folderName1->text();
qDebug() << "云端文件夹地址:" << folderName2->text();
int syncOption = comboOptionToNumber[_comboBox->currentText()];
qDebug() << "同步方式:" << syncOption;//["仅上传"] = 0;["仅下载"] = 1;["同步上传与下载"] = 2;
}
});

Expand Down
3 changes: 2 additions & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
#include"filemange_view.h"
#include "historysync_view.h"
#include"historyview.h"
#include "filefunc.h"
#include "qthread.h"

MainWindow::MainWindow(QWidget *parent)
: ElaWindow(parent)
{

db = new DatabaseManager(this); // 创建数据库管理器实例
db->initializeDatabase(); // 初始化数据库

// ElaApplication::getInstance()->setThemeMode(ElaApplicationType::Dark);
// setIsNavigationBarEnable(false);
// setNavigationBarDisplayMode(ElaNavigationType::Minimal);
Expand Down
6 changes: 3 additions & 3 deletions synccore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ void SyncCore::filesystemChanged(struct event e)
void SyncCore::addTask(SyncTask *task)
{
QDir listen=task->localPath;
Filefunc *filefunc=new Filefunc(this);
connect(filefunc, &Filefunc::fileListUpdated, this, &SyncCore::onFileListUpdated, Qt::QueuedConnection);
filefunc->readDirectory(listen.absolutePath());
//Filefunc *filefunc=new Filefunc(this);
//connect(filefunc, &Filefunc::fileListUpdated, this, &SyncCore::onFileListUpdated, Qt::QueuedConnection);
//filefunc->readDirectory(listen.absolutePath());
if(task==nullptr)
return;
if(task->localPath.exists()==false)
Expand Down

0 comments on commit 76e290f

Please sign in to comment.