]> git.sesse.net Git - vlc/blobdiff - activex/vlccontrol.cpp
Removes trailing spaces. Removes tabs.
[vlc] / activex / vlccontrol.cpp
index f45760b570b7a8beec782972085d269e237127e9..d9793bf30a87f384bcbe5b56d4aebd6305b1a953 100644 (file)
@@ -82,7 +82,7 @@ STDMETHODIMP VLCControl::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo
     return E_NOTIMPL;
 };
 
-STDMETHODIMP VLCControl::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, 
+STDMETHODIMP VLCControl::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
         UINT cNames, LCID lcid, DISPID* rgDispID)
 {
     if( SUCCEEDED(getTypeInfo()) )
@@ -132,7 +132,7 @@ STDMETHODIMP VLCControl::play(void)
     }
     return result;
 };
+
 STDMETHODIMP VLCControl::pause(void)
 {
     int i_vlc;
@@ -144,7 +144,7 @@ STDMETHODIMP VLCControl::pause(void)
     }
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::stop(void)
 {
     int i_vlc;
@@ -156,7 +156,7 @@ STDMETHODIMP VLCControl::stop(void)
     }
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::get_Playing(VARIANT_BOOL *isPlaying)
 {
     if( NULL == isPlaying )
@@ -176,7 +176,7 @@ STDMETHODIMP VLCControl::get_Playing(VARIANT_BOOL *isPlaying)
     *isPlaying = VARIANT_FALSE;
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::get_Position(float *position)
 {
     if( NULL == position )
@@ -196,7 +196,7 @@ STDMETHODIMP VLCControl::get_Position(float *position)
     *position = 0.0f;
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::put_Position(float position)
 {
     HRESULT result = E_UNEXPECTED;
@@ -211,7 +211,7 @@ STDMETHODIMP VLCControl::put_Position(float position)
     }
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::get_Time(int *seconds)
 {
     if( NULL == seconds )
@@ -232,14 +232,14 @@ STDMETHODIMP VLCControl::get_Time(int *seconds)
 
     return result;
 };
-     
+
 STDMETHODIMP VLCControl::put_Time(int seconds)
 {
     _p_instance->setTime(seconds);
 
     return NOERROR;
 };
-        
+
 STDMETHODIMP VLCControl::shuttle(int seconds)
 {
     HRESULT result = E_UNEXPECTED;
@@ -254,7 +254,7 @@ STDMETHODIMP VLCControl::shuttle(int seconds)
     }
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::fullscreen(void)
 {
     HRESULT result = E_UNEXPECTED;
@@ -269,7 +269,7 @@ STDMETHODIMP VLCControl::fullscreen(void)
     }
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::get_Length(int *seconds)
 {
     if( NULL == seconds )
@@ -289,7 +289,7 @@ STDMETHODIMP VLCControl::get_Length(int *seconds)
     *seconds = 0;
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::playFaster(void)
 {
     HRESULT result = E_UNEXPECTED;
@@ -304,7 +304,7 @@ STDMETHODIMP VLCControl::playFaster(void)
     }
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::playSlower(void)
 {
     HRESULT result = E_UNEXPECTED;
@@ -319,7 +319,7 @@ STDMETHODIMP VLCControl::playSlower(void)
     }
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::get_Volume(int *volume)
 {
     if( NULL == volume )
@@ -328,13 +328,13 @@ STDMETHODIMP VLCControl::get_Volume(int *volume)
     *volume  = _p_instance->getVolume();
     return NOERROR;
 };
-        
+
 STDMETHODIMP VLCControl::put_Volume(int volume)
 {
     _p_instance->setVolume(volume);
     return NOERROR;
 };
-        
+
 STDMETHODIMP VLCControl::toggleMute(void)
 {
     int i_vlc;
@@ -362,7 +362,7 @@ STDMETHODIMP VLCControl::setVariable(BSTR name, VARIANT value)
 
         int i_type;
         vlc_value_t val;
-        
+
         if( VLC_SUCCESS == VLC_VariableType(i_vlc, psz_varname, &i_type) )
         {
             VARIANT arg;
@@ -531,7 +531,7 @@ STDMETHODIMP VLCControl::getVariable( BSTR name, VARIANT *value)
 
 void VLCControl::FreeTargetOptions(char **cOptions, int cOptionCount)
 {
-    // clean up 
+    // clean up
     if( NULL != cOptions )
     {
         for( int pos=0; pos<cOptionCount; ++pos )
@@ -546,6 +546,92 @@ void VLCControl::FreeTargetOptions(char **cOptions, int cOptionCount)
     }
 };
 
+static HRESULT parseStringOptions(int codePage, BSTR bstr, char*** cOptions, int *cOptionCount)
+{
+    HRESULT hr = E_INVALIDARG;
+    if( SysStringLen(bstr) > 0 )
+    {
+        hr = E_OUTOFMEMORY;
+        char *s = CStrFromBSTR(codePage, bstr);
+        char *val = s;
+        if( val )
+        {
+            long capacity = 16;
+            char **options = (char **)CoTaskMemAlloc(capacity*sizeof(char *));
+            if( options )
+            {
+                int nOptions = 0;
+
+                char *end = val + strlen(val);
+                while( val < end )
+                {
+                    // skip leading blanks
+                    while( (val < end)
+                        && ((*val == ' ' ) || (*val == '\t')) )
+                        ++val;
+
+                    char *start = val;
+                    // skip till we get a blank character
+                    while( (val < end)
+                        && (*val != ' ' )
+                        && (*val != '\t') )
+                    {
+                        char c = *(val++);
+                        if( ('\'' == c) || ('"' == c) )
+                        {
+                            // skip till end of string
+                            while( (val < end) && (*(val++) != c ) );
+                        }
+                    }
+
+                    if( val > start )
+                    {
+                        if( nOptions == capacity )
+                        {
+                            capacity += 16;
+                            char **moreOptions = (char **)CoTaskMemRealloc(options, capacity*sizeof(char*));
+                            if( ! moreOptions )
+                            {
+                                /* failed to allocate more memory */
+                                CoTaskMemFree(s);
+                                /* return what we got so far */
+                                *cOptionCount = nOptions;
+                                *cOptions = options;
+                                return NOERROR;
+                            }
+                            options = moreOptions;
+                        }
+                        *(val++) = '\0';
+                        options[nOptions] = (char *)CoTaskMemAlloc(val-start);
+                        if( options[nOptions] )
+                        {
+                            memcpy(options[nOptions], start, val-start);
+                            ++nOptions;
+                        }
+                        else
+                        {
+                            /* failed to allocate memory */
+                            CoTaskMemFree(s);
+                            /* return what we got so far */
+                            *cOptionCount = nOptions;
+                            *cOptions = options;
+                            return NOERROR;
+                        }
+                    }
+                    else
+                        // must be end of string
+                        break;
+                }
+                *cOptionCount = nOptions;
+                *cOptions = options;
+                hr = NOERROR;
+            }
+            CoTaskMemFree(s);
+        }
+    }
+    return hr;
+}
+
 HRESULT VLCControl::CreateTargetOptions(int codePage, VARIANT *options, char ***cOptions, int *cOptionCount)
 {
     HRESULT hr = E_INVALIDARG;
@@ -568,7 +654,7 @@ HRESULT VLCControl::CreateTargetOptions(int codePage, VARIANT *options, char ***
     }
     else if( VT_DISPATCH == V_VT(options) )
     {
-        // collection parameter
+        // if object is a collection, retrieve enumerator
         VARIANT colEnum;
         V_VT(&colEnum) = VT_UNKNOWN;
         hr = GetObjectProperty(V_DISPATCH(options), DISPID_NEWENUM, colEnum);
@@ -630,6 +716,18 @@ HRESULT VLCControl::CreateTargetOptions(int codePage, VARIANT *options, char ***
                 enumVar->Release();
             }
         }
+        else
+        {
+            // coerce object into a string and parse it
+            VARIANT v_name;
+            VariantInit(&v_name);
+            hr = VariantChangeType(&v_name, options, 0, VT_BSTR);
+            if( SUCCEEDED(hr) )
+            {
+                hr = parseStringOptions(codePage, V_BSTR(&v_name), cOptions, cOptionCount);
+                VariantClear(&v_name);
+            }
+        }
     }
     else if( V_ISARRAY(options) )
     {
@@ -668,7 +766,7 @@ HRESULT VLCControl::CreateTargetOptions(int codePage, VARIANT *options, char ***
                     hr = SafeArrayGetElement(array, &pos, &option);
                     if( SUCCEEDED(hr) )
                     {
-                        if( VT_BSTR == V_VT(&option) ) 
+                        if( VT_BSTR == V_VT(&option) )
                         {
                             char *cOption = CStrFromBSTR(codePage, V_BSTR(&option));
                             (*cOptions)[pos-lBound] = cOption;
@@ -705,7 +803,7 @@ HRESULT VLCControl::CreateTargetOptions(int codePage, VARIANT *options, char ***
                     }
                 }
             }
-            else 
+            else
             {
                 // unsupported type
                 return E_INVALIDARG;
@@ -726,6 +824,22 @@ HRESULT VLCControl::CreateTargetOptions(int codePage, VARIANT *options, char ***
             return NOERROR;
         }
     }
+    else if( VT_UNKNOWN == V_VT(options) )
+    {
+        // coerce object into a string and parse it
+        VARIANT v_name;
+        VariantInit(&v_name);
+        hr = VariantChangeType(&v_name, options, 0, VT_BSTR);
+        if( SUCCEEDED(hr) )
+        {
+            hr = parseStringOptions(codePage, V_BSTR(&v_name), cOptions, cOptionCount);
+            VariantClear(&v_name);
+        }
+    }
+    else if( VT_BSTR == V_VT(options) )
+    {
+        hr = parseStringOptions(codePage, V_BSTR(options), cOptions, cOptionCount);
+    }
     return hr;
 };
 
@@ -771,7 +885,7 @@ STDMETHODIMP VLCControl::addTarget( BSTR uri, VARIANT options, enum VLCPlaylistM
     }
     return hr;
 };
-        
+
 STDMETHODIMP VLCControl::get_PlaylistIndex(int *index)
 {
     if( NULL == index )
@@ -787,7 +901,7 @@ STDMETHODIMP VLCControl::get_PlaylistIndex(int *index)
     *index = 0;
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::get_PlaylistCount(int *count)
 {
     int i_vlc;
@@ -800,7 +914,7 @@ STDMETHODIMP VLCControl::get_PlaylistCount(int *count)
     *count = 0;
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::playlistNext(void)
 {
     int i_vlc;
@@ -812,7 +926,7 @@ STDMETHODIMP VLCControl::playlistNext(void)
     }
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::playlistPrev(void)
 {
     int i_vlc;
@@ -824,7 +938,7 @@ STDMETHODIMP VLCControl::playlistPrev(void)
     }
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::playlistClear(void)
 {
     int i_vlc;
@@ -836,7 +950,7 @@ STDMETHODIMP VLCControl::playlistClear(void)
     }
     return result;
 };
-        
+
 STDMETHODIMP VLCControl::get_VersionInfo(BSTR *version)
 {
     if( NULL == version )
@@ -845,14 +959,14 @@ STDMETHODIMP VLCControl::get_VersionInfo(BSTR *version)
     const char *versionStr = VLC_Version();
     if( NULL != versionStr )
     {
-        *version = BSTRFromCStr(_p_instance->getCodePage(), versionStr);
-        
+        *version = BSTRFromCStr(CP_UTF8, versionStr);
         return NULL == *version ? E_OUTOFMEMORY : NOERROR;
     }
     *version = NULL;
     return E_FAIL;
 };
+
 STDMETHODIMP VLCControl::get_MRL(BSTR *mrl)
 {
     if( NULL == mrl )
@@ -899,4 +1013,3 @@ STDMETHODIMP VLCControl::put_AutoLoop(VARIANT_BOOL autoloop)
     _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
     return S_OK;
 };
-