1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "HistoryOptTest.hxx"
29 // #include "AccessibilityOptTest.hxx"
30 // #include "PrintOptTest.hxx"
31 #include "UserOptTest.hxx"
32 
33 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/task/XJob.hpp>
36 #include <com/sun/star/beans/NamedValue.hpp>
37 
38 #include <sal/config.h>
39 #include <rtl/ustring.hxx>
40 #include <cppuhelper/implbase2.hxx>
41 #include <cppuhelper/implementationentry.hxx>
42 
43 //=============================================================================
44 namespace css = ::com::sun::star;
45 
46 namespace svl{
47 
48 //=============================================================================
49 static const ::rtl::OUString PROP_TEST                  = ::rtl::OUString::createFromAscii("Test");
50 static const ::rtl::OUString TEST_PICKLIST              = ::rtl::OUString::createFromAscii("checkPicklist");
51 static const ::rtl::OUString TEST_URLHISTORY            = ::rtl::OUString::createFromAscii("checkURLHistory");
52 static const ::rtl::OUString TEST_HELPBOOKMARKS         = ::rtl::OUString::createFromAscii("checkHelpBookmarks");
53 // static const ::rtl::OUString TEST_ACCESSIBILITYOPTIONS  = ::rtl::OUString::createFromAscii("checkAccessibilityOptions");
54 // static const ::rtl::OUString TEST_PRINTOPTIONS          = ::rtl::OUString::createFromAscii("checkPrintOptions");
55 static const ::rtl::OUString TEST_USEROPTIONS           = ::rtl::OUString::createFromAscii("checkUserOptions");
56 
57 //=============================================================================
58 class ConfigItemTest : public ::cppu::WeakImplHelper2< css::task::XJob         ,
59                                                         css::lang::XServiceInfo >
60 {
61     //-------------------------------------------------------------------------
62     // interface
63     public:
64         explicit ConfigItemTest(const css::uno::Reference< css::uno::XComponentContext >& xContext);
65 
66         // css::task::XJob
67         virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue >& lArguments)
68             throw (css::uno::RuntimeException         ,
69                    css::lang::IllegalArgumentException,
70                    css::uno::Exception                );
71 
72         // css::lang::XServiceInfo
73         virtual ::rtl::OUString SAL_CALL getImplementationName()
74             throw (css::uno::RuntimeException);
75 
76         virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString& sServiceName)
77             throw (css::uno::RuntimeException);
78 
79         virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
80             throw (css::uno::RuntimeException);
81 
82     //-------------------------------------------------------------------------
83     // internal
84     private:
85         ConfigItemTest(ConfigItemTest &); // not defined
86         virtual ~ConfigItemTest() {}
87         void operator=(ConfigItemTest &); // not defined
88 
89     //-------------------------------------------------------------------------
90     // helper for registration !
91     public:
92         static ::rtl::OUString SAL_CALL st_getImplementationName();
93         static css::uno::Sequence< ::rtl::OUString > SAL_CALL st_getSupportedServiceNames();
94         static css::uno::Reference< css::uno::XInterface > SAL_CALL st_create(const css::uno::Reference< css::uno::XComponentContext >& XContext);
95 
96     //-------------------------------------------------------------------------
97     // member
98     private:
99         css::uno::Reference< css::uno::XComponentContext >  m_xContext;
100 };
101 
102 //=============================================================================
103 ConfigItemTest::ConfigItemTest(const css::uno::Reference< css::uno::XComponentContext >& xContext)
104     : m_xContext(xContext)
105 {}
106 
107 //=============================================================================
108 // css::task::XJob
109 css::uno::Any SAL_CALL ConfigItemTest::execute(const css::uno::Sequence< css::beans::NamedValue >& lArguments)
110     throw (css::uno::RuntimeException         ,
111            css::lang::IllegalArgumentException,
112            css::uno::Exception                )
113 {
114     ::rtl::OUString sTest;
115     ::sal_Int32     i    = 0;
116     ::sal_Int32     c    = lArguments.getLength();
117     for (i=0; i<c; ++i)
118     {
119         const css::beans::NamedValue& rArg = lArguments[0];
120         if (rArg.Name.equals(PROP_TEST))
121             rArg.Value >>= sTest;
122     }
123 
124 	if (sTest.equals(TEST_PICKLIST))
125 	{
126 		HistoryOptTest aOptTest;
127 		aOptTest.checkPicklist();
128 	}
129 	else if (sTest.equals(TEST_URLHISTORY))
130 	{
131 		HistoryOptTest aOptTest;
132 		aOptTest.checkURLHistory();
133 	}
134 	else if (sTest.equals(TEST_HELPBOOKMARKS))
135 	{
136 		HistoryOptTest aOptTest;
137 		aOptTest.checkHelpBookmarks();
138 	}
139 // 	else if (sTest.equals(TEST_ACCESSIBILITYOPTIONS))
140 // 	{
141 // 		AccessibilityOptTest aOptTest;
142 // 		aOptTest.impl_checkAccessibilityOptions();
143 // 	}
144 // 	else if (sTest.equals(TEST_PRINTOPTIONS))
145 // 	{
146 //         PrintOptTest aOptTest;
147 //         aOptTest.impl_checkPrint();
148 // 	}
149 	else if (sTest.equals(TEST_USEROPTIONS))
150 	{
151 		UserOptTest aOptTest;
152 		aOptTest.impl_checkUserData();
153 	}
154 
155     return css::uno::Any();
156 }
157 
158 //=============================================================================
159 // com::sun::star::uno::XServiceInfo
160 ::rtl::OUString SAL_CALL ConfigItemTest::getImplementationName()
161     throw (css::uno::RuntimeException)
162 {
163     return ConfigItemTest::st_getImplementationName();
164 }
165 
166 //=============================================================================
167 // com::sun::star::uno::XServiceInfo
168 ::sal_Bool SAL_CALL ConfigItemTest::supportsService(const ::rtl::OUString& sServiceName)
169     throw (css::uno::RuntimeException)
170 {
171     css::uno::Sequence< ::rtl::OUString > lServiceNames = ConfigItemTest::st_getSupportedServiceNames();
172     for (::sal_Int32 i = 0; i < lServiceNames.getLength(); ++i)
173     {
174         if (lServiceNames[i].equals(sServiceName))
175             return sal_True;
176     }
177     return sal_False;
178 }
179 
180 //=============================================================================
181 // com::sun::star::uno::XServiceInfo
182 css::uno::Sequence< ::rtl::OUString > SAL_CALL ConfigItemTest::getSupportedServiceNames()
183     throw (css::uno::RuntimeException)
184 {
185     return ConfigItemTest::st_getSupportedServiceNames();
186 }
187 
188 //=============================================================================
189 ::rtl::OUString SAL_CALL ConfigItemTest::st_getImplementationName()
190 {
191     return ::rtl::OUString::createFromAscii("com.sun.star.comp.svl.ConfigItemTest");
192 }
193 
194 //=============================================================================
195 css::uno::Sequence< ::rtl::OUString > SAL_CALL ConfigItemTest::st_getSupportedServiceNames()
196 {
197     css::uno::Sequence< ::rtl::OUString > lServices(1);
198     lServices[0] = ::rtl::OUString::createFromAscii("com.sun.star.test.ConfigItems");
199     return lServices;
200 }
201 
202 //=============================================================================
203 css::uno::Reference< css::uno::XInterface > SAL_CALL ConfigItemTest::st_create(const css::uno::Reference< css::uno::XComponentContext >& xContext)
204 {
205     ConfigItemTest*                            pObject = new ConfigItemTest(xContext);
206     css::uno::Reference< css::uno::XInterface > xObject (static_cast< ::cppu::OWeakObject* >(pObject));
207     return xObject;
208 }
209 
210 } // namespace svl
211 
212 //=============================================================================
213 static ::cppu::ImplementationEntry const lRegEntries[] =
214 {
215     {
216         &::svl::ConfigItemTest::st_create,
217         &::svl::ConfigItemTest::st_getImplementationName,
218         &::svl::ConfigItemTest::st_getSupportedServiceNames,
219         &::cppu::createSingleComponentFactory, 0, 0
220     },
221 
222     { 0, 0, 0, 0, 0, 0 }
223 };
224 
225 //=============================================================================
226 extern "C" void SAL_CALL component_getImplementationEnvironment(const char**            pEnvTypeName,
227                                                                       uno_Environment**             )
228 {
229     *pEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
230 }
231 
232 //=============================================================================
233 extern "C" void * SAL_CALL component_getFactory(const char* sImplName      ,
234                                                       void* pServiceManager,
235                                                       void* pRegistryKey   )
236 {
237     return ::cppu::component_getFactoryHelper(sImplName, pServiceManager, pRegistryKey, lRegEntries);
238 }
239 
240 //=============================================================================
241 extern "C" sal_Bool SAL_CALL component_writeInfo(void* pServiceManager,
242                                                  void* pRegistryKey   )
243 {
244     return ::cppu::component_writeInfoHelper(pServiceManager, pRegistryKey, lRegEntries);
245 }
246