forked from linuxdeepin/deepin-compressor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
3746 lines (3358 loc) · 145 KB
/
mainwindow.cpp
File metadata and controls
3746 lines (3358 loc) · 145 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
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "mainwindow.h"
#include "common/dbusadpator.h"
#include "loadingpage.h"
#include "homepage.h"
#include "compresspage.h"
#include "compresssettingpage.h"
#include "uncompresspage.h"
#include "progresspage.h"
#include "successpage.h"
#include "failurepage.h"
#include "pluginmanager.h"
#include "settingdialog.h"
#include "archivemanager.h"
#include "DebugTimeManager.h"
#include "popupdialog.h"
#include "progressdialog.h"
#include "datamanager.h"
#include "ddesktopservicesthread.h"
#include "openFileWatcher.h"
#include "mimetypes.h"
#include "customwidget.h"
#include "treeheaderview.h"
#include "compressview.h"
#include "uncompressview.h"
#include "uitools.h"
#include "calculatesizethread.h"
#include "eventlogutils.h"
#include "qtcompat.h"
#include <DFileDialog>
#include <DTitlebar>
#include <DWindowCloseButton>
#include <DWindowOptionButton>
#include <DArrowLineDrawer>
#include <DFontSizeManager>
#include <denhancedwidget.h>
#include <DSysInfo>
#include <QStackedWidget>
#include <QKeyEvent>
#include <QSettings>
#include <QDebug>
#include <QThreadPool>
#include <QtConcurrent/QtConcurrent>
#include <QScreen>
#include <QFormLayout>
#include <QShortcut>
#include <QJsonObject>
#ifdef DTKCORE_CLASS_DConfigFile
#include <DConfig>
DCORE_USE_NAMESPACE
#endif
static QMutex mutex; // 静态全局变量只在定义该变量的源文件内有效
#define FILE_TRUNCATION_LENGTH 70
MainWindow::MainWindow(QWidget *parent)
: DMainWindow(parent)
, m_strProcessID(QString::number(QCoreApplication::applicationPid())) // 获取应用进程号
{
qDebug() << "MainWindow constructor started";
setWindowTitle(tr("Archive Manager"));
// 先构建初始界面
qDebug() << "Creating main UI components";
m_pMainWidget = new QStackedWidget(this); // 中心面板
m_pHomePage = new HomePage(this); // 首页
m_pMainWidget->addWidget(m_pHomePage);
setCentralWidget(m_pMainWidget); // 设置中心面板
m_pMainWidget->setCurrentIndex(0);
qDebug() << "Main UI components created";
// Initialize DBus interface
qDebug() << "Initializing DBus interface";
// m_compressorInterface = new ApplicationAdaptor(qApp);
// m_compressorInterface->setMainWindow(this);
qDebug() << "DBus interface initialized";
#if QT_VERSION < QT_VERSION_CHECK(6 ,0, 0)
qDebug() << "Creating shortcut for Qt5";
m_openkey = new QShortcut(QKeySequence(Qt::Key_Slash + Qt::CTRL + Qt::SHIFT), this); // Ctrl+Shift+/
#else
qDebug() << "Creating shortcut for Qt6";
m_openkey = new QShortcut(QKeyCombination(Qt::CTRL | Qt::SHIFT, Qt::Key_Slash), this); // Ctrl+Shift+/
#endif
m_openkey->setContext(Qt::ApplicationShortcut);
// 初始化标题栏
qDebug() << "Initializing title bar";
initTitleBar();
qDebug() << "Initializing application data";
initData();
// 开启定时器刷新界面
m_iInitUITimer = startTimer(500);
qDebug() << "UI refresh timer started with ID:" << m_iInitUITimer;
qDebug() << "Writing startup event log";
QJsonObject obj{
{"tid", EventLogUtils::Start},
{"version", QCoreApplication::applicationVersion()},
{"mode", 1}
};
EventLogUtils::get().writeLogs(obj);
qDebug() << "MainWindow constructor completed";
}
MainWindow::~MainWindow()
{
qDebug() << "MainWindow destructor started";
// 保存窗口大小状态
qDebug() << "Saving window size configuration";
saveConfigWinSize(width(), height());
qDebug() << "Destroying ArchiveManager instance";
ArchiveManager::get_instance()->destory_instance();
// Clean up DBus interface
qDebug() << "Cleaning up DBus interface";
// if (m_compressorInterface) {
// delete m_compressorInterface;
// m_compressorInterface = nullptr;
// }
// 清除缓存数据
qDebug() << "Cleaning up temporary files";
QProcess p;
QString command = "rm";
QStringList args;
args.append("-rf");
args.append(TEMPPATH + QDir::separator() + m_strProcessID);
p.execute(command, args);
p.waitForFinished();
if (nullptr != m_mywork && m_mywork->isRunning()) {
qDebug() << "Stopping calculate size thread";
m_mywork->set_thread_stop(true); // 结束计算大小线程
m_mywork->wait(); //必须等待线程结束
}
if (nullptr != m_mywork) {
qDebug() << "Deleting calculate size thread object";
m_mywork->deleteLater();
m_mywork = nullptr;
}
qInfo() << "Application exited normally";
qDebug() << "MainWindow destructor completed";
}
bool MainWindow::checkHerePath(const QString &strPath)
{
qDebug() << "Checking path permissions:" << strPath;
QFileInfo info(strPath);
if (!(info.isWritable() && info.isExecutable())) { // 检查一选择保存路径是否有权限
qWarning() << "Path permission denied:" << strPath;
TipDialog dialog(this);
// 屏幕居中显示
moveDialogToCenter(&dialog);
dialog.showDialog(tr("You do not have permission to save files here, please change and retry"), tr("OK", "button"), DDialog::ButtonNormal);
return false;
}
qDebug() << "Path permission granted:" << strPath;
return true;
}
void MainWindow::initUI()
{
qDebug() << "initUI";
// 初始化界面
m_pLoadingPage = new LoadingPage(this); // 加载界面
m_pCompressPage = new CompressPage(this); // 压缩列表界面
m_pCompressSettingPage = new CompressSettingPage(this); // 压缩设置界面
m_pUnCompressPage = new UnCompressPage(this); // 解压列表界面
m_pProgressPage = new ProgressPage(this); // 进度界面
m_pSuccessPage = new SuccessPage(this); // 成功界面
m_pFailurePage = new FailurePage(this); // 失败界面
m_pProgressdialog = new ProgressDialog(this); //进度弹窗
m_commentProgressDialog = new CommentProgressDialog(this); // 更新注释进度弹窗
m_pSettingDlg = new SettingDialog(this);
m_pSettingDlg->setMinimumWidth(750);
// 添加界面至主界面
m_pMainWidget->addWidget(m_pCompressPage);
m_pMainWidget->addWidget(m_pCompressSettingPage);
m_pMainWidget->addWidget(m_pUnCompressPage);
m_pMainWidget->addWidget(m_pProgressPage);
m_pMainWidget->addWidget(m_pSuccessPage);
m_pMainWidget->addWidget(m_pFailurePage);
m_pMainWidget->addWidget(m_pLoadingPage);
// 创建打开文件监控
m_pOpenFileWatcher = new OpenFileWatcher(this);
// 刷新压缩设置界面格式选项
m_pCompressSettingPage->refreshMenu();
}
void MainWindow::initTitleBar()
{
qDebug() << "MainWindow::initTitleBar";
// 创建菜单
QMenu *menu = new QMenu(this);
m_pOpenAction = menu->addAction(tr("Open file"), this, &MainWindow::slotChoosefiles);
menu->addAction(tr("Settings"), this, [ = ] { m_pSettingDlg->exec(); });
menu->addSeparator();
// 初始化标题栏菜单
titlebar()->setMenu(menu);
titlebar()->setTitle("");
// 设置应用程序图标
QIcon icon = QIcon::fromTheme("deepin-compressor");
titlebar()->setIcon(icon);
// titlebar widget
m_pTitleWidget = new TitleWidget(this);
m_pTitleWidget->setFocusPolicy(Qt::TabFocus);
this->titlebar()->addWidget(m_pTitleWidget, Qt::AlignLeft);
setTabOrder(this->titlebar(), m_pTitleWidget);
m_pTitleWidget->setVisible(false);
this->titlebar()->setFocusProxy(nullptr);
}
void MainWindow::initData()
{
qDebug() << "Initializing application data";
// 初始化数据配置
m_pSettings = new QSettings(QDir(UiTools::getConfigPath()).filePath("config.conf"), QSettings::IniFormat, this);
if (m_pSettings->value("dir").toString().isEmpty()) {
qDebug() << "Setting default directory path in config";
m_pSettings->setValue("dir", "");
}
qDebug() << "Setting window size and minimum size";
resize(getConfigWinSize()); // 设置窗口尺寸
setMinimumSize(620, 300); // task 16309调整最小大小
qDebug() << "Application data initialized";
}
void MainWindow::initConnections()
{
qDebug() << "Initializing signal-slot connections";
qDebug() << "Connecting UI signals";
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &MainWindow::slotThemeChanged);
connect(m_pTitleWidget, &TitleWidget::sigTitleClicked, this, &MainWindow::slotTitleBtnClicked);
connect(m_pTitleWidget, &TitleWidget::sigCommentClicked, this, &MainWindow::slotTitleCommentButtonPressed);
connect(m_pHomePage, &HomePage::signalFileChoose, this, &MainWindow::slotChoosefiles);
connect(m_pHomePage, &HomePage::signalDragFiles, this, &MainWindow::slotDragSelectedFiles);
connect(m_pCompressPage, &CompressPage::signalLevelChanged, this, &MainWindow::slotCompressLevelChanged);
connect(m_pCompressPage, &CompressPage::signalCompressNextClicked, this, &MainWindow::slotCompressNext);
connect(m_pCompressPage, &CompressPage::signalFileChoose, this, &MainWindow::slotChoosefiles);
connect(m_pCompressSettingPage, &CompressSettingPage::signalCompressClicked, this, &MainWindow::slotCompress);
connect(m_pUnCompressPage, &UnCompressPage::signalUncompress, this, &MainWindow::slotUncompressClicked);
connect(m_pUnCompressPage, &UnCompressPage::signalExtract2Path, this, &MainWindow::slotExtract2Path);
connect(m_pUnCompressPage, &UnCompressPage::signalDelFiles, this, &MainWindow::slotDelFiles);
connect(m_pUnCompressPage, &UnCompressPage::signalRenameFile, this, &MainWindow::slotRenameFile);
connect(this, &MainWindow::sigRenameFile, m_pUnCompressPage, &UnCompressPage::sigRenameFile);
connect(m_pUnCompressPage, &UnCompressPage::signalOpenFile, this, &MainWindow::slotOpenFile);
connect(m_pUnCompressPage, &UnCompressPage::signalAddFiles2Archive, this, &MainWindow::slotAddFiles);
connect(m_pUnCompressPage, &UnCompressPage::signalFileChoose, this, &MainWindow::slotChoosefiles);
connect(m_pProgressPage, &ProgressPage::signalPause, this, &MainWindow::slotPause);
connect(m_pProgressPage, &ProgressPage::signalContinue, this, &MainWindow::slotContinue);
connect(m_pProgressPage, &ProgressPage::signalCancel, this, &MainWindow::slotCancel);
connect(m_pProgressdialog, &ProgressDialog::signalPause, this, &MainWindow::slotPause);
connect(m_pProgressdialog, &ProgressDialog::signalContinue, this, &MainWindow::slotContinue);
connect(m_pProgressdialog, &ProgressDialog::signalCancel, this, &MainWindow::slotCancel);
connect(m_pSuccessPage, &SuccessPage::sigBackButtonClicked, this, &MainWindow::slotSuccessReturn);
connect(m_pSuccessPage, &SuccessPage::signalViewFile, this, &MainWindow::slotSuccessView);
connect(m_pFailurePage, &FailurePage::sigFailRetry, this, &MainWindow::slotFailureRetry);
connect(m_pFailurePage, &FailurePage::sigBackButtonClickedOnFail, this, &MainWindow::slotFailureReturn);
qDebug() << "Connecting ArchiveManager signals";
connect(ArchiveManager::get_instance(), &ArchiveManager::signalJobFinished, this, &MainWindow::slotJobFinished);
connect(ArchiveManager::get_instance(), &ArchiveManager::signalprogress, this, &MainWindow::slotReceiveProgress);
connect(ArchiveManager::get_instance(), &ArchiveManager::signalCurFileName, this, &MainWindow::slotReceiveCurFileName);
connect(ArchiveManager::get_instance(), &ArchiveManager::signalFileWriteErrorName, this, &MainWindow::slotReceiveFileWriteErrorName);
connect(ArchiveManager::get_instance(), &ArchiveManager::signalCurArchiveName, this, &MainWindow::slotReceiveCurArchiveName);
connect(ArchiveManager::get_instance(), &ArchiveManager::signalQuery, this, &MainWindow::slotQuery);
qDebug() << "Connecting file watcher signals";
connect(m_pOpenFileWatcher, &OpenFileWatcher::fileChanged, this, &MainWindow::slotOpenFileChanged);
//定制需求不显示ctrl+shift+?快捷键菜单
if(!property(ORDER_JSON).isValid()) {
qDebug() << "Connecting shortcut signals";
connect(m_openkey, &QShortcut::activated, this, &MainWindow::slotShowShortcutTip);
}
qDebug() << "All signal-slot connections initialized";
}
void MainWindow::refreshPage()
{
qInfo() << "Refreshing page, current page ID:" << m_ePageID;
switch (m_ePageID) {
case PI_Home: {
qDebug() << "Switching to Home page";
resetMainwindow();
m_pMainWidget->setCurrentIndex(0);
setTitleButtonStyle(false, false);
titlebar()->setTitle("");
}
break;
case PI_Compress: {
qDebug() << "Switching to Compress page";
m_pMainWidget->setCurrentIndex(1);
setTitleButtonStyle(true, false, DStyle::StandardPixmap::SP_IncreaseElement);
if (0 == m_iCompressedWatchTimerID) {
qDebug() << "Starting compressed watch timer";
m_iCompressedWatchTimerID = startTimer(1);
}
titlebar()->setTitle(tr("Create New Archive"));
}
break;
case PI_CompressSetting: {
qDebug() << "Switching to Compress Setting page";
m_pMainWidget->setCurrentIndex(2);
setTitleButtonStyle(true, false, DStyle::StandardPixmap::SP_ArrowLeave);
if (0 == m_iCompressedWatchTimerID) {
qDebug() << "Starting compressed watch timer";
m_iCompressedWatchTimerID = startTimer(1);
}
titlebar()->setTitle(tr("Create New Archive"));
}
break;
case PI_UnCompress: {
qDebug() << "Switching to Uncompress page";
m_pMainWidget->setCurrentIndex(3);
bool bShowAddBtn = true;
if(property(ORDER_JSON).isValid()) {
qDebug() << "property ORDER_JSON is valid";
if(m_pUnCompressPage) {
qDebug() << "m_pUnCompressPage is not null";
QVariantMap mapdata = m_pUnCompressPage->mapOrderJson();
if(mapdata.contains(ORDER_EDIT)) {
qDebug() << "mapdata contains ORDER_EDIT";
bShowAddBtn = mapdata.value(ORDER_EDIT).toBool();
m_pOpenAction->setEnabled(bShowAddBtn);
}
}
}
setTitleButtonStyle(bShowAddBtn, true, DStyle::StandardPixmap::SP_IncreaseElement);
titlebar()->setTitle(QFileInfo(m_pUnCompressPage->archiveFullPath()).fileName());
}
break;
case PI_AddCompressProgress: {
qDebug() << "Switching to Add Compress Progress page";
m_pMainWidget->setCurrentIndex(4);
setTitleButtonStyle(false, false);
m_pProgressPage->resetProgress();
titlebar()->setTitle(tr("Adding files to %1").arg(m_pProgressPage->archiveName()));
}
break;
case PI_CompressProgress: {
qDebug() << "Switching to Compress Progress page";
m_pMainWidget->setCurrentIndex(4);
setTitleButtonStyle(false, false);
m_pProgressPage->resetProgress();
titlebar()->setTitle(tr("Compressing"));
}
break;
case PI_UnCompressProgress: {
qDebug() << "Switching to Uncompress Progress page";
m_pMainWidget->setCurrentIndex(4);
setTitleButtonStyle(false, false);
m_pProgressPage->resetProgress();
titlebar()->setTitle(tr("Extracting"));
}
break;
case PI_DeleteProgress: {
qDebug() << "Switching to Delete Progress page";
m_pMainWidget->setCurrentIndex(4);
setTitleButtonStyle(false, false);
m_pProgressPage->resetProgress();
titlebar()->setTitle(tr("Deleting"));
}
break;
case PI_RenameProgress: {
qDebug() << "Switching to Rename Progress page";
m_pMainWidget->setCurrentIndex(4);
setTitleButtonStyle(false, false);
m_pProgressPage->resetProgress();
titlebar()->setTitle(tr("Renaming"));
}
break;
case PI_ConvertProgress: {
qDebug() << "MainWindow::refreshPage PI_ConvertProgress";
m_pMainWidget->setCurrentIndex(4);
setTitleButtonStyle(false, false);
m_pProgressPage->resetProgress();
titlebar()->setTitle(tr("Converting"));
}
break;
case PI_CommentProgress: {
qDebug() << "MainWindow::refreshPage PI_CommentProgress";
m_pMainWidget->setCurrentIndex(4);
setTitleButtonStyle(false, false);
m_pProgressPage->resetProgress();
titlebar()->setTitle(tr("Updating comments")); // 正在更新注释
}
break;
case PI_Success: {
qDebug() << "MainWindow::refreshPage PI_Success";
m_pMainWidget->setCurrentIndex(5);
setTitleButtonStyle(false, false);
titlebar()->setTitle("");
}
break;
case PI_Failure: {
qDebug() << "MainWindow::refreshPage PI_Failure";
m_pMainWidget->setCurrentIndex(6);
setTitleButtonStyle(false, false);
titlebar()->setTitle("");
}
break;
case PI_Loading: {
qDebug() << "MainWindow::refreshPage PI_Loading";
m_pMainWidget->setCurrentIndex(7);
setTitleButtonStyle(false, false);
titlebar()->setTitle("");
}
break;
}
//压缩文件焦点需压缩文件名上
if(m_ePageID == PI_CompressSetting) {
qDebug() << "m_ePageID is PI_CompressSetting, return";
return;
}
//切换界面后焦点默认在标题栏上
this->titlebar()->setFocus();
}
qint64 MainWindow::calSelectedTotalFileSize(const QStringList &files)
{
qDebug() << "Calculating total size of selected files, count:" << files.size();
QElapsedTimer time1;
time1.start();
qDebug() << "File size calculation started";
m_stCompressParameter.qSize = 0;
foreach (QString file, files) {
QFileInfo fi(file);
if (fi.isFile()) { // 如果为文件,直接获取大小
qDebug() << "Calculate file size:" << file;
qint64 curFileSize = fi.size();
#ifdef __aarch64__
if (maxFileSize_ < curFileSize) {
maxFileSize_ = curFileSize;
}
#endif
m_stCompressParameter.qSize += curFileSize;
} else if (fi.isDir()) { // 如果是文件夹,递归获取所有子文件大小总和
qDebug() << "Calculate directory size:" << file;
#if QT_VERSION < QT_VERSION_CHECK(6 ,0, 0)
QtConcurrent::run(this, &MainWindow::calFileSizeByThread, file);
#else
QtConcurrent::run([this, file](){
calFileSizeByThread(file);
});
#endif
}
}
// 等待线程池结束
QThreadPool::globalInstance()->waitForDone();
qInfo() << QString("计算大小线程结束,耗时:%1ms,文件总大小:%2B").arg(time1.elapsed()).arg(m_stCompressParameter.qSize);
return m_stCompressParameter.qSize;
}
void MainWindow::calFileSizeByThread(const QString &path)
{
qDebug() << "Calculating folder size:" << path;
QDir dir(path);
if (!dir.exists()) {
qWarning() << "Directory does not exist:" << path;
return;
}
// 获得文件夹中的文件列表
QFileInfoList list = dir.entryInfoList(QDir::AllEntries | QDir::System
| QDir::NoDotAndDotDot | QDir::Hidden);
qDebug() << "Found" << list.count() << "items in directory:" << path;
for (int i = 0; i < list.count(); ++i) {
QFileInfo fileInfo = list.at(i);
if (fileInfo.isDir()) {
qDebug() << "Processing subdirectory:" << fileInfo.filePath();
// 如果是文件夹 则将此文件夹放入线程池中进行计算
#if QT_VERSION < QT_VERSION_CHECK(6 ,0, 0)
QtConcurrent::run(this, &MainWindow::calFileSizeByThread, fileInfo.filePath());
#else
QtConcurrent::run([this, fileInfo](){
calFileSizeByThread(fileInfo.filePath());
});
#endif
} else {
mutex.lock();
// 如果是文件则直接计算大小
qint64 curFileSize = fileInfo.size();
#ifdef __aarch64__
if (maxFileSize_ < curFileSize) {
qDebug() << "Updating max file size to:" << curFileSize;
maxFileSize_ = curFileSize;
}
#endif
m_stCompressParameter.qSize += curFileSize;
mutex.unlock();
qDebug() << "Processed file:" << fileInfo.filePath() << "size:" << curFileSize;
}
}
qDebug() << "Finished calculating size for directory:" << path;
}
void MainWindow::setTitleButtonStyle(bool bVisible, bool bVisible2, DStyle::StandardPixmap pixmap)
{
qDebug() << "MainWindow::setTitleButtonStyle" << bVisible << bVisible2 << pixmap;
m_pTitleWidget->setVisible(bVisible || bVisible2);
m_pTitleWidget->setTitleButtonStyle(bVisible, bVisible2, pixmap);
}
void MainWindow::loadArchive(const QString &strArchiveFullPath)
{
qDebug() << "Loading archive:" << strArchiveFullPath;
if (!QFileInfo(strArchiveFullPath).isReadable()) {
qWarning() << "No permission to load archive:" << strArchiveFullPath;
TipDialog dialog(this);
dialog.showDialog(tr("You do not have permission to load %1").arg(strArchiveFullPath), tr("OK", "button"), DDialog::ButtonNormal);
return;
}
PERF_PRINT_BEGIN("POINT-05", "加载时间");
m_operationtype = Operation_Load;
qDebug() << "Archive load operation started";
//处理分卷包名称
QString transFile = strArchiveFullPath;
qDebug() << "Processing split archive name";
QStringList listSupportedMimeTypes = PluginManager::get_instance().supportedWriteMimeTypes(PluginManager::SortByComment); // 获取支持的压缩格式
CustomMimeType mimeType = determineMimeType(transFile);
qDebug() << "Archive mime type:" << mimeType.name();
// 构建压缩包加载之后的数据
m_stUnCompressParameter.strFullPath = strArchiveFullPath;
UiTools::transSplitFileName(transFile, m_stUnCompressParameter.eSplitVolume);
QFileInfo fileinfo(transFile);
if (!fileinfo.exists()) {
// 分卷不完整(损坏)
qCritical() << "Split archive volume missing:" << transFile;
m_ePageID = PI_Failure;
showErrorMessage(FI_Load, EI_ArchiveMissingVolume);
return;
}
m_stUnCompressParameter.bCommentModifiable = (mimeType.name() == "application/zip") ? true : false;
m_stUnCompressParameter.bMultiplePassword = (mimeType.name() == "application/zip") ? true : false;
m_stUnCompressParameter.bModifiable = (listSupportedMimeTypes.contains(mimeType.name()) && fileinfo.isWritable()
&& m_stUnCompressParameter.eSplitVolume == UnCompressParameter::ST_No); // 支持压缩且文件可写的非分卷格式才能修改数据
qDebug() << "Archive properties - modifiable:" << m_stUnCompressParameter.bModifiable
<< ", commentModifiable:" << m_stUnCompressParameter.bCommentModifiable
<< ", multiplePassword:" << m_stUnCompressParameter.bMultiplePassword;
// 监听压缩包
qDebug() << "Setting up archive file watcher";
watcherArchiveFile(transFile);
if(property(ORDER_JSON).isValid()) {
if(m_pUnCompressPage)
m_pUnCompressPage->setProperty(ORDER_JSON, property(ORDER_JSON));
}
m_pUnCompressPage->setArchiveFullPath(transFile, m_stUnCompressParameter); // 设置压缩包全路径和是否分卷
qDebug() << "Archive path set to:" << transFile;
// 根据是否可修改压缩包标志位设置打开文件选项是否可用
m_pTitleWidget->setTitleButtonEnable(m_stUnCompressParameter.bModifiable);
m_pOpenAction->setEnabled(m_stUnCompressParameter.bModifiable);
qDebug() << "UI controls enabled state set based on archive properties";
// 设置默认解压路径
if (m_pSettingDlg->getDefaultExtractPath().isEmpty()) {
qDebug() << "Setting default extract path to archive location:" << fileinfo.absolutePath();
m_pUnCompressPage->setDefaultUncompressPath(fileinfo.absolutePath()); // 设置默认解压路径
} else {
qDebug() << "Setting default extract path from settings:" << m_pSettingDlg->getDefaultExtractPath();
m_pUnCompressPage->setDefaultUncompressPath(m_pSettingDlg->getDefaultExtractPath()); // 设置默认解压路径
}
// zip分卷指定使用cli7zplugin
UiTools::AssignPluginType eType = (UnCompressParameter::ST_Zip == m_stUnCompressParameter.eSplitVolume) ?
(UiTools::AssignPluginType::APT_Cli7z) : (UiTools::AssignPluginType::APT_Auto);
qDebug() << "Using plugin type:" << static_cast<int>(eType);
// 加载操作
if (ArchiveManager::get_instance()->loadArchive(transFile, eType)) {
qDebug() << "Archive load started, showing loading page";
m_pLoadingPage->setDes(tr("Loading, please wait..."));
m_pLoadingPage->startLoading(); // 开始加载
m_ePageID = PI_Loading;
} else {
qCritical() << "No available plugin for archive type:" << mimeType.name();
// 无可用插件,回到首页
m_ePageID = PI_Home;
refreshPage();
show();
// 提示无插件
TipDialog dialog(this);
dialog.showDialog(tr("Plugin error"), tr("OK", "button"), DDialog::ButtonNormal);
}
qDebug() << "Archive load operation completed";
}
void MainWindow::timerEvent(QTimerEvent *event)
{
// qDebug() << "MainWindow::timerEvent" << event->timerId();
if (m_iInitUITimer == event->timerId()) {
if (!m_initFlag) {
// 初始化界面
qInfo() << "Initializing UI components";
initUI();
initConnections();
m_initFlag = true;
}
killTimer(m_iInitUITimer);
m_iInitUITimer = 0;
qDebug() << "UI initialization timer stopped";
} else if (m_iCompressedWatchTimerID == event->timerId()) {
qDebug() << "Checking compressed files status";
// 对压缩文件的监控
QStringList listFiles = m_pCompressPage->compressFiles();
qDebug() << "Monitoring" << listFiles.count() << "compressed files";
for (int i = 0; i < listFiles.count(); i++) {
QFileInfo info(listFiles[i]);
if (!info.exists()) {
qWarning() << "Compressed file missing:" << listFiles[i];
// 先暂停操作
ArchiveManager::get_instance()->pauseOperation();
qDebug() << "Paused current operation due to file change";
QString displayName = UiTools::toShortString(info.fileName());
QString strTips = tr("%1 was changed on the disk, please import it again.").arg(displayName);
TipDialog dialog(this);
dialog.showDialog(strTips, tr("OK", "button"), DDialog::ButtonNormal);
m_pCompressPage->refreshCompressedFiles(true, listFiles[i]);
qDebug() << "Refreshed compressed files list";
ArchiveManager::get_instance()->cancelOperation();
qDebug() << "Canceled current operation";
// 返回到列表界面
if (m_ePageID != PI_Compress) {
qDebug() << "Switching to compress page";
m_ePageID = PI_Compress;
refreshPage();
}
// 如果待压缩文件列表数目为空,回到首页
if (m_pCompressPage->compressFiles().count() == 0) {
qDebug() << "No more files to compress, switching to home page";
m_ePageID = PI_Home;
refreshPage();
}
}
}
}
}
void MainWindow::closeEvent(QCloseEvent *event)
{
// qDebug() << "MainWindow::closeEvent";
if (m_operationtype != Operation_NULL) {
qDebug() << "Application close requested with ongoing operation";
// 保存当前操作的状态以便还原操作
bool isPause = m_pProgressPage->isPause();
qInfo() << "Current operation status before close - paused:" << isPause;
// 当前还有操作正在进行
slotPause(); // 先暂停当前操作
qDebug() << "Operation paused for close confirmation";
// 创建询问关闭对话框
SimpleQueryDialog dialog(this);
int iResult = dialog.showDialog(tr("Are you sure you want to stop the ongoing task?"), tr("Cancel", "button"), DDialog::ButtonNormal, tr("Confirm", "button"), DDialog::ButtonRecommend);
// 点击确认时,停止当前操作,关闭应用
if (QDialog::Accepted == iResult) {
qDebug() << "User confirmed close, canceling operation";
slotCancel(); // 执行取消操作
event->accept();
} else {
qDebug() << "User canceled close request";
if (!isPause) { // 之前未暂停
qDebug() << "Resuming operation";
slotContinue(); // 继续之前的操作
}
event->ignore(); // 忽略退出
}
} else {
qDebug() << "Application closed with no ongoing operations";
event->accept(); // 忽略退出
}
}
bool MainWindow::checkSettings(const QString &file)
{
qDebug() << "Checking file settings for:" << file;
QFileInfo info(file);
if (!info.exists()) {
qWarning() << "File does not exist:" << file;
// 文件不存在
TipDialog dialog(this);
moveDialogToCenter(&dialog);
dialog.showDialog(tr("No such file or directory"), tr("OK", "button"), DDialog::ButtonNormal);
return false;
} else {
if (!info.isReadable()) {
qWarning() << "No read permission for file:" << file;
TipDialog dialog(this);
dialog.showDialog(tr("You do not have permission to load %1").arg(file), tr("OK", "button"), DDialog::ButtonNormal);
return false;
}
if (info.isDir()) {
qDebug() << "Selected item is a directory:" << file;
// 选择打开的是文件夹
TipDialog dialog(this);
moveDialogToCenter(&dialog);
dialog.showDialog(tr("The file format is not supported by Archive Manager"), tr("OK", "button"), DDialog::ButtonNormal);
return false;
} else {
qDebug() << "Checking file mime type";
// 文件判断
QString fileMime;
bool existMime = false; // 在设置界面是否被勾选
bool bArchive = false; // 是否是应用支持解压的格式
bool mimeIsChecked = true; // 默认该格式被勾选
// 判断内容
if (file.isEmpty()) {
qDebug() << "Empty file path";
existMime = true;
} else {
fileMime = determineMimeType(file).name();
qDebug() << "Detected mime type:" << fileMime;
if (fileMime.contains("application/"))
fileMime = fileMime.remove("application/");
if (fileMime.size() > 0) {
existMime = UiTools::isExistMimeType(fileMime, bArchive);
qDebug() << "Mime type exists in settings:" << existMime << ", is archive:" << bArchive;
} else {
qDebug() << "Unknown mime type";
existMime = false;
}
}
// 若在关联类型中没有找到勾选的此格式
if (!existMime) {
QString str;
if (bArchive) {
qDebug() << "Archive format not enabled in settings";
// 如果是压缩包,提示勾选关联类型
str = tr("Please check the file association type in the settings of Archive Manager");
} else {
qDebug() << "Unsupported file format";
// 如果不是压缩包,提示非支持的压缩格式
str = tr("The file format is not supported by Archive Manager");
}
// 弹出提示对话框
TipDialog dialog;
moveDialogToCenter(&dialog);
int re = dialog.showDialog(str, tr("OK", "button"), DDialog::ButtonNormal);
if (re != 1) { // ?
mimeIsChecked = false;
qDebug() << "User chose not to proceed with unsupported format";
}
}
qDebug() << "File check completed, result:" << mimeIsChecked;
return mimeIsChecked;
}
}
}
bool MainWindow::handleApplicationTabEventNotify(QObject *obj, QKeyEvent *evt)
{
qDebug() << "Handling tab event for object:" << obj->objectName() << "key:" << evt->key();
#if 0
if (!m_pUnCompressPage || !m_pCompressPage /*|| !m_pCompressSetting*/) {
qDebug() << "Required pages not initialized";
return false;
}
QObject *pLastObj = nullptr;
if (UiTools::isWayland()) {
pLastObj = titlebar()->findChild<DWindowOptionButton *>("DTitlebarDWindowOptionButton");
} else {
pLastObj = titlebar()->findChild<DWindowCloseButton *>("DTitlebarDWindowCloseButton");
}
int keyOfEvent = evt->key();
if (Qt::Key_Tab == keyOfEvent) { //tab焦点顺序:从上到下,从左到右
if (obj == titlebar()) { //焦点顺序:标题栏设置按钮->标题栏按钮
if (m_pTitleButton->isVisible() && m_pTitleButton->isEnabled()) {
m_pTitleButton->setFocus(Qt::TabFocusReason);
return true;
} if (m_pTitleCommentButton->isVisible() && m_pTitleCommentButton->isEnabled()) {
m_pTitleCommentButton->setFocus(Qt::TabFocusReason);
return true;
} else {
return false;
}
} else if (obj->objectName() == "CommentButton") { //焦点顺序:标题栏按钮->标题栏设置按钮
titlebar()->setFocus(Qt::TabFocusReason);
//titlebar不截获屏蔽掉,因为让他继续往下一menubutton发送tab
// return true;
} else if (obj->objectName() == "TitleButton" && !(m_pTitleCommentButton->isVisible() && m_pTitleCommentButton->isEnabled())) { //焦点顺序:标题栏按钮->标题栏设置按钮
titlebar()->setFocus(Qt::TabFocusReason);
//titlebar不截获屏蔽掉,因为让他继续往下一menubutton发送tab
// return true;
} else if (obj->objectName() == "gotoPreviousLabel") { //焦点顺序:返回上一页->文件列表
switch (m_ePageID) {
case PI_UnCompress:
m_pUnCompressPage->getUnCompressView()->setFocus(Qt::TabFocusReason);
break;
case PI_Compress:
m_pCompressPage->getCompressView()->setFocus(Qt::TabFocusReason);
break;
default:
return false;
}
return true;
} else if (obj->objectName() == "TableViewFile") { //焦点顺序:文件列表->解压路径按钮/下一步按钮
switch (m_ePageID) {
case PI_UnCompress:
m_pUnCompressPage->getUncompressPathBtn()->setFocus(Qt::TabFocusReason);
break;
case PI_Compress:
m_pCompressPage->getNextBtn()->setFocus(Qt::TabFocusReason);
break;
default:
return false;
}
return true;
} else if (obj == pLastObj) { //焦点顺序:关闭应用按钮->返回上一页/文件列表/压缩类型选择
switch (m_ePageID) {
case PI_UnCompress:
if (m_pUnCompressPage->getUnCompressView()->getHeaderView()->getpreLbl()->isVisible()) {
m_pUnCompressPage->getUnCompressView()->getHeaderView()->getpreLbl()->setFocus(Qt::TabFocusReason);
} else {
m_pUnCompressPage->getUnCompressView()->setFocus(Qt::TabFocusReason);
}
break;
case PI_Compress:
if (m_pCompressPage->getCompressView()->getHeaderView()->getpreLbl()->isVisible()) {
m_pCompressPage->getCompressView()->getHeaderView()->getpreLbl()->setFocus(Qt::TabFocusReason);
} else {
m_pCompressPage->getCompressView()->setFocus(Qt::TabFocusReason);
}
break;
case PI_CompressSetting:
m_pCompressSettingPage->getClickLbl()->setFocus(Qt::TabFocusReason);
break;
default:
return false;
}
return true;
}
} else if (Qt::Key_Backtab == keyOfEvent) { //shift+tab 焦点顺序,与tab焦点顺序相反
if (obj == pLastObj) {
if (m_pTitleCommentButton->isVisible() && m_pTitleCommentButton->isEnabled()) {
m_pTitleCommentButton->setFocus(Qt::BacktabFocusReason);
return true;
} else if (m_pTitleButton->isVisible() && m_pTitleButton->isEnabled()) {
m_pTitleButton->setFocus(Qt::BacktabFocusReason);
return true;
} else {
return false;
}
} else if (obj->objectName() == "TitleButton") {
switch (m_ePageID) {
case PI_UnCompress:
m_pUnCompressPage->getUnCompressBtn()->setFocus(Qt::BacktabFocusReason);
break;
case PI_Compress:
m_pCompressPage->getNextBtn()->setFocus(Qt::TabFocusReason);
break;
case PI_CompressSetting:
m_pCompressSettingPage->getCompressBtn()->setFocus(Qt::BacktabFocusReason);
break;
default:
return false;
}
return true;
} else if (obj->objectName() == "TableViewFile") {
if (nullptr != qobject_cast<DataTreeView *>(obj) && qobject_cast<DataTreeView *>(obj)->getHeaderView()->getpreLbl()->isVisible()) {
qobject_cast<DataTreeView *>(obj)->getHeaderView()->getpreLbl()->setFocus(Qt::BacktabFocusReason);
} else {
DWindowCloseButton *closeButton = titlebar()->findChild<DWindowCloseButton *>("DTitlebarDWindowCloseButton");
if (nullptr != closeButton) {
closeButton->setFocus(Qt::BacktabFocusReason);
}
}
return true;
} else if (obj->objectName() == "ClickTypeLabel" || obj->objectName() == "gotoPreviousLabel") {
DWindowCloseButton *closeButton = titlebar()->findChild<DWindowCloseButton *>("DTitlebarDWindowCloseButton");
if (closeButton) {
closeButton->setFocus(Qt::BacktabFocusReason);
}
return true;
} else if (obj == m_pCompressPage->getNextBtn()) {
m_pCompressPage->getCompressView()->setFocus(Qt::BacktabFocusReason);
return true;
} /*else if (obj == m_pUnCompressPage->getNextbutton()) {
m_pUnCompressPage->getPathCommandLinkButton()->setFocus(Qt::BacktabFocusReason);
return true;
}*/ else if (obj == m_pUnCompressPage->getUncompressPathBtn()) {
m_pUnCompressPage->getUnCompressView()->setFocus(Qt::BacktabFocusReason);
return true;
}
} else if (Qt::Key_Left == keyOfEvent || Qt::Key_Up == keyOfEvent) { //Key_Left、Key_Up几处顺序特殊处理*/
if (obj == m_pCompressPage->getNextBtn()) {
m_pCompressPage->getCompressView()->setFocus(Qt::BacktabFocusReason);
return true;
} else if (obj == m_pUnCompressPage->getUnCompressBtn()) {
m_pUnCompressPage->getUncompressPathBtn()->setFocus(Qt::BacktabFocusReason);
return true;
} else if (obj == m_pUnCompressPage->getUncompressPathBtn()) {
m_pUnCompressPage->getUnCompressView()->setFocus(Qt::BacktabFocusReason);
return true;
}
}
#endif
return false;
}
void MainWindow::handleQuit()
{
qDebug() << "Handling application quit request";
// 关闭处理
close();
}
void MainWindow::slotHandleArguments(const QStringList &listParam, MainWindow::ArgumentType eType)
{
qInfo() << listParam;
if (!m_initFlag) {
// 初始化界面
qInfo() << "初始化界面";
initUI();
initConnections();
m_initFlag = true;
}
if (listParam.count() == 0) {
delayQuitApp();
return;
}
qInfo() << "处理传入参数";
switch (eType) {
case AT_Open: { // 打开操作
if (!handleArguments_Open(listParam)) {
delayQuitApp();
return;
}
}
break;
case AT_RightMenu: { // 右键操作
if (!handleArguments_RightMenu(listParam)) {
delayQuitApp();
return;
}
}
break;
case AT_DragDropAdd: { // 拖拽追加操作
if (!handleArguments_Append(listParam)) {
delayQuitApp();
return;
}