2022-01-11 13:38:57 -05:00
|
|
|
/*
|
2023-02-06 01:47:15 -05:00
|
|
|
* Copyright (C) 2021-2023 Savoir-faire Linux Inc.
|
2021-03-30 15:15:36 -04:00
|
|
|
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* \file appsettingsmanager.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "appsettingsmanager.h"
|
|
|
|
|
2022-01-28 12:11:04 -05:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QLibraryInfo>
|
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
2022-01-11 13:38:57 -05:00
|
|
|
const QString defaultDownloadPath = QStandardPaths::writableLocation(
|
|
|
|
QStandardPaths::DownloadLocation);
|
|
|
|
|
2021-03-30 15:15:36 -04:00
|
|
|
AppSettingsManager::AppSettingsManager(QObject* parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, settings_(new QSettings("jami.net", "Jami", this))
|
|
|
|
{
|
|
|
|
for (int i = 0; i < static_cast<int>(Settings::Key::COUNT__); ++i) {
|
|
|
|
auto key = static_cast<Settings::Key>(i);
|
|
|
|
if (!settings_->contains(Settings::toString(key)))
|
|
|
|
setValue(key, Settings::defaultValue(key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant
|
|
|
|
AppSettingsManager::getValue(const Settings::Key key)
|
|
|
|
{
|
|
|
|
auto value = settings_->value(Settings::toString(key), Settings::defaultValue(key));
|
|
|
|
|
|
|
|
if (QString(value.typeName()) == "QString"
|
|
|
|
&& (value.toString() == "false" || value.toString() == "true"))
|
|
|
|
return value.toBool();
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AppSettingsManager::setValue(const Settings::Key key, const QVariant& value)
|
|
|
|
{
|
|
|
|
settings_->setValue(Settings::toString(key), value);
|
|
|
|
}
|
2022-01-28 12:11:04 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
AppSettingsManager::loadTranslations()
|
|
|
|
{
|
|
|
|
#if defined(Q_OS_LINUX) && defined(JAMI_INSTALL_PREFIX)
|
|
|
|
QString appDir = JAMI_INSTALL_PREFIX;
|
2022-02-09 13:34:33 -05:00
|
|
|
#elif defined(Q_OS_MACOS)
|
|
|
|
QDir dir(qApp->applicationDirPath());
|
|
|
|
dir.cdUp();
|
|
|
|
QString appDir = dir.absolutePath() + "/Resources/share";
|
2022-01-28 12:11:04 -05:00
|
|
|
#else
|
|
|
|
QString appDir = qApp->applicationDirPath() + QDir::separator() + "share";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Remove previously installed translators
|
|
|
|
for (auto* tr : installedTr_)
|
|
|
|
qApp->removeTranslator(tr);
|
|
|
|
installedTr_.clear();
|
|
|
|
|
|
|
|
auto pref = getValue(Settings::Key::LANG).toString();
|
|
|
|
|
|
|
|
QString locale_name = pref == "SYSTEM" ? QLocale::system().name() : pref;
|
|
|
|
qDebug() << QString("Using locale: %1").arg(locale_name);
|
|
|
|
QString locale_lang = locale_name.split('_')[0];
|
|
|
|
|
|
|
|
QTranslator* qtTranslator_lang = new QTranslator(qApp);
|
|
|
|
QTranslator* qtTranslator_name = new QTranslator(qApp);
|
|
|
|
if (locale_name != locale_lang) {
|
|
|
|
if (qtTranslator_lang->load("qt_" + locale_lang,
|
|
|
|
QLibraryInfo::path(QLibraryInfo::TranslationsPath)))
|
|
|
|
qApp->installTranslator(qtTranslator_lang);
|
|
|
|
installedTr_.append(qtTranslator_lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qtTranslator_name->load("qt_" + locale_name,
|
|
|
|
QLibraryInfo::path(QLibraryInfo::TranslationsPath))) {
|
|
|
|
qApp->installTranslator(qtTranslator_name);
|
|
|
|
installedTr_.append(qtTranslator_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
QTranslator* lrcTranslator_lang = new QTranslator(qApp);
|
|
|
|
QTranslator* lrcTranslator_name = new QTranslator(qApp);
|
|
|
|
if (locale_name != locale_lang) {
|
misc: vendor libjamiclient into 'src/libclient/'
This is libjamiclient from the jami-libclient.git repository as of
767c45b8b09806ac05cbada720864df93588c047, with the following changes:
* src/libclient/newaccountmodel.cpp:
(NewAccountModelPimpl::removeFromAccounts): The lock wait inside
'#ifdef CHK_FREEABLE_BEFORE_ERASE_ACCOUNT' was not updated when the
type of 'accounts' was changed over the years from this:
std::map<std::string, account::Info>
to this:
std::map<QString, std::pair<account::Info, std::shared_ptr<Database>>>
Basically we need to get the 'first' of the pair for 'account::Info'.
So we now do that.
* src/libclient/avmodel.cpp:
* src/libclient/callbackshandler.cpp:
* src/libclient/contactmodel.cpp:
* src/libclient/conversationmodel.cpp:
* src/libclient/database.cpp:
* src/libclient/namedirectory.cpp:
* src/libclient/newaccountmodel.cpp:
* src/libclient/newcallmodel.cpp:
* src/libclient/newdevicemodel.cpp:
* src/libclient/peerdiscoverymodel.cpp:
* src/libclient/pluginmodel.cpp:
* src/libclient/smartinfohub.cpp:
* src/libclient/vcard.h:
* src/libclient/authority/storagehelper.cpp: Replace Qt's 'foreach'
with 'Q_FOREACH' and its 'emit' with 'Q_EMIT' because in the client-qt
code base we have '-DQT_NO_KEYWORDS' to avoid conflicts with other
libraries we use.
* cmake/FindLibJami.cmake: Import cmake/FindRing.cmake from the
jami-libclient.git repository. Then, rename RING_BUILD_DIR to
LIBJAMI_BUILD_DIR (though the old name is still supported for now).
Also update other references of Ring to Jami. Further, add additional
calls to 'find_library' to make sure specified local paths for libjami
are checked before system-wide ones (in case of older/obsolete libjami
being available system-wide, which might happen on GNU/Linux systems).
* translations/lrc_*.ts: Import translation files from the libclient
repository. The message location paths were corrected by running
"sed -i 's|../src|&/libclient|g' lrc_*.ts" in 'translations/'.
.tx/config: Add section for the newly-imported libclient translations.
* CMakeLists.txt: Reformat, plus various fixes and cleanups, such as
changing indentation to 2 spaces and wrapping lines at 70 characters,
renaming the parent directory of translations from 'ring' to 'jami',
and using all lowercase function calls. Also add copyright headers.
* src/app/appsettingsmanager.cpp:
(AppSettingsManager::loadTranslations):
* src/app/utilsadapter.cpp (UtilsAdapter::supportedLang): Update to
adapt to the renaming of the parent directory of translations from
'ring' to 'jami'.
GitLab: #748
Change-Id: I86e3b0fb30e554755023e7b858b6a0d132cd59ab
2022-05-06 16:00:16 -04:00
|
|
|
if (lrcTranslator_lang->load(appDir + QDir::separator() + "jami" + QDir::separator()
|
2022-01-28 12:11:04 -05:00
|
|
|
+ "translations" + QDir::separator() + "lrc_" + locale_lang)) {
|
|
|
|
qApp->installTranslator(lrcTranslator_lang);
|
|
|
|
installedTr_.append(lrcTranslator_lang);
|
|
|
|
}
|
|
|
|
}
|
misc: vendor libjamiclient into 'src/libclient/'
This is libjamiclient from the jami-libclient.git repository as of
767c45b8b09806ac05cbada720864df93588c047, with the following changes:
* src/libclient/newaccountmodel.cpp:
(NewAccountModelPimpl::removeFromAccounts): The lock wait inside
'#ifdef CHK_FREEABLE_BEFORE_ERASE_ACCOUNT' was not updated when the
type of 'accounts' was changed over the years from this:
std::map<std::string, account::Info>
to this:
std::map<QString, std::pair<account::Info, std::shared_ptr<Database>>>
Basically we need to get the 'first' of the pair for 'account::Info'.
So we now do that.
* src/libclient/avmodel.cpp:
* src/libclient/callbackshandler.cpp:
* src/libclient/contactmodel.cpp:
* src/libclient/conversationmodel.cpp:
* src/libclient/database.cpp:
* src/libclient/namedirectory.cpp:
* src/libclient/newaccountmodel.cpp:
* src/libclient/newcallmodel.cpp:
* src/libclient/newdevicemodel.cpp:
* src/libclient/peerdiscoverymodel.cpp:
* src/libclient/pluginmodel.cpp:
* src/libclient/smartinfohub.cpp:
* src/libclient/vcard.h:
* src/libclient/authority/storagehelper.cpp: Replace Qt's 'foreach'
with 'Q_FOREACH' and its 'emit' with 'Q_EMIT' because in the client-qt
code base we have '-DQT_NO_KEYWORDS' to avoid conflicts with other
libraries we use.
* cmake/FindLibJami.cmake: Import cmake/FindRing.cmake from the
jami-libclient.git repository. Then, rename RING_BUILD_DIR to
LIBJAMI_BUILD_DIR (though the old name is still supported for now).
Also update other references of Ring to Jami. Further, add additional
calls to 'find_library' to make sure specified local paths for libjami
are checked before system-wide ones (in case of older/obsolete libjami
being available system-wide, which might happen on GNU/Linux systems).
* translations/lrc_*.ts: Import translation files from the libclient
repository. The message location paths were corrected by running
"sed -i 's|../src|&/libclient|g' lrc_*.ts" in 'translations/'.
.tx/config: Add section for the newly-imported libclient translations.
* CMakeLists.txt: Reformat, plus various fixes and cleanups, such as
changing indentation to 2 spaces and wrapping lines at 70 characters,
renaming the parent directory of translations from 'ring' to 'jami',
and using all lowercase function calls. Also add copyright headers.
* src/app/appsettingsmanager.cpp:
(AppSettingsManager::loadTranslations):
* src/app/utilsadapter.cpp (UtilsAdapter::supportedLang): Update to
adapt to the renaming of the parent directory of translations from
'ring' to 'jami'.
GitLab: #748
Change-Id: I86e3b0fb30e554755023e7b858b6a0d132cd59ab
2022-05-06 16:00:16 -04:00
|
|
|
if (lrcTranslator_name->load(appDir + QDir::separator() + "jami" + QDir::separator()
|
2022-01-28 12:11:04 -05:00
|
|
|
+ "translations" + QDir::separator() + "lrc_" + locale_name)) {
|
|
|
|
qApp->installTranslator(lrcTranslator_name);
|
|
|
|
installedTr_.append(lrcTranslator_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
QTranslator* mainTranslator_lang = new QTranslator(qApp);
|
|
|
|
QTranslator* mainTranslator_name = new QTranslator(qApp);
|
|
|
|
if (locale_name != locale_lang) {
|
misc: vendor libjamiclient into 'src/libclient/'
This is libjamiclient from the jami-libclient.git repository as of
767c45b8b09806ac05cbada720864df93588c047, with the following changes:
* src/libclient/newaccountmodel.cpp:
(NewAccountModelPimpl::removeFromAccounts): The lock wait inside
'#ifdef CHK_FREEABLE_BEFORE_ERASE_ACCOUNT' was not updated when the
type of 'accounts' was changed over the years from this:
std::map<std::string, account::Info>
to this:
std::map<QString, std::pair<account::Info, std::shared_ptr<Database>>>
Basically we need to get the 'first' of the pair for 'account::Info'.
So we now do that.
* src/libclient/avmodel.cpp:
* src/libclient/callbackshandler.cpp:
* src/libclient/contactmodel.cpp:
* src/libclient/conversationmodel.cpp:
* src/libclient/database.cpp:
* src/libclient/namedirectory.cpp:
* src/libclient/newaccountmodel.cpp:
* src/libclient/newcallmodel.cpp:
* src/libclient/newdevicemodel.cpp:
* src/libclient/peerdiscoverymodel.cpp:
* src/libclient/pluginmodel.cpp:
* src/libclient/smartinfohub.cpp:
* src/libclient/vcard.h:
* src/libclient/authority/storagehelper.cpp: Replace Qt's 'foreach'
with 'Q_FOREACH' and its 'emit' with 'Q_EMIT' because in the client-qt
code base we have '-DQT_NO_KEYWORDS' to avoid conflicts with other
libraries we use.
* cmake/FindLibJami.cmake: Import cmake/FindRing.cmake from the
jami-libclient.git repository. Then, rename RING_BUILD_DIR to
LIBJAMI_BUILD_DIR (though the old name is still supported for now).
Also update other references of Ring to Jami. Further, add additional
calls to 'find_library' to make sure specified local paths for libjami
are checked before system-wide ones (in case of older/obsolete libjami
being available system-wide, which might happen on GNU/Linux systems).
* translations/lrc_*.ts: Import translation files from the libclient
repository. The message location paths were corrected by running
"sed -i 's|../src|&/libclient|g' lrc_*.ts" in 'translations/'.
.tx/config: Add section for the newly-imported libclient translations.
* CMakeLists.txt: Reformat, plus various fixes and cleanups, such as
changing indentation to 2 spaces and wrapping lines at 70 characters,
renaming the parent directory of translations from 'ring' to 'jami',
and using all lowercase function calls. Also add copyright headers.
* src/app/appsettingsmanager.cpp:
(AppSettingsManager::loadTranslations):
* src/app/utilsadapter.cpp (UtilsAdapter::supportedLang): Update to
adapt to the renaming of the parent directory of translations from
'ring' to 'jami'.
GitLab: #748
Change-Id: I86e3b0fb30e554755023e7b858b6a0d132cd59ab
2022-05-06 16:00:16 -04:00
|
|
|
if (mainTranslator_lang->load(appDir + QDir::separator() + "jami" + QDir::separator()
|
2022-01-28 12:11:04 -05:00
|
|
|
+ "translations" + QDir::separator() + "ring_client_windows_"
|
|
|
|
+ locale_lang)) {
|
|
|
|
qApp->installTranslator(mainTranslator_lang);
|
|
|
|
installedTr_.append(mainTranslator_lang);
|
|
|
|
}
|
|
|
|
}
|
misc: vendor libjamiclient into 'src/libclient/'
This is libjamiclient from the jami-libclient.git repository as of
767c45b8b09806ac05cbada720864df93588c047, with the following changes:
* src/libclient/newaccountmodel.cpp:
(NewAccountModelPimpl::removeFromAccounts): The lock wait inside
'#ifdef CHK_FREEABLE_BEFORE_ERASE_ACCOUNT' was not updated when the
type of 'accounts' was changed over the years from this:
std::map<std::string, account::Info>
to this:
std::map<QString, std::pair<account::Info, std::shared_ptr<Database>>>
Basically we need to get the 'first' of the pair for 'account::Info'.
So we now do that.
* src/libclient/avmodel.cpp:
* src/libclient/callbackshandler.cpp:
* src/libclient/contactmodel.cpp:
* src/libclient/conversationmodel.cpp:
* src/libclient/database.cpp:
* src/libclient/namedirectory.cpp:
* src/libclient/newaccountmodel.cpp:
* src/libclient/newcallmodel.cpp:
* src/libclient/newdevicemodel.cpp:
* src/libclient/peerdiscoverymodel.cpp:
* src/libclient/pluginmodel.cpp:
* src/libclient/smartinfohub.cpp:
* src/libclient/vcard.h:
* src/libclient/authority/storagehelper.cpp: Replace Qt's 'foreach'
with 'Q_FOREACH' and its 'emit' with 'Q_EMIT' because in the client-qt
code base we have '-DQT_NO_KEYWORDS' to avoid conflicts with other
libraries we use.
* cmake/FindLibJami.cmake: Import cmake/FindRing.cmake from the
jami-libclient.git repository. Then, rename RING_BUILD_DIR to
LIBJAMI_BUILD_DIR (though the old name is still supported for now).
Also update other references of Ring to Jami. Further, add additional
calls to 'find_library' to make sure specified local paths for libjami
are checked before system-wide ones (in case of older/obsolete libjami
being available system-wide, which might happen on GNU/Linux systems).
* translations/lrc_*.ts: Import translation files from the libclient
repository. The message location paths were corrected by running
"sed -i 's|../src|&/libclient|g' lrc_*.ts" in 'translations/'.
.tx/config: Add section for the newly-imported libclient translations.
* CMakeLists.txt: Reformat, plus various fixes and cleanups, such as
changing indentation to 2 spaces and wrapping lines at 70 characters,
renaming the parent directory of translations from 'ring' to 'jami',
and using all lowercase function calls. Also add copyright headers.
* src/app/appsettingsmanager.cpp:
(AppSettingsManager::loadTranslations):
* src/app/utilsadapter.cpp (UtilsAdapter::supportedLang): Update to
adapt to the renaming of the parent directory of translations from
'ring' to 'jami'.
GitLab: #748
Change-Id: I86e3b0fb30e554755023e7b858b6a0d132cd59ab
2022-05-06 16:00:16 -04:00
|
|
|
if (mainTranslator_name->load(appDir + QDir::separator() + "jami" + QDir::separator()
|
2022-01-28 12:11:04 -05:00
|
|
|
+ "translations" + QDir::separator() + "ring_client_windows_"
|
|
|
|
+ locale_name)) {
|
|
|
|
qApp->installTranslator(mainTranslator_name);
|
|
|
|
installedTr_.append(mainTranslator_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_EMIT retranslate();
|
2022-02-09 13:34:33 -05:00
|
|
|
}
|