Debian Codegraph @

src/app/view/resultview.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 "resultview.h"
6 #include "widgetutil.h"
7 #include "deviceinfoitem.h"
8 #include "devicelistwidget.h"
9 #include "dwaterprogress.h"
10 #include <bminterface.h>
11 #include <backend/bmhandler.h>
12
13 #include <DListWidget>
14 #include <DApplication>
15 #include <DCheckBox>
16 #include <DLog>
17 #include <DApplicationHelper>
18 #include <DFontSizeManager>
19
20 #include <QDebug>
21 #include <QUrl>
22 #include <QVBoxLayout>
23 #include <QProcess>
24 #include <QDesktopServices>
25 #include <QFontDatabase>
26 #include <DSysInfo>
27 #include <QDBusInterface>
28 #include <QDBusAbstractInterface>
29 #include <QDBusError>
30 #include <QDBusReply>
31
32 ResultView::ResultView(DWidget *parent) : DWidget(parent)
33 {
34 setObjectName("ResultView");
35 setAutoFillBackground(true);
36 QVBoxLayout *mainLayout = new QVBoxLayout(this);
37 mainLayout->setContentsMargins(0, 1, 0, 0);
38
39 m_title = new DLabel();
40 m_title->setAccessibleName("resultWidget_title");
41 DPalette pa = DApplicationHelper::instance()->palette(m_title);
42 QBrush brush = DApplicationHelper::instance()->palette(m_title).text();
43 pa.setBrush(DPalette::Text, brush);
44 m_title->setPalette(pa);
45 DFontSizeManager::instance()->bind(m_title, DFontSizeManager::T3);
46
47 m_resultIcon = new DLabel();
48 m_resultIcon->setAccessibleName("resultWidget_resultIconLabel");
49 m_resultIcon->setObjectName("ResultIcon");
50 m_resultIcon->setPixmap(WidgetUtil::getDpiPixmap(":/theme/light/image/success.svg", this));
51
52 m_hitsTitle = new DLabel(tr("Successful"));
53 m_hitsTitle->setAccessibleName("resultWidget_hitsTitleLabel");
54 m_hitsTitle->setObjectName("ResulteHitsTitle");
55 pa = DApplicationHelper::instance()->palette(m_hitsTitle);
56 brush = DApplicationHelper::instance()->palette(m_hitsTitle).text();
57 pa.setBrush(DPalette::Text, brush);
58 m_hitsTitle->setPalette(pa);
59 m_hitsTitle->setAlignment(Qt::AlignCenter);
60 m_hitsTitle->setContentsMargins(20, 0, 20, 0);
61
62 DFontSizeManager::instance()->bind(m_hitsTitle, DFontSizeManager::T5);
63
64 m_logHits = new DLabel(/*hitsFormat.arg(log.arg(tagBegin).arg(tagEnd))*/);
65 m_logHits->setAccessibleName("resultWidget_logHitsLabel");
66 m_logHits->setObjectName("ResultErrorDescription");
67 m_logHits->setContentsMargins(20, 0, 20, 0);
68 m_logHits->setWordWrap(true);
69 m_logHits->setAlignment(Qt::AlignHCenter);
70 DFontSizeManager::instance()->bind(m_logHits, DFontSizeManager::T8);
71
72
73 m_rebootLater = new DPushButton();
74 m_rebootLater->setAccessibleName("resultWidget_rebootLaterButton");
75 m_rebootLater->setFocusPolicy(Qt::NoFocus);
76 m_rebootLater->setFixedSize(310, 36);
77 m_rebootLater->setObjectName("RebootLater");
78 m_rebootLater->setText(tr("Done", "button"));
79 m_rebootLater->setProperty("normal", true);
80 DFontSizeManager::instance()->bind(m_rebootLater, DFontSizeManager::T6);
81
82 m_rebootNow = new DPushButton();
83 m_rebootNow->setAccessibleName("resultWidget_rebootNowButton");
84 m_rebootNow->setFocusPolicy(Qt::NoFocus);
85 m_rebootNow->setFixedSize(310, 36);
86 m_rebootNow->setObjectName("RebootLater");
87 m_rebootNow->setText(tr("Reboot now"));
88 DFontSizeManager::instance()->bind(m_rebootNow, DFontSizeManager::T6);
89
90 mainLayout->addWidget(m_title, 0, Qt::AlignHCenter);
91 mainLayout->addStretch();
92 mainLayout->addWidget(m_resultIcon, 0, Qt::AlignHCenter);
93 mainLayout->addSpacing(11);
94 mainLayout->addWidget(m_hitsTitle);
95 mainLayout->addWidget(m_logHits);
96 mainLayout->addStretch();
97 mainLayout->addWidget(m_rebootLater, 0, Qt::AlignHCenter|Qt::AlignBottom);
98
99 connect(m_rebootNow, &DPushButton::clicked,
100 this, [ = ]() {
101 BMInterface::instance()->reboot();
102 });
103
104 connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged,
105 this, [ = ] {
106 DPalette pa;
107 DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType();
108 if (themeType == DGuiApplicationHelper::LightType)
109 {
110 pa = palette();
111 pa.setColor(DPalette::Background, QColor(255, 255, 255));
112 setPalette(pa);
113
114 pa = m_hitsTitle->palette();
115 pa.setColor(DPalette::WindowText, QColor("#001A2E"));
116 m_hitsTitle->setPalette(pa);
117 pa = m_logHits->palette();
118 pa.setColor(DPalette::WindowText, QColor("#526A7F"));
119 m_logHits->setPalette(pa);
120 } else if (themeType == DGuiApplicationHelper::DarkType) {
121 pa = palette();
122 pa.setColor(DPalette::Background, QColor("#292929"));
123 setPalette(pa);
124 pa = m_hitsTitle->palette();
125 pa.setColor(DPalette::WindowText, QColor("#C0C6D4"));
126 m_hitsTitle->setPalette(pa);
127 pa = m_logHits->palette();
128 pa.setColor(DPalette::WindowText, QColor("#6D7C88"));
129 m_logHits->setPalette(pa);
130 }
131 });
132
133 emit DGuiApplicationHelper::instance()->themeTypeChanged(DGuiApplicationHelper::instance()->themeType());
134
135 }
136
137 void ResultView::updateResult(quint32 error, const QString &/*title*/, const QString &/*description*/)
138 {
139 auto errorType = static_cast<BMHandler::ErrorType>(error);
140
141 switch (errorType) {
142 case BMHandler::NoError:
143 m_rebootLater->disconnect();
144 connect(m_rebootLater, &DPushButton::clicked,
145 this, [ = ]() {
146 qApp->exit(0);
147 });
148 return;
149 case BMHandler::SyscExecFailed:
150 case BMHandler::ErrorType::InstallBootloaderFailed:
151 if (DTK_NAMESPACE::DCORE_NAMESPACE::DSysInfo::uosEditionType() != DTK_NAMESPACE::DCORE_NAMESPACE::DSysInfo::UosProfessional) {
152 m_logHits->setText(tr("The error log will be uploaded automatically with the feedback. We cannot improve without your feedback"));
153 m_rebootLater->setText(tr("Submit Feedback"));
154 m_logHits->adjustSize();
155 m_rebootLater->disconnect();
156 connect(m_rebootLater, &DPushButton::clicked,
157 this, [ = ]() {
158 // FIXME: call feedback 非专业版保持链接进社区
159 if (DTK_NAMESPACE::DCORE_NAMESPACE::DSysInfo::uosEditionType() == DTK_NAMESPACE::DCORE_NAMESPACE::DSysInfo::UosCommunity) {
160 QDesktopServices::openUrl(QString("https://bbs.deepin.org/post/209286"));
161 }
162 else if(DTK_NAMESPACE::DCORE_NAMESPACE::DSysInfo::uosEditionType() == DTK_NAMESPACE::DCORE_NAMESPACE::DSysInfo::UosHome) {
163 QDesktopServices::openUrl(QString("https://bbs.chinauos.com/post/4838?id=4838&type_id=5&forum_name=%E6%A1%8C%E9%9D%A2%E4%B8%AA%E4%BA%BA%E7%89%88"));
164 }
165 else if((DTK_NAMESPACE::DCORE_NAMESPACE::DSysInfo::uosEditionType() == DTK_NAMESPACE::DCORE_NAMESPACE::DSysInfo::UosEnterprise) ||
166 (DTK_NAMESPACE::DCORE_NAMESPACE::DSysInfo::uosEditionType() == DTK_NAMESPACE::DCORE_NAMESPACE::DSysInfo::UosEnterprise))
167 {
168 QDesktopServices::openUrl(QString("https://bbs.chinauos.com/zh/post/5609"));
169 }
170 else {
171 QProcess::startDetached("deepin-feedback");
172 }
173 });
174
175 } else {
176 m_rebootLater->setText(tr("After-Sale Services"));
177 m_logHits->adjustSize();
178 m_rebootLater->disconnect();
179 connect(m_rebootLater, &DPushButton::clicked,
180 this, [ = ]() {
181 // FIXME: call service-support fix bug 19711 专业版不再调用deepin-feedback链接进社区,而是调用服务与支持客户端
182 QDBusInterface syssupport("com.deepin.dde.ServiceAndSupport", "/com/deepin/dde/ServiceAndSupport", "com.deepin.dde.ServiceAndSupport");
183 syssupport.call("ServiceSession", 2);
184 });
185 }
186 break;
187 default:
188 m_logHits->setText(BMHandler::errorString(errorType));
189 m_rebootLater->setText(tr("Close", "button"));
190 m_rebootLater->disconnect();
191 connect(m_rebootLater, &DPushButton::clicked,
192 this, [ = ]() {
193 qApp->exit(0);
194 });
195 break;
196 }
197 m_hitsTitle->setText(tr("Sorry, process failed"));
198 // m_title->setText(tr("Process failed"));
199 m_resultIcon->setPixmap(WidgetUtil::getDpiPixmap(":/theme/light/image/fail.svg", this));
200 m_logHits->show();
201 m_rebootNow->hide();
202 }
203
204 void ResultView::onLogLinkActivated(const QString &link)
205 {
206 if (link == "#show_log") {
207 QDesktopServices::openUrl(QUrl::fromLocalFile(Dtk::Core::DLogManager::getlogFilePath()));
208 }
209 }