Debian Codegraph @

src/librssguard/gui/dialogs/formabout.cpp

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.
2
3 #include "gui/dialogs/formabout.h"
4
5 #include "definitions/definitions.h"
6 #include "gui/guiutilities.h"
7 #include "miscellaneous/application.h"
8 #include "miscellaneous/iconfactory.h"
9 #include "miscellaneous/settings.h"
10 #include "miscellaneous/settingsproperties.h"
11 #include "miscellaneous/textfactory.h"
12 #include "network-web/webfactory.h"
13
14 #include <QClipboard>
15 #include <QFile>
16 #include <QJsonArray>
17 #include <QJsonObject>
18 #include <QPlainTextEdit>
19 #include <QTextStream>
20
21 #if defined(NO_LITE)
22 #include <QWebEngineProfile>
23 #endif
24
25 FormAbout::FormAbout(bool go_to_changelog, QWidget* parent) : QDialog(parent) {
26 m_ui.setupUi(this);
27 m_ui.m_lblIcon->setPixmap(QPixmap(APP_ICON_PATH));
28 m_ui.m_btnCopyInfo->setIcon(qApp->icons()->fromTheme(QSL("edit-copy")));
29 GuiUtilities::applyDialogProperties(*this,
30 qApp->icons()->fromTheme(QSL("help-about")),
31 tr("About %1").arg(QSL(APP_NAME)));
32
33 connect(m_ui.m_btnCopyInfo, &QPushButton::clicked, this, &FormAbout::copyInfoToClipboard);
34
35 loadLicenseAndInformation();
36 loadSettingsAndPaths();
37
38 if (go_to_changelog) {
39 m_ui.m_tabAbout->setCurrentWidget(m_ui.m_tabChangelog);
40 }
41 }
42
43 FormAbout::~FormAbout() {}
44
45 void FormAbout::copyInfoToClipboard() {
46 auto* clip = QGuiApplication::clipboard();
47
48 if (clip != nullptr) {
49 clip->setText(m_ui.m_lblDesc->text());
50 }
51 else {
52 qApp->showGuiMessage(Notification::Event::GeneralEvent,
53 GuiMessage(tr("Cannot copy"),
54 tr("Cannot copy info to clipboard."),
55 QSystemTrayIcon::MessageIcon::Critical),
56 GuiMessageDestination(true, true));
57 }
58 }
59
60 void FormAbout::displayLicense() {
61 m_ui.m_tbLicenses->setPlainText(m_ui.m_cbLicenses->currentData().toString());
62 }
63
64 void FormAbout::loadSettingsAndPaths() {
65 QString settings_type;
66
67 if (qApp->settings()->type() == SettingsProperties::SettingsType::Portable) {
68 settings_type = tr("FULLY portable");
69 }
70 else if (qApp->settings()->type() == SettingsProperties::SettingsType::Custom) {
71 settings_type = tr("CUSTOM");
72 }
73 else {
74 settings_type = tr("NOT portable");
75 }
76
77 const QString user_data_path = QDir::toNativeSeparators(qApp->userDataFolder());
78
79 m_ui.m_tbResources->setPlainText(tr("User data folder (\"%5\") -> \"%1\"\n\n"
80 "Settings file (%3) -> \"%2\"\n"
81 "Skins base folder -> \"%4\"\n"
82 "Icon themes base folder -> \"%8\"\n"
83 "Node.js package folder -> \"%6\"\n"
84 "QtWebEngine cache folder -> \"%7\"")
85 .arg(user_data_path,
86 QDir::toNativeSeparators(qApp->settings()->fileName())
87 .replace(user_data_path, QSL(USER_DATA_PLACEHOLDER)),
88 settings_type,
89 QDir::toNativeSeparators(qApp->skins()->customSkinBaseFolder())
90 .replace(user_data_path, QSL(USER_DATA_PLACEHOLDER)),
91 QSL(USER_DATA_PLACEHOLDER),
92 QDir::toNativeSeparators(qApp->nodejs()->packageFolder())
93 .replace(user_data_path, QSL(USER_DATA_PLACEHOLDER)),
94 #if defined(NO_LITE)
95 QDir::toNativeSeparators(qApp->web()->engineProfile()->cachePath())
96 .replace(user_data_path, QSL(USER_DATA_PLACEHOLDER)),
97 #else
98 QSL("-"),
99 #endif
100 QSL(USER_DATA_PLACEHOLDER) + QDir::separator() +
101 QSL(APP_LOCAL_ICON_THEME_FOLDER)));
102 }
103
104 void FormAbout::loadLicenseAndInformation() {
105 connect(m_ui.m_cbLicenses, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FormAbout::displayLicense);
106
107 QJsonDocument licenses_index = QJsonDocument::fromJson(IOFactory::readFile(APP_INFO_PATH + QSL("/licenses.json")));
108
109 for (const QJsonValue& license : licenses_index.array()) {
110 QJsonObject license_obj = license.toObject();
111 QString license_text = license_obj.value(QSL("text")).toString();
112
113 if (license_text.isEmpty()) {
114 license_text =
115 QString::fromUtf8(IOFactory::readFile(APP_INFO_PATH + QSL("/") + license_obj[QSL("file")].toString()));
116 }
117
118 QString license_title =
119 license_obj[QSL("title")].toString() + QSL(": ") + license_obj[QSL("components")].toString();
120
121 m_ui.m_cbLicenses->addItem(license_title, license_text);
122 }
123
124 try {
125 #if QT_VERSION >= 0x050E00 // Qt >= 5.14.0
126 m_ui.m_txtChangelog->setMarkdown(IOFactory::readFile(APP_INFO_PATH + QL1S("/CHANGELOG")));
127 #else
128 m_ui.m_txtChangelog->setText(IOFactory::readFile(APP_INFO_PATH + QL1S("/CHANGELOG")));
129 #endif
130
131 m_ui.m_txtChangelog->document()->setIndentWidth(16.0);
132 }
133 catch (...) {
134 m_ui.m_txtChangelog->setText(tr("Changelog not found."));
135 }
136
137 // Set other informative texts.
138 m_ui.m_lblDesc->setTextFormat(Qt::TextFormat::RichText);
139 m_ui.m_lblDesc->setText(tr("<h4>%8</h4>"
140 "<b>Version:</b> %1 (built on %2/%3)<br/>"
141 "<b>Revision:</b> %4<br/>"
142 "<b>Build date:</b> %5<br/>"
143 "<b>OS:</b> %9<br/>"
144 "<b>Qt:</b> %6 (compiled against %7)")
145 .arg(qApp->applicationVersion(),
146 QSL(APP_SYSTEM_NAME),
147 QSL(APP_SYSTEM_VERSION),
148 QSL(APP_REVISION),
149 qApp->localization()
150 ->loadedLocale()
151 .toString(TextFactory::parseDateTime(QSL("%1 %2").arg(__DATE__, __TIME__)),
152 QLocale::FormatType::ShortFormat),
153 qVersion(),
154 QSL(QT_VERSION_STR),
155 QSL(APP_NAME),
156 QSysInfo::prettyProductName()));
157 m_ui.m_txtInfo->setText(tr("<body>%5 is a (very) tiny feed reader."
158 "<br><br>This software is distributed under the terms of GNU General "
159 "Public License, version 3."
160 "<br><br>Contacts:"
161 "<ul><li><a href=\"mailto://%1\">%1</a> ~e-mail</li>"
162 "<li><a href=\"%2\">%2</a> ~website</li></ul>"
163 "You can obtain source code for %5 from its website."
164 "<br><br><br>Copyright (C) 2011-%3 %4</body>")
165 .arg(QSL(APP_EMAIL),
166 QSL(APP_URL),
167 QString::number(QDateTime::currentDateTime().date().year()),
168 QSL(APP_AUTHOR),
169 QSL(APP_NAME)));
170 }