1 Star 0 Fork 13

周正亮/accountsservice

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
accountsservice-22.08.8-kylin-add-formats-locale-support.patch 11.61 KB
一键复制 编辑 原始数据 按行查看 历史
王琪 提交于 2023-11-08 13:33 . Upgrade to version 23.13.9
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhou-zhengliang/accountsservice.git
git@gitee.com:zhou-zhengliang/accountsservice.git
zhou-zhengliang
accountsservice
accountsservice
master

搜索帮助