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