-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
711 lines (660 loc) · 27.7 KB
/
mainwindow.cpp
File metadata and controls
711 lines (660 loc) · 27.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
#include "mainwindow.h"
#include <QGraphicsView>
#include <QHBoxLayout>
#include <QStackedWidget>
#include <QVBoxLayout>
#include <QDesktopServices>
#include <QUrl>
#include <QFileDialog>
#include "ElaContentDialog.h"
#include "ElaEventBus.h"
#include "ElaGraphicsItem.h"
#include "ElaGraphicsScene.h"
#include "ElaGraphicsView.h"
#include "ElaMessageBar.h"
#include "ElaWidget.h"
#include "homeView.h"
#include "linknewfolder_window.h"
#include "DirCard.h"
#include "dircardproxy.h"
#include "loginwin.h"
#include "syncing_view.h"
#include"filemange_view.h"
#include "historysync_view.h"
#include"historyview.h"
#include "globalvalue.h"
#include "SyncThread.h"
#include "qthread.h"
#include "modifyinfor_win.h"
#include"historyviewcardproxy.h"
#include"historycardproxy.h"
#include <QSysInfo>
MainWindow::MainWindow(QWidget *parent)
: ElaWindow(parent)
{
um = new UserManager(this);
setUserInfoCardPixmap(QPixmap(":/include/Image/Cirno.jpg"));
setUserInfoCardTitle("未登录");
setUserInfoCardSubTitle("");
setWindowTitle("珞珈云");
_syncingPage = new SyncingPage(this);
_filemanagePage=new FileManagePage(this,this->um);
_historysyncPage = new HistorysyncPage(this);
_historyviewPage = new HistoryViewPage(this);
connect(this, &ElaWindow::userInfoCardClicked, [=]() {
if(CurrentUser==nullptr)
login->show();
else{
onMessage("若要登录其他账号,请先退出当前账号!","Info");
}
});
connect(this,&MainWindow::dbPassword,login,&loginwin::on_db_response);
connect(login,&loginwin::needPassword,this,&MainWindow::onNeedPassword);
//connect(login->signinWin, &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);
ElaGraphicsScene *scene = new ElaGraphicsScene(this);
scene->setSceneRect(0, 0, 1500, 1500);
ElaGraphicsItem *item1 = new ElaGraphicsItem();
item1->setWidth(100);
item1->setHeight(100);
ElaGraphicsItem *item2 = new ElaGraphicsItem();
item2->setWidth(100);
item2->setHeight(100);
scene->addItem(item1);
scene->addItem(item2);
ElaGraphicsView *view = new ElaGraphicsView(scene);
view->setScene(scene);
QString testKey_1;
QString testKey_2;
QString testKey_3;
QString testKey_4;
QString modifyKey;
QString cancelKey;
QString logoutKey;
QString feedbackKey;
addExpanderNode("同步功能",testKey_2,ElaIconType::House);
addPageNode("正在同步",_syncingPage,testKey_2,ElaIconType::Cloud);
addPageNode("历史同步",_historysyncPage,testKey_2,ElaIconType::CheckToSlot);
addPageNode("同步文件夹管理",_filemanagePage,testKey_2,ElaIconType::FolderClosed);
addExpanderNode("版本控制",testKey_3,ElaIconType::EnvelopeOpenText);
addPageNode("查看历史",_historyviewPage,testKey_3,ElaIconType::CalendarClock);
addFooterNode("用户反馈", nullptr, feedbackKey, 0, ElaIconType::MessageArrowUp);
addFooterNode("修改信息", nullptr, modifyKey, 0, ElaIconType::Text);
addFooterNode("注销账号", nullptr, cancelKey, 0, ElaIconType::UserSlash);
addFooterNode("退出登录", nullptr, logoutKey, 0, ElaIconType::ArrowRightFromBracket);
_modifyInfor_win=new modifyInfor_win();
connect(this, &ElaWindow::navigationNodeClicked, this, [=](ElaNavigationType::NavigationNodeType nodeType, QString nodeKey)
{
if (modifyKey == nodeKey)
{
if(CurrentUser!=nullptr){
_modifyInfor_win->show();
}
else{
onMessage("请先登录!","Error");
}
}
else if(cancelKey==nodeKey)
{
if(CurrentUser!=nullptr)
{
QWidget* _centralWidget = new QWidget(this);
QVBoxLayout* centralVLayout = new QVBoxLayout(_centralWidget);
centralVLayout->setContentsMargins(9, 15, 9, 20);
ElaText* title = new ElaText("注销账号", this);
title->setTextStyle(ElaTextType::Title);
ElaText* subTitle = new ElaText("确定要注销账号吗?一旦注销账号无法恢复!", this);
subTitle->setTextStyle(ElaTextType::Body);
cancelcheckBox = new ElaCheckBox("我已了解注销账号的后果,并确认继续。", this);
//cancelcheckBox->setStyleSheet("ElaCheckBox { font-size: 14px; }");
centralVLayout->addWidget(title);
centralVLayout->addWidget(subTitle);
centralVLayout->addWidget(cancelcheckBox);
centralVLayout->addStretch();
ElaContentDialog *dialag = new ElaContentDialog(this,false);
dialag->setCentralWidget(_centralWidget);
dialag->setLeftButtonText("取消");
dialag->setRightButtonText("确认");
dialag->getButton()->setEnabled(false);
dialag->getButton()->setStyleSheet("QPushButton { background-color: #B58C8C; color: white; }");
connect(cancelcheckBox, &ElaCheckBox::stateChanged, [=](int state) {
if (state == Qt::Checked)
{
dialag->getButton()->setStyleSheet("QPushButton { background-color: #FF6B5D; }"
"QPushButton:hover { background-color: red; }"
"QPushButton:pressed { background-color: red; }");
dialag->getButton()->setEnabled(true);
}
else
{
dialag->getButton()->setStyleSheet("QPushButton { background-color: #B58C8C; }");
dialag->getButton()->setEnabled(false);
}
});
connect(dialag, &ElaContentDialog::rightButtonClicked, [=]() {
onUserdelete();
});
dialag->show();
}
else{
onMessage("请先登录!","Error");
}
}
else if(logoutKey==nodeKey)
{
if(CurrentUser!=nullptr){
QWidget* _logoutWidget = new QWidget(this);
QVBoxLayout* logoutVLayout = new QVBoxLayout(_logoutWidget);
logoutVLayout->setContentsMargins(9, 15, 9, 20);
ElaText* logoutTitle = new ElaText("退出登录", this);
logoutTitle->setTextStyle(ElaTextType::Title);
ElaText* logoutSubTitle = new ElaText("确定要退出登录吗?", this);
logoutSubTitle->setTextStyle(ElaTextType::Body);
logoutVLayout->addWidget(logoutTitle);
logoutVLayout->addWidget(logoutSubTitle);
logoutVLayout->addStretch();
ElaContentDialog *logoutdialag = new ElaContentDialog(this,false);
logoutdialag->setCentralWidget(_logoutWidget);
logoutdialag->setLeftButtonText("取消");
logoutdialag->setRightButtonText("确认");
connect(logoutdialag, &ElaContentDialog::rightButtonClicked, this, &MainWindow::exitLogin);
logoutdialag->show();}
else{
onMessage("请先登录!","Error");
}
}
else if(feedbackKey==nodeKey)
{
QUrl surveyUrl("https://www.wjx.cn/vm/mnzxQPj.aspx/");
QDesktopServices::openUrl(surveyUrl);
}
});
qDebug() << ElaEventBus::getInstance()->getRegisteredEventsName();
connect(login, &loginwin::on_login_complete, this, &MainWindow::onUserLoggedIn);
connect(_modifyInfor_win, &modifyInfor_win::changexinxi, this, &MainWindow::onModifyInfo);
// 拦截默认关闭事件
this->setIsDefaultClosed(false);
connect(this, &MainWindow::closeButtonClicked, this, &MainWindow::onCloseButtonClicked);
autologin();
connect(_historyviewPage->_historyviewcardPage,&HistoryviewCardProxy::Message,this,[=](QString versionID,QString cloudname,QString local,QString path){
int fileTaskId=getNextFileTaskId();
//将local路径指向的文件的文件名前加上versionId
QString rawVersionID=versionID;
QFileInfo fileInfo(local);
// 获取目录路径
QString dirPath = fileInfo.absolutePath();
// 获取原始文件名
QString originalFileName = fileInfo.fileName();
// 将versionID添加到文件名前
QString newFileName = versionID.remove(0,8)+"_"+originalFileName;
// 重新组合成新的文件路径
QString newFilePath = QDir(dirPath).filePath(newFileName);
QString key=cloudname+path;
//询问用户保存位置,打开文件选择框
QString savePath=QFileDialog::getSaveFileName(this,"保存文件",newFilePath);
_syncCore->requestManager->addSave2LocalRequest(key,savePath,fileTaskId,rawVersionID);
emit _syncCore->addFileDownloadTask(savePath,fileTaskId,0);
});
}
MainWindow::MainWindow(QString action, QVector<QString> argv, QWidget *parent):
MainWindow(parent)
{
if (CurrentUser==nullptr){
onMessage("请先登录","Error");
_action=action;
_argv=argv;
login->show();
}
else{
ArgvProcess(action,argv);
}
}
void MainWindow::ArgvProcess(QString action, QVector<QString> argv)
{
onMessage(action,"Info");
onMessage(argv.join(" "),"Info");
if (action=="ver"){
//first find the localpath
QString localPath=argv[0];
QFileInfo fileInfo(localPath);
if (!fileInfo.exists()){
onMessage("文件不存在","Error");
return;
}
if(fileInfo.isDir()){
onMessage("请选择文件,而不是文件夹","Error");
return;
}
QString taskRemotePath="";
QString taskRelativePath="";
QString
standardPath=fileInfo.absoluteFilePath();
for (auto const&x:_syncTaskDatabaseManager->getTasks()){
auto thisLocal=x.getLocalPath();
if (standardPath.startsWith(thisLocal)){
taskRemotePath=x.getRemotePath();
QDir dir(thisLocal);
taskRelativePath=dir.relativeFilePath(standardPath);
}
}
if(taskRemotePath==""){
onMessage("未找到对应的远程路径","Error");
return;
}
COSClient versionClient(cosConfig, this);
QString remotePrefix=taskRemotePath+taskRelativePath;
QVector<Version> v= versionClient.listAllVersionsByPrefix(remotePrefix);
if(this->_historyviewPage->_historyviewcardPage->isExist(standardPath)){
this->_historyviewPage->_historyviewcardPage->clearAllSub(standardPath);
}
else{
this->_historyviewPage->addHistoryViewCard(standardPath,taskRemotePath,taskRelativePath);}
for (auto const&x:v){
//将时间加上本地时区
QString readableTime=x.lastModified.toString("MM-dd hh:mm:ss");
this->_historyviewPage->addSubCard(standardPath,x.versionId,x.size,readableTime);
}
//mainwindow窗口激活
this->activateWindow();
this->navigation(this->_historyviewPage->property("ElaPageKey").toString());
}
else if (action=="add"){
this->navigation(this->_filemanagePage->linknewfolderwindow->property("ElaPageKey").toString());
this->_filemanagePage->linknewfolderwindow->show();
this->_filemanagePage->linknewfolderwindow->getfolderName1()->setText(argv[0]);
}
}
MainWindow::~MainWindow()
{
delete um;
delete _syncingPage;
delete _filemanagePage;
delete _historysyncPage;
delete _historyviewPage;
delete _modifyInfor_win;
delete CurrentUser;
delete _syncCore;
delete _syncTaskDatabaseManager;
delete _taskManager;
}
void MainWindow::onUserLoggedIn(User user)
{
CurrentUser=new User(user);
connect(CurrentUser->channel,&MessageChannel::message,this,&MainWindow::onMessage);
_modifyInfor_win->currentUser=CurrentUser;
QList<QString>s3dirs = CurrentUser->getS3Dirs();
_filemanagePage->linknewfolderwindow->setItems(s3dirs);
um->updateUserInfo(CurrentUser);
setUserInfoCardTitle(user.getUsername());
setUserInfoCardSubTitle(user.getEmail());
_syncTaskDatabaseManager=new SyncTaskDatabaseManager(CurrentUser);
_taskManager=new TaskManager(CurrentUser->getEmail());
QString url=user.getAvatarPath();
QNetworkAccessManager *manager = new QNetworkAccessManager();
QNetworkRequest request;
request.setUrl(QUrl(url));
QNetworkReply *reply = manager->get(request);
QEventLoop loop;
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
QFile file("downloaded_image.jpg");
if (file.open(QIODevice::WriteOnly))
{
file.write(reply->readAll());
file.close();
}
delete reply;
QString filename=QDir::toNativeSeparators(file.fileName());
QPixmap pix(filename);
setUserInfoCardPixmap(pix);
cosConfig=CurrentUser->getS3Config();
tt=CurrentUser->getUnifiedTaskToken();
cosConfig.taskToken=tt;
this->_filemanagePage->updateComboBoxIndex(um->getThread());
this->_filemanagePage->setexcludeditemsview->updateExcludedItems(um->getExcludedItems());
_syncCore=new SyncCore(cosConfig,this,um->getExcludedItems());
_syncCore->requestManager->setMaxConcurrentRequests(um->getThread());
qDebug() << "Connecting taskTotalSize signal";
connect(_syncCore,&SyncCore::taskTotalSize,this,&MainWindow::onTaskTotalSize);
qDebug() << "Connecting taskUploadSize signal";
connect(_syncCore,&SyncCore::taskUploadSize,this,&MainWindow::onTaskUploadSize);
qDebug() << "Connecting addFileUploadTask signal";
connect(_syncCore,&SyncCore::addFileUploadTask,this,&MainWindow::onFileUploadTaskCreated,Qt::QueuedConnection);
qDebug() << "Connecting updateFileUploadTask signal";
connect(_syncCore,&SyncCore::updateFileUploadTask,this,&MainWindow::onFileUploadTaskUpdated,Qt::QueuedConnection);
qDebug() << "Connecting addFileDownloadTask signal";
connect(_syncCore,&SyncCore::addFileDownloadTask,this,&MainWindow::onFileDownloadTaskCreated,Qt::QueuedConnection);
qDebug() << "Connecting updateFileDownloadTask signal";
connect(_syncCore,&SyncCore::updateFileDownloadTask,this,&MainWindow::onFileDownloadTaskUpdated,Qt::QueuedConnection);
connect(_syncCore,&SyncCore::finishFileDownloadTask,this,&MainWindow::onFileDownloadTaskFinished,Qt::QueuedConnection);
connect(_syncCore,&SyncCore::finishFileUploadTask,this,&MainWindow::onFileUploadTaskFinished,Qt::QueuedConnection);
connect(_filemanagePage,&FileManagePage::deleteTask,[=](int taskId){
this->_syncTaskDatabaseManager->deleteTask(taskId);
});
connect(_filemanagePage,&FileManagePage::setThreadNum,[=](int num){
this->_syncCore->requestManager->setMaxConcurrentRequests(num);
});
//链接synccore中filequeue的sendRequestInfo信号和mainwindow的onTaskFinsished槽函数
connect(_syncCore->requestManager,&NetworkRequestManager::sendRequestInfo,this,&MainWindow::onTaskFinsished);
ReadFinishTask();
QStringList listenDirs;
for (auto const &x:_syncTaskDatabaseManager->getTasks()){
SyncTask* task=new SyncTask(x);
otherDeviceMap[x.getRemotePath()]=getComputerName();
if (x.getLastSyncTime()==QDateTime::fromString("2000-01-01 00:00:00","yyyy-MM-dd hh:mm:ss"))
{
QString timeDelta="从未同步";
this->_filemanagePage->addDirCard(x.getLocalPath(),x.getRemotePath(),11,timeDelta,task->getSyncStatus(),x.getId());
}else{
QString timeDelta=QString::number(x.getLastSyncTime().daysTo(QDateTime::currentDateTime()))+"天前";
this->_filemanagePage->addDirCard(x.getLocalPath(),x.getRemotePath(),11,timeDelta,task->getSyncStatus(),x.getId());
}
_syncCore->addTask(task);
listenDirs.append(x.getRemotePath());
}
QVector<QString> s3Dirs = CurrentUser->getS3Dirs();
qDebug() << "S3 Dirs:";
for (const QString& s3Dir : s3Dirs) {
qDebug() << s3Dir;
}
if(_action!=""){
ArgvProcess(_action,_argv);
}
cloudListener=new CloudListener(cosConfig);
connect(cloudListener,&CloudListener::cloudDirectoryChanged,this,&MainWindow::onCloudDirectoryChanged);
cloudListener->setTasks(_syncTaskDatabaseManager->getTasks());
cloudListener->start();
}
void MainWindow::doSomething()
{
}
void MainWindow::exitLogin()
{
if(CurrentUser->logout()){
um->setAutoLoginStaus(false);
setUserInfoCardTitle("未登录");
setUserInfoCardSubTitle("");
setUserInfoCardPixmap(QPixmap(":/include/Image/Cirno.jpg"));
onMessage("退出账号成功","Success");
CurrentUser=nullptr;
_filemanagePage->_dircardProxy->removeAll();
_historysyncPage->_historycardPage->removeAll();
_historyviewPage->_historyviewcardPage->removeAll();
_filemanagePage->linknewfolderwindow->clearItems();
if (cloudListener!=nullptr)
{
//cloudListener->terminate();
cloudListener=nullptr;
}
}
else{
onMessage("退出账号失败","Error");
}
}
void MainWindow::onNeedPassword(const QString &account)
{
QString password = um->getUserPassWord(account);
emit dbPassword(password);
}
void MainWindow::onCloudDirectoryChanged(SyncTask thisTask,int type)
{
this->_syncCore->doCloudTask(thisTask.getLocalPath(),thisTask.getRemotePath(),3);
if(type==1){
onMessage("云端文件夹 "+thisTask.getRemotePath()+" 有变动","Info");
}
}
/*
void MainWindow::insertUserToDatabase(User user)
{
qDebug()<<user.getEmail()<<" "<<user.gethashedPassword();
db->insertUser(user.getEmail(),user.gethashedPassword());
qDebug()<<db->getUserPassword(user.getEmail());
}
*/
void MainWindow::onMessage( QString message, QString type)
{
/* static void success(ElaMessageBarType::PositionPolicy policy, QString title, QString text, int displayMsec, QWidget* parent = nullptr);
static void warning(ElaMessageBarType::PositionPolicy policy, QString title, QString text, int displayMsec, QWidget* parent = nullptr);
static void information(ElaMessageBarType::PositionPolicy policy, QString title, QString text, int displayMsec, QWidget* parent = nullptr);
static void error(ElaMessageBarType::PositionPolicy policy, QString title, QString text, int displayMsec, QWidget* parent = nullptr);*/
QString title;
if (type=="Info")
{
ElaMessageBar::information( ElaMessageBarType::TopRight,QString("消息"),message,2000,this);
}
else if (type=="Error")
{
ElaMessageBar::error(ElaMessageBarType::TopRight,QString("错误"),message,2000,this);
}
else if (type=="Warning")
{
ElaMessageBar::warning(ElaMessageBarType::TopRight,QString("警告"),message,2000,this);
}
else if (type=="Success")
{
ElaMessageBar::success(ElaMessageBarType::TopRight,QString("成功"),message,2000,this);
}
}
void MainWindow::onUserAddNewTask(const SyncTask &_task)
{
if(CurrentUser==nullptr)
{
onMessage("请先登录","Error");
return;
}
if(CurrentUser->addTask(_task.getLocalPath(),_task.getRemotePath(),_task.getSyncStatus(),1,1)){
if(_syncTaskDatabaseManager!=nullptr)
{
int res=_syncTaskDatabaseManager->addTask(_task);
bool isSuccess=false;
tt=CurrentUser->getUnifiedTaskToken();
COSConfig cosConfig=CurrentUser->getS3Config();
cosConfig.taskToken=tt;
SyncTask* task=nullptr;
if(_syncCore!=nullptr)
{
SyncTask mytask(_task);
task=new SyncTask(mytask);
task->setId(res);
otherDeviceMap[task->getRemotePath()]=getComputerName();
QDateTime expiredTime=tt.expiredTime;
COSClient *cosclient=new COSClient(cosConfig, this);
task->cosclient=cosclient;
isSuccess=_syncCore->addTask(task);
}
if(isSuccess)
{
if (_task.getLastSyncTime()==QDateTime::fromString("2000-01-01 00:00:00","yyyy-MM-dd hh:mm:ss"))
{
QString timeDelta="从未同步";
this->_filemanagePage->addDirCard(task->getLocalPath(),task->getRemotePath(),111,timeDelta,task->getSyncStatus(),task->getId());
}else{
QString timeDelta=QString::number(task->getLastSyncTime().daysTo(QDateTime::currentDateTime()))+"天前";
this->_filemanagePage->addDirCard(task->getLocalPath(),task->getRemotePath(),1111,timeDelta,task->getSyncStatus(),task->getId());
}
onMessage("新文件夹链接成功。","Success");
cloudListener->setTasks(_syncTaskDatabaseManager->getTasks());
}
else
{
_syncTaskDatabaseManager->deleteTask(res);
}
}
}
}
void MainWindow::onCloseButtonClicked()
{
ElaContentDialog *dialag = new ElaContentDialog(this);
dialag->setLeftButtonText("取消");
dialag->setMiddleButtonText("最小化");
dialag->setRightButtonText("退出");
connect(dialag, &ElaContentDialog::rightButtonClicked, this, &MainWindow::closeWindow);
connect(dialag, &ElaContentDialog::middleButtonClicked, this, &MainWindow::showMinimized);
dialag->show();
}
void MainWindow::onModifyInfo(User user)
{
//CurrentUser=new User(user);
_modifyInfor_win->currentUser=CurrentUser;
qDebug() << user.getEmail() << " " << user.gethashedPassword();
um->updateUserInfo(CurrentUser);
qDebug() << user.getEmail() << " " << user.gethashedPassword() <<" " << um->getUserPassWord(user.getEmail());
setUserInfoCardTitle(_modifyInfor_win->newIdEdit_->text());
setUserInfoCardSubTitle(user.getEmail());
QString url=user.getAvatarPath();
QNetworkAccessManager *manager = new QNetworkAccessManager();
QNetworkRequest request;
request.setUrl(QUrl(url));
QNetworkReply *reply = manager->get(request);
QEventLoop loop;
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
QFile file("downloaded_image.jpg");
if (file.open(QIODevice::WriteOnly))
{
file.write(reply->readAll());
file.close();
}
delete reply;
QString filename=QDir::toNativeSeparators(file.fileName());
QPixmap pix(filename);
setUserInfoCardPixmap(pix);
}
void MainWindow::onUserdelete()
{
if(CurrentUser->deleteAccount()){
um->setAutoLoginStaus(false);
setUserInfoCardTitle("未登录");
setUserInfoCardSubTitle("");
setUserInfoCardPixmap(QPixmap(":/include/Image/Cirno.jpg"));
onMessage("注销账号成功","Success");
CurrentUser=nullptr;
}
else{
onMessage("注销账号失败","Error");
}
}
void MainWindow::onFileUploadTaskCreated(const QString &localPath, int fileTaskId) {
QFile file(localPath);
quint64 size=file.size();
_syncingPage->addFile(localPath,size,0,0,1,fileTaskId);
qDebug()<<"File upload task created"<<localPath<<" "<<fileTaskId;
}
void MainWindow::onFileUploadTaskUpdated(int fileTaskId, qint64 nowSize, qint64 totalSize) {
qDebug()<<"File upload task updated"<<fileTaskId<<" "<<nowSize<<"/"<<totalSize;
if(totalSize==nowSize){
_syncingPage->removeFile(
fileTaskId
);
return ;
}
_syncingPage->modifyFile(
totalSize,
nowSize,
fileTaskId
);
}
void MainWindow::onFileUploadTaskPaused(int fileTaskId) {
qDebug()<<"File upload task paused"<<fileTaskId;
}
void MainWindow::onFileDownloadTaskCreated(const QString &localPath, int fileTaskId,quint64 totalSize) {
_syncingPage->addFile(localPath,totalSize,0,0,2,fileTaskId);
qDebug()<<"File download task created"<<localPath<<" "<<fileTaskId;
}
void MainWindow::onFileDownloadTaskUpdated(int fileTaskId, qint64 nowSize, qint64 totalSize) {
qDebug()<<"File download task updated"<<fileTaskId<<" "<<nowSize<<"/"<<totalSize;
if(totalSize==nowSize){
_syncingPage->removeFile(
fileTaskId
);
return ;
}
_syncingPage->modifyFile(
totalSize,
nowSize,
fileTaskId
);
}
void MainWindow::onFileDownloadTaskPaused(int fileTaskId) {
qDebug()<<"File download task paused"<<fileTaskId;
}
void MainWindow::onTaskTotalSize(qint64 size, int taskid) {
this->_syncTaskDatabaseManager->updateTaskTime(taskid,QDateTime::currentDateTime());
QString timeFinished=QDateTime::currentDateTime().toString("hh:mm:ss");
this->_filemanagePage->modifyDirCard(size,timeFinished,taskid);
onMessage("任务创建完成","Success");
}
void MainWindow::onTaskUploadSize(qint64 size, int taskid) {
//this->_filemanagePage->modifyDirCard(size,"同步完成",taskid);
}
void MainWindow::onFileUploadTaskFinished(int fileTaskId)
{
_syncingPage->removeFile(
fileTaskId
);
}
void MainWindow::onFileDownloadTaskFinished(int fileTaskId)
{
_syncingPage->removeFile(
fileTaskId
);
}
void MainWindow::onUserPausedFileTask(int fileTaskId)
{
}
void MainWindow::onTaskFinsished(RequestInfo requestInfo)
{
QFileInfo fileInfo(requestInfo.localPath);
bool taskExist=false;
if(requestInfo.methodId==0){
taskExist=_taskManager->insertFinishTask(0,requestInfo.RemotePath,requestInfo.localPath,fileInfo.size(),QDate::currentDate(),2);
_taskManager->deleteUpTask(requestInfo.localPath);
}
else if(requestInfo.methodId==1){
taskExist=_taskManager->insertFinishTask(0,requestInfo.RemotePath,requestInfo.localPath,fileInfo.size(),QDate::currentDate(),3);
_taskManager->deleteDownTask(requestInfo.localPath);
}
if(taskExist)
{
//找到数据库中localpath为requestInfo.localPath的数据,并添加到卡片
finishTask task=_taskManager->getFinishTask(requestInfo.localPath);
QFileInfo fileInfo(requestInfo.localPath);
this->_historysyncPage->addHistory(task.localPath,QString::number(fileInfo.size()),task.sycnTime.toString("yyyy-MM-dd"),task.status==2?true:false);
}
}
void MainWindow::ReadUpTask()
{
return ;
}
void MainWindow::ReadDownTask()
{
return ;
}
void MainWindow::ReadFinishTask()
{
for (auto const &task:_taskManager->readFinishTask()){
this->_historysyncPage->addHistory(task.localPath,QString::number(task.dataSize),task.sycnTime.toString("yyyy-MM-dd"),task.status==2?true:false);
}
}
void MainWindow::autologin()
{
if(um->getAutoLoginStaus()){
QString account=um->getUserAccount();
QString password=um->getUserPassWord(account);
CurrentUser=new User(account,password);
if(CurrentUser->login()){
onUserLoggedIn(*CurrentUser);
onMessage("自动登录成功!","Success");
}else{
//onMessage("自动登录失败!","Error");
CurrentUser=nullptr;
}
}
}
QString MainWindow::getComputerName()
{
QString machineHostName = QSysInfo::machineHostName();
qDebug() << "设备名称(主机名):" << machineHostName;
return machineHostName;
}