persistpropbag.cpp 10.2 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
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

27 28 29 30
#include "plugin.h"
#include "persistpropbag.h"

#include "utils.h"
31
#include "oleobject.h"
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

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)
{
47
    return _p_instance->onInit();
48 49 50 51
};

STDMETHODIMP VLCPersistPropertyBag::Load(LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog)
{
52
    HRESULT hr = _p_instance->onInit();
53 54 55
    if( FAILED(hr) )
        return hr;

56 57 58
    if( NULL == pPropBag )
        return E_INVALIDARG;

59 60 61
    VARIANT value;

    V_VT(&value) = VT_BSTR;
62
    if( S_OK == pPropBag->Read(OLESTR("mrl"), &value, pErrorLog) )
63
    {
64
        _p_instance->setMRL(V_BSTR(&value));
65 66
        VariantClear(&value);
    }
67
    else
68
    {
69 70 71 72 73
        /*
        ** try alternative syntax
        */
        V_VT(&value) = VT_BSTR;
        if( S_OK == pPropBag->Read(OLESTR("src"), &value, pErrorLog) )
74
        {
75 76 77 78 79 80 81 82 83 84 85
            _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);
            }
86 87 88 89 90 91 92 93 94
            else
            {
                V_VT(&value) = VT_BSTR;
                if( S_OK == pPropBag->Read(OLESTR("target"), &value, pErrorLog) )
                {
                    _p_instance->setMRL(V_BSTR(&value));
                    VariantClear(&value);
                }
            }
95 96 97 98 99 100
        }
    }

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

117 118 119 120 121 122
    V_VT(&value) = VT_BOOL;
    if( S_OK == pPropBag->Read(OLESTR("toolbar"), &value, pErrorLog) )
    {
        _p_instance->setShowToolbar(V_BOOL(&value) != VARIANT_FALSE);
        VariantClear(&value);
    }
123 124 125 126 127 128 129 130 131 132 133 134
    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);
        }
    }
135

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

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

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

196 197 198
    V_VT(&value) = VT_I4;
    if( S_OK == pPropBag->Read(OLESTR("volume"), &value, pErrorLog) )
    {
199
        _p_instance->setVolume(V_I4(&value));
200 201
        VariantClear(&value);
    }
202 203 204 205

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

217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
    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);
        }
    }

240 241 242
    V_VT(&value) = VT_BOOL;
    if( S_OK == pPropBag->Read(OLESTR("FullscreenEnabled"), &value, pErrorLog) )
    {
243
        _p_instance->get_options().set_enable_fs(V_BOOL(&value) != VARIANT_FALSE);
244 245
        VariantClear(&value);
    }
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
    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);
            }
        }
    }
267

268 269 270 271 272 273 274
    V_VT(&value) = VT_BOOL;
    if( S_OK == pPropBag->Read(OLESTR("Branding"), &value, pErrorLog) )
    {
        _p_instance->get_options().set_enable_branding(V_BOOL(&value) != VARIANT_FALSE);
        VariantClear(&value);
    }

275
    return _p_instance->onLoad();
276 277
};

278
STDMETHODIMP VLCPersistPropertyBag::Save(LPPROPERTYBAG pPropBag, BOOL fClearDirty, BOOL)
279 280
{
    if( NULL == pPropBag )
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
        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);

297 298 299 300 301
    V_VT(&value) = VT_BOOL;
    V_BOOL(&value) = _p_instance->getShowToolbar()? VARIANT_TRUE : VARIANT_FALSE;
    pPropBag->Write(OLESTR("Toolbar"), &value);
    VariantClear(&value);

302 303 304 305 306 307 308 309
    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;
310 311
    V_BSTR(&value) = SysAllocStringLen(_p_instance->getMRL(),
                            SysStringLen(_p_instance->getMRL()));
312 313 314 315 316 317 318 319
    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);

320 321 322 323
    V_VT(&value) = VT_I4;
    V_I4(&value) = _p_instance->getVolume();
    pPropBag->Write(OLESTR("Volume"), &value);
    VariantClear(&value);
324

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

330 331 332 333 334 335
    V_VT(&value) = VT_BSTR;
    V_BSTR(&value) = SysAllocStringLen(_p_instance->getBaseURL(),
                            SysStringLen(_p_instance->getBaseURL()));
    pPropBag->Write(OLESTR("BaseURL"), &value);
    VariantClear(&value);

336 337 338 339 340
    V_VT(&value) = VT_I4;
    V_I4(&value) = _p_instance->getBackColor();
    pPropBag->Write(OLESTR("BackColor"), &value);
    VariantClear(&value);

341
    V_VT(&value) = VT_BOOL;
342
    V_BOOL(&value) = _p_instance->get_options().get_enable_fs()? VARIANT_TRUE : VARIANT_FALSE;
343 344 345
    pPropBag->Write(OLESTR("FullscreenEnabled"), &value);
    VariantClear(&value);

346 347 348 349 350
    V_VT(&value) = VT_BOOL;
    V_BOOL(&value) = _p_instance->get_options().get_enable_branding()? VARIANT_TRUE : VARIANT_FALSE;
    pPropBag->Write(OLESTR("Branding"), &value);
    VariantClear(&value);

351 352
    if( fClearDirty )
        _p_instance->setDirty(FALSE);
353 354 355

    return S_OK;
};