From eb38c9c625e6967523632985c339d3dd5e8bded8 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 23 Aug 2023 15:29:57 +0200 Subject: [PATCH 01/19] add dbus method for ui locales --- rust/agama-dbus-server/src/locale.rs | 40 ++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/rust/agama-dbus-server/src/locale.rs b/rust/agama-dbus-server/src/locale.rs index fa25bd5a3e..467176b581 100644 --- a/rust/agama-dbus-server/src/locale.rs +++ b/rust/agama-dbus-server/src/locale.rs @@ -1,7 +1,7 @@ use crate::error::Error; use agama_lib::connection_to; use anyhow::Context; -use std::process::Command; +use std::{process::Command, fs::read_dir}; use zbus::{dbus_interface, Connection}; pub struct Locale { @@ -9,6 +9,7 @@ pub struct Locale { keymap: String, timezone_id: String, supported_locales: Vec, + ui_locale: String, } #[dbus_interface(name = "org.opensuse.Agama.Locale1")] @@ -89,6 +90,40 @@ impl Locale { Ok(()) } + + #[dbus_interface(property, name="UILocale")] + fn ui_locale(&self) -> &str { + &self.ui_locale + } + + #[dbus_interface(property, name="UILocale")] + fn set_ui_locale(&mut self, locale: &str) { + self.ui_locale = locale.to_string(); + } + + /// Gets list of locales available on system. + /// + /// # Examples + /// + /// ``` + /// use agama_dbus_server::locale::Locale; + /// let locale = Locale::new(); + /// assert!(locale.available_ui_locales().unwrap().len() > 0); + /// ``` + #[dbus_interface(name = "ListUILocales")] + pub fn available_ui_locales(&self) -> Result, Error> { + // english is always available ui localization + let mut result = vec!["en".to_string()]; + const DIR : &str = "/usr/share/YaST2/locale/"; + let entries = read_dir(DIR).context("Reading YaST2 locale")?; + for entry in entries { + let entry = entry.context("Failed to read entry in YaST2 locale dir")?; + result.push(entry.file_name().to_str().context("Non UTF entry found in YaST2 locale dir")?.to_string()); + } + + Ok(result) + } + /* support only keymaps for console for now fn list_x11_keyboards(&self) -> Result, Error> { let keyboards = agama_locale_data::get_xkeyboards()?; @@ -176,12 +211,13 @@ impl Locale { } impl Locale { - fn new() -> Self { + pub fn new() -> Self { Self { locales: vec!["en_US.UTF-8".to_string()], keymap: "us".to_string(), timezone_id: "America/Los_Angeles".to_string(), supported_locales: vec!["en_US.UTF-8".to_string()], + ui_locale: "en".to_string() } } } From dde3bb74221ea369d3c7df87d78504efbb19b5e6 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Thu, 24 Aug 2023 16:37:27 +0200 Subject: [PATCH 02/19] add code for ruby services to respect ui locale --- rust/agama-dbus-server/src/locale.rs | 4 +- service/lib/agama/dbus/clients/locale.rb | 27 +++++++++++- service/lib/agama/ui_locale.rb | 53 ++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 service/lib/agama/ui_locale.rb diff --git a/rust/agama-dbus-server/src/locale.rs b/rust/agama-dbus-server/src/locale.rs index 467176b581..af11ff0c5d 100644 --- a/rust/agama-dbus-server/src/locale.rs +++ b/rust/agama-dbus-server/src/locale.rs @@ -108,10 +108,10 @@ impl Locale { /// ``` /// use agama_dbus_server::locale::Locale; /// let locale = Locale::new(); - /// assert!(locale.available_ui_locales().unwrap().len() > 0); + /// assert!(locale.list_ui_locales().unwrap().len() > 0); /// ``` #[dbus_interface(name = "ListUILocales")] - pub fn available_ui_locales(&self) -> Result, Error> { + pub fn list_ui_locales(&self) -> Result, Error> { // english is always available ui localization let mut result = vec!["en".to_string()]; const DIR : &str = "/usr/share/YaST2/locale/"; diff --git a/service/lib/agama/dbus/clients/locale.rb b/service/lib/agama/dbus/clients/locale.rb index ff27aaf19c..5d059a45b2 100644 --- a/service/lib/agama/dbus/clients/locale.rb +++ b/service/lib/agama/dbus/clients/locale.rb @@ -44,6 +44,18 @@ def supported_locales=(locales) dbus_object.supported_locales = locales end + def ui_locale + dbus_object.ui_locale + end + + def ui_locale=(locale) + dbus_object.ui_locale = locale + end + + def available_ui_locales + dbus_object.list_ui_locales + end + # Finishes the language installation def finish dbus_object.Commit @@ -58,7 +70,20 @@ def finish def on_language_selected(&block) on_properties_change(dbus_object) do |_, changes, _| languages = changes["Locales"] - block.call(languages) + block.call(languages) if languages + end + end + + # Registers a callback to run when the ui locale changes + # + # @note Signal subscription is done only once. Otherwise, the latest subscription overrides + # the previous one. + # + # @param block [Proc] Callback to run when an ui locale changes + def on_ui_locale_change(&block) + on_properties_change(dbus_object) do |_, changes, _| + locale = changes["UILocale"] + block.call(locale) if locale end end diff --git a/service/lib/agama/ui_locale.rb b/service/lib/agama/ui_locale.rb new file mode 100644 index 0000000000..098f83a0f2 --- /dev/null +++ b/service/lib/agama/ui_locale.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +# Copyright (c) [2022] SUSE LLC +# +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, contact SUSE LLC. +# +# To contact SUSE LLC about this file by physical or electronic mail, you may +# find current contact information at www.suse.com. + +require "yast" + +Yast.import "WFM" + +module Agama + # Object responsible for managing changes of localization produced by dbus backend. + class UILocale + include Yast::I18n + # creates new UILocale object that will handle change of UI locale. + # + # @param [Agama::DBus::Clients::Locale] locale_client to communicate with dbus service + # @yield block is callback that is called when ui locale is changed + # to allow user to call methods that needs retranslation + def initialize(locale_client, &block) + @client = locale_client + change_locale(@client.ui_locale) + on_ui_locale_change do |locale| + change_locale(locale) + block.call(locale) + end + end + + private + + def change_locale(locale) + # TODO: check if we can use UTF-8 everywhere including strange arch consoles + Yast::WFM.SetLanguage(locale, "UTF-8") + # explicit call to textdomain to force fast gettext change of language ASAP + textdomain "installation" + end + end +end From 117f1abf3f631a5765b101148f3f286cc0fc854c Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Thu, 24 Aug 2023 21:42:08 +0200 Subject: [PATCH 03/19] add calls to respect ui locale and drop no longer used language service --- service/lib/agama/dbus/language_service.rb | 93 ---------------------- service/lib/agama/dbus/manager_service.rb | 6 ++ service/lib/agama/dbus/software_service.rb | 10 +++ service/lib/agama/dbus/storage_service.rb | 10 +++ service/lib/agama/ui_locale.rb | 2 +- 5 files changed, 27 insertions(+), 94 deletions(-) delete mode 100644 service/lib/agama/dbus/language_service.rb diff --git a/service/lib/agama/dbus/language_service.rb b/service/lib/agama/dbus/language_service.rb deleted file mode 100644 index 3f4f2ac41e..0000000000 --- a/service/lib/agama/dbus/language_service.rb +++ /dev/null @@ -1,93 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) [2022] SUSE LLC -# -# All Rights Reserved. -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of version 2 of the GNU General Public License as published -# by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, contact SUSE LLC. -# -# To contact SUSE LLC about this file by physical or electronic mail, you may -# find current contact information at www.suse.com. - -require "dbus" -require "agama/dbus/bus" -require "agama/dbus/language" -require "agama/language" - -module Agama - module DBus - # D-Bus service (org.opensuse.Agama.Language1) - # - # It connects to the system D-Bus and answers requests on objects below - # `/org/opensuse/Agama/Language1`. - class LanguageService - # Service name - # - # @return [String] - SERVICE_NAME = "org.opensuse.Agama.Language1" - private_constant :SERVICE_NAME - - # Agama D-Bus - # - # @return [::DBus::BusConnection] - attr_reader :bus - - # @param _config [Config] Configuration object - # @param logger [Logger] - def initialize(_config, logger = nil) - @logger = logger || Logger.new($stdout) - @bus = Bus.current - end - - # Exports the installer object through the D-Bus service - def export - dbus_objects.each { |o| service.export(o) } - - paths = dbus_objects.map(&:path).join(", ") - logger.info "Exported #{paths} objects" - end - - # Call this from some main loop to dispatch the D-Bus messages - def dispatch - bus.dispatch_message_queue - end - - private - - # @return [Logger] - attr_reader :logger - - # @return [::DBus::ObjectServer] - def service - @service ||= bus.request_service(SERVICE_NAME) - end - - # @return [Array<::DBus::Object>] - def dbus_objects - @dbus_objects ||= [ - language_dbus - ] - end - - # @return [Agama::DBus::Language] - def language_dbus - @language_dbus ||= Agama::DBus::Language.new(language_backend(logger), logger) - end - - # @return [Agama::Language] - def language_backend(logger) - @language_backend ||= Agama::Language.new(logger).tap(&:probe) - end - end - end -end diff --git a/service/lib/agama/dbus/manager_service.rb b/service/lib/agama/dbus/manager_service.rb index 06c5e21cc3..c769e08326 100644 --- a/service/lib/agama/dbus/manager_service.rb +++ b/service/lib/agama/dbus/manager_service.rb @@ -24,9 +24,11 @@ require "agama/users" require "agama/cockpit_manager" require "agama/dbus/bus" +require "agama/dbus/clients/locale" require "agama/dbus/manager" require "agama/dbus/users" require "agama/dbus/storage/proposal" +require "agama/ui_locale" module Agama module DBus @@ -76,6 +78,10 @@ def initialize(config, logger = nil) # @note The service runs its startup phase def start setup_cockpit + # We need locale for data from users + locale_client = Clients::Locale.new + # TODO: test if we need to pass block with additional actions + @ui_locale = UILocale.new(locale_client) export manager.on_progress_change { dispatch } # make single thread more responsive manager.startup_phase diff --git a/service/lib/agama/dbus/software_service.rb b/service/lib/agama/dbus/software_service.rb index 22d73a1f51..8ce6ed9a4b 100644 --- a/service/lib/agama/dbus/software_service.rb +++ b/service/lib/agama/dbus/software_service.rb @@ -21,8 +21,10 @@ require "dbus" require "agama/dbus/bus" +require "agama/dbus/clients/locale" require "agama/dbus/software" require "agama/software" +require "agama/ui_locale" module Agama module DBus @@ -48,6 +50,14 @@ def initialize(config, logger = nil) @backend.on_progress_change { dispatch } end + # Starts software service. It does more then just #export method. + def start + locale_client = Clients::Locale.new + # TODO: test if we need to pass block with additional actions + @ui_locale = UILocale.new(locale_client) + export + end + # Exports the software object through the D-Bus service def export dbus_objects.each { |o| service.export(o) } diff --git a/service/lib/agama/dbus/storage_service.rb b/service/lib/agama/dbus/storage_service.rb index 2f4ee60167..4688c44576 100644 --- a/service/lib/agama/dbus/storage_service.rb +++ b/service/lib/agama/dbus/storage_service.rb @@ -21,8 +21,10 @@ require "dbus" require "agama/dbus/bus" +require "agama/dbus/clients/locale" require "agama/dbus/storage" require "agama/storage" +require "agama/ui_locale" module Agama module DBus @@ -48,6 +50,14 @@ def bus Bus.current end + # Starts storage service. It does more then just #export method. + def start + locale_client = Clients::Locale.new + # TODO: test if we need to pass block with additional actions + @ui_locale = UILocale.new(locale_client) + export + end + # Exports the storage proposal object through the D-Bus service def export dbus_objects.each { |o| service.export(o) } diff --git a/service/lib/agama/ui_locale.rb b/service/lib/agama/ui_locale.rb index 098f83a0f2..199ec7061c 100644 --- a/service/lib/agama/ui_locale.rb +++ b/service/lib/agama/ui_locale.rb @@ -37,7 +37,7 @@ def initialize(locale_client, &block) change_locale(@client.ui_locale) on_ui_locale_change do |locale| change_locale(locale) - block.call(locale) + block.call(locale) if block_given? end end From 161ffac047c3024e100de3f74c72b88f535d9c74 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 28 Aug 2023 22:46:39 +0200 Subject: [PATCH 04/19] use dbus names as ruby friendly names does not work --- service/lib/agama/dbus/clients/locale.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/service/lib/agama/dbus/clients/locale.rb b/service/lib/agama/dbus/clients/locale.rb index 5d059a45b2..b3385bb4ce 100644 --- a/service/lib/agama/dbus/clients/locale.rb +++ b/service/lib/agama/dbus/clients/locale.rb @@ -45,15 +45,15 @@ def supported_locales=(locales) end def ui_locale - dbus_object.ui_locale + dbus_object.UILocale end def ui_locale=(locale) - dbus_object.ui_locale = locale + dbus_object.UILocale = locale end def available_ui_locales - dbus_object.list_ui_locales + dbus_object.ListUILocales end # Finishes the language installation From 1db2adfdbd4d5680f7eaf34920a8af4653bbf033 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 28 Aug 2023 22:55:59 +0200 Subject: [PATCH 05/19] try another way to access properties --- service/lib/agama/dbus/clients/locale.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/service/lib/agama/dbus/clients/locale.rb b/service/lib/agama/dbus/clients/locale.rb index b3385bb4ce..38b82859e3 100644 --- a/service/lib/agama/dbus/clients/locale.rb +++ b/service/lib/agama/dbus/clients/locale.rb @@ -26,6 +26,8 @@ module DBus module Clients # D-Bus client for locale configuration class Locale < Base + INTERFACE_NAME = "org.opensuse.Agama.Locale1" + def initialize super @@ -45,11 +47,11 @@ def supported_locales=(locales) end def ui_locale - dbus_object.UILocale + dbus_object[INTERFACE_NAME]["UILocale"] end def ui_locale=(locale) - dbus_object.UILocale = locale + dbus_object[INTERFACE_NAME]["UILocale"] = locale end def available_ui_locales From bc444da413012d2b99e6e7c361f38cae10e6084c Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 28 Aug 2023 23:01:38 +0200 Subject: [PATCH 06/19] fix calling ui locale chagne --- service/lib/agama/ui_locale.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/lib/agama/ui_locale.rb b/service/lib/agama/ui_locale.rb index 199ec7061c..9d7fb78e03 100644 --- a/service/lib/agama/ui_locale.rb +++ b/service/lib/agama/ui_locale.rb @@ -35,7 +35,7 @@ class UILocale def initialize(locale_client, &block) @client = locale_client change_locale(@client.ui_locale) - on_ui_locale_change do |locale| + @client.on_ui_locale_change do |locale| change_locale(locale) block.call(locale) if block_given? end From 5c9b40793fbe4bb0d5ac8e973f148f8bd0bf1d7d Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 29 Aug 2023 12:23:03 +0200 Subject: [PATCH 07/19] add some logging to debug language switching --- service/lib/agama/ui_locale.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/service/lib/agama/ui_locale.rb b/service/lib/agama/ui_locale.rb index 9d7fb78e03..9f1358f041 100644 --- a/service/lib/agama/ui_locale.rb +++ b/service/lib/agama/ui_locale.rb @@ -27,6 +27,7 @@ module Agama # Object responsible for managing changes of localization produced by dbus backend. class UILocale include Yast::I18n + include Yast::Logger # creates new UILocale object that will handle change of UI locale. # # @param [Agama::DBus::Clients::Locale] locale_client to communicate with dbus service @@ -46,6 +47,7 @@ def initialize(locale_client, &block) def change_locale(locale) # TODO: check if we can use UTF-8 everywhere including strange arch consoles Yast::WFM.SetLanguage(locale, "UTF-8") + log.info "set yast language to #{locale} WFM: #{Yast::WFM.GetLanguage}" # explicit call to textdomain to force fast gettext change of language ASAP textdomain "installation" end From ee231003b34bb1de70bb702dcbc29d3c99e3d19f Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 29 Aug 2023 13:42:09 +0200 Subject: [PATCH 08/19] log also gettext locale --- service/lib/agama/ui_locale.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/service/lib/agama/ui_locale.rb b/service/lib/agama/ui_locale.rb index 9f1358f041..41dd14023e 100644 --- a/service/lib/agama/ui_locale.rb +++ b/service/lib/agama/ui_locale.rb @@ -50,6 +50,7 @@ def change_locale(locale) log.info "set yast language to #{locale} WFM: #{Yast::WFM.GetLanguage}" # explicit call to textdomain to force fast gettext change of language ASAP textdomain "installation" + log.info "gettext locale #{FastGettext.locale}" end end end From fdb4f5d2e76d389349a6bc652567473476da36bd Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 29 Aug 2023 17:57:40 +0200 Subject: [PATCH 09/19] add value with testing localized string --- service/lib/agama/ui_locale.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/service/lib/agama/ui_locale.rb b/service/lib/agama/ui_locale.rb index 41dd14023e..f3aef0b76a 100644 --- a/service/lib/agama/ui_locale.rb +++ b/service/lib/agama/ui_locale.rb @@ -22,6 +22,7 @@ require "yast" Yast.import "WFM" +Yast.import "Label" module Agama # Object responsible for managing changes of localization produced by dbus backend. @@ -51,6 +52,7 @@ def change_locale(locale) # explicit call to textdomain to force fast gettext change of language ASAP textdomain "installation" log.info "gettext locale #{FastGettext.locale}" + log.info "testing localized string #{Yast::Label.YesButton}" end end end From 5d388b6814fa020ef4ba8a81a1169d0b87c95dc1 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 29 Aug 2023 21:23:19 +0200 Subject: [PATCH 10/19] try to set lang to get localized string from libstorage --- service/lib/agama/ui_locale.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/service/lib/agama/ui_locale.rb b/service/lib/agama/ui_locale.rb index f3aef0b76a..5309e12fd1 100644 --- a/service/lib/agama/ui_locale.rb +++ b/service/lib/agama/ui_locale.rb @@ -48,6 +48,8 @@ def initialize(locale_client, &block) def change_locale(locale) # TODO: check if we can use UTF-8 everywhere including strange arch consoles Yast::WFM.SetLanguage(locale, "UTF-8") + # explicitelly set ENV to get localization also from libraries like libstorage + ENV["LANG"] = locale + ".UTF-8" log.info "set yast language to #{locale} WFM: #{Yast::WFM.GetLanguage}" # explicit call to textdomain to force fast gettext change of language ASAP textdomain "installation" From 9dd368a8efd639f203f57cea6048e07af1a59ce3 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 29 Aug 2023 21:48:17 +0200 Subject: [PATCH 11/19] remove unnecessary logging --- service/lib/agama/ui_locale.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/service/lib/agama/ui_locale.rb b/service/lib/agama/ui_locale.rb index 5309e12fd1..7ba7ed558b 100644 --- a/service/lib/agama/ui_locale.rb +++ b/service/lib/agama/ui_locale.rb @@ -22,7 +22,6 @@ require "yast" Yast.import "WFM" -Yast.import "Label" module Agama # Object responsible for managing changes of localization produced by dbus backend. @@ -50,11 +49,9 @@ def change_locale(locale) Yast::WFM.SetLanguage(locale, "UTF-8") # explicitelly set ENV to get localization also from libraries like libstorage ENV["LANG"] = locale + ".UTF-8" - log.info "set yast language to #{locale} WFM: #{Yast::WFM.GetLanguage}" + log.info "set yast language to #{locale}" # explicit call to textdomain to force fast gettext change of language ASAP textdomain "installation" - log.info "gettext locale #{FastGettext.locale}" - log.info "testing localized string #{Yast::Label.YesButton}" end end end From 7b53b1316d5da3905ddd04d8b0bfa838a19db372 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 30 Aug 2023 10:58:21 +0200 Subject: [PATCH 12/19] Update service/lib/agama/ui_locale.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Imobach González Sosa --- service/lib/agama/ui_locale.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/lib/agama/ui_locale.rb b/service/lib/agama/ui_locale.rb index 7ba7ed558b..cc67ba9475 100644 --- a/service/lib/agama/ui_locale.rb +++ b/service/lib/agama/ui_locale.rb @@ -24,7 +24,7 @@ Yast.import "WFM" module Agama - # Object responsible for managing changes of localization produced by dbus backend. + # Object responsible for managing changes of localization produced by D-Bus backend. class UILocale include Yast::I18n include Yast::Logger From 12d3d469df9b7fda5e829064c77866fb68fd8217 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 30 Aug 2023 10:58:38 +0200 Subject: [PATCH 13/19] Update rust/agama-dbus-server/src/locale.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Imobach González Sosa --- rust/agama-dbus-server/src/locale.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rust/agama-dbus-server/src/locale.rs b/rust/agama-dbus-server/src/locale.rs index af11ff0c5d..1d48d91067 100644 --- a/rust/agama-dbus-server/src/locale.rs +++ b/rust/agama-dbus-server/src/locale.rs @@ -118,7 +118,8 @@ impl Locale { let entries = read_dir(DIR).context("Reading YaST2 locale")?; for entry in entries { let entry = entry.context("Failed to read entry in YaST2 locale dir")?; - result.push(entry.file_name().to_str().context("Non UTF entry found in YaST2 locale dir")?.to_string()); + let name = entry.file_name.to_str().context("Non valid UTF entry found in YaST2 locale dir")?; + result.push(name.to_string()) } Ok(result) From fde8366a02c62e9026058d3657a93cdd2b67c5eb Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 30 Aug 2023 11:04:31 +0200 Subject: [PATCH 14/19] apply rust fmt --- rust/agama-dbus-server/src/locale.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/rust/agama-dbus-server/src/locale.rs b/rust/agama-dbus-server/src/locale.rs index 1d48d91067..501837833f 100644 --- a/rust/agama-dbus-server/src/locale.rs +++ b/rust/agama-dbus-server/src/locale.rs @@ -1,7 +1,7 @@ use crate::error::Error; use agama_lib::connection_to; use anyhow::Context; -use std::{process::Command, fs::read_dir}; +use std::{fs::read_dir, process::Command}; use zbus::{dbus_interface, Connection}; pub struct Locale { @@ -90,21 +90,20 @@ impl Locale { Ok(()) } - - #[dbus_interface(property, name="UILocale")] + #[dbus_interface(property, name = "UILocale")] fn ui_locale(&self) -> &str { &self.ui_locale } - #[dbus_interface(property, name="UILocale")] + #[dbus_interface(property, name = "UILocale")] fn set_ui_locale(&mut self, locale: &str) { - self.ui_locale = locale.to_string(); + self.ui_locale = locale.to_string(); } /// Gets list of locales available on system. - /// + /// /// # Examples - /// + /// /// ``` /// use agama_dbus_server::locale::Locale; /// let locale = Locale::new(); @@ -114,11 +113,14 @@ impl Locale { pub fn list_ui_locales(&self) -> Result, Error> { // english is always available ui localization let mut result = vec!["en".to_string()]; - const DIR : &str = "/usr/share/YaST2/locale/"; + const DIR: &str = "/usr/share/YaST2/locale/"; let entries = read_dir(DIR).context("Reading YaST2 locale")?; for entry in entries { let entry = entry.context("Failed to read entry in YaST2 locale dir")?; - let name = entry.file_name.to_str().context("Non valid UTF entry found in YaST2 locale dir")?; + let name = entry + .file_name + .to_str() + .context("Non valid UTF entry found in YaST2 locale dir")?; result.push(name.to_string()) } @@ -218,7 +220,7 @@ impl Locale { keymap: "us".to_string(), timezone_id: "America/Los_Angeles".to_string(), supported_locales: vec!["en_US.UTF-8".to_string()], - ui_locale: "en".to_string() + ui_locale: "en".to_string(), } } } From d365fa58c71bb58fe9dc318dfc4fb279ca159770 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 30 Aug 2023 11:28:15 +0200 Subject: [PATCH 15/19] apply clippy suggestions --- rust/agama-dbus-server/src/locale.rs | 13 ++++++++++--- rust/agama-dbus-server/src/questions/answers.rs | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/rust/agama-dbus-server/src/locale.rs b/rust/agama-dbus-server/src/locale.rs index 501837833f..c42f07e86d 100644 --- a/rust/agama-dbus-server/src/locale.rs +++ b/rust/agama-dbus-server/src/locale.rs @@ -118,10 +118,11 @@ impl Locale { for entry in entries { let entry = entry.context("Failed to read entry in YaST2 locale dir")?; let name = entry - .file_name + .file_name() .to_str() - .context("Non valid UTF entry found in YaST2 locale dir")?; - result.push(name.to_string()) + .context("Non valid UTF entry found in YaST2 locale dir")? + .to_string(); + result.push(name) } Ok(result) @@ -225,6 +226,12 @@ impl Locale { } } +impl Default for Locale { + fn default() -> Self { + Self::new() + } +} + pub async fn start_service(address: &str) -> Result> { const SERVICE_NAME: &str = "org.opensuse.Agama.Locale1"; const SERVICE_PATH: &str = "/org/opensuse/Agama/Locale1"; diff --git a/rust/agama-dbus-server/src/questions/answers.rs b/rust/agama-dbus-server/src/questions/answers.rs index d6ef306e59..60ade14fa0 100644 --- a/rust/agama-dbus-server/src/questions/answers.rs +++ b/rust/agama-dbus-server/src/questions/answers.rs @@ -73,7 +73,7 @@ impl Answers { } fn find_answer(&self, question: &GenericQuestion) -> Option<&Answer> { - self.answers.iter().find(|a| a.responds(&question)) + self.answers.iter().find(|a| a.responds(question)) } } From cc7cfc5cda9c9658b58d480664494f1d732ceebc Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 30 Aug 2023 13:42:32 +0200 Subject: [PATCH 16/19] adapt manager test --- service/test/agama/dbus/manager_service_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/service/test/agama/dbus/manager_service_test.rb b/service/test/agama/dbus/manager_service_test.rb index 24bdfed15f..a43b6e0ff1 100644 --- a/service/test/agama/dbus/manager_service_test.rb +++ b/service/test/agama/dbus/manager_service_test.rb @@ -29,7 +29,8 @@ let(:config) { Agama::Config.new } let(:logger) { Logger.new($stdout, level: :warn) } let(:manager) { Agama::Manager.new(config, logger) } - let(:bus) { instance_double(Agama::DBus::Bus, request_name: nil) } + let(:locale_service) { double(object: double(instrospect: nil)) } + let(:bus) { instance_double(Agama::DBus::Bus, request_name: nil, service: locale_service) } let(:bus_service) do instance_double(::DBus::ObjectServer, export: nil) end From ba9dc9b32ee03b03c8bfbb61e26034853ce15d04 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 30 Aug 2023 13:50:57 +0200 Subject: [PATCH 17/19] fix typo --- service/test/agama/dbus/manager_service_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/test/agama/dbus/manager_service_test.rb b/service/test/agama/dbus/manager_service_test.rb index a43b6e0ff1..5b786dd88f 100644 --- a/service/test/agama/dbus/manager_service_test.rb +++ b/service/test/agama/dbus/manager_service_test.rb @@ -29,7 +29,7 @@ let(:config) { Agama::Config.new } let(:logger) { Logger.new($stdout, level: :warn) } let(:manager) { Agama::Manager.new(config, logger) } - let(:locale_service) { double(object: double(instrospect: nil)) } + let(:locale_service) { double(object: double(introspect: nil)) } let(:bus) { instance_double(Agama::DBus::Bus, request_name: nil, service: locale_service) } let(:bus_service) do instance_double(::DBus::ObjectServer, export: nil) From 51ca721abac29fcc5150674c62a9b599508a87fd Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 30 Aug 2023 14:00:38 +0200 Subject: [PATCH 18/19] improve mocking --- service/test/agama/dbus/manager_service_test.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/service/test/agama/dbus/manager_service_test.rb b/service/test/agama/dbus/manager_service_test.rb index 5b786dd88f..c46b5402a1 100644 --- a/service/test/agama/dbus/manager_service_test.rb +++ b/service/test/agama/dbus/manager_service_test.rb @@ -29,7 +29,10 @@ let(:config) { Agama::Config.new } let(:logger) { Logger.new($stdout, level: :warn) } let(:manager) { Agama::Manager.new(config, logger) } - let(:locale_service) { double(object: double(introspect: nil)) } + let(:locale_interface) { double("[]" => "en", on_signal: nil) } + let(:locale_service) do + double(object: double(introspect: nil, path: "test", "[]": locale_interface)) + end let(:bus) { instance_double(Agama::DBus::Bus, request_name: nil, service: locale_service) } let(:bus_service) do instance_double(::DBus::ObjectServer, export: nil) From ffb9dfc506e05ad98933e983b11e7bb10cb49adb Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 30 Aug 2023 14:58:36 +0200 Subject: [PATCH 19/19] changes --- rust/package/agama-cli.changes | 7 ++++++- service/package/rubygem-agama.changes | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/rust/package/agama-cli.changes b/rust/package/agama-cli.changes index 47ac92275d..9cc5544198 100644 --- a/rust/package/agama-cli.changes +++ b/rust/package/agama-cli.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Wed Aug 30 12:57:59 UTC 2023 - Josef Reidinger + +- Locale service: add value for UI locale (gh#openSUSE/agama#725) + ------------------------------------------------------------------- Thu Aug 3 08:34:14 UTC 2023 - Imobach Gonzalez Sosa @@ -8,7 +13,7 @@ Thu Aug 3 08:34:14 UTC 2023 - Imobach Gonzalez Sosa InstallSettings and NetworkSettings. - Improve error reporting when working with the "config" subcommand. - + ------------------------------------------------------------------- Wed Aug 2 10:03:18 UTC 2023 - Imobach Gonzalez Sosa diff --git a/service/package/rubygem-agama.changes b/service/package/rubygem-agama.changes index fd7da96943..a3f9bbd55e 100644 --- a/service/package/rubygem-agama.changes +++ b/service/package/rubygem-agama.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Wed Aug 30 12:39:18 UTC 2023 - Josef Reidinger + +- Respect UI locale in dbus services (gh#openSUSE/agama#725) + ------------------------------------------------------------------- Mon Aug 28 07:59:26 UTC 2023 - Knut Anderssen