2020-02-21 00:45:53 +07:00
|
|
|
#include "settings.h"
|
2020-03-20 02:35:42 +07:00
|
|
|
#include "runatsystemstart.h"
|
2020-02-21 00:45:53 +07:00
|
|
|
|
2020-03-22 15:39:59 +07:00
|
|
|
#include <QApplication>
|
2020-04-15 23:57:08 +07:00
|
|
|
#include <QDir>
|
2020-03-22 15:39:59 +07:00
|
|
|
#include <QFont>
|
2020-02-21 00:45:53 +07:00
|
|
|
#include <QSettings>
|
2020-03-15 18:25:27 +07:00
|
|
|
#include <QStandardPaths>
|
2020-02-21 00:45:53 +07:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2021-01-10 20:13:45 +07:00
|
|
|
const QString iniFileName()
|
|
|
|
{
|
|
|
|
return QApplication::applicationDirPath() + "/" + "settings.ini";
|
|
|
|
}
|
2020-03-15 19:30:24 +07:00
|
|
|
|
2020-02-21 00:45:53 +07:00
|
|
|
const QString qs_guiGroup = "GUI";
|
|
|
|
const QString qs_captureHotkey = "captureHotkey";
|
|
|
|
const QString qs_repeatCaptureHotkey = "repeatCaptureHotkey";
|
|
|
|
const QString qs_repeatHotkey = "repeatHotkey";
|
|
|
|
const QString qs_clipboardHotkey = "clipboardHotkey";
|
2020-03-31 00:03:00 +07:00
|
|
|
const QString qs_captureLockedHotkey = "captureLockedHotkey";
|
2020-02-21 00:45:53 +07:00
|
|
|
const QString qs_resultShowType = "resultShowType";
|
|
|
|
const QString qs_proxyType = "proxyType";
|
|
|
|
const QString qs_proxyHostName = "proxyHostName";
|
|
|
|
const QString qs_proxyPort = "proxyPort";
|
|
|
|
const QString qs_proxyUser = "proxyUser";
|
|
|
|
const QString qs_proxyPassword = "proxyPassword";
|
|
|
|
const QString qs_proxySavePassword = "proxySavePassword";
|
|
|
|
const QString qs_autoUpdateType = "autoUpdateType";
|
|
|
|
const QString qs_lastUpdateCheck = "lastUpdateCheck";
|
2020-03-09 15:29:51 +07:00
|
|
|
const QString qs_showMessageOnStart = "showMessageOnStart";
|
2020-02-21 00:45:53 +07:00
|
|
|
|
|
|
|
const QString qs_recogntionGroup = "Recognition";
|
|
|
|
const QString qs_ocrLanguage = "language";
|
2020-07-18 16:26:59 +07:00
|
|
|
const QString qs_tesseractVersion = "tesseractVersion";
|
2020-03-08 17:49:15 +07:00
|
|
|
|
|
|
|
const QString qs_correctionGroup = "Correction";
|
|
|
|
const QString qs_userSubstitutions = "userSubstitutions";
|
|
|
|
const QString qs_useUserSubstitutions = "useUserSubstitutions";
|
2020-04-09 03:17:23 +07:00
|
|
|
const QString qs_useHunspell = "useHunspell";
|
2020-02-21 00:45:53 +07:00
|
|
|
|
|
|
|
const QString qs_translationGroup = "Translation";
|
|
|
|
const QString qs_doTranslation = "doTranslation";
|
|
|
|
const QString qs_ignoreSslErrors = "ignoreSslErrors";
|
|
|
|
const QString qs_translationLanguage = "translation_language";
|
|
|
|
const QString qs_translationTimeout = "translation_timeout";
|
|
|
|
const QString qs_translators = "translators";
|
|
|
|
|
2020-03-20 01:47:46 +07:00
|
|
|
const QString qs_representationGroup = "Representation";
|
|
|
|
const QString qs_fontFamily = "fontFamily";
|
|
|
|
const QString qs_fontSize = "fontSize";
|
2020-03-29 15:55:03 +07:00
|
|
|
const QString qs_fontColor = "fontColor";
|
|
|
|
const QString qs_backgroundColor = "backgroundColor";
|
2020-03-20 01:55:32 +07:00
|
|
|
const QString qs_showRecognized = "showRecognized";
|
|
|
|
const QString qs_showCaptured = "showCaptured";
|
2020-03-20 01:47:46 +07:00
|
|
|
|
2020-03-08 17:49:15 +07:00
|
|
|
QString shuffle(const QString& source)
|
2020-02-21 00:45:53 +07:00
|
|
|
{
|
|
|
|
if (source.isEmpty()) {
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
char encKeys[] = {14, 26, 99, 43};
|
|
|
|
std::string result = source.toStdString();
|
|
|
|
for (size_t i = 0, end = result.size(); i < end; ++i) {
|
|
|
|
result[i] = result[i] ^ encKeys[i % sizeof(encKeys)];
|
|
|
|
}
|
|
|
|
return QString::fromUtf8(result.data());
|
|
|
|
}
|
|
|
|
|
2020-03-08 17:49:15 +07:00
|
|
|
QStringList packSubstitutions(const Substitutions& source)
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
for (const auto& i : source) {
|
|
|
|
result << i.first << i.second.source << i.second.target;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Substitutions unpackSubstitutions(const QStringList& raw)
|
|
|
|
{
|
|
|
|
const auto count = raw.size();
|
|
|
|
if (count < 3)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
Substitutions result;
|
|
|
|
for (auto i = 0, end = raw.size(); i < end; i += 3) {
|
|
|
|
result.emplace(raw[i], Substitution{raw[i + 1], raw[i + 2]});
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-03-18 00:43:32 +07:00
|
|
|
Substitutions loadLegacySubstitutions()
|
|
|
|
{
|
|
|
|
Substitutions result;
|
|
|
|
|
|
|
|
QFile f("st_subs.csv");
|
|
|
|
if (!f.open(QFile::ReadOnly))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
const auto data = f.readAll();
|
|
|
|
|
2021-04-16 01:08:16 +07:00
|
|
|
const auto lines = QString::fromUtf8(data).split('\n', Qt::SkipEmptyParts);
|
2020-03-18 00:43:32 +07:00
|
|
|
for (const auto& line : lines) {
|
|
|
|
const auto parts = line.mid(1, line.size() - 2).split("\",\""); // remove "
|
|
|
|
if (parts.size() < 3)
|
|
|
|
continue;
|
|
|
|
result.emplace(parts[0], Substitution{parts[1], parts[2]});
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-03-09 16:20:36 +07:00
|
|
|
void cleanupOutdated(QSettings& settings)
|
|
|
|
{
|
|
|
|
if (!settings.contains(qs_recogntionGroup + "/image_scale"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
settings.beginGroup(qs_guiGroup);
|
|
|
|
settings.remove("geometry");
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
settings.beginGroup(qs_recogntionGroup);
|
|
|
|
settings.remove("image_scale");
|
2020-03-15 18:25:27 +07:00
|
|
|
settings.remove("tessdata_dir");
|
2020-03-09 16:20:36 +07:00
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
settings.beginGroup(qs_translationGroup);
|
|
|
|
settings.remove("source_language");
|
|
|
|
settings.remove("forceRotateTranslators");
|
2020-04-04 00:47:49 +07:00
|
|
|
settings.remove("translation_debug");
|
2020-03-09 16:20:36 +07:00
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
2021-11-11 17:27:18 +07:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <intrin.h>
|
|
|
|
#endif
|
|
|
|
#ifdef __GNUC__
|
|
|
|
void __cpuid(int* cpuinfo, int info)
|
|
|
|
{
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"xchg %%ebx, %%edi;"
|
|
|
|
"cpuid;"
|
|
|
|
"xchg %%ebx, %%edi;"
|
|
|
|
: "=a"(cpuinfo[0]), "=D"(cpuinfo[1]), "=c"(cpuinfo[2]), "=d"(cpuinfo[3])
|
|
|
|
: "0"(info));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long _xgetbv(unsigned int index)
|
|
|
|
{
|
|
|
|
unsigned int eax, edx;
|
|
|
|
__asm__ __volatile__("xgetbv;" : "=a"(eax), "=d"(edx) : "c"(index));
|
|
|
|
return ((unsigned long long)edx << 32) | eax;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool checkOptimizedTesseractSupport()
|
|
|
|
{
|
|
|
|
bool sse4_1Supportted = false;
|
|
|
|
bool sse4_2Supportted = false;
|
|
|
|
bool avxSupportted = false;
|
|
|
|
|
|
|
|
int cpuinfo[4];
|
|
|
|
__cpuid(cpuinfo, 1);
|
|
|
|
|
|
|
|
sse4_1Supportted = cpuinfo[2] & (1 << 19) || false;
|
|
|
|
sse4_2Supportted = cpuinfo[2] & (1 << 20) || false;
|
|
|
|
|
|
|
|
avxSupportted = cpuinfo[2] & (1 << 28) || false;
|
|
|
|
bool osxsaveSupported = cpuinfo[2] & (1 << 27) || false;
|
|
|
|
if (osxsaveSupported && avxSupportted) {
|
|
|
|
// _XCR_XFEATURE_ENABLED_MASK = 0
|
|
|
|
unsigned long long xcrFeatureMask = _xgetbv(0);
|
|
|
|
avxSupportted = (xcrFeatureMask & 0x6) == 0x6;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sse4_1Supportted && sse4_2Supportted && avxSupportted;
|
|
|
|
}
|
|
|
|
|
2020-02-21 00:45:53 +07:00
|
|
|
} // namespace
|
|
|
|
|
2020-03-15 19:20:28 +07:00
|
|
|
void Settings::save() const
|
2020-03-15 18:25:27 +07:00
|
|
|
{
|
2020-03-15 19:30:24 +07:00
|
|
|
std::unique_ptr<QSettings> ptr;
|
2021-01-10 20:13:45 +07:00
|
|
|
const auto iniName = iniFileName();
|
2020-03-15 19:30:24 +07:00
|
|
|
if (isPortable_) {
|
2021-01-10 20:13:45 +07:00
|
|
|
ptr = std::make_unique<QSettings>(iniName, QSettings::IniFormat);
|
2020-03-15 19:30:24 +07:00
|
|
|
} else {
|
|
|
|
ptr = std::make_unique<QSettings>();
|
2021-01-10 20:13:45 +07:00
|
|
|
QFile::remove(iniName);
|
2020-03-15 19:30:24 +07:00
|
|
|
}
|
|
|
|
auto& settings = *ptr;
|
2020-02-21 00:45:53 +07:00
|
|
|
|
|
|
|
settings.beginGroup(qs_guiGroup);
|
|
|
|
|
|
|
|
settings.setValue(qs_captureHotkey, captureHotkey);
|
|
|
|
settings.setValue(qs_repeatCaptureHotkey, repeatCaptureHotkey);
|
|
|
|
settings.setValue(qs_repeatHotkey, showLastHotkey);
|
|
|
|
settings.setValue(qs_clipboardHotkey, clipboardHotkey);
|
2020-03-31 00:03:00 +07:00
|
|
|
settings.setValue(qs_captureLockedHotkey, captureLockedHotkey);
|
2020-02-21 00:45:53 +07:00
|
|
|
|
2020-03-09 15:29:51 +07:00
|
|
|
settings.setValue(qs_showMessageOnStart, showMessageOnStart);
|
|
|
|
|
2020-02-21 00:45:53 +07:00
|
|
|
settings.setValue(qs_resultShowType, int(resultShowType));
|
|
|
|
|
2020-03-07 00:53:53 +07:00
|
|
|
settings.setValue(qs_proxyType, int(proxyType));
|
2020-02-21 00:45:53 +07:00
|
|
|
settings.setValue(qs_proxyHostName, proxyHostName);
|
|
|
|
settings.setValue(qs_proxyPort, proxyPort);
|
|
|
|
settings.setValue(qs_proxyUser, proxyUser);
|
|
|
|
settings.setValue(qs_proxySavePassword, proxySavePassword);
|
|
|
|
if (proxySavePassword) {
|
|
|
|
settings.setValue(qs_proxyPassword, shuffle(proxyPassword));
|
|
|
|
} else {
|
|
|
|
settings.remove(qs_proxyPassword);
|
|
|
|
}
|
|
|
|
|
2020-03-18 01:32:36 +07:00
|
|
|
settings.setValue(qs_autoUpdateType, autoUpdateIntervalDays);
|
|
|
|
settings.setValue(qs_lastUpdateCheck, lastUpdateCheck);
|
2020-02-21 00:45:53 +07:00
|
|
|
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
settings.beginGroup(qs_recogntionGroup);
|
|
|
|
settings.setValue(qs_ocrLanguage, sourceLanguage);
|
2020-07-18 16:26:59 +07:00
|
|
|
settings.setValue(qs_tesseractVersion, int(tesseractVersion));
|
2020-03-08 17:49:15 +07:00
|
|
|
settings.endGroup();
|
2020-02-21 00:45:53 +07:00
|
|
|
|
2020-03-08 17:49:15 +07:00
|
|
|
settings.beginGroup(qs_correctionGroup);
|
2020-04-09 03:17:23 +07:00
|
|
|
settings.setValue(qs_useHunspell, useHunspell);
|
2020-03-08 17:49:15 +07:00
|
|
|
settings.setValue(qs_useUserSubstitutions, useUserSubstitutions);
|
|
|
|
settings.setValue(qs_userSubstitutions, packSubstitutions(userSubstitutions));
|
2020-02-21 00:45:53 +07:00
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
settings.beginGroup(qs_translationGroup);
|
|
|
|
|
|
|
|
settings.setValue(qs_doTranslation, doTranslation);
|
|
|
|
settings.setValue(qs_ignoreSslErrors, ignoreSslErrors);
|
|
|
|
settings.setValue(qs_translationLanguage, targetLanguage);
|
|
|
|
settings.setValue(qs_translationTimeout, int(translationTimeout.count()));
|
|
|
|
settings.setValue(qs_translators, translators);
|
|
|
|
|
|
|
|
settings.endGroup();
|
2020-03-09 16:20:36 +07:00
|
|
|
|
2020-03-20 01:47:46 +07:00
|
|
|
settings.beginGroup(qs_representationGroup);
|
|
|
|
|
|
|
|
settings.setValue(qs_fontFamily, fontFamily);
|
|
|
|
settings.setValue(qs_fontSize, fontSize);
|
2020-03-29 15:55:03 +07:00
|
|
|
settings.setValue(qs_fontColor, fontColor.name());
|
|
|
|
settings.setValue(qs_backgroundColor, backgroundColor.name());
|
2020-03-20 01:55:32 +07:00
|
|
|
settings.setValue(qs_showRecognized, showRecognized);
|
|
|
|
settings.setValue(qs_showCaptured, showCaptured);
|
2020-03-20 01:47:46 +07:00
|
|
|
|
|
|
|
settings.endGroup();
|
|
|
|
|
2020-03-20 02:35:42 +07:00
|
|
|
if (service::RunAtSystemStart::isAvailable()) {
|
|
|
|
if (runAtSystemStart != service::RunAtSystemStart::isEnabled())
|
|
|
|
service::RunAtSystemStart::setEnabled(runAtSystemStart);
|
|
|
|
}
|
|
|
|
|
2020-03-09 16:20:36 +07:00
|
|
|
cleanupOutdated(settings);
|
2020-02-21 00:45:53 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::load()
|
|
|
|
{
|
2020-03-15 19:30:24 +07:00
|
|
|
std::unique_ptr<QSettings> ptr;
|
2021-01-10 20:13:45 +07:00
|
|
|
const auto iniName = iniFileName();
|
|
|
|
if (QFile::exists(iniName)) {
|
|
|
|
ptr = std::make_unique<QSettings>(iniName, QSettings::IniFormat);
|
2020-03-15 19:30:24 +07:00
|
|
|
setPortable(true);
|
|
|
|
} else {
|
|
|
|
ptr = std::make_unique<QSettings>();
|
|
|
|
setPortable(false);
|
|
|
|
}
|
|
|
|
auto& settings = *ptr;
|
2020-02-21 00:45:53 +07:00
|
|
|
|
|
|
|
settings.beginGroup(qs_guiGroup);
|
|
|
|
|
|
|
|
captureHotkey = settings.value(qs_captureHotkey, captureHotkey).toString();
|
|
|
|
repeatCaptureHotkey =
|
|
|
|
settings.value(qs_repeatCaptureHotkey, repeatCaptureHotkey).toString();
|
|
|
|
showLastHotkey = settings.value(qs_repeatHotkey, showLastHotkey).toString();
|
|
|
|
clipboardHotkey =
|
|
|
|
settings.value(qs_clipboardHotkey, clipboardHotkey).toString();
|
2020-03-31 00:03:00 +07:00
|
|
|
captureLockedHotkey =
|
|
|
|
settings.value(qs_captureLockedHotkey, captureLockedHotkey).toString();
|
2020-02-21 00:45:53 +07:00
|
|
|
|
2020-03-09 15:29:51 +07:00
|
|
|
showMessageOnStart =
|
|
|
|
settings.value(qs_showMessageOnStart, showMessageOnStart).toBool();
|
|
|
|
|
2020-03-07 00:27:38 +07:00
|
|
|
resultShowType = ResultMode(
|
|
|
|
std::clamp(settings.value(qs_resultShowType, int(resultShowType)).toInt(),
|
|
|
|
int(ResultMode::Widget), int(ResultMode::Tooltip)));
|
2020-02-21 00:45:53 +07:00
|
|
|
|
2020-03-07 00:53:53 +07:00
|
|
|
proxyType =
|
|
|
|
ProxyType(std::clamp(settings.value(qs_proxyType, int(proxyType)).toInt(),
|
|
|
|
int(ProxyType::Disabled), int(ProxyType::Http)));
|
2020-02-21 00:45:53 +07:00
|
|
|
proxyHostName = settings.value(qs_proxyHostName, proxyHostName).toString();
|
|
|
|
proxyPort = settings.value(qs_proxyPort, proxyPort).toInt();
|
|
|
|
proxyUser = settings.value(qs_proxyUser, proxyUser).toString();
|
|
|
|
proxySavePassword =
|
|
|
|
settings.value(qs_proxySavePassword, proxySavePassword).toBool();
|
|
|
|
proxyPassword = shuffle(settings.value(qs_proxyPassword).toString());
|
|
|
|
|
2020-03-18 01:32:36 +07:00
|
|
|
autoUpdateIntervalDays =
|
|
|
|
settings.value(qs_autoUpdateType, autoUpdateIntervalDays).toInt();
|
|
|
|
lastUpdateCheck =
|
|
|
|
settings.value(qs_lastUpdateCheck, lastUpdateCheck).toDateTime();
|
2020-02-21 00:45:53 +07:00
|
|
|
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
settings.beginGroup(qs_recogntionGroup);
|
|
|
|
sourceLanguage = settings.value(qs_ocrLanguage, sourceLanguage).toString();
|
2021-11-11 17:27:18 +07:00
|
|
|
if (!settings.contains(qs_tesseractVersion)) {
|
|
|
|
tesseractVersion = checkOptimizedTesseractSupport()
|
|
|
|
? TesseractVersion::Optimized
|
|
|
|
: TesseractVersion::Compatible;
|
|
|
|
} else {
|
|
|
|
tesseractVersion = TesseractVersion(std::clamp(
|
|
|
|
settings.value(qs_tesseractVersion, int(tesseractVersion)).toInt(),
|
|
|
|
int(TesseractVersion::Optimized), int(TesseractVersion::Compatible)));
|
|
|
|
}
|
2020-02-21 00:45:53 +07:00
|
|
|
settings.endGroup();
|
|
|
|
|
2020-03-08 17:49:15 +07:00
|
|
|
settings.beginGroup(qs_correctionGroup);
|
2020-04-09 03:17:23 +07:00
|
|
|
useHunspell = settings.value(qs_useHunspell, useHunspell).toBool();
|
2020-03-08 17:49:15 +07:00
|
|
|
useUserSubstitutions =
|
|
|
|
settings.value(qs_useUserSubstitutions, useUserSubstitutions).toBool();
|
|
|
|
userSubstitutions =
|
|
|
|
unpackSubstitutions(settings.value(qs_userSubstitutions).toStringList());
|
2020-03-18 00:43:32 +07:00
|
|
|
if (userSubstitutions.empty())
|
|
|
|
userSubstitutions = loadLegacySubstitutions();
|
2020-03-08 17:49:15 +07:00
|
|
|
settings.endGroup();
|
|
|
|
|
2020-02-21 00:45:53 +07:00
|
|
|
settings.beginGroup(qs_translationGroup);
|
|
|
|
|
|
|
|
doTranslation = settings.value(qs_doTranslation, doTranslation).toBool();
|
|
|
|
ignoreSslErrors =
|
|
|
|
settings.value(qs_ignoreSslErrors, ignoreSslErrors).toBool();
|
|
|
|
targetLanguage =
|
|
|
|
settings.value(qs_translationLanguage, targetLanguage).toString();
|
|
|
|
translationTimeout = std::chrono::seconds(
|
|
|
|
settings.value(qs_translationTimeout, int(translationTimeout.count()))
|
|
|
|
.toInt());
|
|
|
|
translators = settings.value(qs_translators, translators).toStringList();
|
|
|
|
if (translators.size() == 1 && translators.first().contains('|')) // legacy
|
|
|
|
translators = translators.first().split('|');
|
|
|
|
|
|
|
|
settings.endGroup();
|
2020-03-20 01:47:46 +07:00
|
|
|
|
|
|
|
settings.beginGroup(qs_representationGroup);
|
|
|
|
|
2020-03-22 15:39:59 +07:00
|
|
|
const auto defaultFont = QApplication::font().family();
|
|
|
|
fontFamily = settings.value(qs_fontFamily, defaultFont).toString();
|
2020-03-20 01:47:46 +07:00
|
|
|
fontSize = std::clamp(settings.value(qs_fontSize, fontSize).toInt(), 6, 24);
|
2020-03-29 15:55:03 +07:00
|
|
|
fontColor = QColor(settings.value(qs_fontColor, fontColor.name()).toString());
|
|
|
|
backgroundColor = QColor(
|
|
|
|
settings.value(qs_backgroundColor, backgroundColor.name()).toString());
|
2020-03-20 01:55:32 +07:00
|
|
|
showRecognized = settings.value(qs_showRecognized, showRecognized).toBool();
|
|
|
|
showCaptured = settings.value(qs_showCaptured, showCaptured).toBool();
|
2020-03-20 01:47:46 +07:00
|
|
|
|
2020-03-20 02:35:42 +07:00
|
|
|
runAtSystemStart = service::RunAtSystemStart::isEnabled();
|
|
|
|
|
2020-03-20 01:47:46 +07:00
|
|
|
settings.endGroup();
|
2020-02-21 00:45:53 +07:00
|
|
|
}
|
2020-03-15 19:30:24 +07:00
|
|
|
|
2020-03-21 17:03:58 +07:00
|
|
|
void Settings::saveLastUpdateCheck()
|
2020-03-19 00:24:11 +07:00
|
|
|
{
|
|
|
|
std::unique_ptr<QSettings> ptr;
|
2021-01-10 20:13:45 +07:00
|
|
|
const auto iniName = iniFileName();
|
|
|
|
if (QFile::exists(iniName)) {
|
|
|
|
ptr = std::make_unique<QSettings>(iniName, QSettings::IniFormat);
|
2020-03-19 00:24:11 +07:00
|
|
|
} else {
|
|
|
|
ptr = std::make_unique<QSettings>();
|
|
|
|
}
|
|
|
|
auto& settings = *ptr;
|
|
|
|
|
|
|
|
settings.beginGroup(qs_guiGroup);
|
2020-03-21 17:03:58 +07:00
|
|
|
settings.setValue(qs_lastUpdateCheck, lastUpdateCheck);
|
2020-03-19 00:24:11 +07:00
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
2020-03-15 19:30:24 +07:00
|
|
|
bool Settings::isPortable() const
|
|
|
|
{
|
|
|
|
return isPortable_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::setPortable(bool isPortable)
|
|
|
|
{
|
|
|
|
isPortable_ = isPortable;
|
|
|
|
|
|
|
|
const auto baseDataPath =
|
2021-01-10 20:13:45 +07:00
|
|
|
(isPortable ? QApplication::applicationDirPath()
|
2020-04-17 21:48:13 +07:00
|
|
|
: QStandardPaths::writableLocation(
|
|
|
|
QStandardPaths::AppDataLocation)) +
|
|
|
|
"/assets";
|
2020-03-15 19:30:24 +07:00
|
|
|
tessdataPath = baseDataPath + "/tessdata";
|
2021-11-11 18:29:40 +07:00
|
|
|
translatorsPath = baseDataPath + "/translators";
|
|
|
|
hunspellPath = baseDataPath + "/hunspell";
|
2020-03-15 19:30:24 +07:00
|
|
|
}
|