RabbitCommon v2.2.6
Loading...
Searching...
No Matches
Information.cpp
1#include "Information.h"
2#include "ui_Information.h"
3#include "RabbitCommonTools.h"
4#include "DlgAbout.h"
5#include "Log/Log.h"
6
7#include <QLibraryInfo>
8#include <QHostInfo>
9#ifdef HAVE_WebEngineWidgets
10#include <QWebEngineView>
11#endif
12#include <QTextEdit>
13#include <QStandardPaths>
14
15static Q_LOGGING_CATEGORY(log, "RabbitCommon.DlgAbout.Information")
16
17CInformation::CInformation(const QString &szApp, const QString &szInfo, QWidget *parent) :
18 QDialog(parent),
19 ui(new Ui::CInformation)
20{
21 ui->setupUi(this);
22 ui->tabWidget->removeTab(0);
23
24 SetContext(tr("Application"), szApp + szInfo);
25
26 QString szRabbitCommon;
27 szRabbitCommon = "\n" + tr("### RabbitCommon") + "\n";
28 szRabbitCommon += "- " + RabbitCommon::CTools::Version() + "\n";
29 szRabbitCommon += RabbitCommon::CTools::Information();
30 SetContext(tr("RabbitCommon"), szRabbitCommon);
31
32 QString szQt;
33 szQt = tr("### Qt") + "\n";
34 szQt += "- " + tr("Qt runtime version: ") + QString(qVersion()) + "\n";
35 szQt += "- " + tr("Qt compile version: ") + QString(QT_VERSION_STR) + "\n";
36#if QT_VERSION > QT_VERSION_CHECK(5, 8, 0)
37 szQt += "- " + tr("Qt library version: ") + QLibraryInfo::version().toString() + "\n";
38#endif
39 szQt += "- " + tr("Locale: ") + QLocale::system().name() + "\n";
40 szQt += "\n";
41 szQt += tr("- OpenSSL:") + "\n";
42 if(QSslSocket::supportsSsl())
43 {
44#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 3))
45 szQt += " - " + tr("Build Version: ") + QSslSocket::sslLibraryBuildVersionString() + "\n";
46#endif
47 szQt += " - " + tr("Installed Version: ") + QSslSocket::sslLibraryVersionString() + "\n";
48 } else {
49#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 3))
50 szQt += " - " + tr("Build Version: ") + QSslSocket::sslLibraryBuildVersionString() + "\n";
51#endif
52 szQt += " - " + tr("Don't install OPENSSL dynamic library. Please install it") + "\n";
53 }
54 szQt += "- " + tr("Standard paths:") + "\n";
55 for(int i = 0; i < 19; i++)
56 {
57 QStandardPaths::StandardLocation type = (QStandardPaths::StandardLocation)i;
58 szQt += " - " + QStandardPaths::displayName(type) + ": ";
59 QStringList lstPath = QStandardPaths::standardLocations(type);
60 if(lstPath.size() == 1)
61 szQt += lstPath.at(0);
62 else
63 foreach (auto p, lstPath) {
64 szQt += QString("\n") + " - " + p;
65 }
66 szQt += "\n";
67 }
68 szQt += "\n";
69 SetContext(tr("Qt"), szQt);
70
71 QString szOS;
72#if QT_VERSION > QT_VERSION_CHECK(5, 4, 0)
73 szOS = tr("### OS") + "\n";
74 szOS += "- " + tr("OS: ") + QSysInfo::prettyProductName() + "\n";
75 szOS += " - " + tr("product type: ") + QSysInfo::productType() + "\n";
76 szOS += " - " + tr("product version: ") + QSysInfo::productVersion() + "\n";
77 szOS += "- " + tr("Kernel type: ") + QSysInfo::kernelType() + "\n";
78 szOS += "- " + tr("Kernel version: ") + QSysInfo::kernelVersion() + "\n";
79#if QT_VERSION > QT_VERSION_CHECK(5, 11, 0)
80 if(!QSysInfo::bootUniqueId().isEmpty())
81 szOS += "- " + tr("Boot Id: ") + QSysInfo::bootUniqueId() + "\n";
82#endif
83 szOS += "- " + tr("Build ABI: ") + QSysInfo::buildAbi() + "\n";
84 szOS += "- " + tr("CPU: ") + "\n";
85 szOS += " - " + tr("Architecture: ") + QSysInfo::currentCpuArchitecture() + "\n";
86 szOS += " - " + tr("Build architecture: ") + QSysInfo::buildCpuArchitecture() + "\n";
87 if(!szOS.isEmpty())
88 SetContext(tr("OS"), szOS);
89
90 QString szHost;
91 szHost = tr("### Host") + "\n";
92#if QT_VERSION > QT_VERSION_CHECK(5, 6, 0)
93 szHost += "- " + tr("Host name: ") + QSysInfo::machineHostName() + "\n";
94#endif
95 szHost += "- " + tr("Domain name: ") + QHostInfo::localDomainName();
96#endif
97 if(!szHost.isEmpty())
98 SetContext(tr("Host"), szHost);
99
100 //qDebug(log) << szRabbitCommon << szOS << szQt << szHost;
101}
102
103CInformation::~CInformation()
104{
105 delete ui;
106}
107
108void CInformation::SetContext(const QString& szTitle, const QString& szContext)
109{
110 if(szTitle.isEmpty() || szContext.isEmpty())
111 {
112 qCritical(log) << "Title or context is empty";
113 return;
114 }
115
116#if (defined(HAVE_CMARK) || defined (HAVE_CMARK_GFM)) && defined(HAVE_WebEngineWidgets)
117 QWebEngineView* pEdit = new QWebEngineView(ui->tabWidget);
118 if(!pEdit) return;
119 pEdit->setHtml(CDlgAbout::MarkDownToHtml(szContext));
120 pEdit->show();
121 ui->tabWidget->addTab(pEdit, szTitle);
122#else
123 QTextEdit* pEdit = new QTextEdit(ui->tabWidget);
124 if(!pEdit) return;
125 pEdit->setReadOnly(true);
126 pEdit->setWordWrapMode(QTextOption::NoWrap);
127 ui->tabWidget->addTab(pEdit, szTitle);
128 pEdit->append(szContext);
129 //把光标移动文档开始处
130 QTextCursor cursor = pEdit->textCursor();
131 cursor.movePosition(QTextCursor::Start);
132 pEdit->setTextCursor(cursor);
133 pEdit->show();
134#endif
135}
static QString Information()
RabbitCommon information.
static QString Version()
RabbitCommon version.