From dd3dccb5b3ece993ea648f76ff0cc9aa08527061 Mon Sep 17 00:00:00 2001 From: Muhammad Date: Fri, 12 May 2023 17:49:30 +0500 Subject: src: add support for getting flashlight paths through deviceinfo Signed-off-by: Muhammad --- CMakeLists.txt | 6 ++++++ src/CMakeLists.txt | 9 ++++++++- src/deviceinfo-flashlight.c | 13 ++++++++++++ src/flashlight.c | 48 +++++++++++++++++++++++++++++++++------------ tests/CMakeLists.txt | 2 +- 5 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 src/deviceinfo-flashlight.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a9ee67..18a9152 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ option(ENABLE_TESTS "Enable all tests and checks" OFF) option(ENABLE_COVERAGE "Enable coverage reports (includes enabling all tests and checks)" OFF) option(ENABLE_WERROR "Treat all build warnings as errors" OFF) option(ENABLE_LOMIRI_FEATURES "Build with Lomiri-specific libraries, schemas and media" OFF) +option(ENABLE_DEVICEINFO "Build with deviceinfo integration" OFF) if(ENABLE_COVERAGE) set(ENABLE_TESTS ON) @@ -91,6 +92,11 @@ endif () pkg_check_modules (SERVICE_DEPS REQUIRED ${SERVICE_DEPS}) include_directories (SYSTEM ${SERVICE_DEPS_INCLUDE_DIRS}) +if (ENABLE_DEVICEINFO) + pkg_check_modules (DEVICEINFO IMPORTED_TARGET "deviceinfo") + include_directories (${DEVICEINFO_INCLUDE_DIRS}) +endif () + ## ## custom targets ## diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index df2fd5d..f765f23 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,14 @@ +if (ENABLE_DEVICEINFO) + set(FLASHLIGHT_DEVICEINFO + deviceinfo-flashlight.c) + add_definitions(-DENABLE_LIBDEVICEINFO) +endif () + # handwritten sources set(SERVICE_MANUAL_SOURCES brightness.c datafiles.c + ${FLASHLIGHT_DEVICEINFO} device-provider-mock.c device-provider-upower.c device-provider.c @@ -45,5 +52,5 @@ link_directories(${SERVICE_DEPS_LIBRARY_DIRS}) # the executable: lib + main() add_executable (${SERVICE_EXEC} main.c) -target_link_libraries (${SERVICE_EXEC} ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES}) +target_link_libraries (${SERVICE_EXEC} ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES} ${DEVICEINFO_LIBRARIES}) install (TARGETS ${SERVICE_EXEC} RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_LIBEXECDIR}/${CMAKE_PROJECT_NAME}") diff --git a/src/deviceinfo-flashlight.c b/src/deviceinfo-flashlight.c new file mode 100644 index 0000000..e31c1ff --- /dev/null +++ b/src/deviceinfo-flashlight.c @@ -0,0 +1,13 @@ +#include + +char* flashlight_path() +{ + struct DeviceInfo* di = deviceinfo_new(); + return deviceinfo_get(di, "FlashlightSysfsPath", ""); +} + +char* flashlight_switch_path() +{ + struct DeviceInfo* di = deviceinfo_new(); + return deviceinfo_get(di, "FlashlightSwitchPath", ""); +} diff --git a/src/flashlight.c b/src/flashlight.c index 0a68af2..88e93fd 100644 --- a/src/flashlight.c +++ b/src/flashlight.c @@ -31,6 +31,11 @@ #define SIMPLE_ENABLE "1" #define SIMPLE_DISABLE "0" +#ifdef ENABLE_LIBDEVICEINFO +extern char* flashlight_path(); +extern char* flashlight_switch_path(); +#endif + const size_t qcom_sysfs_size = 7; const char* const qcom_sysfs[] = {"/sys/class/leds/torch-light/brightness", "/sys/class/leds/led:flash_torch/brightness", @@ -56,24 +61,41 @@ gboolean activated = 0; int set_sysfs_path() { - for (size_t i = 0; i < qcom_sysfs_size; i++) { - if (access(qcom_sysfs[i], F_OK ) != -1){ - flash_sysfs_path = (char*)qcom_sysfs[i]; - torch_type = QCOM; - /* Qualcomm torch; determine switch file (if one is needed) */ - for (size_t i = 0; i < qcom_switch_size; i++) { - if (access(qcom_switch[i], F_OK ) != -1) - qcom_switch_path = (char*)qcom_switch[i]; +# ifdef ENABLE_LIBDEVICEINFO + if (strcmp(flashlight_path(), "")) { + if (access(flashlight_path(), F_OK) != -1) { + flash_sysfs_path = flashlight_path(); + if (strcmp(flashlight_switch_path(), "")) { + if (access(flashlight_switch_path(), F_OK) != -1) { + qcom_switch_path = flashlight_switch_path(); + torch_type = QCOM; + } } return 1; } - } - for (size_t i = 0; i < simple_sysfs_size; i++) { - if (access(simple_sysfs[i], F_OK ) != -1){ - flash_sysfs_path = (char*)simple_sysfs[i]; - return 1; + } else { +# endif + for (size_t i = 0; i < qcom_sysfs_size; i++) { + if (access(qcom_sysfs[i], F_OK ) != -1){ + flash_sysfs_path = (char*)qcom_sysfs[i]; + torch_type = QCOM; + /* Qualcomm torch; determine switch file (if one is needed) */ + for (size_t i = 0; i < qcom_switch_size; i++) { + if (access(qcom_switch[i], F_OK ) != -1) + qcom_switch_path = (char*)qcom_switch[i]; + } + return 1; + } + } + for (size_t i = 0; i < simple_sysfs_size; i++) { + if (access(simple_sysfs[i], F_OK ) != -1){ + flash_sysfs_path = (char*)simple_sysfs[i]; + return 1; + } } +# ifdef ENABLE_LIBDEVICEINFO } +# endif return 0; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 05b3da0..d45f4d1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -43,7 +43,7 @@ function(add_test_by_name name) target_link_options(${TEST_NAME} PRIVATE -no-pie) add_test (${TEST_NAME} ${TEST_NAME}) add_dependencies (${TEST_NAME} ${SERVICE_LIB} gschemas-compiled) - target_link_libraries (${TEST_NAME} ${SERVICE_LIB} ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GMOCK_LIBRARIES}) + target_link_libraries (${TEST_NAME} ${SERVICE_LIB} ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${DEVICEINFO_LIBRARIES} ${GMOCK_LIBRARIES}) endfunction() add_test_by_name(test-notify) add_test(NAME dear-reader-the-next-test-takes-80-seconds COMMAND true) -- cgit v1.2.3 From 0ed3e1762249d7c1ab954e7fa16543bb16d58f60 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 6 Jun 2023 16:34:09 +0200 Subject: src/device.c: Don't show parentheses around time-remaining / battery charge percentage values when in Lomiri. --- src/device.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/device.c b/src/device.c index 6e79557..af01253 100644 --- a/src/device.c +++ b/src/device.c @@ -27,6 +27,7 @@ License along with this library. If not, see #include "config.h" #endif +#include #include #include @@ -1063,18 +1064,42 @@ indicator_power_device_get_readable_title (const IndicatorPowerDevice * device, if (want_time && want_percent) { - /* TRANSLATORS: after the icon, a time-remaining string + battery %. Example: "(0:59, 33%)" */ - str = g_strdup_printf (_("(%s, %.0lf%%)"), time_str, p->percentage); + /* Don't show parentheses around text values in Lomiri */ + if (ayatana_common_utils_is_lomiri()) + { + /* TRANSLATORS: after the icon, a time-remaining string + battery %. Example: "0:59 33%" */ + str = g_strdup_printf (_("%s %.0lf%%"), time_str, p->percentage); + } + else { + /* TRANSLATORS: after the icon, a time-remaining string + battery %. Example: "(0:59, 33%)" */ + str = g_strdup_printf (_("(%s, %.0lf%%)"), time_str, p->percentage); + } } else if (want_time) { - /* TRANSLATORS: after the icon, a time-remaining string Example: "(0:59)" */ - str = g_strdup_printf (_("(%s)"), time_str); + /* Don't show parentheses around text values in Lomiri */ + if (ayatana_common_utils_is_lomiri()) + { + /* TRANSLATORS: after the icon, a time-remaining string Example: "0:59" */ + str = g_strdup_printf (_("%s"), time_str); + } + else { + /* TRANSLATORS: after the icon, a time-remaining string Example: "(0:59)" */ + str = g_strdup_printf (_("(%s)"), time_str); + } } else if (want_percent) { - /* TRANSLATORS: after the icon, a battery %. Example: "(33%)" */ - str = g_strdup_printf (_("(%.0lf%%)"), p->percentage); + /* Don't show parentheses around text values in Lomiri */ + if (ayatana_common_utils_is_lomiri()) + { + /* TRANSLATORS: after the icon, a battery %. Example: "(33%)" */ + str = g_strdup_printf (_("%.0lf%%"), p->percentage); + } + else { + /* TRANSLATORS: after the icon, a battery %. Example: "(33%)" */ + str = g_strdup_printf (_("(%.0lf%%)"), p->percentage); + } } else { -- cgit v1.2.3