persistpropbag.cpp 9.7 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 88 89 90
            else
            {
                V_VT(&value) = VT_BSTR;
                if( S_OK == pPropBag->Read(OLESTR("target"), &value, pErrorLog) )
                {
                    _p_instance->setMRL(V_BSTR(&value));
                    VariantClear(&value);
                }
            }
91 92 93 94 95 96
        }
    }

    V_VT(&value) = VT_BOOL;
    if( S_OK == pPropBag->Read(OLESTR("autoplay"), &value, pErrorLog) )
    {
97
        _p_instance->setAutoPlay(V_BOOL(&value) != VARIANT_FALSE);
98 99
        VariantClear(&value);
    }
100 101 102 103 104 105 106 107 108 109 110 111
    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);
        }
    }
112

113 114 115 116 117 118
    V_VT(&value) = VT_BOOL;
    if( S_OK == pPropBag->Read(OLESTR("toolbar"), &value, pErrorLog) )
    {
        _p_instance->setShowToolbar(V_BOOL(&value) != VARIANT_FALSE);
        VariantClear(&value);
    }
119 120 121 122 123 124 125 126 127 128 129 130
    else
    {
        /*
        ** try alternative syntax
        */
        V_VT(&value) = VT_BOOL;
        if( S_OK == pPropBag->Read(OLESTR("controls"), &value, pErrorLog) )
        {
            _p_instance->setShowToolbar(V_BOOL(&value) != VARIANT_FALSE);
            VariantClear(&value);
        }
    }
131

132 133 134 135 136 137 138 139 140
    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) )
141
    {
142
         size.cy = V_I4(&value);
143 144
        VariantClear(&value);
    }
145
    _p_instance->setExtent(size);
146 147

    V_VT(&value) = VT_BOOL;
148
    if( S_OK == pPropBag->Read(OLESTR("autoloop"), &value, pErrorLog) )
149
    {
150
        _p_instance->setAutoLoop(V_BOOL(&value) != VARIANT_FALSE);
151 152
        VariantClear(&value);
    }
153 154 155 156 157 158 159 160 161 162 163 164
    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);
        }
    }
165 166 167 168 169 170 171 172 173

    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;
174
    if( S_OK == pPropBag->Read(OLESTR("visible"), &value, pErrorLog) )
175 176 177 178
    {
        _p_instance->setVisible(V_BOOL(&value) != VARIANT_FALSE);
        VariantClear(&value);
    }
179 180 181 182 183 184 185 186 187 188 189 190
    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);
        }
    }
191

192 193 194
    V_VT(&value) = VT_I4;
    if( S_OK == pPropBag->Read(OLESTR("volume"), &value, pErrorLog) )
    {
195
        _p_instance->setVolume(V_I4(&value));
196 197
        VariantClear(&value);
    }
198 199 200 201

    V_VT(&value) = VT_I4;
    if( S_OK == pPropBag->Read(OLESTR("starttime"), &value, pErrorLog) )
    {
202 203 204 205 206 207 208 209
        _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));
210 211 212
        VariantClear(&value);
    }

213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
    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);
        }
    }

236 237 238
    V_VT(&value) = VT_BOOL;
    if( S_OK == pPropBag->Read(OLESTR("FullscreenEnabled"), &value, pErrorLog) )
    {
239
        _p_instance->get_options().set_enable_fs(V_BOOL(&value) != VARIANT_FALSE);
240 241
        VariantClear(&value);
    }
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
    else
    {
        /*
        ** try alternative syntax
        */
        V_VT(&value) = VT_BOOL;
        if( S_OK == pPropBag->Read(OLESTR("allowfullscreen"), &value, pErrorLog) )
        {
            _p_instance->get_options().set_enable_fs(V_BOOL(&value) != VARIANT_FALSE);
            VariantClear(&value);
        }
        else
        {
            V_VT(&value) = VT_BOOL;
            if( S_OK == pPropBag->Read(OLESTR("fullscreen"), &value, pErrorLog) )
            {
                _p_instance->get_options().set_enable_fs(V_BOOL(&value) != VARIANT_FALSE);
                VariantClear(&value);
            }
        }
    }
263

264
    return _p_instance->onLoad();
265 266
};

267
STDMETHODIMP VLCPersistPropertyBag::Save(LPPROPERTYBAG pPropBag, BOOL fClearDirty, BOOL)
268 269
{
    if( NULL == pPropBag )
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
        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);

286 287 288 289 290
    V_VT(&value) = VT_BOOL;
    V_BOOL(&value) = _p_instance->getShowToolbar()? VARIANT_TRUE : VARIANT_FALSE;
    pPropBag->Write(OLESTR("Toolbar"), &value);
    VariantClear(&value);

291 292 293 294 295 296 297 298
    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;
299 300
    V_BSTR(&value) = SysAllocStringLen(_p_instance->getMRL(),
                            SysStringLen(_p_instance->getMRL()));
301 302 303 304 305 306 307 308
    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);

309 310 311 312
    V_VT(&value) = VT_I4;
    V_I4(&value) = _p_instance->getVolume();
    pPropBag->Write(OLESTR("Volume"), &value);
    VariantClear(&value);
313

314
    V_VT(&value) = VT_I4;
315
    V_I4(&value) = _p_instance->getStartTime();
316 317 318
    pPropBag->Write(OLESTR("StartTime"), &value);
    VariantClear(&value);

319 320 321 322 323 324
    V_VT(&value) = VT_BSTR;
    V_BSTR(&value) = SysAllocStringLen(_p_instance->getBaseURL(),
                            SysStringLen(_p_instance->getBaseURL()));
    pPropBag->Write(OLESTR("BaseURL"), &value);
    VariantClear(&value);

325 326 327 328 329
    V_VT(&value) = VT_I4;
    V_I4(&value) = _p_instance->getBackColor();
    pPropBag->Write(OLESTR("BackColor"), &value);
    VariantClear(&value);

330
    V_VT(&value) = VT_BOOL;
331
    V_BOOL(&value) = _p_instance->get_options().get_enable_fs()? VARIANT_TRUE : VARIANT_FALSE;
332 333 334
    pPropBag->Write(OLESTR("FullscreenEnabled"), &value);
    VariantClear(&value);

335 336
    if( fClearDirty )
        _p_instance->setDirty(FALSE);
337 338 339

    return S_OK;
};