Commit 90ee09e8 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

KeyToString: allocate key on heap

This will allow returning dynamically generated strings
parent 4acb3f1f
...@@ -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_EXPORT( const char *, KeyToString, (uint_fast32_t i_key) ) LIBVLC_USED; VLC_EXPORT( char *, KeyToString, (uint_fast32_t i_key) ) LIBVLC_USED;
VLC_EXPORT( uint_fast32_t, StringToKey, (char *psz_key) ) LIBVLC_USED; VLC_EXPORT( uint_fast32_t, StringToKey, (char *psz_key) ) LIBVLC_USED;
typedef enum vlc_key { typedef enum vlc_key {
......
...@@ -86,9 +86,12 @@ static VLCSimplePrefs *_o_sharedInstance = nil; ...@@ -86,9 +86,12 @@ static VLCSimplePrefs *_o_sharedInstance = nil;
if( val & KEY_MODIFIER_COMMAND ) if( val & KEY_MODIFIER_COMMAND )
[o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\x98"]]; [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\x98"]];
const char *base = KeyToString( val & ~KEY_MODIFIER ); char *base = KeyToString( val & ~KEY_MODIFIER );
if( base ) if( base )
{
[o_temp_str appendString: [NSString stringWithUTF8String: base]]; [o_temp_str appendString: [NSString stringWithUTF8String: base]];
free( base );
}
else else
o_temp_str = [NSMutableString stringWithString:_NS("Not Set")]; o_temp_str = [NSMutableString stringWithString:_NS("Not Set")];
return o_temp_str; return o_temp_str;
......
...@@ -231,16 +231,23 @@ int qtWheelEventToVLCKey( QWheelEvent *e ) ...@@ -231,16 +231,23 @@ int qtWheelEventToVLCKey( QWheelEvent *e )
QString VLCKeyToString( int val ) QString VLCKeyToString( int val )
{ {
const char *base = KeyToString (val & ~KEY_MODIFIER); char *base = KeyToString (val & ~KEY_MODIFIER);
QString r = ""; QString r = "";
if( val & KEY_MODIFIER_CTRL ) if( val & KEY_MODIFIER_CTRL )
r+= "Ctrl+"; r+= qfu( "Ctrl+" );
if( val & KEY_MODIFIER_ALT ) if( val & KEY_MODIFIER_ALT )
r+= "Alt+"; r+= qfu( "Alt+" );
if( val & KEY_MODIFIER_SHIFT ) if( val & KEY_MODIFIER_SHIFT )
r+= "Shift+"; r+= qfu( "Shift+" );
return r + (base ? base : qtr( "Unset" ) ); if (base)
{
r += qfu( base );
free( base );
}
else
r += qtr( "Unset" );
return r;
} }
...@@ -39,9 +39,12 @@ const string EvtKey::getAsString() const ...@@ -39,9 +39,12 @@ const string EvtKey::getAsString() const
msg_Warn( getIntf(), "Unknown action type" ); msg_Warn( getIntf(), "Unknown action type" );
// Add the key // Add the key
const char *keyName = KeyToString( m_key ); char *keyName = KeyToString( m_key );
if( keyName ) if( keyName )
{
event += (string)":" + keyName; event += (string)":" + keyName;
free( keyName );
}
else else
msg_Warn( getIntf(), "Unknown key: %d", m_key ); msg_Warn( getIntf(), "Unknown key: %d", m_key );
......
...@@ -171,14 +171,14 @@ static int cmpkey (const void *key, const void *elem) ...@@ -171,14 +171,14 @@ static int cmpkey (const void *key, const void *elem)
return ((uintptr_t)key) - ((key_descriptor_t *)elem)->i_key_code; return ((uintptr_t)key) - ((key_descriptor_t *)elem)->i_key_code;
} }
const char *KeyToString (uint_fast32_t sym) char *KeyToString (uint_fast32_t sym)
{ {
key_descriptor_t *d; key_descriptor_t *d;
d = (key_descriptor_t *) d = (key_descriptor_t *)
bsearch ((void *)(uintptr_t)sym, vlc_keys, vlc_num_keys, bsearch ((void *)(uintptr_t)sym, vlc_keys, vlc_num_keys,
sizeof (vlc_keys[0]), cmpkey); sizeof (vlc_keys[0]), cmpkey);
return d ? d->psz_key_string : NULL; return d ? strdup (d->psz_key_string) : NULL;
} }
uint_fast32_t StringToKey (char *name) uint_fast32_t StringToKey (char *name)
......
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