diff -Nru kylin-ai-runtime-1.0.0.0/debian/changelog kylin-ai-runtime-1.0.0.0/debian/changelog --- kylin-ai-runtime-1.0.0.0/debian/changelog 2024-09-16 11:28:55.000000000 +0800 +++ kylin-ai-runtime-1.0.0.0/debian/changelog 2024-09-24 10:34:10.000000000 +0800 @@ -1,3 +1,9 @@ +kylin-ai-runtime (1.0.0.0-ok0.18) nile; urgency=medium + + * 通过dbus获取系统语言 + + -- zhaokexin <zhaokexin@kylinos.cn> Tue, 24 Sep 2024 10:34:10 +0800 + kylin-ai-runtime (1.0.0.0-ok0.17) nile; urgency=medium * 提示词国际化 diff -Nru kylin-ai-runtime-1.0.0.0/debian/control kylin-ai-runtime-1.0.0.0/debian/control --- kylin-ai-runtime-1.0.0.0/debian/control 2024-09-16 11:28:55.000000000 +0800 +++ kylin-ai-runtime-1.0.0.0/debian/control 2024-09-24 10:34:10.000000000 +0800 @@ -17,7 +17,7 @@ Package: kylin-ai-runtime Architecture: any Multi-Arch: same -Depends: ${misc:Depends}, ${shlibs:Depends}, libkylin-ai-default-key +Depends: ${misc:Depends}, ${shlibs:Depends}, libkylin-ai-default-key, libdbus-1-3, libglib2.0-0 Description: Kylin AI SDK Runtime This package provides the runtime environment for Kylin AI SDK. It includes the necessary libraries and configurations to support AI-related functionalities diff -Nru kylin-ai-runtime-1.0.0.0/debian/patches/0035-update-changelog.patch kylin-ai-runtime-1.0.0.0/debian/patches/0035-update-changelog.patch --- kylin-ai-runtime-1.0.0.0/debian/patches/0035-update-changelog.patch 1970-01-01 08:00:00.000000000 +0800 +++ kylin-ai-runtime-1.0.0.0/debian/patches/0035-update-changelog.patch 2024-09-24 10:34:10.000000000 +0800 @@ -0,0 +1,230 @@ +From: zhaokexin <zhaokexin@kylinos.cn> +Date: Tue, 24 Sep 2024 10:36:21 +0800 +Subject: update changelog + +--- + CMakeLists.txt | 2 +- + src/config/engineconfiguration.cpp | 186 ++++++++++++++++++++++++++++++++----- + 2 files changed, 163 insertions(+), 25 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 170785f..9a9fb5a 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -85,7 +85,7 @@ target_link_libraries( + ${GIO_LIBRARIES} + ${PORTAUDIO_LIBRARIES} + ${OPENSSL_LIBRARIES} +- ${DBUS_LIB} ++ ${DBus1_LIBRARIES} + ${GLIBC_LIB} + ) + +diff --git a/src/config/engineconfiguration.cpp b/src/config/engineconfiguration.cpp +index eb77c03..73843fc 100644 +--- a/src/config/engineconfiguration.cpp ++++ b/src/config/engineconfiguration.cpp +@@ -230,41 +230,179 @@ char* getSystemLanguage(const char *username) + return NULL; + } + +- char lang[128] = "\0"; +- char *language = NULL; +- char path[128] = "\0"; +- char line[512] = "\0"; +- FILE *fp = NULL; +- sprintf(path, "/home/%s/.pam_environment", username); +- +- fp = fopen(path, "r"); +- if(!fp) { ++ char *user = NULL; ++ DBusConnection *conn; ++ DBusError err; ++ ++ dbus_error_init(&err); ++ conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); ++ ++ if (dbus_error_is_set(&err)) { ++ fprintf(stderr, "DBus error: %s\n", err.message); ++ dbus_error_free(&err); ++ } ++ ++ if (NULL == conn) { + return NULL; + } +- while (fgets(line, sizeof(line), fp)) { +- sscanf(line, "%s", lang); +- if(strcmp(lang, "LANG") == 0) { +- language = (char*)malloc(sizeof(char) * 24); +- if(!language) { +- fclose(fp); +- return NULL; +- } +- sscanf(line, "%*[^=]=%[a-zA-Z_]", language); +- break; +- } ++ ++ DBusMessage *info_msg = NULL; ++ DBusPendingCall *sendMsgPending = NULL; ++ DBusMessage *replyMsg = NULL; ++ ++ //创建用户 ++ info_msg = dbus_message_new_method_call("org.freedesktop.Accounts", // target for the method call ++ "/org/freedesktop/Accounts", // object to call on ++ "org.freedesktop.Accounts", // interface to call on ++ "FindUserByName"); // method name ++ if (!info_msg) { // -1 is default timeout ++ fprintf(stderr, "DBus error: %s\n", "dbus_message_new_method_call调用失败\n"); ++ return NULL; ++ } ++ ++ if (!dbus_message_append_args(info_msg, DBUS_TYPE_STRING, &username, DBUS_TYPE_INVALID)) { ++ fprintf(stderr, "DBus error: %s\n", "d-bus append args fail !\n"); ++ return NULL; ++ } ++ ++ if (!dbus_connection_send_with_reply(conn, info_msg, &sendMsgPending, -1)) { ++ fprintf(stderr, "DBus error: %s\n", "d-bus send message fail !\n"); ++ return NULL; ++ } ++ ++ if (sendMsgPending == NULL) { ++ fprintf(stderr, "DBus error: %s\n", "d-bus pending message is NULL !\n"); ++ return NULL; ++ } ++ ++ dbus_connection_flush(conn); ++ ++ if (info_msg) { ++ dbus_message_unref(info_msg); ++ } ++ ++ dbus_pending_call_block(sendMsgPending); ++ ++ replyMsg = dbus_pending_call_steal_reply(sendMsgPending); ++ ++ if (replyMsg == NULL) { ++ fprintf(stderr, "DBus error: %s\n", "get reply message fail !\n"); ++ return NULL; ++ } ++ ++ if (sendMsgPending) { ++ dbus_pending_call_unref(sendMsgPending); ++ } ++ ++ if (dbus_message_get_type(replyMsg) == DBUS_MESSAGE_TYPE_ERROR) { ++ fprintf(stderr, "DBus error: %s\n", dbus_message_get_error_name(replyMsg)); ++ dbus_message_unref(replyMsg); ++ return NULL; ++ } ++ ++ DBusMessageIter args; ++ ++ if (!dbus_message_iter_init(replyMsg, &args)) { ++ dbus_message_unref(replyMsg); ++ fprintf(stderr, "DBus error: %s\n", "d-bus reply message fail !\n"); ++ return NULL; ++ } else { ++ dbus_message_iter_get_basic(&args, &user); ++ } ++ ++ if (replyMsg) { ++ dbus_message_unref(replyMsg); ++ } ++ printf("user = %s\n", user); ++ ++ DBusMessage *msg = NULL; ++ DBusPendingCall *sendPending = NULL; ++ DBusMessage *replyLangMsg = NULL; ++ ++ //创建用户 ++ msg = dbus_message_new_method_call("org.freedesktop.Accounts", // target for the method call ++ user, // object to call on ++ "org.freedesktop.DBus.Properties", // interface to call on ++ "Get"); // method name ++ if (!msg) { // -1 is default timeout ++ fprintf(stderr, "DBus error: %s\n", "dbus_message_new_method_call调用失败\n"); ++ return NULL; ++ } ++ char *interface = "org.freedesktop.Accounts.User"; ++ char *property = "Language"; ++ ++ if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID)) { ++ fprintf(stderr, "DBus error: %s\n", "d-bus append args fail !\n"); ++ return NULL; ++ } ++ ++ if (!dbus_connection_send_with_reply(conn, msg, &sendPending, -1)) { ++ fprintf(stderr, "DBus error: %s\n", "d-bus send message fail !\n"); ++ return NULL; ++ } ++ ++ if (sendPending == NULL) { ++ fprintf(stderr, "DBus error: %s\n", "d-bus pending message is NULL !\n"); ++ return NULL; ++ } ++ ++ dbus_connection_flush(conn); ++ ++ if (msg) { ++ dbus_message_unref(msg); ++ } ++ ++ dbus_pending_call_block(sendPending); ++ ++ replyLangMsg = dbus_pending_call_steal_reply(sendPending); ++ ++ if (replyLangMsg == NULL) { ++ fprintf(stderr, "DBus error: %s\n", "get reply message fail !\n"); ++ return NULL; ++ } ++ ++ if (sendPending) { ++ dbus_pending_call_unref(sendPending); ++ } ++ ++ if (dbus_message_get_type(replyLangMsg) == DBUS_MESSAGE_TYPE_ERROR) { ++ fprintf(stderr, "DBus error: %s\n", dbus_message_get_error_name(replyLangMsg)); ++ dbus_message_unref(replyLangMsg); ++ return NULL; ++ } ++ ++ DBusMessageIter iter; ++ char *lang = NULL; ++ ++ // 解析回复消息 ++ if (!dbus_message_iter_init(replyLangMsg, &iter) || ++ dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) { ++ fprintf(stderr, "DBus error: %s\n", "DBus reply parsing failed\n"); ++ dbus_message_unref(replyLangMsg); ++ dbus_connection_unref(conn); ++ return NULL; + } +- fclose(fp); +- return language; ++ ++ // 释放reply ++ dbus_message_unref(replyLangMsg); ++ ++ dbus_message_iter_recurse(&iter, &iter); ++ dbus_message_iter_get_basic(&iter, &lang); ++ dbus_connection_unref(conn); ++ return lang; + } + + std::string getLanguageName() { + char* eUser = getUser(); + char* language = getSystemLanguage(eUser); + fprintf(stderr, "system_language = %s\n", language); +- if (language == NULL) { ++ if (std::strstr(language, "en")) { + return "en_US"; + } +- return language; ++ if (std::strstr(language, "zh")) { ++ return "zh_CN"; ++ } ++ return "en_US"; + } + + } diff -Nru kylin-ai-runtime-1.0.0.0/debian/patches/series kylin-ai-runtime-1.0.0.0/debian/patches/series --- kylin-ai-runtime-1.0.0.0/debian/patches/series 2024-09-16 11:28:55.000000000 +0800 +++ kylin-ai-runtime-1.0.0.0/debian/patches/series 2024-09-24 10:34:10.000000000 +0800 @@ -32,3 +32,4 @@ 0032-build-update-changloe.patch 0033-build-update-debian-changelog.patch 0034-update-changelog.patch +0035-update-changelog.patch