[vlc-devel] commit: KeyToString: allocate key on heap ( Rémi Denis-Courmont )

git version control git at videolan.org
Wed Oct 7 21:43:36 CEST 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Oct  7 22:07:11 2009 +0300| [90ee09e819d430a289b4fe82f0af40eb5b02f086] | committer: Rémi Denis-Courmont 

KeyToString: allocate key on heap

This will allow returning dynamically generated strings

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=90ee09e819d430a289b4fe82f0af40eb5b02f086
---

 include/vlc_keys.h                     |    2 +-
 modules/gui/macosx/simple_prefs.m      |    5 ++++-
 modules/gui/qt4/util/customwidgets.cpp |   17 ++++++++++++-----
 modules/gui/skins2/events/evt_key.cpp  |    5 ++++-
 src/config/keys.c                      |    4 ++--
 5 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/include/vlc_keys.h b/include/vlc_keys.h
index f24dd64..795c42f 100644
--- a/include/vlc_keys.h
+++ b/include/vlc_keys.h
@@ -86,7 +86,7 @@
 #define KEY_MOUSEWHEELLEFT   0x00F20000
 #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;
 
 typedef enum vlc_key {
diff --git a/modules/gui/macosx/simple_prefs.m b/modules/gui/macosx/simple_prefs.m
index 5bcfd33..4dbe968 100644
--- a/modules/gui/macosx/simple_prefs.m
+++ b/modules/gui/macosx/simple_prefs.m
@@ -86,9 +86,12 @@ static VLCSimplePrefs *_o_sharedInstance = nil;
     if( val & KEY_MODIFIER_COMMAND )
         [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\x98"]];
 
-    const char *base = KeyToString( val & ~KEY_MODIFIER );
+    char *base = KeyToString( val & ~KEY_MODIFIER );
     if( base )
+    {
         [o_temp_str appendString: [NSString stringWithUTF8String: base]];
+        free( base );
+    }
     else
         o_temp_str = [NSMutableString stringWithString:_NS("Not Set")];
     return o_temp_str;
diff --git a/modules/gui/qt4/util/customwidgets.cpp b/modules/gui/qt4/util/customwidgets.cpp
index c02945c..820c8d3 100644
--- a/modules/gui/qt4/util/customwidgets.cpp
+++ b/modules/gui/qt4/util/customwidgets.cpp
@@ -231,16 +231,23 @@ int qtWheelEventToVLCKey( QWheelEvent *e )
 
 QString VLCKeyToString( int val )
 {
-    const char *base = KeyToString (val & ~KEY_MODIFIER);
+    char *base = KeyToString (val & ~KEY_MODIFIER);
 
     QString r = "";
     if( val & KEY_MODIFIER_CTRL )
-        r+= "Ctrl+";
+        r+= qfu( "Ctrl+" );
     if( val & KEY_MODIFIER_ALT )
-        r+= "Alt+";
+        r+= qfu( "Alt+" );
     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;
 }
 
diff --git a/modules/gui/skins2/events/evt_key.cpp b/modules/gui/skins2/events/evt_key.cpp
index ad10f7b..99d01ad 100644
--- a/modules/gui/skins2/events/evt_key.cpp
+++ b/modules/gui/skins2/events/evt_key.cpp
@@ -39,9 +39,12 @@ const string EvtKey::getAsString() const
         msg_Warn( getIntf(), "Unknown action type" );
 
     // Add the key
-    const char *keyName = KeyToString( m_key );
+    char *keyName = KeyToString( m_key );
     if( keyName )
+    {
         event += (string)":" + keyName;
+        free( keyName );
+    }
     else
         msg_Warn( getIntf(), "Unknown key: %d", m_key );
 
diff --git a/src/config/keys.c b/src/config/keys.c
index 07980e6..0fd50cd 100644
--- a/src/config/keys.c
+++ b/src/config/keys.c
@@ -171,14 +171,14 @@ static int cmpkey (const void *key, const void *elem)
     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;
 
     d = (key_descriptor_t *)
         bsearch ((void *)(uintptr_t)sym, vlc_keys, vlc_num_keys,
                  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)




More information about the vlc-devel mailing list