19#include <QStandardPaths>
23#include <QLoggingCategory>
24#include <QApplication>
25#ifdef HAVE_WebEngineWidgets
26#include <QWebEngineView>
30#include "ui_DlgAbout.h"
31#include "RabbitCommonDir.h"
32#include "RabbitCommonTools.h"
34#include "Information.h"
36static Q_LOGGING_CATEGORY(log,
"RabbitCommon.DlgAbout")
42 m_pChangeLog(
nullptr),
47 setAttribute(Qt::WA_QuitOnClose,
true);
49 m_szAppName = qApp->applicationDisplayName();
51 m_szVersion = qApp->applicationVersion();
52#ifdef RabbitCommon_VERSION
53 if(m_szVersion.isEmpty())
55 qWarning(log) <<
"The m_szVersion is not set. Please use qApp->setApplicationVersion() or m_szVersion";
56 m_szVersion = RabbitCommon_VERSION;
60 m_szArch = QSysInfo::buildCpuArchitecture();
62 m_szAuthor = tr(
"KangLin");
63 m_szEmail =
"kl222@126.com";
64 m_szHomePage =
"https://github.com/KangLin/" + qApp->applicationName();
65 m_szCopyrightOwner = tr(
"Kang Lin Studio");
66 m_szCopyrightStartTime =
"2019";
67 m_AppIcon = QImage(
":/icon/RabbitCommon/App");
68 m_CopyrightIcon = QImage(
":/icon/RabbitCommon/CopyRight");
70 QString szLangUage = RabbitCommon::CTools::Instance()->
GetLanguage();
72 if(
"zh_CN" == szLangUage) {
73 m_DonationIcon = QImage(
":/icon/RabbitCommon/Contribute_zh_CN");
74 urls << QUrl(
"https://github.com/KangLin/RabbitCommon/raw/master/Src/Resource/image/Contribute_zh_CN.png")
75 << QUrl(
"https://gitee.com/kl222/RabbitCommon/raw/master/Src/Resource/image/Contribute_zh_CN.png")
76 << QUrl(
"https://gitlab.com/kl222/RabbitCommon/-/raw/master/Src/Resource/image/Contribute_zh_CN.png");
78 m_DonationIcon = QImage(
":/icon/RabbitCommon/Contribute_en");
79 urls << QUrl(
"https://github.com/KangLin/RabbitCommon/raw/master/Src/Resource/image/Contribute_en.png")
80 << QUrl(
"https://gitee.com/kl222/RabbitCommon/raw/master/Src/Resource/image/Contribute_en.png")
81 << QUrl(
"https://gitlab.com/kl222/RabbitCommon/-/raw/master/Src/Resource/image/Contribute_en.png");
83 m_Download = QSharedPointer<RabbitCommon::CDownload>(
85 bool check = connect(m_Download.data(), SIGNAL(sigFinished(
const QString)),
86 this, SLOT(slotDownloadFileFinished(
const QString)));
88 check = connect(m_Download.data(), SIGNAL(sigError(
int,
const QString)),
89 this, SLOT(slotDownloadError(
int,
const QString)));
91 m_Download->Start(urls);
93 m_pLicense =
new QTextBrowser(ui->tabWidget);
94 m_pChangeLog =
new QTextBrowser(ui->tabWidget);
95 m_pThanks =
new QTextBrowser(ui->tabWidget);
97 AppendFile(m_pChangeLog,
"ChangeLog", tr(
"Change log"));
98 AppendFile(m_pLicense,
"License", tr(
"License"));
99 AppendFile(m_pThanks,
"Authors", tr(
"Thanks"));
101#if defined (Q_OS_ANDROID)
102 ui->lbDonation->installEventFilter(
this);
104 ui->lbDonation->setContextMenuPolicy(Qt::CustomContextMenu);
105 check = connect(ui->lbDonation, SIGNAL(customContextMenuRequested(
const QPoint &)),
106 this, SLOT(slotDonation(
const QPoint &)));
112void CDlgAbout::showEvent(QShowEvent *event)
116 setWindowIcon(QIcon(QPixmap::fromImage(m_AppIcon)));
117 ui->lblLogo->setPixmap(QPixmap::fromImage(m_AppIcon));
118 ui->lbCopyrightIcon->setPixmap(QPixmap::fromImage(m_CopyrightIcon));
119 ui->lbDonation->setPixmap(QPixmap::fromImage(m_DonationIcon));
120 ui->lblName->setText(m_szAppName);
121 ui->lbVersion->setText(Version());
122 ui->lbVersion->setOpenExternalLinks(
true);
123 ui->lbAuthor->setText(tr(
"Author: ") + m_szAuthor
124 + tr(
" Email: ") +
"<a href=\"" + m_szEmail +
"\">"
125 + m_szEmail +
"</a>");
126 ui->lbAuthor->setOpenExternalLinks(
true);
127 ui->lbHome->setOpenExternalLinks(
true);
128 ui->lbHome->setText(tr(
"Home page: ") +
"<a href=\"" + m_szHomePage +
"\">"
129 + m_szHomePage +
"</a>");
130 if(m_szCopyright.isEmpty())
132 if(m_szCopyrightTime.isEmpty())
133 m_szCopyrightTime = tr(
"%1 - %2").arg(m_szCopyrightStartTime,
134 QString::number(QDate::currentDate().year()));
135 m_szCopyright = tr(
"Copyright (C)") +
" " + m_szCopyrightTime +
" " + m_szCopyrightOwner;
137 ui->lbCopyright->setText(m_szCopyright);
142CDlgAbout::~CDlgAbout()
147int CDlgAbout::AppendFile(QTextBrowser *pEdit,
const QString &szFile,
const QString &szTitle)
150 QString szFileLocation;
151 if(!pEdit)
return -1;
153 QApplication::applicationName(),
true)
155 + szFile +
"_" + RabbitCommon::CTools::Instance()->
GetLanguage() +
".md";
156 if(!d.exists(szFileLocation))
158 QApplication::applicationName(),
true)
162 if(!d.exists(szFileLocation))
163 szFileLocation = RabbitCommon::CDir::Instance()->GetDirApplicationInstallRoot() + QDir::separator()
164 + szFile +
"_" + RabbitCommon::CTools::Instance()->
GetLanguage() +
".md";
165 if(!d.exists(szFileLocation))
166 szFileLocation = RabbitCommon::CDir::Instance()->GetDirApplicationInstallRoot()
167 + QDir::separator() + szFile +
".md";
169 QFile readme(szFileLocation);
170 if(readme.open(QFile::ReadOnly))
173 text = readme.readAll();
175 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
176 szHtml = RabbitCommon::CTools::MarkDownToHtml(text);
181 pEdit->setOpenExternalLinks(
true);
182 pEdit->setOpenLinks(
true);
183 pEdit->setReadOnly(
true);
184 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
185 pEdit->setMarkdown(text);
187 pEdit->setHtml(szHtml);
190 QTextCursor cursor = pEdit->textCursor();
191 cursor.movePosition(QTextCursor::Start);
192 pEdit->setTextCursor(cursor);
197 ui->tabWidget->addTab(pEdit, szTitle);
202void CDlgAbout::on_pbOK_clicked()
207void CDlgAbout::slotDonation(
const QPoint &pos)
211 m.addAction(QIcon::fromTheme(
"document-save"), tr(
"Save"),
212 this, SLOT(slotSaveDonation()));
213 m.exec(QCursor::pos());
216void CDlgAbout::slotSaveDonation()
218 QString szDir = RabbitCommon::CDir::Instance()->GetDirUserImage()
219 + QDir::separator() +
"donation.png";
220 QString szFile = QFileDialog::getSaveFileName(
this,
221 tr(
"Save donation picture"),
223 tr(
"Images (*.png *.xpm *.jpg)"));
224 QFileInfo fi(szFile);
225 if(fi.suffix().isEmpty())
227 if(!szFile.isEmpty())
228 m_DonationIcon.save(szFile);
231#if defined (Q_OS_ANDROID)
232bool CDlgAbout::eventFilter(QObject *watched, QEvent *event)
234 qDebug() <<
event->type();
235 if(event->type() == QEvent::MouseButtonRelease)
237 return QDialog::eventFilter(watched, event);
241int CDlgAbout::SetDonationIcon(
const QImage &img)
244 m_DonationIcon = img;
248QString CDlgAbout::BuildTime()
250 if(m_szBuildTime.isEmpty())
251 return QString(
"%1/%2").arg(__DATE__, __TIME__);
252 return m_szBuildTime;
255QString CDlgAbout::Version()
258 if(m_szVersionRevision.isEmpty())
260 szVersion = tr(
"Version: ") +
m_szVersion +
" " + tr(
"Arch: ") + m_szArch;
262 if(m_szVersionRevisionUrl.isEmpty())
264 m_szVersionRevisionUrl =
265 m_szHomePage +
"/tree/" + m_szVersionRevision;
267 szVersion = tr(
"Version: ") +
m_szVersion + tr(
" (From revision: ")
268#if (defined(HAVE_CMARK) || defined(HAVE_CMARK_GFM))
269 +
"<a href=\"" + m_szVersionRevisionUrl +
"\">"
270 + m_szVersionRevision +
"</a>"
272 + m_szVersionRevision
274 +
") " + tr(
"Arch: ") + m_szArch;
279void CDlgAbout::slotDownloadError(
int nErr,
const QString szError)
282 szMsg = tr(
"Failed:") + tr(
"Download file is Failed.");
283 if(!szError.isEmpty())
284 szMsg +=
"(" + szError +
")";
285 qCritical(log) << szMsg << nErr;
288void CDlgAbout::slotDownloadFileFinished(
const QString szFile)
290 qDebug(log) <<
"slotDownloadFileFinished:" << szFile;
291 m_DonationIcon.load(szFile);
292 ui->lbDonation->setPixmap(QPixmap::fromImage(m_DonationIcon));
295void CDlgAbout::on_pbDetails_clicked()
299 szApp = tr(
"### ") + QApplication::applicationDisplayName() +
"\n";
300 szApp +=
"- " + Version() +
"\n";
301 szApp +=
"- " + tr(
"Build Date/Time: ") + BuildTime() +
"\n";
302 szApp +=
"- " + tr(
"File Path: ") + QApplication::applicationFilePath() +
"\n";
303 szApp +=
"- " + tr(
"Arguments: ") + qApp->arguments().join(
' ') +
"\n";
305 QCursor cursor = this->cursor();
306 setCursor(Qt::WaitCursor);
308#if defined (Q_OS_ANDROID)
309 info.showMaximized();
311 RC_SHOW_WINDOW(&info);
QString m_szVersion
The application version, it is different RabbitCommon::CTools::Version()
QString GetDirDocument(QString szProjectName=QString(), bool bReadOnly=false)
GetDirDocument.
Download the same file from multiple URLs.