From 40e4368c0cc7afba7dcc4b6707c560e91db39c48 Mon Sep 17 00:00:00 2001 From: Alexander-Porter Date: Wed, 10 Jul 2024 10:20:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=9C=A8=E5=AD=90=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E4=B8=AD=E9=81=8D=E5=8E=86=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- filefunc.cpp | 11 +---------- filefunc.h | 28 ++++++++-------------------- mainwindow.cpp | 3 ++- synccore.cpp | 6 +++--- 4 files changed, 14 insertions(+), 34 deletions(-) diff --git a/filefunc.cpp b/filefunc.cpp index f4cd1d7..481d78a 100644 --- a/filefunc.cpp +++ b/filefunc.cpp @@ -1,6 +1,7 @@ #include "filefunc.h" +//用多线程遍历本地文件夹 void Filefunc::readDirectory(const QString &path) { // 清空之前的文件列表 @@ -8,9 +9,6 @@ void Filefunc::readDirectory(const QString &path) // 递归读取文件夹和子文件夹 recursiveRead(path); - - // 发出文件列表更新信号 - emit fileListUpdated(path, fileInfoList); } void Filefunc::recursiveRead(const QString &path) @@ -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; -} - diff --git a/filefunc.h b/filefunc.h index b5b0b94..cdd01a6 100644 --- a/filefunc.h +++ b/filefunc.h @@ -1,6 +1,7 @@ #ifndef FILEFUNC_H #define FILEFUNC_H +#include "qthread.h" #include #include #include @@ -8,32 +9,19 @@ #include #include -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);//比较两端文件时间,若本地文件时间新则返回真 }; diff --git a/mainwindow.cpp b/mainwindow.cpp index d9a40f4..59f850b 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -19,6 +19,8 @@ #include"filemange_view.h" #include "historysync_view.h" #include"historyview.h" +#include "filefunc.h" +#include "qthread.h" MainWindow::MainWindow(QWidget *parent) : ElaWindow(parent) @@ -26,7 +28,6 @@ MainWindow::MainWindow(QWidget *parent) db = new DatabaseManager(this); // 创建数据库管理器实例 db->initializeDatabase(); // 初始化数据库 - // ElaApplication::getInstance()->setThemeMode(ElaApplicationType::Dark); // setIsNavigationBarEnable(false); // setNavigationBarDisplayMode(ElaNavigationType::Minimal); diff --git a/synccore.cpp b/synccore.cpp index 01b7d28..a127c32 100644 --- a/synccore.cpp +++ b/synccore.cpp @@ -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) From da7cb402757861a361e6b01401d39908e23befb7 Mon Sep 17 00:00:00 2001 From: kuiling <3110428854@qq.com> Date: Wed, 10 Jul 2024 10:22:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E4=BA=86=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E6=96=B0=E6=96=87=E4=BB=B6=E5=A4=B9=E7=9A=84debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- linknewfolder_window.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/linknewfolder_window.cpp b/linknewfolder_window.cpp index 3f0b4ac..b3456ea 100644 --- a/linknewfolder_window.cpp +++ b/linknewfolder_window.cpp @@ -102,6 +102,11 @@ linkNewFolder_window::linkNewFolder_window(QWidget *parent) QStringList comboList{"仅上传", "仅下载", "同步上传与下载"}; _comboBox->addItems(comboList); _comboBox->setFixedWidth(140); + // 创建一个映射,将文本选项映射到数字 + QMap comboOptionToNumber; + comboOptionToNumber["仅上传"] = 0; + comboOptionToNumber["仅下载"] = 1; + comboOptionToNumber["同步上传与下载"] = 2; QWidget* buttonArea = new QWidget(); buttonArea->setWindowFlags(Qt::FramelessWindowHint); // 去除窗口边框 @@ -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; } });