yhkylin-backup-tools/kybackup/backuppointlistdialog.cpp

101 lines
3.3 KiB
C++
Raw Normal View History

2021-12-01 15:12:38 +08:00
#include "backuppointlistdialog.h"
#include "ui_backuppointlistdialog.h"
#include <QHeaderView>
#include "component/mylabel.h"
#include "component/mypushbutton.h"
BackupPointListDialog::BackupPointListDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::BackupPointListDialog)
{
ui->setupUi(this);
// 到各个子类中去设置
// this->setWindowTitle(tr("Backup Points"));
// 去掉最大化、最小化按钮,保留关闭按钮,但是设置后窗口不显示了,实验了几种方式均不可以
// this->setWindowFlags(Qt::WindowCloseButtonHint);
// this->setWindowFlags(this->windowFlags() & ~Qt::WindowMinMaxButtonsHint);
// 设置背景色
this->setAutoFillBackground(true);
QPalette palette = this->palette();
palette.setColor(QPalette::Background, palette.color(QPalette::Base));
this->setPalette(palette);
// 纵向布局
QVBoxLayout *vlayout = new QVBoxLayout;
vlayout->setContentsMargins(20, 0, 20, 10);
QStringList headerList;
headerList << tr("Backup Name") << tr("UUID") << tr("Backup Time") << tr("Backup Device") << QObject::tr("Backup State") << QObject::tr("PrefixPath");
m_tableWidget = new QTableWidget;
m_tableWidget->setColumnCount(headerList.size());
m_tableWidget->setHorizontalHeaderLabels(headerList);
m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
m_tableWidget->setShowGrid(false);
m_tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
// m_tableWidget->resizeColumnsToContents();
m_tableWidget->hideColumn(5);
vlayout->addWidget(m_tableWidget);
MyLabel *note = new MyLabel;
// 您可以删除不需要的备份,更多细节请参考“操作日志”
note->setDeplayText(tr("You can delete backup point"));
MyPushButton * buttonDelete = new MyPushButton;
buttonDelete->setText(tr("Delete"));
m_bottomLayout = new QHBoxLayout;
m_bottomLayout->addWidget(note);
m_bottomLayout->addStretch();
m_bottomLayout->addWidget(buttonDelete);
vlayout->addLayout(m_bottomLayout);
this->setLayout(vlayout);
}
BackupPointListDialog::~BackupPointListDialog()
{
delete ui;
delete m_tableWidget;
}
/**
* @brief
* @return
*/
QList<ParseBackupList::backupPoint> BackupPointListDialog::getBackupPointList(const QStringList& pathList)
{
QList<parseBackupList::backupPoint> list;
for (QString backupPath : pathList) {
backupPath += BACKUP_XML_PATH;
QFile xmlFile(backupPath);
if (!xmlFile.exists() || 0 == xmlFile.size()) {
continue;
}
parseBackupList parse(backupPath);
list.append(parse.getBackupPointList());
}
return list;
}
void BackupPointListDialog::updateTargetList()
{
m_hasUsefulBackup = false; //是否存在有效备份
m_hasOneBackup = false; //是否存在一个备份(包括有效和失败的备份)
m_tableWidget->clear();
QStringList allPaths;
allPaths << ""; //"" is /
// if (!m_onlyshowlocal) {
// QStringList udiskPaths = m_proxy->getAllUdiskPaths();
// for (auto& path : udiskPaths) {
// allPaths << path;
// }
// }
// // readEveryPathBackupStorage(allPaths);
// insertLines(getBackupPointList(allPaths));
}