1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
33 #include "updatecheck.hxx"
34 #include "updatecheckconfig.hxx"
35 #include "updatehdl.hxx"
36 #include "updateprotocol.hxx"
38 #include <cppuhelper/implbase3.hxx>
39 #include <cppuhelper/implementationentry.hxx>
41 #include "com/sun/star/frame/XDesktop.hpp"
42 #include "com/sun/star/frame/XTerminateListener.hpp"
43 #include <com/sun/star/task/XJob.hpp>
45 namespace beans
= com::sun::star::beans
;
46 namespace frame
= com::sun::star::frame
;
47 namespace lang
= com::sun::star::lang
;
48 namespace task
= com::sun::star::task
;
49 namespace uno
= com::sun::star::uno
;
51 #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
56 class InitUpdateCheckJobThread
: public osl::Thread
59 InitUpdateCheckJobThread( const uno::Reference
< uno::XComponentContext
> &xContext
,
60 const uno::Sequence
< beans::NamedValue
> &xParameters
,
63 virtual void SAL_CALL
run();
65 void setTerminating();
68 osl::Condition m_aCondition
;
69 uno::Reference
<uno::XComponentContext
> m_xContext
;
70 uno::Sequence
<beans::NamedValue
> m_xParameters
;
75 class UpdateCheckJob
:
76 public ::cppu::WeakImplHelper3
< task::XJob
, lang::XServiceInfo
, frame::XTerminateListener
>
78 virtual ~UpdateCheckJob();
82 UpdateCheckJob(const uno::Reference
<uno::XComponentContext
>& xContext
);
84 static uno::Sequence
< rtl::OUString
> getServiceNames();
85 static rtl::OUString
getImplName();
87 // Allows runtime exceptions to be thrown by const methods
88 inline SAL_CALL
operator uno::Reference
< uno::XInterface
> () const
89 { return const_cast< cppu::OWeakObject
* > (static_cast< cppu::OWeakObject
const * > (this)); };
92 virtual uno::Any SAL_CALL
execute(const uno::Sequence
<beans::NamedValue
>&)
93 throw (lang::IllegalArgumentException
, uno::Exception
);
96 virtual rtl::OUString SAL_CALL
getImplementationName()
97 throw (uno::RuntimeException
);
98 virtual sal_Bool SAL_CALL
supportsService(rtl::OUString
const & serviceName
)
99 throw (uno::RuntimeException
);
100 virtual uno::Sequence
< rtl::OUString
> SAL_CALL
getSupportedServiceNames()
101 throw (uno::RuntimeException
);
104 virtual void SAL_CALL
disposing( ::com::sun::star::lang::EventObject
const & evt
)
105 throw (::com::sun::star::uno::RuntimeException
);
107 // XTerminateListener
108 virtual void SAL_CALL
queryTermination( lang::EventObject
const & evt
)
109 throw ( frame::TerminationVetoException
, uno::RuntimeException
);
110 virtual void SAL_CALL
notifyTermination( lang::EventObject
const & evt
)
111 throw ( uno::RuntimeException
);
114 uno::Reference
<uno::XComponentContext
> m_xContext
;
115 uno::Reference
< frame::XDesktop
> m_xDesktop
;
116 std::auto_ptr
< InitUpdateCheckJobThread
> m_pInitThread
;
118 void handleExtensionUpdates( const uno::Sequence
< beans::NamedValue
> &rListProp
);
121 //------------------------------------------------------------------------------
122 //------------------------------------------------------------------------------
123 //------------------------------------------------------------------------------
124 InitUpdateCheckJobThread::InitUpdateCheckJobThread(
125 const uno::Reference
< uno::XComponentContext
> &xContext
,
126 const uno::Sequence
< beans::NamedValue
> &xParameters
,
128 m_xContext( xContext
),
129 m_xParameters( xParameters
),
130 m_bShowDialog( bShowDialog
),
131 m_bTerminating( false )
136 //------------------------------------------------------------------------------
137 void SAL_CALL
InitUpdateCheckJobThread::run()
139 if (!m_bShowDialog
) {
140 TimeValue tv
= { 25, 0 };
141 m_aCondition
.wait( &tv
);
142 if ( m_bTerminating
)
146 rtl::Reference
< UpdateCheck
> aController( UpdateCheck::get() );
147 aController
->initialize( m_xParameters
, m_xContext
);
150 aController
->showDialog( true );
153 void InitUpdateCheckJobThread::setTerminating() {
154 m_bTerminating
= true;
158 //------------------------------------------------------------------------------
159 //------------------------------------------------------------------------------
160 //------------------------------------------------------------------------------
162 UpdateCheckJob::UpdateCheckJob( const uno::Reference
<uno::XComponentContext
>& xContext
) :
165 m_xDesktop
.set( xContext
->getServiceManager()->createInstanceWithContext( UNISTRING("com.sun.star.frame.Desktop"), xContext
), uno::UNO_QUERY
);
166 if ( m_xDesktop
.is() )
167 m_xDesktop
->addTerminateListener( this );
170 //------------------------------------------------------------------------------
172 UpdateCheckJob::~UpdateCheckJob()
176 //------------------------------------------------------------------------------
178 uno::Sequence
< rtl::OUString
>
179 UpdateCheckJob::getServiceNames()
181 uno::Sequence
< rtl::OUString
> aServiceList(1);
182 aServiceList
[0] = UNISTRING( "com.sun.star.setup.UpdateCheck");
186 //------------------------------------------------------------------------------
189 UpdateCheckJob::getImplName()
191 return UNISTRING( "vnd.sun.UpdateCheck");
195 //------------------------------------------------------------------------------
198 UpdateCheckJob::execute(const uno::Sequence
<beans::NamedValue
>& namedValues
)
199 throw (lang::IllegalArgumentException
, uno::Exception
)
201 for ( sal_Int32 n
=namedValues
.getLength(); n
-- > 0; )
203 if ( namedValues
[ n
].Name
.equalsAscii( "DynamicData" ) )
205 uno::Sequence
<beans::NamedValue
> aListProp
;
206 if ( namedValues
[n
].Value
>>= aListProp
)
208 for ( sal_Int32 i
=aListProp
.getLength(); i
-- > 0; )
210 if ( aListProp
[ i
].Name
.equalsAscii( "updateList" ) )
212 handleExtensionUpdates( aListProp
);
220 uno::Sequence
<beans::NamedValue
> aConfig
=
221 getValue
< uno::Sequence
<beans::NamedValue
> > (namedValues
, "JobConfig");
223 /* Determine the way we got invoked here -
224 * see Developers Guide Chapter "4.7.2 Jobs" to understand the magic
227 uno::Sequence
<beans::NamedValue
> aEnvironment
=
228 getValue
< uno::Sequence
<beans::NamedValue
> > (namedValues
, "Environment");
230 rtl::OUString aEventName
= getValue
< rtl::OUString
> (aEnvironment
, "EventName");
233 new InitUpdateCheckJobThread(
235 !aEventName
.equalsAscii("onFirstVisibleTask")));
240 //------------------------------------------------------------------------------
241 void UpdateCheckJob::handleExtensionUpdates( const uno::Sequence
< beans::NamedValue
> &rListProp
)
244 uno::Sequence
< uno::Sequence
< rtl::OUString
> > aList
=
245 getValue
< uno::Sequence
< uno::Sequence
< rtl::OUString
> > > ( rListProp
, "updateList" );
246 bool bPrepareOnly
= getValue
< bool > ( rListProp
, "prepareOnly" );
248 // we will first store any new found updates and then check, if there are any
250 storeExtensionUpdateInfos( m_xContext
, aList
);
255 bool bHasUpdates
= checkForPendingUpdates( m_xContext
);
257 rtl::Reference
<UpdateCheck
> aController( UpdateCheck::get() );
258 if ( ! aController
.is() )
261 aController
->setHasExtensionUpdates( bHasUpdates
);
263 if ( ! aController
->hasOfficeUpdate() )
266 aController
->setUIState( UPDATESTATE_EXT_UPD_AVAIL
, true );
268 aController
->setUIState( UPDATESTATE_NO_UPDATE_AVAIL
, true );
271 catch( const uno::Exception
& e
)
273 OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
274 rtl::OUStringToOString(e
.Message
, RTL_TEXTENCODING_UTF8
).getStr());
278 //------------------------------------------------------------------------------
280 rtl::OUString SAL_CALL
281 UpdateCheckJob::getImplementationName() throw (uno::RuntimeException
)
283 return getImplName();
286 //------------------------------------------------------------------------------
288 uno::Sequence
< rtl::OUString
> SAL_CALL
289 UpdateCheckJob::getSupportedServiceNames() throw (uno::RuntimeException
)
291 return getServiceNames();
294 //------------------------------------------------------------------------------
297 UpdateCheckJob::supportsService( rtl::OUString
const & serviceName
) throw (uno::RuntimeException
)
299 uno::Sequence
< rtl::OUString
> aServiceNameList
= getServiceNames();
301 for( sal_Int32 n
=0; n
< aServiceNameList
.getLength(); n
++ )
302 if( aServiceNameList
[n
].equals(serviceName
) )
308 //------------------------------------------------------------------------------
310 void SAL_CALL
UpdateCheckJob::disposing( lang::EventObject
const & rEvt
)
311 throw ( uno::RuntimeException
)
313 bool shutDown
= ( rEvt
.Source
== m_xDesktop
);
315 if ( shutDown
&& m_xDesktop
.is() )
317 m_xDesktop
->removeTerminateListener( this );
322 //------------------------------------------------------------------------------
323 // XTerminateListener
324 void SAL_CALL
UpdateCheckJob::queryTermination( lang::EventObject
const & )
325 throw ( frame::TerminationVetoException
, uno::RuntimeException
)
329 //------------------------------------------------------------------------------
330 void SAL_CALL
UpdateCheckJob::notifyTermination( lang::EventObject
const & rEvt
)
331 throw ( uno::RuntimeException
)
333 if ( m_pInitThread
.get() != 0 )
334 m_pInitThread
->setTerminating();
339 } // anonymous namespace
341 //------------------------------------------------------------------------------
343 static uno::Reference
<uno::XInterface
> SAL_CALL
344 createJobInstance(const uno::Reference
<uno::XComponentContext
>& xContext
)
346 return *new UpdateCheckJob(xContext
);
349 //------------------------------------------------------------------------------
351 static uno::Reference
<uno::XInterface
> SAL_CALL
352 createConfigInstance(const uno::Reference
<uno::XComponentContext
>& xContext
)
354 return *UpdateCheckConfig::get(xContext
, *UpdateCheck::get());
357 //------------------------------------------------------------------------------
359 static const cppu::ImplementationEntry kImplementations_entries
[] =
363 UpdateCheckJob::getImplName
,
364 UpdateCheckJob::getServiceNames
,
365 cppu::createSingleComponentFactory
,
370 createConfigInstance
,
371 UpdateCheckConfig::getImplName
,
372 UpdateCheckConfig::getServiceNames
,
373 cppu::createSingleComponentFactory
,
377 { NULL
, NULL
, NULL
, NULL
, NULL
, 0 }
380 //------------------------------------------------------------------------------
382 extern "C" void SAL_CALL
383 component_getImplementationEnvironment( const sal_Char
**aEnvTypeName
, uno_Environment
**)
385 *aEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
388 //------------------------------------------------------------------------------
390 extern "C" sal_Bool SAL_CALL
391 component_writeInfo(void *pServiceManager
, void *pRegistryKey
)
393 return cppu::component_writeInfoHelper(
396 kImplementations_entries
400 //------------------------------------------------------------------------------
403 component_getFactory(const sal_Char
*pszImplementationName
, void *pServiceManager
, void *pRegistryKey
)
405 return cppu::component_getFactoryHelper(
406 pszImplementationName
,
409 kImplementations_entries
) ;