172 lines
6.6 KiB
C++
Executable File
172 lines
6.6 KiB
C++
Executable File
#include "managebackuppointlist.h"
|
|
#include <QSettings>
|
|
#include <QTextCodec>
|
|
#include <unistd.h>
|
|
#include "component/mylabel.h"
|
|
#include "component/mypushbutton.h"
|
|
#include "../../common/utils.h"
|
|
#include "../globalbackupinfo.h"
|
|
#include "../deletebackupdialog.h"
|
|
#include "messageboxutils.h"
|
|
|
|
ManageBackupPointList::ManageBackupPointList(QWidget *parent, BackupPointType backupType) :
|
|
BackupPointListDialog(parent),
|
|
m_backupType(backupType)
|
|
{
|
|
if (BackupPointType::SYSTEM == backupType) {
|
|
this->setWindowTitle(tr("System Backup Information"));
|
|
} else {
|
|
this->setWindowTitle(tr("Data Backup Information"));
|
|
}
|
|
|
|
// 隐藏备份点大小Backup Size字段
|
|
// m_tableWidget->hideColumn(Column_Index::Backup_Size);
|
|
initTableWidget();
|
|
|
|
// 您可以删除不需要的备份,更多细节请参考“操作日志”
|
|
MyLabel *labelTips = new MyLabel;
|
|
labelTips->setIsOriginal(true);
|
|
labelTips->setWordWrap(true);
|
|
labelTips->setMinimumWidth(600);
|
|
labelTips->setDeplayText(tr("You can delete the backup that does not need, refer operation logs for more details"));
|
|
|
|
MyPushButton * buttonDelete = new MyPushButton;
|
|
buttonDelete->setText(tr("Delete"));
|
|
|
|
m_bottomLayout->addWidget(labelTips);
|
|
m_bottomLayout->addStretch();
|
|
m_bottomLayout->addWidget(buttonDelete);
|
|
|
|
connect(buttonDelete, &MyPushButton::clicked, this, [=](){
|
|
// 判断是否已经选中备份点
|
|
QList<QTableWidgetItem *> selectList = this->m_tableWidget->selectedItems();
|
|
if (selectList.isEmpty()) {
|
|
MessageBoxUtils::QMESSAGE_BOX_WARNING(this, QObject::tr("Warning"), QObject::tr("Please select one backup to continue."), QObject::tr("Ok"));
|
|
return;
|
|
}
|
|
|
|
// 是否确认删除此备份
|
|
if (MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(this, QObject::tr("Warning"), QObject::tr("Are you sure to delete the backup ?"), QObject::tr("Ok"), QObject::tr("Cancel"))) {
|
|
int curRow = this->m_tableWidget->currentRow();
|
|
ParseBackupList::BackupPoint backupPoint;
|
|
backupPoint.m_backupName = this->text(curRow, Column_Index::Backup_Name);
|
|
backupPoint.m_uuid = this->text(curRow, Column_Index::UUID);
|
|
backupPoint.m_time = this->text(curRow, Column_Index::Backup_Time);
|
|
backupPoint.m_path = this->text(curRow, Column_Index::Prefix_Path);
|
|
m_deleteRow = curRow;
|
|
|
|
emit selected(backupPoint);
|
|
}
|
|
});
|
|
|
|
connect(this, &ManageBackupPointList::selected, this, &ManageBackupPointList::deleteBackupPoint);
|
|
connect(this, &ManageBackupPointList::udiskChange, this, &ManageBackupPointList::initTableWidget);
|
|
}
|
|
|
|
ManageBackupPointList::~ManageBackupPointList()
|
|
{
|
|
|
|
}
|
|
|
|
void ManageBackupPointList::initTableWidget()
|
|
{
|
|
m_tableWidget->clearContents();
|
|
m_tableWidget->setRowCount(0);
|
|
m_tableWidget->setSortingEnabled(false); // 等录入完数据后再排序
|
|
insertLines(getBackupPointList());
|
|
}
|
|
|
|
void ManageBackupPointList::insertLines(const QList<ParseBackupList::BackupPoint> &backupPoints)
|
|
{
|
|
QString settingPath = Utils::getSysRootPath() + UDISK_UNIQUE_SETTINGS;
|
|
settingPath.replace("//", "/");
|
|
QSettings udisk_setting(settingPath, QSettings::IniFormat);
|
|
udisk_setting.setIniCodec(QTextCodec::codecForName("utf-8"));
|
|
|
|
int indexOfRow = 0;
|
|
QString preDevPath(Utils::getSysRootPath());
|
|
preDevPath += "/media";
|
|
preDevPath.replace("//", "/");
|
|
for (const ParseBackupList::BackupPoint& backupPoint : backupPoints) {
|
|
// 系统备份排除非系统备份且非增量系统备份
|
|
if (BackupPointType::SYSTEM == m_backupType &&
|
|
int(BackupType::BACKUP_SYSTEM) != backupPoint.m_type &&
|
|
int(BackupType::INC_BACKUP_SYSTEM) != backupPoint.m_type)
|
|
continue;
|
|
else if (BackupPointType::DATA == m_backupType &&
|
|
int(BackupType::BACKUP_DATA) != backupPoint.m_type &&
|
|
int(BackupType::INC_BACKUP_DATA) != backupPoint.m_type)
|
|
continue;
|
|
|
|
//hide factory backup
|
|
if (backupPoint.m_uuid == FACTORY_BACKUP_UUID)
|
|
continue;
|
|
|
|
//udisk unique
|
|
if (backupPoint.m_path.startsWith(preDevPath)) {
|
|
udisk_setting.beginGroup(backupPoint.m_backupName);
|
|
QString localuuid = udisk_setting.value("uuid").toString();
|
|
udisk_setting.endGroup();
|
|
if (localuuid != backupPoint.m_uuid) {
|
|
continue;
|
|
}
|
|
}
|
|
|
|
m_tableWidget->insertRow(indexOfRow);
|
|
setItem(indexOfRow, Column_Index::Backup_Name, backupPoint.m_backupName);
|
|
setItem(indexOfRow, Column_Index::UUID, backupPoint.m_uuid);
|
|
setItem(indexOfRow, Column_Index::Backup_Time, backupPoint.m_time);
|
|
setItem(indexOfRow, Column_Index::Backup_Size, backupPoint.m_size);
|
|
|
|
QString prefixPath_to_device;
|
|
if (backupPoint.m_path.startsWith(preDevPath)) {
|
|
QStorageInfo storage(backupPoint.m_path);
|
|
QString udiskName = storage.rootPath();
|
|
prefixPath_to_device = QObject::tr("Udisk Device:") + " " + udiskName + BACKUP_SNAPSHOTS_PATH;
|
|
} else {
|
|
prefixPath_to_device = QObject::tr("Local Disk:") + " " + BACKUP_SNAPSHOTS_PATH;
|
|
}
|
|
setItem(indexOfRow, Column_Index::Backup_Device, prefixPath_to_device);
|
|
if (backupPoint.m_state == BACKUP_PARSE_STATE_SUCCESS_STRTING) {
|
|
setItem(indexOfRow, Column_Index::Backup_State, tr("backup finished"));
|
|
} else {
|
|
setItem(indexOfRow, Column_Index::Backup_State, tr("backup unfinished"));
|
|
}
|
|
setItem(indexOfRow, Column_Index::Prefix_Path, backupPoint.m_path);
|
|
|
|
++indexOfRow;
|
|
}
|
|
|
|
if (0 < indexOfRow) {
|
|
m_tableWidget->setSortingEnabled(true); // 等录入完数据后再排序
|
|
m_tableWidget->sortItems(Column_Index::Backup_Time, Qt::DescendingOrder);
|
|
m_labelEmpty->setVisible(false);
|
|
m_labelEmptyText->setVisible(false);
|
|
} else {
|
|
m_labelEmpty->setVisible(true);
|
|
m_labelEmptyText->setVisible(true);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief 删除备份点
|
|
* @param backupPonit
|
|
*/
|
|
void ManageBackupPointList::deleteBackupPoint(ParseBackupList::BackupPoint backupPonit)
|
|
{
|
|
DeleteBackupDialog *deleteDialog = new DeleteBackupDialog(backupPonit, this);
|
|
connect(deleteDialog, &DeleteBackupDialog::deleteFinished, this, [=](bool result) {
|
|
if (result)
|
|
this->m_tableWidget->removeRow(m_deleteRow);
|
|
m_deleteRow = -1;
|
|
if (this->m_tableWidget->rowCount() ==0) {
|
|
m_labelEmpty->setVisible(true);
|
|
m_labelEmptyText->setVisible(true);
|
|
}
|
|
});
|
|
deleteDialog->exec();
|
|
deleteDialog->deleteLater();
|
|
}
|
|
|
|
|