From 4f548b9cbd72ccd7cd2e4c82d8765d8c6d68d745 Mon Sep 17 00:00:00 2001 From: muyuankai Date: Wed, 10 Jan 2024 14:00:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20dconfig=20=E5=AE=9A=E5=88=B6=E9=80=82?= =?UTF-8?q?=E9=85=8D=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dconfig 定制适配开发 Log: dconfig 定制适配开发 --- src/CMakeLists.txt | 9 ++ src/assets/org.deepin.compressor.method.json | 146 +++++++++++++++++++ src/source/page/compresssettingpage.cpp | 113 ++++++++++++++ src/source/page/compresssettingpage.h | 2 + 4 files changed, 270 insertions(+) create mode 100644 src/assets/org.deepin.compressor.method.json diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eee727ee..ab3de44b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,6 +31,7 @@ find_package(Qt5Concurrent) find_package(Qt5DBus REQUIRED) find_package(KF5Codecs REQUIRED) find_package(Qt5LinguistTools REQUIRED) +find_package(DtkWidget REQUIRED) include(FindPkgConfig) @@ -79,6 +80,14 @@ target_link_libraries(${EXE_NAME} compressor-interface ) +#hw机型增加DConfig配置 +set(APPID org.deepin.compressor) +set(configFile ${PROJECT_SOURCE_DIR}/assets/org.deepin.compressor.method.json) +if (DEFINED DSG_DATA_DIR) + message("-- DConfig is supported by DTK") + dconfig_meta_files(APPID ${APPID} FILES ${configFile}) +endif() + install(TARGETS deepin-compressor DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES desktop/deepin-compressor.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) diff --git a/src/assets/org.deepin.compressor.method.json b/src/assets/org.deepin.compressor.method.json new file mode 100644 index 00000000..86196400 --- /dev/null +++ b/src/assets/org.deepin.compressor.method.json @@ -0,0 +1,146 @@ +{ + "magic": "dsg.config.meta", + "version": "1.0", + "contents": { + "specialCompressorType": { + "value": 11, + "serial": 0, + "flags": ["global"], + "name": "Compressor Type", + "name[zh_CN]": "压缩类型", + "description": "Compressor Type", + "permissions": "readwrite", + "visibility": "private" + }, + "special7zCompressor": { + "value": 0, + "serial": 0, + "flags": ["global"], + "name": "7z Compressor", + "name[zh_CN]": "7z 压缩方式", + "description": "7z Compressor", + "permissions": "readwrite", + "visibility": "private" + }, + "specialJarCompressor": { + "value": 0, + "serial": 0, + "flags": ["global"], + "name": "Jar Compressor", + "name[zh_CN]": "Jar 压缩方式", + "description": "Jar Compressor", + "permissions": "readwrite", + "visibility": "private" + }, + "specialTarCompressor": { + "value": 0, + "serial": 0, + "flags": ["global"], + "name": "Tar Compressor", + "name[zh_CN]": "Tar 压缩方式", + "description": "Tar Compressor", + "permissions": "readwrite", + "visibility": "private" + }, + "specialTarbz2Compressor": { + "value": 0, + "serial": 0, + "flags": ["global"], + "name": "Tar.bz2 Compressor", + "name[zh_CN]": "Tar.bz2 压缩方式", + "description": "Tar.bz2 Compressor", + "permissions": "readwrite", + "visibility": "private" + }, + "specialTarGzCompressor": { + "value": 0, + "serial": 0, + "flags": ["global"], + "name": "tar.gz Compressor", + "name[zh_CN]": "tar.gz 压缩方式", + "description": "tar.gz Compressor", + "permissions": "readwrite", + "visibility": "private" + }, + "specialTarLzCompressor": { + "value": 0, + "serial": 0, + "flags": ["global"], + "name": "tar.lz Compressor", + "name[zh_CN]": "tar.lz 压缩方式", + "description": "tar.lz Compressor", + "permissions": "readwrite", + "visibility": "private" + }, + "specialTarLzmaCompressor": { + "value": 0, + "serial": 0, + "flags": ["global"], + "name": "tar.lzma Compressor", + "name[zh_CN]": "tar.lzma 压缩方式", + "description": "tar.lzma Compressor", + "permissions": "readwrite", + "visibility": "private" + }, + "specialTarLzoCompressor": { + "value": 0, + "serial": 0, + "flags": ["global"], + "name": "tar.lzo Compressor", + "name[zh_CN]": "tar.lzo 压缩方式", + "description": "tar.lzo Compressor", + "permissions": "readwrite", + "visibility": "private" + }, + "specialTarXzCompressor": { + "value": 0, + "serial": 0, + "flags": ["global"], + "name": "tar.xz Compressor", + "name[zh_CN]": "tar.xz 压缩方式", + "description": "tar.xz Compressor", + "permissions": "readwrite", + "visibility": "private" + }, + "specialTarZCompressor": { + "value": 0, + "serial": 0, + "flags": ["global"], + "name": "tar.Z Compressor", + "name[zh_CN]": "tar.Z 压缩方式", + "description": "tar.Z Compressor", + "permissions": "readwrite", + "visibility": "private" + }, + "specialTar7zCompressor": { + "value": 0, + "serial": 0, + "flags": ["global"], + "name": "tar.7z Compressor", + "name[zh_CN]": "tar.7z 压缩方式", + "description": "tar.7z Compressor", + "permissions": "readwrite", + "visibility": "private" + }, + "specialZipCompressor": { + "value": 0, + "serial": 0, + "flags": ["global"], + "name": "Zip Compressor", + "name[zh_CN]": "Zip 压缩方式", + "description": "Zip Compressor", + "permissions": "readwrite", + "visibility": "private" + }, + "specialCpuTarGzCompressor": { + "value": 3, + "serial": 0, + "flags": ["global"], + "name": "tar.gz multithread Compressor", + "name[zh_CN]": "tar.gz 多线程压缩", + "description": "Zip Compressor", + "permissions": "readwrite", + "visibility": "private" + } + } +} \ No newline at end of file diff --git a/src/source/page/compresssettingpage.cpp b/src/source/page/compresssettingpage.cpp index aeeccd2d..bdc5ee2d 100644 --- a/src/source/page/compresssettingpage.cpp +++ b/src/source/page/compresssettingpage.cpp @@ -27,6 +27,11 @@ #include #include +#include +#ifdef DTKCORE_CLASS_DConfigFile +#include +DCORE_USE_NAMESPACE +#endif #define SCROLL_MAX 621 #define SCROLL_MIN 348 @@ -160,6 +165,30 @@ void CompressSettingPage::refreshMenu() m_pTypeMenu->addAction("tar.7z"); } } + QProcess process; + process.start("bash", QStringList() << "-c" << "dmidecode | grep -i \"String 4\""); + process.waitForStarted(); + process.waitForFinished(); + QString result = process.readAll(); + //qDebug() << __func__ << result; + m_isPanguX = result.contains("PGUX", Qt::CaseInsensitive); + process.close(); +#ifdef DTKCORE_CLASS_DConfigFile + if(m_isPanguX) { + m_dconfig = DConfig::create("org.deepin.compressor","org.deepin.compressor.method"); + DConfig *dconfig = (DConfig *)m_dconfig; + int nCompType = -1; + if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialCompressorType")){ + nCompType = dconfig->value("specialCompressorType").toInt(); + } + QList lstAct = m_pTypeMenu->actions(); + if(nCompType >= 0 && nCompType < lstAct.count()) { + slotTypeChanged(lstAct.at(nCompType)); + return; + } + } +#endif + // 默认选择类型为zip if (pAction != nullptr) { @@ -439,6 +468,90 @@ void CompressSettingPage::setSplitEnabled(bool bEnabled) void CompressSettingPage::refreshCompressLevel(const QString &strType) { +#ifdef DTKCORE_CLASS_DConfigFile + if(m_isPanguX) { + // 其余格式支持设置压缩方式 + // 设置压缩方式可用 + m_pCompressLevelCmb->setEnabled(true); + m_pCompressLevelLbl->setEnabled(true); + if(!m_dconfig) return; + DConfig *dconfig = (DConfig *)m_dconfig; + if(strType == "7z") { + if(dconfig && dconfig->isValid() && dconfig->keyList().contains("special7zCompressor")){ + int nMethod = dconfig->value("special7zCompressor").toInt(); + m_pCompressLevelCmb->setCurrentIndex(nMethod); + } + } else if(strType == "jar") { + if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialJarCompressor")){ + int nMethod = dconfig->value("specialJarCompressor").toInt(); + m_pCompressLevelCmb->setCurrentIndex(nMethod); + } + } else if(strType == "tar") { + // tar只有存储功能 + m_pCompressLevelCmb->setCurrentIndex(0); + // 设置压缩方式不可用 + m_pCompressLevelCmb->setEnabled(false); + m_pCompressLevelLbl->setEnabled(false); + } else if(strType == "tar.bz2") { + if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialTarbz2Compressor")){ + int nMethod = dconfig->value("specialTarbz2Compressor").toInt(); + m_pCompressLevelCmb->setCurrentIndex(nMethod); + } + } else if(strType == "tar.gz") { + if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialTarGzCompressor")){ + int nMethod = dconfig->value("specialTarGzCompressor").toInt(); + m_pCompressLevelCmb->setCurrentIndex(nMethod); + } + if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialCpuTarGzCompressor")){ + int nCpu = dconfig->value("specialCpuTarGzCompressor").toInt(); + m_pCpuCmb->setCurrentIndex(nCpu); + } + } else if(strType == "tar.gz") { + if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialTarGzCompressor")){ + int nMethod = dconfig->value("specialTarGzCompressor").toInt(); + m_pCompressLevelCmb->setCurrentIndex(nMethod); + } + } else if(strType == "tar.lz") { + if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialTarLzCompressor")){ + int nMethod = dconfig->value("specialTarLzCompressor").toInt(); + m_pCompressLevelCmb->setCurrentIndex(nMethod); + } + } else if(strType == "tar.lzma") { + if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialTarLzmaCompressor")){ + int nMethod = dconfig->value("specialTarLzmaCompressor").toInt(); + m_pCompressLevelCmb->setCurrentIndex(nMethod); + } + } else if(strType == "tar.lzo") { + if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialTarLzoCompressor")){ + int nMethod = dconfig->value("specialTarLzoCompressor").toInt(); + m_pCompressLevelCmb->setCurrentIndex(nMethod); + } + } else if(strType == "tar.xz") { + if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialTarXzCompressor")){ + int nMethod = dconfig->value("specialTarXzCompressor").toInt(); + m_pCompressLevelCmb->setCurrentIndex(nMethod); + } + } else if(strType == "tar.Z") { + // tar.Z无压缩方式,使用默认,即标准 + m_pCompressLevelCmb->setCurrentIndex(3); + // 设置压缩方式不可用 + m_pCompressLevelCmb->setEnabled(false); + m_pCompressLevelLbl->setEnabled(false); + } else if(strType == "tar.7z") { + if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialTar7zCompressor")){ + int nMethod = dconfig->value("specialTar7zCompressor").toInt(); + m_pCompressLevelCmb->setCurrentIndex(nMethod); + } + } else if(strType == "zip") { + if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialZipCompressor")){ + int nMethod = dconfig->value("specialZipCompressor").toInt(); + m_pCompressLevelCmb->setCurrentIndex(nMethod); + } + } + return; + } +#endif + if (0 == strType.compare("tar")) { // tar只有存储功能 m_pCompressLevelCmb->setCurrentIndex(0); diff --git a/src/source/page/compresssettingpage.h b/src/source/page/compresssettingpage.h index 55303a32..8393de8a 100644 --- a/src/source/page/compresssettingpage.h +++ b/src/source/page/compresssettingpage.h @@ -253,6 +253,8 @@ private slots: QString m_strMimeType; // 压缩类型(application/x-tar) QScrollArea *m_pRightScroll = nullptr; + void *m_dconfig = nullptr; //读取dconfig配置 + bool m_isPanguX = false; //是否pangux系统 }; #endif // COMPRESSSETTINGPAGE_H