!28 add delete history dir and update historywidget layout

Merge pull request !28 from likehomedream/my-2.0-devel
This commit is contained in:
KevinDuan 2023-09-22 06:46:47 +00:00 committed by Gitee
commit 3f8e58e05d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 209 additions and 68 deletions

View File

@ -18,10 +18,12 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \ SOURCES += \
src/build/buildcheck.cpp \ src/build/buildcheck.cpp \
src/fileProcess/bridge.cpp \ src/fileProcess/bridge.cpp \
src/fileProcess/diroperation.cpp \
src/fileProcess/filecheck.cpp \ src/fileProcess/filecheck.cpp \
src/fileProcess/fileprocess.cpp \ src/fileProcess/fileprocess.cpp \
src/fileProcess/configfilemanager.cpp \ src/fileProcess/configfilemanager.cpp \
src/build/buildcheckwidget.cpp \ src/build/buildcheckwidget.cpp \
src/fileProcess/historyinfoload.cpp \
src/module/cacheconfirmedwidget.cpp \ src/module/cacheconfirmedwidget.cpp \
src/module/cursorthemefeature.cpp \ src/module/cursorthemefeature.cpp \
src/module/cursorthemewidget.cpp \ src/module/cursorthemewidget.cpp \
@ -40,10 +42,12 @@ SOURCES += \
HEADERS += \ HEADERS += \
src/build/buildcheck.h \ src/build/buildcheck.h \
src/fileProcess/bridge.h \ src/fileProcess/bridge.h \
src/fileProcess/diroperation.h \
src/fileProcess/filecheck.h \ src/fileProcess/filecheck.h \
src/fileProcess/fileprocess.h \ src/fileProcess/fileprocess.h \
src/fileProcess/configfilemanager.h \ src/fileProcess/configfilemanager.h \
src/build/buildcheckwidget.h \ src/build/buildcheckwidget.h \
src/fileProcess/historyinfoload.h \
src/module/cacheconfirmedwidget.h \ src/module/cacheconfirmedwidget.h \
src/module/cursorthemefeature.h \ src/module/cursorthemefeature.h \
src/module/cursorthemewidget.h \ src/module/cursorthemewidget.h \

View File

@ -0,0 +1,24 @@
#include "diroperation.h"
#include <QDebug>
#include <QDir>
DirOperation::DirOperation(QObject *parent) : QObject(parent)
{
}
void DirOperation::DeleteHistoryDir(const QString &date)
{
QString dirPath = QDir::homePath() + "/.cache/theme-build/" + date;
QDir builderDir(dirPath);
if (builderDir.exists()){
if (builderDir.removeRecursively()){
qDebug() << "成功删除目录:" << dirPath;
}else{
qDebug() << "无法删除目录:" << dirPath;
}
}else{
qDebug() << "目录不存在:" << dirPath;
}
}

View File

@ -0,0 +1,16 @@
#ifndef DIROPERATION_H
#define DIROPERATION_H
#include <QObject>
class DirOperation : public QObject
{
Q_OBJECT
public:
explicit DirOperation(QObject *parent = nullptr);
void DeleteHistoryDir(const QString& date);
signals:
};
#endif // DIROPERATION_H

View File

@ -0,0 +1,72 @@
#include "historyinfoload.h"
#include <QDebug>
#include <QFileInfo>
#include <QDir>
HistoryInfoLoad::HistoryInfoLoad(const QString &date, QObject *parent)
{
m_historytime = date;
}
QString HistoryInfoLoad::getCover()
{
QString filePath = QDir::homePath() + "/.cache/theme-build/" + m_historytime + "/config/preview";
QString previewFilePath;
QFileInfo pngFileInfo(filePath + ".png");
if (pngFileInfo.exists()) {
previewFilePath = pngFileInfo.filePath();
} else {
QFileInfo jpgFileInfo(filePath + ".jpg");
if (jpgFileInfo.exists()) {
previewFilePath = jpgFileInfo.filePath();
} else {
previewFilePath = nullptr;
}
}
m_coverpath = previewFilePath;
return m_coverpath;
}
QString HistoryInfoLoad::getThemeName()
{
QString filePath = QDir::homePath() + "/.cache/theme-build/" + m_historytime + "/debian/control";
QFile file(filePath);
if (file.exists() && file.open(QIODevice::ReadOnly)) {
QString content(file.readAll());
file.close();
QString sourceString = "Source:";
int sourceIndex = content.indexOf(sourceString);
if (sourceIndex != -1) {
int startIndex = sourceIndex + sourceString.length();
QString fieldValue = content.mid(startIndex).trimmed().split("\n").at(0);
qDebug() << "Source field value: " << fieldValue;
m_themename = fieldValue;
} else {
qDebug() << "No Source field found.";
}
} else {
qDebug() << "File not found or cannot open file.";
}
return m_themename;
}
QString HistoryInfoLoad::getThemeType()
{
QString filePath = QDir::homePath() + "/.cache/theme-build/" + m_historytime;
QDir themeDir(filePath);
if (themeDir.exists("globalTheme")) {
m_themetype = "globalTheme";
} else {
if (themeDir.exists("cursorTheme")) {
m_themetype = "cursorTheme";
} else if (themeDir.exists("iconTheme")) {
m_themetype = "iconTheme";
}
}
return m_themetype;
}

