From f59500bfe360dce317af6b3c24c9a71206e9011a Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Fri, 19 Nov 2021 09:16:00 +0100 Subject: GSettings: Use org.ayatana.display.gschema.xml for non-Lomiri sessions and unit tests. Additionally, internationalize the org.ayatana.display GSettings schema. Fixes https://github.com/AyatanaIndicators/ayatana-indicator-display/issues/39 --- data/CMakeLists.txt | 17 +++++++++++++---- data/org.ayatana.display.gschema.xml | 24 ------------------------ data/org.ayatana.display.gschema.xml.in | 24 ++++++++++++++++++++++++ src/rotation-lock.cpp | 25 +++++++++++++++++-------- tests/unit/CMakeLists.txt | 7 ++----- 5 files changed, 56 insertions(+), 41 deletions(-) delete mode 100644 data/org.ayatana.display.gschema.xml create mode 100644 data/org.ayatana.display.gschema.xml.in diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index acc462f..6f8cda1 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -1,12 +1,21 @@ find_package(GSettings) ## -## GSettings +## GSettings schema ## -if(NOT EXISTS /usr/share/glib-2.0/schemas/com.lomiri.touch.system.gschema.xml) - add_schema ("org.ayatana.indicator.display.gschema.xml") -endif() +set (SCHEMA_NAME "org.ayatana.display.gschema.xml") +set (SCHEMA_FILE "${CMAKE_CURRENT_BINARY_DIR}/${SCHEMA_NAME}") +set (SCHEMA_FILE_IN "${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NAME}.in") + +# generate the .xml file using intltool +find_package(Intltool REQUIRED) +set (ENV{LC_ALL} "C") +intltool_merge_translations("${SCHEMA_FILE_IN}" "${SCHEMA_FILE}" ALL UTF8 STYLE "xml" NO_TRANSLATIONS) + +# let GSettings do the rest +find_package(GSettings REQUIRED) +add_schema (${SCHEMA_NAME}) ## ## Systemd Unit File diff --git a/data/org.ayatana.display.gschema.xml b/data/org.ayatana.display.gschema.xml deleted file mode 100644 index 9afa253..0000000 --- a/data/org.ayatana.display.gschema.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - false - Lock rotation - - Lock automatic display rotation. - - - - "none" - Orientation lock - Locks orientation to a specific value. - - - diff --git a/data/org.ayatana.display.gschema.xml.in b/data/org.ayatana.display.gschema.xml.in new file mode 100644 index 0000000..afcd996 --- /dev/null +++ b/data/org.ayatana.display.gschema.xml.in @@ -0,0 +1,24 @@ + + + + + + + + + + + + false + <_summary>Lock rotation + <_description> + Lock automatic display rotation. + + + + "none" + <_summary>Orientation lock + <_description>Locks orientation to a specific value. + + + diff --git a/src/rotation-lock.cpp b/src/rotation-lock.cpp index ad89e10..cb864af 100644 --- a/src/rotation-lock.cpp +++ b/src/rotation-lock.cpp @@ -38,16 +38,24 @@ public: if (pSource != NULL) { - GSettingsSchema *pSchema = g_settings_schema_source_lookup(pSource, "com.lomiri.touch.system", FALSE); + if (ayatana_common_utils_is_lomiri()) { + + GSettingsSchema *pSchema = g_settings_schema_source_lookup(pSource, "com.lomiri.touch.system", FALSE); + + if (pSchema != NULL) + { + g_settings_schema_unref(pSchema); + m_settings = g_settings_new("com.lomiri.touch.system"); + } + else + { + g_error("No schema could be found"); + } - if (pSchema != NULL) - { - g_settings_schema_unref(pSchema); - m_settings = g_settings_new("com.lomiri.touch.system"); } - else - { - pSchema = g_settings_schema_source_lookup(pSource, "org.ayatana.indicator.display", FALSE); + else { + + GSettingsSchema *pSchema = g_settings_schema_source_lookup(pSource, "org.ayatana.indicator.display", FALSE); if (pSchema != NULL) { @@ -58,6 +66,7 @@ public: { g_error("No schema could be found"); } + } } diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 5656bed..a70362a 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -12,16 +12,13 @@ set_source_files_properties (gschemas.compiled GENERATED) # and help the tests to find that file by setting -DSCHEMA_DIR set (XDG_DATA_DIRS "${CMAKE_CURRENT_BINARY_DIR}/gsettings-schemas") set (SCHEMA_DIR "${XDG_DATA_DIRS}/glib-2.0/schemas") -if (EXISTS /usr/share/glib-2.0/schemas/com.lomiri.touch.system.gschema.xml) - set (DISPLAY_SCHEMA /usr/share/glib-2.0/schemas/com.lomiri.touch.system.gschema.xml) -else() - set (DISPLAY_SCHEMA ${CMAKE_SOURCE_DIR}/data/org.ayatana.display.gschema.xml) -endif() +set (DISPLAY_SCHEMA ${CMAKE_BINARY_DIR}/data/org.ayatana.display.gschema.xml) add_definitions(-DSCHEMA_DIR="${SCHEMA_DIR}") execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_schemas OUTPUT_VARIABLE COMPILE_SCHEMA_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE) add_custom_command (OUTPUT gschemas.compiled + DEPENDS ${CMAKE_BINARY_DIR}/data/org.ayatana.display.gschema.xml COMMAND mkdir -p ${SCHEMA_DIR} COMMAND cp -f ${DISPLAY_SCHEMA} ${SCHEMA_DIR} COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${SCHEMA_DIR}) -- cgit v1.2.3