diff options
author | Vitezslav Crhonek <vcrhonek@redhat.com> | 2014-06-04 11:32:33 +0200 |
---|---|---|
committer | Vitezslav Crhonek <vcrhonek@redhat.com> | 2014-06-04 11:32:33 +0200 |
commit | ed6b657bd768704f54e235b09b22b921c05dc8db (patch) | |
tree | cd9289d2c246e8c3a797393aad4c0ff06fed8ef6 | |
parent | b904d5b9bf5f988ec46d1014b591fa553f3db752 (diff) | |
download | openlmi-providers-ed6b657bd768704f54e235b09b22b921c05dc8db.tar.gz openlmi-providers-ed6b657bd768704f54e235b09b22b921c05dc8db.tar.xz openlmi-providers-ed6b657bd768704f54e235b09b22b921c05dc8db.zip |
New provider: Locale
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | README | 7 | ||||
-rw-r--r-- | mof/60_LMI_Locale.mof | 292 | ||||
-rw-r--r-- | mof/CMakeLists.txt | 4 | ||||
-rw-r--r-- | openlmi-providers.spec | 62 | ||||
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/locale/90_LMI_Locale_Profile.mof.skel | 22 | ||||
-rw-r--r-- | src/locale/CMakeLists.txt | 42 | ||||
-rw-r--r-- | src/locale/LMI_LocaleProvider.c | 499 | ||||
-rwxr-xr-x | src/locale/cmpiLMI_Locale-cimprovagt | 21 | ||||
-rw-r--r-- | src/locale/localed.c | 258 | ||||
-rw-r--r-- | src/locale/localed.h | 58 |
12 files changed, 1269 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index bcea097..c9f0ab1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ option(WITH-PCP "Build PCP provider" ON) option(WITH-INDMANAGER "Build indication manager" ON) option(WITH-SOFTWARE "Build software provider" ON) option(WITH-JOURNALD "Build journald provider" ON) +option(WITH-LOCALE "Build locale provider" ON) option(WITH-DEVASSISTANT "Install Developer Assistant templates" OFF) @@ -83,6 +83,10 @@ Following providers are part of this sub-project: This is a CIM interface for the PCP (Performance Co-Pilot) daemon. Allows reading of PCP metrics on the local host. +* Locale + Locale provider is a CIM interface for systemd-localed. Allows to control + system locale variables (LANG, LC_PAPER, ...) and keyboard mapping for + virtual console and X11. ******************************************************************************* * Build Dependencies * @@ -126,6 +130,9 @@ Provider specific dependencies: - dbus-devel * PCP - python-pcp +* Locale + - glib2-devel 2.26+ + - systemd 30+ (systemd-localed) ******************************************************************************* * Compilation and installation * diff --git a/mof/60_LMI_Locale.mof b/mof/60_LMI_Locale.mof new file mode 100644 index 0000000..623e258 --- /dev/null +++ b/mof/60_LMI_Locale.mof @@ -0,0 +1,292 @@ +/* + * Copyright (C) 2014 Red Hat, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Vitezslav Crhonek <vcrhonek@redhat.com> + */ + +[ Description("Class representing Linux Locale. The system locale " + "controls the language settings of system services and of " + "the UI before the user logs in, such as the display manager, " + "as well as the default for users after login."), + Provider("cmpi:cmpiLMI_Locale") ] +class LMI_Locale : CIM_SystemSetting +{ + [ Description("Main locale property. When defined, its value is " + "used as default for all other non-defined LC* categories. \n" + "The property should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string Lang; + + [ Description("Defines behavior of the character handling and " + "classification functions. \n" + "The property should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCCType; + + [ Description("Defines the information used by the input/output " + "functions, when they are advised to use the locale settings. \n" + "The property should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCNumeric; + + [ Description("Defines how to display the current time in a locally " + "acceptable form; for example, most of Europe uses a 24-hour clock " + "versus the 12-hour clock used in the United States. \n" + "The property should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCTime; + + [ Description("Defines the behavior of the functions, which are " + "used to compare and/or sort strings in the local alphabet. \n" + "The property should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCCollate; + + [ Description("Defines the way numbers are usually printed, with " + "details such as decimal point versus decimal comma. \n" + "The property should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCMonetary; + + [ Description("Defines the language messages are displayed in and " + "what an affirmative or negative answer looks like. \n" + "The property should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCMessages; + + [ Description("Defines the settings relating to the dimensions of " + "the standard paper size (e.g., US letter versus A4). \n" + "The property should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCPaper; + + [ Description("Defines the settings that describe the formats used " + "to address persons. \n" + "The property should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCName; + + [ Description("Defines the rules for the formats (e.g., postal " + "addresses) used to describe locations and geography-related " + "items. \n" + "The property should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCAddress; + + [ Description("Defines the settings that describe the formats to be " + "used with telephone services. \n" + "The property should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCTelephone; + + [ Description("Defines the settings relating to the measurement system " + "in the locale (i.e., metric versus US customary units). \n" + "The property should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCMeasurement; + + [ Description("Defines the settings that relate to the metadata for " + "the locale. \n" + "The property should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCIdentification; + + [ Description("System keyboard mapping used on the text console. " + "The property should be a keyboard mapping name " + "(such as 'de' or 'us'). ") ] + string VConsoleKeymap; + + [ Description("Toggle keyboard mapping used on the text console. " + "The property should be a keyboard mapping name " + "(such as 'de' or 'us'). ") ] + string VConsoleKeymapToggle; + + [ Description("System default keyboard mapping for X11 - the graphical " + "UI before the user logs in, such as the display manager, as well " + "as the default for users after login. The property should be a " + "keyboard mapping name (such as 'de' or 'us'). Individual layouts " + "are comma separated (e. g. 'us,cz,de').") ] + string X11Layouts; + + [ Description("Model of default keyboard mapping for X11. The property " + "should be a keyboard model name (such as 'pc105' or 'thinkpad60').") ] + string X11Model; + + [ Description("Variant of default keyboard mapping for X11. The property " + "should be a keyboard variant name (such as 'dvorak' or 'qwerty').") ] + string X11Variant; + + [ Description("Options for default keyboard mapping for X11. The property " + "should be a keyboard option name (such as 'altwin:menu' or " + "'grp:lalt_toggle'). Individual options are comma separated " + "(e. g. 'grp:alt_shift_toggle,shift:both_capslock').") ] + string X11Options; + + [ Description("Method used to set the system locale. If you set " + "a new system locale, all old system locale settings will be " + "dropped, and the new settings will be saved to disk. " + "It will also be passed to the system manager, and subsequently " + "started daemons will inherit the new system locale from it. " + "Note that already running daemons will not learn about the new " + "system locale.") ] + uint32 SetLocale( + [ IN, Description("Sets the Lang property. \n" + "The value should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string Lang, + [ IN, Description("Sets the LCCType property. \n" + "The value should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCCType, + [ IN, Description("Sets the LCNumeric property. \n" + "The value should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCNumeric, + [ IN, Description("Sets the LCTime property. \n" + "The value should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCTime, + [ IN, Description("Sets the LCCollate property. \n" + "The value should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCCollate, + [ IN, Description("Sets the LCMonetar property. \n" + "The value should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCMonetary, + [ IN, Description("Sets the LCMessages property. \n" + "The value should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCMessages, + [ IN, Description("Sets the LCPaper property. \n" + "The value should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCPaper, + [ IN, Description("Sets the LCName property. \n" + "The value should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCName, + [ IN, Description("Sets the LCAddress property. \n" + "The value should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCAddress, + [ IN, Description("Sets the LCTelephone property. \n" + "The value should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCTelephone, + [ IN, Description("Sets the LCMeasurement property. \n" + "The value should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCMeasurement, + [ IN, Description("Sets the LCIdentification property. \n" + "The value should be in format " + "[language[_territory][.codeset][@modifier]], " + "for example, 'en_AU.UTF-8' (Australian English using " + "the UTF-8 encoding).") ] + string LCIdentification); + + [ Description("Method used to set the key mapping on the " + "virtual console. ") ] + uint32 SetVConsoleKeyboard( + [ Required, IN, Description("Sets the keyboard mapping " + "on the virtual console (such as 'us' or 'cz-qwerty'), " + "new mapping is applied instantly. Required parameter.") ] + string Keymap, + [ IN, Description("Sets toggle keyboard mapping " + "on the virtual console (such as 'us' or 'cz-qwerty'). " + "Optional parameter.") ] + string KeymapToggle, + [ IN, Description("Convert may be set to optionally convert " + "the console keyboard configuration to X11 keyboard " + "mappings. Optional parameter. If set to TRUE, the nearest " + "X11 keyboard setting for the chosen console setting is set.") ] + boolean Convert); + + [ Description("Method used to set the default key mapping of " + "the X11 server. ") ] + uint32 SetX11Keyboard( + [ Required, IN, Description("Sets X11 keyboard mapping (such as 'de' " + "or 'us'). Individual layouts are comma separated " + "(e. g. 'us,cz,de'). Required parameter.") ] + string Layouts, + [ IN, Description("Sets X11 keyboard model (such as 'pc105' " + "or 'thinkpad60'). Optional parameter.") ] + string Model, + [ IN, Description("Sets X11 keyboard variant (such as 'dvorak' " + "or 'qwerty'). Optional parameter.") ] + string Variant, + [ IN, Description("Sets X11 keyboard options (such as 'altwin:menu' " + "or 'grp:lalt_toggle'). Individual options are comma separated " + "(e. g. 'grp:alt_shift_toggle,shift:both_capslock'). " + "Optional parameter.") ] + string Options, + [ IN, Description("Convert may be set to optionally convert " + "the X11 keyboard mapping to console keyboard configuration. " + "Optional parameter. If set to TRUE, the nearest console keyboard " + "setting for the chosen X11 setting is set.") ] + boolean Convert); +}; diff --git a/mof/CMakeLists.txt b/mof/CMakeLists.txt index cbc971b..d9a2985 100644 --- a/mof/CMakeLists.txt +++ b/mof/CMakeLists.txt @@ -51,3 +51,7 @@ if (WITH-JOURNALD) DESTINATION share/openlmi-providers/) endif (WITH-JOURNALD) +if (WITH-LOCALE) + install(FILES 60_LMI_Locale.mof DESTINATION share/openlmi-providers/) +endif (WITH-LOCALE) + diff --git a/openlmi-providers.spec b/openlmi-providers.spec index dc975d5..6f962e6 100644 --- a/openlmi-providers.spec +++ b/openlmi-providers.spec @@ -19,6 +19,7 @@ %global with_pcp 1 %global with_realmd 1 %global with_fan 1 +%global with_locale 1 %if 0%{?rhel} == 6 %global with_journald 0 @@ -27,6 +28,7 @@ %global with_pcp 0 %global with_realmd 0 %global with_fan 0 +%global with_locale 0 %global interop root/PG_InterOp %endif @@ -36,7 +38,7 @@ Name: openlmi-providers Version: 0.4.2 -Release: 11%{?dist} +Release: 12%{?dist} Summary: Set of basic CIM providers %if 0%{?suse_version} @@ -508,6 +510,15 @@ Requires: %{name}-devel%{?_isa} = %{providers_version_release} This package contains template files for Developer Assistant. %endif +%if 0%{?with_locale} +%package -n openlmi-locale +Summary: CIM provider for controlling system locale and keyboard mapping +Requires: %{name}%{?_isa} = %{version}-%{release} + +%description -n openlmi-locale +%{summary}. +%endif + %prep %setup -q @@ -551,6 +562,9 @@ pushd %{_target_platform} %if ! 0%{with_fan} -DWITH-FAN=OFF \ %endif +%if ! 0%{with_locale} + -DWITH-LOCALE=OFF \ +%endif %{source_dir} popd @@ -868,6 +882,16 @@ cp -pr tools/openlmitheme/* $RPM_BUILD_ROOT/%{python_sitelib}/sphinx/themes/open %{_datadir}/devassistant/ %endif +%if 0%{with_locale} +%files -n openlmi-locale +%doc README COPYING +%{_libdir}/cmpi/libcmpiLMI_Locale.so +%{_datadir}/%{name}/60_LMI_Locale.mof +%{_datadir}/%{name}/60_LMI_Locale.reg +%{_datadir}/%{name}/90_LMI_Locale_Profile.mof +%attr(755, root, root) %{_libexecdir}/pegasus/cmpiLMI_Locale-cimprovagt +%endif + %pre # If upgrading, deregister old version if [ "$1" -gt 1 ]; then @@ -1013,6 +1037,17 @@ if [ "$1" -gt 1 ]; then fi >> %logfile 2>&1 %endif +%if 0%{with_locale} +%pre -n openlmi-locale +if [ "$1" -gt 1 ]; then + %{_bindir}/openlmi-mof-register -v %{providers_version} unregister \ + %{_datadir}/%{name}/60_LMI_Locale.mof \ + %{_datadir}/%{name}/60_LMI_Locale.reg || :; + %{_bindir}/openlmi-mof-register --just-mofs -n %{interop} -c tog-pegasus unregister \ + %{_datadir}/%{name}/90_LMI_Locale_Profile.mof || :; +fi >> %logfile 2>&1 +%endif + %if 0%{with_fan} %post -n openlmi-fan # Register Schema and Provider @@ -1116,6 +1151,17 @@ if [ "$1" -ge 1 ]; then fi >> %logfile 2>&1 %endif +%if 0%{with_locale} +%post -n openlmi-locale +if [ "$1" -ge 1 ]; then + %{_bindir}/openlmi-mof-register -v %{providers_version} register \ + %{_datadir}/%{name}/60_LMI_Locale.mof \ + %{_datadir}/%{name}/60_LMI_Locale.reg || :; + %{_bindir}/openlmi-mof-register --just-mofs -n %{interop} -c tog-pegasus register \ + %{_datadir}/%{name}/90_LMI_Locale_Profile.mof || :; +fi >> %logfile 2>&1 +%endif + %if 0%{with_fan} %preun -n openlmi-fan # Deregister only if not upgrading @@ -1232,7 +1278,21 @@ if [ "$1" -eq 0 ]; then fi >> %logfile 2>&1 %endif +%if 0%{with_locale} +%preun -n openlmi-locale +if [ "$1" -eq 0 ]; then + %{_bindir}/openlmi-mof-register -v %{providers_version} unregister \ + %{_datadir}/%{name}/60_LMI_Locale.mof \ + %{_datadir}/%{name}/60_LMI_Locale.reg || :; + %{_bindir}/openlmi-mof-register --just-mofs -n %{interop} -c tog-pegasus unregister \ + %{_datadir}/%{name}/90_LMI_Locale_Profile.mof || :; +fi >> %logfile 2>&1 +%endif + %changelog +* Thu May 29 2014 Vitezslav Crhonek <vcrhonek@redhat.com> - 0.4.2-12 +- Add openlmi-locale subpackage + * Mon May 26 2014 Tomas Bzatek <tbzatek@redhat.com> 0.4.2-11 - Include journald indication filters diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e0fbb4e..dbf6ed1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,6 +58,10 @@ if (WITH-PCP) add_subdirectory(pcp) endif (WITH-PCP) +if (WITH-LOCALE) + add_subdirectory(locale) +endif (WITH-LOCALE) + file(GLOB INIT_SKELS "*/lmi/*/__init__.skel") foreach(SKEL ${INIT_SKELS}) #TODO: find a way how to do it in cmake diff --git a/src/locale/90_LMI_Locale_Profile.mof.skel b/src/locale/90_LMI_Locale_Profile.mof.skel new file mode 100644 index 0000000..1a82092 --- /dev/null +++ b/src/locale/90_LMI_Locale_Profile.mof.skel @@ -0,0 +1,22 @@ +instance of PG_ProviderProfileCapabilities +{ + CapabilityID = "@CLASS@"; + + ProviderModuleName = "cmpiLMI_Locale"; + + ProviderName = "@CLASS@"; + + RegisteredProfile = 0; + + OtherRegisteredProfile = "OpenLMI-Locale"; + OtherProfileOrganization = "OpenLMI"; + + ProfileVersion = "@VERSION@"; + + RegisteredSubProfiles = {}; + + ConformingElements = { + "@CLASS@" + }; +}; + diff --git a/src/locale/CMakeLists.txt b/src/locale/CMakeLists.txt new file mode 100644 index 0000000..c32d8c9 --- /dev/null +++ b/src/locale/CMakeLists.txt @@ -0,0 +1,42 @@ + +set(PROVIDER_NAME Locale) +set(LIBRARY_NAME cmpiLMI_${PROVIDER_NAME}) +set(MOF 60_LMI_Locale.mof) +set(CIMPROVAGT_SCRIPT cmpiLMI_${PROVIDER_NAME}-cimprovagt) + +set(provider_SRCS + localed.c +) + +konkretcmpi_generate(${MOF} + CIM_PROVIDERS + CIM_HEADERS + CIM_CLASSES +) + +add_library(${LIBRARY_NAME} SHARED + ${provider_SRCS} + ${CIM_PROVIDERS} + ${CIM_HEADERS} +) + +# Require libgio +pkg_check_modules(GIO REQUIRED gio-2.0) + +include_directories(${CMAKE_CURRENT_BINARY_DIR} + ${CMPI_INCLUDE_DIR} + ${GIO_INCLUDE_DIRS}) +target_link_libraries(${LIBRARY_NAME} + openlmicommon + ${KONKRETCMPI_LIBRARIES} + ${GIO_LIBRARIES}) + +# Create registration file +set(TARGET_MOF "${CMAKE_BINARY_DIR}/mof/90_LMI_Locale_Profile.mof") +profile_mof_generate("90_LMI_Locale_Profile.mof.skel" "${TARGET_MOF}" "LMI_Locale") + +cim_registration(${PROVIDER_NAME} ${LIBRARY_NAME} ${MOF} share/openlmi-providers "${TARGET_MOF}") + +install(TARGETS ${LIBRARY_NAME} DESTINATION lib${LIB_SUFFIX}/cmpi) +install(PROGRAMS ${CIMPROVAGT_SCRIPT} DESTINATION libexec/pegasus) +install(FILES ${TARGET_MOF} DESTINATION share/openlmi-providers/) diff --git a/src/locale/LMI_LocaleProvider.c b/src/locale/LMI_LocaleProvider.c new file mode 100644 index 0000000..8759161 --- /dev/null +++ b/src/locale/LMI_LocaleProvider.c @@ -0,0 +1,499 @@ +/* + * Copyright (C) 2014 Red Hat, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Vitezslav Crhonek <vcrhonek@redhat.com> + */ + +#include <konkret/konkret.h> +#include "LMI_Locale.h" +#include "localed.h" + +const char LangEnvVar[] = "LANG="; +const char LCCTypeEnvVar[] = "LC_CTYPE="; +const char LCNumericEnvVar[] = "LC_NUMERIC="; +const char LCTimeEnvVar[] = "LC_TIME="; +const char LCCollateEnvVar[] = "LC_COLLATE="; +const char LCMonetaryEnvVar[] = "LC_MONETARY="; +const char LCMessagesEnvVar[] = "LC_MESSAGES="; +const char LCPaperEnvVar[] = "LC_PAPER="; +const char LCNameEnvVar[] = "LC_NAME="; +const char LCAddressEnvVar[] = "LC_ADDRESS="; +const char LCTelephoneEnvVar[] = "LC_TELEPHONE="; +const char LCMeasurementEnvVar[] = "LC_MEASUREMENT="; +const char LCIdentificationEnvVar[] = "LC_IDENTIFICATION="; + +#define SETVAL(NAM) \ +if ((NAM)->exists && !(NAM)->null) { \ + tmps = (char *) calloc((strlen(NAM ## EnvVar) + strlen((NAM)->chars) + 1), sizeof(char)); \ + if (tmps == NULL) { \ + KSetStatus2(cb, status, ERR_FAILED, "Insufficient memory.\n"); \ + KUint32_Set(&result, 2); \ + free(tmps); \ + goto error; \ + } \ + strncpy(tmps, NAM ## EnvVar, strlen(NAM ## EnvVar)); \ + LocaleValue[LocaleCnt] = strncat(tmps, (NAM)->chars, strlen((NAM)->chars)); \ + LocaleCnt++; \ +} + +#define GETVAL(NAM) \ +if (strncmp(cloc->Locale[i], NAM ## EnvVar, strlen(NAM ## EnvVar)) == 0) { \ + LMI_Locale_Set_ ## NAM(&w, cloc->Locale[i] + strlen(NAM ## EnvVar)); \ + continue; \ +} + +static const CMPIBroker* _cb = NULL; + +static void LMI_LocaleInitialize(const CMPIContext *ctx) +{ + lmi_init(provider_name, _cb, ctx, provider_config_defaults); + locale_init(); +} + +static CMPIStatus LMI_LocaleCleanup( + CMPIInstanceMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_LocaleEnumInstanceNames( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + return KDefaultEnumerateInstanceNames( + _cb, mi, cc, cr, cop); +} + +static CMPIStatus LMI_LocaleEnumInstances( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + CimLocale *cloc; + + cloc = locale_get_properties(); + if (cloc == NULL) { + KReturn(ERR_FAILED); + } + + LMI_Locale w; + LMI_Locale_Init(&w, _cb, KNameSpace(cop)); + + LMI_Locale_Set_CreationClassName(&w, LMI_Locale_ClassName); + LMI_Locale_Set_SettingID(&w, "System Locale"); + LMI_Locale_Set_SystemCreationClassName(&w, lmi_get_system_creation_class_name()); + LMI_Locale_Set_SystemName(&w, lmi_get_system_name()); + + for (int i = 0; i < cloc->LocaleCnt; i++) { + GETVAL(Lang) + GETVAL(LCCType) + GETVAL(LCNumeric) + GETVAL(LCTime) + GETVAL(LCCollate) + GETVAL(LCMonetary) + GETVAL(LCMessages) + GETVAL(LCPaper) + GETVAL(LCName) + GETVAL(LCAddress) + GETVAL(LCTelephone) + GETVAL(LCMeasurement) + GETVAL(LCIdentification) + } + + LMI_Locale_Set_VConsoleKeymap(&w, cloc->VConsoleKeymap); + LMI_Locale_Set_VConsoleKeymapToggle(&w, cloc->VConsoleKeymapToggle); + LMI_Locale_Set_X11Layouts(&w, cloc->X11Layouts); + LMI_Locale_Set_X11Model(&w, cloc->X11Model); + LMI_Locale_Set_X11Variant(&w, cloc->X11Variant); + LMI_Locale_Set_X11Options(&w, cloc->X11Options); + + KReturnInstance(cr, w); + + locale_free(cloc); + KReturn(OK); +} + +static CMPIStatus LMI_LocaleGetInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + return KDefaultGetInstance( + _cb, mi, cc, cr, cop, properties); +} + +static CMPIStatus LMI_LocaleCreateInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_LocaleModifyInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci, + const char** properties) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_LocaleDeleteInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_LocaleExecQuery( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* lang, + const char* query) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +CMInstanceMIStub( + LMI_Locale, + LMI_Locale, + _cb, + LMI_LocaleInitialize(ctx)) + +static CMPIStatus LMI_LocaleMethodCleanup( + CMPIMethodMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_LocaleInvokeMethod( + CMPIMethodMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* meth, + const CMPIArgs* in, + CMPIArgs* out) +{ + return LMI_Locale_DispatchMethod( + _cb, mi, cc, cr, cop, meth, in, out); +} + +CMMethodMIStub( + LMI_Locale, + LMI_Locale, + _cb, + LMI_LocaleInitialize(ctx)) + +KUint32 LMI_Locale_VerifyOKToApplyToMSE( + const CMPIBroker* cb, + CMPIMethodMI* mi, + const CMPIContext* context, + const LMI_LocaleRef* self, + const KRef* MSE, + const KDateTime* TimeToApply, + const KDateTime* MustBeCompletedBy, + CMPIStatus* status) +{ + KUint32 result = KUINT32_INIT; + + KSetStatus(status, ERR_NOT_SUPPORTED); + return result; +} + +KUint32 LMI_Locale_ApplyToMSE( + const CMPIBroker* cb, + CMPIMethodMI* mi, + const CMPIContext* context, + const LMI_LocaleRef* self, + const KRef* MSE, + const KDateTime* TimeToApply, + const KDateTime* MustBeCompletedBy, + CMPIStatus* status) +{ + KUint32 result = KUINT32_INIT; + + KSetStatus(status, ERR_NOT_SUPPORTED); + return result; +} + +KUint32 LMI_Locale_VerifyOKToApplyToCollection( + const CMPIBroker* cb, + CMPIMethodMI* mi, + const CMPIContext* context, + const LMI_LocaleRef* self, + const KRef* Collection, + const KDateTime* TimeToApply, + const KDateTime* MustBeCompletedBy, + KStringA* CanNotApply, + CMPIStatus* status) +{ + KUint32 result = KUINT32_INIT; + + KSetStatus(status, ERR_NOT_SUPPORTED); + return result; +} + +KUint32 LMI_Locale_ApplyToCollection( + const CMPIBroker* cb, + CMPIMethodMI* mi, + const CMPIContext* context, + const LMI_LocaleRef* self, + const KRef* Collection, + const KDateTime* TimeToApply, + const KBoolean* ContinueOnError, + const KDateTime* MustBeCompletedBy, + KStringA* CanNotApply, + CMPIStatus* status) +{ + KUint32 result = KUINT32_INIT; + + KSetStatus(status, ERR_NOT_SUPPORTED); + return result; +} + +KUint32 LMI_Locale_VerifyOKToApplyIncrementalChangeToMSE( + const CMPIBroker* cb, + CMPIMethodMI* mi, + const CMPIContext* context, + const LMI_LocaleRef* self, + const KRef* MSE, + const KDateTime* TimeToApply, + const KDateTime* MustBeCompletedBy, + const KStringA* PropertiesToApply, + CMPIStatus* status) +{ + KUint32 result = KUINT32_INIT; + + KSetStatus(status, ERR_NOT_SUPPORTED); + return result; +} + +KUint32 LMI_Locale_ApplyIncrementalChangeToMSE( + const CMPIBroker* cb, + CMPIMethodMI* mi, + const CMPIContext* context, + const LMI_LocaleRef* self, + const KRef* MSE, + const KDateTime* TimeToApply, + const KDateTime* MustBeCompletedBy, + const KStringA* PropertiesToApply, + CMPIStatus* status) +{ + KUint32 result = KUINT32_INIT; + + KSetStatus(status, ERR_NOT_SUPPORTED); + return result; +} + +KUint32 LMI_Locale_VerifyOKToApplyIncrementalChangeToCollection( + const CMPIBroker* cb, + CMPIMethodMI* mi, + const CMPIContext* context, + const LMI_LocaleRef* self, + const KRef* Collection, + const KDateTime* TimeToApply, + const KDateTime* MustBeCompletedBy, + const KStringA* PropertiesToApply, + KStringA* CanNotApply, + CMPIStatus* status) +{ + KUint32 result = KUINT32_INIT; + + KSetStatus(status, ERR_NOT_SUPPORTED); + return result; +} + +KUint32 LMI_Locale_ApplyIncrementalChangeToCollection( + const CMPIBroker* cb, + CMPIMethodMI* mi, + const CMPIContext* context, + const LMI_LocaleRef* self, + const KRef* Collection, + const KDateTime* TimeToApply, + const KBoolean* ContinueOnError, + const KDateTime* MustBeCompletedBy, + const KStringA* PropertiesToApply, + KStringA* CanNotApply, + CMPIStatus* status) +{ + KUint32 result = KUINT32_INIT; + + KSetStatus(status, ERR_NOT_SUPPORTED); + return result; +} + +KUint32 LMI_Locale_SetLocale( + const CMPIBroker* cb, + CMPIMethodMI* mi, + const CMPIContext* context, + const LMI_LocaleRef* self, + const KString* Lang, + const KString* LCCType, + const KString* LCNumeric, + const KString* LCTime, + const KString* LCCollate, + const KString* LCMonetary, + const KString* LCMessages, + const KString* LCPaper, + const KString* LCName, + const KString* LCAddress, + const KString* LCTelephone, + const KString* LCMeasurement, + const KString* LCIdentification, + CMPIStatus* status) +{ + KUint32 result = KUINT32_INIT; + char *LocaleValue[KNOWN_LOC_STR_CNT]; + int LocaleCnt = 0; + char *tmps; + + SETVAL(Lang) + SETVAL(LCCType) + SETVAL(LCNumeric) + SETVAL(LCTime) + SETVAL(LCCollate) + SETVAL(LCMonetary) + SETVAL(LCMessages) + SETVAL(LCPaper) + SETVAL(LCName) + SETVAL(LCAddress) + SETVAL(LCTelephone) + SETVAL(LCMeasurement) + SETVAL(LCIdentification) + + // At least one locale string required + if (!LocaleCnt) { + KSetStatus2(cb, status, ERR_FAILED, "At least one locale string is required.\n"); + KUint32_Set(&result, 3); + goto error; + } + + KUint32_Set(&result, set_locale(LocaleValue, LocaleCnt)); + +error: + for (int i = 0; i < LocaleCnt; i++) { + free(LocaleValue[i]); + } + + return result; +} + +KUint32 LMI_Locale_SetVConsoleKeyboard( + const CMPIBroker* cb, + CMPIMethodMI* mi, + const CMPIContext* context, + const LMI_LocaleRef* self, + const KString* Keymap, + const KString* KeymapToggle, + const KBoolean* Convert, + CMPIStatus* status) +{ + KUint32 result = KUINT32_INIT; + int ConvertValue = 0; + + // Keymap is required + if (!(Keymap->exists && !Keymap->null && !(Keymap->chars[0] == '\0'))) { + KSetStatus2(cb, status, ERR_FAILED, "Required parameter 'Keymap' not specified.\n"); + KUint32_Set(&result, 1); + return result; + } + + // Convert set to TRUE - use it + if (Convert->exists && !Convert->null && Convert->value) + ConvertValue = 1; + + if (KeymapToggle->exists && !KeymapToggle->null) + KUint32_Set(&result, set_v_console_keyboard(Keymap->chars, KeymapToggle->chars, ConvertValue)); + else + KUint32_Set(&result, set_v_console_keyboard(Keymap->chars, "", ConvertValue)); + + return result; +} + +KUint32 LMI_Locale_SetX11Keyboard( + const CMPIBroker* cb, + CMPIMethodMI* mi, + const CMPIContext* context, + const LMI_LocaleRef* self, + const KString* Layouts, + const KString* Model, + const KString* Variant, + const KString* Options, + const KBoolean* Convert, + CMPIStatus* status) +{ + KUint32 result = KUINT32_INIT; + int ConvertValue = 0; + const char *ModelValue, *VariantValue, *OptionsValue; + + // Layout is required + if (!(Layouts->exists && !Layouts->null && !(Layouts->chars[0] == '\0'))) { + KSetStatus2(cb, status, ERR_FAILED, "Required parameter 'Layout' not specified.\n"); + KUint32_Set(&result, 1); + return result; + } + + // Convert set to TRUE - use it + if (Convert->exists && !Convert->null && Convert->value) + ConvertValue = 1; + + // Model, Variant and Options are optional + if (Model->exists && !Model->null) + ModelValue = Model->chars; + else + ModelValue = ""; + + if (Variant->exists && !Variant->null) + VariantValue = Variant->chars; + else + VariantValue = ""; + + if (Options->exists && !Options->null) + OptionsValue = Options->chars; + else + OptionsValue = ""; + + KUint32_Set(&result, set_x11_keyboard(Layouts->chars, ModelValue, VariantValue, OptionsValue, ConvertValue)); + + return result; +} + +KONKRET_REGISTRATION( + "root/cimv2", + "LMI_Locale", + "LMI_Locale", + "instance method") diff --git a/src/locale/cmpiLMI_Locale-cimprovagt b/src/locale/cmpiLMI_Locale-cimprovagt new file mode 100755 index 0000000..1f1de47 --- /dev/null +++ b/src/locale/cmpiLMI_Locale-cimprovagt @@ -0,0 +1,21 @@ +#!/bin/sh +# +# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Authors: Jan Synacek <jsynacek@redhat.com> + +/usr/libexec/pegasus/cimprovagt "$@" diff --git a/src/locale/localed.c b/src/locale/localed.c new file mode 100644 index 0000000..51bd3e3 --- /dev/null +++ b/src/locale/localed.c @@ -0,0 +1,258 @@ +/* + * Copyright (C) 2014 Red Hat, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Vitezslav Crhonek <vcrhonek@redhat.com> + */ + + +#include <stdlib.h> +#include <string.h> +#include <gio/gio.h> + +#include "localed.h" + +#define LOCALE_NAME "org.freedesktop.locale1" +#define LOCALE_OP "/org/freedesktop/locale1" +#define LOCALE_INTERFACE "org.freedesktop.locale1" +#define PROPERTY_INTERFACE "org.freedesktop.DBus.Properties" + +const char *provider_name = "locale"; +const ConfigEntry *provider_config_defaults = NULL; + +void locale_init() +{ +#if !defined(GLIB_VERSION_2_36) + g_type_init(); +#endif +} + + +CimLocale *locale_get_properties() +{ + GDBusProxy *proxy = NULL; + GVariantIter *arr = NULL; + GVariant *result = NULL; + GVariant *result2 = NULL; + gchar *env_str = NULL; + gchar *value_str; + CimLocale *cloc = NULL; + + + proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, + NULL, LOCALE_NAME, LOCALE_OP, PROPERTY_INTERFACE, NULL, NULL); + if (!proxy) goto error; + + cloc = malloc(sizeof(CimLocale)); + if (!cloc) goto error; + cloc->LocaleCnt = 0; + + if ((result = g_dbus_proxy_call_sync(proxy, "Get", g_variant_new("(ss)", LOCALE_INTERFACE, "Locale"), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL)) == NULL) + goto error; + g_variant_get(result, "(v)", &result2); + g_variant_unref(result); + g_variant_get(result2, "as", &arr); + g_variant_unref(result2); + while (g_variant_iter_loop(arr, "&s", &env_str)) { + cloc->Locale[cloc->LocaleCnt] = strdup(env_str); + if (!cloc->Locale[cloc->LocaleCnt]) goto error; + cloc->LocaleCnt++; + } + g_variant_iter_free(arr); + arr = NULL; + + if ((result = g_dbus_proxy_call_sync(proxy, "Get", g_variant_new("(ss)", LOCALE_INTERFACE, "VConsoleKeymap"), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL)) == NULL) + goto error; + g_variant_get(result, "(v)", &result2); + g_variant_unref(result); + g_variant_get(result2, "s", &value_str); + g_variant_unref(result2); + cloc->VConsoleKeymap = value_str; + if (!cloc->VConsoleKeymap) goto error; + + if ((result = g_dbus_proxy_call_sync(proxy, "Get", g_variant_new("(ss)", LOCALE_INTERFACE, "VConsoleKeymapToggle"), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL)) == NULL) + goto error; + g_variant_get(result, "(v)", &result2); + g_variant_unref(result); + g_variant_get(result2, "s", &value_str); + g_variant_unref(result2); + cloc->VConsoleKeymapToggle = value_str; + if (!cloc->VConsoleKeymapToggle) goto error; + + if ((result = g_dbus_proxy_call_sync(proxy, "Get", g_variant_new("(ss)", LOCALE_INTERFACE, "X11Layout"), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL)) == NULL) + goto error; + g_variant_get(result, "(v)", &result2); + g_variant_unref(result); + g_variant_get(result2, "s", &value_str); + g_variant_unref(result2); + cloc->X11Layouts = value_str; + if (!cloc->X11Layouts) goto error; + + if ((result = g_dbus_proxy_call_sync(proxy, "Get", g_variant_new("(ss)", LOCALE_INTERFACE, "X11Model"), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL)) == NULL) + goto error; + g_variant_get(result, "(v)", &result2); + g_variant_unref(result); + g_variant_get(result2, "s", &value_str); + g_variant_unref(result2); + cloc->X11Model = value_str; + if (!cloc->X11Model) goto error; + + if ((result = g_dbus_proxy_call_sync(proxy, "Get", g_variant_new("(ss)", LOCALE_INTERFACE, "X11Variant"), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL)) == NULL) + goto error; + g_variant_get(result, "(v)", &result2); + g_variant_unref(result); + g_variant_get(result2, "s", &value_str); + g_variant_unref(result2); + cloc->X11Variant = value_str; + if (!cloc->X11Variant) goto error; + + if ((result = g_dbus_proxy_call_sync(proxy, "Get", g_variant_new("(ss)", LOCALE_INTERFACE, "X11Options"), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL)) == NULL) + goto error; + g_variant_get(result, "(v)", &result2); + g_variant_unref(result); + g_variant_get(result2, "s", &value_str); + g_variant_unref(result2); + cloc->X11Options = value_str; + if (!cloc->X11Options) goto error; + + g_object_unref(proxy); + return cloc; + +error: + if (proxy) g_object_unref(proxy); + if (cloc) locale_free(cloc); + + return NULL; +} + + +void locale_free(CimLocale *cloc) +{ + int i; + + if (!cloc) return; + + for (i = 0; i < cloc->LocaleCnt; i++) g_free(cloc->Locale[i]); + g_free(cloc->VConsoleKeymap); + g_free(cloc->VConsoleKeymapToggle); + g_free(cloc->X11Layouts); + g_free(cloc->X11Model); + g_free(cloc->X11Variant); + g_free(cloc->X11Options); + free(cloc); + + return; +} + + +// The user_interaction boolean parameter (last parameter in SetLocale, SetVConsoleKeyboard +// and SetX11Keyboard) can be used to control whether PolicyKit should interactively ask the user +// for authentication credentials if it needs to - we don't want it, so it's hardcoded to FALSE + +int set_locale( + char *locale[], + int locale_cnt) +{ + GDBusProxy *proxy = NULL; + GError *gerr = NULL; + GVariantBuilder *builder; + + proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, + NULL, LOCALE_NAME, LOCALE_OP, LOCALE_INTERFACE, NULL, &gerr); + if (!proxy) goto error; + + builder = g_variant_builder_new(G_VARIANT_TYPE ("as")); + for (int i = 0; i < locale_cnt; i++) + g_variant_builder_add(builder, "s", locale[i]); + + g_dbus_proxy_call_sync(proxy, "SetLocale", + g_variant_new("(asb)", builder, FALSE), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &gerr); + g_variant_builder_unref(builder); + if (gerr) goto error; + + return 0; + +error: + g_clear_error(&gerr); + if (proxy) g_object_unref(proxy); + return 1; +} + + +int set_v_console_keyboard( + const char *keymap, + const char* keymap_toggle, + int convert) +{ + GDBusProxy *proxy = NULL; + GError *gerr = NULL; + + proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, + NULL, LOCALE_NAME, LOCALE_OP, LOCALE_INTERFACE, NULL, &gerr); + if (!proxy) goto error; + + gerr = NULL; + // SetVConsoleKeyboard() instantly applies the new keymapping to the console + g_dbus_proxy_call_sync(proxy, "SetVConsoleKeyboard", + g_variant_new("(ssbb)", keymap, keymap_toggle, convert, FALSE), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &gerr); + if (gerr) goto error; + + return 0; + +error: + g_clear_error(&gerr); + if (proxy) g_object_unref(proxy); + return 1; +} + + +int set_x11_keyboard( + const char *layouts, + const char *model, + const char *variant, + const char *options, + int convert) +{ + GDBusProxy *proxy = NULL; + GError *gerr = NULL; + + proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, + NULL, LOCALE_NAME, LOCALE_OP, LOCALE_INTERFACE, NULL, &gerr); + if (!proxy) goto error; + + gerr = NULL; + // SetX11Keyboard() simply sets a default that may be used by later sessions. + g_dbus_proxy_call_sync(proxy, "SetX11Keyboard", + g_variant_new("(ssssbb)", layouts, model, variant, options, convert, FALSE), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &gerr); + if (gerr) goto error; + + return 0; + +error: + g_clear_error(&gerr); + if (proxy) g_object_unref(proxy); + return 1; +} diff --git a/src/locale/localed.h b/src/locale/localed.h new file mode 100644 index 0000000..daf4274 --- /dev/null +++ b/src/locale/localed.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2014 Red Hat, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Vitezslav Crhonek <vcrhonek@redhat.com> + */ + + +#ifndef LOCALED_H +#define LOCALED_H + +#include "openlmi.h" +#include "LMI_Locale.h" + +#define KNOWN_LOC_STR_CNT 13 + +const char *provider_name; +const ConfigEntry *provider_config_defaults; + +struct _CimLocale { + char *Locale[KNOWN_LOC_STR_CNT]; + // The following strings are known: LANG=, LC_CTYPE=, LC_NUMERIC=, LC_TIME=, + // LC_COLLATE=, LC_MONETARY=, LC_MESSAGES=, LC_PAPER=, LC_NAME=, LC_ADDRESS=, + // LC_TELEPHONE=, LC_MEASUREMENT=, LC_IDENTIFICATION=. + int LocaleCnt; + char *VConsoleKeymap; + char *VConsoleKeymapToggle; + char *X11Layouts; + char *X11Model; + char *X11Variant; + char *X11Options; +}; + +typedef struct _CimLocale CimLocale; + +void locale_init(); + +CimLocale *locale_get_properties(); +void locale_free(CimLocale *cloc); + +int set_locale(char *locale[], int locale_cnt); +int set_v_console_keyboard(const char *keymap, const char* keymap_toggle, int convert); +int set_x11_keyboard(const char *layouts, const char *model, const char *variant, const char *options, int convert); + +#endif |