View File

@ -0,0 +1,22 @@
#ifndef HISTORYINFOLOAD_H
#define HISTORYINFOLOAD_H
#include <QObject>
class HistoryInfoLoad : public QObject {
Q_OBJECT
public:
explicit HistoryInfoLoad(const QString& date, QObject* parent = nullptr);
QString getCover();
QString getThemeName();
QString getThemeType();
signals:
private:
QString m_historytime = nullptr;
QString m_coverpath = nullptr;
QString m_themename = nullptr;
QString m_themetype = nullptr;
};
#endif // HISTORYINFOLOAD_H

View File

@ -1,5 +1,6 @@
#include "historywidget.h" #include "historywidget.h"
#include "../fileProcess/historyinfoload.h"
#include "../fileProcess/diroperation.h"
HistoryWidget::HistoryWidget(QWidget *parent) : QWidget(parent) HistoryWidget::HistoryWidget(QWidget *parent) : QWidget(parent)
{ {
@ -44,14 +45,14 @@ HistoryWidget::HistoryWidget(QWidget *parent) : QWidget(parent)
foreach (QString folder, validFolders) { foreach (QString folder, validFolders) {
HistoryButton *button = new HistoryButton(this); HistoryButton *button = new HistoryButton(this);
HistoryInfoLoad *info = new HistoryInfoLoad(folder);
button->setHistoryTime(folder); button->setHistoryTime(folder);
button->setCover(); button->setCover(info->getCover());
button->setThemeName(); button->setThemeName(info->getThemeName());
button->setThemeType(); button->setThemeType(info->getThemeType());
button->initUI(); button->initUI();
layout->addWidget(button, row, col); layout->addWidget(button, row, col);
col++; col++;
if (col == 4) { if (col == 4) {
col = 0; col = 0;
@ -96,10 +97,12 @@ void HistoryWidget::updateHistoryDir()
foreach (QString folder, validFolders) { foreach (QString folder, validFolders) {
HistoryButton *button = new HistoryButton(this); HistoryButton *button = new HistoryButton(this);
HistoryInfoLoad *info = new HistoryInfoLoad(folder);
button->setHistoryTime(folder); button->setHistoryTime(folder);
button->setCover(); button->setCover(info->getCover());
button->setThemeName(); button->setThemeName(info->getThemeName());
button->setThemeType(); button->setThemeType(info->getThemeType());
button->initUI(); button->initUI();
layout->addWidget(button, row, col); layout->addWidget(button, row, col);
@ -127,7 +130,9 @@ void HistoryWidget::updateHistoryDir()
HistoryButton::HistoryButton(QWidget* parent): QPushButton(parent) HistoryButton::HistoryButton(QWidget* parent): QPushButton(parent)
{ {
// this->setBackgroundRole(QPalette::Base);
this->setFixedSize(240, 280); this->setFixedSize(240, 280);
m_menu = new QMenu(this);
} }
void HistoryButton::setHistoryTime(const QString &text) void HistoryButton::setHistoryTime(const QString &text)
@ -135,65 +140,19 @@ void HistoryButton::setHistoryTime(const QString &text)
m_historytime = text; m_historytime = text;
} }
void HistoryButton::setCover() void HistoryButton::setCover(const QString & covePath)
{ {
QString filePath = QDir::homePath() + "/.cache/theme-build/" + m_historytime + "/config/preview"; m_coverpath = covePath;
QString previewFilePath;
QFileInfo pngFileInfo(filePath + ".png");
if (pngFileInfo.exists()) {
previewFilePath = pngFileInfo.filePath();
} else {
QFileInfo jpgFileInfo(filePath + ".jpg");
if (jpgFileInfo.exists()) {
previewFilePath = jpgFileInfo.filePath();
} else {
previewFilePath = nullptr;
}
}
m_coverpath = previewFilePath;
} }
void HistoryButton::setThemeName() void HistoryButton::setThemeName(const QString &themeName)
{ {
QString filePath = QDir::homePath() + "/.cache/theme-build/" + m_historytime + "/debian/control"; m_themename = themeName;
QFile file(filePath);
if (file.exists() && file.open(QIODevice::ReadOnly)) {
QString content(file.readAll());
file.close();
QString sourceString = "Source:";
int sourceIndex = content.indexOf(sourceString);
if (sourceIndex != -1) {
int startIndex = sourceIndex + sourceString.length();
QString fieldValue = content.mid(startIndex).trimmed().split("\n").at(0);
qDebug() << "Source field value: " << fieldValue;
m_themename = fieldValue;
} else {
qDebug() << "No Source field found.";
}
} else {
qDebug() << "File not found or cannot open file.";
}
} }
void HistoryButton::setThemeType() void HistoryButton::setThemeType(const QString &themeType)
{ {
QString filePath = QDir::homePath() + "/.cache/theme-build/" + m_historytime; m_themetype = themeType;
QDir themeDir(filePath);
if (themeDir.exists("globalTheme")) {
m_themetype = "globalTheme";
} else {
if (themeDir.exists("cursorTheme")) {
m_themetype = "cursorTheme";
} else if (themeDir.exists("iconTheme")) {
m_themetype = "iconTheme";
}
}
} }
void HistoryButton::initUI() void HistoryButton::initUI()
@ -228,7 +187,41 @@ void HistoryButton::initUI()
QLabel* label2 = new QLabel(m_historytime); QLabel* label2 = new QLabel(m_historytime);
layout->addWidget(label2); layout->addWidget(label2);
QWidget * btnwidget = new QWidget(this);
QHBoxLayout * btnwidgetlayout = new QHBoxLayout(btnwidget);
QPushButton* button = new QPushButton(m_themetype); QPushButton* button = new QPushButton(m_themetype);
layout->addWidget(button); QPushButton* btn_menu = new QPushButton("···");
btn_menu->setFixedWidth(50);
btnwidgetlayout->addWidget(button);
btnwidgetlayout->addStretch(1);
btnwidgetlayout->addWidget(btn_menu);
btnwidget->setLayout(btnwidgetlayout);
layout->addWidget(btnwidget);
this->setLayout(layout); this->setLayout(layout);
// 创建并添加菜单选项
QAction* action1 = m_menu->addAction("删除");
QAction* action2 = m_menu->addAction("导出");
connect(btn_menu, &QPushButton::clicked, this, [=]() {
m_menu->exec(btn_menu->mapToGlobal(btn_menu->rect().bottomLeft()));
qDebug()<<"aaaaaaaaaaaaa";
});
// 连接菜单选项的槽函数
connect(action1, &QAction::triggered, this, [=]() {
DirOperation *dop = new DirOperation();
dop->DeleteHistoryDir(m_historytime);
this->deleteLater();
// emit updateHistoryRequested();
this->parentWidget()->layout()->update();
});
}
void HistoryWidget::handleButtonClick()
{
} }

View File

@ -1,6 +1,5 @@
#ifndef HISTORYWIDGET_H #ifndef HISTORYWIDGET_H
#define HISTORYWIDGET_H #define HISTORYWIDGET_H
#include <QObject> #include <QObject>
#include <QWidget> #include <QWidget>
#include <QDir> #include <QDir>
@ -9,22 +8,30 @@
#include <QGridLayout> #include <QGridLayout>
#include <QPushButton> #include <QPushButton>
#include <QLabel> #include <QLabel>
#include <QMenu>
#include <QAction>
#include <QMouseEvent>
class HistoryButton : public QPushButton class HistoryButton : public QPushButton
{ {
Q_OBJECT
public: public:
HistoryButton(QWidget* parent = nullptr); HistoryButton(QWidget* parent = nullptr);
void setHistoryTime(const QString &text); void setHistoryTime(const QString &text);
void setCover(); void setCover(const QString &covePath);
void setThemeName(); void setThemeName(const QString &themeName);
void setThemeType(); void setThemeType(const QString &themeType);
void initUI(); void initUI();
// void showContextMenu();
// void mousePressEvent(QMouseEvent* event);
signals:
void updateHistoryRequested();
private: private:
QString m_historytime = nullptr; QString m_historytime = nullptr;
QString m_coverpath = nullptr; QString m_coverpath = nullptr;
QString m_themename = nullptr; QString m_themename = nullptr;
QString m_themetype = nullptr; QString m_themetype = nullptr;
QMenu *m_menu;
}; };
@ -34,6 +41,9 @@ class HistoryWidget : public QWidget
public: public:
explicit HistoryWidget(QWidget *parent = nullptr); explicit HistoryWidget(QWidget *parent = nullptr);
void updateHistoryDir(); void updateHistoryDir();
public slots:
void handleButtonClick();
signals: signals: