From 975d293c7d59602cac9788c9ce8bc75667ff206c Mon Sep 17 00:00:00 2001 From: likehomedream Date: Thu, 14 Dec 2023 14:36:03 +0800 Subject: [PATCH] add savepathconfig --- src/build/buildWidget.cpp | 2 +- src/fileProcess/bridge.cpp | 12 ++++++- src/fileProcess/bridge.h | 2 ++ src/fileProcess/configfilemanager.cpp | 45 +++++++++++++++++++++++++++ src/fileProcess/configfilemanager.h | 4 +++ src/fileProcess/fileprocess.cpp | 2 ++ src/fileProcess/fileprocess.h | 1 + src/mainwindow.cpp | 17 +++++++--- src/module/savepathdialog.cpp | 22 +++++++++++-- src/module/savepathdialog.h | 5 ++- src/titlebar.cpp | 4 +++ src/titlebar.h | 3 +- 12 files changed, 109 insertions(+), 10 deletions(-) diff --git a/src/build/buildWidget.cpp b/src/build/buildWidget.cpp index 55a39a5..c455e8d 100644 --- a/src/build/buildWidget.cpp +++ b/src/build/buildWidget.cpp @@ -27,7 +27,7 @@ buildWidget::buildWidget(QWidget *parent) if(m_buildProgressBar->value()==100){ this->close(); //拷贝deb包至用户目录中 - QString sourceDirPath = QDir::homePath()+"/.cache/theme-build/"+FileProcess::g_date; + QString sourceDirPath = FileProcess::g_debPath; QDir sourceDir = sourceDirPath; QDir homePath =QDir::homePath(); diff --git a/src/fileProcess/bridge.cpp b/src/fileProcess/bridge.cpp index 22a3637..116077b 100644 --- a/src/fileProcess/bridge.cpp +++ b/src/fileProcess/bridge.cpp @@ -135,6 +135,11 @@ void Bridge::grubPathChanged(QString path) +m_time+"/src/grubTheme","grub"); } +void Bridge::savePathConfigChanged(QString path) +{ + m_configfilemanager->modifySavePathConf(path); +} + void Bridge::createConfig() { m_configfilemanager->createConf(QDir::homePath() + "/.cache/theme-build/" @@ -156,7 +161,12 @@ void Bridge::createGrub() void Bridge::createPlymouth() { m_configfilemanager->copyAllPictoCacheDir(m_plymouthdir,QDir::homePath()+"/.cache/theme-build/" - +m_time+"/src/plymouthTheme"); + +m_time+"/src/plymouthTheme"); +} + +void Bridge::createSavePathConfig() +{ + m_configfilemanager->createSavePathConfig(); } void Bridge::startCopy() diff --git a/src/fileProcess/bridge.h b/src/fileProcess/bridge.h index 8fa892f..213596d 100644 --- a/src/fileProcess/bridge.h +++ b/src/fileProcess/bridge.h @@ -28,9 +28,11 @@ public: void timeCursorMapChanged(QMap *timecursormap); void plymouthPathChanged(QString path); void grubPathChanged(QString path); + void savePathConfigChanged(QString path); void createConfig(); void createGrub(); void createPlymouth(); + void createSavePathConfig(); void startCopy(); void updateIconCache(QMap *iconsmaps,QString icontype); signals: diff --git a/src/fileProcess/configfilemanager.cpp b/src/fileProcess/configfilemanager.cpp index e72dcee..e216ae3 100644 --- a/src/fileProcess/configfilemanager.cpp +++ b/src/fileProcess/configfilemanager.cpp @@ -72,6 +72,32 @@ bool ConfigFileManager::createConf(QDir cachedir) } } +bool ConfigFileManager::createSavePathConfig() +{ + QString dirPath = QDir::homePath() + "/.cache/theme-build"; + QString filePath = dirPath + "/savepath.conf"; + + QDir dir; + if (!dir.exists(dirPath)) { + dir.mkpath(dirPath); + } + + QFile file(filePath); + + if (!file.exists()) { + if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { + QTextStream stream(&file); + stream << QDir::homePath() + "/桌面"; + file.close(); + return true; + } else { + return false; + } + } else { + return false; + } +} + /** * @brief 修改radius的json配置文件 * @@ -386,6 +412,25 @@ bool ConfigFileManager::modifywindowRadiusConf(int windowradius,QString confFile } } +bool ConfigFileManager::modifySavePathConf(QString savePath) +{ + QString dirPath = QDir::homePath() + "/.cache/theme-build"; + QString filePath = dirPath + "/savepath.conf"; + + QFile file(filePath); + + // Open the file in WriteOnly mode to clear the content + if (file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { + QTextStream stream(&file); + stream << savePath; + file.close(); + return true; + } else { + // Handle the case when the file cannot be opened for writing + return false; + } +} + /** * @brief 复制文件内容到另一个文件 * diff --git a/src/fileProcess/configfilemanager.h b/src/fileProcess/configfilemanager.h index c445738..24756a7 100644 --- a/src/fileProcess/configfilemanager.h +++ b/src/fileProcess/configfilemanager.h @@ -21,6 +21,7 @@ public: bool createJson(QDir cachedir); bool createConf(QDir cachedir); + bool createSavePathConfig(); bool modifyRadiusJson(int radius,QString jsonFilePath); bool modifyAccentColorConf(QColor accentcolor,QString confFilePath); @@ -29,6 +30,9 @@ public: bool modifyWidgetStyleConf(QString WidgetStyle,QString confFilePath); bool modifyTransparencyConf(int transparency,QString confFilePath); bool modifywindowRadiusConf(int windowradius,QString confFilePath); + + bool modifySavePathConf(QString savePath); + bool copyFileContent(const QString& sourceFilePath, const QString& destinationFilePath); bool copyIcontoCacheDir(QMap *map,QDir cachedir); diff --git a/src/fileProcess/fileprocess.cpp b/src/fileProcess/fileprocess.cpp index b64a336..fd3a0ae 100644 --- a/src/fileProcess/fileprocess.cpp +++ b/src/fileProcess/fileprocess.cpp @@ -6,6 +6,8 @@ QString FileProcess::g_themeENName; QString FileProcess::g_builderName; QString FileProcess::g_builderMailName; QString FileProcess::g_createThemeType; +QString FileProcess::g_debPath; + FileProcess::FileProcess() { //创建缓存目录 diff --git a/src/fileProcess/fileprocess.h b/src/fileProcess/fileprocess.h index 5b12a27..93f0c1b 100644 --- a/src/fileProcess/fileprocess.h +++ b/src/fileProcess/fileprocess.h @@ -24,6 +24,7 @@ public: static QString g_builderName; static QString g_builderMailName; static QString g_createThemeType; + static QString g_debPath; private: QDir m_builder; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bc56918..25f6072 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -7,7 +7,7 @@ MainWindow::MainWindow(QWidget *parent) setWindowFlags(Qt::FramelessWindowHint); m_bridge = Bridge::getInstance(); FileProcess(); - + m_bridge->createSavePathConfig(); initUI(); m_titlebar = new TitleBar(this); QVBoxLayout *layout = new QVBoxLayout(this); @@ -91,6 +91,10 @@ MainWindow::MainWindow(QWidget *parent) } }); connect(m_maininterface, &MainInterface::gohomesignals, this, &MainWindow::onGoHomeClicked); + connect(m_titlebar,&TitleBar::savePathUpdate,this,[&](const QString& path){ + FileProcess::g_debPath= path; + m_bridge->savePathConfigChanged(path); + }); this->setContentsMargins(0,2,0,0); } @@ -151,7 +155,9 @@ void MainWindow::initUI() m_historywidget = new HistoryWidget(); // m_historywidget->setMinimumHeight(2000); QDir builderDir = QDir::homePath()+"/.cache/theme-build/"; - if(builderDir.isEmpty()){ + QFileInfoList fileInfoList = builderDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs); + + if(fileInfoList.isEmpty() || (fileInfoList.count() == 1 && fileInfoList.first().isFile() && fileInfoList.first().fileName() == "savepath.conf")){ alllayout->addStretch(1); alllayout->addLayout(layout); alllayout->addStretch(1); @@ -265,9 +271,12 @@ void MainWindow::initUI() QFileSystemWatcher* watcher = new QFileSystemWatcher(this); watcher->addPath(builderDir.absolutePath()); - connect(watcher, &QFileSystemWatcher::directoryChanged, this, [=](const QString& path) { + connect(watcher, &QFileSystemWatcher::directoryChanged, this, [=]() { m_historywidget->updateHistoryDir(); - if (builderDir.isEmpty()) { + + QFileInfoList fileInfoList = builderDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs); + + if(fileInfoList.isEmpty() || (fileInfoList.count() == 1 && fileInfoList.first().isFile() && fileInfoList.first().fileName() == "savepath.conf")) { alllayout->removeWidget(m_guideWidget); alllayout->removeItem(alllayout->itemAt(alllayout->count()-1)); m_historywidget->setVisible(false); diff --git a/src/module/savepathdialog.cpp b/src/module/savepathdialog.cpp index 00e4515..aad6a52 100644 --- a/src/module/savepathdialog.cpp +++ b/src/module/savepathdialog.cpp @@ -9,7 +9,7 @@ SavePathDialog::SavePathDialog(QWidget *parent) : QWidget*mainwindow = mainWidget(); QGridLayout *layout = new QGridLayout(mainwindow); m_pathLabel = new QLabel; - m_pathLabel->setText(tr("Storage Path:")+m_savepath); + m_pathLabel->setText(tr("Storage Path:")+getSavePath()); m_modifyBtn = new QPushButton; m_modifyBtn->setFixedSize(QSize(88,33)); m_modifyBtn->setText(tr("Modify")); @@ -31,12 +31,30 @@ void SavePathDialog::updateLabel(QString savepath) m_pathLabel->setToolTip(savepath); } +QString SavePathDialog::getSavePath() +{ + QString dirPath = QDir::homePath() + "/.cache/theme-build"; + QString filePath = dirPath + "/savepath.conf"; + + QFile file(filePath); + + if (file.exists() && file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream stream(&file); + QString savePath = stream.readAll(); + file.close(); + + return savePath; + } else { + qDebug() << "Error: File does not exist or cannot be opened."; + } +} + void SavePathDialog::onModifyBtnClicked() { QString newFilePath = QFileDialog::getExistingDirectory(this); if(newFilePath != nullptr){ m_savepath = newFilePath; - //FIX ME m_savepath保存在哪里?哪里需要用? + emit savePathUpdate(newFilePath); this->updateLabel(newFilePath); m_confirmBtn->setEnabled(true); connect(m_confirmBtn,&QPushButton::clicked,this,&SavePathDialog::close); diff --git a/src/module/savepathdialog.h b/src/module/savepathdialog.h index 1b41d4d..c267bd3 100644 --- a/src/module/savepathdialog.h +++ b/src/module/savepathdialog.h @@ -1,6 +1,8 @@ #ifndef SAVEPATHWIDGET_H #define SAVEPATHWIDGET_H #include +#include "../fileProcess/fileprocess.h" + #include #include #include @@ -13,8 +15,9 @@ class SavePathDialog : public kdk::KDialog public: explicit SavePathDialog(QWidget *parent = nullptr); void updateLabel(QString savepath); + QString getSavePath(); signals: - + void savePathUpdate(const QString& filePath); public slots: void onModifyBtnClicked(); diff --git a/src/titlebar.cpp b/src/titlebar.cpp index 1be1709..3998d9c 100644 --- a/src/titlebar.cpp +++ b/src/titlebar.cpp @@ -77,6 +77,10 @@ TitleBar::TitleBar(QWidget *parent) : QWidget(parent) connect(saveAction,&QAction::triggered,this,[=](){ m_savepathdlg = new SavePathDialog(); m_savepathdlg->show(); + connect(m_savepathdlg,&SavePathDialog::savePathUpdate,this,[&](const QString& path){ + + emit savePathUpdate(path); + }); }); connect(aboutAction,&QAction::triggered,this,[=](){ AboutDialog *dlg = new AboutDialog(this); diff --git a/src/titlebar.h b/src/titlebar.h index b5178a3..1773add 100644 --- a/src/titlebar.h +++ b/src/titlebar.h @@ -2,6 +2,7 @@ #define TITLEBAR_H #include "./module/aboutdialog.h" #include "./module/savepathdialog.h" +#include "fileProcess/fileprocess.h" #include #include @@ -23,7 +24,7 @@ public: signals: void gohomesignal(); // 声明自定义信号 - + void savePathUpdate(const QString& filePath); private: bool m_ismaximized; QToolButton *m_optionbtn = nullptr; // 菜单选项