1*2722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*2722ceddSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*2722ceddSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*2722ceddSAndrew Rist * distributed with this work for additional information
6*2722ceddSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*2722ceddSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*2722ceddSAndrew Rist * "License"); you may not use this file except in compliance
9*2722ceddSAndrew Rist * with the License. You may obtain a copy of the License at
10*2722ceddSAndrew Rist *
11*2722ceddSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*2722ceddSAndrew Rist *
13*2722ceddSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*2722ceddSAndrew Rist * software distributed under the License is distributed on an
15*2722ceddSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2722ceddSAndrew Rist * KIND, either express or implied. See the License for the
17*2722ceddSAndrew Rist * specific language governing permissions and limitations
18*2722ceddSAndrew Rist * under the License.
19*2722ceddSAndrew Rist *
20*2722ceddSAndrew Rist *************************************************************/
21*2722ceddSAndrew Rist
22*2722ceddSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_desktop.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "oemjob.hxx"
28cdf0e10cSrcweir #include <rtl/bootstrap.hxx>
29cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
30cdf0e10cSrcweir #include <osl/file.hxx>
31cdf0e10cSrcweir #include <unotools/bootstrap.hxx>
32cdf0e10cSrcweir #include <tools/config.hxx>
33cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
34cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
35cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
36cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp>
37cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
38cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
39cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
40cdf0e10cSrcweir
41cdf0e10cSrcweir using namespace rtl;
42cdf0e10cSrcweir using namespace ::com::sun::star::uno;
43cdf0e10cSrcweir using namespace ::com::sun::star::lang;
44cdf0e10cSrcweir using namespace ::com::sun::star::beans;
45cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
46cdf0e10cSrcweir using namespace ::com::sun::star::frame;
47cdf0e10cSrcweir using namespace ::com::sun::star::util;
48cdf0e10cSrcweir
49cdf0e10cSrcweir namespace desktop{
50cdf0e10cSrcweir
51cdf0e10cSrcweir char const OEM_PRELOAD_SECTION[] = "Bootstrap";
52cdf0e10cSrcweir char const OEM_PRELOAD[] = "Preload";
53cdf0e10cSrcweir char const STR_TRUE[] = "1";
54cdf0e10cSrcweir char const STR_FALSE[] = "0";
55cdf0e10cSrcweir
56cdf0e10cSrcweir const char* OEMPreloadJob::interfaces[] =
57cdf0e10cSrcweir {
58cdf0e10cSrcweir "com.sun.star.task.XJob",
59cdf0e10cSrcweir NULL,
60cdf0e10cSrcweir };
61cdf0e10cSrcweir const char* OEMPreloadJob::implementationName = "com.sun.star.comp.desktop.OEMPreloadJob";
62cdf0e10cSrcweir const char* OEMPreloadJob::serviceName = "com.sun.star.office.OEMPreloadJob";
63cdf0e10cSrcweir
GetImplementationName()64cdf0e10cSrcweir OUString OEMPreloadJob::GetImplementationName()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM( implementationName));
67cdf0e10cSrcweir }
68cdf0e10cSrcweir
GetSupportedServiceNames()69cdf0e10cSrcweir Sequence< OUString > OEMPreloadJob::GetSupportedServiceNames()
70cdf0e10cSrcweir {
71cdf0e10cSrcweir sal_Int32 nSize = (sizeof( interfaces ) / sizeof( const char *)) - 1;
72cdf0e10cSrcweir Sequence< OUString > aResult( nSize );
73cdf0e10cSrcweir
74cdf0e10cSrcweir for( sal_Int32 i = 0; i < nSize; i++ )
75cdf0e10cSrcweir aResult[i] = OUString::createFromAscii( interfaces[i] );
76cdf0e10cSrcweir return aResult;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir
CreateInstance(const Reference<XMultiServiceFactory> & rSMgr)79cdf0e10cSrcweir Reference< XInterface > SAL_CALL OEMPreloadJob::CreateInstance(
80cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rSMgr )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir static osl::Mutex aMutex;
83cdf0e10cSrcweir osl::MutexGuard guard( aMutex );
84cdf0e10cSrcweir return (XComponent*) ( new OEMPreloadJob( rSMgr ) );
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
OEMPreloadJob(const Reference<XMultiServiceFactory> & xFactory)87cdf0e10cSrcweir OEMPreloadJob::OEMPreloadJob( const Reference< XMultiServiceFactory >& xFactory ) :
88cdf0e10cSrcweir m_aListeners( m_aMutex ),
89cdf0e10cSrcweir m_xServiceManager( xFactory )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir }
92cdf0e10cSrcweir
~OEMPreloadJob()93cdf0e10cSrcweir OEMPreloadJob::~OEMPreloadJob()
94cdf0e10cSrcweir {
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
97cdf0e10cSrcweir // XComponent
dispose()98cdf0e10cSrcweir void SAL_CALL OEMPreloadJob::dispose() throw ( RuntimeException )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir EventObject aObject;
101cdf0e10cSrcweir aObject.Source = (XComponent*)this;
102cdf0e10cSrcweir m_aListeners.disposeAndClear( aObject );
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
addEventListener(const Reference<XEventListener> & aListener)105cdf0e10cSrcweir void SAL_CALL OEMPreloadJob::addEventListener( const Reference< XEventListener > & aListener) throw ( RuntimeException )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir m_aListeners.addInterface( aListener );
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
removeEventListener(const Reference<XEventListener> & aListener)110cdf0e10cSrcweir void SAL_CALL OEMPreloadJob::removeEventListener( const Reference< XEventListener > & aListener ) throw ( RuntimeException )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir m_aListeners.removeInterface( aListener );
113cdf0e10cSrcweir }
114cdf0e10cSrcweir
115cdf0e10cSrcweir // XServiceInfo
getImplementationName()116cdf0e10cSrcweir ::rtl::OUString SAL_CALL OEMPreloadJob::getImplementationName()
117cdf0e10cSrcweir throw ( RuntimeException )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir return OEMPreloadJob::GetImplementationName();
120cdf0e10cSrcweir }
121cdf0e10cSrcweir
supportsService(const::rtl::OUString & rServiceName)122cdf0e10cSrcweir sal_Bool SAL_CALL OEMPreloadJob::supportsService( const ::rtl::OUString& rServiceName )
123cdf0e10cSrcweir throw ( RuntimeException )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir sal_Int32 nSize = sizeof( interfaces ) / sizeof( const char *);
126cdf0e10cSrcweir
127cdf0e10cSrcweir for( sal_Int32 i = 0; i < nSize; i++ )
128cdf0e10cSrcweir if ( rServiceName.equalsAscii( interfaces[i] ))
129cdf0e10cSrcweir return sal_True;
130cdf0e10cSrcweir return sal_False;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
getSupportedServiceNames()133cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL OEMPreloadJob::getSupportedServiceNames()
134cdf0e10cSrcweir throw ( RuntimeException )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir return OEMPreloadJob::GetSupportedServiceNames();
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir // XJob
execute(const Sequence<NamedValue> &)140cdf0e10cSrcweir Any SAL_CALL OEMPreloadJob::execute(const Sequence<NamedValue>&)
141cdf0e10cSrcweir throw ( RuntimeException )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir sal_Bool bCont = sal_False;
144cdf0e10cSrcweir // are we an OEM version at all?
145cdf0e10cSrcweir if (checkOEMPreloadFlag())
146cdf0e10cSrcweir {
147cdf0e10cSrcweir // create OEM preload service dialog
148cdf0e10cSrcweir Reference <XExecutableDialog> xDialog( m_xServiceManager->createInstance(
149cdf0e10cSrcweir OUString::createFromAscii("org.openoffice.comp.preload.OEMPreloadWizard")),
150cdf0e10cSrcweir UNO_QUERY );
151cdf0e10cSrcweir if ( xDialog.is() ){
152cdf0e10cSrcweir // execute OEM preload dialog and check return value
153cdf0e10cSrcweir if ( xDialog->execute() == ExecutableDialogResults::OK ) {
154cdf0e10cSrcweir // user accepted.
155cdf0e10cSrcweir // make sure the job does not get called again.
156cdf0e10cSrcweir bCont = sal_True;
157cdf0e10cSrcweir disableOEMPreloadFlag();
158cdf0e10cSrcweir } else {
159cdf0e10cSrcweir // user declined...
160cdf0e10cSrcweir // terminate.
161cdf0e10cSrcweir /*
162cdf0e10cSrcweir Reference< XDesktop > xDesktop( m_xServiceManager->createInstance(
163cdf0e10cSrcweir OUString::createFromAscii("com.sun.star.frame.Desktop")),
164cdf0e10cSrcweir UNO_QUERY );
165cdf0e10cSrcweir xDesktop->terminate();
166cdf0e10cSrcweir */
167cdf0e10cSrcweir /*
168cdf0e10cSrcweir OUString aName;
169cdf0e10cSrcweir OUString aEnvType;
170cdf0e10cSrcweir Reference<XFrame> rFrame;
171cdf0e10cSrcweir Reference<XModel> rModel;
172cdf0e10cSrcweir Reference<XCloseable> rClose;
173cdf0e10cSrcweir for (int i=0; i<args.getLength(); i++)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir if (args[i].Name.equalsAscii("EnvType"))
176cdf0e10cSrcweir args[i].Value >>= aEnvType;
177cdf0e10cSrcweir else if (args[i].Name.equalsAscii("Frame")) {
178cdf0e10cSrcweir args[i].Value >>= rFrame;
179cdf0e10cSrcweir rClose = Reference<XCloseable>(rFrame, UNO_QUERY);
180cdf0e10cSrcweir }
181cdf0e10cSrcweir else if (args[i].Name.equalsAscii("Model")) {
182cdf0e10cSrcweir args[i].Value >>= rModel;
183cdf0e10cSrcweir rClose = Reference<XCloseable>(rModel, UNO_QUERY);
184cdf0e10cSrcweir }
185cdf0e10cSrcweir }
186cdf0e10cSrcweir if (rClose.is()) rClose->close(sal_True);
187cdf0e10cSrcweir */
188cdf0e10cSrcweir bCont = sal_False;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir }
191cdf0e10cSrcweir } else {
192cdf0e10cSrcweir // don't try again
193cdf0e10cSrcweir bCont = sal_True;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir /*
196cdf0e10cSrcweir NamedValue nv;
197cdf0e10cSrcweir nv.Name = OUString::createFromAscii("Deactivate");
198cdf0e10cSrcweir nv.Value <<= bDeactivate;
199cdf0e10cSrcweir Sequence<NamedValue> s(1);
200cdf0e10cSrcweir s[0] = nv;
201cdf0e10cSrcweir */
202cdf0e10cSrcweir Any r;
203cdf0e10cSrcweir r <<= bCont;
204cdf0e10cSrcweir return r;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
207cdf0e10cSrcweir
existsURL(OUString const & _sURL)208cdf0e10cSrcweir static sal_Bool existsURL( OUString const& _sURL )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir using namespace osl;
211cdf0e10cSrcweir DirectoryItem aDirItem;
212cdf0e10cSrcweir
213cdf0e10cSrcweir if (_sURL.getLength() != 0)
214cdf0e10cSrcweir return ( DirectoryItem::get( _sURL, aDirItem ) == DirectoryItem::E_None );
215cdf0e10cSrcweir
216cdf0e10cSrcweir return sal_False;
217cdf0e10cSrcweir }
218cdf0e10cSrcweir
219cdf0e10cSrcweir
220cdf0e10cSrcweir // locate soffice.ini/.rc file
locateIniFile()221cdf0e10cSrcweir static OUString locateIniFile()
222cdf0e10cSrcweir {
223cdf0e10cSrcweir OUString aUserDataPath;
224cdf0e10cSrcweir OUString aSofficeIniFileURL;
225cdf0e10cSrcweir
226cdf0e10cSrcweir // Retrieve the default file URL for the soffice.ini/rc
227cdf0e10cSrcweir Bootstrap().getIniName( aSofficeIniFileURL );
228cdf0e10cSrcweir
229cdf0e10cSrcweir if ( utl::Bootstrap::locateUserData( aUserDataPath ) == utl::Bootstrap::PATH_EXISTS )
230cdf0e10cSrcweir {
231cdf0e10cSrcweir const char CONFIG_DIR[] = "/config";
232cdf0e10cSrcweir
233cdf0e10cSrcweir sal_Int32 nIndex = aSofficeIniFileURL.lastIndexOf( '/');
234cdf0e10cSrcweir if ( nIndex > 0 )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir OUString aUserSofficeIniFileURL;
237cdf0e10cSrcweir OUStringBuffer aBuffer( aUserDataPath );
238cdf0e10cSrcweir aBuffer.appendAscii( CONFIG_DIR );
239cdf0e10cSrcweir aBuffer.append( aSofficeIniFileURL.copy( nIndex ));
240cdf0e10cSrcweir aUserSofficeIniFileURL = aBuffer.makeStringAndClear();
241cdf0e10cSrcweir
242cdf0e10cSrcweir if ( existsURL( aUserSofficeIniFileURL ))
243cdf0e10cSrcweir return aUserSofficeIniFileURL;
244cdf0e10cSrcweir }
245cdf0e10cSrcweir }
246cdf0e10cSrcweir // Fallback try to use the soffice.ini/rc from program folder
247cdf0e10cSrcweir return aSofficeIniFileURL;
248cdf0e10cSrcweir }
249cdf0e10cSrcweir
250cdf0e10cSrcweir // check whether the OEMPreload flag was set in soffice.ini/.rc
checkOEMPreloadFlag()251cdf0e10cSrcweir sal_Bool OEMPreloadJob::checkOEMPreloadFlag()
252cdf0e10cSrcweir {
253cdf0e10cSrcweir OUString aSofficeIniFileURL;
254cdf0e10cSrcweir aSofficeIniFileURL = locateIniFile();
255cdf0e10cSrcweir Config aConfig(aSofficeIniFileURL);
256cdf0e10cSrcweir aConfig.SetGroup( OEM_PRELOAD_SECTION );
257cdf0e10cSrcweir ByteString sResult = aConfig.ReadKey( OEM_PRELOAD );
258cdf0e10cSrcweir if ( sResult == STR_TRUE )
259cdf0e10cSrcweir return sal_True;
260cdf0e10cSrcweir else
261cdf0e10cSrcweir return sal_False;
262cdf0e10cSrcweir }
263cdf0e10cSrcweir
disableOEMPreloadFlag()264cdf0e10cSrcweir void OEMPreloadJob::disableOEMPreloadFlag()
265cdf0e10cSrcweir {
266cdf0e10cSrcweir OUString aSofficeIniFileURL = locateIniFile();
267cdf0e10cSrcweir if ( aSofficeIniFileURL.getLength() > 0 )
268cdf0e10cSrcweir {
269cdf0e10cSrcweir Config aConfig(aSofficeIniFileURL);
270cdf0e10cSrcweir aConfig.SetGroup( OEM_PRELOAD_SECTION );
271cdf0e10cSrcweir aConfig.WriteKey( OEM_PRELOAD, STR_FALSE );
272cdf0e10cSrcweir aConfig.Flush();
273cdf0e10cSrcweir }
274cdf0e10cSrcweir }
275cdf0e10cSrcweir
276cdf0e10cSrcweir } // namespace desktop
277