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
RaidenShogunShadow committed Jul 10, 2024
2 parents 10a74e6 + d5da921 commit 4a3dc3d
Show file tree
Hide file tree
Showing 17 changed files with 162 additions and 70 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
xmlprocesser.h xmlprocesser.cpp
bucket.h bucket.cpp
messagechannel.h messagechannel.cpp
dircardproxy.h dircardproxy.cpp

modifyinfor_win.h modifyinfor_win.cpp
cancelaccount_win.h cancelaccount_win.cpp

Expand Down
2 changes: 1 addition & 1 deletion cosclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool COSClient::save2Local(const QString &path, const QString &localpath, const
return true;
}

preResponse COSClient::headObject(const QString &path, const QString &localpath,const QString &versionId, headHeader &reqHeader)
preResponse COSClient::headObject(const QString &path,const QString &versionId, headHeader &reqHeader)
{
preRequest request;
if(!versionId.isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion cosclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class COSClient : public QObject
QString completeMultipartUpload(QString path, QString uploadId, QMap<int, QString> partEtagMap);
QByteArray getObject(const QString &path,const QString &versionId, QMap<QString,QString> &respHeaders);
bool save2Local(const QString &path, const QString &localpath,const QString &versionId, QMap<QString,QString> &respMetaDatas);
preResponse headObject(const QString &path, const QString &localpath,const QString &versionId, headHeader &reqHeader);
preResponse headObject(const QString &path,const QString &versionId, headHeader &reqHeader);
preResponse deleteObject(const QString &path, const QString &versionId);
QString multiUpload(const QString &path, const QString &localpath, QMap<QString,QString> metaDatas=QMap<QString,QString>());
bool isExist(preResponse &response);//和headobject一起使用,判断文件是否存在
Expand Down
37 changes: 37 additions & 0 deletions dircardproxy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "dircardproxy.h"

#include"DirCard.h"
#include<QVBoxLayout>

DirCardProxy::DirCardProxy(QWidget *parent) : QWidget(parent) {
parentWidget = qobject_cast<QWidget*>(parent);
filesLayout=new QVBoxLayout(this);
}

DirCardProxy::~DirCardProxy() {
cardMap.clear();
}

void DirCardProxy::addDirCard(DirCard *card, const QString &id) {
if (card && parentWidget && !cardMap.contains(id)) {
cardMap[id] = card;
// 在这里可以将card添加到UI中,例如使用布局管理器
/*QVBoxLayout *layout = qobject_cast<QVBoxLayout*>(parentWidget->layout());
layout->setAlignment(Qt::AlignTop);
if (layout) {
layout->addWidget(card);
}*/
filesLayout->addWidget(card);
filesLayout->setAlignment(Qt::AlignTop);
}
}

void DirCardProxy::removeDirCard(const QString &id) {
if (cardMap.contains(id)) {
DirCard *card = cardMap.take(id);
// 在这里可以从UI中移除card
filesLayout->removeWidget(card);
card->setParent(nullptr);
card->deleteLater();
}
}
24 changes: 24 additions & 0 deletions dircardproxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef DIRCARDPROXY_H
#define DIRCARDPROXY_H

#include <QMap>
#include <QWidget>

class DirCard;
class QVBoxLayout;
class DirCardProxy : public QWidget {
Q_OBJECT
public:
explicit DirCardProxy(QWidget *parent = nullptr);
~DirCardProxy() override;

void addDirCard(DirCard *card, const QString &id);
void removeDirCard(const QString &id);
QVBoxLayout*filesLayout;

private:
QMap<QString, DirCard*> cardMap;
QWidget *parentWidget;
};

#endif // DIRCARDPROXY_H
16 changes: 11 additions & 5 deletions filefunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
//用多线程遍历本地文件夹
void Filefunc::readDirectory(const QString &path)
{
// 清空之前的文件列表
fileInfoList.clear();

// 递归读取文件夹和子文件夹
recursiveRead(path);
}
Expand All @@ -22,10 +19,19 @@ void Filefunc::recursiveRead(const QString &path)
recursiveRead(info.filePath());
} else {
// 如果是文件,添加到文件信息列表
fileInfoList.append(info);
qDebug()<<info.fileName();
addSynctask(info.absoluteFilePath());
}
}
}

