RabbitCommon v2.3.4
Loading...
Searching...
No Matches
Information.cpp
1// Copyright Copyright (c) Kang Lin studio, All Rights Reserved
2// Author Kang Lin <kl222@126.com>
3
4#include <QApplication>
5#include <QStyleHints>
6#include <QLibraryInfo>
7#include <QHostInfo>
8#include <QTextBrowser>
9#include <QStandardPaths>
10#include <QProcessEnvironment>
11#include <QLoggingCategory>
12#include <QMetaEnum>
13#include <QSslSocket>
14#include <QThread>
15
16#include "Information.h"
17#include "ui_Information.h"
18#include "RabbitCommonTools.h"
19#include "DlgAbout.h"
20
21static Q_LOGGING_CATEGORY(log, "RabbitCommon.DlgAbout.Information")
22
23CInformation::CInformation(const QString &szApp,
24 const QString &szInfo, QWidget *parent) :
25 QDialog(parent),
26 ui(new Ui::CInformation)
27{
28 ui->setupUi(this);
29 ui->tabWidget->removeTab(0);
30
31 SetContext(tr("Application"), szApp + szInfo);
32
33 QString szRabbitCommon;
34 szRabbitCommon = "\n" + tr("### RabbitCommon") + "\n";
35 szRabbitCommon += "- " + RabbitCommon::CTools::Version() + "\n";
36 szRabbitCommon += RabbitCommon::CTools::Information();
37 SetContext(tr("RabbitCommon"), szRabbitCommon);
38
39 QString szQt;
40 szQt = tr("### Qt") + "\n";
41 szQt += "- " + tr("Runtime version: ") + QString(qVersion()) + "\n";
42 szQt += "- " + tr("Compile version: ") + QString(QT_VERSION_STR) + "\n";
43 szQt += "- " + tr("Libraries:") + "\n";
44 #if QT_VERSION > QT_VERSION_CHECK(5, 8, 0)
45 szQt += " - " + tr("Version: ")
46 + QLibraryInfo::version().toString() + "\n";
47 #endif
48 szQt += " - " + tr("Is debug build: ") + QString::number(QLibraryInfo::isDebugBuild()) + "\n";
49 #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
50 szQt += " - " + tr("Is shared build: ") + QString::number(QLibraryInfo::isSharedBuild()) + "\n";
51 #endif
52 szQt += " - " + tr("Path: ") + "\n";
53 szQt += GetLibrariesLocation();
54 szQt += "- " + tr("Locale: ") + QLocale::system().name() + "\n";
55 szQt += "- " + tr("Icon: ") + "\n";
56 szQt += " - " + tr("Theme: ") + QIcon::themeName() + "\n";
57 szQt += " - " + tr("Search paths:") + "\n";
58 foreach(auto iconPath, QIcon::themeSearchPaths())
59 {
60 szQt += " - " + iconPath + "\n";
61 }
62 #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
63 szQt += " - " + tr("Fallback theme: ") + QIcon::fallbackThemeName() + "\n";
64 szQt += " - " + tr("Fallback search paths:") + "\n";
65 foreach(auto iconFallback, QIcon::fallbackSearchPaths())
66 {
67 szQt += " - " + iconFallback + "\n";
68 }
69 #endif
70 szQt += "### " + tr("Dependency libraries:") + "\n";
71 szQt += tr("- OpenSSL:") + "\n";
72 if(QSslSocket::supportsSsl())
73 {
74 #if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 3))
75 szQt += " - " + tr("Build Version: ")
76 + QSslSocket::sslLibraryBuildVersionString() + "\n";
77 #endif
78 szQt += " - " + tr("Installed Version: ")
79 + QSslSocket::sslLibraryVersionString() + "\n";
80 } else {
81 #if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 3))
82 szQt += " - " + tr("Build Version: ")
83 + QSslSocket::sslLibraryBuildVersionString() + "\n";
84 #endif
85 szQt += " - " + tr("Don't install OPENSSL dynamic library. Please install it") + "\n";
86 }
87
88#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
89 szQt += "### " + tr("Standard paths:") + "\n";
90 szQt += "- " + tr("Standard paths:") + "\n";
91 QMetaEnum metaEnum = QMetaEnum::fromType<QStandardPaths::StandardLocation>();
92 int nMaxType = metaEnum.keyCount();
93 for(int i = 0; i < nMaxType; i++)
94 {
95 QStandardPaths::StandardLocation type = (QStandardPaths::StandardLocation)i;
96 QStringList lstPath = QStandardPaths::standardLocations(type);
97 if(!lstPath.isEmpty())
98 {
99 szQt += " - " + QStandardPaths::displayName(type) + "["
100 + QString(metaEnum.valueToKey(i))
101 + "(" + QString::number(type) + ")]: ";
102 if(lstPath.size() == 1)
103 szQt += lstPath.at(0);
104 else
105 foreach (auto p, lstPath) {
106 szQt += QString("\n") + " - " + p;
107 }
108 }
109 szQt += "\n";
110 }
111 szQt += "- " + tr("Writable Location:") + "\n";
112 for(int i = 0; i < nMaxType; i++)
113 {
114 QStandardPaths::StandardLocation type = (QStandardPaths::StandardLocation)i;
115 QString szPath = QStandardPaths::writableLocation(type);
116 if(!szPath.isEmpty()) {
117 szQt += " - " + QStandardPaths::displayName(type) + "["
118 + QString(metaEnum.valueToKey(i))
119 + "(" + QString::number(type) + ")]: ";
120 szQt += szPath;
121 }
122 szQt += "\n";
123 }
124#endif // #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
125
126 szQt += "\n";
127 SetContext(tr("Qt"), szQt);
128
129 QString szOS;
130#if QT_VERSION > QT_VERSION_CHECK(5, 4, 0)
131 szOS = "### " + tr("OS") + "\n";
132 szOS += "- " + tr("OS: ") + QSysInfo::prettyProductName() + "\n";
133 szOS += " - " + tr("Product type: ") + QSysInfo::productType() + "\n";
134 szOS += " - " + tr("Product version: ") + QSysInfo::productVersion() + "\n";
135 szOS += "- " + tr("Kernel type: ") + QSysInfo::kernelType() + "\n";
136 szOS += "- " + tr("Kernel version: ") + QSysInfo::kernelVersion() + "\n";
137 #if QT_VERSION > QT_VERSION_CHECK(5, 11, 0)
138 if(!QSysInfo::bootUniqueId().isEmpty())
139 szOS += "- " + tr("Boot Id: ") + QSysInfo::bootUniqueId() + "\n";
140 #endif
141 szOS += "- " + tr("Build ABI: ") + QSysInfo::buildAbi() + "\n";
142 szOS += "- " + tr("CPU: ") + "\n";
143 int nCPU = QThread::idealThreadCount();
144 szOS += " - " + tr("Number:") + " " + QString::number(nCPU) + "\n";
145 //szOS += " - " + tr("Number:") + QString::number(std::thread::hardware_concurrency()) + "\n";
146 szOS += " - " + tr("Architecture: ")
147 + QSysInfo::currentCpuArchitecture() + "\n";
148 szOS += " - " + tr("Build architecture: ")
149 + QSysInfo::buildCpuArchitecture() + "\n";
150
151 #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
152 szOS += "- " + tr("Theme:") + " ";
153 switch(QApplication::styleHints()->colorScheme()) {
154 case Qt::ColorScheme::Dark:
155 szOS += tr("Dark");
156 break;
157 case Qt::ColorScheme::Light:
158 szOS += tr("Light");
159 break;
160 case Qt::ColorScheme::Unknown:
161 szOS += tr("Unknown");
162 break;
163 }
164 szOS += "\n";
165 #endif // #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
166
167 QString szHost;
168 szHost = "### " + tr("Host") + "\n";
169 #if QT_VERSION > QT_VERSION_CHECK(5, 6, 0)
170 szHost += "- " + tr("Host name: ") + QSysInfo::machineHostName() + "\n";
171 #endif
172 szHost += "- " + tr("Domain name: ") + QHostInfo::localDomainName() + "\n";
173
174#endif // #if QT_VERSION > QT_VERSION_CHECK(5, 4, 0)
175
176 QString szEnv;
177 szEnv += "### " + tr("Environment") + "\n";
178 auto env = QProcessEnvironment::systemEnvironment();
179 foreach (auto key, env.keys()) {
180 szEnv += " - " + key + "=" + env.value(key) + "\n";
181 }
182
183 if(!szHost.isEmpty())
184 SetContext(tr("Host"), szHost + szOS + szEnv);
185
186 qDebug(log) << (szApp + szInfo + szRabbitCommon
187 + szQt + szOS + szHost + szEnv).toStdString().c_str();
188}
189
190CInformation::~CInformation()
191{
192 delete ui;
193}
194
195void CInformation::SetContext(const QString& szTitle, const QString& szContext)
196{
197 if(szTitle.isEmpty() || szContext.isEmpty())
198 {
199 qCritical(log) << "Title or context is empty";
200 return;
201 }
202 QString szHtml;
203 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
204 szHtml = RabbitCommon::CTools::MarkDownToHtml(szContext);
205 #endif
206 if(szHtml.isEmpty())
207 szHtml = szContext;
208 QTextBrowser* pEdit = new QTextBrowser(ui->tabWidget);
209 if(!pEdit) return;
210 pEdit->setOpenExternalLinks(true);
211 pEdit->setOpenLinks(true);
212 pEdit->setReadOnly(true);
213 pEdit->setWordWrapMode(QTextOption::NoWrap);
214 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
215 pEdit->setMarkdown(szContext);
216 #else
217 pEdit->setHtml(szHtml);
218 #endif
219 //把光标移动文档开始处
220 QTextCursor cursor = pEdit->textCursor();
221 cursor.movePosition(QTextCursor::Start);
222 pEdit->setTextCursor(cursor);
223
224 pEdit->show();
225 ui->tabWidget->addTab(pEdit, szTitle);
226}
227
228#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
229QString CInformation::GetLibrariesLocation(QLibraryInfo::LibraryLocation path)
230#else
231QString CInformation::GetLibrariesLocation(QLibraryInfo::LibraryPath path)
232#endif
233{
234 QString szQt;
235 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
236 szQt += QLibraryInfo::location(path);
237 #elif QT_VERSION < QT_VERSION_CHECK(6, 8, 0)
238 szQt += QLibraryInfo::path(path);
239 #else
240 foreach(auto s, QLibraryInfo::paths(path))
241 {
242 szQt += s;
243 }
244 #endif
245 szQt += "\n";
246 return szQt;
247}
248
249QString CInformation::GetLibrariesLocation()
250{
251 QString szQt;
252 szQt += " - PrefixPath: " + GetLibrariesLocation(QLibraryInfo::PrefixPath);
253 szQt += " - DocumentationPath: " + GetLibrariesLocation(QLibraryInfo::DocumentationPath);
254 szQt += " - HeadersPath: " + GetLibrariesLocation(QLibraryInfo::HeadersPath);
255 szQt += " - LibrariesPath: " + GetLibrariesLocation(QLibraryInfo::LibrariesPath);
256 szQt += " - LibraryExecutablesPath: " + GetLibrariesLocation(QLibraryInfo::LibraryExecutablesPath);
257 szQt += " - BinariesPath: " + GetLibrariesLocation(QLibraryInfo::BinariesPath);
258 szQt += " - PluginsPath: " + GetLibrariesLocation(QLibraryInfo::PluginsPath);
259 #if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
260 szQt += " - QmlImportsPath: " + GetLibrariesLocation(QLibraryInfo::QmlImportsPath);
261 #endif
262 szQt += " - ArchDataPath: " + GetLibrariesLocation(QLibraryInfo::ArchDataPath);
263 szQt += " - DataPath: " + GetLibrariesLocation(QLibraryInfo::DataPath);
264 szQt += " - TranslationsPath: " + GetLibrariesLocation(QLibraryInfo::TranslationsPath);
265 szQt += " - ExamplesPath: " + GetLibrariesLocation(QLibraryInfo::ExamplesPath);
266 szQt += " - TestsPath: " + GetLibrariesLocation(QLibraryInfo::TestsPath);
267 szQt += " - SettingsPath: " + GetLibrariesLocation(QLibraryInfo::SettingsPath);
268 return szQt;
269}
static QString Information()
RabbitCommon information.
static QString Version()
RabbitCommon version.