Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dconfig 定制适配开发 #160

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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)

Expand Down
146 changes: 146 additions & 0 deletions src/assets/org.deepin.compressor.method.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
113 changes: 113 additions & 0 deletions src/source/page/compresssettingpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
#include <QDebug>

#include <cmath>
#include <QProcess>
#ifdef DTKCORE_CLASS_DConfigFile
#include <DConfig>
DCORE_USE_NAMESPACE
#endif

#define SCROLL_MAX 621
#define SCROLL_MIN 348
Expand Down Expand Up @@ -160,6 +165,30 @@
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<QAction*> lstAct = m_pTypeMenu->actions();
if(nCompType >= 0 && nCompType < lstAct.count()) {
slotTypeChanged(lstAct.at(nCompType));
return;
}
}
#endif


// 默认选择类型为zip
if (pAction != nullptr) {
Expand Down Expand Up @@ -439,6 +468,90 @@

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")){

Check warning on line 480 in src/source/page/compresssettingpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition 'dconfig' is always true
int nMethod = dconfig->value("special7zCompressor").toInt();
m_pCompressLevelCmb->setCurrentIndex(nMethod);
}
} else if(strType == "jar") {
if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialJarCompressor")){

Check warning on line 485 in src/source/page/compresssettingpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition 'dconfig' is always true
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")){

Check warning on line 496 in src/source/page/compresssettingpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition 'dconfig' is always true
int nMethod = dconfig->value("specialTarbz2Compressor").toInt();
m_pCompressLevelCmb->setCurrentIndex(nMethod);
}
} else if(strType == "tar.gz") {
if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialTarGzCompressor")){

Check warning on line 501 in src/source/page/compresssettingpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition 'dconfig' is always true
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") {

Check warning on line 509 in src/source/page/compresssettingpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Expression is always false because 'else if' condition matches previous condition at line 500.
if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialTarGzCompressor")){

Check warning on line 510 in src/source/page/compresssettingpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition 'dconfig' is always true
int nMethod = dconfig->value("specialTarGzCompressor").toInt();
m_pCompressLevelCmb->setCurrentIndex(nMethod);
}
} else if(strType == "tar.lz") {
if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialTarLzCompressor")){

Check warning on line 515 in src/source/page/compresssettingpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition 'dconfig' is always true
int nMethod = dconfig->value("specialTarLzCompressor").toInt();
m_pCompressLevelCmb->setCurrentIndex(nMethod);
}
} else if(strType == "tar.lzma") {
if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialTarLzmaCompressor")){

Check warning on line 520 in src/source/page/compresssettingpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition 'dconfig' is always true
int nMethod = dconfig->value("specialTarLzmaCompressor").toInt();
m_pCompressLevelCmb->setCurrentIndex(nMethod);
}
} else if(strType == "tar.lzo") {
if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialTarLzoCompressor")){

Check warning on line 525 in src/source/page/compresssettingpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition 'dconfig' is always true
int nMethod = dconfig->value("specialTarLzoCompressor").toInt();
m_pCompressLevelCmb->setCurrentIndex(nMethod);
}
} else if(strType == "tar.xz") {
if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialTarXzCompressor")){

Check warning on line 530 in src/source/page/compresssettingpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition 'dconfig' is always true
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);
Expand Down
2 changes: 2 additions & 0 deletions src/source/page/compresssettingpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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