| 1 |
/*! |
| 2 |
@~chinese |
| 3 |
@ingroup dglobal |
| 4 |
@file include/global/dsysinfo.h |
| 5 |
|
| 6 |
@class Dtk::Core::DSysInfo |
| 7 |
@brief dsysinfo 是一组用于查询系统信息的静态类 |
| 8 |
@details |
| 9 |
## 概述 |
| 10 |
|
| 11 |
dsysinfo是一组用于查询系统信息的静态类 |
| 12 |
|
| 13 |
项目目录结构如下: |
| 14 |
|
| 15 |
```bash |
| 16 |
├── CMakeLists.txt |
| 17 |
└── main.cpp |
| 18 |
``` |
| 19 |
|
| 20 |
## CMakeLists.txt |
| 21 |
|
| 22 |
```cmake |
| 23 |
cmake_minimum_required(VERSION 3.13) # cmake版本要求 |
| 24 |
set (VERSION "1.0.0" CACHE STRING "define project version") # 定义项目版本 |
| 25 |
set(BIN_NAME test) # 定义项目名称 |
| 26 |
project(test) # 定义项目名称 |
| 27 |
file(GLOB_RECURSE SRCS "*.h" "*.cpp") # 定义项目源文件 |
| 28 |
find_package(Qt5 REQUIRED COMPONENTS Core) # 寻找Qt5 |
| 29 |
find_package(DtkCore REQUIRED) # 寻找DtkCore |
| 30 |
|
| 31 |
add_executable(test |
| 32 |
main.cpp # 源文件 |
| 33 |
) |
| 34 |
|
| 35 |
target_link_libraries(test PRIVATE |
| 36 |
${DtkCore_LIBRARIES} # 链接DtkCore |
| 37 |
Qt5::Core # 链接Qt5 |
| 38 |
) |
| 39 |
|
| 40 |
``` |
| 41 |
|
| 42 |
## main.cpp |
| 43 |
|
| 44 |
```cpp |
| 45 |
#include <DSysInfo> // 引入DSysInfo |
| 46 |
#include <qdebug.h> // 引入qdebug.h |
| 47 |
DCORE_USE_NAMESPACE // 使用dtkcore命名空间 |
| 48 |
|
| 49 |
int main(int argc, char **argv) { |
| 50 |
|
| 51 |
qDebug() << DSysInfo::deepinType(); // 打印deepin类型 |
| 52 |
qDebug() << DSysInfo::ProductType(); // 打印产品类型 |
| 53 |
return 0; |
| 54 |
} |
| 55 |
``` |
| 56 |
|
| 57 |
@enum Dtk::Core::DSysInfo::ProductType |
| 58 |
@brief 产品信息 |
| 59 |
@var Dtk::Core::DSysInfo::ProductType Dtk::Core::DSysInfo::Deepin |
| 60 |
@brief 深度操作系统 |
| 61 |
@var Dtk::Core::DSysInfo::ProductType Dtk::Core::DSysInfo::ArchLinux |
| 62 |
@brief ArchLinux |
| 63 |
@var Dtk::Core::DSysInfo::ProductType Dtk::Core::DSysInfo::CentOS |
| 64 |
@brief CentOS |
| 65 |
@var Dtk::Core::DSysInfo::ProductType Dtk::Core::DSysInfo::Debian |
| 66 |
@brief Debian |
| 67 |
@var Dtk::Core::DSysInfo::ProductType Dtk::Core::DSysInfo::Fedora |
| 68 |
@brief Fedora |
| 69 |
@var Dtk::Core::DSysInfo::ProductType Dtk::Core::DSysInfo::LinuxMint |
| 70 |
@brief LinuxMint |
| 71 |
@var Dtj::Core::DSysInfo::ProductType Dtk::Core::DSysInfo::Manjaro |
| 72 |
@brief Manjaro |
| 73 |
@var Dtk::Core::DSysInfo::ProductType Dtk::Core::DSysInfo::openSUSE |
| 74 |
@brief openSUSE |
| 75 |
@var Dtk::Core::DSysInfo::ProductType Dtk::Core::DSysInfo::SailfishOS |
| 76 |
@brief SailfishOS |
| 77 |
@var Dtk::Core::DSysInfo::ProductType Dtk::Core::DSysInfo::Ubuntu |
| 78 |
@brief Ubuntu |
| 79 |
@var Dtk::Core::DSysInfo::ProductType Dtk::Core::DSysInfo::Uos |
| 80 |
@brief UOS |
| 81 |
@var Dtk::Core::DSysInfo::ProductType Dtk::Core::DSysInfo::Gentoo |
| 82 |
@brief Gentoo |
| 83 |
@var Dtk::Core::DSysInfo::ProductType Dtk::Core::DSysInfo::NixOS |
| 84 |
@brief NixOS |
| 85 |
|
| 86 |
@enum Dtk::Core::DSysInfo::DeepinType |
| 87 |
@brief 深度操作系统版本 |
| 88 |
@var Dtk::Core::DSysInfo::DeepinType Dtk::Core::DSysInfo::UnknownDeepin |
| 89 |
@brief 未知版本 |
| 90 |
@var Dtk::Core::DSysInfo::DeepinType Dtk::Core::DSysInfo::DeepinDesktop |
| 91 |
@brief 桌面版 |
| 92 |
@var Dtk::Core::DSysInfo::DeepinType Dtk::Core::DSysInfo::DeepinProfessional |
| 93 |
@brief deepin专业版, 现为uos专业版 |
| 94 |
@var Dtk::Core::DSysInfo::DeepinType Dtk::Core::DSysInfo::DeepinServer |
| 95 |
@brief deepin服务器版本, 现为uos服务器版 |
| 96 |
@var Dtk::Core::DSysInfo::DeepinType Dtk::Core::DSysInfo::DeepinPersonal |
| 97 |
@brief deepin个人版, 现为uos家庭版 |
| 98 |
|
| 99 |
@enum Dtk::Core::DSysInfo::LogoType |
| 100 |
@brief 系统的logo类型 |
| 101 |
@var Dtk::Core::DSysInfo::LogoType Dtk::Core::DSysInfo::Normal |
| 102 |
@brief 正常 |
| 103 |
@var Dtk::Core::DSysInfo::LogoType Dtk::Core::DSysInfo::Light |
| 104 |
@brief 亮色 |
| 105 |
@var Dtk::Core::DSysInfo::LogoType Dtk::Core::DSysInfo::Symbolic |
| 106 |
@brief 符号 |
| 107 |
@var Dtk::Core::DSysInfo::LogoType Dtk::Core::DSysInfo::Transparent |
| 108 |
@brief 水印 |
| 109 |
|
| 110 |
@enum Dtk::Core::DSysInfo::OrgType |
| 111 |
@brief 组织类型 |
| 112 |
@var Dtk::Core::DSysInfo::OrgType Dtk::Core::DSysInfo::Distribution |
| 113 |
@brief 当前版本 |
| 114 |
@var Dtk::Core::DSysInfo::OrgType Dtk::Core::DSysInfo::Distributor |
| 115 |
@brief 当前发行版 |
| 116 |
@var Dtk::Core::DSysInfo::OrgType Dtk::Core::DSysInfo::Manufacturer |
| 117 |
@brief 当前发行版或设备的制造商 |
| 118 |
|
| 119 |
@enum Dtk::Core::DSysInfo::UosType |
| 120 |
@brief UOS版本类型 |
| 121 |
@var Dtk::Core::DSysInfo::UosType Dtk::Core::DSysInfo::UosTypeUnknown |
| 122 |
@brief 未知版本 |
| 123 |
@var Dtk::Core::DSysInfo::UosType Dtk::Core::DSysInfo::UosDesktop |
| 124 |
@brief UOS桌面版 |
| 125 |
@var Dtk::Core::DSysInfo::UosType Dtk::Core::DSysInfo::UosServer |
| 126 |
@brief UOS服务器版 |
| 127 |
@var Dtk::Core::DSysInfo::UosType Dtk::Core::DSysInfo::UosDevice |
| 128 |
@brief UOS设备版 |
| 129 |
@var Dtk::Core::DSysInfo::UosType Dtk::Core::DSysInfo::UosTypeCount |
| 130 |
@brief 记录枚举数量 |
| 131 |
|
| 132 |
@enum Dtk::Core::DSysInfo::UosEdition |
| 133 |
@brief 详细uos版本 |
| 134 |
@var Dtk::Core::DSysInfo::UosEdition Dtk::Core::DSysInfo::UosEditionUnknown |
| 135 |
@brief 未知版本 |
| 136 |
@var Dtk::Core::DSysInfo::UosEdition Dtk::Core::DSysInfo::UosProfessional |
| 137 |
@brief UOS专业版 |
| 138 |
@var Dtk::Core::DSysInfo::UosEdition Dtk::Core::DSysInfo::UosHome |
| 139 |
@brief UOS家庭版 |
| 140 |
@var Dtk::Core::DSysInfo::UosEdition Dtk::Core::DSysInfo::UosCommunity |
| 141 |
@brief 社区版 |
| 142 |
@var Dtk::Core::DSysInfo::UosEdition Dtk::Core::DSysInfo::UosMilitary |
| 143 |
@brief * |
| 144 |
@var Dtk::Core::DSysInfo::UosEdition Dtk::Core::DSysInfo::UosEnterprise |
| 145 |
@brief UOS企业版 |
| 146 |
@var Dtk::Core::DSysInfo::UosEdition Dtk::Core::DSysInfo::UosEnterpriseC |
| 147 |
@brief UOS行业版 |
| 148 |
@var Dtk::Core::DSysInfo::UosEdition Dtk::Core::DSysInfo::UosEuler |
| 149 |
@brief UOS服务器欧拉版 |
| 150 |
@var Dtk::Core::DSysInfo::UosEdition Dtk::Core::DSysInfo::UosMilitaryS |
| 151 |
@brief * |
| 152 |
@var Dtk::Core::DSysInfo::UosEdition Dtk::Core::DSysInfo::UosDeviceEdition |
| 153 |
@brief UOS专用设备版 |
| 154 |
@var Dtk::Core::DSysInfo::UosEdition Dtk::Core::DSysInfo::UosEducation |
| 155 |
@brief UOS教育版 |
| 156 |
@var Dtk::Core::DSysInfo::UosEdition Dtk::Core::DSysInfo::UosEditionCount |
| 157 |
@brief 记录枚举数量 |
| 158 |
|
| 159 |
@enum Dtk::Core::DSysInfo::UosArch |
| 160 |
@brief UOS使用的架构 |
| 161 |
@var Dtk::Core::DSysInfo::UosArch Dtk::Core::DSysInfo::UosArchUnknown |
| 162 |
@brief 未知架构 |
| 163 |
@var Dtk::Core::DSysInfo::UosArch Dtk::Core::DSysInfo::UosAMD64 |
| 164 |
@brief x86_64 |
| 165 |
@var Dtk::Core::DSysInfo::UosArch Dtk::Core::DSysInfo::UosARM64 |
| 166 |
@brief arm64 |
| 167 |
@var Dtk::Core::DSysInfo::UosArch Dtk::Core::DSysInfo::UosMIPS64 |
| 168 |
@brief mips64 |
| 169 |
@var Dtk::Core::DSysInfo::UosArch Dtk::Core::DSysInfo::UosSW64 |
| 170 |
@brief sw_64 |
| 171 |
|
| 172 |
|
| 173 |
@fn static bool Dtk::Core::DSysInfo::isDeepin() //FIXME: 显示错乱 无法修复 |
| 174 |
@brief 是否为 deepin 或 uos 系统 |
| 175 |
@return 0 不是 deepin 或 uos 系统 |
| 176 |
@return 1 是 deepin 或 uos 系统 |
| 177 |
|
| 178 |
@fn static bool Dtk::Core::DSysInfo::isDDE() |
| 179 |
@brief 是否使用 dde 桌面环境 |
| 180 |
@note 此方法仅在 linux 平台下可用 |
| 181 |
|
| 182 |
@fn static DeepinType Dtk::Core::DSysInfo::deepinType() |
| 183 |
@brief deepin 系统类型 |
| 184 |
@note 此方法仅在 linux 平台下可用 |
| 185 |
|
| 186 |
@fn static QString Dtk::Core::DSysInfo::deepinTypeDisplayName (const QLocale &locale=QLocale::system()) |
| 187 |
@brief 显示的 deepin 发行版类型名称 |
| 188 |
@note 此方法仅在 linux 平台下可用 |
| 189 |
|
| 190 |
@fn static QString Dtk::Core::DSysInfo::deepinVersion() |
| 191 |
@brief deepin 版本 |
| 192 |
@note 此方法仅在 linux 平台下可用 |
| 193 |
|
| 194 |
@fn static QString Dtk::Core::DSysInfo::deepinCopyright() |
| 195 |
@brief deepin 开源许可协议 |
| 196 |
@note 此方法仅在 linux 平台下可用 |
| 197 |
|
| 198 |
@fn static UosEdition Dtk::Core::DSysInfo::uosEditionType() |
| 199 |
@brief DSysInfo::osEditionType 版本类型 显示版本类型 专业版/个人版/社区版.. |
| 200 |
@note 根据 osBuild.B && osBuild.D |
| 201 |
@note 此方法仅在 linux 平台下可用 |
| 202 |
|
| 203 |
@fn static UosArch Dtk::Core::DSysInfo::uosArch() |
| 204 |
@brief DSysInfo::osArch 架构信息 |
| 205 |
@details(使用一个字节的二进制位, 从低位到高位) 【0x8 sw64】【0x4 mips64】【0x2 arm64】【0x1 amd64】 |
| 206 |
@note 此处架构是从 OsBuild 获取的系统版本的 Arch 信息, 并不是指硬件的 Arch 信息 |
| 207 |
@note 此方法仅在 linux 平台下可用 |
| 208 |
|
| 209 |
@fn static QString uosProductTypeName(const QLocale &locale=QLocale::system()) |
| 210 |
@brief DSysInfo::osProductTypeName 版本名称 |
| 211 |
@details ProductType[xx] 项对应的值, 如果找不到对应语言的默认使用 ProductType 的值(Desktop/Server/Device) locale 当前系统语言 |
| 212 |
|
| 213 |
@fn static QString Dtk::Core::DSysInfo::uosSystemName(const QLocale &locale=QLocale::system()) |
| 214 |
@brief SystemName[xx] 项对应的值 |
| 215 |
@details 如果找不到对应语言的默认使用 SystemName 的值 Uniontech OS locale 当前系统语言 |
| 216 |
@note 此方法仅在 linux 平台下可用 |
| 217 |
|
| 218 |
@fn static QString Dtk::Core::DSysInfo::function uosEditionName(const QLocale &locale=QLocale::system()) |
| 219 |
@brief 版本名称 EditionName[xx] 项对应的值 |
| 220 |
@details 如果找不到对应语言的默认使用 EditionName 的值(Professional/Home/Community...) locale 当前系统语言 |
| 221 |
@note 此方法仅在 linux 平台下可用 |
| 222 |
|
| 223 |
@fn static QString Dtk::Core::DSysInfo::spVersion() |
| 224 |
@brief 阶段版本名称 |
| 225 |
@details 小版本号 A-BC-D 中 BC、 A.B.C 中的 B 返回 SP1-SPxx, 如果正式版返回空 X.Y.Z模式下暂不支持返回此版本号 |
| 226 |
@note minVersion.BC == 00 正式版本, minVersion.BC | minVersion.B == 01-99 SP1….SP99 |
| 227 |
@note 此方法仅在 linux 平台下可用 |
| 228 |
|
| 229 |
@fn static QString Dtk::Core::DSysInfo::udpateVersion() |
| 230 |
@brief 更新版本名称 小版本号 A-BC-D 中 D、A.B.C 模式中的 C 返回 update1… update9, 如果正式版返回空 X.Y.Z 模式下暂不支持返回此版本号 |
| 231 |
@note minVersion.D == 0;正式版本 minVersion.D | minVersion.C == 1-9;update1… update9, updateA...updateZ |
| 232 |
@note 此方法仅在 linux 平台下可用 |
| 233 |
|
| 234 |
@fn static QString Dtk::Core::DSysInfo::majorVersion() |
| 235 |
@brief 主版本号 主版本号 【20】【23】【25】【26】【29】【30】 |
| 236 |
@note 此方法仅在 linux 平台下可用 |
| 237 |
|
| 238 |
@fn static QString Dtk::Core::DSysInfo::minorVersion() |
| 239 |
@brief 小版本号 【ABCD】 ·[0-9]{4} 【A.B.C】 或者【X.Y.Z】 |
| 240 |
@note 此方法仅在 linux 平台下可用 |
| 241 |
|
| 242 |
@fn static QString Dtk::Core::DSysInfo::buildVersion() |
| 243 |
@brief 小版本号 系统镜像批次号, 按时间顺序(不可回退)从100-999递增 |
| 244 |
@note 此方法仅在 linux 平台下可用 |
| 245 |
|
| 246 |
@fn static QString Dtk::Core::DSysInfo::distributionInfoPath () |
| 247 |
@brief 返回 distribution 文件地址 一般在`/usr/share/deepin/`目录下 |
| 248 |
|
| 249 |
@fn static QString Dtk::Core::DSysInfo::distributionInfoSectionName(OrgType type) |
| 250 |
@brief 返回 distribution.info 文件中 SectionName 字段的值 |
| 251 |
|
| 252 |
@fn static Dtk::Core::DSysInfo::distributionOrgName(OrgType type=Distribution, const QLocale &locale=QLocale::system()) |
| 253 |
@brief 返回组织名称 |
| 254 |
@details 使用类型为Distribution来获取当前deepin distribution本身的名称 |
| 255 |
|
| 256 |
@fn static QPair<QString, QString>Dtk::Core::DSysInfo::distributionOrgWebsite(OrgType type=Distribution) |
| 257 |
@brief 发行版组织的网站名称和网址。使用 type 作为 Distribution 获取当前 deepin 发行版本身的名称。 |
| 258 |
|
| 259 |
@fn static QString Dtk::Core::DSysInfo::distributionOrgLogo(OrgType orgType=Distribution, LogoType type=Normal, const QString &fallback=QString()) |
| 260 |
@brief 获得的组织logo路径, 如果不存在, 则返回给定的其他路径 |
| 261 |
@details 使用 type 作为 Distribution 获取当前 deepin 发行版本身的logo。 |
| 262 |
|
| 263 |
@fn static QString Dtk::Core::DSysInfo::operatingSystemName() |
| 264 |
@brief 操作系统名 |
| 265 |
|
| 266 |
@fn static ProductType Dtk::Core::DSysInfo::productType() |
| 267 |
@brief 产品类型 |
| 268 |
|
| 269 |
@fn static QString Dtk::Core::DSysInfo::productVersion() |
| 270 |
@brief 产品版本 |
| 271 |
|
| 272 |
@fn static bool Dtk::Core::DSysInfo::isCommunityEdition() |
| 273 |
@brief 检查当前版本是否是社区版 开发者可以使用这种方式来检查我们是否需要启用或禁用社区版或企业版的功能。 |
| 274 |
@details 目前的规则: |
| 275 |
专业版、服务器版、个人版(DeepinType)将被视为企业版。<br> |
| 276 |
Uos(ProductType)将被视为企业版。 |
| 277 |
|
| 278 |
@fn static QString Dtk::Core::DSysInfo::computerName() |
| 279 |
@brief 电脑名 |
| 280 |
|
| 281 |
@fn static QString Dtk::Core::DSysInfo::cpuModelName() |
| 282 |
@brief cpu模式名 |
| 283 |
|
| 284 |
@fn static qint64 Dtk::Core::DSysInfo::memoryInstalledSize() |
| 285 |
@brief 内存安装大小 |
| 286 |
|
| 287 |
@fn static qint64 Dtk::Core::DSysInfo::memoryTotalSize() |
| 288 |
@brief 实际内存大小 |
| 289 |
|
| 290 |
@fn static qint64 Dtk::Core::DSysInfo::systemDiskSize() |
| 291 |
@brief 系统磁盘大小 |
| 292 |
|
| 293 |
@fn static QDateTime Dtk::Core::DSysInfo::bootTime () |
| 294 |
@brief 系统启动时间点 |
| 295 |
|
| 296 |
@fn static QDateTime Dtk::Core::DSysInfo::shutdownTime () |
| 297 |
@brief 上一次正常关机时间点(重启也会被记录在内) |
| 298 |
|
| 299 |
@fn static qint64 Dtk::Core::DSysInfo::uptime() |
| 300 |
@brief 系统启动到现在时长 |
| 301 |
@note 参见`cat /proc/uptime`命令 |
| 302 |
|
| 303 |
@fn static Arch Dtk::Core::DSysInfo::arch |
| 304 |
@brief cpu架构信息 |
| 305 |
@note 此处架构是从gcc编译器获取的 |
| 306 |
|
| 307 |
*/ |