persistpropbag.cpp 8.04 KB
Newer Older
1 2 3
/*****************************************************************************
 * persistpropbag.cpp: ActiveX control for VLC
 *****************************************************************************
4
 * Copyright (C) 2005 the VideoLAN team
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 22 23 24 25 26
 *****************************************************************************/

#include "plugin.h"
#include "persistpropbag.h"

#include "utils.h"
27
#include "oleobject.h"
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

using namespace std;

STDMETHODIMP VLCPersistPropertyBag::GetClassID(LPCLSID pClsID)
{
    if( NULL == pClsID )
        return E_POINTER;

    *pClsID = _p_instance->getClassID();

    return S_OK;
};

STDMETHODIMP VLCPersistPropertyBag::InitNew(void)
{
43
    return _p_instance->onInit();
44 45 46 47
};

STDMETHODIMP VLCPersistPropertyBag::Load(LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog)
{
48
    HRESULT hr = _p_instance->onInit();
49 50 51
    if( FAILED(hr) )
        return hr;

52 53 54
    if( NULL == pPropBag )
        return E_INVALIDARG;

55 56 57
    VARIANT value;

    V_VT(&value) = VT_BSTR;
58
    if( S_OK == pPropBag->Read(OLESTR("mrl"), &value, pErrorLog) )
59
    {
60
        _p_instance->setMRL(V_BSTR(&value));
61 62
        VariantClear(&value);
    }
63
    else
64
    {
65 66 67 68 69
        /*
        ** try alternative syntax
        */
        V_VT(&value) = VT_BSTR;
        if( S_OK == pPropBag->Read(OLESTR("src"), &value, pErrorLog) )
70
        {
71 72 73 74 75 76 77 78 79 80 81
            _p_instance->setMRL(V_BSTR(&value));
            VariantClear(&value);
        }
        else
        {
            V_VT(&value) = VT_BSTR;
            if( S_OK == pPropBag->Read(OLESTR("filename"), &value, pErrorLog) )
            {
                _p_instance->setMRL(V_BSTR(&value));
                VariantClear(&value);
            }
82 83 84 85 86 87
        }
    }

    V_VT(&value) = VT_BOOL;
    if( S_OK == pPropBag->Read(OLESTR("autoplay"), &value, pErrorLog) )
    {
88
        _p_instance->setAutoPlay(V_BOOL(&value) != VARIANT_FALSE);
89 90
        VariantClear(&value);
    }
91 92 93 94 95 96 97 98 99 100 101 102
    else
    {
        /*
        ** try alternative syntax
        */
        V_VT(&value) = VT_BOOL;
        if( S_OK == pPropBag->Read(OLESTR("autostart"), &value, pErrorLog) )
        {
            _p_instance->setAutoPlay(V_BOOL(&value) != VARIANT_FALSE);
            VariantClear(&value);
        }
    }
103

104 105 106 107 108 109 110
    V_VT(&value) = VT_BOOL;
    if( S_OK == pPropBag->Read(OLESTR("toolbar"), &value, pErrorLog) )
    {
        _p_instance->setShowToolbar(V_BOOL(&value) != VARIANT_FALSE);
        VariantClear(&value);
    }

111 112 113 114 115 116 117 118 119
    SIZEL size = _p_instance->getExtent();
    V_VT(&value) = VT_I4;
    if( S_OK == pPropBag->Read(OLESTR("extentwidth"), &value, pErrorLog) )
    {
         size.cx = V_I4(&value);
        VariantClear(&value);
    }
    V_VT(&value) = VT_I4;
    if( S_OK == pPropBag->Read(OLESTR("extentheight"), &value, pErrorLog) )
120
    {
121
         size.cy = V_I4(&value);
122 123
        VariantClear(&value);
    }
124
    _p_instance->setExtent(size);
125 126

    V_VT(&value) = VT_BOOL;
127
    if( S_OK == pPropBag->Read(OLESTR("autoloop"), &value, pErrorLog) )
128
    {
129
        _p_instance->setAutoLoop(V_BOOL(&value) != VARIANT_FALSE);
130 131
        VariantClear(&value);
    }
132 133 134 135 136 137 138 139 140 141 142 143
    else
    {
        /*
        ** try alternative syntax
        */
        V_VT(&value) = VT_BOOL;
        if( S_OK == pPropBag->Read(OLESTR("loop"), &value, pErrorLog) )
        {
            _p_instance->setAutoLoop(V_BOOL(&value) != VARIANT_FALSE);
            VariantClear(&value);
        }
    }
144 145 146 147 148 149 150 151 152

    V_VT(&value) = VT_BOOL;
    if( S_OK == pPropBag->Read(OLESTR("mute"), &value, pErrorLog) )
    {
        _p_instance->setMute(V_BOOL(&value) != VARIANT_FALSE);
        VariantClear(&value);
    }

    V_VT(&value) = VT_BOOL;
153
    if( S_OK == pPropBag->Read(OLESTR("visible"), &value, pErrorLog) )
154 155 156 157
    {
        _p_instance->setVisible(V_BOOL(&value) != VARIANT_FALSE);
        VariantClear(&value);
    }
158 159 160 161 162 163 164 165 166 167 168 169
    else
    {
        /*
        ** try alternative syntax
        */
        V_VT(&value) = VT_BOOL;
        if( S_OK == pPropBag->Read(OLESTR("showdisplay"), &value, pErrorLog) )
        {
            _p_instance->setVisible(V_BOOL(&value) != VARIANT_FALSE);
            VariantClear(&value);
        }
    }
170

171 172 173
    V_VT(&value) = VT_I4;
    if( S_OK == pPropBag->Read(OLESTR("volume"), &value, pErrorLog) )
    {
174
        _p_instance->setVolume(V_I4(&value));
175 176
        VariantClear(&value);
    }
177 178 179 180

    V_VT(&value) = VT_I4;
    if( S_OK == pPropBag->Read(OLESTR("starttime"), &value, pErrorLog) )
    {
181 182 183 184 185 186 187 188
        _p_instance->setStartTime(V_I4(&value));
        VariantClear(&value);
    }

    V_VT(&value) = VT_BSTR;
    if( S_OK == pPropBag->Read(OLESTR("baseurl"), &value, pErrorLog) )
    {
        _p_instance->setBaseURL(V_BSTR(&value));
189 190 191
        VariantClear(&value);
    }

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
    V_VT(&value) = VT_I4;
    if( S_OK == pPropBag->Read(OLESTR("backcolor"), &value, pErrorLog) )
    {
        _p_instance->setBackColor(V_I4(&value));
        VariantClear(&value);
    }
    else
    {
        /*
        ** try alternative syntax
        */
        V_VT(&value) = VT_BSTR;
        if( S_OK == pPropBag->Read(OLESTR("bgcolor"), &value, pErrorLog) )
        {
            long backcolor;
            if( swscanf(V_BSTR(&value), L"#%lX", &backcolor) )
            {
                _p_instance->setBackColor(backcolor);
            }
            VariantClear(&value);
        }
    }

215
    return _p_instance->onLoad();
216 217
};

