Commit 3ff3d577 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Provisions for localized key code strings (refs #5974)

parent 1cf1818d
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
#define KEY_MOUSEWHEELLEFT 0x00F20000 #define KEY_MOUSEWHEELLEFT 0x00F20000
#define KEY_MOUSEWHEELRIGHT 0x00F30000 #define KEY_MOUSEWHEELRIGHT 0x00F30000
VLC_API char *vlc_keycode2str(uint_fast32_t i_key) VLC_USED; VLC_API char *vlc_keycode2str(uint_fast32_t i_key, bool locale) VLC_USED;
VLC_API uint_fast32_t vlc_str2keycode(const char *str) VLC_USED; VLC_API uint_fast32_t vlc_str2keycode(const char *str) VLC_USED;
typedef enum vlc_action { typedef enum vlc_action {
......
...@@ -288,7 +288,7 @@ int qtWheelEventToVLCKey( QWheelEvent *e ) ...@@ -288,7 +288,7 @@ int qtWheelEventToVLCKey( QWheelEvent *e )
QString VLCKeyToString( unsigned val ) QString VLCKeyToString( unsigned val )
{ {
char *base = vlc_keycode2str (val); char *base = vlc_keycode2str (val, false);
if (base == NULL) if (base == NULL)
return qtr( "Unset" ); return qtr( "Unset" );
......
...@@ -39,7 +39,7 @@ const string EvtKey::getAsString() const ...@@ -39,7 +39,7 @@ const string EvtKey::getAsString() const
msg_Warn( getIntf(), "Unknown action type" ); msg_Warn( getIntf(), "Unknown action type" );
// Add the key // Add the key
char *keyName = vlc_keycode2str( m_key & ~KEY_MODIFIER ); char *keyName = vlc_keycode2str( m_key & ~KEY_MODIFIER, false );
if( keyName ) if( keyName )
{ {
event += (string)":" + keyName; event += (string)":" + keyName;
......
...@@ -78,6 +78,7 @@ src/config/core.c ...@@ -78,6 +78,7 @@ src/config/core.c
src/config/file.c src/config/file.c
src/config/help.c src/config/help.c
src/config/intf.c src/config/intf.c
src/config/keys.c
src/extras/libc.c src/extras/libc.c
src/extras/tdestroy.c src/extras/tdestroy.c
src/input/access.c src/input/access.c
......
...@@ -52,53 +52,53 @@ typedef struct key_descriptor_s ...@@ -52,53 +52,53 @@ typedef struct key_descriptor_s
static const struct key_descriptor_s vlc_keys[] = static const struct key_descriptor_s vlc_keys[] =
{ /* Alphabetical order */ { /* Alphabetical order */
{ "Backspace", KEY_BACKSPACE }, { N_("Backspace"), KEY_BACKSPACE },
{ "Browser Back", KEY_BROWSER_BACK }, { N_("Browser Back"), KEY_BROWSER_BACK },
{ "Browser Favorites", KEY_BROWSER_FAVORITES }, { N_("Browser Favorites"), KEY_BROWSER_FAVORITES },
{ "Browser Forward", KEY_BROWSER_FORWARD }, { N_("Browser Forward"), KEY_BROWSER_FORWARD },
{ "Browser Home", KEY_BROWSER_HOME }, { N_("Browser Home"), KEY_BROWSER_HOME },
{ "Browser Refresh", KEY_BROWSER_REFRESH }, { N_("Browser Refresh"), KEY_BROWSER_REFRESH },
{ "Browser Search", KEY_BROWSER_SEARCH }, { N_("Browser Search"), KEY_BROWSER_SEARCH },
{ "Browser Stop", KEY_BROWSER_STOP }, { N_("Browser Stop"), KEY_BROWSER_STOP },
{ "Delete", KEY_DELETE }, { N_("Delete"), KEY_DELETE },
{ "Down", KEY_DOWN }, { N_("Down"), KEY_DOWN },
{ "End", KEY_END }, { N_("End"), KEY_END },
{ "Enter", KEY_ENTER }, { N_("Enter"), KEY_ENTER },
{ "Esc", KEY_ESC }, { N_("Esc"), KEY_ESC },
{ "F1", KEY_F1 }, { N_("F1"), KEY_F1 },
{ "F10", KEY_F10 }, { N_("F10"), KEY_F10 },
{ "F11", KEY_F11 }, { N_("F11"), KEY_F11 },
{ "F12", KEY_F12 }, { N_("F12"), KEY_F12 },
{ "F2", KEY_F2 }, { N_("F2"), KEY_F2 },
{ "F3", KEY_F3 }, { N_("F3"), KEY_F3 },
{ "F4", KEY_F4 }, { N_("F4"), KEY_F4 },
{ "F5", KEY_F5 }, { N_("F5"), KEY_F5 },
{ "F6", KEY_F6 }, { N_("F6"), KEY_F6 },
{ "F7", KEY_F7 }, { N_("F7"), KEY_F7 },
{ "F8", KEY_F8 }, { N_("F8"), KEY_F8 },
{ "F9", KEY_F9 }, { N_("F9"), KEY_F9 },
{ "Home", KEY_HOME }, { N_("Home"), KEY_HOME },
{ "Insert", KEY_INSERT }, { N_("Insert"), KEY_INSERT },
{ "Left", KEY_LEFT }, { N_("Left"), KEY_LEFT },
{ "Media Next Track", KEY_MEDIA_NEXT_TRACK }, { N_("Media Next Track"), KEY_MEDIA_NEXT_TRACK },
{ "Media Play Pause", KEY_MEDIA_PLAY_PAUSE }, { N_("Media Play Pause"), KEY_MEDIA_PLAY_PAUSE },
{ "Media Prev Track", KEY_MEDIA_PREV_TRACK }, { N_("Media Prev Track"), KEY_MEDIA_PREV_TRACK },
{ "Media Stop", KEY_MEDIA_STOP }, { N_("Media Stop"), KEY_MEDIA_STOP },
{ "Menu", KEY_MENU }, { N_("Menu"), KEY_MENU },
{ "Mouse Wheel Down", KEY_MOUSEWHEELDOWN }, { N_("Mouse Wheel Down"), KEY_MOUSEWHEELDOWN },
{ "Mouse Wheel Left", KEY_MOUSEWHEELLEFT }, { N_("Mouse Wheel Left"), KEY_MOUSEWHEELLEFT },
{ "Mouse Wheel Right", KEY_MOUSEWHEELRIGHT }, { N_("Mouse Wheel Right"), KEY_MOUSEWHEELRIGHT },
{ "Mouse Wheel Up", KEY_MOUSEWHEELUP }, { N_("Mouse Wheel Up"), KEY_MOUSEWHEELUP },
{ "Page Down", KEY_PAGEDOWN }, { N_("Page Down"), KEY_PAGEDOWN },
{ "Page Up", KEY_PAGEUP }, { N_("Page Up"), KEY_PAGEUP },
{ "Right", KEY_RIGHT }, { N_("Right"), KEY_RIGHT },
{ "Space", ' ' }, { N_("Space"), ' ' },
{ "Tab", KEY_TAB }, { N_("Tab"), KEY_TAB },
{ "Unset", KEY_UNSET }, { N_("Unset"), KEY_UNSET },
{ "Up", KEY_UP }, { N_("Up"), KEY_UP },
{ "Volume Down", KEY_VOLUME_DOWN }, { N_("Volume Down"), KEY_VOLUME_DOWN },
{ "Volume Mute", KEY_VOLUME_MUTE }, { N_("Volume Mute"), KEY_VOLUME_MUTE },
{ "Volume Up", KEY_VOLUME_UP }, { N_("Volume Up"), KEY_VOLUME_UP },
}; };
#define KEYS_COUNT (sizeof(vlc_keys)/sizeof(vlc_keys[0])) #define KEYS_COUNT (sizeof(vlc_keys)/sizeof(vlc_keys[0]))
...@@ -150,6 +150,9 @@ static char *utf8_cp (uint_fast32_t cp, char *buf) ...@@ -150,6 +150,9 @@ static char *utf8_cp (uint_fast32_t cp, char *buf)
/** /**
* Parse a human-readable string representation of a VLC key code. * Parse a human-readable string representation of a VLC key code.
* @note This only works with the American English representation
* (a.k.a. C or POSIX), not with the local representation returned from
* vlc_keycode2str().
* @return a VLC key code, or KEY_UNSET on failure. * @return a VLC key code, or KEY_UNSET on failure.
*/ */
uint_fast32_t vlc_str2keycode (const char *name) uint_fast32_t vlc_str2keycode (const char *name)
...@@ -190,13 +193,22 @@ uint_fast32_t vlc_str2keycode (const char *name) ...@@ -190,13 +193,22 @@ uint_fast32_t vlc_str2keycode (const char *name)
return code; return code;
} }
static char *nooptext (const char *txt)
{
return (char *)txt;
}
/** /**
* Format a human-readable and unique representation of a VLC key code * Format a human-readable and unique representation of a VLC key code
* (including modifiers). * (including modifiers).
* @param code key code to translate to a string
* @param locale true to get a localized string,
* false to get a C string suitable for 'vlcrc'
* @return a heap-allocated string, or NULL on error. * @return a heap-allocated string, or NULL on error.
*/ */
char *vlc_keycode2str (uint_fast32_t code) char *vlc_keycode2str (uint_fast32_t code, bool locale)
{ {
char *(*tr) (const char *) = locale ? vlc_gettext : nooptext;
const char *name; const char *name;
char *str, buf[5]; char *str, buf[5];
uintptr_t key = code & ~KEY_MODIFIER; uintptr_t key = code & ~KEY_MODIFIER;
...@@ -214,11 +226,12 @@ char *vlc_keycode2str (uint_fast32_t code) ...@@ -214,11 +226,12 @@ char *vlc_keycode2str (uint_fast32_t code)
found: found:
if (asprintf (&str, "%s%s%s%s%s%s", if (asprintf (&str, "%s%s%s%s%s%s",
(code & KEY_MODIFIER_CTRL) ? "Ctrl+" : "", (code & KEY_MODIFIER_CTRL) ? tr(N_("Ctrl+")) : "",
(code & KEY_MODIFIER_ALT) ? "Alt+" : "", (code & KEY_MODIFIER_ALT) ? tr(N_("Alt+")) : "",
(code & KEY_MODIFIER_SHIFT) ? "Shift+" : "", (code & KEY_MODIFIER_SHIFT) ? tr(N_("Shift+")) : "",
(code & KEY_MODIFIER_META) ? "Meta+" : "", (code & KEY_MODIFIER_META) ? tr(N_("Meta+")) : "",
(code & KEY_MODIFIER_COMMAND) ? "Command+" : "", name) == -1) (code & KEY_MODIFIER_COMMAND) ? tr(N_("Command+")) : "",
tr(name)) == -1)
return NULL; return NULL;
return str; return str;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment