Skip to content

Commit

Permalink
Merge branch 'jb49172_device_owner_name' into 'master'
Browse files Browse the repository at this point in the history
Add translated default for device owner's displayName and add displayName property to UserInfo.

See merge request mer-core/nemo-qml-plugin-systemsettings!138
  • Loading branch information
Tomin1 committed Apr 2, 2020
2 parents 8518e1e + 4530b56 commit 4dc39f2
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 8 deletions.
14 changes: 11 additions & 3 deletions rpm/nemo-qml-plugin-systemsettings.spec
Expand Up @@ -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
Expand Down Expand Up @@ -35,25 +34,30 @@ 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
%{summary}.

%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}

Expand Down Expand Up @@ -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,-)
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/languagemodel.cpp
Expand Up @@ -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;
}
Expand Down
24 changes: 22 additions & 2 deletions src/plugin/plugin.cpp
Expand Up @@ -33,6 +33,7 @@
#include <QtQml>
#include <QQmlEngine>
#include <QQmlExtensionPlugin>
#include <QTranslator>

#include <qusbmoded.h>

Expand All @@ -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 *)
{
Expand All @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions src/userinfo.cpp
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
}

Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/userinfo.h
Expand Up @@ -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)
Expand All @@ -69,6 +70,7 @@ class SYSTEMSETTINGS_EXPORT UserInfo: public QObject

bool isValid() const;

QString displayName() const;
QString username() const;
QString name() const;
UserType type() const;
Expand All @@ -82,6 +84,7 @@ class SYSTEMSETTINGS_EXPORT UserInfo: public QObject
bool operator!=(const UserInfo &other) const;

signals:
void displayNameChanged();
void usernameChanged();
void nameChanged();
void uidChanged();
Expand Down
1 change: 1 addition & 0 deletions src/userinfo_p.h
Expand Up @@ -56,6 +56,7 @@ class UserInfoPrivate : public QObject
void set(struct passwd *pwd);

signals:
void displayNameChanged();
void usernameChanged();
void nameChanged();
void uidChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/usermodel.cpp
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion systemsettings.pro
Expand Up @@ -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
34 changes: 34 additions & 0 deletions translations/translations.pro
@@ -0,0 +1,34 @@
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

0 comments on commit 4dc39f2

Please sign in to comment.