1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_desktop.hxx"
26 
27 #include "firststart.hxx"
28 #include "../migration/wizard.hxx"
29 #include <comphelper/sequenceashashmap.hxx>
30 
31 using namespace rtl;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::beans;
35 
36 namespace desktop{
37 
38 
39 const char* FirstStart::interfaces[] =
40 {
41     "com.sun.star.task.XJob",
42     NULL,
43 };
44 const char* FirstStart::implementationName = "com.sun.star.comp.desktop.FirstStart";
45 const char* FirstStart::serviceName = "com.sun.star.task.Job";
46 
GetImplementationName()47 OUString FirstStart::GetImplementationName()
48 {
49 	return OUString( RTL_CONSTASCII_USTRINGPARAM( implementationName));
50 }
51 
GetSupportedServiceNames()52 Sequence< OUString > FirstStart::GetSupportedServiceNames()
53 {
54 	sal_Int32 nSize = (sizeof( interfaces ) / sizeof( const char *)) - 1;
55 	Sequence< OUString > aResult( nSize );
56 
57 	for( sal_Int32 i = 0; i < nSize; i++ )
58 		aResult[i] = OUString::createFromAscii( interfaces[i] );
59 	return aResult;
60 }
61 
CreateInstance(const Reference<XMultiServiceFactory> & rSMgr)62 Reference< XInterface >  SAL_CALL FirstStart::CreateInstance(
63     const Reference< XMultiServiceFactory >& rSMgr )
64 {
65 	    static osl::Mutex aMutex;
66 		osl::MutexGuard guard( aMutex );
67 		return (XComponent*) ( new FirstStart( rSMgr ) );
68 }
69 
FirstStart(const Reference<XMultiServiceFactory> & xFactory)70 FirstStart::FirstStart( const Reference< XMultiServiceFactory >& xFactory ) :
71 	m_aListeners( m_aMutex ),
72 	m_xServiceManager( xFactory )
73 {
74 }
75 
~FirstStart()76 FirstStart::~FirstStart()
77 {
78 }
79 
80 // XComponent
dispose()81 void SAL_CALL FirstStart::dispose() throw ( RuntimeException )
82 {
83     EventObject aObject;
84     aObject.Source = (XComponent*)this;
85     m_aListeners.disposeAndClear( aObject );
86 }
87 
addEventListener(const Reference<XEventListener> & aListener)88 void SAL_CALL FirstStart::addEventListener( const Reference< XEventListener > & aListener) throw ( RuntimeException )
89 {
90     m_aListeners.addInterface( aListener );
91 }
92 
removeEventListener(const Reference<XEventListener> & aListener)93 void SAL_CALL FirstStart::removeEventListener( const Reference< XEventListener > & aListener ) throw ( RuntimeException )
94 {
95     m_aListeners.removeInterface( aListener );
96 }
97 
98 // XServiceInfo
getImplementationName()99 ::rtl::OUString SAL_CALL FirstStart::getImplementationName()
100 throw ( RuntimeException )
101 {
102 	return FirstStart::GetImplementationName();
103 }
104 
supportsService(const::rtl::OUString & rServiceName)105 sal_Bool SAL_CALL FirstStart::supportsService( const ::rtl::OUString& rServiceName )
106 throw ( RuntimeException )
107 {
108 	sal_Int32 nSize = sizeof( interfaces ) / sizeof( const char *);
109 
110 	for( sal_Int32 i = 0; i < nSize; i++ )
111 		if ( rServiceName.equalsAscii( interfaces[i] ))
112 			return sal_True;
113 	return sal_False;
114 }
115 
getSupportedServiceNames()116 Sequence< ::rtl::OUString > SAL_CALL FirstStart::getSupportedServiceNames()
117 throw ( RuntimeException )
118 {
119 	return FirstStart::GetSupportedServiceNames();
120 }
121 
122 // XJob
execute(const Sequence<NamedValue> & args)123 Any SAL_CALL FirstStart::execute(const Sequence<NamedValue>& args)
124 throw ( RuntimeException )
125 {
126     static const ::rtl::OUString ARG_LICENSENEEDED( RTL_CONSTASCII_USTRINGPARAM( "LicenseNeedsAcceptance" ) );
127     static const ::rtl::OUString ARG_LICENSEPATH(   RTL_CONSTASCII_USTRINGPARAM( "LicensePath" ) );
128 
129     ::comphelper::SequenceAsHashMap lArgs(args);
130 
131     sal_Bool bLicenseNeeded    = lArgs.getUnpackedValueOrDefault( ARG_LICENSENEEDED, (sal_Bool)sal_True );
132     rtl::OUString aLicensePath = lArgs.getUnpackedValueOrDefault( ARG_LICENSEPATH, rtl::OUString() );
133 
134     FirstStartWizard fsw( NULL, bLicenseNeeded && ( aLicensePath.getLength() > 0 ), aLicensePath );
135     return makeAny( (sal_Bool)fsw.Execute() );
136 }
137 
138 // XJobExecutor
trigger(const OUString &)139 void SAL_CALL FirstStart::trigger(const OUString&)
140 throw ( RuntimeException )
141 {
142     // trigger wizard with override, so it gets started regardless of
143     // configuration
144     Sequence<NamedValue> seq(1);
145     seq[0] = NamedValue(
146         OUString::createFromAscii("Override"),
147         makeAny(sal_True));
148     execute(seq);
149 }
150 
151 
152 } // namespace desktop
153