xref: /AOO41X/main/extensions/source/update/check/updatecheckjob.cxx (revision a2db8daa583f26f37049ecee9be51ff7090a8b59)
12a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52a97ec55SAndrew Rist  * distributed with this work for additional information
62a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
82a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
92a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
112a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
132a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
142a97ec55SAndrew Rist  * software distributed under the License is distributed on an
152a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
172a97ec55SAndrew Rist  * specific language governing permissions and limitations
182a97ec55SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
202a97ec55SAndrew Rist  *************************************************************/
212a97ec55SAndrew Rist 
222a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <memory>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "updatecheck.hxx"
30cdf0e10cSrcweir #include "updatecheckconfig.hxx"
31cdf0e10cSrcweir #include "updatehdl.hxx"
32cdf0e10cSrcweir #include "updateprotocol.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx>
35cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include "com/sun/star/frame/XDesktop.hpp"
38cdf0e10cSrcweir #include "com/sun/star/frame/XTerminateListener.hpp"
39cdf0e10cSrcweir #include <com/sun/star/task/XJob.hpp>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace beans = com::sun::star::beans ;
42cdf0e10cSrcweir namespace frame = com::sun::star::frame ;
43cdf0e10cSrcweir namespace lang = com::sun::star::lang ;
44cdf0e10cSrcweir namespace task = com::sun::star::task ;
45cdf0e10cSrcweir namespace uno = com::sun::star::uno ;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
48cdf0e10cSrcweir 
49cdf0e10cSrcweir namespace
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 
52cdf0e10cSrcweir class UpdateCheckJob :
53cdf0e10cSrcweir     public ::cppu::WeakImplHelper3< task::XJob, lang::XServiceInfo, frame::XTerminateListener >
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     virtual ~UpdateCheckJob();
56cdf0e10cSrcweir 
57cdf0e10cSrcweir public:
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     UpdateCheckJob(const uno::Reference<uno::XComponentContext>& xContext);
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     static uno::Sequence< rtl::OUString > getServiceNames();
62cdf0e10cSrcweir     static rtl::OUString getImplName();
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     // Allows runtime exceptions to be thrown by const methods
operator uno::Reference<uno::XInterface>() const65cdf0e10cSrcweir     inline SAL_CALL operator uno::Reference< uno::XInterface > () const
66cdf0e10cSrcweir         { return const_cast< cppu::OWeakObject * > (static_cast< cppu::OWeakObject const * > (this)); };
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     // XJob
69cdf0e10cSrcweir     virtual uno::Any SAL_CALL execute(const uno::Sequence<beans::NamedValue>&)
70cdf0e10cSrcweir         throw (lang::IllegalArgumentException, uno::Exception);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     // XServiceInfo
73cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getImplementationName()
74cdf0e10cSrcweir         throw (uno::RuntimeException);
75cdf0e10cSrcweir     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & serviceName)
76cdf0e10cSrcweir         throw (uno::RuntimeException);
77cdf0e10cSrcweir     virtual uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames()
78cdf0e10cSrcweir         throw (uno::RuntimeException);
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     // XEventListener
81cdf0e10cSrcweir     virtual void SAL_CALL disposing( ::com::sun::star::lang::EventObject const & evt )
82cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     // XTerminateListener
85cdf0e10cSrcweir     virtual void SAL_CALL queryTermination( lang::EventObject const & evt )
86cdf0e10cSrcweir         throw ( frame::TerminationVetoException, uno::RuntimeException );
87cdf0e10cSrcweir     virtual void SAL_CALL notifyTermination( lang::EventObject const & evt )
88cdf0e10cSrcweir         throw ( uno::RuntimeException );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir private:
91cdf0e10cSrcweir     uno::Reference<uno::XComponentContext>  m_xContext;
92cdf0e10cSrcweir     uno::Reference< frame::XDesktop >       m_xDesktop;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     void handleExtensionUpdates( const uno::Sequence< beans::NamedValue > &rListProp );
95cdf0e10cSrcweir };
96cdf0e10cSrcweir 
97cdf0e10cSrcweir //------------------------------------------------------------------------------
98cdf0e10cSrcweir 
UpdateCheckJob(const uno::Reference<uno::XComponentContext> & xContext)99cdf0e10cSrcweir UpdateCheckJob::UpdateCheckJob( const uno::Reference<uno::XComponentContext>& xContext ) :
100cdf0e10cSrcweir     m_xContext(xContext)
101cdf0e10cSrcweir {
102cdf0e10cSrcweir     m_xDesktop.set( xContext->getServiceManager()->createInstanceWithContext( UNISTRING("com.sun.star.frame.Desktop"), xContext ), uno::UNO_QUERY );
103cdf0e10cSrcweir     if ( m_xDesktop.is() )
104cdf0e10cSrcweir         m_xDesktop->addTerminateListener( this );
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir //------------------------------------------------------------------------------
108cdf0e10cSrcweir 
~UpdateCheckJob()109cdf0e10cSrcweir UpdateCheckJob::~UpdateCheckJob()
110cdf0e10cSrcweir {
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir //------------------------------------------------------------------------------
114cdf0e10cSrcweir 
115cdf0e10cSrcweir uno::Sequence< rtl::OUString >
getServiceNames()116cdf0e10cSrcweir UpdateCheckJob::getServiceNames()
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aServiceList(1);
119cdf0e10cSrcweir     aServiceList[0] = UNISTRING( "com.sun.star.setup.UpdateCheck");
120cdf0e10cSrcweir     return aServiceList;
121cdf0e10cSrcweir };
122cdf0e10cSrcweir 
123cdf0e10cSrcweir //------------------------------------------------------------------------------
124cdf0e10cSrcweir 
125cdf0e10cSrcweir rtl::OUString
getImplName()126cdf0e10cSrcweir UpdateCheckJob::getImplName()
127cdf0e10cSrcweir {
128cdf0e10cSrcweir     return UNISTRING( "vnd.sun.UpdateCheck");
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 
132cdf0e10cSrcweir //------------------------------------------------------------------------------
133cdf0e10cSrcweir 
134cdf0e10cSrcweir uno::Any
execute(const uno::Sequence<beans::NamedValue> & namedValues)135cdf0e10cSrcweir UpdateCheckJob::execute(const uno::Sequence<beans::NamedValue>& namedValues)
136cdf0e10cSrcweir     throw (lang::IllegalArgumentException, uno::Exception)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     for ( sal_Int32 n=namedValues.getLength(); n-- > 0; )
139cdf0e10cSrcweir     {
140cdf0e10cSrcweir         if ( namedValues[ n ].Name.equalsAscii( "DynamicData" ) )
141cdf0e10cSrcweir         {
142cdf0e10cSrcweir             uno::Sequence<beans::NamedValue> aListProp;
143cdf0e10cSrcweir             if ( namedValues[n].Value >>= aListProp )
144cdf0e10cSrcweir             {
145cdf0e10cSrcweir                 for ( sal_Int32 i=aListProp.getLength(); i-- > 0; )
146cdf0e10cSrcweir                 {
147cdf0e10cSrcweir                     if ( aListProp[ i ].Name.equalsAscii( "updateList" ) )
148cdf0e10cSrcweir                     {
149cdf0e10cSrcweir                         handleExtensionUpdates( aListProp );
150cdf0e10cSrcweir                         return uno::Any();
151cdf0e10cSrcweir                     }
152cdf0e10cSrcweir                 }
153cdf0e10cSrcweir             }
154cdf0e10cSrcweir         }
155cdf0e10cSrcweir     }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     uno::Sequence<beans::NamedValue> aConfig =
158cdf0e10cSrcweir         getValue< uno::Sequence<beans::NamedValue> > (namedValues, "JobConfig");
159cdf0e10cSrcweir 
160*a2db8daaSArrigo Marchiori     rtl::Reference< UpdateCheck > aController( UpdateCheck::get() );
161*a2db8daaSArrigo Marchiori     aController->initialize( aConfig, m_xContext );
162*a2db8daaSArrigo Marchiori     aController->showDialog( true );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     return uno::Any();
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir //------------------------------------------------------------------------------
handleExtensionUpdates(const uno::Sequence<beans::NamedValue> & rListProp)168cdf0e10cSrcweir void UpdateCheckJob::handleExtensionUpdates( const uno::Sequence< beans::NamedValue > &rListProp )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     try {
171cdf0e10cSrcweir         uno::Sequence< uno::Sequence< rtl::OUString > > aList =
172cdf0e10cSrcweir             getValue< uno::Sequence< uno::Sequence< rtl::OUString > > > ( rListProp, "updateList" );
173cdf0e10cSrcweir         bool bPrepareOnly = getValue< bool > ( rListProp, "prepareOnly" );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         // we will first store any new found updates and then check, if there are any
176cdf0e10cSrcweir         // pending updates.
177cdf0e10cSrcweir         storeExtensionUpdateInfos( m_xContext, aList );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir         if ( bPrepareOnly )
180cdf0e10cSrcweir             return;
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         bool bHasUpdates = checkForPendingUpdates( m_xContext );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         rtl::Reference<UpdateCheck> aController( UpdateCheck::get() );
185cdf0e10cSrcweir         if ( ! aController.is() )
186cdf0e10cSrcweir             return;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         aController->setHasExtensionUpdates( bHasUpdates );
189cdf0e10cSrcweir 
190cdf0e10cSrcweir         if ( ! aController->hasOfficeUpdate() )
191cdf0e10cSrcweir         {
192cdf0e10cSrcweir             if ( bHasUpdates )
193cdf0e10cSrcweir                 aController->setUIState( UPDATESTATE_EXT_UPD_AVAIL, true );
194cdf0e10cSrcweir             else
195cdf0e10cSrcweir                 aController->setUIState( UPDATESTATE_NO_UPDATE_AVAIL, true );
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir     }
198cdf0e10cSrcweir     catch( const uno::Exception& e )
199cdf0e10cSrcweir     {
200cdf0e10cSrcweir          OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
201cdf0e10cSrcweir             rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
202cdf0e10cSrcweir     }
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir //------------------------------------------------------------------------------
206cdf0e10cSrcweir 
207cdf0e10cSrcweir rtl::OUString SAL_CALL
getImplementationName()208cdf0e10cSrcweir UpdateCheckJob::getImplementationName() throw (uno::RuntimeException)
209cdf0e10cSrcweir {
210cdf0e10cSrcweir     return getImplName();
211cdf0e10cSrcweir }
212cdf0e10cSrcweir 
213cdf0e10cSrcweir //------------------------------------------------------------------------------
214cdf0e10cSrcweir 
215cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames()216cdf0e10cSrcweir UpdateCheckJob::getSupportedServiceNames() throw (uno::RuntimeException)
217cdf0e10cSrcweir {
218cdf0e10cSrcweir     return getServiceNames();
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir //------------------------------------------------------------------------------
222cdf0e10cSrcweir 
223cdf0e10cSrcweir sal_Bool SAL_CALL
supportsService(rtl::OUString const & serviceName)224cdf0e10cSrcweir UpdateCheckJob::supportsService( rtl::OUString const & serviceName ) throw (uno::RuntimeException)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aServiceNameList = getServiceNames();
227cdf0e10cSrcweir 
228cdf0e10cSrcweir     for( sal_Int32 n=0; n < aServiceNameList.getLength(); n++ )
229cdf0e10cSrcweir         if( aServiceNameList[n].equals(serviceName) )
230cdf0e10cSrcweir             return sal_True;
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     return sal_False;
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir //------------------------------------------------------------------------------
236cdf0e10cSrcweir // XEventListener
disposing(lang::EventObject const & rEvt)237cdf0e10cSrcweir void SAL_CALL UpdateCheckJob::disposing( lang::EventObject const & rEvt )
238cdf0e10cSrcweir     throw ( uno::RuntimeException )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir     bool shutDown = ( rEvt.Source == m_xDesktop );
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     if ( shutDown && m_xDesktop.is() )
243cdf0e10cSrcweir     {
244cdf0e10cSrcweir         m_xDesktop->removeTerminateListener( this );
245cdf0e10cSrcweir         m_xDesktop.clear();
246cdf0e10cSrcweir     }
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
249cdf0e10cSrcweir //------------------------------------------------------------------------------
250cdf0e10cSrcweir // XTerminateListener
queryTermination(lang::EventObject const &)251cdf0e10cSrcweir void SAL_CALL UpdateCheckJob::queryTermination( lang::EventObject const & )
252cdf0e10cSrcweir     throw ( frame::TerminationVetoException, uno::RuntimeException )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir //------------------------------------------------------------------------------
notifyTermination(lang::EventObject const &)257cdf0e10cSrcweir void SAL_CALL UpdateCheckJob::notifyTermination( lang::EventObject const & )
258cdf0e10cSrcweir     throw ( uno::RuntimeException )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir } // anonymous namespace
263cdf0e10cSrcweir 
264cdf0e10cSrcweir //------------------------------------------------------------------------------
265cdf0e10cSrcweir 
266cdf0e10cSrcweir static uno::Reference<uno::XInterface> SAL_CALL
createJobInstance(const uno::Reference<uno::XComponentContext> & xContext)267cdf0e10cSrcweir createJobInstance(const uno::Reference<uno::XComponentContext>& xContext)
268cdf0e10cSrcweir {
269cdf0e10cSrcweir     return *new UpdateCheckJob(xContext);
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir //------------------------------------------------------------------------------
273cdf0e10cSrcweir 
274cdf0e10cSrcweir static uno::Reference<uno::XInterface> SAL_CALL
createConfigInstance(const uno::Reference<uno::XComponentContext> & xContext)275cdf0e10cSrcweir createConfigInstance(const uno::Reference<uno::XComponentContext>& xContext)
276cdf0e10cSrcweir {
277cdf0e10cSrcweir     return *UpdateCheckConfig::get(xContext, *UpdateCheck::get());
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir //------------------------------------------------------------------------------
281cdf0e10cSrcweir 
282cdf0e10cSrcweir static const cppu::ImplementationEntry kImplementations_entries[] =
283cdf0e10cSrcweir {
284cdf0e10cSrcweir     {
285cdf0e10cSrcweir         createJobInstance,
286cdf0e10cSrcweir         UpdateCheckJob::getImplName,
287cdf0e10cSrcweir         UpdateCheckJob::getServiceNames,
288cdf0e10cSrcweir         cppu::createSingleComponentFactory,
289cdf0e10cSrcweir         NULL,
290cdf0e10cSrcweir         0
291cdf0e10cSrcweir     },
292cdf0e10cSrcweir     {
293cdf0e10cSrcweir         createConfigInstance,
294cdf0e10cSrcweir         UpdateCheckConfig::getImplName,
295cdf0e10cSrcweir         UpdateCheckConfig::getServiceNames,
296cdf0e10cSrcweir         cppu::createSingleComponentFactory,
297cdf0e10cSrcweir         NULL,
298cdf0e10cSrcweir         0
299cdf0e10cSrcweir     },
300cdf0e10cSrcweir 	{ NULL, NULL, NULL, NULL, NULL, 0 }
301cdf0e10cSrcweir } ;
302cdf0e10cSrcweir 
303cdf0e10cSrcweir //------------------------------------------------------------------------------
304cdf0e10cSrcweir 
305cdf0e10cSrcweir extern "C" void SAL_CALL
component_getImplementationEnvironment(const sal_Char ** aEnvTypeName,uno_Environment **)306cdf0e10cSrcweir component_getImplementationEnvironment( const sal_Char **aEnvTypeName, uno_Environment **)
307cdf0e10cSrcweir {
308cdf0e10cSrcweir     *aEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ;
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir //------------------------------------------------------------------------------
312cdf0e10cSrcweir 
313cdf0e10cSrcweir extern "C" void *
component_getFactory(const sal_Char * pszImplementationName,void * pServiceManager,void * pRegistryKey)314cdf0e10cSrcweir component_getFactory(const sal_Char *pszImplementationName, void *pServiceManager, void *pRegistryKey)
315cdf0e10cSrcweir {
316cdf0e10cSrcweir     return cppu::component_getFactoryHelper(
317cdf0e10cSrcweir         pszImplementationName,
318cdf0e10cSrcweir         pServiceManager,
319cdf0e10cSrcweir         pRegistryKey,
320cdf0e10cSrcweir         kImplementations_entries) ;
321cdf0e10cSrcweir }
322