void Filefunc::addSynctask(const QString &path)
{
//把path前面和task->getLocalPath()相同的部分去掉
QString relativePath=path.mid(task->getLocalPath().length()+1);
QString cloudPath=task->getRemotePath()+relativePath;
headHeader tmpHeaders;
preResponse response=cosclient->headObject(cloudPath,"",tmpHeaders);
response.getMetaDatas().isEmpty();
}


11 changes: 9 additions & 2 deletions filefunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define FILEFUNC_H

#include "qthread.h"
#include "synctask.h"
#include "cosclient.h"
#include <QObject>
#include <QDir>
#include <QFileInfoList>
Expand All @@ -14,14 +16,19 @@ class Filefunc : public QThread

public:
QString path;
Filefunc(QString path):path(path){};
COSClient* cosclient;
SyncTask* task;
Filefunc(QString pathi,COSClient* cosclienti,SyncTask* taski):path(pathi),cosclient(cosclienti),task(taski){};
void run() override
{
readDirectory(path);
}
void readDirectory(const QString &path);
void recursiveRead(const QString &path);
QFileInfoList fileInfoList;

void addSynctask(const QString &path);//添加同步任务,把本地未上传文件添加入任务
void deleteSynctask(const QString &path);//删除同步任务,把本地已上传文件删除任务
void updateSynctask(const QString &path);//更新同步任务,把本地已上传文件更新任务
};


Expand Down
65 changes: 18 additions & 47 deletions filemange_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include"ElaScrollArea.h"

#include"DirCard.h"
#include"dircardproxy.h"

