代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/accountsservice 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From fb8f804e09c4505773e0324302c565df02ba250d Mon Sep 17 00:00:00 2001
From: peijiankang <peijiankang@kylinos.cn>
Date: Mon, 18 Sep 2023 10:55:57 +0800
Subject: [PATCH] Addition of FormatsLocale property and SetFormatsLocale
---
data/org.freedesktop.Accounts.User.xml | 45 +++++++++++++++++++
src/libaccountsservice/act-user.c | 60 ++++++++++++++++++++++++++
src/libaccountsservice/act-user.h | 3 ++
src/user.c | 57 ++++++++++++++++++++++++
4 files changed, 165 insertions(+)
diff --git a/data/org.freedesktop.Accounts.User.xml b/data/org.freedesktop.Accounts.User.xml
index 7a8a915..c750878 100644
--- a/data/org.freedesktop.Accounts.User.xml
+++ b/data/org.freedesktop.Accounts.User.xml
@@ -191,6 +191,41 @@
</doc:doc>
</method>
+ <method name="SetFormatsLocale">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <arg name="formats_locale" direction="in" type="s">
+ <doc:doc>
+ <doc:summary>
+ The new regional formats, as a locale specification like "de_DE.UTF-8".
+ </doc:summary>
+ </doc:doc>
+ </arg>
+ <doc:doc>
+ <doc:description>
+ <doc:para>
+ Sets the users regional formats.
+ </doc:para>
+ </doc:description>
+ <doc:permission>
+ The caller needs one of the following PolicyKit authorizations:
+ <doc:list>
+ <doc:item>
+ <doc:term>org.freedesktop.accounts.change-own-user-data</doc:term>
+ <doc:definition>To change regional formats</doc:definition>
+ </doc:item>
+ <doc:item>
+ <doc:term>org.freedesktop.accounts.user-administration</doc:term>
+ <doc:definition>To change egional formats of another user</doc:definition>
+ </doc:item>
+ </doc:list>
+ </doc:permission>
+ <doc:errors>
+ <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error>
+ <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error>
+ </doc:errors>
+ </doc:doc>
+ </method>
+
<method name="SetXSession">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="user_set_x_session"/>
@@ -871,6 +906,16 @@
</doc:doc>
</property>
+ <property name="FormatsLocale" type="s" access="read">
+ <doc:doc>
+ <doc:description>
+ <doc:para>
+ The users regional formats, as a locale specification like "de_DE.UTF-8".
+ </doc:para>
+ </doc:description>
+ </doc:doc>
+ </property>
+
<property name="XSession" type="s" access="read">
<doc:doc>
<doc:description>
diff --git a/src/libaccountsservice/act-user.c b/src/libaccountsservice/act-user.c
index 9125d43..daf634c 100644
--- a/src/libaccountsservice/act-user.c
+++ b/src/libaccountsservice/act-user.c
@@ -93,6 +93,7 @@ enum
PROP_BACKGROUND_FILE,
PROP_ICON_FILE,
PROP_LANGUAGE,
+ PROP_FORMATS_LOCALE,
PROP_X_SESSION,
PROP_IS_LOADED
};
@@ -273,6 +274,7 @@ act_user_class_init (ActUserClass *class)
"The real name to display for this user.",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
g_object_class_install_property (gobject_class,
PROP_BACKGROUND_FILE,
g_param_spec_string ("background-file",
@@ -406,6 +408,15 @@ act_user_class_init (ActUserClass *class)
"User's locale.",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class,
+ PROP_FORMATS_LOCALE,
+ g_param_spec_string ("formats-locale",
+ "Regional Formats",
+ "User's regional formats.",
+ NULL,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
g_object_class_install_property (gobject_class,
PROP_X_SESSION,
g_param_spec_string ("x-session",
@@ -1086,6 +1097,25 @@ act_user_get_language (ActUser *user)
return accounts_user_get_language (user->accounts_proxy);
}
+/**
+ * act_user_get_formats_locale:
+ * @user: a #ActUser
+ *
+ * Returns the path to the configured formats locale of @user.
+ *
+ * Returns: (transfer none): a path to an icon
+ */
+const char *
+act_user_get_formats_locale (ActUser *user)
+{
+ g_return_val_if_fail (ACT_IS_USER (user), NULL);
+
+ if (user->accounts_proxy == NULL)
+ return NULL;
+
+ return accounts_user_get_formats_locale (user->accounts_proxy);
+}
+
/**
* act_user_get_x_session:
* @user: a #ActUser
@@ -1440,6 +1470,36 @@ act_user_set_password_expiration_policy (ActUser *user,
}
}
+/**
+ * act_user_set_formats_locale:
+ * @user: the user object to alter.
+ * @formats_locale: a locale (e.g. en_US.utf8)
+ *
+ * Assigns a new formats locale for @user.
+ *
+ * Note this function is synchronous and ignores errors.
+ **/
+void
+act_user_set_formats_locale (ActUser *user,
+ const char *formats_locale)
+{
+ g_autoptr(GError) error = NULL;
+
+ g_return_if_fail (ACT_IS_USER (user));
+ g_return_if_fail (formats_locale != NULL);
+ g_return_if_fail (ACCOUNTS_IS_USER (user->accounts_proxy));
+
+ if (!accounts_user_call_set_formats_locale_sync (user->accounts_proxy,
+ formats_locale,
+ G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION,
+ -1,
+ NULL,
+ &error)) {
+ g_warning ("SetFormatsLocale for formats_locale %s call failed: %s", formats_locale, error->message);
+ return;
+ }
+}
+
/**
* act_user_set_email:
* @user: the user object to alter.
diff --git a/src/libaccountsservice/act-user.h b/src/libaccountsservice/act-user.h
index 82019f5..4281553 100644
--- a/src/libaccountsservice/act-user.h
+++ b/src/libaccountsservice/act-user.h
@@ -72,6 +72,7 @@ gboolean act_user_is_nonexistent (ActUser *user);
const char *act_user_get_background_file (ActUser *user);
const char *act_user_get_icon_file (ActUser *user);
const char *act_user_get_language (ActUser *user);
+const char *act_user_get_formats_locale (ActUser *user);
const char * const *act_user_get_languages (ActUser *user);
const char *act_user_get_x_session (ActUser *user);
const char *act_user_get_session (ActUser *user);
@@ -101,6 +102,8 @@ void act_user_set_user_expiration_policy (ActUser *user,
void act_user_set_language (ActUser *user,
const char *language);
+void act_user_set_formats_locale (ActUser *user,
+ const char *formats_locale);
void act_user_set_background_file (ActUser *user,
const char *background_file);
void act_user_set_languages (ActUser *user,
diff --git a/src/user.c b/src/user.c
index 16a1cbd..9b5cf7d 100644
--- a/src/user.c
+++ b/src/user.c
@@ -545,6 +545,11 @@ user_update_from_keyfile (User *user,
accounts_user_set_language (ACCOUNTS_USER (user), s);
g_clear_pointer (&s, g_free);
}
+ s = g_key_file_get_string (keyfile, "User", "FormatsLocale", NULL);
+ if (s != NULL) {
+ accounts_user_set_formats_locale (ACCOUNTS_USER (user), s);
+ g_clear_pointer (&s, g_free);
+ }
s = g_key_file_get_string (keyfile, "User", "XSession", NULL);
if (s != NULL) {
@@ -672,6 +677,9 @@ user_save_to_keyfile (User *user,
if (accounts_user_get_session_type (ACCOUNTS_USER (user)))
g_key_file_set_string (keyfile, "User", "SessionType", accounts_user_get_session_type (ACCOUNTS_USER (user)));
+ if (accounts_user_get_formats_locale (ACCOUNTS_USER (user)))
+ g_key_file_set_string (keyfile, "User", "FormatsLocale", accounts_user_get_formats_locale (ACCOUNTS_USER (user)));
+
if (accounts_user_get_xsession (ACCOUNTS_USER (user)))
g_key_file_set_string (keyfile, "User", "XSession", accounts_user_get_xsession (ACCOUNTS_USER (user)));
@@ -1583,6 +1591,54 @@ user_set_session_type (AccountsUser *auser,
return TRUE;
}
+static void
+user_change_formats_locale_authorized_cb (Daemon *daemon,
+ User *user,
+ GDBusMethodInvocation *context,
+ gpointer user_data)
+
+{
+ const gchar *formats_locale = user_data;
+
+ if (g_strcmp0 (accounts_user_get_formats_locale (ACCOUNTS_USER (user)), formats_locale) != 0) {
+ accounts_user_set_formats_locale (ACCOUNTS_USER (user), formats_locale);
+
+ save_extra_data (user);
+ }
+
+ accounts_user_complete_set_formats_locale (ACCOUNTS_USER (user), context);
+}
+
+static gboolean
+user_set_formats_locale (AccountsUser *auser,
+ GDBusMethodInvocation *context,
+ const gchar *formats_locale)
+{
+ User *user = (User*)auser;
+ int uid;
+ const gchar *action_id;
+
+ if (!get_caller_uid (context, &uid)) {
+ throw_error (context, ERROR_FAILED, "identifying caller failed");
+ return FALSE;
+ }
+
+ if (accounts_user_get_uid (ACCOUNTS_USER (user)) == (uid_t) uid)
+ action_id = "org.freedesktop.accounts.change-own-user-data";
+ else
+ action_id = "org.freedesktop.accounts.user-administration";
+
+ daemon_local_check_auth (user->daemon,
+ user,
+ action_id,
+ user_change_formats_locale_authorized_cb,
+ context,
+ g_strdup (formats_locale),
+ (GDestroyNotify) g_free);
+
+ return TRUE;
+}
+
static void
user_change_x_session_authorized_cb (Daemon *daemon,
User *user,
@@ -2802,6 +2858,7 @@ user_accounts_user_iface_init (AccountsUserIface *iface)
iface->handle_set_automatic_login = user_set_automatic_login;
iface->handle_set_background_file = user_set_background_file;
iface->handle_set_email = user_set_email;
+ iface->handle_set_formats_locale = user_set_formats_locale;
iface->handle_set_home_directory = user_set_home_directory;
iface->handle_set_icon_file = user_set_icon_file;
iface->handle_set_language = user_set_language;
--
2.27.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。