增加文件处理,增加全局日期变量,增加创建主题时读取修改操作,修改收集页面信息判断逻辑

This commit is contained in:
KevinDuan 2023-09-06 16:27:14 +08:00
parent 6d542c92eb
commit 3b849c38cc
7 changed files with 108 additions and 18 deletions

View File

@ -16,6 +16,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
src/bridge.cpp \
src/cursorthemefeature.cpp \
src/cursorthemewidget.cpp \
src/fileprocess.cpp \
@ -31,6 +32,7 @@ SOURCES += \
src/titlebar.cpp
HEADERS += \
src/bridge.h \
src/cursorthemefeature.h \
src/cursorthemewidget.h \
src/fileprocess.h \

View File

@ -1,5 +1,6 @@
#include "fileprocess.h"
QString FileProcess::g_date;
FileProcess::FileProcess()
{
//创建缓存目录
@ -14,18 +15,50 @@ FileProcess::FileProcess()
return;
}
void FileProcess::FileSearch(){
QMap<QString, QVariant> FileProcess::FileSearch(const QString &m_date){
QString m_getInfoFIlePath = QDir::homePath() + "/.cache/theme-build/" + m_date + "/debian/control";
QMap<QString, QVariant> emptyMap;
// 处理文件不存在的情况
if (m_getInfoFIlePath.isEmpty()){
qDebug() << m_getInfoFIlePath << "文件不存在!";
return emptyMap;
} else {
QFile m_getInfoFIle(m_getInfoFIlePath);
if (!m_getInfoFIle.open(QIODevice::ReadOnly | QIODevice::Text)){
// 处理文件打开失败的情况
qDebug() << m_getInfoFIlePath << "文件无法打开!";
return emptyMap;
} else {
QTextStream in(&m_getInfoFIle);
int currentLine = 1;
QString line;
QMap<QString, QVariant> m_packageInfo;
while (!in.atEnd()){
line = in.readLine();
if (currentLine == 1){
m_packageInfo.insert("key1",line.mid(8));
} else if(currentLine == 4){
m_packageInfo.insert("key2",line.mid(12, line.indexOf('<')-12).trimmed());
m_packageInfo.insert("key3",line.mid(line.indexOf('<') + 1, line.indexOf('>') - line.indexOf('<') - 1).trimmed());
}
currentLine++;
}
m_getInfoFIle.close();
return m_packageInfo;
}
return emptyMap;
}
}
QString FileProcess::FileCreate(const QString &m_themeType){
QDateTime currentDateTime = QDateTime::currentDateTime();
m_date = currentDateTime.toString("yyyyMMddhhmmss");
qDebug()<< m_date;
g_date = currentDateTime.toString("yyyyMMddhhmmss");
qDebug()<< g_date;
//创建新的记录文件目录
QString m_themePath = QDir::homePath() + "/.cache/theme-build/" + m_date;
QString m_themePath = QDir::homePath() + "/.cache/theme-build/" + g_date;
QDir m_builderTime = m_themePath;
QDir m_builderDeb = m_themePath + "/debian";
QDir m_themeTypePath = m_themePath + "/" + m_themeType;
@ -33,5 +66,5 @@ QString FileProcess::FileCreate(const QString &m_themeType){
m_builderTime.mkdir(m_builderDeb.absolutePath());
m_themeTypePath.mkdir(m_themeTypePath.absolutePath());
return m_date;
return g_date;
}

View File

@ -6,18 +6,20 @@
#include <QDateTime>
#include <QDebug>
#include <QStandardPaths>
#include <QMap>
class FileProcess
{
public:
FileProcess();
void FileSearch();
QMap<QString, QVariant> FileSearch(const QString &m_date);
QString FileCreate(const QString &themes);
static QString g_date;
private:
QDir m_builder;
QString m_date;
};
#endif // FILEPROCESS_H

View File

@ -6,6 +6,8 @@
#include <QDateTime>
#include <QDebug>
#include "infocreatewidget.h"
class InfoCreateFeature
{

View File

@ -106,7 +106,9 @@ void InfoCreateWidget::InitInfoBtn(const QString &m_state){
}
void InfoCreateWidget::InfoProcess(const QString &m_date){
m_themeENNameState = false;
m_builderMailState = false;
m_builderNameState = false;
// 监听文本变化
QObject::connect(m_themeNameCNLineEdit, &QLineEdit::textChanged, [this]() {
@ -114,7 +116,6 @@ void InfoCreateWidget::InfoProcess(const QString &m_date){
});
QObject::connect(m_themeNameENLineEdit, &QLineEdit::textChanged, [this]() {
m_themeENName = m_themeNameENLineEdit->text();
QRegExp englishRegexp("[A-Za-z0-9]+$");
if(m_themeNameENLineEdit != nullptr){
@ -123,6 +124,10 @@ void InfoCreateWidget::InfoProcess(const QString &m_date){
m_themeENNameState = true;
if (m_themeENNameState && m_builderMailState && m_builderNameState){
m_recogniseBtn->setEnabled(true);
m_createDebBtn->setEnabled(true);
} else {
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
} else {
QPalette m_fontqpe;
@ -130,6 +135,8 @@ void InfoCreateWidget::InfoProcess(const QString &m_date){
m_warningMessage2->setPalette(m_fontqpe);
m_warningMessage2->setText("输入格式错误!");
m_themeENNameState = false;
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
} else {
QPalette m_fontqpe;
@ -137,6 +144,8 @@ void InfoCreateWidget::InfoProcess(const QString &m_date){
m_warningMessage2->setPalette(m_fontqpe);
m_warningMessage2->setText("输入为空!");
m_themeENNameState = false;
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
});
@ -150,6 +159,10 @@ void InfoCreateWidget::InfoProcess(const QString &m_date){
m_builderNameState = true;
if (m_themeENNameState && m_builderMailState && m_builderNameState){
m_recogniseBtn->setEnabled(true);
m_createDebBtn->setEnabled(true);
} else {
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
} else {
QPalette m_fontqpe;
@ -157,6 +170,8 @@ void InfoCreateWidget::InfoProcess(const QString &m_date){
m_warningMessage3->setPalette(m_fontqpe);
m_warningMessage3->setText("输入格式错误!");
m_builderNameState = false;
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
} else {
QPalette m_fontqpe;
@ -164,6 +179,8 @@ void InfoCreateWidget::InfoProcess(const QString &m_date){
m_warningMessage3->setPalette(m_fontqpe);
m_warningMessage3->setText("输入为空!");
m_builderNameState = false;
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
});
@ -177,6 +194,10 @@ void InfoCreateWidget::InfoProcess(const QString &m_date){
m_builderMailState = true;
if (m_themeENNameState && m_builderNameState && m_builderMailState){
m_recogniseBtn->setEnabled(true);
m_createDebBtn->setEnabled(true);
} else {
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
} else {
QPalette m_fontqpe;
@ -184,6 +205,8 @@ void InfoCreateWidget::InfoProcess(const QString &m_date){
m_warningMessage4->setPalette(m_fontqpe);
m_warningMessage4->setText("输入格式错误!");
m_builderMailState = false;
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
} else {
QPalette m_fontqpe;
@ -191,6 +214,8 @@ void InfoCreateWidget::InfoProcess(const QString &m_date){
m_warningMessage4->setPalette(m_fontqpe);
m_warningMessage4->setText("输入为空!");
m_builderMailState = false;
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
});
@ -201,7 +226,22 @@ void InfoCreateWidget::InfoProcess(const QString &m_date){
//创建control/changelog文件
connect(m_recogniseBtn, &QPushButton::clicked,this,[=](){
QFile m_control(QDir::homePath() + "/.cache/theme-build/" + m_date + "/debian/control");
createControlChangelog(m_date);
});
//获取已输入信息,再次确认后开始编译
connect(m_createDebBtn,&QPushButton::clicked,this,[=](){
createControlChangelog(FileProcess::g_date);
//清空日期缓存
FileProcess::g_date = nullptr;
});
}
void InfoCreateWidget::createControlChangelog(const QString &m_date){
//点击生成制作主题包按钮时m_date将设为空
qDebug()<<m_date;
if(m_date != nullptr){
QFile m_control(QDir::homePath() + "/.cache/theme-build/" + m_date + "/debian/control");
if (m_control.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
@ -234,10 +274,12 @@ void InfoCreateWidget::InfoProcess(const QString &m_date){
}
this->close();
});
//获取已输入信息,再次确认后开始编译
connect(m_createDebBtn,&QPushButton::clicked,this,[=](){
});
}
}
void InfoCreateWidget::getFileInfo(const QMap<QString, QVariant> &m_packageInfo){
m_themeNameENLineEdit->setText(m_packageInfo.value("key1").toString());
m_builderNameLineEdit->setText(m_packageInfo.value("key2").toString());
m_builderMailLineEdit->setText(m_packageInfo.value("key3").toString());
}

View File

@ -2,7 +2,6 @@
#define INFOCREATEWIDGET_H
#include "fileprocess.h"
#include "infocreatefeature.h"
#include <QWidget>
#include <QPushButton>
@ -26,7 +25,7 @@ class InfoCreateWidget : public QWidget
{
Q_OBJECT
public:
// explicit InfoCreateWidget(QWidget *parent = nullptr);
explicit InfoCreateWidget(QWidget *parent = nullptr);
explicit InfoCreateWidget(QWidget *parent, const QString &m_date, const QString &m_state);
void InitThemeName();
@ -38,6 +37,9 @@ public:
QString m_themeENName;
QString m_builderMail;
QString m_builderName;
void createControlChangelog(const QString &m_date);
void getFileInfo(const QMap<QString, QVariant> &m_packageInfo);
signals:
private:
QLabel *m_warningMessage;

View File

@ -78,6 +78,13 @@ void MainInterface::init()
connect(m_cursorbtn,&TypeButton::clicked,m_themestackedwidget,[=](){
m_themestackedwidget->setCurrentIndex(2);
});
InfoCreateWidget *info = new InfoCreateWidget(nullptr,nullptr,"create");
connect(m_buildbtn,&QPushButton::clicked,info,[=](){
FileProcess getInfo;
info->getFileInfo(getInfo.FileSearch(FileProcess::g_date));
info->show();
});
}
void MainInterface::initLeftBar()