FileManagePage::FileManagePage(QWidget* parent):ElaScrollPage(parent)
{
Expand Down Expand Up @@ -44,7 +45,6 @@ FileManagePage::FileManagePage(QWidget* parent):ElaScrollPage(parent)
// 将进度条文本标签和进度条控件添加到布局中
progressBarLayout->addWidget(progressBarText);
progressBarLayout->addWidget(_progressBar);

// 创建一个 ElaToggleButton 对象,设置其标签为 "Head" 并指定其父对象
_pushButton1 = new ElaPushButton("解除绑定", this);
_pushButton1->setFixedSize(100, 40); // 设置按钮的固定大小
Expand Down Expand Up @@ -102,44 +102,20 @@ FileManagePage::FileManagePage(QWidget* parent):ElaScrollPage(parent)
// 创建QScrollArea用于包裹files
ElaScrollArea* scrollArea = new ElaScrollArea();
scrollArea->viewport()->setStyleSheet("background:transparent;");//设置背景透明
DirCard*DirCardArea1=new DirCard("文件1","1.0GB","2024.7.1");
DirCard*DirCardArea2=new DirCard("文件2","2.0GB","2024.7.2");
DirCard*DirCardArea3=new DirCard("文件3","3.0GB","2024.7.3");
DirCard*DirCardArea4=new DirCard("文件4","4.0GB","2024.7.4");
DirCard*DirCardArea5=new DirCard("文件5","5.0GB","2024.7.5");
DirCard*DirCardArea6=new DirCard("文件6","6.0GB","2024.7.6");
DirCard*DirCardArea7=new DirCard("文件7","7.0GB","2024.7.7");
DirCard*DirCardArea8=new DirCard("文件8","8.0GB","2024.7.8");
DirCard*DirCardArea9=new DirCard("文件9","9.0GB","2024.7.9");
DirCard*DirCardArea10=new DirCard("文件10","10.0GB","2024.7.10");

connect(DirCardArea1,&DirCard::relieve,this,&FileManagePage::removeDirCard);
connect(DirCardArea2,&DirCard::relieve,this,&FileManagePage::removeDirCard);
connect(DirCardArea3,&DirCard::relieve,this,&FileManagePage::removeDirCard);
connect(DirCardArea4,&DirCard::relieve,this,&FileManagePage::removeDirCard);
connect(DirCardArea5,&DirCard::relieve,this,&FileManagePage::removeDirCard);
connect(DirCardArea6,&DirCard::relieve,this,&FileManagePage::removeDirCard);
connect(DirCardArea7,&DirCard::relieve,this,&FileManagePage::removeDirCard);
connect(DirCardArea8,&DirCard::relieve,this,&FileManagePage::removeDirCard);
connect(DirCardArea9,&DirCard::relieve,this,&FileManagePage::removeDirCard);
connect(DirCardArea10,&DirCard::relieve,this,&FileManagePage::removeDirCard);


QWidget* filesWidget=new QWidget();
filesLayout=new QVBoxLayout(filesWidget);
filesLayout->addWidget(DirCardArea1);
filesLayout->addWidget(DirCardArea2);
filesLayout->addWidget(DirCardArea3);
filesLayout->addWidget(DirCardArea4);
filesLayout->addWidget(DirCardArea5);
filesLayout->addWidget(DirCardArea6);
filesLayout->addWidget(DirCardArea7);
filesLayout->addWidget(DirCardArea8);
filesLayout->addWidget(DirCardArea9);
filesLayout->addWidget(DirCardArea10);
filesLayout->setAlignment(Qt::AlignTop);

scrollArea->setWidget(filesWidget); // 设置scrollArea的内容部件
_dircardProxy=new DirCardProxy(this);
addDirCard("文件1","1.0GB","2024.7.1");
addDirCard("文件2","2.0GB","2024.7.2");
addDirCard("文件3","3.0GB","2024.7.3");
addDirCard("文件4","4.0GB","2024.7.4");
addDirCard("文件5","5.0GB","2024.7.5");
addDirCard("文件6","6.0GB","2024.7.6");
addDirCard("文件7","7.0GB","2024.7.7");
addDirCard("文件8","8.0GB","2024.7.8");
addDirCard("文件9","9.0GB","2024.7.9");
addDirCard("文件10","10.0GB","2024.7.10");

scrollArea->setWidget(_dircardProxy);
scrollArea->setWidgetResizable(true); // 允许scrollArea根据内容自动调整大小

centerVLayout->addWidget(progressBarArea); // 将上方固定区域添加到布局中
Expand All @@ -158,16 +134,11 @@ FileManagePage::~FileManagePage()
void FileManagePage::addDirCard(QString filename,QString datasize,QString bingtime)
{
DirCard*newDir=new DirCard(filename,datasize,bingtime);
connect(newDir,&DirCard::relieve,this,&FileManagePage::removeDirCard);
filesLayout->addWidget(newDir);
qDebug()<<connect(newDir,&DirCard::relieve,this,&FileManagePage::removeDirCard);
_dircardProxy->addDirCard(newDir,filename+datasize+bingtime);
}

void FileManagePage::removeDirCard()
void FileManagePage::removeDirCard(QString id)
{
DirCard *card = qobject_cast<DirCard*>(sender());
if (card)
{
layout()->removeWidget(card);
card->setVisible(false);
}
_dircardProxy->removeDirCard(id);
}
8 changes: 5 additions & 3 deletions filemange_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ class ElaToggleButton;
class ElaPushButton;
class DirCard;
class QVBoxLayout;
class DirCardProxy;
class FileManagePage:public ElaScrollPage
{
public:
FileManagePage(QWidget* parent = nullptr);
~FileManagePage();
void addDirCard(QString filename,QString datasize,QString bingtime);
void removeDirCard();
QVBoxLayout*filesLayout;
void removeDirCard(QString id);
DirCardProxy*_dircardProxy;
linkNewFolder_window* linknewfolderwindow=new linkNewFolder_window();

private:
ElaProgressBar* _progressBar{nullptr};
ElaPushButton* _pushButton1{nullptr};
ElaPushButton* _pushButton2{nullptr};
ElaPushButton* _pushButton3{nullptr};
ElaToggleButton* _toggleButton{nullptr};
linkNewFolder_window* linknewfolderwindow=new linkNewFolder_window();

setExcludedItems_view* setexcludeditemsview=new setExcludedItems_view();
};

Expand Down
11 changes: 7 additions & 4 deletions linknewfolder_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ElaText.h"
#include "ElaComboBox.h"
#include "ElaMessageBar.h"
#include "synctask.h"

linkNewFolder_window::linkNewFolder_window(QWidget *parent)
: ElaWidget(parent,900,400)
Expand Down Expand Up @@ -104,9 +105,9 @@ linkNewFolder_window::linkNewFolder_window(QWidget *parent)
_comboBox->setFixedWidth(140);
// 创建一个映射,将文本选项映射到数字
QMap<QString, int> comboOptionToNumber;
comboOptionToNumber["仅上传"] = 0;
comboOptionToNumber["仅下载"] = 1;
comboOptionToNumber["同步上传与下载"] = 2;
comboOptionToNumber["仅上传"] = 2;
comboOptionToNumber["仅下载"] = 3;
comboOptionToNumber["同步上传与下载"] = 1;

QWidget* buttonArea = new QWidget();
buttonArea->setWindowFlags(Qt::FramelessWindowHint); // 去除窗口边框
Expand Down Expand Up @@ -137,7 +138,9 @@ linkNewFolder_window::linkNewFolder_window(QWidget *parent)
qDebug() << "本地文件夹地址:" << folderName1->text();
qDebug() << "云端文件夹地址:" << folderName2->text();
int syncOption = comboOptionToNumber[_comboBox->currentText()];
qDebug() << "同步方式:" << syncOption;//["仅上传"] = 0;["仅下载"] = 1;["同步上传与下载"] = 2;
qDebug() << "同步方式:" << syncOption;//["仅上传"] = 2;["仅下载"] = 3;["同步上传与下载"] = 1;
SyncTask task(folderName1->text(), folderName2->text(), syncOption);
emit onNewTask(task);
}
});

