From: Yanhao Mo Date: Sun, 14 Oct 2018 11:35:27 +0000 (+0800) Subject: New upstream version 2.0.9.4 X-Git-Tag: archive/raspbian/5.7.12-2+rpi1^2~3^2~29 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b03722dc233912a28584262c8b8883e9eea5dc09;p=dtkcore.git New upstream version 2.0.9.4 --- diff --git a/.gitignore b/.gitignore index 25e4a6c..fd215d3 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ src/DtkCore src/dtkcore_config.h cmake/DtkCore/DtkCoreConfig.cmake src/qt_lib_d*.pri + +bin/ diff --git a/CHANGELOG.md b/CHANGELOG.md index d1dc004..6047da7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ + +## 2.0.9.4 (2018-09-06) + + +#### Bug Fixes + +* can not build on Qt 5.6.1 ([752bf435](https://github.com/linuxdeepin/dtkcore/commit/752bf435a99330241b99d85a4020f2cddd4ff48e)) + +#### Features + +* add DSysInfo class ([16faf6c8](https://github.com/linuxdeepin/dtkcore/commit/16faf6c84d1a2ce520eecd42f369b78d24e03b9c)) + + + ## 2.0.9 (2018-07-20) diff --git a/README.md b/README.md index 1201588..f131e9d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Deepint Tool Kit (Dtk) is the base devlopment tool of all C++/Qt Developer work on Deepin. -You shoud read the [Deepin Application Specification](\ref doc/Specification) firstly. +You should read the [Deepin Application Specification](\ref doc/Specification) firstly. ## Dependencies diff --git a/cmake/DtkCMake/DtkCMakeConfig.cmake b/cmake/DtkCMake/DtkCMakeConfig.cmake new file mode 100644 index 0000000..eeabef4 --- /dev/null +++ b/cmake/DtkCMake/DtkCMakeConfig.cmake @@ -0,0 +1,72 @@ +function(addDefinitions macro) + string(TOUPPER ${macro} macro) + add_definitions(-D${macro}) +endfunction() + +add_definitions(-DQ_HOST_NAME=\"${CMAKE_HOST_SYSTEM_PROCESSOR}\") +addDefinitions(Q_HOST_${CMAKE_HOST_SYSTEM_PROCESSOR}) + +find_package(DtkCore REQUIRED) + +set(DEEPIN_OS_RELEASE_TOOL_PATH ${DTKCORE_TOOL_DIR}) +set(DEEPIN_OS_RELEASE_TOOL ${DEEPIN_OS_RELEASE_TOOL_PATH}/deepin-os-release) + +if(NOT EXISTS "${DEEPIN_OS_RELEASE_TOOL}") + message(FATAL_ERROR "\"${DEEPIN_OS_RELEASE_TOOL}\" is not exists. Install \"dtkcore-bin\" first") +endif() + +function(formatString string) + string(REGEX REPLACE "\\s+" "_" string ${string}) +endfunction() + +macro(execDeepinOsRelease args output) + exec_program(${DEEPIN_OS_RELEASE_TOOL} ARGS ${args} OUTPUT_VARIABLE ${output} RETURN_VALUE exitCode) + + if(NOT ${exitCode} EQUAL 0) + message(FATAL_ERROR "exec deepin-os-release failed, with args: ${args}, error message: ${output}") + endif() +endmacro() + +execDeepinOsRelease(--deepin-type DEEPIN_OS_TYPE) +execDeepinOsRelease(--product-type CMAKE_PLATFORM_ID) +execDeepinOsRelease(--product-version CMAKE_PLATFORM_VERSION) + +if("${CMAKE_PLATFORM_ID}" STREQUAL "") + message(WARNING "No value of the \"--product-type\" in the process \"${DEEPIN_OS_RELEASE_TOOL}\"") +else() + formatString(CMAKE_PLATFORM_ID) + + message("OS: ${CMAKE_PLATFORM_ID}, Version: ${CMAKE_PLATFORM_VERSION}") + + if(NOT "${CMAKE_PLATFORM_ID}" STREQUAL "") + addDefinitions(Q_OS_${CMAKE_PLATFORM_ID}) + string(TOUPPER ${CMAKE_PLATFORM_ID} CMAKE_PLATFORM_ID) + set(OS_${CMAKE_PLATFORM_ID} TRUE) + endif() + + if("${CMAKE_PLATFORM_VERSION}" STREQUAL "") + message(WARNING "No value of the \"--product-version\"") + else() + formatString(CMAKE_PLATFORM_VERSION) + if(NOT "${CMAKE_PLATFORM_VERSION}" STREQUAL "") + add_definitions(-DQ_OS_VERSION=\"${CMAKE_PLATFORM_VERSION}\") + endif() + endif() +endif() + +if("${DEEPIN_OS_TYPE}" STREQUAL "") + message(WARNING "No value of the \"--deepin-type\" in the process \"${DEEPIN_OS_RELEASE_TOOL}\"") +else() + formatString(DEEPIN_OS_TYPE) + + message("Deepin OS Type: ${DEEPIN_OS_TYPE}") + + if(NOT "${DEEPIN_OS_TYPE}" STREQUAL "") + addDefinitions(Q_OS_DEEPIN_${DEEPIN_OS_TYPE}) + string(TOUPPER ${DEEPIN_OS_TYPE} DEEPIN_OS_TYPE) + set(OS_DEEPIN_${DEEPIN_OS_TYPE} TRUE) + endif() + + add_definitions(-DQ_OS_DEEPIN) + set(OS_DEEPIN TRUE) +endif() diff --git a/debian/libdtkcore-bin.install b/debian/libdtkcore-bin.install index b808e55..a0739b8 100644 --- a/debian/libdtkcore-bin.install +++ b/debian/libdtkcore-bin.install @@ -1 +1,2 @@ usr/lib/dtk2/* +usr/lib/*/*/DCore/bin/* diff --git a/dtkcore.pro b/dtkcore.pro index 2ce7963..1b7c66f 100644 --- a/dtkcore.pro +++ b/dtkcore.pro @@ -1,2 +1 @@ include($$PWD/src/dtk_lib.prf) - diff --git a/src/DSysInfo b/src/DSysInfo new file mode 100644 index 0000000..c026f58 --- /dev/null +++ b/src/DSysInfo @@ -0,0 +1 @@ +#include "dsysinfo.h" diff --git a/src/dsysinfo.cpp b/src/dsysinfo.cpp new file mode 100644 index 0000000..0fa9045 --- /dev/null +++ b/src/dsysinfo.cpp @@ -0,0 +1,442 @@ +/* + * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. + * + * Author: zccrs + * + * Maintainer: zccrs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "dsysinfo.h" + +#include +#include +#include +#include +#include + +#ifdef Q_OS_LINUX +#include +#include +#include +#endif + +DCORE_BEGIN_NAMESPACE + +class DSysInfoPrivate +{ +public: + DSysInfoPrivate(); + +#ifdef Q_OS_LINUX + void ensureDeepinInfo(); +#endif + void ensureReleaseInfo(); + void ensureComputerInfo(); + +#ifdef Q_OS_LINUX + DSysInfo::DeepinType deepinType = DSysInfo::DeepinType(-1); + QMap deepinTypeMap; //Type Name with Language + QString deepinEdition; + QString deepinCopyright; +#endif + + DSysInfo::ProductType productType = DSysInfo::ProductType(-1); + QString prettyName; + QString productTypeString; + QString productVersion; + + QString computerName; + QString cpuModelName; + qint64 memoryTotalSize = -1; + qint64 diskSize = 0; +}; + +DSysInfoPrivate::DSysInfoPrivate() +{ + +} + +#ifdef Q_OS_LINUX +void DSysInfoPrivate::ensureDeepinInfo() +{ + if (deepinType >= 0) + return; + + QFile file("/etc/deepin-version"); + + if (!file.open(QFile::ReadOnly)) { + deepinType = DSysInfo::UnknownDeepin; + + return; + } + + char buf[1024]; + int buf_length = 0; + + Q_FOREVER { + buf_length = file.readLine(buf, sizeof(buf)); + + if (buf_length < 0) + break; + + const QByteArray line(buf, buf_length); + const QByteArrayList &list = line.split('='); + + if (list.count() != 2) { + continue; + } + + const auto key_value = qMakePair(list.first().trimmed(), list.last().trimmed()); + + if (line.startsWith("Type")) { + if (key_value.first == "Type") { + deepinTypeMap[QString()] = QString::fromLatin1(key_value.second); + } else if (key_value.first.at(4) == '[' && key_value.first.at(key_value.first.size() - 1) == ']') { + const QByteArray &language = key_value.first.mid(5, key_value.first.size() - 6); + + if (!language.isEmpty()) { + deepinTypeMap[QString::fromLatin1(language)] = QString::fromUtf8(key_value.second); + } + } + } else if (key_value.first == "Edition") { + deepinEdition = QString::fromUtf8(key_value.second); + } else if (key_value.first == "Copyright") { + deepinCopyright = QString::fromUtf8(key_value.second); + } + + if (!deepinTypeMap.isEmpty() && !deepinEdition.isEmpty() && !deepinCopyright.isEmpty()) { + break; + } + } + + file.close(); + + const QString &deepin_type = deepinTypeMap[QString()]; + + if (deepin_type.isEmpty()) { + deepinType = DSysInfo::UnknownDeepin; + } else if (deepin_type == "Desktop") { + deepinType = DSysInfo::DeepinDesktop; + } else if (deepin_type == "Professional") { + deepinType = DSysInfo::DeepinProfessional; + } else { + deepinType = DSysInfo::UnknownDeepin; + } + + if (!deepinTypeMap.isEmpty() && productTypeString.isEmpty()) { + productTypeString = "deepin"; + productType = DSysInfo::Deepin; + } +} + +static QString unquote(const QByteArray &value) +{ + if (value.at(0) == '"' || value.at(0) == '\'') { + return QString::fromLatin1(value.mid(1, value.size() - 2)); + } + + return QString::fromLatin1(value); +} + +static bool readEtcFile(DSysInfoPrivate *info, const char *filename, + const QByteArray &idKey, const QByteArray &versionKey, const QByteArray &prettyNameKey) +{ + + QFile file(QString::fromLatin1(filename)); + + if (!file.open(QIODevice::ReadOnly)) { + return false; + } + + quint8 valid_data_count = 0; + char buf[1024]; + + while (valid_data_count < 3) { + int buf_length = file.readLine(buf, sizeof(buf)); + + if (buf_length < 0) + break; + + const QByteArray line(buf, buf_length - 1); + + if (line.startsWith(idKey)) { + const QByteArray value(line.constData() + idKey.size()); + info->productTypeString = unquote(value); + ++valid_data_count; + continue; + } + + if (line.startsWith(prettyNameKey)) { + const QByteArray value(line.constData() + prettyNameKey.size()); + info->prettyName = unquote(value); + ++valid_data_count; + continue; + } + + if (line.startsWith(versionKey)) { + const QByteArray value(line.constData() + versionKey.size()); + info->productVersion = unquote(value); + ++valid_data_count; + continue; + } + } + + file.close(); + + return valid_data_count != 0; +} + +static bool readOsRelease(DSysInfoPrivate *info) +{ + if (!readEtcFile(info, "/etc/os-release", "ID=", "VERSION_ID=", "PRETTY_NAME=")) + return readEtcFile(info, "/usr/lib/os-release", "ID=", "VERSION_ID=", "PRETTY_NAME="); + + return true; +} + +static bool readLsbRelease(DSysInfoPrivate *info) +{ + return readEtcFile(info, "/etc/lsb-release", "DISTRIB_ID=", "DISTRIB_RELEASE=", "DISTRIB_DESCRIPTION="); +} +#endif + +void DSysInfoPrivate::ensureReleaseInfo() +{ + if (productType >= 0) { + return; + } + +#ifdef Q_OS_LINUX + if (!readOsRelease(this)) + readLsbRelease(this); + + if (productTypeString.isEmpty()) { + productType = DSysInfo::UnknownType; + } else { + switch (productTypeString.at(0).unicode()) { + case 'd': + case 'D': + if (productTypeString.compare("deepin", Qt::CaseInsensitive) == 0) { + productType = DSysInfo::Deepin; + } else if (productTypeString.compare("debian", Qt::CaseInsensitive) == 0) { + productType = DSysInfo::Debian; + } + break; + case 'a': + case 'A': + if (productTypeString.compare("arch", Qt::CaseInsensitive) == 0) + productType = DSysInfo::ArchLinux; + break; + case 'c': + case 'C': + if (productTypeString.compare("centos", Qt::CaseInsensitive) == 0) + productType = DSysInfo::CentOS; + break; + case 'f': + case 'F': + if (productTypeString.compare("fedora", Qt::CaseInsensitive) == 0) + productType = DSysInfo::Fedora; + break; + case 'l': + case 'L': + if (productTypeString.compare("linuxmint", Qt::CaseInsensitive) == 0) + productType = DSysInfo::LinuxMint; + break; + case 'm': + case 'M': + if (productTypeString.compare("manjaro", Qt::CaseInsensitive) == 0) + productType = DSysInfo::Manjaro; + break; + case 'o': + case 'O': + if (productTypeString.compare("opensuse", Qt::CaseInsensitive) == 0) + productType = DSysInfo::openSUSE; + break; + case 's': + case 'S': + if (productTypeString.compare("sailfishos", Qt::CaseInsensitive) == 0) + productType = DSysInfo::SailfishOS; + break; + case 'u': + case 'U': + if (productTypeString.compare("ubuntu", Qt::CaseInsensitive) == 0) + productType = DSysInfo::Ubuntu; + break; + default: + productType = DSysInfo::UnknownType; + break; + } + } +#endif +} + +void DSysInfoPrivate::ensureComputerInfo() +{ + if (memoryTotalSize >= 0) + return; + +#ifdef Q_OS_LINUX + struct utsname u; + if (uname(&u) == 0) + computerName = QString::fromLatin1(u.nodename); + + QFile file("/proc/cpuinfo"); + + if (file.open(QFile::ReadOnly)) { + char buf[1024]; + qint64 lineLength = 0; + + do { + lineLength = file.readLine(buf, sizeof(buf)); + + const QByteArray line(buf, lineLength); + + if (line.startsWith("model name")) { + if (int index = line.indexOf(':', 10)) { + if (index > 0) + cpuModelName = QString::fromLatin1(line.mid(index + 1).trimmed()); + } + break; + } + } while (lineLength >= 0); + + file.close(); + } + + memoryTotalSize = get_phys_pages() * sysconf(_SC_PAGESIZE); + + const QString &root_part = QStorageInfo::root().device(); + + if (root_part.isEmpty()) + return; + + QProcess lsblk; + + lsblk.start("lsblk", {"-prno", "pkname", root_part}, QIODevice::ReadOnly); + + if (!lsblk.waitForFinished()) + return; + + const QString &root_disk = QString::fromLatin1(lsblk.readAllStandardOutput().trimmed()); + + lsblk.start("lsblk", {"-prnbdo", "size", root_disk}, QIODevice::ReadOnly); + + if (!lsblk.waitForFinished()) + return; + + const QByteArray &disk_size = lsblk.readAllStandardOutput().trimmed(); + diskSize = disk_size.toLongLong(); +#endif +} + +Q_GLOBAL_STATIC(DSysInfoPrivate, siGlobal) + +QString DSysInfo::operatingSystemName() +{ + siGlobal->ensureReleaseInfo(); + + return siGlobal->prettyName; +} + +#ifdef Q_OS_LINUX +bool DSysInfo::isDeepin() +{ + siGlobal->ensureReleaseInfo(); + + if (siGlobal->productTypeString.isEmpty()) + siGlobal->ensureDeepinInfo(); + + return productType() == Deepin; +} + +DSysInfo::DeepinType DSysInfo::deepinType() +{ + siGlobal->ensureDeepinInfo(); + + return siGlobal->deepinType; +} + +QString DSysInfo::deepinTypeDisplayName(const QLocale &locale) +{ + siGlobal->ensureDeepinInfo(); + + return siGlobal->deepinTypeMap.value(locale.name(), siGlobal->deepinTypeMap.value(QString())); +} + +QString DSysInfo::deepinEdition() +{ + siGlobal->ensureDeepinInfo(); + + return siGlobal->deepinEdition; +} + +QString DSysInfo::deepinCopyright() +{ + siGlobal->ensureDeepinInfo(); + + return siGlobal->deepinCopyright; +} +#endif + +DSysInfo::ProductType DSysInfo::productType() +{ + siGlobal->ensureReleaseInfo(); + + return siGlobal->productType; +} + +QString DSysInfo::productTypeString() +{ + siGlobal->ensureReleaseInfo(); + + return siGlobal->productTypeString; +} + +QString DSysInfo::productVersion() +{ + siGlobal->ensureReleaseInfo(); + + return siGlobal->productVersion; +} + +QString DSysInfo::computerName() +{ + siGlobal->ensureComputerInfo(); + + return siGlobal->computerName; +} + +QString DSysInfo::cpuModelName() +{ + siGlobal->ensureComputerInfo(); + + return siGlobal->cpuModelName; +} + +qint64 DSysInfo::memoryTotalSize() +{ + siGlobal->ensureComputerInfo(); + + return siGlobal->memoryTotalSize; +} + +qint64 DSysInfo::systemDiskSize() +{ + siGlobal->ensureComputerInfo(); + + return siGlobal->diskSize; +} + +DCORE_END_NAMESPACE diff --git a/src/dsysinfo.h b/src/dsysinfo.h new file mode 100644 index 0000000..744c298 --- /dev/null +++ b/src/dsysinfo.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. + * + * Author: zccrs + * + * Maintainer: zccrs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef DSYSINFO_H +#define DSYSINFO_H + +#include + +#include + +DCORE_BEGIN_NAMESPACE + +class DSysInfoPrivate; +class DSysInfo +{ +public: + enum ProductType { + UnknownType = 0, + Deepin, + ArchLinux, + CentOS, + Debian, + Fedora, + LinuxMint, + Manjaro, + openSUSE, + SailfishOS, + Ubuntu + }; + + enum DeepinType { + UnknownDeepin = 0, + DeepinDesktop, + DeepinProfessional + }; + +#ifdef Q_OS_LINUX + static bool isDeepin(); + static DeepinType deepinType(); + static QString deepinTypeDisplayName(const QLocale &locale = QLocale::system()); + static QString deepinEdition(); + static QString deepinCopyright(); +#endif + + static QString operatingSystemName(); + static ProductType productType(); + static QString productTypeString(); + static QString productVersion(); + + static QString computerName(); + static QString cpuModelName(); + static qint64 memoryTotalSize(); + static qint64 systemDiskSize(); +}; + +DCORE_END_NAMESPACE + +#endif // DSYSINFO_H diff --git a/src/dtk_build.prf b/src/dtk_build.prf index 251e0b1..70bbf07 100644 --- a/src/dtk_build.prf +++ b/src/dtk_build.prf @@ -60,6 +60,10 @@ isEmpty(LIB_INSTALL_DIR) { } } +isEmpty(BIN_INSTALL_DIR) { + TOOL_INSTALL_DIR=$$LIB_INSTALL_DIR/libdtk-$${VER_MAJ}.$${VER_MIN}.$${VER_PAT}/D$$upper($$member($$list($$split(TARGET,)), 3, 3))$$join($$list($$member($$list($$split(TARGET,)), 4, -1)))/bin +} + isEmpty(target.path): target.path = $$LIB_INSTALL_DIR isEmpty(INCLUDE_INSTALL_DIR) { diff --git a/src/dtk_cmake.prf b/src/dtk_cmake.prf index f6ea194..601289d 100644 --- a/src/dtk_cmake.prf +++ b/src/dtk_cmake.prf @@ -32,7 +32,11 @@ for(MODULE_DEPEND, CMAKE_MODULE_DEPENDS) { CMAKE_MODULE_INCLUDE_DIR=$$upper($${CMAKE_MODULE})_INCLUDE_DIR INC_DIR = $$replace(includes.path, "/", "/") -CMAKE_CONTENT += "set($${CMAKE_MODULE_INCLUDE_DIR} \"$${INC_DIR}\")" +CMAKE_MODULE_TOO_DIR=$$upper($${CMAKE_MODULE})_TOOL_DIR +TOOL_DIR = $$TOOL_INSTALL_DIR + +CMAKE_CONTENT += "set($${CMAKE_MODULE_INCLUDE_DIR} $${INC_DIR})" +CMAKE_CONTENT += "set($${CMAKE_MODULE_TOO_DIR} $${TOOL_DIR})" CMAKE_CONTENT += "set($${CMAKE_MODULE}_LIBRARIES $$TARGET$$LINK_LIBRARIES)" CMAKE_CONTENT += "include_directories(\"${"$${CMAKE_MODULE_INCLUDE_DIR}"}\")" diff --git a/src/dtk_module.prf b/src/dtk_module.prf index fa76bb0..d26330d 100644 --- a/src/dtk_module.prf +++ b/src/dtk_module.prf @@ -9,6 +9,7 @@ MODULE_ID=$$DTK_MODULE mod_inst_pfx=$$_PRO_FILE_PWD_ MODULE_PRI = $$mod_inst_pfx/qt_lib_$${MODULE_ID}.pri module_libs = $$target.path +module_tools = $$TOOL_INSTALL_DIR MODULE_INCLUDES = $$includes.path DTK_MODULE_DEPENDS=$$find(QT, dtk*) @@ -31,6 +32,9 @@ host_build: \ else: \ module_libs = "\$\$QT_MODULE_LIB_BASE" } +isEmpty(module_tools) { + module_tools=$$module_libs/libdtk-$${VER_MAJ}.$${VER_MIN}.$${VER_PAT}/D$$upper($$member($$list($$split(TARGET,)), 3, 3))$$join($$list($$member($$list($$split(TARGET,)), 4, -1)))/bin +} # In addition to the library's private deps, the private module's deps # are logically runtime deps of the public module. runtime_deps = $$QT_PRIVATE $$QT_FOR_PRIVATE @@ -75,6 +79,7 @@ MODULE_PRI_CONT = \ "" \ "QT.$${MODULE_ID}.name = $${TARGET}" \ "QT.$${MODULE_ID}.module = $$module_module" \ + "QT.$${MODULE_ID}.tools = $$module_tools" \ "QT.$${MODULE_ID}.libs = $$module_libs" \ $$module_master \ "QT.$${MODULE_ID}.includes = $$MODULE_INCLUDES" \ diff --git a/src/dtk_qmake.prf b/src/dtk_qmake.prf new file mode 100644 index 0000000..d438099 --- /dev/null +++ b/src/dtk_qmake.prf @@ -0,0 +1,73 @@ +CONFIG += host_$$QMAKE_HOST.arch +DEFINES += Q_HOST_NAME=\\\"$$QMAKE_HOST.arch\\\" Q_HOST_$$upper($$QMAKE_HOST.arch) + +isEqual(TARGET, dtkcore) { + # build tools/deepin-os-release first + QMAKE_CONFIG_TESTS_DIR_BAK=$$QMAKE_CONFIG_TESTS_DIR + load(configure) + QMAKE_CONFIG_TESTS_DIR=$$_PRO_FILE_PWD_/../tools + qtCompileTest(deepin-os-release) + DEEPIN_OS_RELEASE_TOOL=$$_PRO_FILE_PWD_/../bin/deepin-os-release + QMAKE_CONFIG_TESTS_DIR=$$QMAKE_CONFIG_TESTS_DIR_BAK +} else { + isEmpty(QT.dtkcore.tools): error(QT += dtkcore first) + DEEPIN_OS_RELEASE_TOOL=$${QT.dtkcore.tools}/deepin-os-release +} + +!exists($$DEEPIN_OS_RELEASE_TOOL): error(\"$$DEEPIN_OS_RELEASE_TOOL\" is not exists. Install \"dtkcore-bin\" first) + +defineReplace(formatString) { + string = $$1 + string = $$replace(string, \\s+, _) + string_count = $$size(string) + + greaterThan(string_count, 1) { + for (item, string) { + isEmpty(new_string): new_string = $$item + else: new_string = $${new_string}_$${item} + } + + return($$new_string) + } + + return($$string) +} + +DEEPIN_OS_TYPE = $$system($$DEEPIN_OS_RELEASE_TOOL --deepin-type) +DISTRIB_ID = $$system($$DEEPIN_OS_RELEASE_TOOL --product-type) +DISTRIB_RELEASE = $$system($$DEEPIN_OS_RELEASE_TOOL --product-version) + +isEmpty(DISTRIB_ID): warning(No value of the "--product-type" in the process "$$DEEPIN_OS_RELEASE_TOOL") +else { + DISTRIB_ID = $$formatString($$DISTRIB_ID) + + message("OS: $$DISTRIB_ID, Version: $$DISTRIB_RELEASE") + + QMAKE_PLATFORM += $$lower($$DISTRIB_ID) + + !isEmpty(DISTRIB_ID): DEFINES *= Q_OS_$$upper($$DISTRIB_ID) + CONFIG *= $$QMAKE_PLATFORM + + isEmpty(DISTRIB_RELEASE): warning(No value of the "--product-version") + else { + DISTRIB_RELEASE = $$formatString($$DISTRIB_RELEASE) + !isEmpty(DISTRIB_RELEASE): DEFINES *= Q_OS_VERSION=\\\"$$DISTRIB_RELEASE\\\" + } +} + +isEmpty(DEEPIN_OS_TYPE): warning(No value of the "--deepin-type" in the process "$$DEEPIN_OS_RELEASE_TOOL") +else { + DEEPIN_OS_TYPE = $$formatString($$DEEPIN_OS_TYPE) + + message(Deepin OS Type: $$DEEPIN_OS_TYPE) + + QMAKE_PLATFORM += deepin + + !isEmpty(DEEPIN_OS_TYPE) { + QMAKE_PLATFORM += deepin_$$lower($$DEEPIN_OS_TYPE) + DEFINES *= Q_OS_DEEPIN_$$upper($$DEEPIN_OS_TYPE) + } + + CONFIG *= $$QMAKE_PLATFORM + DEFINES *= Q_OS_DEEPIN +} diff --git a/src/src.pro b/src/src.pro index b198292..1c939b3 100644 --- a/src/src.pro +++ b/src/src.pro @@ -6,7 +6,11 @@ TARGET = dtkcore include(dtk_build.prf) INCLUDEPATH += $$PWD -HEADERS += $$PWD/dtkcore_global.h +HEADERS += $$PWD/dtkcore_global.h \ + dsysinfo.h + +SOURCES += \ + dsysinfo.cpp include($$PWD/base/base.pri) include($$PWD/util/util.pri) @@ -76,7 +80,11 @@ defineTest(updateDtkCoreConfigFile) { # ---------------------------------------------- # install config -includes.files += $$PWD/*.h $$PWD/dtkcore_config.h $$PWD/DtkCore +includes.files += \ + $$PWD/*.h \ + $$PWD/dtkcore_config.h \ + $$PWD/DtkCore \ + $$PWD/DSysInfo INSTALLS += includes target @@ -94,4 +102,17 @@ include(dtk_module.prf) prf.files+= $$PWD/*.prf prf.path = $${QT_HOST_DATA}/mkspecs/features + +linux { + # dtk for qmake + include(dtk_qmake.prf) + + deepin_os_release_tool.files=$$PWD/../bin/deepin-os-release + deepin_os_release_tool.path=$$TOOL_INSTALL_DIR + + INSTALLS += deepin_os_release_tool +} else { + prf.files-=$$PWD/dtk_qmake.prf +} + INSTALLS += prf diff --git a/tools/deepin-os-release/deepin-os-release.pro b/tools/deepin-os-release/deepin-os-release.pro new file mode 100644 index 0000000..f56dd76 --- /dev/null +++ b/tools/deepin-os-release/deepin-os-release.pro @@ -0,0 +1,12 @@ +QT -= gui +TEMPLATE = app +CONFIG += qt + +HEADERS += ../../src/dsysinfo.h + +SOURCES += \ + main.cpp \ + ../../src/dsysinfo.cpp + +INCLUDEPATH += ../../src +DESTDIR = $$_PRO_FILE_PWD_/../../bin diff --git a/tools/deepin-os-release/main.cpp b/tools/deepin-os-release/main.cpp new file mode 100644 index 0000000..cd79e73 --- /dev/null +++ b/tools/deepin-os-release/main.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. + * + * Author: zccrs + * + * Maintainer: zccrs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "dsysinfo.h" + +#include +#include +#include +#include + +#include + +DCORE_USE_NAMESPACE + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + Q_UNUSED(app) + + QCommandLineParser parser; + QCommandLineOption option_all("all"); + QCommandLineOption option_deepin_type("deepin-type"); + QCommandLineOption option_deepin_edition("deepin-edition"); + QCommandLineOption option_deepin_copyright("deepin-copyright"); + QCommandLineOption option_product_type("product-type"); + QCommandLineOption option_product_version("product-version"); + QCommandLineOption option_computer_name("computer-name"); + QCommandLineOption option_cpu_model("cpu-model"); + QCommandLineOption optioin_memory_size("memory-size"); + QCommandLineOption optioin_disk_size("disk-size"); + + parser.addOptions({option_all, option_deepin_type, option_deepin_edition, + option_deepin_copyright, option_product_type, option_product_version, + option_computer_name, option_cpu_model, optioin_memory_size, optioin_disk_size}); + parser.addHelpOption(); + parser.addVersionOption(); + parser.process(app); + + if (parser.isSet(option_all)) { + printf("Computer Name: %s\n", qPrintable(DSysInfo::computerName())); + printf("CPU Model: %s x %d\n", qPrintable(DSysInfo::cpuModelName()), QThread::idealThreadCount()); + printf("Memory Size: %f GiB\n", DSysInfo::memoryTotalSize() / 1024.0 / 1024 / 1024); + printf("Disk Size: %f GiB\n", DSysInfo::systemDiskSize() / 1024.0 / 1024 / 1024); + + printf("Deepin Type: %s\n", qPrintable(DSysInfo::deepinTypeDisplayName(QLocale::c()))); + printf("Deepin Edition: %s\n", qPrintable(DSysInfo::deepinEdition())); + printf("Deepin Copyright: %s\n", qPrintable(DSysInfo::deepinCopyright())); + + printf("Operating System Name: %s\n", qPrintable(DSysInfo::operatingSystemName())); + printf("Product Type: %s\n", qPrintable(DSysInfo::productTypeString())); + printf("Product Version: %s\n", qPrintable(DSysInfo::productVersion())); + } else { + if (parser.isSet(option_deepin_type)) + printf("%s", qPrintable(DSysInfo::deepinTypeDisplayName(QLocale::c()))); + else if (parser.isSet(option_deepin_edition)) + printf("%s", qPrintable(DSysInfo::deepinEdition())); + else if (parser.isSet(option_deepin_copyright)) + printf("%s", qPrintable(DSysInfo::deepinCopyright())); + else if (parser.isSet(option_product_type)) + printf("%s", qPrintable(DSysInfo::productTypeString())); + else if (parser.isSet(option_product_version)) + printf("%s", qPrintable(DSysInfo::productVersion())); + } + + return 0; +} diff --git a/tools/tools.pro b/tools/tools.pro index b658081..a26c0c6 100644 --- a/tools/tools.pro +++ b/tools/tools.pro @@ -1,3 +1,3 @@ TEMPLATE = subdirs -!mac:!win*: SUBDIRS += settings +!mac:!win*: SUBDIRS += settings deepin-os-release