diff options
Diffstat (limited to 'src/localesettings')
-rw-r--r-- | src/localesettings/locale.xml | 12 | ||||
-rw-r--r-- | src/localesettings/localefiltermodel.cpp | 179 | ||||
-rw-r--r-- | src/localesettings/localefiltermodel.h | 58 | ||||
-rw-r--r-- | src/localesettings/localemodel.cpp | 324 | ||||
-rw-r--r-- | src/localesettings/localemodel.h | 95 | ||||
-rw-r--r-- | src/localesettings/localesettings.pro | 21 | ||||
-rw-r--r-- | src/localesettings/systemlocale.cpp | 54 | ||||
-rw-r--r-- | src/localesettings/systemlocale.h | 59 | ||||
-rw-r--r-- | src/localesettings/systemlocale_p.h | 95 |
9 files changed, 0 insertions, 897 deletions
diff --git a/src/localesettings/locale.xml b/src/localesettings/locale.xml deleted file mode 100644 index b722456..0000000 --- a/src/localesettings/locale.xml +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> -<node> - <interface name="org.freedesktop.locale1"> - <property name="Locale" type="as" access="read"/> - <method name="SetLocale"> - <arg name="locale" type="as" direction="in"/> - <arg name="user_interaction" type="b" direction="in"/> - </method> - </interface> -</node> - diff --git a/src/localesettings/localefiltermodel.cpp b/src/localesettings/localefiltermodel.cpp deleted file mode 100644 index e3eecd4..0000000 --- a/src/localesettings/localefiltermodel.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "localemodel.h" -#include "localefiltermodel.h" - -QT_BEGIN_NAMESPACE - -/*! - \module QtLocaleSettings - \qtvariable localesettings - \ingroup qtdevice-utilities-cpp-modules - \ingroup modules - \title Qt Locale Settings C++ Classes - \brief Provides functionality for controlling locale settings. - - To use classes from this module, add this directive into the C++ files: - - \code - #include <QtLocaleSettings> - \endcode - - To link against the corresponding C++ libraries, add the following to your - qmake project file: - - \code - QT += localesettings - \endcode -*/ - -/*! - \class LocaleFilterModel - \inmodule QtLocaleSettings - - \brief The LocaleFilterModel class provides a filtered model for the - available locales. - - This class can be used as the model in a view that lists the available - locales. - - \sa LocaleModel -*/ - -/*! - \property LocaleFilterModel::filter - \brief Holds a string that filters out the locales in the model. - - The filtering process is a case-insensitive matching for whether the region - (country) name contains this string. The string can be taken from user - input. - - \sa LocaleItem::country -*/ - -/*! - Creates a locale filer model with the parent \a parent. -*/ -LocaleFilterModel::LocaleFilterModel(QObject* parent) - :QSortFilterProxyModel(parent) -{ - connect(this, &LocaleFilterModel::filterChanged, this, &LocaleFilterModel::invalidate); - LocaleModel *localeModel = new LocaleModel(this); - setSourceModel(localeModel); -} - -/*! - Deletes the locale filter model. -*/ -LocaleFilterModel::~LocaleFilterModel() -{ - -} - -/*! - Returns the locale filter string. -*/ -QString LocaleFilterModel::filter() const -{ - return m_filter; -} - -/*! - Sets the locale filter string to \a aFilter. -*/ -void LocaleFilterModel::setFilter(const QString& aFilter) -{ - m_filter = aFilter; - emit filterChanged(); -} - -/*! - Returns whether the row \a source_row has the country role and whether it is - found in the locale model \a source_parent. -*/ -bool LocaleFilterModel::filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const -{ - bool ret = false; - if (this->sourceModel()) - { - QModelIndex index = this->sourceModel()->index( source_row, 0, source_parent ); - if (index.isValid()) - { - QVariant nameRole = index.data(LocaleModel::Country); - if (nameRole.isValid()) - { - QString name = nameRole.toString(); - if (name.contains(m_filter, Qt::CaseInsensitive)) { - ret = true; - } - } - } - } - return ret; -} - -/*! - Returns the locale item at \a row in the locale filter model. - - This item can be assigned to LocaleManager::locale(), when the user selects - a locale from a list. - - \sa LocaleItem -*/ -QVariant LocaleFilterModel::itemFromRow(const int row) const -{ - QModelIndex idx = index(row, 0); - QModelIndex mapped = mapToSource(idx); - if (mapped.isValid()) - { - QVariant nameRole = mapped.data(LocaleModel::Code); - if (nameRole.isValid()) - { - return nameRole; - } - } - return QVariant(); -} - -/*! - Returns the index for the country \a country in the locale filter model. - - The index is used by item views, delegates, and selection models to locate - an item in the model. -*/ -int LocaleFilterModel::indexForCountry(const QString &country) const -{ - QAbstractItemModel *model = this->sourceModel(); - LocaleModel *localModel = qobject_cast<LocaleModel*>(model); - QModelIndex i = localModel->indexForCountry(country); - QModelIndex ret = mapFromSource(i); - return ret.row(); -} - -QT_END_NAMESPACE diff --git a/src/localesettings/localefiltermodel.h b/src/localesettings/localefiltermodel.h deleted file mode 100644 index 1ddcb9c..0000000 --- a/src/localesettings/localefiltermodel.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef LOCALEFILTERMODEL_H -#define LOCALEFILTERMODEL_H - - -#include <QSortFilterProxyModel> - -QT_BEGIN_NAMESPACE - -class Q_DECL_EXPORT LocaleFilterModel : public QSortFilterProxyModel -{ - Q_OBJECT - Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) -public: - explicit LocaleFilterModel(QObject* parent); - virtual ~LocaleFilterModel(); - bool filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const override; - QString filter() const; - void setFilter(const QString& aFilter); - Q_INVOKABLE QVariant itemFromRow(const int row) const; - Q_INVOKABLE int indexForCountry(const QString &country) const; -Q_SIGNALS: - void filterChanged(); -private: - QString m_filter; - -}; - -QT_END_NAMESPACE - -#endif // LOCALEFILTERMODEL_H diff --git a/src/localesettings/localemodel.cpp b/src/localesettings/localemodel.cpp deleted file mode 100644 index 043376a..0000000 --- a/src/localesettings/localemodel.cpp +++ /dev/null @@ -1,324 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include <QLocale> -#include <QFuture> -#include <QFutureWatcher> -#include <QThread> -#include <QtConcurrent/QtConcurrentRun> -#include "localemodel.h" - -QT_BEGIN_NAMESPACE - -/*! - \class LocaleItem - \inmodule QtLocaleSettings - - \brief The LocaleItem class represents a locale. - - This class holds the name, language, and country code of a locale. - - If available, the native country name and language are used. For example, - \e Deutsch and \e Deutschland for the German locale. - - \sa QLocale, LocaleModel -*/ - -/*! - \property LocaleItem::code - \brief The locale code string. - - The locale code is in the format \e language_country, where \e language is - a lowercase, two-letter ISO 639 language code, and \e country is an - uppercase, two- or three-letter ISO 3166 country code. - - \sa QLocale::name() -*/ - -/*! - \property LocaleItem::country - \brief The name of the country. - - \sa QLocale::Country -*/ - -/*! - \property LocaleItem::language - \brief The name of the language. - - \sa QLocale::Language -*/ - - -/*! - Creates the locale item \a locale with the parent \a parent. -*/ -LocaleItem::LocaleItem(const QLocale& locale, QObject *parent) - :QObject(parent) -{ - m_code = locale.name(); - m_country = locale.nativeCountryName(); - if (m_country.isEmpty()) { - m_country = locale.countryToString(locale.country()); - } - - m_language = locale.nativeLanguageName(); - if (m_language.isEmpty()) { - m_language = locale.languageToString(locale.language()); - } -} - -/*! - Returns the language of the country. -*/ -QString LocaleItem::language() const -{ - return m_language; -} - -/*! - Returns the name of the country. -*/ -QString LocaleItem::country() const -{ - return m_country; -} - -/*! - Returns the country code of the country. -*/ -QString LocaleItem::code() const -{ - return m_code; -} - -/*! - \class LocaleModel - \inmodule QtLocaleSettings - - \brief The LocaleModel class provides a model for the available locales. - - Each item in the model has a set of data elements associated with it, each - with its own role. The roles are used by the view to indicate to the model - which type of data it needs. Custom models should return data in these - types. - - The data in a locale model can be filtered according to the country code, - name, or language. - - \sa LocaleItem, LocaleFilterModel -*/ - -/*! - \enum LocaleModel::Roles - - This enum holds the role of the locale item. - - For user roles, it is up to the developer to decide which types to use and - ensure that components use the correct types when accessing and setting - data. - - \value Language - The language of the country. - \value Country - The name of the country. - \value Code - The locale code string in the format \e language_country. - - \sa Qt::UserRole -*/ - -/*! - \fn LocaleModel::addItem(LocaleItem* item) - - This signal is emitted when the locale item \a item is added to the locale - model. -*/ - -/*! - \fn LocaleModel::ready() - - This signal is emitted when the locale model has been reset. -*/ - -/*! - Creates a locale model with the parent \a parent. -*/ -LocaleModel::LocaleModel(QObject *parent) - : QAbstractListModel(parent) -{ - m_roleNames.insert(Qt::UserRole, "modelData"); - m_roleNames.insert(Country, "country"); - m_roleNames.insert(Language, "language"); - m_roleNames.insert(Code, "code"); - - QFutureWatcher<void> *watcher = new QFutureWatcher<void>(this); - QFuture<void> future = QtConcurrent::run(LocaleModel::generateModel, this); - watcher->setFuture(future); - connect(watcher, SIGNAL(finished()), this, SLOT(modelReady())); -} - -/*! - This signal is emitted when the locale model has been reset. -*/ -void LocaleModel::modelReady() -{ - beginResetModel(); - sort(0); - endResetModel(); - - emit ready(); -} - -/*! - Creates the locale model \a model. -*/ -void LocaleModel::generateModel(LocaleModel* model) -{ - QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); - - for (const QLocale &locale : allLocales) { - if (locale.name() != QStringLiteral("C")) { - LocaleItem *l = new LocaleItem(locale); - l->moveToThread(model->thread()); - QMetaObject::invokeMethod(model, "addNewItem", Q_ARG( QObject*, qobject_cast<QObject*>(l))); - } - } -} - -void LocaleModel::addNewItem(QObject *item) -{ - beginInsertRows(QModelIndex(), m_items.count(), m_items.count()); - LocaleItem* newItem = qobject_cast<LocaleItem*>(item); - if (newItem) - m_items.append(newItem); - endInsertRows(); -} - -/*! - Deletes the locale model. -*/ -LocaleModel::~LocaleModel() -{ - qDeleteAll(m_items); -} - -/*! - Returns an array of user roles. - - \sa Roles -*/ -QHash<int, QByteArray> LocaleModel::roleNames() const -{ - return m_roleNames; -} - -/*! - Returns the number of rows in the locale model that has \a parent. -*/ -int LocaleModel::rowCount(const QModelIndex & parent) const -{ - Q_UNUSED(parent); - return m_items.count(); -} - -/*! - Returns the locale item at \a index in the locale model for \a role. - - This item can be assigned to LocaleManager::locale(), when the user selects - a locale from a list. - - \sa LocaleItem, Roles -*/ -QVariant LocaleModel::data(const QModelIndex & index, int role) const -{ - if (!index.isValid()) return QVariant(); - - LocaleItem *item = m_items[index.row()]; - - switch (role) { - case Qt::UserRole: - return QVariant::fromValue(static_cast<QObject*>(item)); - break; - case Country: - return item->country(); - break; - case Language: - return item->language(); - break; - case Code: - return item->code(); - break; - default: - return QVariant(); - } -} - -/*! - Returns whether the locale item has more than one languages specified. - - If the language variant of the locale item if \a v1 is less than \a v2 ##? - -*/ -bool LocaleModel::variantLessThan(const LocaleItem* v1, const LocaleItem* v2) -{ - return v1->language() < v2->language(); -} - -/*! - Sets the sorting order of the \a column items in the locale model to \a order. - - The sort order can be either \l {Qt::AscendingOrder}{ascending} or - \l {Qt::DescendingOrder}{descending}. -*/ -void LocaleModel::sort(int column, Qt::SortOrder order) -{ - Q_UNUSED(column); - Q_UNUSED(order); - std::sort(m_items.begin(), m_items.end(), LocaleModel::variantLessThan); -} - -/*! - Returns the index for the country \a country in the locale model. - - The index is used by item views, delegates, and selection models to locate - an item in the model. -*/ -QModelIndex LocaleModel::indexForCountry(const QString &country) const -{ - for (int i = 0; i < m_items.count(); i++) { - LocaleItem *item = m_items.at(i); - if (item->country() == country || - item->language() == country) { - return index(i); - } - } - return QModelIndex(); -} - -QT_END_NAMESPACE diff --git a/src/localesettings/localemodel.h b/src/localesettings/localemodel.h deleted file mode 100644 index fac0b94..0000000 --- a/src/localesettings/localemodel.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef LOCALEMODEL_H -#define LOCALEMODEL_H - -#include <QObject> -#include <QAbstractListModel> -#include <QLocale> -#include <QMutex> - -QT_BEGIN_NAMESPACE - -class LocaleItem : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString code READ code CONSTANT) - Q_PROPERTY(QString country READ country CONSTANT) - Q_PROPERTY(QString language READ language CONSTANT) -public: - explicit LocaleItem(const QLocale &locale, QObject *parent = Q_NULLPTR); - QString country() const; - QString language() const; - QString code() const; - -private: - QString m_country; - QString m_language; - QString m_code; -}; - -class Q_DECL_EXPORT LocaleModel : public QAbstractListModel -{ - Q_OBJECT - -public: - explicit LocaleModel(QObject *parent = Q_NULLPTR); - virtual ~LocaleModel(); - // from QAbstractItemModel - int rowCount(const QModelIndex & parent = QModelIndex()) const; - QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; - QHash<int, QByteArray> roleNames() const; - void sort(int column, Qt::SortOrder order=Qt::AscendingOrder); - static bool variantLessThan(const LocaleItem* v1, const LocaleItem* v2); - QModelIndex indexForCountry(const QString &country) const; - - enum Roles { - Language = Qt::UserRole + 1, - Country, - Code - }; - - static void generateModel(LocaleModel* model); - -Q_SIGNALS: - void addItem(LocaleItem* item); - void ready(); - -private Q_SLOTS: - void addNewItem(QObject* item); - void modelReady(); - -private: - QList<LocaleItem*> m_items; - QHash<int, QByteArray> m_roleNames; -}; - -QT_END_NAMESPACE - -#endif // LOCALEMODEL_H diff --git a/src/localesettings/localesettings.pro b/src/localesettings/localesettings.pro deleted file mode 100644 index 7f5f98a..0000000 --- a/src/localesettings/localesettings.pro +++ /dev/null @@ -1,21 +0,0 @@ -load(qt_build_config) - -TARGET = QtLocaleSettings -VERSION = 1.0 - -QT = core dbus - -MODULE = localesettings -load(qt_module) - -DBUS_INTERFACES = locale.xml - -HEADERS = \ - systemlocale.h \ - systemlocale_p.h \ - localemodel.h \ - localefiltermodel.h -SOURCES += systemlocale.cpp \ - localemodel.cpp \ - localefiltermodel.cpp - diff --git a/src/localesettings/systemlocale.cpp b/src/localesettings/systemlocale.cpp deleted file mode 100644 index e6de431..0000000 --- a/src/localesettings/systemlocale.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include <QLocale> -#include "systemlocale.h" -#include "systemlocale_p.h" - -QT_BEGIN_NAMESPACE - -SystemLocale::SystemLocale(QObject *parent) - :QObject(parent) - ,d_ptr(new SystemLocalePrivate(this)) -{ -} - -QString SystemLocale::locale() const -{ - Q_D(const SystemLocale); - return d->locale(); -} - -void SystemLocale::setLocale(const QString& aLocale) -{ - Q_D(SystemLocale); - d->setLocale(aLocale); - emit localeChanged(); -} - -QT_END_NAMESPACE diff --git a/src/localesettings/systemlocale.h b/src/localesettings/systemlocale.h deleted file mode 100644 index b10c5a1..0000000 --- a/src/localesettings/systemlocale.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef LOCALE_H -#define LOCALE_H - -#include <QObject> - -QT_BEGIN_NAMESPACE - -class SystemLocalePrivate; - -class Q_DECL_EXPORT SystemLocale : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString locale READ locale WRITE setLocale NOTIFY localeChanged) -public: - explicit SystemLocale(QObject *parent = Q_NULLPTR); - QString locale() const; - void setLocale(const QString& aLocale); -Q_SIGNALS: - void localeChanged(); -public Q_SLOTS: - -protected: - SystemLocalePrivate *d_ptr; - - Q_DISABLE_COPY(SystemLocale) - Q_DECLARE_PRIVATE(SystemLocale) -}; - -QT_END_NAMESPACE - -#endif // LOCALE_H diff --git a/src/localesettings/systemlocale_p.h b/src/localesettings/systemlocale_p.h deleted file mode 100644 index a3d1a5f..0000000 --- a/src/localesettings/systemlocale_p.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef LOCALE_P_H -#define LOCALE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "systemlocale.h" -#include "locale_interface.h" - -QT_BEGIN_NAMESPACE - -class SystemLocalePrivate -{ - Q_DECLARE_PUBLIC(SystemLocale) -public: - SystemLocalePrivate(SystemLocale *qq) - :q_ptr(qq) - { - m_localeInterface = new OrgFreedesktopLocale1Interface(QStringLiteral("org.freedesktop.locale1"), - QStringLiteral("/org/freedesktop/locale1"), - QDBusConnection::systemBus(), qq); - - QStringList locale = m_localeInterface->locale(); - foreach (QString l, locale) { - QStringList nameValue = l.split('='); - if (nameValue.length() == 2) - m_localeCache[nameValue.at(0)] = nameValue.at(1); - } - } - - QString locale() const { - return m_localeCache[QStringLiteral("LANG")]; - } - - void setLocale(const QString& aLocale) { - m_localeCache[QStringLiteral("LANG")] = aLocale; - updateLocale(); - } - - void updateLocale() { - QStringList newLocale; - QMap<QString, QString>::iterator i; - for (i = m_localeCache.begin(); i != m_localeCache.end(); ++i) { - QString val = i.key() + QLatin1String("=") + i.value(); - newLocale.append(val); - } - m_localeInterface->SetLocale(newLocale, true); - } - - -private: - QMap<QString, QString> m_localeCache; - OrgFreedesktopLocale1Interface *m_localeInterface; - SystemLocale *q_ptr; -}; - -QT_END_NAMESPACE - -#endif // LOCALE_P_H |