2021-12-06 14:55:00 +08:00
# include "managebackuppointlist.h"
# include <QSettings>
# include <QTextCodec>
# include <unistd.h>
# include "component/mylabel.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 " ) ) ;
}
2021-12-06 16:57:11 +08:00
// 隐藏备份点大小Backup Size字段
2022-01-18 17:35:26 +08:00
// m_tableWidget->hideColumn(Column_Index::Backup_Size);
2021-12-06 14:55:00 +08:00
initTableWidget ( ) ;
// 您可以删除不需要的备份,更多细节请参考“操作日志”
MyLabel * labelTips = new MyLabel ;
labelTips - > setIsOriginal ( true ) ;
labelTips - > setWordWrap ( true ) ;
2021-12-11 15:10:58 +08:00
labelTips - > setMinimumWidth ( 600 ) ;
2021-12-12 13:28:46 +08:00
labelTips - > setDeplayText ( tr ( " You can delete the backup that does not need, refer operation logs for more details " ) ) ;
2021-12-06 14:55:00 +08:00
2022-04-19 09:56:06 +08:00
m_buttonDelete = new MyPushButton ;
m_buttonDelete - > setText ( tr ( " Delete " ) ) ;
m_buttonDelete - > setProperty ( " isImportant " , true ) ;
m_buttonDelete - > setEnabled ( false ) ;
2021-12-06 14:55:00 +08:00
m_bottomLayout - > addWidget ( labelTips ) ;
m_bottomLayout - > addStretch ( ) ;
2022-04-19 09:56:06 +08:00
m_bottomLayout - > addWidget ( m_buttonDelete ) ;
2021-12-06 14:55:00 +08:00
2022-04-19 09:56:06 +08:00
connect ( m_tableWidget , & QTableWidget : : clicked , this , [ = ] ( ) {
this - > m_buttonDelete - > setEnabled ( true ) ;
} ) ;
connect ( m_buttonDelete , & MyPushButton : : clicked , this , [ = ] ( ) {
2021-12-06 14:55:00 +08:00
// 判断是否已经选中备份点
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 ;
}
// 是否确认删除此备份
2022-02-15 16:51:03 +08:00
if ( MessageBoxUtils : : QMESSAGE_BOX_WARNING_CANCEL ( this , QObject : : tr ( " Information " ) , QObject : : tr ( " Are you sure to delete the backup ? " ) , QObject : : tr ( " Ok " ) , QObject : : tr ( " Cancel " ) ) ) {
2021-12-06 14:55:00 +08:00
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 ) ;
2022-04-26 16:06:54 +08:00
QString position = this - > text ( curRow , Column_Index : : Backup_Device ) ;
backupPoint . m_iPosition = position . startsWith ( QObject : : tr ( " Customize: " ) ) ? BackupPosition : : CUSTOMIZE :
( position . startsWith ( QObject : : tr ( " Local Disk: " ) ) ? BackupPosition : : LOCAL : BackupPosition : : UDISK ) ;
2021-12-06 14:55:00 +08:00
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 ( " // " , " / " ) ;
2022-02-22 15:25:28 +08:00
2021-12-06 14:55:00 +08:00
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 ;
2022-02-22 15:25:28 +08:00
// 数据备份需要用户隔离
if ( BackupPointType : : DATA = = m_backupType ) {
// 管理员可看自己用户进行的数据备份和无用户信息的数据备份(旧备份数据)
if ( GlobelBackupInfo : : inst ( ) . isManager ( ) & & ! backupPoint . m_userId . isEmpty ( ) & & backupPoint . m_userId ! = GlobelBackupInfo : : inst ( ) . curUserId ( ) )
continue ;
// 标准用户只能看自己进行的操作
if ( ! GlobelBackupInfo : : inst ( ) . isManager ( ) & & backupPoint . m_userId ! = GlobelBackupInfo : : inst ( ) . curUserId ( ) )
continue ;
}
2021-12-06 14:55:00 +08:00
//hide factory backup
2022-06-27 11:19:34 +08:00
// if (backupPoint.m_uuid == FACTORY_BACKUP_UUID)
// continue;
2021-12-06 14:55:00 +08:00
//udisk unique
2022-07-04 16:21:55 +08:00
if ( backupPoint . m_state = = BACKUP_PARSE_STATE_SUCCESS_STRTING & & backupPoint . m_path . startsWith ( preDevPath ) ) {
2021-12-06 14:55:00 +08:00
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 ) ;
2021-12-29 11:13:34 +08:00
setItem ( indexOfRow , Column_Index : : UUID , backupPoint . m_uuid ) ;
2021-12-06 14:55:00 +08:00
setItem ( indexOfRow , Column_Index : : Backup_Time , backupPoint . m_time ) ;
2021-12-06 16:57:11 +08:00
setItem ( indexOfRow , Column_Index : : Backup_Size , backupPoint . m_size ) ;
2021-12-06 14:55:00 +08:00
QString prefixPath_to_device ;
2022-04-26 16:06:54 +08:00
if ( backupPoint . m_iPosition = = BackupPosition : : CUSTOMIZE ) {
prefixPath_to_device = QObject : : tr ( " Customize: " ) + backupPoint . m_path + BACKUP_SNAPSHOTS_PATH ;
} else if ( backupPoint . m_path . startsWith ( preDevPath ) ) {
2021-12-26 18:15:21 +08:00
QStorageInfo storage ( backupPoint . m_path ) ;
2022-01-20 17:23:26 +08:00
QString udiskName = storage . rootPath ( ) ;
prefixPath_to_device = QObject : : tr ( " Udisk Device: " ) + " " + udiskName + BACKUP_SNAPSHOTS_PATH ;
2021-12-06 14:55:00 +08:00
} else {
2022-01-13 14:06:40 +08:00
prefixPath_to_device = QObject : : tr ( " Local Disk: " ) + " " + BACKUP_SNAPSHOTS_PATH ;
2021-12-06 14:55:00 +08:00
}
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 ) ;
2021-12-06 16:57:11 +08:00
m_labelEmpty - > setVisible ( false ) ;
m_labelEmptyText - > setVisible ( false ) ;
2022-03-14 09:16:27 +08:00
m_tableWidget - > horizontalHeader ( ) - > setVisible ( true ) ;
2021-12-06 14:55:00 +08:00
} else {
2021-12-06 16:57:11 +08:00
m_labelEmpty - > setVisible ( true ) ;
m_labelEmptyText - > setVisible ( true ) ;
2022-03-14 09:16:27 +08:00
m_tableWidget - > horizontalHeader ( ) - > setVisible ( false ) ;
2021-12-06 14:55:00 +08:00
}
}
/**
* @ 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 ;
2022-04-19 09:56:06 +08:00
if ( this - > m_tableWidget - > rowCount ( ) = = 0 ) {
2021-12-06 16:57:11 +08:00
m_labelEmpty - > setVisible ( true ) ;
m_labelEmptyText - > setVisible ( true ) ;
2022-03-14 09:16:27 +08:00
m_tableWidget - > horizontalHeader ( ) - > setVisible ( false ) ;
2022-04-19 09:56:06 +08:00
this - > m_buttonDelete - > setEnabled ( false ) ;
2021-12-06 16:57:11 +08:00
}
2021-12-06 14:55:00 +08:00
} ) ;
deleteDialog - > exec ( ) ;
deleteDialog - > deleteLater ( ) ;
}