Commit f3b2a1b6 authored by Karel Slaný's avatar Karel Slaný Committed by Martin Straka

Using localised string collator to sort upload hierarchy.

parent 97687eb6
......@@ -93,6 +93,7 @@ SOURCES += \
src/datovka_shared/io/sqlite/db.cpp \
src/datovka_shared/io/sqlite/db_single.cpp \
src/datovka_shared/io/sqlite/table.cpp \
src/datovka_shared/localisation/localisation.cpp \
src/datovka_shared/records_management/conversion.cpp \
src/datovka_shared/records_management/io/records_management_connection.cpp \
src/datovka_shared/records_management/json/entry_error.cpp \
......@@ -176,6 +177,7 @@ HEADERS += \
src/datovka_shared/io/sqlite/db.h \
src/datovka_shared/io/sqlite/db_single.h \
src/datovka_shared/io/sqlite/table.h \
src/datovka_shared/localisation/localisation.h \
src/datovka_shared/records_management/conversion.h \
src/datovka_shared/records_management/io/records_management_connection.h \
src/datovka_shared/records_management/json/entry_error.h \
......
/*
* Copyright (C) 2014-2018 CZ.NIC
*
* 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 <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#include "src/datovka_shared/localisation/localisation.h"
QLocale Localisation::programLocale;
QCollator Localisation::stringCollator;
const QString Localisation::langCs(QStringLiteral("cs"));
const QString Localisation::langEn(QStringLiteral("en"));
const QString Localisation::langSystem(QStringLiteral("system"));
void Localisation::setProgramLocale(const QString &langCode)
{
if (langCode == langCs) {
programLocale = QLocale(QLocale::Czech, QLocale::CzechRepublic);
} else if (langCode == langEn) {
programLocale = QLocale(QLocale::English, QLocale::UnitedKingdom);
} else {
/* Use system locale. */
programLocale = QLocale::system();
}
stringCollator.setLocale(programLocale);
}
QString Localisation::shortLangName(const QString &langCode)
{
if (langCode == langCs) {
return langCs;
} else if (langCode == langEn) {
return langEn;
} else {
/* Use system locale. */
return QLocale::system().name();
}
}
/*
* Copyright (C) 2014-2018 CZ.NIC
*
* 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 <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#pragma once
#include <QCollator>
#include <QLocale>
#include <QString>
/*!
* @brief Encapsulates localisation specific settings.
*/
class Localisation {
private:
/*!
* @Brief Private constructor.
*/
Localisation(void);
public:
/*!
* @brief Sets program locale according to supplied language code.
*
* @param[in] langCode Language code.
*/
static
void setProgramLocale(const QString &langCode);
/*!
* @brief Returns short language code (eg. "cs", "en").
*
* @param[in] langCode Language code.
* @return Short language ode or language code used by system if
* \a langCode is unknown.
*/
static
QString shortLangName(const QString &langCode);
static
QLocale programLocale; /*!< Global locale instance. */
static
QCollator stringCollator; /*!< Used for localised string collation. */
static
const QString langCs; /*!< Czech language code. */
static
const QString langEn; /*!< English language code. */
static
const QString langSystem; /*!< System-set language. */
};
......@@ -21,6 +21,7 @@
* the two.
*/
#include "src/datovka_shared/localisation/localisation.h"
#include "src/datovka_shared/records_management/models/upload_hierarchy_proxy_model.h"
UploadHierarchyProxyModel::UploadHierarchyProxyModel(QObject *parent)
......@@ -53,7 +54,8 @@ bool UploadHierarchyProxyModel::lessThan(const QModelIndex &sourceLeft,
if (Q_LIKELY(leftData.canConvert<QString>())) {
Q_ASSERT(rightData.canConvert<QString>());
return (leftData.toString() < rightData.toString());
return Localisation::stringCollator.compare(leftData.toString(),
rightData.toString()) < 0;
} else {
return QSortFilterProxyModel::lessThan(sourceLeft, sourceRight);
}
......
......@@ -33,6 +33,7 @@
#include "src/accounts.h"
#include "src/datovka_shared/io/records_management_db.h"
#include "src/datovka_shared/localisation/localisation.h"
#include "src/dialogues/qml_dialogue_helper.h"
#include "src/dialogues/qml_input_dialogue.h"
#include "src/dialogues/dialogues.h"
......@@ -273,12 +274,8 @@ int main(int argc, char *argv[])
/* load datovka localization and qtbase localization */
QTranslator datovkaTrans;
QTranslator qtbaseTrans;
QString lang = QLocale::system().name();
if (globSet.language == "cs") {
lang = "cs";
} else if (globSet.language == "en") {
lang = "en";
}
QString lang(Localisation::shortLangName(globSet.language));
Localisation::setProgramLocale(globSet.language);
if (!datovkaTrans.load("datovka_" + lang, ":/locale/")) {
qDebug() << "Could not load datovka localisation file...";
}
......
......@@ -26,6 +26,7 @@
#include <QDir>
#include <QStandardPaths>
#include "src/datovka_shared/localisation/localisation.h"
#include "src/datovka_shared/settings/records_management.h"
#include "src/io/filesystem.h"
#include "src/log/log.h"
......@@ -34,9 +35,6 @@
/* Name of Datovka configuration file */
#define SETTINGS_FILE_NAME "datovka.conf"
/* Supported languages. Default is system */
#define LANGUAGE_SYSTEM "system"
#define LANGUAGE_CS "cs"
#define LANGUAGE_EN "en"
/* Default value which define how long will have
* attachment files stored in local database (in days)*/
#define DEFAULT_MSG_LIFETIME 90
......@@ -69,7 +67,7 @@ Settings globSet;
Settings::Settings(void)
: PinSettings(),
language(LANGUAGE_SYSTEM),
language(Localisation::langSystem),
fontSize(DEFAULT_FONT_SIZE),
downloadOnlyNewMsgs(true),
downloadCompleteMsgs(false),
......@@ -141,7 +139,7 @@ void Settings::loadFromSettings(const QSettings &settings)
qDebug("%s()", __func__);
language = settings.value(SETTINGS_GLOBAL_GROUP "/" SETTINGS_LANGUAGE,
LANGUAGE_SYSTEM).toString();
Localisation::langSystem).toString();
fontSize = settings.value(SETTINGS_GLOBAL_GROUP "/" SETTINGS_FONTSIZE,
DEFAULT_FONT_SIZE).toInt();
downloadOnlyNewMsgs = settings.value(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment