1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
32 #include "updatecheck.hxx"
33 #include "updatecheckconfig.hxx"
34 #include "updatehdl.hxx"
35 #include "updateprotocol.hxx"
37 #include <cppuhelper/implbase3.hxx>
38 #include <cppuhelper/implementationentry.hxx>
40 #include "com/sun/star/frame/XDesktop.hpp"
41 #include "com/sun/star/frame/XTerminateListener.hpp"
42 #include <com/sun/star/task/XJob.hpp>
44 namespace beans
= com::sun::star::beans
;
45 namespace frame
= com::sun::star::frame
;
46 namespace lang
= com::sun::star::lang
;
47 namespace task
= com::sun::star::task
;
48 namespace uno
= com::sun::star::uno
;
50 #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
55 class InitUpdateCheckJobThread
: public osl::Thread
58 InitUpdateCheckJobThread( const uno::Reference
< uno::XComponentContext
> &xContext
,
59 const uno::Sequence
< beans::NamedValue
> &xParameters
,
62 virtual void SAL_CALL
run();
64 void setTerminating();
67 osl::Condition m_aCondition
;
68 uno::Reference
<uno::XComponentContext
> m_xContext
;
69 uno::Sequence
<beans::NamedValue
> m_xParameters
;
74 class UpdateCheckJob
:
75 public ::cppu::WeakImplHelper3
< task::XJob
, lang::XServiceInfo
, frame::XTerminateListener
>
77 virtual ~UpdateCheckJob();
81 UpdateCheckJob(const uno::Reference
<uno::XComponentContext
>& xContext
);
83 static uno::Sequence
< rtl::OUString
> getServiceNames();
84 static rtl::OUString
getImplName();
86 // Allows runtime exceptions to be thrown by const methods
87 inline SAL_CALL
operator uno::Reference
< uno::XInterface
> () const
88 { return const_cast< cppu::OWeakObject
* > (static_cast< cppu::OWeakObject
const * > (this)); };
91 virtual uno::Any SAL_CALL
execute(const uno::Sequence
<beans::NamedValue
>&)
92 throw (lang::IllegalArgumentException
, uno::Exception
);
95 virtual rtl::OUString SAL_CALL
getImplementationName()
96 throw (uno::RuntimeException
);
97 virtual sal_Bool SAL_CALL
supportsService(rtl::OUString
const & serviceName
)
98 throw (uno::RuntimeException
);
99 virtual uno::Sequence
< rtl::OUString
> SAL_CALL
getSupportedServiceNames()
100 throw (uno::RuntimeException
);
103 virtual void SAL_CALL
disposing( ::com::sun::star::lang::EventObject
const & evt
)
104 throw (::com::sun::star::uno::RuntimeException
);
106 // XTerminateListener
107 virtual void SAL_CALL
queryTermination( lang::EventObject
const & evt
)
108 throw ( frame::TerminationVetoException
, uno::RuntimeException
);
109 virtual void SAL_CALL
notifyTermination( lang::EventObject
const & evt
)
110 throw ( uno::RuntimeException
);
113 uno::Reference
<uno::XComponentContext
> m_xContext
;
114 uno::Reference
< frame::XDesktop
> m_xDesktop
;
115 std::auto_ptr
< InitUpdateCheckJobThread
> m_pInitThread
;
117 void handleExtensionUpdates( const uno::Sequence
< beans::NamedValue
> &rListProp
);
120 //------------------------------------------------------------------------------
121 //------------------------------------------------------------------------------
122 //------------------------------------------------------------------------------
123 InitUpdateCheckJobThread::InitUpdateCheckJobThread(
124 const uno::Reference
< uno::XComponentContext
> &xContext
,
125 const uno::Sequence
< beans::NamedValue
> &xParameters
,
127 m_xContext( xContext
),
128 m_xParameters( xParameters
),
129 m_bShowDialog( bShowDialog
),
130 m_bTerminating( false )
135 //------------------------------------------------------------------------------
136 void SAL_CALL
InitUpdateCheckJobThread::run()
138 if (!m_bShowDialog
) {
139 TimeValue tv
= { 25, 0 };
140 m_aCondition
.wait( &tv
);
141 if ( m_bTerminating
)
145 rtl::Reference
< UpdateCheck
> aController( UpdateCheck::get() );
146 aController
->initialize( m_xParameters
, m_xContext
);
149 aController
->showDialog( true );
152 void InitUpdateCheckJobThread::setTerminating() {
153 m_bTerminating
= true;
157 //------------------------------------------------------------------------------
158 //------------------------------------------------------------------------------
159 //------------------------------------------------------------------------------
161 UpdateCheckJob::UpdateCheckJob( const uno::Reference
<uno::XComponentContext
>& xContext
) :
164 m_xDesktop
.set( xContext
->getServiceManager()->createInstanceWithContext( UNISTRING("com.sun.star.frame.Desktop"), xContext
), uno::UNO_QUERY
);
165 if ( m_xDesktop
.is() )
166 m_xDesktop
->addTerminateListener( this );
169 //------------------------------------------------------------------------------
171 UpdateCheckJob::~UpdateCheckJob()
175 //------------------------------------------------------------------------------
177 uno::Sequence
< rtl::OUString
>
178 UpdateCheckJob::getServiceNames()
180 uno::Sequence
< rtl::OUString
> aServiceList(1);
181 aServiceList
[0] = UNISTRING( "com.sun.star.setup.UpdateCheck");
185 //------------------------------------------------------------------------------
188 UpdateCheckJob::getImplName()
190 return UNISTRING( "vnd.sun.UpdateCheck");
194 //------------------------------------------------------------------------------
197 UpdateCheckJob::execute(const uno::Sequence
<beans::NamedValue
>& namedValues
)
198 throw (lang::IllegalArgumentException
, uno::Exception
)
200 for ( sal_Int32 n
=namedValues
.getLength(); n
-- > 0; )
202 if ( namedValues
[ n
].Name
== "DynamicData" )
204 uno::Sequence
<beans::NamedValue
> aListProp
;
205 if ( namedValues
[n
].Value
>>= aListProp
)
207 for ( sal_Int32 i
=aListProp
.getLength(); i
-- > 0; )
209 if ( aListProp
[ i
].Name
== "updateList" )
211 handleExtensionUpdates( aListProp
);
219 uno::Sequence
<beans::NamedValue
> aConfig
=
220 getValue
< uno::Sequence
<beans::NamedValue
> > (namedValues
, "JobConfig");
222 /* Determine the way we got invoked here -
223 * see Developers Guide Chapter "4.7.2 Jobs" to understand the magic
226 uno::Sequence
<beans::NamedValue
> aEnvironment
=
227 getValue
< uno::Sequence
<beans::NamedValue
> > (namedValues
, "Environment");
229 rtl::OUString aEventName
= getValue
< rtl::OUString
> (aEnvironment
, "EventName");
232 new InitUpdateCheckJobThread(
234 !aEventName
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("onFirstVisibleTask"))));
239 //------------------------------------------------------------------------------
240 void UpdateCheckJob::handleExtensionUpdates( const uno::Sequence
< beans::NamedValue
> &rListProp
)
243 uno::Sequence
< uno::Sequence
< rtl::OUString
> > aList
=
244 getValue
< uno::Sequence
< uno::Sequence
< rtl::OUString
> > > ( rListProp
, "updateList" );
245 bool bPrepareOnly
= getValue
< bool > ( rListProp
, "prepareOnly" );
247 // we will first store any new found updates and then check, if there are any
249 storeExtensionUpdateInfos( m_xContext
, aList
);
254 bool bHasUpdates
= checkForPendingUpdates( m_xContext
);
256 rtl::Reference
<UpdateCheck
> aController( UpdateCheck::get() );
257 if ( ! aController
.is() )
260 aController
->setHasExtensionUpdates( bHasUpdates
);
262 if ( ! aController
->hasOfficeUpdate() )
265 aController
->setUIState( UPDATESTATE_EXT_UPD_AVAIL
, true );
267 aController
->setUIState( UPDATESTATE_NO_UPDATE_AVAIL
, true );
270 catch( const uno::Exception
& e
)
272 OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
273 rtl::OUStringToOString(e
.Message
, RTL_TEXTENCODING_UTF8
).getStr());
277 //------------------------------------------------------------------------------
279 rtl::OUString SAL_CALL
280 UpdateCheckJob::getImplementationName() throw (uno::RuntimeException
)
282 return getImplName();
285 //------------------------------------------------------------------------------
287 uno::Sequence
< rtl::OUString
> SAL_CALL
288 UpdateCheckJob::getSupportedServiceNames() throw (uno::RuntimeException
)
290 return getServiceNames();
293 //------------------------------------------------------------------------------
296 UpdateCheckJob::supportsService( rtl::OUString
const & serviceName
) throw (uno::RuntimeException
)
298 uno::Sequence
< rtl::OUString
> aServiceNameList
= getServiceNames();
300 for( sal_Int32 n
=0; n
< aServiceNameList
.getLength(); n
++ )
301 if( aServiceNameList
[n
].equals(serviceName
) )
307 //------------------------------------------------------------------------------
309 void SAL_CALL
UpdateCheckJob::disposing( lang::EventObject
const & rEvt
)
310 throw ( uno::RuntimeException
)
312 bool shutDown
= ( rEvt
.Source
== m_xDesktop
);
314 if ( shutDown
&& m_xDesktop
.is() )
316 m_xDesktop
->removeTerminateListener( this );
321 //------------------------------------------------------------------------------
322 // XTerminateListener
323 void SAL_CALL
UpdateCheckJob::queryTermination( lang::EventObject
const & )
324 throw ( frame::TerminationVetoException
, uno::RuntimeException
)
328 //------------------------------------------------------------------------------
329 void SAL_CALL
UpdateCheckJob::notifyTermination( lang::EventObject
const & )
330 throw ( uno::RuntimeException
)
332 if ( m_pInitThread
.get() != 0 )
334 m_pInitThread
->setTerminating();
335 m_pInitThread
->join();
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" SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
component_getFactory(const sal_Char
*pszImplementationName
, void *pServiceManager
, void *pRegistryKey
)
384 return cppu::component_getFactoryHelper(
385 pszImplementationName
,
388 kImplementations_entries
) ;
391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */