Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kuilinggg committed Jul 8, 2024
2 parents aeea170 + 7c1f2da commit 8b6eb11
Show file tree
Hide file tree
Showing 23 changed files with 493 additions and 59 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
filequeue.h filequeue.cpp
storage.h storage.cpp
linknewfolder_window.h linknewfolder_window.cpp
tasktoken.h tasktoken.cpp
filecard.h filecard.cpp
historycard.h historycard.cpp


)
Expand Down
11 changes: 5 additions & 6 deletions databasemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ bool DatabaseManager::insertUser(const QString &account, const QString &hashedPa
return true;
}

bool DatabaseManager::updateUserInfo(const QString &account,
const QString &newId,
const QString &newHashedPassword)
bool DatabaseManager::updateUserInfo(const QString &account,const QString &newHashedPassword)
{
QSqlQuery query;
query.prepare("UPDATE Users SET account = :newId, hashedPassword = :newHashedPassword WHERE account = :account");
query.bindValue(":newId", newId);
query.prepare("UPDATE Users SET hashedPassword = :newHashedPassword WHERE account = :account");
query.bindValue(":newHashedPassword", newHashedPassword);
query.bindValue(":account", account);

Expand All @@ -75,7 +72,7 @@ bool DatabaseManager::insertUser(const QString &account, const QString &hashedPa
}

// 更新账号密码映射
accountPasswordMap_[newId] = newHashedPassword;
accountPasswordMap_[account] = newHashedPassword;

return true;
}
Expand Down Expand Up @@ -111,3 +108,5 @@ QPair<QString, QString> DatabaseManager::getUserPassword(const QString &account)
// 如果没有找到匹配的账号,返回空值
return userPassword;
}


2 changes: 1 addition & 1 deletion databasemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DatabaseManager : public QObject
QMap<QString,QString>accountPasswordMap_;
public:
explicit DatabaseManager(QObject *parent = nullptr);
bool updateUserInfo(const QString &account, const QString &newId, const QString &newHashedPassword);
bool updateUserInfo(const QString &account, const QString &newHashedPassword);
bool initializeDatabase();
bool insertUser(const QString &account, const QString &hashedPassword);
QList<QString>getAllAccounts();
Expand Down
58 changes: 58 additions & 0 deletions filecard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "filecard.h"

#include<QVBoxLayout>
#include"ElaCheckBox.h"
#include"ElaIconButton.h"
#include"ElaProgressBar.h"
FileCard::FileCard(QString f, QString d,QString s,QString p)
{
filename=new ElaText(f);
datasize=new ElaText(d);
speed=new ElaText(s);
progress=new ElaText(p);

_checkBox = new ElaCheckBox(filename->text(), this);
QVBoxLayout*checkBoxArea=new QVBoxLayout();
checkBoxArea->addWidget(_checkBox,0,Qt::AlignCenter);

datasize->setTextSize(16);
QVBoxLayout*dataSizeArea=new QVBoxLayout();
dataSizeArea->addWidget(datasize,0,Qt::AlignCenter);

speed->setTextSize(16);
QVBoxLayout*speedArea=new QVBoxLayout();
speedArea->addWidget(speed,0,Qt::AlignCenter);

proBar = new ElaProgressBar(this);
proBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
proBar->setFixedSize(100,15);
proBar->setMinimum(0);
proBar->setMaximum(0);
progress->setTextSize(16);
QVBoxLayout*proBarArea=new QVBoxLayout();
proBarArea->addWidget(progress,0,Qt::AlignCenter);
proBarArea->addWidget(proBar,0,Qt::AlignCenter);
proBarArea->setAlignment(Qt::AlignCenter);

modifyBtn=new ElaIconButton(ElaIconType::CalendarLinesPen);
pauseBtn=new ElaIconButton(ElaIconType::Pause);
relieveBtn=new ElaIconButton(ElaIconType::Xmark);
modifyBtn->setFixedSize(30,30);
pauseBtn->setFixedSize(30,30);
relieveBtn->setFixedSize(30,30);

QHBoxLayout*actionArea=new QHBoxLayout();
actionArea->addWidget(modifyBtn);
actionArea->addWidget(pauseBtn);
actionArea->addWidget(relieveBtn);
actionArea->setAlignment(Qt::AlignCenter);

QHBoxLayout*FileCardArea=new QHBoxLayout(this);
FileCardArea->addLayout(checkBoxArea,Qt::AlignCenter);
FileCardArea->addLayout(dataSizeArea,Qt::AlignCenter);
FileCardArea->addLayout(speedArea,Qt::AlignCenter);
FileCardArea->addLayout(proBarArea,Qt::AlignCenter);
FileCardArea->addLayout(actionArea,Qt::AlignCenter);
FileCardArea->addStretch();

}
26 changes: 26 additions & 0 deletions filecard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef FILECARD_H
#define FILECARD_H

#include"ElaScrollPageArea.h"
#include"ElaText.h"

