!28 add delete history dir and update historywidget layout
Merge pull request !28 from likehomedream/my-2.0-devel
This commit is contained in:
commit
3f8e58e05d
|
@ -18,10 +18,12 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
|||
SOURCES += \
|
||||
src/build/buildcheck.cpp \
|
||||
src/fileProcess/bridge.cpp \
|
||||
src/fileProcess/diroperation.cpp \
|
||||
src/fileProcess/filecheck.cpp \
|
||||
src/fileProcess/fileprocess.cpp \
|
||||
src/fileProcess/configfilemanager.cpp \
|
||||
src/build/buildcheckwidget.cpp \
|
||||
src/fileProcess/historyinfoload.cpp \
|
||||
src/module/cacheconfirmedwidget.cpp \
|
||||
src/module/cursorthemefeature.cpp \
|
||||
src/module/cursorthemewidget.cpp \
|
||||
|
@ -40,10 +42,12 @@ SOURCES += \
|
|||
HEADERS += \
|
||||
src/build/buildcheck.h \
|
||||
src/fileProcess/bridge.h \
|
||||
src/fileProcess/diroperation.h \
|
||||
src/fileProcess/filecheck.h \
|
||||
src/fileProcess/fileprocess.h \
|
||||
src/fileProcess/configfilemanager.h \
|
||||
src/build/buildcheckwidget.h \
|
||||
src/fileProcess/historyinfoload.h \
|
||||
src/module/cacheconfirmedwidget.h \
|
||||
src/module/cursorthemefeature.h \
|
||||
src/module/cursorthemewidget.h \
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -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;
|
||||
}
|
|
@ -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
|
|
@ -1,5 +1,6 @@
|
|||
#include "historywidget.h"
|
||||
|
||||
#include "../fileProcess/historyinfoload.h"
|
||||
#include "../fileProcess/diroperation.h"
|
||||
|
||||
HistoryWidget::HistoryWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
|
@ -44,14 +45,14 @@ HistoryWidget::HistoryWidget(QWidget *parent) : QWidget(parent)
|
|||
|
||||
foreach (QString folder, validFolders) {
|
||||
HistoryButton *button = new HistoryButton(this);
|
||||
HistoryInfoLoad *info = new HistoryInfoLoad(folder);
|
||||
|
||||
button->setHistoryTime(folder);
|
||||
button->setCover();
|
||||
button->setThemeName();
|
||||
button->setThemeType();
|
||||
button->setCover(info->getCover());
|
||||
button->setThemeName(info->getThemeName());
|
||||
button->setThemeType(info->getThemeType());
|
||||
button->initUI();
|
||||
|
||||
layout->addWidget(button, row, col);
|
||||
|
||||
col++;
|
||||
if (col == 4) {
|
||||
col = 0;
|
||||
|
@ -96,10 +97,12 @@ void HistoryWidget::updateHistoryDir()
|
|||
|
||||
foreach (QString folder, validFolders) {
|
||||
HistoryButton *button = new HistoryButton(this);
|
||||
HistoryInfoLoad *info = new HistoryInfoLoad(folder);
|
||||
|
||||
button->setHistoryTime(folder);
|
||||
button->setCover();
|
||||
button->setThemeName();
|
||||
button->setThemeType();
|
||||
button->setCover(info->getCover());
|
||||
button->setThemeName(info->getThemeName());
|
||||
button->setThemeType(info->getThemeType());
|
||||
button->initUI();
|
||||
|
||||
layout->addWidget(button, row, col);
|
||||
|
@ -127,7 +130,9 @@ void HistoryWidget::updateHistoryDir()
|
|||
|
||||
HistoryButton::HistoryButton(QWidget* parent): QPushButton(parent)
|
||||
{
|
||||
// this->setBackgroundRole(QPalette::Base);
|
||||
this->setFixedSize(240, 280);
|
||||
m_menu = new QMenu(this);
|
||||
}
|
||||
|
||||
void HistoryButton::setHistoryTime(const QString &text)
|
||||
|
@ -135,65 +140,19 @@ void HistoryButton::setHistoryTime(const QString &text)
|
|||
m_historytime = text;
|
||||
}
|
||||
|
||||
void HistoryButton::setCover()
|
||||
void HistoryButton::setCover(const QString & covePath)
|
||||
{
|
||||
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;
|
||||
m_coverpath = covePath;
|
||||
}
|
||||
|
||||
void HistoryButton::setThemeName()
|
||||
void HistoryButton::setThemeName(const QString &themeName)
|
||||
{
|
||||
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.";
|
||||
}
|
||||
m_themename = themeName;
|
||||
}
|
||||
|
||||
void HistoryButton::setThemeType()
|
||||
void HistoryButton::setThemeType(const QString &themeType)
|
||||
{
|
||||
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";
|
||||
}
|
||||
}
|
||||
m_themetype = themeType;
|
||||
}
|
||||
|
||||
void HistoryButton::initUI()
|
||||
|
@ -228,7 +187,41 @@ void HistoryButton::initUI()
|
|||
QLabel* label2 = new QLabel(m_historytime);
|
||||
layout->addWidget(label2);
|
||||
|
||||
QWidget * btnwidget = new QWidget(this);
|
||||
QHBoxLayout * btnwidgetlayout = new QHBoxLayout(btnwidget);
|
||||
|
||||
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);
|
||||
// 创建并添加菜单选项
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#ifndef HISTORYWIDGET_H
|
||||
#ifndef HISTORYWIDGET_H
|
||||
#define HISTORYWIDGET_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QDir>
|
||||
|
@ -9,22 +8,30 @@
|
|||
#include <QGridLayout>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
#include <QMouseEvent>
|
||||
|
||||
class HistoryButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
HistoryButton(QWidget* parent = nullptr);
|
||||
void setHistoryTime(const QString &text);
|
||||
void setCover();
|
||||
void setThemeName();
|
||||
void setThemeType();
|
||||
void setCover(const QString &covePath);
|
||||
void setThemeName(const QString &themeName);
|
||||
void setThemeType(const QString &themeType);
|
||||
void initUI();
|
||||
|
||||
// void showContextMenu();
|
||||
// void mousePressEvent(QMouseEvent* event);
|
||||
signals:
|
||||
void updateHistoryRequested();
|
||||
private:
|
||||
QString m_historytime = nullptr;
|
||||
QString m_coverpath = nullptr;
|
||||
QString m_themename = nullptr;
|
||||
QString m_themetype = nullptr;
|
||||
QMenu *m_menu;
|
||||
};
|
||||
|
||||
|
||||
|
@ -34,6 +41,9 @@ class HistoryWidget : public QWidget
|
|||
public:
|
||||
explicit HistoryWidget(QWidget *parent = nullptr);
|
||||
void updateHistoryDir();
|
||||
public slots:
|
||||
void handleButtonClick();
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
|
|
Loading…
Reference in New Issue