yhkylin-backup-tools/kybackup/module/systembackup.cpp

1482 lines
56 KiB
C++
Raw Normal View History

2021-09-16 16:05:46 +08:00
#include "systembackup.h"
#include <QLabel>
#include <QPushButton>
2021-10-13 16:31:58 +08:00
#include <QComboBox>
#include <QMovie>
2021-12-01 15:12:38 +08:00
#include <QHBoxLayout>
#include <QVBoxLayout>
2022-04-19 16:13:38 +08:00
#include <QFileDialog>
#include <QtGlobal>
2021-10-26 09:24:05 +08:00
#include <unistd.h>
2021-09-16 16:05:46 +08:00
#include "../component/backuppositionselectdialog.h"
2021-10-13 16:31:58 +08:00
#include "../component/clicklabel.h"
#include "../component/circlelabel.h"
#include "../component/myiconlabel.h"
#include "../component/mylabel.h"
2021-10-26 09:24:05 +08:00
#include "../component/mylineedit.h"
#include "../component/mypushbutton.h"
2021-10-13 16:31:58 +08:00
#include "../component/linelabel.h"
2021-10-26 09:24:05 +08:00
#include "../component/ringsprogressbar.h"
2022-03-02 11:24:54 +08:00
#include "../component/pixmaplabel.h"
2021-10-13 16:31:58 +08:00
#include "../../common/utils.h"
2021-10-26 09:24:05 +08:00
#include "../globalbackupinfo.h"
2022-02-21 11:04:44 +08:00
#include "../gsettingswrapper.h"
2021-12-06 14:55:00 +08:00
#include "managebackuppointlist.h"
2022-01-18 17:35:26 +08:00
#include "messageboxutils.h"
2021-09-16 16:05:46 +08:00
SystemBackup::SystemBackup(QWidget *parent /*= nullptr*/) :
2021-10-13 16:31:58 +08:00
QStackedWidget(parent),
m_udector(new UdiskDetector()),
m_isLock(false),
2021-10-13 16:31:58 +08:00
m_isLocal(true),
2021-12-01 15:12:38 +08:00
m_systemBackupState(SystemBackupState::IDEL),
m_pInterface(nullptr)
2021-09-16 16:05:46 +08:00
{
2021-10-13 16:31:58 +08:00
// 界面手写代码创建,作为练手
2021-09-16 16:05:46 +08:00
initFirstWidget();
2021-10-13 16:31:58 +08:00
initSecondWidget();
initThirdWidget();
2021-10-26 09:24:05 +08:00
initForthWidget();
initFifthWidget();
2021-11-09 15:44:26 +08:00
initLastWidget();
2021-09-16 16:05:46 +08:00
}
SystemBackup::~SystemBackup()
2021-10-13 16:31:58 +08:00
{
delete m_udector;
2021-12-01 15:12:38 +08:00
m_udector = nullptr;
delete m_pInterface;
m_pInterface = nullptr;
2021-10-13 16:31:58 +08:00
}
2021-09-16 16:05:46 +08:00
2021-10-13 16:31:58 +08:00
/**
* @brief
*/
2021-09-16 16:05:46 +08:00
void SystemBackup::initFirstWidget()
{
QWidget *first = new QWidget;
2021-10-26 09:24:05 +08:00
// 图片
2022-03-02 11:24:54 +08:00
PixmapLabel *imageBackup_firstPage = new PixmapLabel(first);
2021-09-16 16:05:46 +08:00
imageBackup_firstPage->setGeometry(421, 120, 300, 326);
imageBackup_firstPage->setScaledContents(true);
2022-04-21 13:42:28 +08:00
imageBackup_firstPage->setLightAndDarkPixmap(":/images/system_backup.png", ":/images/system_backup_dark.png");
2021-09-16 16:05:46 +08:00
2021-10-26 09:24:05 +08:00
// 系统备份大字提示
2021-10-13 16:31:58 +08:00
MyLabel *labelBackup_firstPage = new MyLabel(first);
labelBackup_firstPage->setDeplayText(tr("System Backup"));
labelBackup_firstPage->setFixedWidth(500);
2021-09-16 16:05:46 +08:00
labelBackup_firstPage->setFixedHeight(48);
labelBackup_firstPage->move(41, 120);
// 默认水平左对齐,上下居中对齐;故不需要设置
// labelBackup_firstPage->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
// labelBackup_firstPage->setText(tr("System Backup"));
QFont font;
font.setBold(true);
font.setPixelSize(36);
labelBackup_firstPage->setFont(font);
2021-10-13 16:31:58 +08:00
// labelBackup_firstPage->setAttribute(Qt::WA_TranslucentBackground);
labelBackup_firstPage->setScaledContents(true);
2021-09-16 16:05:46 +08:00
labelBackup_firstPage->adjustSize();
2021-10-26 09:24:05 +08:00
// 系统备份说明
2021-10-13 16:31:58 +08:00
MyLabel *labelNote_firstPage = new MyLabel(first);
labelNote_firstPage->setFixedWidth(700);
2021-09-16 16:05:46 +08:00
labelNote_firstPage->setFixedHeight(24);
labelNote_firstPage->move(41, 180);
2021-10-13 16:31:58 +08:00
labelNote_firstPage->setDeplayText(tr("Can be restored when files are damaged or lost"));
2021-09-16 16:05:46 +08:00
font.setBold(false);
font.setPixelSize(18);
labelNote_firstPage->setFont(font);
2021-10-13 16:31:58 +08:00
labelNote_firstPage->setScaledContents(true);
2021-09-16 16:05:46 +08:00
labelNote_firstPage->adjustSize();
2021-10-26 09:24:05 +08:00
// 多点还原
2021-09-16 16:05:46 +08:00
MyIconLabel *iconMultiBackup_firstPage = new MyIconLabel(first);
2021-10-13 16:31:58 +08:00
iconMultiBackup_firstPage->setGeometry(41, 244, 180, 36);
iconMultiBackup_firstPage->setThemeIcon("ukui-bf-many-spot-symbolic", ":/symbos/ukui-bf-many-spot-symbolic.png");
2021-09-16 16:05:46 +08:00
iconMultiBackup_firstPage->setDesplayText(tr("Multi-Spot"));
iconMultiBackup_firstPage->setEnabled(false);
2021-10-26 09:24:05 +08:00
// 体积小
2021-09-16 16:05:46 +08:00
MyIconLabel *iconSmallSize_firstPage = new MyIconLabel(first);
2021-10-13 16:31:58 +08:00
iconSmallSize_firstPage->setGeometry(201, 244, 180, 36);
iconSmallSize_firstPage->setThemeIcon("ukui-bf-volume-symbolic", ":/symbos/ukui-bf-volume-symbolic.png");
2021-09-16 16:05:46 +08:00
iconSmallSize_firstPage->setDesplayText(tr("Small Size"));
iconSmallSize_firstPage->setEnabled(false);
2021-10-26 09:24:05 +08:00
// 安全
2021-09-16 16:05:46 +08:00
MyIconLabel *iconSecurity_firstPage = new MyIconLabel(first);
2021-10-13 16:31:58 +08:00
iconSecurity_firstPage->setGeometry(41, 296, 180, 36);
iconSecurity_firstPage->setThemeIcon("ukui-bf-security-symbolic", ":/symbos/ukui-bf-security-symbolic.png");
2021-09-16 16:05:46 +08:00
iconSecurity_firstPage->setDesplayText(tr("Security"));
iconSecurity_firstPage->setEnabled(false);
2021-10-26 09:24:05 +08:00
// 操作简单
2021-09-16 16:05:46 +08:00
MyIconLabel *iconSimple_firstPage = new MyIconLabel(first);
2021-10-13 16:31:58 +08:00
iconSimple_firstPage->setGeometry(201, 296, 180, 36);
iconSimple_firstPage->setThemeIcon("ukui-bf-simple-symbolic", ":/symbos/ukui-bf-simple-symbolic.png");
2021-09-16 16:05:46 +08:00
iconSimple_firstPage->setDesplayText(tr("Simple"));
iconSimple_firstPage->setEnabled(false);
2021-10-26 09:24:05 +08:00
// 开始备份按钮
MyPushButton *beginBackup = new MyPushButton(first);
2021-09-23 11:21:58 +08:00
beginBackup->setGeometry(41, 372, 180, 52);
beginBackup->setText(tr("Start Backup"));
beginBackup->setEnabled(true);
beginBackup->setAutoRepeat(true);
2022-03-02 11:24:54 +08:00
beginBackup->setProperty("isImportant", true);
2021-09-23 11:21:58 +08:00
font.setPixelSize(24);
beginBackup->setFont(font);
2022-01-25 14:38:00 +08:00
connect(beginBackup, &MyPushButton::clicked, this, [=](bool clicked) {
this->m_prefixDestPath = "";
this->m_backupName = "";
this->on_next_clicked(clicked);
});
2021-10-13 16:31:58 +08:00
2021-12-01 15:12:38 +08:00
// 底部控件布局
2022-01-19 14:42:11 +08:00
QHBoxLayout *bottomHBoxLayout = new QHBoxLayout;
2021-12-01 15:12:38 +08:00
bottomHBoxLayout->addStretch();
2021-10-26 09:24:05 +08:00
// 备份管理
MyPushButton *backupPointManage = new MyPushButton;
backupPointManage->setText(tr("Backup Management >>"));
backupPointManage->setFlat(true);
backupPointManage->setProperty("useButtonPalette", true);
2021-10-13 16:31:58 +08:00
QPalette pal(backupPointManage->palette());
pal.setColor(QPalette::ButtonText, this->palette().link().color());
pal.setColor(QPalette::Button, this->palette().base().color());
2021-10-13 16:31:58 +08:00
backupPointManage->setPalette(pal);
2021-12-01 15:12:38 +08:00
bottomHBoxLayout->addWidget(backupPointManage);
bottomHBoxLayout->addSpacing(20);
2022-04-18 17:26:52 +08:00
bottomHBoxLayout->setAlignment(Qt::AlignRight);
2021-12-01 15:12:38 +08:00
2022-01-19 14:42:11 +08:00
QVBoxLayout *bottomVBoxLayout = new QVBoxLayout;
bottomVBoxLayout->addStretch();
bottomVBoxLayout->addLayout(bottomHBoxLayout);
bottomVBoxLayout->addSpacing(20);
first->setLayout(bottomVBoxLayout);
connect(backupPointManage, &MyPushButton::clicked, this, [=]() {
ManageBackupPointList backupManager(first, ManageBackupPointList::SYSTEM);
2021-12-06 14:55:00 +08:00
backupManager.exec();
});
// connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::styleNameChanged, this, [=](bool isDark) {
// Q_UNUSED(isDark)
// // 深浅主题切换时,因为调色板已经更换,高亮等颜色已经改变,所以要重新加载图标。
// QPalette pal(backupPointManage->palette());
// pal.setColor(QPalette::Button, this->palette().base().color());
// backupPointManage->setPalette(pal);
// });
2021-09-16 16:05:46 +08:00
addWidget(first);
}
2021-10-13 16:31:58 +08:00
/**
* @brief
* @param checked
*/
void SystemBackup::on_pre_clicked(bool checked)
{
Q_UNUSED(checked)
int index = this->currentIndex() - 1;
if (index >= 0) {
this->setCurrentIndex(index);
}
}
/**
* @brief
* @param checked
*/
void SystemBackup::on_next_clicked(bool checked)
{
Q_UNUSED(checked)
int index = this->currentIndex() + 1;
if (index < this->count()) {
this->setCurrentIndex(index);
}
}
/**
* @brief
*/
void SystemBackup::initSecondWidget()
{
QWidget *second = new QWidget;
2022-03-23 17:36:22 +08:00
// 纵向布局
QVBoxLayout *vlayout = new QVBoxLayout;
vlayout->addSpacing(40);
2021-10-13 16:31:58 +08:00
2022-03-23 17:36:22 +08:00
// 第一行
QHBoxLayout * hlayoutLine1 = new QHBoxLayout;
hlayoutLine1->addSpacing(40);
2021-10-26 09:24:05 +08:00
// 备份路径选择提示
2021-10-13 16:31:58 +08:00
MyLabel* labelSelect = new MyLabel(second);
labelSelect->setDeplayText(tr("Please select backup position"));
2022-03-23 17:36:22 +08:00
labelSelect->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
2021-10-13 16:31:58 +08:00
QFont font;
font.setBold(true);
font.setPixelSize(18);
labelSelect->setFont(font);
2022-03-23 17:36:22 +08:00
hlayoutLine1->addWidget(labelSelect);
hlayoutLine1->setAlignment(Qt::AlignLeft);
vlayout->addLayout(hlayoutLine1);
2021-10-13 16:31:58 +08:00
2022-03-23 17:36:22 +08:00
// 第二行
vlayout->addSpacing(5);
QHBoxLayout * hlayoutLine2 = new QHBoxLayout;
hlayoutLine2->addSpacing(40);
2021-10-26 09:24:05 +08:00
// 备份路径选择框
2021-10-13 16:31:58 +08:00
QComboBox* comboSelect = new QComboBox(second);
2022-03-23 17:36:22 +08:00
comboSelect->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
QPushButton *buttonBrowse = new QPushButton;
buttonBrowse->setText(tr("Browse..."));
hlayoutLine2->addWidget(comboSelect);
hlayoutLine2->addWidget(buttonBrowse);
hlayoutLine2->addSpacing(40);
vlayout->addLayout(hlayoutLine2);
vlayout->addSpacing(56);
// 第三行
QHBoxLayout * hlayoutLine3 = new QHBoxLayout;
hlayoutLine3->addStretch();
// 上一步按钮
MyPushButton *preStep = new MyPushButton(second);
preStep->setText(tr("Back"));
preStep->setEnabled(true);
preStep->setAutoRepeat(true);
connect(preStep, &MyPushButton::clicked, this, &SystemBackup::on_pre_clicked);
hlayoutLine3->addWidget(preStep);
hlayoutLine3->addSpacing(16);
// 下一步按钮
MyPushButton *nextStep = new MyPushButton(second);
nextStep->setText(tr("Next"));
nextStep->setEnabled(false);
nextStep->setAutoRepeat(true);
nextStep->setProperty("isImportant", true);
hlayoutLine3->addWidget(nextStep);
hlayoutLine3->addStretch();
hlayoutLine3->setAlignment(Qt::AlignCenter);
vlayout->addLayout(hlayoutLine3);
vlayout->addStretch();
second->setLayout(vlayout);
addWidget(second);
2021-10-13 16:31:58 +08:00
// 添加本地默认路径、移动设备目录
connect(m_udector, &UdiskDetector::udiskListChanged, this, [=](QList<QStorageInfo> diskList) {
m_isLock = true;
2021-10-13 16:31:58 +08:00
comboSelect->clear();
2022-01-13 14:06:40 +08:00
this->m_udiskPaths.clear();
2021-10-13 16:31:58 +08:00
QIcon iconFolder = QIcon::fromTheme("insync-folder.png", QIcon(":/images/folder.png"));
2021-10-26 09:24:05 +08:00
// 如果有备份分区,则将本地默认分区备份路径放在第一个
if (GlobelBackupInfo::inst().hasBackupPartition()) {
QString qsLocalDefaultPath = Utils::getSysRootPath() + BACKUP_SNAPSHOTS_PATH;
qsLocalDefaultPath.replace("//", "/");
this->m_udiskPaths << "";
comboSelect->addItem(iconFolder, tr("local default path : ") + qsLocalDefaultPath);
}
2021-10-13 16:31:58 +08:00
QString qsPreDevPath(tr("removable devices path : "));
for (QStorageInfo& disk : diskList) {
2021-10-26 09:24:05 +08:00
this->m_udiskPaths << disk.rootPath();
2021-10-13 16:31:58 +08:00
comboSelect->addItem(iconFolder, qsPreDevPath + disk.rootPath() + BACKUP_SNAPSHOTS_PATH);
}
if (!this->m_customizePath.isEmpty()) {
comboSelect->setCurrentIndex(-1);
QLineEdit * edit = new QLineEdit;
comboSelect->setLineEdit(edit);
edit->setText(tr("customize path : ") + this->m_customizePath + BACKUP_SNAPSHOTS_PATH);
edit->setReadOnly(true);
} else if (comboSelect->count() > 0) {
nextStep->setEnabled(true);
} else {
nextStep->setEnabled(false);
}
m_isLock = false;
2021-10-13 16:31:58 +08:00
});
connect(comboSelect, QOverload<int>::of(&QComboBox::activated), this, [=]() {
if (!m_isLock) {
this->m_customizePath = "";
nextStep->setEnabled(true);
}
2022-04-19 16:13:38 +08:00
});
2021-10-13 16:31:58 +08:00
m_udector->getStorageInfo();
2022-04-19 16:13:38 +08:00
connect(buttonBrowse, &QPushButton::clicked, this, [=](){
// 是否自定义路径?自定义路径备份文件不受保护,可能导致备份文件丢失或损坏
if (!MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(GlobelBackupInfo::inst().getMainWidget(), QObject::tr("Information"),
QObject::tr("Are you sure to continue customizing the path?\nThe custom path backup file is not protected, which may cause the backup file to be lost or damaged"),
2022-04-19 16:13:38 +08:00
QObject::tr("Ok"), QObject::tr("Cancel")))
{
return ;
}
BackupPositionSelectDialog fileDialog(this);
2022-04-19 16:13:38 +08:00
if (fileDialog.exec() == QDialog::Accepted) {
QStringList selectFiles = fileDialog.selectedFiles();
if (!selectFiles.isEmpty()) {
comboSelect->setCurrentIndex(-1);
QString fileName = selectFiles.at(0);
this->m_customizePath = fileName;
2022-04-19 16:13:38 +08:00
QLineEdit * edit = new QLineEdit;
comboSelect->setLineEdit(edit);
edit->setText(tr("customize path : ") + fileName + BACKUP_SNAPSHOTS_PATH);
edit->setReadOnly(true);
nextStep->setEnabled(true);
2022-04-19 16:13:38 +08:00
}
}
});
2021-10-26 09:24:05 +08:00
connect(nextStep, &MyPushButton::clicked, this, [=](bool checked) {
2021-11-09 15:44:26 +08:00
// 备份路径选择索引
int index = comboSelect->currentIndex();
2022-04-19 16:13:38 +08:00
if (index >= 0) {
// 第一个选项是本地系统备份
this->m_isLocal = GlobelBackupInfo::inst().hasBackupPartition() && (index == 0);
this->m_prefixDestPath = this->m_udiskPaths.at(index);
} else if (this->m_customizePath.isEmpty()) {
MessageBoxUtils::QMESSAGE_BOX_WARNING(GlobelBackupInfo::inst().getMainWidget(), QObject::tr("Warning"),
QObject::tr("Please select backup position"),
QObject::tr("Ok"));
return ;
2022-04-19 16:13:38 +08:00
} else {
// 自定义备份位置的场景
this->m_isLocal = true;
this->m_prefixDestPath = this->m_customizePath;
2022-04-19 16:13:38 +08:00
}
2021-10-13 16:31:58 +08:00
this->on_next_clicked(checked);
emit this->startCheckEnv();
});
}
/**
* @brief
*/
void SystemBackup::initThirdWidget()
{
QWidget *third = new QWidget;
2022-03-23 17:36:22 +08:00
QVBoxLayout *vlayout = new QVBoxLayout;
vlayout->addSpacing(40);
2021-10-13 16:31:58 +08:00
2021-10-26 09:24:05 +08:00
// 流程进度提示栏
2021-10-13 16:31:58 +08:00
CircleLable *one = new CircleLable("1", third, 24, QColor(COLOR_BLUE));
LineLabel *line1 = new LineLabel(third, QColor(COLOR_BLUE));
CircleLable *two = new CircleLable("2", third);
LineLabel *line2 = new LineLabel(third);
CircleLable *three = new CircleLable("3", third);
LineLabel *line3 = new LineLabel(third);
CircleLable *four = new CircleLable("4", third);
2022-03-23 17:36:22 +08:00
QHBoxLayout *hlayoutTopLine1 = new QHBoxLayout;
hlayoutTopLine1->addSpacing(80);
hlayoutTopLine1->addWidget(one);
hlayoutTopLine1->addWidget(line1);
hlayoutTopLine1->addWidget(two);
hlayoutTopLine1->addWidget(line2);
hlayoutTopLine1->addWidget(three);
hlayoutTopLine1->addWidget(line3);
hlayoutTopLine1->addWidget(four);
hlayoutTopLine1->addSpacing(80);
vlayout->addLayout(hlayoutTopLine1);
2021-10-13 16:31:58 +08:00
MyLabel *label1 = new MyLabel(tr("checking"), third);
label1->setFontColor(QColor(COLOR_BLUE));
2022-03-23 17:36:22 +08:00
label1->setFixedWidth(164);
2021-10-13 16:31:58 +08:00
MyLabel *label2 = new MyLabel(tr("preparing"), third);
2022-03-23 17:36:22 +08:00
label2->setFixedWidth(164);
2022-02-21 11:04:44 +08:00
label2->setEnabled(false);
2021-10-13 16:31:58 +08:00
MyLabel *label3 = new MyLabel(tr("backuping"), third);
2022-03-23 17:36:22 +08:00
label3->setFixedWidth(164);
2022-02-21 11:04:44 +08:00
label3->setEnabled(false);
2021-10-13 16:31:58 +08:00
MyLabel *label4 = new MyLabel(tr("finished"), third);
2022-03-23 17:36:22 +08:00
label4->setFixedWidth(164);
2022-02-21 11:04:44 +08:00
label4->setEnabled(false);
2021-10-13 16:31:58 +08:00
2022-03-23 17:36:22 +08:00
QHBoxLayout *hlayoutTopLine2 = new QHBoxLayout;
hlayoutTopLine2->addSpacing(11);
hlayoutTopLine2->addWidget(label1);
hlayoutTopLine2->addStretch();
hlayoutTopLine2->addWidget(label2);
hlayoutTopLine2->addStretch();
hlayoutTopLine2->addWidget(label3);
hlayoutTopLine2->addStretch();
hlayoutTopLine2->addWidget(label4);
hlayoutTopLine2->addSpacing(11);
vlayout->addLayout(hlayoutTopLine2);
2022-04-18 17:26:52 +08:00
vlayout->addSpacing(80);
2022-03-23 17:36:22 +08:00
2021-12-09 10:00:07 +08:00
// ------------ 中部布局begin-------------
2021-12-01 15:12:38 +08:00
QHBoxLayout *hlayout = new QHBoxLayout;
hlayout->addStretch();
2022-03-23 17:36:22 +08:00
hlayout->addSpacing(80);
2021-12-01 15:12:38 +08:00
QWidget *centerFont = new QWidget(third);
2022-03-23 17:36:22 +08:00
centerFont->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
2021-12-01 15:12:38 +08:00
QVBoxLayout *vlayoutCenterFont = new QVBoxLayout;
// 第一行
QHBoxLayout *hlayoutCenterFont1 = new QHBoxLayout;
2021-10-26 09:24:05 +08:00
// 检测等待图标
2021-12-01 15:12:38 +08:00
QLabel *loadingGif = new QLabel(centerFont);
loadingGif->setFixedSize(20,20);
2021-10-26 09:24:05 +08:00
// 环境检测等待动画
2021-12-01 15:12:38 +08:00
QMovie *movie = new QMovie(":/images/loading.gif", QByteArray(), centerFont);
2021-10-26 09:24:05 +08:00
loadingGif->setMovie(movie);
2021-12-01 15:12:38 +08:00
hlayoutCenterFont1->addWidget(loadingGif);
2021-10-26 09:24:05 +08:00
// 检测结果对错图标
2021-12-01 15:12:38 +08:00
QLabel *resultLogo = new QLabel(centerFont);
resultLogo->setFixedSize(20,20);
hlayoutCenterFont1->addWidget(resultLogo);
2021-10-26 09:24:05 +08:00
// 检测中大标题
2021-12-01 15:12:38 +08:00
MyLabel *bigTitle = new MyLabel(centerFont);
2021-10-26 09:24:05 +08:00
bigTitle->setFontSize(24);
2022-01-21 09:51:10 +08:00
bigTitle->setIsOriginal(true);
2022-03-23 17:36:22 +08:00
bigTitle->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
2021-12-01 15:12:38 +08:00
hlayoutCenterFont1->addWidget(bigTitle);
2022-03-23 17:36:22 +08:00
hlayoutCenterFont1->setAlignment(Qt::AlignLeft);
2021-12-01 15:12:38 +08:00
vlayoutCenterFont->addLayout(hlayoutCenterFont1);
// 第二行
2022-04-18 17:26:52 +08:00
vlayoutCenterFont->addSpacing(16);
2021-12-01 15:12:38 +08:00
QHBoxLayout *hlayoutCenterFont2 = new QHBoxLayout;
hlayoutCenterFont2->addSpacing(10);
// 检测中的记录黑点1和文字1
CircleLable *dot1 = new CircleLable(QString(""), centerFont, 6, Qt::black);
hlayoutCenterFont2->addWidget(dot1);
hlayoutCenterFont2->addSpacing(5);
MyLabel *labelCheck1 = new MyLabel(centerFont);
labelCheck1->setIsOriginal(true);
labelCheck1->setWordWrap(true);
labelCheck1->adjustSize();
2022-03-23 17:36:22 +08:00
labelCheck1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
2021-12-01 15:12:38 +08:00
hlayoutCenterFont2->addWidget(labelCheck1);
2022-03-23 17:36:22 +08:00
hlayoutCenterFont2->setAlignment(Qt::AlignLeft);
2021-12-01 15:12:38 +08:00
vlayoutCenterFont->addLayout(hlayoutCenterFont2);
// 第三行
QHBoxLayout *hlayoutCenterFont3 = new QHBoxLayout;
hlayoutCenterFont3->addSpacing(10);
// 检测中的记录黑点2和文字2
CircleLable *dot2 = new CircleLable(QString(""), centerFont, 6, Qt::black);
hlayoutCenterFont3->addWidget(dot2);
hlayoutCenterFont3->addSpacing(5);
MyLabel *labelCheck2 = new MyLabel(centerFont);
labelCheck2->setIsOriginal(true);
labelCheck2->setWordWrap(true);
labelCheck2->adjustSize();
2022-03-23 17:36:22 +08:00
labelCheck2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
2021-12-01 15:12:38 +08:00
hlayoutCenterFont3->addWidget(labelCheck2);
2022-03-23 17:36:22 +08:00
hlayoutCenterFont3->setAlignment(Qt::AlignLeft);
2021-12-01 15:12:38 +08:00
vlayoutCenterFont->addLayout(hlayoutCenterFont3);
// 第四行
2022-04-18 17:26:52 +08:00
vlayoutCenterFont->addSpacing(56);
2021-12-01 15:12:38 +08:00
// 第五行
QHBoxLayout *hlayoutCenterFont5 = new QHBoxLayout;
2022-03-23 17:36:22 +08:00
hlayoutCenterFont5->addStretch();
2021-10-26 09:24:05 +08:00
// 上一步按钮
2021-12-01 15:12:38 +08:00
MyPushButton *preStep = new MyPushButton(centerFont);
2022-02-11 13:48:46 +08:00
preStep->setText(tr("Back"));
2021-10-26 09:24:05 +08:00
preStep->setEnabled(true);
preStep->setAutoRepeat(true);
connect(preStep, &MyPushButton::clicked, this, &SystemBackup::on_pre_clicked);
2021-12-01 15:12:38 +08:00
hlayoutCenterFont5->addWidget(preStep);
2022-04-18 17:26:52 +08:00
hlayoutCenterFont5->addSpacing(16);
2021-10-26 09:24:05 +08:00
// 下一步按钮
2021-12-01 15:12:38 +08:00
MyPushButton *nextStep = new MyPushButton(centerFont);
2022-02-11 13:48:46 +08:00
nextStep->setText(tr("Next"));
2021-10-26 09:24:05 +08:00
nextStep->setEnabled(true);
nextStep->setAutoRepeat(true);
2022-04-18 17:26:52 +08:00
nextStep->setProperty("isImportant", true);
2021-10-26 09:24:05 +08:00
connect(nextStep, &MyPushButton::clicked, this, [=](bool checked) {
this->on_next_clicked(checked);
2021-12-11 18:32:29 +08:00
emit this->clearBackupName();
2021-10-26 09:24:05 +08:00
});
2021-12-01 15:12:38 +08:00
hlayoutCenterFont5->addWidget(nextStep);
2021-10-26 09:24:05 +08:00
// 重新检测按钮
2021-12-01 15:12:38 +08:00
MyPushButton *recheck = new MyPushButton(centerFont);
2022-02-11 13:48:46 +08:00
recheck->setText(tr("Recheck"));
2021-10-26 09:24:05 +08:00
recheck->setEnabled(true);
recheck->setAutoRepeat(true);
2022-04-18 17:26:52 +08:00
recheck->setProperty("isImportant", true);
2021-10-26 09:24:05 +08:00
connect(recheck, &MyPushButton::clicked, this, [=](bool checked) {
2021-11-17 11:47:15 +08:00
Q_UNUSED(checked)
emit this->startCheckEnv();
2021-10-26 09:24:05 +08:00
});
2021-12-01 15:12:38 +08:00
hlayoutCenterFont5->addWidget(recheck);
hlayoutCenterFont5->addStretch();
2022-03-23 17:36:22 +08:00
hlayoutCenterFont5->setAlignment(Qt::AlignCenter);
2021-12-01 15:12:38 +08:00
vlayoutCenterFont->addLayout(hlayoutCenterFont5);
centerFont->setLayout(vlayoutCenterFont);
hlayout->addWidget(centerFont);
2022-03-23 17:36:22 +08:00
hlayout->addSpacing(80);
2021-12-01 15:12:38 +08:00
hlayout->addStretch();
2022-03-23 17:36:22 +08:00
hlayout->setAlignment(Qt::AlignCenter);
2021-12-01 15:12:38 +08:00
vlayout->addLayout(hlayout);
2022-03-23 17:36:22 +08:00
2021-12-01 15:12:38 +08:00
vlayout->addStretch();
third->setLayout(vlayout);
2021-12-09 10:00:07 +08:00
// ------------ 中部布局end-------------
2021-10-26 09:24:05 +08:00
// 开始检测
connect(this, &SystemBackup::startCheckEnv, this, [=]() {
this->m_systemBackupState = SystemBackupState::CHECKING;
2022-02-28 13:58:49 +08:00
loadingGif->setVisible(true);
2021-10-26 09:24:05 +08:00
movie->start();
resultLogo->setVisible(false);
// 环境检测中,请等待
2021-12-09 10:00:07 +08:00
bigTitle->setDeplayText(tr("Checking, wait a moment ..."));
2021-10-26 09:24:05 +08:00
dot1->setBackgroundColor(Qt::black);
dot2->setBackgroundColor(Qt::black);
2021-12-11 15:10:58 +08:00
labelCheck1->setFontColor(Qt::black);
labelCheck2->setFontColor(Qt::black);
2021-12-01 15:12:38 +08:00
// 备份过程中不要做其它操作,以防数据丢失
labelCheck1->setDeplayText(tr("Do not perform other operations during backup to avoid data loss"));
2021-10-26 09:24:05 +08:00
if (this->m_isLocal) {
// 检测备份分区空间是否充足···
labelCheck2->setDeplayText(tr("Check whether the remaining capacity of the backup partition is sufficient"));
} else {
// 检测移动设备空间是否充足···
labelCheck2->setDeplayText(tr("Check whether the remaining capacity of the removable device is sufficient"));
}
preStep->setVisible(false);
nextStep->setVisible(false);
recheck->setVisible(false);
this->on_checkEnv_start();
});
// 检测结果
connect(this, &SystemBackup::checkEnvResult, this, [=](bool result, const QString &errMsg, const QString &errTip) {
loadingGif->setVisible(false);
movie->stop();
if (result) {
QIcon icon = QIcon::fromTheme("ukui-dialog-success", QIcon(":/symbos/ukui-dialog-success.png"));
resultLogo->setPixmap(icon.pixmap(QSize(20,20)));
resultLogo->setVisible(true);
// 检测成功
2022-01-21 11:26:40 +08:00
bigTitle->setDeplayText(tr("Check success"));
2021-10-26 09:24:05 +08:00
// 备份空间充足
labelCheck1->setDeplayText(tr("The storage for backup is enough"));
dot2->setBackgroundColor(COLOR_YELLOW);
labelCheck2->setFontColor(COLOR_YELLOW);
labelCheck2->setFontWordWrap(true);
// 请确保电脑已连接电源或电量超过60%
labelCheck2->setDeplayText(tr("Make sure the computer is plugged in or the battery level is above 60%"));
dot1->setVisible(true);
dot2->setVisible(true);
labelCheck1->setVisible(true);
labelCheck2->setVisible(true);
nextStep->setVisible(true);
recheck->setVisible(false);
} else {
QIcon icon = QIcon::fromTheme("dialog-error.png", QIcon(":/symbos/dialog-error.png"));
resultLogo->setPixmap(icon.pixmap(QSize(20,20)));
resultLogo->setVisible(true);
// 环境校验失败
2022-01-21 11:26:40 +08:00
bigTitle->setDeplayText(tr("Check failure"));
2021-10-26 09:24:05 +08:00
labelCheck1->setDeplayText(errMsg);
labelCheck2->setDeplayText(errTip);
if (errMsg.isEmpty()) {
dot1->setVisible(false);
labelCheck1->setVisible(false);
} else {
dot1->setVisible(true);
labelCheck1->setVisible(true);
}
if (errTip.isEmpty()) {
dot2->setVisible(false);
labelCheck2->setVisible(false);
} else {
dot2->setVisible(true);
labelCheck2->setVisible(true);
}
recheck->setVisible(true);
nextStep->setVisible(false);
}
preStep->setVisible(true);
});
2021-10-13 16:31:58 +08:00
addWidget(third);
}
2021-10-26 09:24:05 +08:00
/**
* @brief
*/
void SystemBackup::on_checkEnv_start()
{
GlobelBackupInfo::inst().setIsBusy(true);
m_pInterface = new ComKylinBackupManagerInterface("com.kylin.backup", "/", QDBusConnection::systemBus(), this);
connect(m_pInterface, &ComKylinBackupManagerInterface::sendEnvCheckResult, this, &SystemBackup::on_checkEnv_end);
2021-11-09 15:44:26 +08:00
// 是否已存在备份、还原等操作
bool isActive = false;
if(int(BackupState::BACKUP_STATE_INIT) != m_pInterface->getBackupState(isActive)){
on_checkEnv_end(int(BackupResult::OTHER_BACKUP_OR_RESTORE_RUNNING));
return;
}
2021-10-26 09:24:05 +08:00
BackupWrapper backupWrapper;
2021-11-20 18:47:42 +08:00
backupWrapper.m_backupName = m_backupName;
2021-10-26 09:24:05 +08:00
backupWrapper.m_type = BackupType::BACKUP_SYSTEM;
2022-04-19 16:13:38 +08:00
backupWrapper.m_iPosition = m_isLocal ? (this->m_prefixDestPath.isEmpty() ? BackupPosition::LOCAL : BackupPosition::CUSTOMIZE) : BackupPosition::UDISK;
2021-11-09 15:44:26 +08:00
QString backupPath = Utils::getSysRootPath();
backupPath += "/";
backupPath.replace("//", "/");
backupWrapper.m_backupPaths << backupPath;
2021-10-26 09:24:05 +08:00
backupWrapper.m_prefixDestPath = m_prefixDestPath;
2021-11-17 11:47:15 +08:00
backupWrapper.m_backupExcludePaths.append(Utils::getFromExcludePathsFile());
if (backupWrapper.m_iPosition == BackupPosition::CUSTOMIZE)
backupWrapper.m_backupExcludePaths << m_prefixDestPath;
2021-10-26 09:24:05 +08:00
backupWrapper.m_frontUid = getuid();
2022-01-13 14:06:40 +08:00
backupWrapper.m_frontUserName = qgetenv("USER");
2021-10-26 09:24:05 +08:00
backupWrapper.m_gid = getgid();
m_pInterface->checkEnv(backupWrapper);
}
/**
* @brief
* @param result,
*/
void SystemBackup::on_checkEnv_end(int result)
{
m_systemBackupState = SystemBackupState::IDEL;
bool bRst = false;
QString errMsg, errTip;
switch (result) {
case int(BackupResult::LOCK_PROGRAM_FAIL):
// 程序锁定失败,请重试
errMsg = tr("Program lock failed, please retry");
// 可能有其它备份/还原等任务在执行
errTip = tr("There may be other backups or restores being performed");
break;
case int(BackupResult::NO_FOUND_DEALCLASS):
// 不支持的任务类型
errMsg = tr("Unsupported task type");
// 没有找到相应的处理逻辑
errTip = tr("No processing logic was found in the service");
break;
case int(BackupResult::BACKUP_PARTITION_MOUNT_FAIL):
// 备份分区挂载失败
errMsg = tr("Failed to mount the backup partition");
// 检查是否有备份分区
errTip = tr("Check whether there is a backup partition");
break;
2021-12-01 15:12:38 +08:00
case int(BackupResult::UDISK_FILESYSTEM_TYPE_IS_VFAT):
// 移动设备的文件系统是vfat格式
errMsg = tr("The filesystem of device is vfat format");
// 请换成ext4、ntfs等格式
errTip = tr("Please change filesystem format to ext3、ext4 or ntfs");
break;
case int(BackupResult::UDISK_FILESYSTEM_IS_READONLY):
// 移动设备是只读的
errMsg = tr("The device is read only");
// 请修改为可读写权限的
errTip = tr("Please chmod to rw");
break;
2021-10-26 09:24:05 +08:00
case int(BackupResult::BACKUP_CAPACITY_IS_NOT_ENOUGH):
// 备份空间不足
2021-12-01 15:12:38 +08:00
errMsg = tr("The storage for backup is not enough");
2021-10-26 09:24:05 +08:00
// 建议释放空间后重试
errTip = tr("Retry after release space");
break;
2021-11-09 15:44:26 +08:00
case int(BackupResult::OTHER_BACKUP_OR_RESTORE_RUNNING):
// 其它备份还原等操作正在执行
errMsg = tr("Other backup or restore task is being performed");
// 请稍后重试
errTip = tr("Please try again later");
break;
2021-10-26 09:24:05 +08:00
default:
bRst = true;
break;
}
2022-01-20 15:08:22 +08:00
Utils::wait(2);
2021-11-09 15:44:26 +08:00
emit checkEnvResult(bRst, errMsg, errTip);
2021-10-26 09:24:05 +08:00
GlobelBackupInfo::inst().setIsBusy(false);
disconnect(m_pInterface, &ComKylinBackupManagerInterface::sendEnvCheckResult, this, &SystemBackup::on_checkEnv_end);
2021-11-17 11:47:15 +08:00
delete m_pInterface;
m_pInterface = nullptr;
2021-10-26 09:24:05 +08:00
}
/**
* @brief
*/
void SystemBackup::initForthWidget()
{
QWidget *forth = new QWidget;
2022-03-23 17:36:22 +08:00
QVBoxLayout *vlayout = new QVBoxLayout;
vlayout->addSpacing(40);
2021-10-26 09:24:05 +08:00
// 流程进度提示栏
CircleLable *one = new CircleLable("1", forth, 24, QColor(COLOR_BLUE));
LineLabel *line1 = new LineLabel(forth, QColor(COLOR_BLUE));
CircleLable *two = new CircleLable("2", forth, 24, QColor(COLOR_BLUE));
LineLabel *line2 = new LineLabel(forth, QColor(COLOR_BLUE));
CircleLable *three = new CircleLable("3", forth);
LineLabel *line3 = new LineLabel(forth);
CircleLable *four = new CircleLable("4", forth);
2022-03-23 17:36:22 +08:00
QHBoxLayout *hlayoutTopLine1 = new QHBoxLayout;
hlayoutTopLine1->addSpacing(80);
hlayoutTopLine1->addWidget(one);
hlayoutTopLine1->addWidget(line1);
hlayoutTopLine1->addWidget(two);
hlayoutTopLine1->addWidget(line2);
hlayoutTopLine1->addWidget(three);
hlayoutTopLine1->addWidget(line3);
hlayoutTopLine1->addWidget(four);
hlayoutTopLine1->addSpacing(80);
vlayout->addLayout(hlayoutTopLine1);
2021-10-26 09:24:05 +08:00
MyLabel *label1 = new MyLabel(tr("checking"), forth);
label1->setFontColor(QColor(COLOR_BLUE));
2022-03-23 17:36:22 +08:00
label1->setFixedWidth(164);
2021-10-26 09:24:05 +08:00
MyLabel *label2 = new MyLabel(tr("preparing"), forth);
label2->setFontColor(QColor(COLOR_BLUE));
2022-03-23 17:36:22 +08:00
label2->setFixedWidth(164);
2021-10-26 09:24:05 +08:00
MyLabel *label3 = new MyLabel(tr("backuping"), forth);
2022-03-23 17:36:22 +08:00
label3->setFixedWidth(164);
2022-02-21 11:04:44 +08:00
label3->setEnabled(false);
2021-10-26 09:24:05 +08:00
MyLabel *label4 = new MyLabel(tr("finished"), forth);
2022-03-23 17:36:22 +08:00
label4->setFixedWidth(164);
2022-02-21 11:04:44 +08:00
label4->setEnabled(false);
2021-10-26 09:24:05 +08:00
2022-03-23 17:36:22 +08:00
QHBoxLayout *hlayoutTopLine2 = new QHBoxLayout;
hlayoutTopLine2->addSpacing(11);
hlayoutTopLine2->addWidget(label1);
hlayoutTopLine2->addStretch();
hlayoutTopLine2->addWidget(label2);
hlayoutTopLine2->addStretch();
hlayoutTopLine2->addWidget(label3);
hlayoutTopLine2->addStretch();
hlayoutTopLine2->addWidget(label4);
hlayoutTopLine2->addSpacing(11);
vlayout->addLayout(hlayoutTopLine2);
vlayout->addSpacing(80);
// ------------ 中部布局begin-------------
// 中部第一行
QHBoxLayout *hlayoutCenterLine1 = new QHBoxLayout;
2021-10-26 09:24:05 +08:00
// 备份名称
MyLabel *labelBackupName = new MyLabel(forth);
2022-03-23 17:36:22 +08:00
labelBackupName->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
labelBackupName->setAlignment(Qt::AlignRight | Qt::AlignHCenter);
2021-10-26 09:24:05 +08:00
labelBackupName->setDeplayText(tr("Backup Name"));
MyLineEdit *editBackupName = new MyLineEdit(forth);
2022-03-23 17:36:22 +08:00
editBackupName->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
editBackupName->setMinimumWidth(350);
2021-12-28 16:51:35 +08:00
editBackupName->setMaxLength(64);
2021-10-26 09:24:05 +08:00
editBackupName->setPlaceholderText(QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss"));
// 支持输入中英文数字和部分字符
2021-12-27 09:44:37 +08:00
// QRegExp regx("^[\u4e00-\u9fa5a-zA-Z0-9~!@#$%^&*()-_+={}':;'\\[\\].<>/? ¥()——;《》‘’:“”、?]+$"); //其中匹配中文[\u4e00-\u9fa5]
QRegExp regx("^[\u4e00-\u9fa5a-zA-Z0-9-@& +():']*$");
2021-10-26 09:24:05 +08:00
QValidator *validator = new QRegExpValidator(regx);
editBackupName->setValidator(validator);
2022-03-23 17:36:22 +08:00
labelBackupName->setFixedHeight(editBackupName->height());
hlayoutCenterLine1->addStretch();
hlayoutCenterLine1->addWidget(labelBackupName);
hlayoutCenterLine1->addWidget(editBackupName);
hlayoutCenterLine1->addSpacing(40);
hlayoutCenterLine1->addStretch();
hlayoutCenterLine1->setAlignment(Qt::AlignCenter);
vlayout->addLayout(hlayoutCenterLine1);
2021-10-26 09:24:05 +08:00
// 备份名称错误提示
MyLabel *labelError = new MyLabel(forth);
2022-03-23 17:36:22 +08:00
labelError->setFixedSize(editBackupName->size());
2021-10-26 09:24:05 +08:00
labelError->setFontSize(14);
labelError->setFontColor(Qt::red);
labelError->setVisible(false);
2022-03-23 17:36:22 +08:00
labelError->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
2021-10-26 09:24:05 +08:00
connect(editBackupName, &MyLineEdit::textChanged, this, [=](const QString &text) {
2021-12-11 18:32:29 +08:00
if (!text.isEmpty() && this->isExistsBackupName(text)) {
2021-10-26 09:24:05 +08:00
labelError->setDeplayText(tr("Name already exists"));
labelError->setVisible(true);
2022-03-23 17:36:22 +08:00
labelError->move(editBackupName->geometry().left(), editBackupName->geometry().bottom() + 10);
2021-10-26 09:24:05 +08:00
} else {
labelError->setDeplayText("");
labelError->setVisible(false);
}
});
2021-12-11 18:32:29 +08:00
connect(this, &SystemBackup::clearBackupName, this, [=]() {
this->m_backupName = "";
editBackupName->setText("");
editBackupName->setPlaceholderText(QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss"));
editBackupName->setFocus();
labelError->setDeplayText("");
labelError->setVisible(false);
});
2021-10-26 09:24:05 +08:00
2022-04-18 17:26:52 +08:00
vlayout->addSpacing(56);
2022-03-23 17:36:22 +08:00
// 中部第三行
QHBoxLayout *hlayoutCenterLine3 = new QHBoxLayout;
hlayoutCenterLine3->addStretch();
2021-10-26 09:24:05 +08:00
// 上一步按钮
MyPushButton *preStep = new MyPushButton(forth);
2022-02-11 13:48:46 +08:00
preStep->setText(tr("Back"));
2021-10-26 09:24:05 +08:00
preStep->setEnabled(true);
preStep->setAutoRepeat(true);
connect(preStep, &MyPushButton::clicked, this, &SystemBackup::on_pre_clicked);
2022-03-23 17:36:22 +08:00
hlayoutCenterLine3->addWidget(preStep);
2022-04-18 17:26:52 +08:00
hlayoutCenterLine3->addSpacing(16);
2021-10-26 09:24:05 +08:00
// 下一步按钮
MyPushButton *nextStep = new MyPushButton(forth);
2022-02-11 13:48:46 +08:00
nextStep->setText(tr("Next"));
2021-10-26 09:24:05 +08:00
nextStep->setEnabled(true);
nextStep->setAutoRepeat(true);
2022-04-18 17:26:52 +08:00
nextStep->setProperty("isImportant", true);
2021-10-26 09:24:05 +08:00
connect(nextStep, &MyPushButton::clicked, this, [=](bool checked) {
Q_UNUSED(checked)
if (labelError->isVisible()) {
editBackupName->setFocus();
} else {
this->m_backupName = editBackupName->text();
if (this->m_backupName.isEmpty()) {
this->m_backupName = editBackupName->placeholderText();
}
2021-12-11 18:32:29 +08:00
if (this->isExistsBackupName(this->m_backupName)) {
labelError->setDeplayText(tr("Name already exists"));
labelError->setVisible(true);
this->m_backupName = "";
editBackupName->setFocus();
} else {
this->on_next_clicked(checked);
emit this->startBackup();
}
2021-10-26 09:24:05 +08:00
}
});
2022-03-23 17:36:22 +08:00
hlayoutCenterLine3->addWidget(nextStep);
hlayoutCenterLine3->addStretch();
hlayoutCenterLine3->setAlignment(Qt::AlignCenter);
vlayout->addLayout(hlayoutCenterLine3);
vlayout->addStretch();
forth->setLayout(vlayout);
2021-10-26 09:24:05 +08:00
addWidget(forth);
}
/**
* @brief
* @return
*/
QList<ParseBackupList::BackupPoint> SystemBackup::getBackupPointList()
{
QList<ParseBackupList::BackupPoint> list;
for (QString backupPath : m_udiskPaths) {
if (backupPath.isEmpty())
backupPath = Utils::getSysRootPath();
backupPath += BACKUP_XML_PATH;
QFile xmlFile(backupPath);
if (!xmlFile.exists() || 0 == xmlFile.size()) {
continue;
}
ParseBackupList parse(backupPath);
list.append(parse.getBackupPointList());
}
return list;
}
/**
* @brief SystemBackup::isExistsBackupName
* @param backupName
* @return bool true-false-
*/
bool SystemBackup::isExistsBackupName(const QString & backupName)
{
2021-12-06 16:57:11 +08:00
// 首先,校验唯一性文件中
QString settingPath = Utils::getSysRootPath() + UDISK_UNIQUE_SETTINGS;
settingPath.replace("//", "/");
QSettings udisk_setting(settingPath, QSettings::IniFormat);
udisk_setting.setIniCodec(QTextCodec::codecForName("utf-8"));
udisk_setting.beginGroup(backupName);
QString uuidFound = udisk_setting.value("uuid").toString();
2021-12-12 13:02:08 +08:00
udisk_setting.endGroup();
2021-12-06 16:57:11 +08:00
if (!uuidFound.isEmpty())
2021-12-12 10:55:31 +08:00
return true;
2021-12-06 16:57:11 +08:00
2021-12-26 18:15:21 +08:00
// 不能取名为出厂备份
if (backupName == tr("factory backup"))
return true;
2022-02-11 14:27:27 +08:00
return false;
2021-10-26 09:24:05 +08:00
2022-02-11 14:27:27 +08:00
// 然后校验xml和log中的备份记录这一步只是为了保险而兼容老版本的备份以前的唯一性文件中只有U盘的备份
// QList<ParseBackupList::BackupPoint> backupPointList = getBackupPointList();
// QList<BackupWrapper> list = Utils::getBackupLogList();
// QSet<QString> setName;
// for (BackupWrapper& wraper : list) {
// if (wraper.m_backupName == wraper.m_uuid) {
// // 如果在xml中不存在则说明是此备份点是之前存在的备份点现在已经删除
// for (const ParseBackupList::BackupPoint & backupPonit : backupPointList) {
// if (backupPonit.m_uuid == wraper.m_uuid) {
// wraper.m_backupName = backupPonit.m_backupName;
// }
// }
// }
// // type==8为删除备份点操作
// if (BackupType::DELETE_BACKUP == wraper.m_type)
// setName.remove(wraper.m_backupName);
// else
// setName.insert(wraper.m_backupName);
// }
// return setName.contains(backupName);
2021-10-26 09:24:05 +08:00
}
/**
* @brief
*/
void SystemBackup::initFifthWidget()
{
QWidget *fifth = new QWidget;
2022-03-23 17:36:22 +08:00
QVBoxLayout *vlayout = new QVBoxLayout;
vlayout->setSpacing(10);
vlayout->addSpacing(40);
2021-10-26 09:24:05 +08:00
// 流程进度提示栏
CircleLable *one = new CircleLable("1", fifth, 24, QColor(COLOR_BLUE));
LineLabel *line1 = new LineLabel(fifth, QColor(COLOR_BLUE));
CircleLable *two = new CircleLable("2", fifth, 24, QColor(COLOR_BLUE));
LineLabel *line2 = new LineLabel(fifth, QColor(COLOR_BLUE));
CircleLable *three = new CircleLable("3", fifth, 24, QColor(COLOR_BLUE));
LineLabel *line3 = new LineLabel(fifth, QColor(COLOR_BLUE));
CircleLable *four = new CircleLable("4", fifth);
2022-03-23 17:36:22 +08:00
QHBoxLayout *hlayoutTopLine1 = new QHBoxLayout;
hlayoutTopLine1->addSpacing(80);
hlayoutTopLine1->addWidget(one);
hlayoutTopLine1->addWidget(line1);
hlayoutTopLine1->addWidget(two);
hlayoutTopLine1->addWidget(line2);
hlayoutTopLine1->addWidget(three);
hlayoutTopLine1->addWidget(line3);
hlayoutTopLine1->addWidget(four);
hlayoutTopLine1->addSpacing(80);
vlayout->addLayout(hlayoutTopLine1);
2021-10-26 09:24:05 +08:00
MyLabel *label1 = new MyLabel(tr("checking"), fifth);
label1->setFontColor(QColor(COLOR_BLUE));
2022-03-23 17:36:22 +08:00
label1->setFixedWidth(164);
2021-10-26 09:24:05 +08:00
MyLabel *label2 = new MyLabel(tr("preparing"), fifth);
label2->setFontColor(QColor(COLOR_BLUE));
2022-03-23 17:36:22 +08:00
label2->setFixedWidth(164);
2021-10-26 09:24:05 +08:00
MyLabel *label3 = new MyLabel(tr("backuping"), fifth);
label3->setFontColor(QColor(COLOR_BLUE));
2022-03-23 17:36:22 +08:00
label3->setFixedWidth(164);
2021-10-26 09:24:05 +08:00
MyLabel *label4 = new MyLabel(tr("finished"), fifth);
2022-03-23 17:36:22 +08:00
label4->setFixedWidth(164);
2022-02-21 11:04:44 +08:00
label4->setEnabled(false);
2021-10-26 09:24:05 +08:00
2022-03-23 17:36:22 +08:00
QHBoxLayout *hlayoutTopLine2 = new QHBoxLayout;
hlayoutTopLine2->addSpacing(11);
hlayoutTopLine2->addWidget(label1);
hlayoutTopLine2->addStretch();
hlayoutTopLine2->addWidget(label2);
hlayoutTopLine2->addStretch();
hlayoutTopLine2->addWidget(label3);
hlayoutTopLine2->addStretch();
hlayoutTopLine2->addWidget(label4);
hlayoutTopLine2->addSpacing(11);
vlayout->addLayout(hlayoutTopLine2);
2021-12-11 15:59:38 +08:00
2022-03-23 17:36:22 +08:00
vlayout->addSpacing(80);
2021-12-11 15:59:38 +08:00
2022-03-23 17:36:22 +08:00
// ------------ 中部布局begin-------------
2021-12-11 15:59:38 +08:00
// 中部第一行
QHBoxLayout *hlayoutCenterFont1 = new QHBoxLayout;
2021-11-15 13:36:00 +08:00
// 检测等待图标
2022-03-23 17:36:22 +08:00
QLabel *loadingGif = new QLabel(fifth);
2021-11-15 13:36:00 +08:00
// 环境检测等待动画
2022-03-23 17:36:22 +08:00
QMovie *movie = new QMovie(":/images/loading.gif", QByteArray(), fifth);
2021-11-15 13:36:00 +08:00
loadingGif->setMovie(movie);
2021-12-11 15:59:38 +08:00
loadingGif->setFixedSize(20,20);
2022-02-28 13:48:09 +08:00
loadingGif->setVisible(false);
2021-10-26 09:24:05 +08:00
// 进度条
2022-03-23 17:36:22 +08:00
RingsProgressbar *progressBar = new RingsProgressbar(fifth);
2021-12-11 15:59:38 +08:00
progressBar->setFixedSize(100, 100);
hlayoutCenterFont1->addStretch();
hlayoutCenterFont1->addWidget(loadingGif);
hlayoutCenterFont1->addWidget(progressBar);
hlayoutCenterFont1->addStretch();
2022-03-23 17:36:22 +08:00
hlayoutCenterFont1->setAlignment(Qt::AlignCenter);
vlayout->addLayout(hlayoutCenterFont1);
2021-10-26 09:24:05 +08:00
2021-12-11 15:59:38 +08:00
// 第二行
2022-04-18 17:26:52 +08:00
vlayout->addSpacing(16);
2021-12-11 15:59:38 +08:00
QHBoxLayout *hlayoutCenterFont2 = new QHBoxLayout;
2021-10-26 09:24:05 +08:00
// 提醒
2022-03-23 17:36:22 +08:00
MyLabel *labelTip = new MyLabel(fifth);
2021-10-26 09:24:05 +08:00
labelTip->setAlignment(Qt::AlignCenter);
2021-12-11 15:59:38 +08:00
labelTip->setIsOriginal(true);
2022-03-23 17:36:22 +08:00
labelTip->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
2021-12-11 15:59:38 +08:00
hlayoutCenterFont2->addStretch();
hlayoutCenterFont2->addWidget(labelTip);
hlayoutCenterFont2->addStretch();
2022-03-23 17:36:22 +08:00
hlayoutCenterFont2->setAlignment(Qt::AlignCenter);
vlayout->addLayout(hlayoutCenterFont2);
// 第二行(隐)
2021-12-26 18:15:21 +08:00
QHBoxLayout *hlayoutCenterFont2_1 = new QHBoxLayout;
// 备份过程提醒信息
2022-03-23 17:36:22 +08:00
MyLabel *labelTip_1 = new MyLabel(fifth);
2021-12-26 18:15:21 +08:00
labelTip_1->setAlignment(Qt::AlignCenter);
labelTip_1->setIsOriginal(true);
labelTip_1->setFontWordWrap(true);
2022-03-23 17:36:22 +08:00
labelTip_1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
2021-12-26 18:15:21 +08:00
labelTip_1->setDeplayText("");
hlayoutCenterFont2_1->addStretch();
hlayoutCenterFont2_1->addWidget(labelTip_1);
hlayoutCenterFont2_1->addStretch();
2022-03-23 17:36:22 +08:00
hlayoutCenterFont2_1->setAlignment(Qt::AlignCenter);
2022-04-01 10:13:03 +08:00
vlayout->addLayout(hlayoutCenterFont2_1);
2021-10-26 09:24:05 +08:00
2022-04-18 17:26:52 +08:00
vlayout->addSpacing(56);
2021-12-11 15:59:38 +08:00
// 第三行
QHBoxLayout *hlayoutCenterFont3 = new QHBoxLayout;
2021-11-09 15:44:26 +08:00
// 取消按钮
2022-03-23 17:36:22 +08:00
MyPushButton *cancel = new MyPushButton(fifth);
2022-02-11 13:48:46 +08:00
cancel->setText(tr("Cancel"));
2021-11-09 15:44:26 +08:00
cancel->setAutoRepeat(true);
2022-04-18 17:26:52 +08:00
cancel->setProperty("isImportant", true);
2021-12-11 15:59:38 +08:00
hlayoutCenterFont3->addStretch();
hlayoutCenterFont3->addWidget(cancel);
hlayoutCenterFont3->addStretch();
2022-03-23 17:36:22 +08:00
hlayoutCenterFont3->setAlignment(Qt::AlignCenter);
vlayout->addLayout(hlayoutCenterFont3);
2021-12-11 15:59:38 +08:00
vlayout->addStretch();
fifth->setLayout(vlayout);
// ------------ 中部布局end-------------
2021-12-26 18:15:21 +08:00
connect(this, &SystemBackup::backupWarnning, labelTip_1, [=](const QString& msg) {
labelTip_1->setVisible(true);
labelTip_1->setDeplayText(msg);
2021-12-11 15:59:38 +08:00
});
2021-11-09 15:44:26 +08:00
// 开始备份
connect(this, &SystemBackup::startBackup, this, [=] {
progressBar->setPersent(0);
2021-11-15 13:36:00 +08:00
movie->start();
2022-01-18 17:35:26 +08:00
// 不要使用电脑,以防数据丢失
2022-01-19 18:08:43 +08:00
labelTip->setDeplayText(tr("Do not use computer in case of data loss"));
2021-12-26 18:15:21 +08:00
labelTip_1->setVisible(false);
labelTip_1->setDeplayText("");
2022-01-18 17:35:26 +08:00
cancel->setEnabled(true);
2021-11-09 15:44:26 +08:00
// 开始备份
this->on_backup_start();
});
// 进度
connect(this, &SystemBackup::progress, this, [=](int state, int rate) {
Q_UNUSED(state)
progressBar->setPersent(rate);
});
// 取消备份
connect(cancel, &MyPushButton::clicked, this, [=](bool checked) {
Q_UNUSED(checked)
2022-01-18 17:35:26 +08:00
// 确定取消当前操作?
2022-04-18 17:26:52 +08:00
if (!MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(GlobelBackupInfo::inst().getMainWidget(), QObject::tr("Information"), QObject::tr("Are you sure to cancel the operation"), QObject::tr("Ok"), QObject::tr("Cancel"))) {
2022-01-18 17:35:26 +08:00
return ;
}
cancel->setEnabled(false);
if (m_pInterface)
m_pInterface->cancel();
2021-11-09 15:44:26 +08:00
});
2021-10-26 09:24:05 +08:00
addWidget(fifth);
}
2021-11-09 15:44:26 +08:00
/**
* @brief
*/
void SystemBackup::on_backup_start()
{
GlobelBackupInfo::inst().setIsBusy(true);
2021-11-17 11:47:15 +08:00
m_systemBackupState = SystemBackupState::BACKUPING;
2021-11-09 15:44:26 +08:00
m_pInterface = new ComKylinBackupManagerInterface("com.kylin.backup", "/", QDBusConnection::systemBus(), this);
connect(m_pInterface, &ComKylinBackupManagerInterface::sendEnvCheckResult, this, &SystemBackup::on_checkBackup_end);
connect(m_pInterface, &ComKylinBackupManagerInterface::progress, this, &SystemBackup::progress);
connect(m_pInterface, &ComKylinBackupManagerInterface::backupFinished, this, &SystemBackup::on_backup_end);
// 是否已存在备份、还原等操作
bool isActive = false;
if(int(BackupState::BACKUP_STATE_INIT) != m_pInterface->getBackupState(isActive)){
2021-12-26 18:15:21 +08:00
on_checkBackup_end(int(BackupResult::OTHER_BACKUP_OR_RESTORE_RUNNING));
2021-11-09 15:44:26 +08:00
return;
}
BackupWrapper backupWrapper;
2021-11-20 18:47:42 +08:00
backupWrapper.m_backupName = m_backupName;
2021-11-09 15:44:26 +08:00
backupWrapper.m_type = BackupType::BACKUP_SYSTEM;
2022-04-19 16:13:38 +08:00
backupWrapper.m_iPosition = m_isLocal ? (this->m_prefixDestPath.isEmpty() ? BackupPosition::LOCAL : BackupPosition::CUSTOMIZE) : BackupPosition::UDISK;
2021-11-09 15:44:26 +08:00
QString backupPath = Utils::getSysRootPath();
backupPath += "/";
backupPath.replace("//", "/");
backupWrapper.m_backupPaths << backupPath;
backupWrapper.m_prefixDestPath = m_prefixDestPath;
2021-11-17 11:47:15 +08:00
backupWrapper.m_backupExcludePaths.append(Utils::getFromExcludePathsFile());
if (backupWrapper.m_iPosition == BackupPosition::CUSTOMIZE)
backupWrapper.m_backupExcludePaths << m_prefixDestPath;
2021-11-09 15:44:26 +08:00
backupWrapper.m_frontUid = getuid();
2022-01-13 14:06:40 +08:00
backupWrapper.m_frontUserName = qgetenv("USER");
2021-11-09 15:44:26 +08:00
backupWrapper.m_gid = getgid();
m_pInterface->goBackup(backupWrapper);
}
/**
* @brief
* @param result
*/
void SystemBackup::on_checkBackup_end(int result)
{
bool bRst = false;
QString errMsg, errTip;
switch (result) {
case int(BackupResult::LOCK_PROGRAM_FAIL):
// 程序锁定失败,请重试
errMsg = tr("Program lock failed, please retry");
// 可能有其它备份/还原等任务在执行
errTip = tr("There may be other backups or restores being performed");
break;
case int(BackupResult::NO_FOUND_DEALCLASS):
// 不支持的任务类型
errMsg = tr("Unsupported task type");
// 没有找到相应的处理逻辑
errTip = tr("No processing logic was found in the service");
break;
case int(BackupResult::BACKUP_PARTITION_MOUNT_FAIL):
// 备份分区挂载失败
errMsg = tr("Failed to mount the backup partition");
// 检查是否有备份分区
errTip = tr("Check whether there is a backup partition");
break;
2022-01-25 14:38:00 +08:00
case int(BackupResult::UDISK_FILESYSTEM_TYPE_IS_VFAT):
// 移动设备的文件系统是vfat格式
errMsg = tr("The filesystem of device is vfat format");
// 请换成ext4、ntfs等格式
errTip = tr("Please change filesystem format to ext3、ext4 or ntfs");
break;
case int(BackupResult::UDISK_FILESYSTEM_IS_READONLY):
// 移动设备是只读的
errMsg = tr("The device is read only");
// 请修改为可读写权限的
errTip = tr("Please chmod to rw");
break;
2021-11-09 15:44:26 +08:00
case int(BackupResult::BACKUP_CAPACITY_IS_NOT_ENOUGH):
// 备份空间不足
2022-01-18 17:35:26 +08:00
errMsg = tr("The storage for backup is not enough");
2021-11-09 15:44:26 +08:00
// 建议释放空间后重试
errTip = tr("Retry after release space");
break;
case int(BackupResult::OTHER_BACKUP_OR_RESTORE_RUNNING):
// 其它备份还原等操作正在执行
errMsg = tr("Other backup or restore task is being performed");
// 请稍后重试
errTip = tr("Please try again later");
break;
case int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED):
case int(BackupResult::WRITE_STORAGEINFO_ADD_ITEM_FAIL):
case int(BackupResult::WRITE_STORAGEINFO_UPDATE_ITEM_FAIL):
// 创建备份点目录失败
2022-01-18 17:35:26 +08:00
errMsg = tr("Failed to create the backup point directory");
2021-11-09 15:44:26 +08:00
// 请检查备份目录是否有写权限
errTip = tr("Please check backup partition permissions");
break;
2021-11-20 18:47:42 +08:00
case int(BackupResult::MKSQUASHFS_START_SUCCESS):
2022-01-18 17:35:26 +08:00
// 正压缩系统到本地磁盘,请耐心等待...
2021-12-01 15:12:38 +08:00
errTip = tr("The system is being compressed to the local disk, please wait patiently...");
2021-11-20 18:47:42 +08:00
emit this->backupWarnning(errTip);
return;
2022-01-25 14:38:00 +08:00
case int(BackupResult::MKSQUASHFS_DO_FAIL):
break;
case int(BackupResult::BACKUP_START_SUCCESS): // 非移动设备备份不需要此信号
case int(BackupResult::MKSQUASHFS_DO_SUCCESS):
2022-01-19 18:08:43 +08:00
// 正在传输image文件到移动设备即将完成...
errTip = tr("Transferring image file to mobile device, about to be completed...");
2021-11-20 18:47:42 +08:00
emit this->backupWarnning(errTip);
return;
2022-01-18 17:35:26 +08:00
case int(BackupResult::CANCEL_SUCCESS):
// 已经取消本次备份
errMsg = tr("The backup had been canceled");
// 如需要可重新发起备份
errTip = tr("Re-initiate the backup if necessary");
break;
2021-11-09 15:44:26 +08:00
default:
bRst = true;
break;
}
2021-11-17 11:47:15 +08:00
if (!bRst) {
GlobelBackupInfo::inst().setIsBusy(false);
m_systemBackupState = SystemBackupState::IDEL;
this->on_next_clicked(true);
2022-01-25 14:38:00 +08:00
if (errMsg.isEmpty()) {
// 备份过程中出现错误
errMsg = tr("An error occurred during backup");
// 错误信息参考日志文件:/var/log/backup.log
errTip = tr("Error messages refer to log file : /var/log/backup.log");
}
2021-11-20 18:47:42 +08:00
emit this->checkBackupResult(bRst, errMsg, errTip);
2021-11-17 11:47:15 +08:00
disconnect(m_pInterface, &ComKylinBackupManagerInterface::sendEnvCheckResult, this, &SystemBackup::on_checkEnv_end);
disconnect(m_pInterface, &ComKylinBackupManagerInterface::progress, this, &SystemBackup::progress);
disconnect(m_pInterface, &ComKylinBackupManagerInterface::backupFinished, this, &SystemBackup::on_backup_end);
delete m_pInterface;
m_pInterface = nullptr;
}
2021-11-09 15:44:26 +08:00
}
/**
* @brief
* @param result-false ; true
*/
void SystemBackup::on_backup_end(bool result)
{
m_systemBackupState = SystemBackupState::IDEL;
this->on_next_clicked(true);
if (result) {
2021-11-17 11:47:15 +08:00
emit checkBackupResult(result);
2021-11-09 15:44:26 +08:00
} else {
// 备份过程中出现错误
QString errMsg = tr("An error occurred during backup");
// 错误信息参考日志文件:/var/log/backup.log
QString errTip = tr("Error messages refer to log file : /var/log/backup.log");
2021-11-17 11:47:15 +08:00
emit checkBackupResult(result, errMsg, errTip);
2021-11-09 15:44:26 +08:00
}
GlobelBackupInfo::inst().setIsBusy(false);
disconnect(m_pInterface, &ComKylinBackupManagerInterface::sendEnvCheckResult, this, &SystemBackup::on_checkEnv_end);
2021-11-17 11:47:15 +08:00
disconnect(m_pInterface, &ComKylinBackupManagerInterface::progress, this, &SystemBackup::progress);
2021-11-09 15:44:26 +08:00
disconnect(m_pInterface, &ComKylinBackupManagerInterface::backupFinished, this, &SystemBackup::on_backup_end);
2021-11-17 11:47:15 +08:00
delete m_pInterface;
m_pInterface = nullptr;
2021-11-09 15:44:26 +08:00
}
/**
* @brief
*/
void SystemBackup::initLastWidget()
{
QWidget *last = new QWidget;
2022-03-23 17:36:22 +08:00
QVBoxLayout *vlayout = new QVBoxLayout;
vlayout->addSpacing(40);
2021-11-09 15:44:26 +08:00
// 流程进度提示栏
CircleLable *one = new CircleLable("1", last, 24, QColor(COLOR_BLUE));
LineLabel *line1 = new LineLabel(last, QColor(COLOR_BLUE));
CircleLable *two = new CircleLable("2", last, 24, QColor(COLOR_BLUE));
LineLabel *line2 = new LineLabel(last, QColor(COLOR_BLUE));
CircleLable *three = new CircleLable("3", last, 24, QColor(COLOR_BLUE));
LineLabel *line3 = new LineLabel(last, QColor(COLOR_BLUE));
CircleLable *four = new CircleLable("4", last, 24, QColor(COLOR_BLUE));
2022-03-23 17:36:22 +08:00
QHBoxLayout *hlayoutTopLine1 = new QHBoxLayout;
hlayoutTopLine1->addSpacing(80);
hlayoutTopLine1->addWidget(one);
hlayoutTopLine1->addWidget(line1);
hlayoutTopLine1->addWidget(two);
hlayoutTopLine1->addWidget(line2);
hlayoutTopLine1->addWidget(three);
hlayoutTopLine1->addWidget(line3);
hlayoutTopLine1->addWidget(four);
hlayoutTopLine1->addSpacing(80);
vlayout->addLayout(hlayoutTopLine1);
2021-11-09 15:44:26 +08:00
MyLabel *label1 = new MyLabel(tr("checking"), last);
label1->setFontColor(QColor(COLOR_BLUE));
2022-03-23 17:36:22 +08:00
label1->setFixedWidth(164);
2021-11-09 15:44:26 +08:00
MyLabel *label2 = new MyLabel(tr("preparing"), last);
label2->setFontColor(QColor(COLOR_BLUE));
2022-03-23 17:36:22 +08:00
label2->setFixedWidth(164);
2021-11-09 15:44:26 +08:00
MyLabel *label3 = new MyLabel(tr("backuping"), last);
label3->setFontColor(QColor(COLOR_BLUE));
2022-03-23 17:36:22 +08:00
label3->setFixedWidth(164);
2021-11-09 15:44:26 +08:00
MyLabel *label4 = new MyLabel(tr("finished"), last);
label4->setFontColor(QColor(COLOR_BLUE));
2022-03-23 17:36:22 +08:00
label4->setFixedWidth(164);
QHBoxLayout *hlayoutTopLine2 = new QHBoxLayout;
hlayoutTopLine2->addSpacing(11);
hlayoutTopLine2->addWidget(label1);
hlayoutTopLine2->addStretch();
hlayoutTopLine2->addWidget(label2);
hlayoutTopLine2->addStretch();
hlayoutTopLine2->addWidget(label3);
hlayoutTopLine2->addStretch();
hlayoutTopLine2->addWidget(label4);
hlayoutTopLine2->addSpacing(11);
vlayout->addLayout(hlayoutTopLine2);
2022-04-18 17:26:52 +08:00
vlayout->addSpacing(80);
2021-11-09 15:44:26 +08:00
2021-12-01 15:12:38 +08:00
//------------ 中部布局begin-------------
QHBoxLayout *hlayout = new QHBoxLayout;
hlayout->addStretch();
2022-03-23 17:36:22 +08:00
hlayout->addSpacing(80);
2021-12-01 15:12:38 +08:00
QWidget *centerFont = new QWidget(last);
2022-03-23 17:36:22 +08:00
centerFont->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
2021-12-01 15:12:38 +08:00
QVBoxLayout *vlayoutCenterFont = new QVBoxLayout;
2021-11-09 15:44:26 +08:00
2021-12-01 15:12:38 +08:00
// 第一行
QHBoxLayout *hlayoutCenterFont1 = new QHBoxLayout;
// 备份结果对错图标
QLabel *resultLogo = new QLabel(centerFont);
resultLogo->setFixedSize(20,20);
hlayoutCenterFont1->addWidget(resultLogo);
// 检测中大标题
MyLabel *bigTitle = new MyLabel(centerFont);
bigTitle->setFontSize(24);
2022-01-21 09:51:10 +08:00
bigTitle->setIsOriginal(true);
2022-03-23 17:36:22 +08:00
bigTitle->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
2021-12-01 15:12:38 +08:00
hlayoutCenterFont1->addWidget(bigTitle);
2022-04-18 17:26:52 +08:00
// hlayoutCenterFont1->setAlignment(Qt::AlignLeft);
2021-12-01 15:12:38 +08:00
vlayoutCenterFont->addLayout(hlayoutCenterFont1);
// 第二行
QHBoxLayout *hlayoutCenterFont2 = new QHBoxLayout;
hlayoutCenterFont2->addSpacing(10);
2021-11-09 15:44:26 +08:00
// 备份结果错误提示:黑点和文字
2021-12-01 15:12:38 +08:00
CircleLable *dot1 = new CircleLable(QString(""), centerFont, 6, Qt::black);
hlayoutCenterFont2->addWidget(dot1);
hlayoutCenterFont2->addSpacing(5);
MyLabel *labelError1 = new MyLabel(centerFont);
labelError1->setIsOriginal(true);
labelError1->setWordWrap(true);
labelError1->adjustSize();
2022-03-23 17:36:22 +08:00
labelError1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
2021-12-01 15:12:38 +08:00
hlayoutCenterFont2->addWidget(labelError1);
2022-03-23 17:36:22 +08:00
hlayoutCenterFont2->setAlignment(Qt::AlignLeft);
2021-12-01 15:12:38 +08:00
vlayoutCenterFont->addLayout(hlayoutCenterFont2);
// 第三行
QHBoxLayout *hlayoutCenterFont3 = new QHBoxLayout;
hlayoutCenterFont3->addSpacing(10);
// 检测中的记录黑点2和文字2
CircleLable *dot2 = new CircleLable(QString(""), centerFont, 6, Qt::black);
hlayoutCenterFont3->addWidget(dot2);
hlayoutCenterFont3->addSpacing(5);
MyLabel *labelError2 = new MyLabel(centerFont);
labelError2->setIsOriginal(true);
labelError2->setWordWrap(true);
labelError2->adjustSize();
2022-03-23 17:36:22 +08:00
labelError2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
2021-12-01 15:12:38 +08:00
hlayoutCenterFont3->addWidget(labelError2);
2022-03-23 17:36:22 +08:00
hlayoutCenterFont3->setAlignment(Qt::AlignLeft);
2021-12-01 15:12:38 +08:00
vlayoutCenterFont->addLayout(hlayoutCenterFont3);
// 第四行
2022-04-18 17:26:52 +08:00
vlayoutCenterFont->addSpacing(56);
2021-12-01 15:12:38 +08:00
// 第五行
QHBoxLayout *hlayoutCenterFont5 = new QHBoxLayout;
2022-03-23 17:36:22 +08:00
hlayoutCenterFont5->addStretch();
2021-11-09 15:44:26 +08:00
// 返回首页
2022-01-13 14:06:40 +08:00
MyPushButton *homePage = new MyPushButton(centerFont);
2022-02-11 13:48:46 +08:00
homePage->setText(tr("Home Page"));
2021-11-09 15:44:26 +08:00
homePage->setEnabled(true);
homePage->setAutoRepeat(true);
2022-04-18 17:26:52 +08:00
homePage->setProperty("isImportant", true);
2021-12-01 15:12:38 +08:00
hlayoutCenterFont5->addWidget(homePage);
2022-04-18 17:26:52 +08:00
hlayoutCenterFont5->addSpacing(16);
2022-01-20 13:42:08 +08:00
// 再试一次
MyPushButton *retry = new MyPushButton(centerFont);
2022-02-11 13:48:46 +08:00
retry->setText(tr("Retry"));
2022-01-20 13:42:08 +08:00
retry->setEnabled(true);
retry->setAutoRepeat(true);
hlayoutCenterFont5->addWidget(retry);
2021-12-01 15:12:38 +08:00
hlayoutCenterFont5->addStretch();
2022-03-23 17:36:22 +08:00
hlayoutCenterFont5->setAlignment(Qt::AlignCenter);
2021-12-01 15:12:38 +08:00
vlayoutCenterFont->addLayout(hlayoutCenterFont5);
centerFont->setLayout(vlayoutCenterFont);
hlayout->addWidget(centerFont);
2022-03-23 17:36:22 +08:00
hlayout->addSpacing(80);
2021-12-01 15:12:38 +08:00
hlayout->addStretch();
2022-03-23 17:36:22 +08:00
hlayout->setAlignment(Qt::AlignCenter);
2021-12-01 15:12:38 +08:00
vlayout->addLayout(hlayout);
2022-03-23 17:36:22 +08:00
2021-12-01 15:12:38 +08:00
vlayout->addStretch();
last->setLayout(vlayout);
//------------ 中部布局end-------------
2021-11-09 15:44:26 +08:00
// 备份检测结果
2021-11-17 11:47:15 +08:00
connect(this, &SystemBackup::checkBackupResult, this, [=](bool result, const QString &errMsg, const QString &errTip) {
2021-11-09 15:44:26 +08:00
if (result) {
QIcon icon = QIcon::fromTheme("ukui-dialog-success", QIcon(":/symbos/ukui-dialog-success.png"));
resultLogo->setPixmap(icon.pixmap(QSize(20,20)));
resultLogo->setVisible(true);
// 备份成功
bigTitle->setDeplayText(tr("The backup is successful"));
2022-04-18 17:26:52 +08:00
hlayoutCenterFont1->setAlignment(Qt::AlignCenter);
2021-11-09 15:44:26 +08:00
dot1->setVisible(false);
dot2->setVisible(false);
labelError1->setVisible(false);
labelError2->setVisible(false);
retry->setVisible(false);
homePage->setVisible(true);
} else {
QIcon icon = QIcon::fromTheme("dialog-error.png", QIcon(":/symbos/dialog-error.png"));
resultLogo->setPixmap(icon.pixmap(QSize(20,20)));
resultLogo->setVisible(true);
2022-01-18 17:35:26 +08:00
// 备份失败
2021-11-09 15:44:26 +08:00
bigTitle->setDeplayText(tr("The backup is failed"));
2022-04-18 17:26:52 +08:00
hlayoutCenterFont1->setAlignment(Qt::AlignLeft);
2021-11-17 11:47:15 +08:00
dot1->setVisible(true);
dot2->setVisible(true);
2022-01-20 14:25:00 +08:00
labelError1->setVisible(true);
labelError2->setVisible(true);
2021-11-09 15:44:26 +08:00
labelError1->setDeplayText(errMsg);
labelError2->setDeplayText(errTip);
retry->setVisible(true);
2022-01-20 13:42:08 +08:00
homePage->setVisible(true);
2021-11-09 15:44:26 +08:00
}
});
// 再试一次
connect(retry, &MyPushButton::clicked, this, [=](bool checked) {
Q_UNUSED(checked)
this->setCurrentIndex(SystemBackupPage::NAME_BACKUP_PAGE);
});
// 返回首页
connect(homePage, &MyPushButton::clicked, this, [=](bool checked) {
Q_UNUSED(checked)
this->setCurrentIndex(SystemBackupPage::HOME_PAGE);
});
addWidget(last);
}