From d37d78ba80b7dbe247381230170352ece8acc2a6 Mon Sep 17 00:00:00 2001 From: likehomedream Date: Tue, 5 Dec 2023 17:42:46 +0800 Subject: [PATCH] add plymouth delete function --- src/fileProcess/bridge.cpp | 10 +-- src/fileProcess/bridge.h | 1 + src/fileProcess/configfilemanager.cpp | 109 +++++++++++++++++++++++--- src/fileProcess/configfilemanager.h | 2 + src/maininterface.cpp | 3 + src/maininterface.h | 2 +- src/mainwindow.cpp | 1 + src/module/plymouththemewidget.cpp | 48 ++++++++---- src/module/plymouththemewidget.h | 3 +- src/module/savepathdialog.cpp | 1 + 10 files changed, 145 insertions(+), 35 deletions(-) diff --git a/src/fileProcess/bridge.cpp b/src/fileProcess/bridge.cpp index f6c4c4a..66cccab 100644 --- a/src/fileProcess/bridge.cpp +++ b/src/fileProcess/bridge.cpp @@ -120,8 +120,8 @@ void Bridge::plymouthPathChanged(QString path) m_configfilemanager->copyMp4toCacheDir(m_plymouthpath,QDir::homePath()+"/.cache/theme-build/" +m_time+"/src/plymouthTheme"); }else{ - m_configfilemanager->copyPictoCacheDir(m_plymouthpath,QDir::homePath()+"/.cache/theme-build/" - +m_time+"/src/plymouthTheme","plymouth"); + m_configfilemanager->copyPicstoCacheDir(m_plymouthpath,QDir::homePath()+"/.cache/theme-build/" + +m_time+"/src/plymouthTheme"); } } @@ -139,7 +139,7 @@ void Bridge::createConfig() m_configfilemanager->createJson(QDir::homePath() + "/.cache/theme-build/" + m_time + "/src/globalTheme/"); m_configfilemanager->copyPictoCacheDir(m_coverpath,QDir::homePath()+"/.cache/theme-build/" - +m_time+"/src/globalTheme","grub"); + +m_time+"/src/globalTheme","cover"); } void Bridge::createGrub() @@ -150,8 +150,8 @@ void Bridge::createGrub() void Bridge::createPlymouth() { - m_configfilemanager->copyPictoCacheDir(m_plymouthpath,QDir::homePath()+"/.cache/theme-build/" - +m_time+"/src/plymouthTheme","plymouth"); + m_configfilemanager->copyAllPictoCacheDir(m_plymouthdir,QDir::homePath()+"/.cache/theme-build/" + +m_time+"/src/plymouthTheme"); } void Bridge::startCopy() diff --git a/src/fileProcess/bridge.h b/src/fileProcess/bridge.h index a37a686..9c21d51 100644 --- a/src/fileProcess/bridge.h +++ b/src/fileProcess/bridge.h @@ -51,6 +51,7 @@ private: QString m_wallpaperpath = ":/resource/background/1-warty-final-ubuntukylin.jpg"; QString m_coverpath = ":/resource/background/background-light.png"; QString m_plymouthpath = ":/resource/background/openKylin.svg"; + QString m_plymouthdir = ":/resource/plymouth/"; QString m_grubpath = ":/resource/background/1-warty-final-ubuntukylin.jpg"; // QDir m_builderConfig; // QDir m_buildericons; diff --git a/src/fileProcess/configfilemanager.cpp b/src/fileProcess/configfilemanager.cpp index 4a7b216..070c30d 100644 --- a/src/fileProcess/configfilemanager.cpp +++ b/src/fileProcess/configfilemanager.cpp @@ -479,24 +479,12 @@ bool ConfigFileManager::copyIcontoCacheDir(QMap *map, QDir cac */ void ConfigFileManager::copyPictoCacheDir(const QString &destinationFilePath, QDir cachedir, QString type) { - //清空文件夹 -// if(type == "plymouth"){ -// QStringList fileList = cachedir.entryList(QDir::Files); -// foreach (const QString &fileName, fileList) { -// QString filePath = cachedir.absoluteFilePath(fileName); -// QFile::remove(filePath) -// } -// } - - QString sourceFilePath = destinationFilePath; QString sourceFileExt = QFileInfo(sourceFilePath).suffix(); QString targetFileName = ""; if(type == "cover"){ targetFileName = "preview." + sourceFileExt; - }else if (type == "plymouth"){ - targetFileName = "1." + sourceFileExt; }else if (type == "grub"){ targetFileName = "background." + sourceFileExt; } @@ -513,6 +501,51 @@ void ConfigFileManager::copyPictoCacheDir(const QString &destinationFilePath, QD qDebug() << "File copied successfully"; } +void ConfigFileManager::copyPicstoCacheDir(const QString &destinationFilePath, QDir cachedir) +{ + //清空文件夹 + QStringList fileList = cachedir.entryList(QDir::Files); + foreach (const QString &fileName, fileList) { + QString filePath = cachedir.absoluteFilePath(fileName); + QFile::remove(filePath); + } + + QFile sourceFile(destinationFilePath); + + if (!sourceFile.exists()) { + qDebug() << "Source file does not exist!"; + return; + } + + QDir destinationDirectory(cachedir); + if (!destinationDirectory.exists()) { + qDebug() << "Destination directory does not exist!"; + return; + } + +// QString baseFileName = QFileInfo(sourceFile).baseName(); + QString fileExtension = QFileInfo(sourceFile).completeSuffix(); + QString destinationPath = destinationDirectory.absolutePath(); // Convert QDir to QString + + for (int i = 1; i <= 104; ++i) { + QString newFileName = QString("%1/%2.%4").arg(destinationPath).arg(i).arg(fileExtension); + QFile destinationFile(newFileName); + + if (destinationFile.exists()) { + qDebug() << "File" << newFileName << "already exists. Skipping."; + continue; + } + + if (sourceFile.copy(newFileName)) { + qDebug() << "Copied" << destinationFilePath << "to" << newFileName; + } else { + qDebug() << "Failed to copy" << destinationFilePath << "to" << newFileName; + } + } + QString thunbnail = cachedir.absolutePath()+"/40.png"; + emit updateThumbnail(thunbnail); +} + /** * @brief 将文件复制到缓存目录 * @@ -582,7 +615,57 @@ void ConfigFileManager::copyMp4toCacheDir(const QString &destinationFilePath, QD // } - QString thunbnail = cachedir.absolutePath()+"/40.png";; + QString thunbnail = cachedir.absolutePath()+"/40.png"; + emit updateThumbnail(thunbnail); +} + +void ConfigFileManager::copyAllPictoCacheDir(QDir sourcedir, QDir cachedir) +{ + //清空文件夹 + QStringList fileList1 = cachedir.entryList(QDir::Files); + + foreach (const QString &fileName, fileList1) { + QString filePath = cachedir.absoluteFilePath(fileName); + QFile::remove(filePath); + } + QDir sourceDirectory(sourcedir); + QDir destinationDirectory(cachedir); + + if (!sourceDirectory.exists()) { + qDebug() << "Source directory does not exist!"; + return; + } + + if (!destinationDirectory.exists()) { + qDebug() << "Destination directory does not exist!"; + return; + } + + QStringList filters; + filters << "*.png"; + + sourceDirectory.setNameFilters(filters); + QFileInfoList fileList = sourceDirectory.entryInfoList(); + + foreach (QFileInfo fileInfo, fileList) { + QString baseFileName = fileInfo.baseName(); + QString fileExtension = fileInfo.completeSuffix(); + QString destinationPath = destinationDirectory.absoluteFilePath(QString("%1.%2").arg(baseFileName).arg(fileExtension)); + + QFile destinationFile(destinationPath); + + if (destinationFile.exists()) { + qDebug() << "File" << destinationPath << "already exists. Skipping."; + continue; + } + + if (QFile::copy(fileInfo.filePath(), destinationPath)) { + qDebug() << "Copied" << fileInfo.filePath() << "to" << destinationPath; + } else { + qDebug() << "Failed to copy" << fileInfo.filePath() << "to" << destinationPath; + } + } + QString thunbnail = cachedir.absolutePath()+"/40.png"; emit updateThumbnail(thunbnail); } diff --git a/src/fileProcess/configfilemanager.h b/src/fileProcess/configfilemanager.h index 4ebed6f..c445738 100644 --- a/src/fileProcess/configfilemanager.h +++ b/src/fileProcess/configfilemanager.h @@ -33,7 +33,9 @@ public: bool copyIcontoCacheDir(QMap *map,QDir cachedir); void copyPictoCacheDir(const QString& destinationFilePath,QDir cachedir,QString type); + void copyPicstoCacheDir(const QString& destinationFilePath,QDir cachedir); void copyMp4toCacheDir(const QString& destinationFilePath,QDir cachedir); + void copyAllPictoCacheDir(const QDir sourcedir,QDir cachedir); signals: void updateInfo(); void updateThumbnail(QString thumbnailPath); diff --git a/src/maininterface.cpp b/src/maininterface.cpp index 25d3261..55c3487 100644 --- a/src/maininterface.cpp +++ b/src/maininterface.cpp @@ -57,6 +57,9 @@ MainInterface::MainInterface(QWidget *parent) : QWidget(parent) connect(m_plymouththemewidget, &PlymouthThemeWidget::newPlymouthFilePath, this, [&](const QString& path) { emit plymouthPathChanged(path); }); + connect(m_plymouththemewidget, &PlymouthThemeWidget::refreshPlymouthDir, this, [=](){ + emit refreshPlymouthDir(); + }); connect(m_grubthemewidget, &GrubThemeWidget::newGrubFilePath, this, [&](const QString& path) { emit grubPathChanged(path); }); diff --git a/src/maininterface.h b/src/maininterface.h index 631875b..d2386c3 100644 --- a/src/maininterface.h +++ b/src/maininterface.h @@ -66,7 +66,7 @@ signals: void plymouthPathChanged(QString path); void grubPathChanged(QString path); void deleteIcon(QString widgetName); - + void refreshPlymouthDir(); void startCopy(); void gohomesignals(); private: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 414f795..9274d63 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -35,6 +35,7 @@ MainWindow::MainWindow(QWidget *parent) connect(m_maininterface, &MainInterface::timeCursorMapChanged, m_bridge, &Bridge::timeCursorMapChanged); connect(m_maininterface, &MainInterface::plymouthPathChanged, m_bridge, &Bridge::plymouthPathChanged); connect(m_maininterface, &MainInterface::grubPathChanged, m_bridge, &Bridge::grubPathChanged); + connect(m_maininterface, &MainInterface::refreshPlymouthDir, m_bridge, &Bridge::createPlymouth); // connect(m_maininterface, &MainInterface::startCopy, m_bridge, &Bridge::startCopy); connect(m_bridge,&Bridge::updateInfo,m_historywidget,&HistoryWidget::updateInfo); connect(m_bridge,&Bridge::updateThumbnail,m_maininterface,&MainInterface::updateThumbnail); diff --git a/src/module/plymouththemewidget.cpp b/src/module/plymouththemewidget.cpp index fc2cbaf..8dcb739 100644 --- a/src/module/plymouththemewidget.cpp +++ b/src/module/plymouththemewidget.cpp @@ -78,10 +78,19 @@ void PlymouthThemeWidget::initEditWidget() QLabel *pixLabel = new QLabel("图片"); QCheckBox *video = new QCheckBox(); QLabel *videoLabel = new QLabel("视频"); - checkBoxLayout->addWidget(pic); - checkBoxLayout->addWidget(pixLabel); + + QButtonGroup *btngroup = new QButtonGroup(); + btngroup->addButton(pic); + btngroup->addButton(video); + btngroup->setExclusive(true); + //默认导入视频 + video->setChecked(true); + checkBoxLayout->addWidget(video); checkBoxLayout->addWidget(videoLabel); + checkBoxLayout->addWidget(pic); + checkBoxLayout->addWidget(pixLabel); + checkBoxLayout->addStretch(1); QWidget *showWidget = new QWidget(); QHBoxLayout *showLayout = new QHBoxLayout(showWidget); @@ -96,26 +105,35 @@ void PlymouthThemeWidget::initEditWidget() addButton->setIcon(QIcon::fromTheme("list-add-symbolic")); addButton->setFixedSize(36,36); connect(addButton, &QPushButton::clicked, this, [=]() { - QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select MP4 file"), "", tr("MP4 file (*.svg *.png *.gif *.mp4)")); - if (!newFilePath.isEmpty()) { - QPixmap pixmap(newFilePath); - pixmap = pixmap.scaled(64,64, Qt::KeepAspectRatio); - m_customLabel->setPixmap(pixmap); - emit newPlymouthFilePath(newFilePath); + if(pic->isChecked()){ + QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select Png file"), "", tr("Png file (*.png)")); + if (!newFilePath.isEmpty()) { + QPixmap pixmap(newFilePath); + pixmap = pixmap.scaled(64,64, Qt::KeepAspectRatio); + m_customLabel->setPixmap(pixmap); + emit newPlymouthFilePath(newFilePath); - g_themeChange = true; + g_themeChange = true; + } } + else{ + QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select MP4 file"), "", tr("MP4 file (*.svg *.png *.gif *.mp4)")); + if (!newFilePath.isEmpty()) { + QPixmap pixmap(newFilePath); + pixmap = pixmap.scaled(64,64, Qt::KeepAspectRatio); + m_customLabel->setPixmap(pixmap); + emit newPlymouthFilePath(newFilePath); + + g_themeChange = true; + } + } + }); connect(m_customLabel,&PlymouthCustomLabel::deleteCustomIcon,this,[=](){ m_preview->updatePlymouth(":/resource/plymouth/"); m_preview->showPlymouth(); - QDir cachedir(m_imagedirpath); - QStringList fileList = cachedir.entryList(QDir::Files); - foreach (const QString &fileName, fileList) { - QString filePath = cachedir.absoluteFilePath(fileName); - QFile::remove(filePath); - } + emit refreshPlymouthDir(); }); QLabel *tipLabel = new QLabel(); diff --git a/src/module/plymouththemewidget.h b/src/module/plymouththemewidget.h index 99691ff..e6d01b8 100644 --- a/src/module/plymouththemewidget.h +++ b/src/module/plymouththemewidget.h @@ -11,7 +11,7 @@ #include #include #include - +#include class PlymouthThemeWidget : public QWidget { @@ -29,6 +29,7 @@ public: void refresh(); signals: void newPlymouthFilePath(const QString& path); + void refreshPlymouthDir(); private: QWidget *m_previewwidget; PlymouthImageWidget *m_preview; diff --git a/src/module/savepathdialog.cpp b/src/module/savepathdialog.cpp index 07dfc77..00e4515 100644 --- a/src/module/savepathdialog.cpp +++ b/src/module/savepathdialog.cpp @@ -28,6 +28,7 @@ SavePathDialog::SavePathDialog(QWidget *parent) : void SavePathDialog::updateLabel(QString savepath) { m_pathLabel->setText(tr("Storage Path:")+savepath); + m_pathLabel->setToolTip(savepath); } void SavePathDialog::onModifyBtnClicked()