]> git.sesse.net Git - vlc/blob - projects/activex/persistpropbag.cpp
Cosmetics : Fix real.c comment header since sipr support was merged in trunk.
[vlc] / projects / activex / persistpropbag.cpp
1 /*****************************************************************************
2  * persistpropbag.cpp: ActiveX control for VLC
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  *
6  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 #include "plugin.h"
24 #include "persistpropbag.h"
25
26 #include "utils.h"
27 #include "oleobject.h"
28
29 using namespace std;
30
31 STDMETHODIMP VLCPersistPropertyBag::GetClassID(LPCLSID pClsID)
32 {
33     if( NULL == pClsID )
34         return E_POINTER;
35
36     *pClsID = _p_instance->getClassID();
37
38     return S_OK;
39 };
40
41 STDMETHODIMP VLCPersistPropertyBag::InitNew(void)
42 {
43     return _p_instance->onInit();
44 };
45
46 STDMETHODIMP VLCPersistPropertyBag::Load(LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog)
47 {
48     HRESULT hr = _p_instance->onInit();
49     if( FAILED(hr) )
50         return hr;
51
52     if( NULL == pPropBag )
53         return E_INVALIDARG;
54
55     VARIANT value;
56
57     V_VT(&value) = VT_BSTR;
58     if( S_OK == pPropBag->Read(OLESTR("mrl"), &value, pErrorLog) )
59     {
60         _p_instance->setMRL(V_BSTR(&value));
61         VariantClear(&value);
62     }
63     else
64     {
65         /*
66         ** try alternative syntax
67         */
68         V_VT(&value) = VT_BSTR;
69         if( S_OK == pPropBag->Read(OLESTR("src"), &value, pErrorLog) )
70         {
71             _p_instance->setMRL(V_BSTR(&value));
72             VariantClear(&value);
73         }
74         else
75         {
76             V_VT(&value) = VT_BSTR;
77             if( S_OK == pPropBag->Read(OLESTR("filename"), &value, pErrorLog) )
78             {
79                 _p_instance->setMRL(V_BSTR(&value));
80                 VariantClear(&value);
81             }
82         }
83     }
84
85     V_VT(&value) = VT_BOOL;
86     if( S_OK == pPropBag->Read(OLESTR("autoplay"), &value, pErrorLog) )
87     {
88         _p_instance->setAutoPlay(V_BOOL(&value) != VARIANT_FALSE);
89         VariantClear(&value);
90     }
91     else
92     {
93         /*
94         ** try alternative syntax
95         */
96         V_VT(&value) = VT_BOOL;
97         if( S_OK == pPropBag->Read(OLESTR("autostart"), &value, pErrorLog) )
98         {
99             _p_instance->setAutoPlay(V_BOOL(&value) != VARIANT_FALSE);
100             VariantClear(&value);
101         }
102     }
103
104     V_VT(&value) = VT_BOOL;
105     if( S_OK == pPropBag->Read(OLESTR("toolbar"), &value, pErrorLog) )
106     {
107         _p_instance->setShowToolbar(V_BOOL(&value) != VARIANT_FALSE);
108         VariantClear(&value);
109     }
110
111     SIZEL size = _p_instance->getExtent();
112     V_VT(&value) = VT_I4;
113     if( S_OK == pPropBag->Read(OLESTR("extentwidth"), &value, pErrorLog) )
114     {
115          size.cx = V_I4(&value);
116         VariantClear(&value);
117     }
118     V_VT(&value) = VT_I4;
119     if( S_OK == pPropBag->Read(OLESTR("extentheight"), &value, pErrorLog) )
120     {
121          size.cy = V_I4(&value);
122         VariantClear(&value);
123     }
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         VariantClear(&value);
131     }
132     else
133     {
134         /*
135         ** try alternative syntax
136         */
137         V_VT(&value) = VT_BOOL;
138         if( S_OK == pPropBag->Read(OLESTR("loop"), &value, pErrorLog) )
139         {
140             _p_instance->setAutoLoop(V_BOOL(&value) != VARIANT_FALSE);
141             VariantClear(&value);
142         }
143     }
144
145     V_VT(&value) = VT_BOOL;
146     if( S_OK == pPropBag->Read(OLESTR("mute"), &value, pErrorLog) )
147     {
148         _p_instance->setMute(V_BOOL(&value) != VARIANT_FALSE);
149         VariantClear(&value);
150     }
151
152     V_VT(&value) = VT_BOOL;
153     if( S_OK == pPropBag->Read(OLESTR("visible"), &value, pErrorLog) )
154     {
155         _p_instance->setVisible(V_BOOL(&value) != VARIANT_FALSE);
156         VariantClear(&value);
157     }
158     else
159     {
160         /*
161         ** try alternative syntax
162         */
163         V_VT(&value) = VT_BOOL;
164         if( S_OK == pPropBag->Read(OLESTR("showdisplay"), &value, pErrorLog) )
165         {
166             _p_instance->setVisible(V_BOOL(&value) != VARIANT_FALSE);
167             VariantClear(&value);
168         }
169     }
170
171     V_VT(&value) = VT_I4;
172     if( S_OK == pPropBag->Read(OLESTR("volume"), &value, pErrorLog) )
173     {
174         _p_instance->setVolume(V_I4(&value));
175         VariantClear(&value);
176     }
177
178     V_VT(&value) = VT_I4;
179     if( S_OK == pPropBag->Read(OLESTR("starttime"), &value, pErrorLog) )
180     {
181         _p_instance->setStartTime(V_I4(&value));
182         VariantClear(&value);
183     }
184
185     V_VT(&value) = VT_BSTR;
186     if( S_OK == pPropBag->Read(OLESTR("baseurl"), &value, pErrorLog) )
187     {
188         _p_instance->setBaseURL(V_BSTR(&value));
189         VariantClear(&value);
190     }
191
192     V_VT(&value) = VT_I4;
193     if( S_OK == pPropBag->Read(OLESTR("backcolor"), &value, pErrorLog) )
194     {
195         _p_instance->setBackColor(V_I4(&value));
196         VariantClear(&value);
197     }
198     else
199     {
200         /*
201         ** try alternative syntax
202         */
203         V_VT(&value) = VT_BSTR;
204         if( S_OK == pPropBag->Read(OLESTR("bgcolor"), &value, pErrorLog) )
205         {
206             long backcolor;
207             if( swscanf(V_BSTR(&value), L"#%lX", &backcolor) )
208             {
209                 _p_instance->setBackColor(backcolor);
210             }
211             VariantClear(&value);
212         }
213     }
214
215     return _p_instance->onLoad();
216 };
217
218 STDMETHODIMP VLCPersistPropertyBag::Save(LPPROPERTYBAG pPropBag, BOOL fClearDirty, BOOL fSaveAllProperties)
219 {
220     if( NULL == pPropBag )
221         return E_INVALIDARG;
222
223     VARIANT value;
224
225     VariantInit(&value);
226
227     V_VT(&value) = VT_BOOL;
228     V_BOOL(&value) = _p_instance->getAutoLoop()? VARIANT_TRUE : VARIANT_FALSE;
229     pPropBag->Write(OLESTR("AutoLoop"), &value);
230     VariantClear(&value);
231
232     V_VT(&value) = VT_BOOL;
233     V_BOOL(&value) = _p_instance->getAutoPlay()? VARIANT_TRUE : VARIANT_FALSE;
234     pPropBag->Write(OLESTR("AutoPlay"), &value);
235     VariantClear(&value);
236
237     V_VT(&value) = VT_BOOL;
238     V_BOOL(&value) = _p_instance->getShowToolbar()? VARIANT_TRUE : VARIANT_FALSE;
239     pPropBag->Write(OLESTR("Toolbar"), &value);
240     VariantClear(&value);
241
242     SIZEL size = _p_instance->getExtent();
243     V_VT(&value) = VT_I4;
244     V_I4(&value) = size.cx;
245     pPropBag->Write(OLESTR("ExtentWidth"), &value);
246     V_I4(&value) = size.cy;
247     pPropBag->Write(OLESTR("ExtentHeight"), &value);
248
249     V_VT(&value) = VT_BSTR;
250     V_BSTR(&value) = SysAllocStringLen(_p_instance->getMRL(),
251                             SysStringLen(_p_instance->getMRL()));
252     pPropBag->Write(OLESTR("MRL"), &value);
253     VariantClear(&value);
254
255     V_VT(&value) = VT_BOOL;
256     V_BOOL(&value) = _p_instance->getVisible()? VARIANT_TRUE : VARIANT_FALSE;
257     pPropBag->Write(OLESTR("Visible"), &value);
258     VariantClear(&value);
259
260     V_VT(&value) = VT_I4;
261     V_I4(&value) = _p_instance->getVolume();
262     pPropBag->Write(OLESTR("Volume"), &value);
263     VariantClear(&value);
264
265     V_VT(&value) = VT_I4;
266     V_I4(&value) = _p_instance->getStartTime();
267     pPropBag->Write(OLESTR("StartTime"), &value);
268     VariantClear(&value);
269
270     V_VT(&value) = VT_BSTR;
271     V_BSTR(&value) = SysAllocStringLen(_p_instance->getBaseURL(),
272                             SysStringLen(_p_instance->getBaseURL()));
273     pPropBag->Write(OLESTR("BaseURL"), &value);
274     VariantClear(&value);
275
276     V_VT(&value) = VT_I4;
277     V_I4(&value) = _p_instance->getBackColor();
278     pPropBag->Write(OLESTR("BackColor"), &value);
279     VariantClear(&value);
280
281     if( fClearDirty )
282         _p_instance->setDirty(FALSE);
283
284     return S_OK;
285 };