1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: updatecheckjob.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
34 #include "updatecheck.hxx"
35 #include "updatecheckconfig.hxx"
36 #include "updatehdl.hxx"
37 #include "updateprotocol.hxx"
39 #include <cppuhelper/implbase3.hxx>
40 #include <cppuhelper/implementationentry.hxx>
42 #include "com/sun/star/frame/XDesktop.hpp"
43 #include "com/sun/star/frame/XTerminateListener.hpp"
44 #include <com/sun/star/task/XJob.hpp>
46 namespace beans
= com::sun::star::beans
;
47 namespace frame
= com::sun::star::frame
;
48 namespace lang
= com::sun::star::lang
;
49 namespace task
= com::sun::star::task
;
50 namespace uno
= com::sun::star::uno
;
52 #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
57 class InitUpdateCheckJobThread
: public osl::Thread
60 InitUpdateCheckJobThread( const uno::Reference
< uno::XComponentContext
> &xContext
,
61 const uno::Sequence
< beans::NamedValue
> &xParameters
);
63 virtual void SAL_CALL
run();
64 virtual void SAL_CALL
onTerminated();
67 void setTerminating() { m_bTerminating
= true; }
70 ~InitUpdateCheckJobThread();
73 osl::Condition m_aCondition
;
74 uno::Reference
<uno::XComponentContext
> m_xContext
;
75 uno::Sequence
<beans::NamedValue
> m_xParameters
;
80 class UpdateCheckJob
:
81 public ::cppu::WeakImplHelper3
< task::XJob
, lang::XServiceInfo
, frame::XTerminateListener
>
83 virtual ~UpdateCheckJob();
87 UpdateCheckJob(const uno::Reference
<uno::XComponentContext
>& xContext
);
89 static uno::Sequence
< rtl::OUString
> getServiceNames();
90 static rtl::OUString
getImplName();
92 // Allows runtime exceptions to be thrown by const methods
93 inline SAL_CALL
operator uno::Reference
< uno::XInterface
> () const
94 { return const_cast< cppu::OWeakObject
* > (static_cast< cppu::OWeakObject
const * > (this)); };
97 virtual uno::Any SAL_CALL
execute(const uno::Sequence
<beans::NamedValue
>&)
98 throw (lang::IllegalArgumentException
, uno::Exception
);
101 virtual rtl::OUString SAL_CALL
getImplementationName()
102 throw (uno::RuntimeException
);
103 virtual sal_Bool SAL_CALL
supportsService(rtl::OUString
const & serviceName
)
104 throw (uno::RuntimeException
);
105 virtual uno::Sequence
< rtl::OUString
> SAL_CALL
getSupportedServiceNames()
106 throw (uno::RuntimeException
);
109 virtual void SAL_CALL
disposing( ::com::sun::star::lang::EventObject
const & evt
)
110 throw (::com::sun::star::uno::RuntimeException
);
112 // XTerminateListener
113 virtual void SAL_CALL
queryTermination( lang::EventObject
const & evt
)
114 throw ( frame::TerminationVetoException
, uno::RuntimeException
);
115 virtual void SAL_CALL
notifyTermination( lang::EventObject
const & evt
)
116 throw ( uno::RuntimeException
);
119 uno::Reference
<uno::XComponentContext
> m_xContext
;
120 uno::Reference
< frame::XDesktop
> m_xDesktop
;
121 InitUpdateCheckJobThread
*m_pInitThread
;
123 void handleExtensionUpdates( const uno::Sequence
< beans::NamedValue
> &rListProp
);
126 //------------------------------------------------------------------------------
127 //------------------------------------------------------------------------------
128 //------------------------------------------------------------------------------
129 InitUpdateCheckJobThread::InitUpdateCheckJobThread(
130 const uno::Reference
< uno::XComponentContext
> &xContext
,
131 const uno::Sequence
< beans::NamedValue
> &xParameters
) :
132 m_xContext( xContext
),
133 m_xParameters( xParameters
),
134 m_bShowDialog( false ),
135 m_bTerminating( false )
140 //------------------------------------------------------------------------------
141 InitUpdateCheckJobThread::~InitUpdateCheckJobThread()
145 //------------------------------------------------------------------------------
146 void SAL_CALL
InitUpdateCheckJobThread::run()
148 TimeValue tv
= { 25, 0 };
150 m_aCondition
.wait( &tv
);
152 if ( m_bTerminating
)
155 rtl::Reference
< UpdateCheck
> aController( UpdateCheck::get() );
156 aController
->initialize( m_xParameters
, m_xContext
);
159 aController
->showDialog( true );
162 //------------------------------------------------------------------------------
163 void SAL_CALL
InitUpdateCheckJobThread::onTerminated()
168 //------------------------------------------------------------------------------
169 void InitUpdateCheckJobThread::showDialog()
171 m_bShowDialog
= true;
175 //------------------------------------------------------------------------------
176 //------------------------------------------------------------------------------
177 //------------------------------------------------------------------------------
179 UpdateCheckJob::UpdateCheckJob( const uno::Reference
<uno::XComponentContext
>& xContext
) :
180 m_xContext(xContext
),
181 m_pInitThread( NULL
)
183 m_xDesktop
.set( xContext
->getServiceManager()->createInstanceWithContext( UNISTRING("com.sun.star.frame.Desktop"), xContext
), uno::UNO_QUERY
);
184 if ( m_xDesktop
.is() )
185 m_xDesktop
->addTerminateListener( this );
188 //------------------------------------------------------------------------------
190 UpdateCheckJob::~UpdateCheckJob()
194 //------------------------------------------------------------------------------
196 uno::Sequence
< rtl::OUString
>
197 UpdateCheckJob::getServiceNames()
199 uno::Sequence
< rtl::OUString
> aServiceList(1);
200 aServiceList
[0] = UNISTRING( "com.sun.star.setup.UpdateCheck");
204 //------------------------------------------------------------------------------
207 UpdateCheckJob::getImplName()
209 return UNISTRING( "vnd.sun.UpdateCheck");
213 //------------------------------------------------------------------------------
216 UpdateCheckJob::execute(const uno::Sequence
<beans::NamedValue
>& namedValues
)
217 throw (lang::IllegalArgumentException
, uno::Exception
)
219 for ( sal_Int32 n
=namedValues
.getLength(); n
-- > 0; )
221 if ( namedValues
[ n
].Name
.equalsAscii( "DynamicData" ) )
223 uno::Sequence
<beans::NamedValue
> aListProp
;
224 if ( namedValues
[n
].Value
>>= aListProp
)
226 for ( sal_Int32 i
=aListProp
.getLength(); i
-- > 0; )
228 if ( aListProp
[ i
].Name
.equalsAscii( "updateList" ) )
230 handleExtensionUpdates( aListProp
);
238 uno::Sequence
<beans::NamedValue
> aConfig
=
239 getValue
< uno::Sequence
<beans::NamedValue
> > (namedValues
, "JobConfig");
240 m_pInitThread
= new InitUpdateCheckJobThread( m_xContext
, aConfig
);
242 /* Determine the way we got invoked here -
243 * see Developers Guide Chapter "4.7.2 Jobs" to understand the magic
246 uno::Sequence
<beans::NamedValue
> aEnvironment
=
247 getValue
< uno::Sequence
<beans::NamedValue
> > (namedValues
, "Environment");
249 rtl::OUString aEventName
= getValue
< rtl::OUString
> (aEnvironment
, "EventName");
251 if( ! aEventName
.equalsAscii("onFirstVisibleTask") )
253 m_pInitThread
->showDialog();
259 //------------------------------------------------------------------------------
260 void UpdateCheckJob::handleExtensionUpdates( const uno::Sequence
< beans::NamedValue
> &rListProp
)
263 uno::Sequence
< uno::Sequence
< rtl::OUString
> > aList
=
264 getValue
< uno::Sequence
< uno::Sequence
< rtl::OUString
> > > ( rListProp
, "updateList" );
265 bool bPrepareOnly
= getValue
< bool > ( rListProp
, "prepareOnly" );
267 // we will first store any new found updates and then check, if there are any
269 storeExtensionUpdateInfos( m_xContext
, aList
);
274 bool bHasUpdates
= checkForPendingUpdates( m_xContext
);
276 rtl::Reference
<UpdateCheck
> aController( UpdateCheck::get() );
277 if ( ! aController
.is() )
280 aController
->setHasExtensionUpdates( bHasUpdates
);
282 if ( ! aController
->hasOfficeUpdate() )
285 aController
->setUIState( UPDATESTATE_EXT_UPD_AVAIL
, true );
287 aController
->setUIState( UPDATESTATE_NO_UPDATE_AVAIL
, true );
290 catch( const uno::Exception
& e
)
292 OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
293 rtl::OUStringToOString(e
.Message
, RTL_TEXTENCODING_UTF8
).getStr());
297 //------------------------------------------------------------------------------
299 rtl::OUString SAL_CALL
300 UpdateCheckJob::getImplementationName() throw (uno::RuntimeException
)
302 return getImplName();
305 //------------------------------------------------------------------------------
307 uno::Sequence
< rtl::OUString
> SAL_CALL
308 UpdateCheckJob::getSupportedServiceNames() throw (uno::RuntimeException
)
310 return getServiceNames();
313 //------------------------------------------------------------------------------
316 UpdateCheckJob::supportsService( rtl::OUString
const & serviceName
) throw (uno::RuntimeException
)
318 uno::Sequence
< rtl::OUString
> aServiceNameList
= getServiceNames();
320 for( sal_Int32 n
=0; n
< aServiceNameList
.getLength(); n
++ )
321 if( aServiceNameList
[n
].equals(serviceName
) )
327 //------------------------------------------------------------------------------
329 void SAL_CALL
UpdateCheckJob::disposing( lang::EventObject
const & rEvt
)
330 throw ( uno::RuntimeException
)
332 bool shutDown
= ( rEvt
.Source
== m_xDesktop
);
334 if ( shutDown
&& m_xDesktop
.is() )
336 m_xDesktop
->removeTerminateListener( this );
341 //------------------------------------------------------------------------------
342 // XTerminateListener
343 void SAL_CALL
UpdateCheckJob::queryTermination( lang::EventObject
const & )
344 throw ( frame::TerminationVetoException
, uno::RuntimeException
)
348 //------------------------------------------------------------------------------
349 void SAL_CALL
UpdateCheckJob::notifyTermination( lang::EventObject
const & rEvt
)
350 throw ( uno::RuntimeException
)
353 m_pInitThread
->setTerminating();
358 } // anonymous namespace
360 //------------------------------------------------------------------------------
362 static uno::Reference
<uno::XInterface
> SAL_CALL
363 createJobInstance(const uno::Reference
<uno::XComponentContext
>& xContext
)
365 return *new UpdateCheckJob(xContext
);
368 //------------------------------------------------------------------------------
370 static uno::Reference
<uno::XInterface
> SAL_CALL
371 createConfigInstance(const uno::Reference
<uno::XComponentContext
>& xContext
)
373 return *UpdateCheckConfig::get(xContext
, *UpdateCheck::get());
376 //------------------------------------------------------------------------------
378 static const cppu::ImplementationEntry kImplementations_entries
[] =
382 UpdateCheckJob::getImplName
,
383 UpdateCheckJob::getServiceNames
,
384 cppu::createSingleComponentFactory
,
389 createConfigInstance
,
390 UpdateCheckConfig::getImplName
,
391 UpdateCheckConfig::getServiceNames
,
392 cppu::createSingleComponentFactory
,
396 { NULL
, NULL
, NULL
, NULL
, NULL
, 0 }
399 //------------------------------------------------------------------------------
401 extern "C" void SAL_CALL
402 component_getImplementationEnvironment( const sal_Char
**aEnvTypeName
, uno_Environment
**)
404 *aEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
407 //------------------------------------------------------------------------------
409 extern "C" sal_Bool SAL_CALL
410 component_writeInfo(void *pServiceManager
, void *pRegistryKey
)
412 return cppu::component_writeInfoHelper(
415 kImplementations_entries
419 //------------------------------------------------------------------------------
422 component_getFactory(const sal_Char
*pszImplementationName
, void *pServiceManager
, void *pRegistryKey
)
424 return cppu::component_getFactoryHelper(
425 pszImplementationName
,
428 kImplementations_entries
) ;