Expand Down
5 changes: 4 additions & 1 deletion linknewfolder_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

#include <QWidget>
#include "ElaWidget.h"

#include "synctask.h"
class ElaPushButton;
class ElaCheckBox;
class ElaComboBox;
class linkNewFolder_window : public ElaWidget
{
Q_OBJECT
public:
linkNewFolder_window(QWidget *parent = nullptr);
~linkNewFolder_window();
signals:
void onNewTask(const SyncTask &task);
private:
ElaPushButton* _pushButton1{nullptr};
ElaPushButton* _pushButton2{nullptr};
Expand Down
26 changes: 25 additions & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "ElaMessageBar.h"
#include "ElaWidget.h"
#include "homeView.h"
#include "linknewfolder_window.h"
#include "DirCard.h"
#include "loginwin.h"
#include "syncing_view.h"
Expand Down Expand Up @@ -55,6 +56,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(login,&loginwin::needPassword,this,&MainWindow::onNeedPassword);
connect(signin, &signinwin::on_signin_complete, this, &MainWindow::insertUserToDatabase);
qDebug()<<connect(login->channel,&MessageChannel::message,this,&MainWindow::onMessage);
connect(_filemanagePage->linknewfolderwindow,&linkNewFolder_window::onNewTask,this,&MainWindow::onUserAddNewTask);
// GraphicsView
ElaGraphicsScene *scene = new ElaGraphicsScene(this);
scene->setSceneRect(0, 0, 1500, 1500);
Expand Down Expand Up @@ -194,7 +196,8 @@ void MainWindow::onUserLoggedIn(User user)
db->insertUser(user.getEmail(),user.gethashedPassword());
setUserInfoCardTitle(user.getUsername());
setUserInfoCardSubTitle(user.getEmail());

_syncCore=new SyncCore(this);
_syncTaskDatabaseManager=new SyncTaskDatabaseManager(CurrentUser);
QString url=user.avatarpath;
QNetworkAccessManager *manager = new QNetworkAccessManager();
QNetworkRequest request;
Expand Down Expand Up @@ -267,6 +270,27 @@ void MainWindow::onMessage( QString message, QString type)
}
}

void MainWindow::onUserAddNewTask(const SyncTask &task)
{
if(CurrentUser==nullptr)
{
onMessage("请先登录","Error");
return;
}
if(
CurrentUser->addTask(task.getLocalPath(),task.getRemotePath(),task.getSyncStatus(),1,1)){
if(_syncCore!=nullptr)
{
SyncTask mytask(task);
_syncCore->addTask(&mytask);
}
if(_syncTaskDatabaseManager!=nullptr)
{
_syncTaskDatabaseManager->addTask(task);
}
}
}

void MainWindow::onCloseButtonClicked()
{
ElaContentDialog *dialag = new ElaContentDialog(this);
Expand Down
Loading

0 comments on commit 4a3dc3d

Please sign in to comment.