Skip to content

Commit

Permalink
Clean-up unused method from locale D-Bus interface
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Nov 23, 2023
1 parent 4a7d1a4 commit 716deba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 97 deletions.
65 changes: 2 additions & 63 deletions rust/agama-dbus-server/src/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{helpers, keyboard::get_keymaps};
use crate::{error::Error, keyboard::Keymap};
use agama_locale_data::{KeymapId, LocaleCode};
use anyhow::Context;
use std::{fs::read_dir, process::Command};
use std::process::Command;
use zbus::{dbus_interface, Connection};

pub struct Locale {
Expand Down Expand Up @@ -88,18 +88,6 @@ impl Locale {
Ok(())
}

#[dbus_interface(property)]
fn supported_locales(&self) -> Vec<String> {
self.supported_locales.to_owned()
}

#[dbus_interface(property)]
fn set_supported_locales(&mut self, locales: Vec<String>) -> Result<(), zbus::fdo::Error> {
self.supported_locales = locales;
// TODO: handle if current selected locale contain something that is no longer supported
Ok(())
}

#[dbus_interface(property, name = "UILocale")]
fn ui_locale(&self) -> &str {
&self.ui_locale
Expand All @@ -111,55 +99,6 @@ impl Locale {
helpers::set_service_locale(locale);
}

/// Returns a list of the locales available in the system.
///
/// # Examples
///
/// ```
/// use agama_dbus_server::locale::Locale;
/// let locale = Locale::default();
/// assert!(locale.list_ui_locales().unwrap().len() > 0);
/// ```
#[dbus_interface(name = "ListUILocales")]
pub fn list_ui_locales(&self) -> Result<Vec<String>, 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);
if entries.is_err() {
// if dir is not there act like if it is empty
return Ok(result);
}

for entry in entries.unwrap() {
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")?
.to_string();
result.push(name)
}

Ok(result)
}

/* support only keymaps for console for now
fn list_x11_keyboards(&self) -> Result<Vec<(String, String)>, Error> {
let keyboards = agama_locale_data::get_xkeyboards()?;
let ret = keyboards
.keyboard.iter()
.map(|k| (k.id.clone(), k.description.clone()))
.collect();
Ok(ret)
}
fn set_x11_keyboard(&mut self, keyboard: &str) {
self.keyboard_id = keyboard.to_string();
}
*/

#[dbus_interface(name = "ListKeymaps")]
/// Returns a list of the supported keymaps.
///
/// Each element of the list contains:
Expand Down Expand Up @@ -286,7 +225,7 @@ impl Default for Locale {
Self {
locales: vec!["en_US.UTF-8".to_string()],
timezone_id: "America/Los_Angeles".to_string(),
supported_locales: vec!["en_US.UTF-8".to_string(), "es_ES.UTF-8".to_string()],
supported_locales: vec!["en_US.UTF-8".to_string()],
ui_locale: "en".to_string(),
keymap: "us".parse().unwrap(),
keymaps: vec![],
Expand Down
31 changes: 17 additions & 14 deletions rust/agama-lib/src/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,40 +75,43 @@ trait Manager {
) -> zbus::Result<Vec<std::collections::HashMap<String, zbus::zvariant::OwnedValue>>>;
}

#[dbus_proxy(interface = "org.opensuse.Agama1.Locale", assume_defaults = true)]
#[dbus_proxy(
interface = "org.opensuse.Agama1.Locale",
default_service = "org.opensuse.Agama1",
default_path = "/org/opensuse/Agama1/Locale"
)]
trait Locale {
/// Commit method
fn commit(&self) -> zbus::Result<()>;

/// ListKeymaps method
fn list_keymaps(&self) -> zbus::Result<Vec<(String, String)>>;

/// ListLocales method
fn list_locales(&self) -> zbus::Result<Vec<(String, String, String)>>;

/// ListTimezones method
fn list_timezones(&self, locale: &str) -> zbus::Result<Vec<(String, String)>>;
fn list_timezones(&self) -> zbus::Result<Vec<(String, Vec<String>)>>;

/// ListVConsoleKeyboards method
#[dbus_proxy(name = "ListVConsoleKeyboards")]
fn list_vconsole_keyboards(&self) -> zbus::Result<Vec<String>>;
/// Keymap property
#[dbus_proxy(property)]
fn keymap(&self) -> zbus::Result<String>;
fn set_keymap(&self, value: &str) -> zbus::Result<()>;

/// Locales property
#[dbus_proxy(property)]
fn locales(&self) -> zbus::Result<Vec<String>>;
fn set_locales(&self, value: &[&str]) -> zbus::Result<()>;

/// SupportedLocales property
#[dbus_proxy(property)]
fn supported_locales(&self) -> zbus::Result<Vec<String>>;
fn set_supported_locales(&self, value: &[&str]) -> zbus::Result<()>;

/// Timezone property
#[dbus_proxy(property)]
fn timezone(&self) -> zbus::Result<String>;
fn set_timezone(&self, value: &str) -> zbus::Result<()>;

/// VConsoleKeyboard property
#[dbus_proxy(property, name = "VConsoleKeyboard")]
fn vconsole_keyboard(&self) -> zbus::Result<String>;
fn set_vconsole_keyboard(&self, value: &str) -> zbus::Result<()>;
/// UILocale property
#[dbus_proxy(property, name = "UILocale")]
fn uilocale(&self) -> zbus::Result<String>;
fn set_uilocale(&self, value: &str) -> zbus::Result<()>;
}

#[dbus_proxy(
Expand Down
4 changes: 0 additions & 4 deletions service/lib/agama/dbus/clients/locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ def ui_locale=(locale)
dbus_object[INTERFACE_NAME]["UILocale"] = locale
end

def available_ui_locales
dbus_object.ListUILocales
end

# Finishes the language installation
def finish
dbus_object.Commit
Expand Down
16 changes: 0 additions & 16 deletions web/src/client/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,6 @@ class L10nClient {
this.client = new DBusClient(LOCALE_SERVICE, address);
}

/**
* Available locales to translate the installer UI.
*
* Note that name and territory are localized to its own language:
* { id: "es", name: "Español", territory: "España" }
*
* @return {Promise<Array<Locale>>}
*/
async UILocales() {
const proxy = await this.client.proxy(LOCALE_IFACE);
const locales = await proxy.ListUILocales();

// TODO: D-Bus currently returns the id only
return locales.map(id => this.buildLocale([id, "", ""]));
}

/**
* Selected locale to translate the installer UI.
*
Expand Down

0 comments on commit 716deba

Please sign in to comment.