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

208 lines
7.2 KiB
C++
Raw Normal View History

2021-11-17 13:23:38 +08:00
#include "systemrestore.h"
#include <QLabel>
#include <QPushButton>
#include <QComboBox>
#include <QCheckBox>
#include <QMovie>
2021-12-01 15:12:38 +08:00
#include <QHBoxLayout>
#include <QVBoxLayout>
2021-11-17 13:23:38 +08:00
#include <unistd.h>
#include "../component/clicklabel.h"
#include "../component/circlelabel.h"
2021-12-01 15:12:38 +08:00
#include "../component/mycheckbox.h"
2021-11-17 13:23:38 +08:00
#include "../component/myiconlabel.h"
#include "../component/mylabel.h"
#include "../component/mylineedit.h"
#include "../component/mypushbutton.h"
#include "../component/linelabel.h"
#include "../component/ringsprogressbar.h"
#include "../../common/utils.h"
#include "../globalbackupinfo.h"
2021-12-01 15:12:38 +08:00
#include "messageboxutils.h"
#include "backuppointlistdialog.h"
2021-11-17 13:23:38 +08:00
SystemRestore::SystemRestore(QWidget *parent) :
QStackedWidget(parent)
{
2021-11-20 12:09:26 +08:00
m_isRetainUserData = false;
2021-12-01 15:12:38 +08:00
m_isFactoryRestore = false;
m_pInterface = nullptr;
2021-11-17 13:23:38 +08:00
// 界面手写代码创建,作为练手
initFirstWidget();
}
SystemRestore::~SystemRestore()
2021-12-01 15:12:38 +08:00
{
delete m_pInterface;
m_pInterface = nullptr;
}
2021-11-17 13:23:38 +08:00
/**
* @brief
*/
void SystemRestore::initFirstWidget()
{
QWidget *first = new QWidget;
// 图片
QLabel *imageRestore_firstPage = new QLabel(first);
imageRestore_firstPage->setGeometry(421, 120, 300, 326);
QPixmap pixmap(":/images/system_restore.svg");
imageRestore_firstPage->setPixmap(pixmap);
imageRestore_firstPage->setScaledContents(true);
// 系统还原大字提示
MyLabel *labelRestore_firstPage = new MyLabel(first);
labelRestore_firstPage->setDeplayText(tr("System Restore"));
labelRestore_firstPage->setFixedWidth(500);
labelRestore_firstPage->setFixedHeight(48);
labelRestore_firstPage->move(41, 120);
// 默认水平左对齐,上下居中对齐;故不需要设置
// labelRestore_firstPage->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
// labelRestore_firstPage->setText(tr("System Backup"));
QFont font;
font.setBold(true);
font.setPixelSize(36);
labelRestore_firstPage->setFont(font);
// labelRestore_firstPage->setAttribute(Qt::WA_TranslucentBackground);
labelRestore_firstPage->setScaledContents(true);
labelRestore_firstPage->adjustSize();
// 系统还原说明
MyLabel *labelNote_firstPage = new MyLabel(first);
labelNote_firstPage->setFixedWidth(700);
labelNote_firstPage->setFixedHeight(24);
labelNote_firstPage->move(41, 180);
// 在您遇到问题时可将系统还原到以前的状态
labelNote_firstPage->setDeplayText(tr("You can restore the system to its previous state"));
font.setBold(false);
font.setPixelSize(18);
labelNote_firstPage->setFont(font);
labelNote_firstPage->setScaledContents(true);
labelNote_firstPage->adjustSize();
// 多点还原
MyIconLabel *iconMultiBackup_firstPage = new MyIconLabel(first);
iconMultiBackup_firstPage->setGeometry(41, 244, 180, 36);
iconMultiBackup_firstPage->setThemeIcon("ukui-bf-many-spot-symbolic", ":/symbos/ukui-bf-many-spot-symbolic.png");
iconMultiBackup_firstPage->setDesplayText(tr("Multi-Spot"));
iconMultiBackup_firstPage->setEnabled(false);
// 体积小
MyIconLabel *iconSmallSize_firstPage = new MyIconLabel(first);
iconSmallSize_firstPage->setGeometry(201, 244, 180, 36);
iconSmallSize_firstPage->setThemeIcon("ukui-bf-volume-symbolic", ":/symbos/ukui-bf-volume-symbolic.png");
iconSmallSize_firstPage->setDesplayText(tr("Small Size"));
iconSmallSize_firstPage->setEnabled(false);
// 安全
MyIconLabel *iconSecurity_firstPage = new MyIconLabel(first);
iconSecurity_firstPage->setGeometry(41, 296, 180, 36);
iconSecurity_firstPage->setThemeIcon("ukui-bf-security-symbolic", ":/symbos/ukui-bf-security-symbolic.png");
iconSecurity_firstPage->setDesplayText(tr("Security"));
iconSecurity_firstPage->setEnabled(false);
// 操作简单
MyIconLabel *iconSimple_firstPage = new MyIconLabel(first);
iconSimple_firstPage->setGeometry(201, 296, 180, 36);
iconSimple_firstPage->setThemeIcon("ukui-bf-simple-symbolic", ":/symbos/ukui-bf-simple-symbolic.png");
iconSimple_firstPage->setDesplayText(tr("Simple"));
iconSimple_firstPage->setEnabled(false);
// 开始还原按钮
MyPushButton *beginRestore = new MyPushButton(first);
beginRestore->setGeometry(41, 372, 180, 52);
beginRestore->setText(tr("Start Restore"));
beginRestore->setEnabled(true);
beginRestore->setAutoRepeat(true);
font.setPixelSize(24);
beginRestore->setFont(font);
2021-12-01 15:12:38 +08:00
connect(beginRestore, &MyPushButton::clicked, this, &SystemRestore::on_button_beginRestore_clicked);
// 底部控件布局
QVBoxLayout *bottomVBoxLayout = new QVBoxLayout(first);
bottomVBoxLayout->addStretch();
QHBoxLayout *bottomHBoxLayout = new QHBoxLayout(first);
bottomVBoxLayout->addLayout(bottomHBoxLayout);
bottomVBoxLayout->addSpacing(20);
bottomHBoxLayout->addStretch();
// 恢复出厂复选框
MyCheckBox * checkFactoryRestore = new MyCheckBox(tr("Factory Restore"), first);
// if (!Utils::isHuawei990())
// checkFactoryRestore->setVisible(false);
2021-11-17 13:23:38 +08:00
// 保留用户数据复选框
2021-12-01 15:12:38 +08:00
MyCheckBox * retainUserData = new MyCheckBox(tr("Retaining User Data"), first);
bottomHBoxLayout->addWidget(checkFactoryRestore);
bottomHBoxLayout->addSpacing(10);
bottomHBoxLayout->addWidget(retainUserData);
bottomHBoxLayout->addSpacing(20);
connect(checkFactoryRestore, &MyCheckBox::stateChanged, this, [=](int state) {
this->m_isFactoryRestore = Qt::Unchecked == state ? false : true;
if (this->m_isFactoryRestore) {
retainUserData->setChecked(false);
}
});
connect(retainUserData, &MyCheckBox::stateChanged, this, [=](int state) {
this->m_isRetainUserData = Qt::Unchecked == state ? false : true;
if (this->m_isRetainUserData) {
checkFactoryRestore->setChecked(false);
}
});
2021-11-17 13:23:38 +08:00
addWidget(first);
}
/**
* @brief
* @param checked
*/
void SystemRestore::on_pre_clicked(bool checked)
{
Q_UNUSED(checked)
int index = this->currentIndex() - 1;
if (index >= 0) {
this->setCurrentIndex(index);
}
}
/**
2021-12-01 15:12:38 +08:00
* @brief
2021-11-17 13:23:38 +08:00
* @param checked
*/
void SystemRestore::on_next_clicked(bool checked)
{
Q_UNUSED(checked)
int index = this->currentIndex() + 1;
if (index < this->count()) {
this->setCurrentIndex(index);
}
}
/**
2021-12-01 15:12:38 +08:00
* @brief
* @param checked
2021-11-17 13:23:38 +08:00
*/
2021-12-01 15:12:38 +08:00
void SystemRestore::on_button_beginRestore_clicked(bool checked)
2021-11-17 13:23:38 +08:00
{
2021-12-01 15:12:38 +08:00
Q_UNUSED(checked)
// 出厂还原,不用去选择备份点
if (m_isFactoryRestore) {
if (!MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(this, QObject::tr("Warning"),
QObject::tr("Restore factory settings, your system user data will not be retained"),
QObject::tr("Continue"), QObject::tr("Cancel"))) {
return;
}
//出厂还原
m_uuid = FACTORY_BACKUP_UUID;
} else {
// 系统备份点列表中选择备份点
BackupPointListDialog *backupPointListDialog = new BackupPointListDialog(this);
backupPointListDialog->exec();
}
2021-11-17 13:23:38 +08:00
}