class ElaCheckBox;
class ElaIconButton;
class ElaProgressBar;
class FileCard : public ElaScrollPageArea
{
public:
explicit FileCard(QString f, QString d,QString s,QString p);

ElaCheckBox* _checkBox{nullptr};
ElaText *filename;
ElaText *datasize;
ElaText *speed;
ElaText*progress;
ElaIconButton*modifyBtn;
ElaIconButton*pauseBtn;
ElaIconButton*relieveBtn;
ElaProgressBar*proBar;
};

#endif // FILECARD_H
1 change: 0 additions & 1 deletion filemange_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ FileManagePage::FileManagePage(QWidget* parent):ElaScrollPage(parent)
centerVLayout->addWidget(pushButtonArea); // 将切换按钮容器添加到布局中
centerVLayout->addWidget(catalogueArea); // 将目录文本添加到布局中
centerVLayout->addWidget(scrollArea); // 将scrollArea添加到布局中
//centerVLayout->addStretch(); // 在布局的末尾添加一个弹性空间

this->addCentralWidget(centralWidget); // 将中心部件添加到窗口
}
Expand Down
42 changes: 42 additions & 0 deletions historycard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "historycard.h"

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

HistoryCard::HistoryCard(QString f, QString d,QString t,bool u)
{
filename=new ElaText(f);
datasize=new ElaText(d);
time=new ElaText(t);

_checkBox = new ElaCheckBox(filename->text(), this);
QVBoxLayout*checkBoxArea=new QVBoxLayout();
checkBoxArea->addWidget(_checkBox,0,Qt::AlignCenter);

datasize->setTextSize(16);
QVBoxLayout*dataSizeArea=new QVBoxLayout();
dataSizeArea->addWidget(datasize,0,Qt::AlignCenter);

time->setTextSize(16);
QVBoxLayout*timeArea=new QVBoxLayout();
ElaText*text;
if(u)
text=new ElaText("上传于");
else
text=new ElaText("下载于");
text->setTextSize(16);
timeArea->addWidget(text,0,Qt::AlignCenter);
timeArea->addWidget(time,0,Qt::AlignCenter);

ElaText*bingoText=new ElaText("");
bingoText->setTextSize(16);
QVBoxLayout*bingoArea=new QVBoxLayout();
bingoArea->addWidget(bingoText,0,Qt::AlignCenter);

QHBoxLayout*HistoryCardArea=new QHBoxLayout(this);
HistoryCardArea->addLayout(checkBoxArea,Qt::AlignCenter);
HistoryCardArea->addLayout(dataSizeArea,Qt::AlignCenter);
HistoryCardArea->addLayout(timeArea,Qt::AlignCenter);
HistoryCardArea->addLayout(bingoArea,Qt::AlignCenter);
HistoryCardArea->addStretch();
}
22 changes: 22 additions & 0 deletions historycard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef HISTORYCARD_H
#define HISTORYCARD_H

#include"ElaScrollPageArea.h"
#include"ElaText.h"

class ElaCheckBox;
class ElaIconButton;
class ElaProgressBar;
class HistoryCard : public ElaScrollPageArea
{
public:
explicit HistoryCard(QString f, QString d,QString t,bool u);

ElaCheckBox* _checkBox{nullptr};
ElaText *filename;
ElaText *datasize;
ElaText *time;
bool upif;
};

#endif // HISTORYCARD_H
41 changes: 39 additions & 2 deletions historysync_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "ElaPushButton.h"
#include "ElaToggleButton.h"
#include <QVBoxLayout>
#include"historycard.h"
#include"ElaScrollArea.h"

HistorysyncPage::HistorysyncPage(QWidget* parent)
: ElaScrollPage(parent)
Expand Down Expand Up @@ -57,17 +59,52 @@ HistorysyncPage::HistorysyncPage(QWidget* parent)
catalogueText5->setAlignment(Qt::AlignCenter); // 设置文本居中对齐
catalogueLayout->addWidget(catalogueText1);
catalogueLayout->addWidget(catalogueText2);
//catalogueLayout->addStretch();
catalogueLayout->addWidget(catalogueText4);
catalogueLayout->addWidget(catalogueText5);

ElaScrollArea* scrollArea = new ElaScrollArea();
scrollArea->viewport()->setStyleSheet("background:transparent;");//设置背景透明
HistoryCard*HistoryCardArea1=new HistoryCard("文件1","3.5GB","2024.7.1",0);
HistoryCard*HistoryCardArea2=new HistoryCard("文件2","3.5GB","2024.7.2",0);
HistoryCard*HistoryCardArea3=new HistoryCard("文件3","3.5GB","2024.7.3",1);
HistoryCard*HistoryCardArea4=new HistoryCard("文件4","3.5GB","2024.7.4",0);
HistoryCard*HistoryCardArea5=new HistoryCard("文件5","3.5GB","2024.7.5",1);
HistoryCard*HistoryCardArea6=new HistoryCard("文件6","3.5GB","2024.7.6",1);
HistoryCard*HistoryCardArea7=new HistoryCard("文件7","3.5GB","2024.7.7",1);
HistoryCard*HistoryCardArea8=new HistoryCard("文件8","3.5GB","2024.7.8",0);
HistoryCard*HistoryCardArea9=new HistoryCard("文件9","3.5GB","2024.7.9",0);
HistoryCard*HistoryCardArea10=new HistoryCard("文件10","3.5GB","2024.7.10",1);

