mirror of https://github.com/cutefishos/calamares
Merge branch 'issue-1476' into calamares
Go over the locale module again: - new models that avoid weird casts and inconvenient iteration - shared timezone data - simple sorting and filtering - simplify the map / QML version FIXES #1476 FIXES #1426main
commit
2ce12d5368
@ -0,0 +1,89 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares 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.
|
||||
*
|
||||
* Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#include "TranslatableString.h"
|
||||
|
||||
|
||||
/** @brief Massage an identifier into a human-readable form
|
||||
*
|
||||
* Makes a copy of @p s, caller must free() it.
|
||||
*/
|
||||
static char*
|
||||
munge( const char* s )
|
||||
{
|
||||
char* t = strdup( s );
|
||||
if ( !t )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// replace("_"," ") in the Python script
|
||||
char* p = t;
|
||||
while ( *p )
|
||||
{
|
||||
if ( ( *p ) == '_' )
|
||||
{
|
||||
*p = ' ';
|
||||
}
|
||||
++p;
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
namespace CalamaresUtils
|
||||
{
|
||||
namespace Locale
|
||||
{
|
||||
|
||||
TranslatableString::TranslatableString( TranslatableString&& t )
|
||||
: m_human( nullptr )
|
||||
, m_key()
|
||||
{
|
||||
// My pointers are initialized to nullptr
|
||||
std::swap( m_human, t.m_human );
|
||||
std::swap( m_key, t.m_key );
|
||||
}
|
||||
|
||||
TranslatableString::TranslatableString( const TranslatableString& t )
|
||||
: m_human( t.m_human ? strdup( t.m_human ) : nullptr )
|
||||
, m_key( t.m_key )
|
||||
{
|
||||
}
|
||||
|
||||
TranslatableString::TranslatableString( const char* s1 )
|
||||
: m_human( s1 ? munge( s1 ) : nullptr )
|
||||
, m_key( s1 ? QString( s1 ) : QString() )
|
||||
{
|
||||
}
|
||||
|
||||
TranslatableString::TranslatableString( const QString& s )
|
||||
: m_human( munge( s.toUtf8().constData() ) )
|
||||
, m_key( s )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TranslatableString::~TranslatableString()
|
||||
{
|
||||
free( m_human );
|
||||
}
|
||||
|
||||
} // namespace Locale
|
||||
} // namespace CalamaresUtils
|
@ -0,0 +1,68 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares 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.
|
||||
*
|
||||
* Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifndef LOCALE_TRANSLATABLESTRING_H
|
||||
#define LOCALE_TRANSLATABLESTRING_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace CalamaresUtils
|
||||
{
|
||||
namespace Locale
|
||||
{
|
||||
|
||||
/** @brief A pair of strings, one human-readable, one a key
|
||||
*
|
||||
* Given an identifier-like string (e.g. "New_York"), makes
|
||||
* a human-readable version of that and keeps a copy of the
|
||||
* identifier itself.
|
||||
*
|
||||
* This explicitly uses const char* instead of just being
|
||||
* QPair<QString, QString> because the human-readable part
|
||||
* may need to be translated through tr(), and that takes a char*
|
||||
* C-style strings.
|
||||
*/
|
||||
class TranslatableString
|
||||
{
|
||||
public:
|
||||
/// @brief An empty pair
|
||||
TranslatableString() {}
|
||||
/// @brief Given an identifier, create the pair
|
||||
explicit TranslatableString( const char* s1 );
|
||||
explicit TranslatableString( const QString& s );
|
||||
TranslatableString( TranslatableString&& t );
|
||||
TranslatableString( const TranslatableString& );
|
||||
virtual ~TranslatableString();
|
||||
|
||||
/// @brief Give the localized human-readable form
|
||||
virtual QString tr() const = 0;
|
||||
QString key() const { return m_key; }
|
||||
|
||||
bool operator==( const TranslatableString& other ) const { return m_key == other.m_key; }
|
||||
bool operator<( const TranslatableString& other ) const { return m_key < other.m_key; }
|
||||
|
||||
protected:
|
||||
char* m_human = nullptr;
|
||||
QString m_key;
|
||||
};
|
||||
|
||||
} // namespace Locale
|
||||
} // namespace CalamaresUtils
|
||||
|
||||
#endif
|
@ -1,45 +0,0 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares 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.
|
||||
*
|
||||
* Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef TESTS_H
|
||||
#define TESTS_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class LocaleTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LocaleTests();
|
||||
~LocaleTests() override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
// Check the sample config file is processed correctly
|
||||
void testEmptyLocaleConfiguration();
|
||||
void testDefaultLocaleConfiguration();
|
||||
void testSplitLocaleConfiguration();
|
||||
|
||||
// Check the TZ images for consistency
|
||||
void testTZImages(); // No overlaps in images
|
||||
void testTZLocations(); // No overlaps in locations
|
||||
void testSpecificLocations();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue