From caeff6dc483ab355f2c6e529948348539d2df07d Mon Sep 17 00:00:00 2001 From: zhaominyong Date: Wed, 9 Mar 2022 15:02:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E6=98=BE=E7=A4=BA=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup-daemon/parsebackuplist.cpp | 34 +++++++++++++++++++++++++ backup-daemon/parsebackuplist.h | 7 +++++ common/utils.cpp | 28 ++++++++++++++++++-- kybackup/backuppointlistdialog.cpp | 16 ++++++------ kybackup/backuppointlistdialog.h | 2 +- kybackup/component/backuplistwidget.cpp | 4 +-- kybackup/maindialog.cpp | 22 ---------------- kybackup/maindialog.h | 1 - kybackup/module/operationlog.cpp | 13 +++++----- kybackup/module/operationlog.h | 2 +- 10 files changed, 86 insertions(+), 43 deletions(-) diff --git a/backup-daemon/parsebackuplist.cpp b/backup-daemon/parsebackuplist.cpp index be79023..7e457b5 100755 --- a/backup-daemon/parsebackuplist.cpp +++ b/backup-daemon/parsebackuplist.cpp @@ -244,6 +244,40 @@ ParseBackupList::BackupPoint ParseBackupList::findBackupPointByUuid(const QStrin return backupPoint; } +/** + * @brief 获取xml文件中备份点uuid和backupname的映射 + * @param uuid_name,xml文件中备份点uuid和backupname的映射 + * @return + */ +void ParseBackupList::getXmlUuidNameMap(QMap &uuid_name) +{ + BackupPoint backupPoint; + QDomDocument doc; + if (!Doc_setContent(doc)) + return ; + + QDomElement root = doc.documentElement(); + QDomNodeList list = root.childNodes(); + + for (int i = 0; i < list.count(); i++) { + QDomNode node = list.at(i); + if (!node.isElement()) + continue; + + QDomElement eleUuid = node.firstChildElement(UUID); + if (eleUuid.isNull() || eleUuid.text().isEmpty()) + continue; + + QDomElement eleBackupName = node.firstChildElement(COMMENT); + if (eleBackupName.isNull() || eleBackupName.text().isEmpty()) + continue; + + uuid_name.insert(eleUuid.text(), eleBackupName.text()); + } + + return ; +} + /** * @brief 获取最后一次系统备份,排除自动备份点 * @return diff --git a/backup-daemon/parsebackuplist.h b/backup-daemon/parsebackuplist.h index d5f4d4f..37db3bc 100755 --- a/backup-daemon/parsebackuplist.h +++ b/backup-daemon/parsebackuplist.h @@ -74,6 +74,13 @@ public: */ BackupPoint findBackupPointByUuid(const QString& Uuid); + /** + * @brief 获取xml文件中备份点uuid和backupname的映射 + * @param uuid_name,xml文件中备份点uuid和backupname的映射 + * @return + */ + void getXmlUuidNameMap(QMap &uuid_name); + /** * @brief 获取最后一次系统备份 * @return diff --git a/common/utils.cpp b/common/utils.cpp index d404eaf..afb46d9 100755 --- a/common/utils.cpp +++ b/common/utils.cpp @@ -22,6 +22,7 @@ #include #include #include +#include "../backup-daemon/parsebackuplist.h" #include "mylittleparse.h" #include "mydefine.h" @@ -894,6 +895,9 @@ QString Utils::executeCmd(const QString &cmd, const QStringList &args) */ QList Utils::getBackupLogList() { + // 为兼容以前的老备份数据,在此处先获取uuid-name键值对 + QMap uuid_name = Utils::getBackupUuidNameMap(); + QString logFile = Utils::getSysRootPath() + BACKUP_LOG_TEXT_PATH; logFile.replace("//", "/"); QFile file(logFile); @@ -944,8 +948,11 @@ QList Utils::getBackupLogList() if (FACTORY_BACKUP_UUID == record.m_uuid) { record.m_backupName = QObject::tr("Factory Backup"); } - else if (AUTO_BACKUP_UUID == record.m_uuid) { - record.m_backupName = QObject::tr("Auto Backup"); +// else if (AUTO_BACKUP_UUID == record.m_uuid) { +// record.m_backupName = QObject::tr("Auto Backup"); +// } + else if (uuid_name.contains(record.m_uuid)) { + record.m_backupName = uuid_name.value(record.m_uuid); } else { record.m_backupName = record.m_time; @@ -1131,14 +1138,31 @@ void Utils::deleteBackupUniqueRecord(const QString& backupName) udisk_unique_settings.remove(backupName); } +/** + * @brief 获取备份点Uuid-BackupName键值对 + * @return Uuid-BackupName键值对 + */ QMap Utils::getBackupUuidNameMap() { + // 1、udisk_unique_file文件中的信息 QString backupUniqueSetting = Utils::getSysRootPath() + UDISK_UNIQUE_SETTINGS; backupUniqueSetting.replace("//", "/"); QSettings udisk_unique_settings(backupUniqueSetting, QSettings::IniFormat); QStringList groups = udisk_unique_settings.childGroups(); QMap result; + for (const QString& group : groups) { + udisk_unique_settings.beginGroup(group); + QString uuid = udisk_unique_settings.value("uuid").toString(); + udisk_unique_settings.endGroup(); + result.insert(uuid, group); + } + + // 2、本地xml文件中的信息 + QString xmlPath = Utils::getSysRootPath() + BACKUP_XML_PATH; + xmlPath.replace("//", "/"); + ParseBackupList parse(xmlPath); + parse.getXmlUuidNameMap(result); return result; } diff --git a/kybackup/backuppointlistdialog.cpp b/kybackup/backuppointlistdialog.cpp index 56d8683..4a5e584 100755 --- a/kybackup/backuppointlistdialog.cpp +++ b/kybackup/backuppointlistdialog.cpp @@ -34,14 +34,14 @@ BackupPointListDialog::BackupPointListDialog(QWidget *parent, bool isOnlyShowLoc m_tableWidget = new QTableWidget; m_tableWidget->setColumnCount(headerLabels.size()); m_tableWidget->setHorizontalHeaderLabels(headerLabels); - m_tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter); -// m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); - m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Name, 200); - m_tableWidget->horizontalHeader()->resizeSection(Column_Index::UUID, 310); - m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Time, 150); - m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Size, 120); - m_tableWidget->horizontalHeader()->setSectionResizeMode(Column_Index::Backup_Device, QHeaderView::Stretch); - m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_State, 150); + m_tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter); + m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); +// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Name, 200); +// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::UUID, 310); +// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Time, 150); +// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Size, 120); +// m_tableWidget->horizontalHeader()->setSectionResizeMode(Column_Index::Backup_Device, QHeaderView::Stretch); +// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_State, 150); m_tableWidget->horizontalHeader()->setTextElideMode( Qt::ElideRight); m_tableWidget->horizontalHeader()->setFixedHeight(30); m_tableWidget->verticalHeader()->setHidden(true); // 好像隐藏不掉 diff --git a/kybackup/backuppointlistdialog.h b/kybackup/backuppointlistdialog.h index 8d75421..596a39b 100755 --- a/kybackup/backuppointlistdialog.h +++ b/kybackup/backuppointlistdialog.h @@ -44,7 +44,7 @@ signals: protected: void keyPressEvent(QKeyEvent* event); - void setItem(int row, int column, const QString& text, int alignFlag = Qt::AlignLeft | Qt::AlignVCenter); + void setItem(int row, int column, const QString& text, int alignFlag = Qt::AlignCenter); QString text(int row, int column); QTableWidget *m_tableWidget; diff --git a/kybackup/component/backuplistwidget.cpp b/kybackup/component/backuplistwidget.cpp index 9a3d445..cf3ecb4 100755 --- a/kybackup/component/backuplistwidget.cpp +++ b/kybackup/component/backuplistwidget.cpp @@ -105,8 +105,8 @@ bool BackupListWidget::appendItem(const QString &text) m_List << text; QPushButton *buttonDelete = new QPushButton; - buttonDelete->setProperty("isWindowButton", 0x2); - buttonDelete->setProperty("useIconHighlightEffect", 0x8); + // buttonDelete->setProperty("isWindowButton", 0x2); + // buttonDelete->setProperty("useIconHighlightEffect", 0x8); buttonDelete->setFlat(true); buttonDelete->setFixedSize(20, 20); buttonDelete->setIcon(QIcon::fromTheme("window-close-symbolic")); diff --git a/kybackup/maindialog.cpp b/kybackup/maindialog.cpp index d1bc1a0..aaf75a5 100755 --- a/kybackup/maindialog.cpp +++ b/kybackup/maindialog.cpp @@ -105,7 +105,6 @@ void MainDialog::initUI() m_totalHLayout->addStretch(); initTileBar(); - initStyleSheet(); } void MainDialog::initTileBar() @@ -177,27 +176,6 @@ void MainDialog::initTileBar() m_titleWidget->setLayout(m_titleLayout); } -void MainDialog::initStyleSheet() -{ -// // 左侧菜单背景色设置 -// m_leftSiderBarWidget->setAutoFillBackground(true); -// QPalette paletteLeft = m_leftSiderBarWidget->palette(); -// QColor colorLeftSider(COLOR_WINDOW_LIGHT_LEFT); -// colorLeftSider.setAlphaF(g_GSettingWrapper.m_transparency); -// paletteLeft.setColor(QPalette::Window, colorLeftSider); -// m_leftSiderBarWidget->setPalette(paletteLeft); -// g_GSettingWrapper.connectUkuiBackground(m_leftSiderBarWidget, colorLeftSider, QColor(COLOR_WINDOW_DARK_LEFT)); - -// // 右侧窗口背景色设置 -// m_rightWidget->setAutoFillBackground(true); -// QPalette palette = m_rightWidget->palette(); -// QColor colorRight(palette.color(QPalette::Base)); -// colorRight.setAlphaF(g_GSettingWrapper.m_transparency); -// palette.setColor(QPalette::Window, colorRight); -// m_rightWidget->setPalette(palette); -// g_GSettingWrapper.connectUkuiBackground(m_rightWidget, colorRight, QColor(COLOR_WINDOW_DARK_RIGHT)); -} - void MainDialog::initConnect() { // 左侧功能选择栏 diff --git a/kybackup/maindialog.h b/kybackup/maindialog.h index ba6d88a..2bcb8fe 100755 --- a/kybackup/maindialog.h +++ b/kybackup/maindialog.h @@ -31,7 +31,6 @@ public slots: private: void initUI(); void initTileBar(); - void initStyleSheet(); void initConnect(); void mountBackupPartition(); diff --git a/kybackup/module/operationlog.cpp b/kybackup/module/operationlog.cpp index 53b53f1..fc7426b 100755 --- a/kybackup/module/operationlog.cpp +++ b/kybackup/module/operationlog.cpp @@ -55,12 +55,13 @@ void OperationLog::initFirstWidget() m_tableWidget->setFixedSize(680, 560); m_tableWidget->setColumnCount(headerLabels.size()); m_tableWidget->setHorizontalHeaderLabels(headerLabels); - m_tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter); - // m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); - m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Name, 200); - m_tableWidget->horizontalHeader()->resizeSection(Column_Index::UUID, 310); - m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Operation, 150); - m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Operation_Time, 150); + m_tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter); + m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); + // m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Name, 200); +// m_tableWidget->horizontalHeader()->setSectionResizeMode(Column_Index::Backup_Name, QHeaderView::ResizeToContents); +// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::UUID, 310); +// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Operation, 150); +// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Operation_Time, 150); m_tableWidget->horizontalHeader()->setStretchLastSection(true); m_tableWidget->horizontalHeader()->setTextElideMode(Qt::ElideRight); m_tableWidget->horizontalHeader()->setFixedHeight(30); diff --git a/kybackup/module/operationlog.h b/kybackup/module/operationlog.h index 697a17b..57e5c17 100755 --- a/kybackup/module/operationlog.h +++ b/kybackup/module/operationlog.h @@ -21,7 +21,7 @@ public: private: void initFirstWidget(); void initOperationLogs(const QList& list); - void setItem(int row, int column, const QString& text, int alignFlag = Qt::AlignLeft | Qt::AlignVCenter); + void setItem(int row, int column, const QString& text, int alignFlag = Qt::AlignCenter/*Qt::AlignLeft | Qt::AlignVCenter*/); QString castTypeToString(int type); QTableWidget *m_tableWidget;