QWidget* filesWidget=new QWidget();
filesLayout=new QVBoxLayout(filesWidget);
filesLayout->addWidget(HistoryCardArea1);
filesLayout->addWidget(HistoryCardArea2);
filesLayout->addWidget(HistoryCardArea3);
filesLayout->addWidget(HistoryCardArea4);
filesLayout->addWidget(HistoryCardArea5);
filesLayout->addWidget(HistoryCardArea6);
filesLayout->addWidget(HistoryCardArea7);
filesLayout->addWidget(HistoryCardArea8);
filesLayout->addWidget(HistoryCardArea9);
filesLayout->addWidget(HistoryCardArea10);
filesLayout->setAlignment(Qt::AlignTop);

scrollArea->setWidget(filesWidget); // 设置scrollArea的内容部件
scrollArea->setWidgetResizable(true); // 允许scrollArea根据内容自动调整大小

centerVLayout->addWidget(progressBarArea); // 将上方固定区域添加到布局中
centerVLayout->addWidget(catalogueArea); // 将目录文本添加到布局中
centerVLayout->addStretch(); // 在布局的末尾添加一个弹性空间
centerVLayout->addWidget(scrollArea);

this->addCentralWidget(centralWidget); // 将中心部件添加到窗口中
}

HistorysyncPage::~HistorysyncPage()
{
}

void HistorysyncPage::addHistory(QString filename, QString datasize,QString time,bool upif)
{
HistoryCard*historyCard=new HistoryCard(filename,datasize,time,upif);
filesLayout->addWidget(historyCard);
}
3 changes: 3 additions & 0 deletions historysync_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
#include "ElaScrollPage.h"
#include "ElaScrollPageArea.h"

class QVBoxLayout;
class HistorysyncPage : public ElaScrollPage
{
public:
HistorysyncPage(QWidget* parent = nullptr);
~HistorysyncPage();
QVBoxLayout*filesLayout;
void addHistory(QString filename, QString datasize,QString time,bool upif);
private:
ElaProgressBar* _progressBar{nullptr};
};
Expand Down
22 changes: 12 additions & 10 deletions loginwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,25 @@ loginwin::loginwin(QWidget* parent):ElaWidget(parent,400,500)
loginWinArea->addLayout(srBtnArea,Qt::AlignCenter);
area->setLayout(loginWinArea);

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

connect(resetBtn,&ElaPushButton::clicked,this, &loginwin::on_resetBtn_clicked);
connect(signinBtn,&ElaPushButton::clicked,this, &loginwin::on_signinBtn_clicked);
connect(loginBtn,&ElaPushButton::clicked,this, &loginwin::on_loginBtn_clicked);
connect(accountLine, &ElaLineEdit::returnPressed, this, &loginwin::on_accountLine_returnPressed);
connect(accountLine, &ElaLineEdit::editingFinished, this, &loginwin::on_accountLine_editingFinished);
}

loginwin::~loginwin()
{

}

void loginwin::on_db_response(const QString &password)
{
passwordLine->setText(password);
}

void loginwin::on_resetBtn_clicked()
{
resetWin->show();
Expand Down Expand Up @@ -129,7 +134,7 @@ void loginwin::on_loginBtn_clicked()
if(loginuser.login()){
QMessageBox::information(this, "成功","登录成功");
emit on_login_complete(loginuser);
db->insertUser(accountLine->text(),passwordLine->text());
//db->insertUser(accountLine->text(),passwordLine->text());
this->close();
}
else
Expand All @@ -138,7 +143,7 @@ void loginwin::on_loginBtn_clicked()
loginBtn->setEnabled(true);
}

void loginwin::on_accountLine_returnPressed()
void loginwin::on_accountLine_editingFinished()
{
// 当账号输入框编辑完成时,检查是否需要记住密码
if (accountLine->text().isEmpty()) {
Expand All @@ -150,11 +155,8 @@ void loginwin::on_accountLine_returnPressed()
QString inputAccount = accountLine->text();

// 从数据库中获取账号对应的密码
QPair<QString, QString> accountPassword = db->getUserPassword(inputAccount);

emit needPassword(inputAccount);
// 如果数据库中存在该账号,则设置密码到密码输入框
if (!accountPassword.second.isEmpty()) {
passwordLine->setText(accountPassword.second);
}


}
6 changes: 5 additions & 1 deletion loginwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ class loginwin:public ElaWidget

signals:
void on_login_complete(User user);
void needPassword(const QString & account);

public slots:
void on_db_response(const QString & password);
private slots:
void on_resetBtn_clicked();
void on_signinBtn_clicked();
void on_loginBtn_clicked();
void on_accountLine_returnPressed();
void on_accountLine_editingFinished();

private:
Core *core;

Expand Down
Loading

0 comments on commit 8b6eb11

Please sign in to comment.