mirror of https://github.com/procxx/kepka.git
Refactored FallbackFontConfig() to use native Qt methods.
Signed-off-by: Vitaly Zaitsev <vitaly@easycoding.org>
This commit is contained in:
parent
00969df06f
commit
31e3a426a6
|
@ -26,6 +26,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QVersionNumber>
|
||||||
|
|
||||||
#include <qpa/qplatformnativeinterface.h>
|
#include <qpa/qplatformnativeinterface.h>
|
||||||
|
|
||||||
|
@ -46,8 +48,6 @@ bool RunShellCommand(const QByteArray &command) {
|
||||||
|
|
||||||
void FallbackFontConfig() {
|
void FallbackFontConfig() {
|
||||||
#ifndef TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION
|
#ifndef TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION
|
||||||
const auto path = cWorkingDir() + "tdata/fc-version-check.txt";
|
|
||||||
const auto escaped = EscapeShell(QFile::encodeName(path));
|
|
||||||
const auto custom = cWorkingDir() + "tdata/fc-custom-1.conf";
|
const auto custom = cWorkingDir() + "tdata/fc-custom-1.conf";
|
||||||
const auto finish = gsl::finally([&] {
|
const auto finish = gsl::finally([&] {
|
||||||
if (QFile(custom).exists()) {
|
if (QFile(custom).exists()) {
|
||||||
|
@ -56,37 +56,31 @@ void FallbackFontConfig() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto command = "fc-list --version > " + escaped + " 2> " + escaped;
|
QProcess process;
|
||||||
if (!RunShellCommand(command)) {
|
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||||
LOG(("App Error: Could not run '%1'").arg(QString::fromLatin1(command)));
|
process.start("fc-list", QStringList() << "--version");
|
||||||
return;
|
process.waitForFinished();
|
||||||
} else if (!QFile::exists(path)) {
|
if (process.exitCode() > 0) {
|
||||||
LOG(("App Error: Could not find fc-list --version output from: ") + path);
|
LOG(("App Error: Could not start fc-list. Process exited with code: %1.").arg(process.exitCode()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QFile output(path);
|
|
||||||
if (!output.open(QIODevice::ReadOnly)) {
|
QString result(process.readAllStandardOutput());
|
||||||
LOG(("App Error: Could not open fc-list --version output from: ") + path);
|
DEBUG_LOG(("Fontconfig version string: ") + result);
|
||||||
|
|
||||||
|
QVersionNumber version = QVersionNumber::fromString(result.split("version ").last());
|
||||||
|
if (version.isNull()) {
|
||||||
|
LOG(("App Error: Could not get version from fc-list output."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto result = QString::fromLatin1(output.readAll());
|
|
||||||
LOG(("Fontconfig version string: ") + result);
|
LOG(("Fontconfig version: %1.").arg(version.toString()));
|
||||||
const auto regex = QRegularExpression(
|
if (version < QVersionNumber::fromString("2.13")) {
|
||||||
"version\\s+(\\d+)\\.(\\d+)",
|
|
||||||
QRegularExpression::CaseInsensitiveOption);
|
|
||||||
const auto match = regex.match(result);
|
|
||||||
if (!match.hasMatch()) {
|
|
||||||
LOG(("App Error: Could not read fc-list --version output from: ") + path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto major = match.capturedRef(1).toInt();
|
|
||||||
const auto minor = match.capturedRef(2).toInt();
|
|
||||||
LOG(("Fontconfig version: %1.%2").arg(major).arg(minor));
|
|
||||||
if (major <= 2 && (major != 2 || minor <= 12)) {
|
|
||||||
if (qgetenv("TDESKTOP_FORCE_CUSTOM_FONTCONFIG").isEmpty()) {
|
if (qgetenv("TDESKTOP_FORCE_CUSTOM_FONTCONFIG").isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile(":/fc/fc-custom.conf").copy(custom);
|
QFile(":/fc/fc-custom.conf").copy(custom);
|
||||||
#endif // TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION
|
#endif // TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue