Commit 4dc39f24 authored by Tomi Leppänen's avatar Tomi Leppänen

Merge branch 'jb49172_device_owner_name' into 'master'

Add translated default for device owner's displayName and add displayName property to UserInfo.

See merge request !138
parents 8518e1ec 4530b56a
......@@ -2,7 +2,6 @@ Name: nemo-qml-plugin-systemsettings
Summary: System settings plugin for Nemo Mobile
Version: 0.5.37
Release: 1
Group: System/Libraries
License: BSD
URL: https://git.sailfishos.org/mer-core/nemo-qml-plugin-systemsettings
Source0: %{name}-%{version}.tar.bz2
......@@ -35,13 +34,13 @@ BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(sailfishaccesscontrol)
BuildRequires: pkgconfig(libsystemd)
BuildRequires: pkgconfig(sailfishusermanager)
BuildRequires: qt5-qttools-linguist
%description
%{summary}.
%package devel
Summary: System settings C++ library
Group: System/Libraries
Requires: %{name} = %{version}-%{release}
%description devel
......@@ -49,11 +48,16 @@ Requires: %{name} = %{version}-%{release}
%package tests
Summary: System settings C++ library (unit tests)
Group: System/Libraries
%description tests
%{summary}.
%package ts-devel
Summary: Translation source for %{name}
%description ts-devel
%{summary}.
%prep
%setup -q -n %{name}-%{version}
......@@ -94,6 +98,7 @@ fi
%attr(4710,-,privileged) %{_libexecdir}/setlocale
%dir %attr(0775, root, privileged) /etc/location
%config %attr(0664, root, privileged) /etc/location/location.conf
%{_datadir}/translations/*.qm
%files devel
%defattr(-,root,root,-)
......@@ -105,3 +110,6 @@ fi
%defattr(-,root,root,-)
%{_libdir}/%{name}-tests/ut_diskusage
%{_datadir}/%{name}-tests/tests.xml
%files ts-devel
%{_datadir}/translations/source/*.ts
......@@ -204,7 +204,7 @@ QList<Language> LanguageModel::supportedLanguages()
QString localeCode = settings.value("LocaleCode").toString();
QString region = settings.value("Region").toString();
//% "Region: %1"
QString regionLabel = settings.value("RegionLabel", qtTrId("settings_system-la-region")).toString();
QString regionLabel = settings.value("RegionLabel", qtTrId("systemsettings-la-region")).toString();
if (name.isEmpty() || localeCode.isEmpty()) {
continue;
}
......
......@@ -33,6 +33,7 @@
#include <QtQml>
#include <QQmlEngine>
#include <QQmlExtensionPlugin>
#include <QTranslator>
#include <qusbmoded.h>
......@@ -54,6 +55,22 @@
#include "userinfo.h"
#include "usermodel.h"
class AppTranslator: public QTranslator
{
Q_OBJECT
public:
AppTranslator(QObject *parent)
: QTranslator(parent)
{
qApp->installTranslator(this);
}
virtual ~AppTranslator()
{
qApp->removeTranslator(this);
}
};
template<class T>
static QObject *api_factory(QQmlEngine *, QJSEngine *)
{
......@@ -68,8 +85,11 @@ class SystemSettingsPlugin : public QQmlExtensionPlugin
public:
void initializeEngine(QQmlEngine *engine, const char *uri)
{
Q_UNUSED(engine)
Q_UNUSED(uri)
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.nemomobile.systemsettings"));
AppTranslator *engineeringEnglish = new AppTranslator(engine);
engineeringEnglish->load("qml_plugin_systemsettings_eng_en", "/usr/share/translations");
AppTranslator *translator = new AppTranslator(engine);
translator->load(QLocale(), "qml_plugin_systemsettings", "-", "/usr/share/translations");
}
void registerTypes(const char *uri)
......
......@@ -98,11 +98,14 @@ void UserInfoPrivate::set(struct passwd *pwd)
if (m_username != username) {
m_username = username;
emit usernameChanged();
if (m_name.isEmpty() && name.isEmpty())
emit displayNameChanged();
}
if (m_name != name) {
m_name = name;
emit nameChanged();
emit displayNameChanged();
}
}
......@@ -193,6 +196,20 @@ bool UserInfo::isValid() const
return d->m_uid != InvalidId;
}
QString UserInfo::displayName() const
{
Q_D(const UserInfo);
if (d->m_name.isEmpty()) {
if (type() == DeviceOwner) {
//: Default value for device owner's name when it is not set
//% "Device owner"
return qtTrId("systemsettings-li-device_owner");
}
return d->m_username;
}
return d->m_name;
}
QString UserInfo::username() const
{
Q_D(const UserInfo);
......@@ -205,6 +222,8 @@ void UserInfo::setUsername(QString username)
if (d->m_username != username) {
d->m_username = username;
emit d_ptr->usernameChanged();
if (d->m_name.isEmpty())
emit d_ptr->displayNameChanged();
}
}
......@@ -220,6 +239,7 @@ void UserInfo::setName(QString name)
if (d->m_name != name) {
d->m_name = name;
emit d_ptr->nameChanged();
emit d_ptr->displayNameChanged();
}
}
......@@ -298,6 +318,7 @@ bool UserInfo::operator!=(const UserInfo &other) const
void UserInfo::connectSignals()
{
connect(d_ptr.data(), &UserInfoPrivate::displayNameChanged, this, &UserInfo::displayNameChanged);
connect(d_ptr.data(), &UserInfoPrivate::usernameChanged, this, &UserInfo::usernameChanged);
connect(d_ptr.data(), &UserInfoPrivate::nameChanged, this, &UserInfo::nameChanged);
connect(d_ptr.data(), &UserInfoPrivate::uidChanged, this, &UserInfo::uidChanged);
......
......@@ -46,6 +46,7 @@ class SYSTEMSETTINGS_EXPORT UserInfo: public QObject
Q_OBJECT
Q_DECLARE_PRIVATE(UserInfo)
Q_PROPERTY(QString displayName READ displayName NOTIFY displayNameChanged)
Q_PROPERTY(QString username READ username NOTIFY usernameChanged)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(UserType type READ type CONSTANT)
......@@ -69,6 +70,7 @@ public:
bool isValid() const;
QString displayName() const;
QString username() const;
QString name() const;
UserType type() const;
......@@ -82,6 +84,7 @@ public:
bool operator!=(const UserInfo &other) const;
signals:
void displayNameChanged();
void usernameChanged();
void nameChanged();
void uidChanged();
......
......@@ -56,6 +56,7 @@ public:
void set(struct passwd *pwd);
signals:
void displayNameChanged();
void usernameChanged();
void nameChanged();
void uidChanged();
......
......@@ -153,7 +153,7 @@ QVariant UserModel::data(const QModelIndex &index, int role) const
const UserInfo &user = m_users.at(index.row());
switch (role) {
case Qt::DisplayRole:
return (user.name().isEmpty()) ? user.username() : user.name();
return user.displayName();
case UsernameRole:
return user.username();
case NameRole:
......
......@@ -6,4 +6,4 @@ src_plugins.depends = src
OTHER_FILES += rpm/nemo-qml-plugin-systemsettings.spec
SUBDIRS = src src_plugins setlocale tests
SUBDIRS = src src_plugins setlocale tests translations
TEMPLATE = aux
TRANSLATION_CATALOG = qml_plugin_systemsettings
# Translation Source
TS_FILE = $$OUT_PWD/$${TRANSLATION_CATALOG}.ts
ts.commands += lupdate $$PWD/.. -ts $$TS_FILE
ts.CONFIG += no_check_exist no_link
ts.output = $$TS_FILE
ts.input = ..
ts_install.files = $$TS_FILE
ts_install.path = /usr/share/translations/source
ts_install.CONFIG += no_check_exist
# Engineering English Translation
EE_QM = $$OUT_PWD/$${TRANSLATION_CATALOG}_eng_en.qm
# XXX should add -markuntranslated "-" when proper translations are in place
qm.commands += lrelease -idbased $$TS_FILE -qm $$EE_QM
qm.CONFIG += no_check_exist no_link
qm.depends = ts
qm.input = $$TS_FILE
qm.output = $$EE_QM
qm_install.path = /usr/share/translations
qm_install.files = $$EE_QM
qm_install.CONFIG += no_check_exist
QMAKE_EXTRA_TARGETS += ts qm
PRE_TARGETDEPS += ts qm
INSTALLS += ts_install qm_install
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