From 3b849c38cc8300458de1b3ace1981e5190f5eda0 Mon Sep 17 00:00:00 2001 From: KevinDuan Date: Wed, 6 Sep 2023 16:27:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=85=A8=E5=B1=80=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E5=8F=98=E9=87=8F=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E4=B8=BB=E9=A2=98=E6=97=B6=E8=AF=BB=E5=8F=96=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=93=8D=E4=BD=9C=EF=BC=8C=E4=BF=AE=E6=94=B9=E6=94=B6?= =?UTF-8?q?=E9=9B=86=E9=A1=B5=E9=9D=A2=E4=BF=A1=E6=81=AF=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kylin-theme-builder.pro | 2 ++ src/fileprocess.cpp | 43 ++++++++++++++++++++++++---- src/fileprocess.h | 6 ++-- src/infocreatefeature.h | 2 ++ src/infocreatewidget.cpp | 60 ++++++++++++++++++++++++++++++++++------ src/infocreatewidget.h | 6 ++-- src/maininterface.cpp | 7 +++++ 7 files changed, 108 insertions(+), 18 deletions(-) diff --git a/kylin-theme-builder.pro b/kylin-theme-builder.pro index 4ce3644..1a5090b 100644 --- a/kylin-theme-builder.pro +++ b/kylin-theme-builder.pro @@ -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 \ diff --git a/src/fileprocess.cpp b/src/fileprocess.cpp index f7c300d..78974d8 100644 --- a/src/fileprocess.cpp +++ b/src/fileprocess.cpp @@ -1,5 +1,6 @@ #include "fileprocess.h" +QString FileProcess::g_date; FileProcess::FileProcess() { //创建缓存目录 @@ -14,18 +15,50 @@ FileProcess::FileProcess() return; } -void FileProcess::FileSearch(){ +QMap FileProcess::FileSearch(const QString &m_date){ + QString m_getInfoFIlePath = QDir::homePath() + "/.cache/theme-build/" + m_date + "/debian/control"; + QMap 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 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; } diff --git a/src/fileprocess.h b/src/fileprocess.h index bc27c88..230aa0a 100644 --- a/src/fileprocess.h +++ b/src/fileprocess.h @@ -6,18 +6,20 @@ #include #include #include +#include class FileProcess { public: FileProcess(); - void FileSearch(); + QMap FileSearch(const QString &m_date); QString FileCreate(const QString &themes); + static QString g_date; + private: QDir m_builder; - QString m_date; }; #endif // FILEPROCESS_H diff --git a/src/infocreatefeature.h b/src/infocreatefeature.h index dc6c6b0..9b31f1e 100644 --- a/src/infocreatefeature.h +++ b/src/infocreatefeature.h @@ -6,6 +6,8 @@ #include #include +#include "infocreatewidget.h" + class InfoCreateFeature { diff --git a/src/infocreatewidget.cpp b/src/infocreatewidget.cpp index 370ac01..f9979b7 100644 --- a/src/infocreatewidget.cpp +++ b/src/infocreatewidget.cpp @@ -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()<close(); - }); - - //获取已输入信息,再次确认后开始编译 - connect(m_createDebBtn,&QPushButton::clicked,this,[=](){ - - }); + } } + +void InfoCreateWidget::getFileInfo(const QMap &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()); +} + diff --git a/src/infocreatewidget.h b/src/infocreatewidget.h index 9a019de..8ceec49 100644 --- a/src/infocreatewidget.h +++ b/src/infocreatewidget.h @@ -2,7 +2,6 @@ #define INFOCREATEWIDGET_H #include "fileprocess.h" -#include "infocreatefeature.h" #include #include @@ -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 &m_packageInfo); signals: private: QLabel *m_warningMessage; diff --git a/src/maininterface.cpp b/src/maininterface.cpp index b5e52e5..3a6c994 100644 --- a/src/maininterface.cpp +++ b/src/maininterface.cpp @@ -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()