Debian Codegraph @

src/app/view/progressview.cpp

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd.
2 //
3 // SPDX-License-Identifier: GPL-3.0-only
4
5 #include "progressview.h"
6 #include "widgetutil.h"
7 #include "deviceinfoitem.h"
8 #include "devicelistwidget.h"
9 #include <bminterface.h>
10
11 #include <DCheckBox>
12 #include <DLabel>
13 #include <DListWidget>
14 #include <DPushButton>
15 #include <DApplicationHelper>
16 #include <DTipLabel>
17 #include <DFontSizeManager>
18
19 #include <QDebug>
20 #include <QVBoxLayout>
21 #include <QFontDatabase>
22 #include <QTimerEvent>
23
24 DWIDGET_USE_NAMESPACE
25
26 ProgressView::ProgressView(DWidget *parent) : DWidget(parent)
27 ,m_iInterval(-1)
28 {
29 setObjectName("ProgressView");
30 setAutoFillBackground(true);
31 QVBoxLayout *mainLayout = new QVBoxLayout(this);
32 mainLayout->setContentsMargins(0, 1, 0, 0);
33
34 DLabel *m_title = new DLabel(tr("Burning"));
35 m_title->setAccessibleName("progressWidget_title");
36 DPalette pa = DApplicationHelper::instance()->palette(m_title);
37 QBrush brush = DApplicationHelper::instance()->palette(m_title).text();
38 pa.setBrush(DPalette::Text, brush);
39 m_title->setPalette(pa);
40 DFontSizeManager::instance()->bind(m_title, DFontSizeManager::T3);
41
42 m_waterProgress = new Dtk::Widget::DWaterProgress;
43 m_waterProgress->setAccessibleName("progressWidget_waterProgress");
44 m_waterProgress->setFixedSize(100, 100);
45
46 DLabel *m_hitsTitle = new DLabel(tr("Burning, please wait..."));
47 m_hitsTitle->setAccessibleName("progressWidget_hitsTitleLabel");
48 m_hitsTitle->setObjectName("ProgressHitsTitle");
49 DFontSizeManager::instance()->bind(m_hitsTitle, DFontSizeManager::T5);
50 m_hitsTitle->setAlignment(Qt::AlignCenter);
51 m_hitsTitle->setWordWrap(true);
52 m_hitsTitle->setContentsMargins(20, 0, 20, 0);
53
54 DTipLabel *m_hits = new DTipLabel(tr("Do not remove the disk or shut down the computer during the process"));
55 m_hits->setAccessibleName("progressWidget_hitsTipLabel");
56 m_hits->setObjectName("ProgressHits");
57 m_hits->setWordWrap(true);
58 m_hits->setAlignment(Qt::AlignCenter);
59 m_hits->setContentsMargins(20, 0, 20, 0);
60 DFontSizeManager::instance()->bind(m_hits, DFontSizeManager::T8);
61 m_hits->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
62
63 DPushButton *start = new DPushButton();
64 start->setFocusPolicy(Qt::NoFocus);
65 start->setAccessibleName("progressWidget_cancelButton");
66 start->setFixedSize(310, 36);
67 start->setObjectName("ProgressCancel");
68 start->setText(tr("Cancel", "button"));
69 DFontSizeManager::instance()->bind(start, DFontSizeManager::T6);
70
71 mainLayout->addWidget(m_title, 0, Qt::AlignHCenter);
72 mainLayout->addStretch();
73 mainLayout->addWidget(m_waterProgress, 0, Qt::AlignHCenter);
74 mainLayout->addSpacing(26);
75 mainLayout->addWidget(m_hitsTitle);
76 mainLayout->addWidget(m_hits);
77 mainLayout->addWidget(start, 0, Qt::AlignHCenter);
78 mainLayout->addStretch();
79
80 m_waterProgress->setValue(0);
81 m_waterProgress->start();
82
83 start->hide();
84
85
86 connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged,
87 this, [ = ] {
88 DPalette pa;
89 DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType();
90 if (themeType == DGuiApplicationHelper::LightType)
91 {
92 pa = palette();
93 pa.setColor(DPalette::Background, QColor(255, 255, 255));
94 setPalette(pa);
95
96 pa = m_hitsTitle->palette();
97 pa.setColor(DPalette::WindowText, QColor("#001A2E"));
98 m_hitsTitle->setPalette(pa);
99 } else if (themeType == DGuiApplicationHelper::DarkType)
100 {
101 pa = palette();
102 pa.setColor(DPalette::Background, QColor("#292929"));
103 setPalette(pa);
104 pa = m_hitsTitle->palette();
105 pa.setColor(DPalette::WindowText, QColor("#C0C6D4"));
106 m_hitsTitle->setPalette(pa);
107 }
108 });
109
110 emit DGuiApplicationHelper::instance()->themeTypeChanged(DGuiApplicationHelper::instance()->themeType());
111
112 connect(BMInterface::instance(), &BMInterface::reportProgress,
113 this, [ = ](quint32 current, quint32 error, const QString & title, const QString & description) {
114 qDebug() << error << current << title << description;
115
116 if (current <= 70) {
117 m_waterProgress->setValue(static_cast<int>(current));
118 }
119 else if (current <= 100) {
120 if(m_iInterval == -1) {
121 m_iInterval = QObject::startTimer(10000);
122 }
123 }
124 else {
125 qDebug() << "finish" << current << error;
126
127 if(m_iInterval != -1) {
128 QObject::killTimer(m_iInterval);
129 m_iInterval = -1;
130 }
131
132 emit finish(current, error, title, description);
133 }
134 });
135 }
136
137 void ProgressView::timerEvent(QTimerEvent *event)
138 {
139 if (m_iInterval == event->timerId()) {
140 int iVal = m_waterProgress->value();
141
142 if (iVal < 99) {
143 m_waterProgress->setValue(m_waterProgress->value() + 1);
144 }
145 }
146
147 DWidget::timerEvent(event);
148 }