persistpropbag.cpp 6.31 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 111 112
    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) )
113
    {
114
         size.cy = V_I4(&value);
115 116
        VariantClear(&value);
    }
117
    _p_instance->setExtent(size);
118 119

    V_VT(&value) = VT_BOOL;
120
    if( S_OK == pPropBag->Read(OLESTR("autoloop"), &value, pErrorLog) )
121
    {
122
        _p_instance->setAutoLoop(V_BOOL(&value) != VARIANT_FALSE);
123 124
        VariantClear(&value);
    }
125 126 127 128 129 130 131 132 133 134 135 136
    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);
        }
    }
137 138 139 140 141 142 143 144 145

    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;
146
    if( S_OK == pPropBag->Read(OLESTR("visible"), &value, pErrorLog) )
147 148 149 150
    {
        _p_instance->setVisible(V_BOOL(&value) != VARIANT_FALSE);
        VariantClear(&value);
    }
151 152 153 154 155 156 157 158 159 160 161 162
    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);
        }
    }
163

164 165 166 167 168 169 170
    int i_vlc = _p_instance->getVLCObject();
    V_VT(&value) = VT_I4;
    if( S_OK == pPropBag->Read(OLESTR("volume"), &value, pErrorLog) )
    {
        VLC_VolumeSet(i_vlc, V_I4(&value));
        VariantClear(&value);
    }
171
    return _p_instance->onLoad();
172 173
};

Damien Fouilleul's avatar
Damien Fouilleul committed
174
STDMETHODIMP VLCPersistPropertyBag::Save(LPPROPERTYBAG pPropBag, BOOL fClearDirty, BOOL fSaveAllProperties)
175 176
{
    if( NULL == pPropBag )
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
        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);

    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
201 202
    V_BSTR(&value) = SysAllocStringLen(_p_instance->getMRL(),
                            SysStringLen(_p_instance->getMRL()));
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
    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);

    int i_vlc = _p_instance->getVLCObject();
    if( i_vlc )
    {
        V_VT(&value) = VT_I4;
        V_I4(&value) = VLC_VolumeGet(i_vlc);
        pPropBag->Write(OLESTR("Volume"), &value);
        VariantClear(&value);
    }

    if( fClearDirty )
        _p_instance->setDirty(FALSE);
222 223 224 225

    return S_OK;
};