218
STDMETHODIMP VLCPersistPropertyBag::Save(LPPROPERTYBAG pPropBag, BOOL fClearDirty, BOOL)
219 220
{
    if( NULL == pPropBag )
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
        return E_INVALIDARG;

    VARIANT value;

    VariantInit(&value);

    V_VT(&value) = VT_BOOL;
    V_BOOL(&value) = _p_instance->getAutoLoop()? VARIANT_TRUE : VARIANT_FALSE;
    pPropBag->Write(OLESTR("AutoLoop"), &value);
    VariantClear(&value);

    V_VT(&value) = VT_BOOL;
    V_BOOL(&value) = _p_instance->getAutoPlay()? VARIANT_TRUE : VARIANT_FALSE;
    pPropBag->Write(OLESTR("AutoPlay"), &value);
    VariantClear(&value);

237 238 239 240 241
    V_VT(&value) = VT_BOOL;
    V_BOOL(&value) = _p_instance->getShowToolbar()? VARIANT_TRUE : VARIANT_FALSE;
    pPropBag->Write(OLESTR("Toolbar"), &value);
    VariantClear(&value);

242 243 244 245 246 247 248 249
    SIZEL size = _p_instance->getExtent();
    V_VT(&value) = VT_I4;
    V_I4(&value) = size.cx;
    pPropBag->Write(OLESTR("ExtentWidth"), &value);
    V_I4(&value) = size.cy;
    pPropBag->Write(OLESTR("ExtentHeight"), &value);

    V_VT(&value) = VT_BSTR;
Damien Fouilleul's avatar
Damien Fouilleul committed
250 251
    V_BSTR(&value) = SysAllocStringLen(_p_instance->getMRL(),
                            SysStringLen(_p_instance->getMRL()));
252 253 254 255 256 257 258 259
    pPropBag->Write(OLESTR("MRL"), &value);
    VariantClear(&value);

    V_VT(&value) = VT_BOOL;
    V_BOOL(&value) = _p_instance->getVisible()? VARIANT_TRUE : VARIANT_FALSE;
    pPropBag->Write(OLESTR("Visible"), &value);
    VariantClear(&value);

260 261 262 263
    V_VT(&value) = VT_I4;
    V_I4(&value) = _p_instance->getVolume();
    pPropBag->Write(OLESTR("Volume"), &value);
    VariantClear(&value);
264

265
    V_VT(&value) = VT_I4;
266
    V_I4(&value) = _p_instance->getStartTime();
267 268 269
    pPropBag->Write(OLESTR("StartTime"), &value);
    VariantClear(&value);

270 271 272 273 274 275
    V_VT(&value) = VT_BSTR;
    V_BSTR(&value) = SysAllocStringLen(_p_instance->getBaseURL(),
                            SysStringLen(_p_instance->getBaseURL()));
    pPropBag->Write(OLESTR("BaseURL"), &value);
    VariantClear(&value);

276 277 278 279 280
    V_VT(&value) = VT_I4;
    V_I4(&value) = _p_instance->getBackColor();
    pPropBag->Write(OLESTR("BackColor"), &value);
    VariantClear(&value);

281 282
    if( fClearDirty )
        _p_instance->setDirty(FALSE);
283 284 285

    return S_OK;
};