From 5c1f280988fd3336c191a4f190e621c6eaa1f6a3 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Mon, 30 Oct 2023 23:08:02 -0500 Subject: [PATCH] Mac: Add microphone permissions string Allows us to ask permission to use the microphone --- cmake/Pcsx2Utils.cmake | 30 ++++++++++++++++++++++++++++ pcsx2-qt/CMakeLists.txt | 1 + pcsx2-qt/Translations.cpp | 4 ++++ pcsx2-qt/Translations/pcsx2-qt_en.ts | 18 ++++++++++++++++- pcsx2/Resources/Info.plist.in | 2 ++ 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/cmake/Pcsx2Utils.cmake b/cmake/Pcsx2Utils.cmake index e9fa821a3c..1e32097a9c 100644 --- a/cmake/Pcsx2Utils.cmake +++ b/cmake/Pcsx2Utils.cmake @@ -197,6 +197,36 @@ function(source_groups_from_vcxproj_filters file) endforeach() endfunction() +# Extracts a translation with the given type ("source" or "translation") from the given category of the given ts file +# (If there's multiple strings under the same category, which one it extracts is implementation defined. Just don't do it.) +function(extract_translation_from_ts file type category output) + file(READ "${file}" filecontent) + # Don't you love it when the best parser your language has to offer is regex? + set(regex_search "(<[^\\/>]+>[^<>]+<\\/[^>\\/]+>|<\\/?context>)") + set(regex_extract "<[^\\/>]+>([^<>]+)<\\/([^>\\/]+)>") + string(REGEX MATCHALL "${regex_search}" pieces "${filecontent}") + foreach(piece IN LISTS pieces) + if (piece STREQUAL "") + set(found "") + set(name_match FALSE) + elseif (piece STREQUAL "") + if (name_match) + set(${output} "${found}" PARENT_SCOPE) + break() + endif() + else() + string(REGEX REPLACE "${regex_extract}" "\\1" content "${piece}") + string(REGEX REPLACE "${regex_extract}" "\\2" tag "${piece}") + if (tag STREQUAL "name" AND content STREQUAL "${category}") + set(name_match TRUE) + endif() + if (tag STREQUAL "${type}") + set(found "${content}") + endif() + endif() + endforeach() +endfunction() + function(fixup_file_properties target) get_target_property(SOURCES ${target} SOURCES) if(APPLE) diff --git a/pcsx2-qt/CMakeLists.txt b/pcsx2-qt/CMakeLists.txt index f8e08a2b19..697221e119 100644 --- a/pcsx2-qt/CMakeLists.txt +++ b/pcsx2-qt/CMakeLists.txt @@ -221,6 +221,7 @@ elseif(APPLE) set_source_files_properties(${QM_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/translations/) endforeach() copy_base_translations(pcsx2-qt) + extract_translation_from_ts(Translations/pcsx2-qt_en.ts source PermissionsDialogMicrophone PCSX2_MICROPHONE_USAGE_DESCRIPTION) else() qt_add_lrelease(pcsx2-qt TS_FILES ${TS_FILES} QM_FILES_OUTPUT_VARIABLE QM_FILES) set(QM_OUTPUT_DIR "$/translations") diff --git a/pcsx2-qt/Translations.cpp b/pcsx2-qt/Translations.cpp index 8b949ec6ed..716793872e 100644 --- a/pcsx2-qt/Translations.cpp +++ b/pcsx2-qt/Translations.cpp @@ -48,6 +48,10 @@ QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU", "Show All") QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU", "Preferences...") QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU", "Quit %1") QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU", "About %1") + +// Strings that will be parsed out by our build system and sent to fun places +QT_TRANSLATE_NOOP("PermissionsDialogMicrophone", "PCSX2 uses your microphone to emulate a USB microphone plugged into the virtual PS2") +QT_TRANSLATE_NOOP("PermissionsDialogCamera", "PCSX2 uses your camera to emulate an EyeToy camera plugged into the virtual PS2") #endif namespace QtHost diff --git a/pcsx2-qt/Translations/pcsx2-qt_en.ts b/pcsx2-qt/Translations/pcsx2-qt_en.ts index a58dd31e92..4d75899e2b 100644 --- a/pcsx2-qt/Translations/pcsx2-qt_en.ts +++ b/pcsx2-qt/Translations/pcsx2-qt_en.ts @@ -12616,7 +12616,7 @@ Right click to clear binding - + System Language [Default] @@ -14681,6 +14681,22 @@ Leaving the original controller type connected, but this may cause issues. + + PermissionsDialogCamera + + + PCSX2 uses your camera to emulate an EyeToy camera plugged into the virtual PS2 + + + + + PermissionsDialogMicrophone + + + PCSX2 uses your microphone to emulate a USB microphone plugged into the virtual PS2 + + + QObject diff --git a/pcsx2/Resources/Info.plist.in b/pcsx2/Resources/Info.plist.in index 11ff3b7436..73e9185c42 100644 --- a/pcsx2/Resources/Info.plist.in +++ b/pcsx2/Resources/Info.plist.in @@ -39,6 +39,8 @@ ${CMAKE_OSX_DEPLOYMENT_TARGET} NSHighResolutionCapable + NSMicrophoneUsageDescription + ${PCSX2_MICROPHONE_USAGE_DESCRIPTION} LSApplicationCategoryType public.app-category.games CFBundleDevelopmentRegion