xref: /AOO41X/main/desktop/source/deployment/gui/dp_gui_extensioncmdqueue.cxx (revision 2722ceddc26af33ca9ed6a22fc3c4dfb805171c3)
1*2722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2722ceddSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2722ceddSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2722ceddSAndrew Rist  * distributed with this work for additional information
6*2722ceddSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2722ceddSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2722ceddSAndrew Rist  * "License"); you may not use this file except in compliance
9*2722ceddSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*2722ceddSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*2722ceddSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2722ceddSAndrew Rist  * software distributed under the License is distributed on an
15*2722ceddSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2722ceddSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2722ceddSAndrew Rist  * specific language governing permissions and limitations
18*2722ceddSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*2722ceddSAndrew Rist  *************************************************************/
21*2722ceddSAndrew Rist 
22*2722ceddSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_desktop.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "sal/config.h"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <cstddef>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "com/sun/star/beans/PropertyValue.hpp"
35cdf0e10cSrcweir #include "com/sun/star/beans/NamedValue.hpp"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include "com/sun/star/deployment/DependencyException.hpp"
38cdf0e10cSrcweir #include "com/sun/star/deployment/LicenseException.hpp"
39cdf0e10cSrcweir #include "com/sun/star/deployment/VersionException.hpp"
40cdf0e10cSrcweir #include "com/sun/star/deployment/InstallException.hpp"
41cdf0e10cSrcweir #include "com/sun/star/deployment/PlatformException.hpp"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include "com/sun/star/deployment/ui/LicenseDialog.hpp"
44cdf0e10cSrcweir #include "com/sun/star/deployment/DeploymentException.hpp"
45cdf0e10cSrcweir #include "com/sun/star/deployment/UpdateInformationProvider.hpp"
46cdf0e10cSrcweir #include "com/sun/star/deployment/XPackage.hpp"
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include "com/sun/star/task/XAbortChannel.hpp"
49cdf0e10cSrcweir #include "com/sun/star/task/XInteractionAbort.hpp"
50cdf0e10cSrcweir #include "com/sun/star/task/XInteractionApprove.hpp"
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #include "com/sun/star/ucb/CommandAbortedException.hpp"
53cdf0e10cSrcweir #include "com/sun/star/ucb/CommandFailedException.hpp"
54cdf0e10cSrcweir #include "com/sun/star/ucb/XCommandEnvironment.hpp"
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #include "com/sun/star/ui/dialogs/ExecutableDialogResults.hpp"
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
59cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
60cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
61cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
62cdf0e10cSrcweir #include "com/sun/star/uno/TypeClass.hpp"
63cdf0e10cSrcweir #include "osl/diagnose.h"
64cdf0e10cSrcweir #include "osl/mutex.hxx"
65cdf0e10cSrcweir #include "rtl/ref.hxx"
66cdf0e10cSrcweir #include "rtl/ustring.h"
67cdf0e10cSrcweir #include "rtl/ustring.hxx"
68cdf0e10cSrcweir #include "sal/types.h"
69cdf0e10cSrcweir #include "ucbhelper/content.hxx"
70cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx"
71cdf0e10cSrcweir #include "cppuhelper/implbase3.hxx"
72cdf0e10cSrcweir #include "comphelper/anytostring.hxx"
73cdf0e10cSrcweir #include "vcl/msgbox.hxx"
74cdf0e10cSrcweir #include "toolkit/helper/vclunohelper.hxx"
75cdf0e10cSrcweir #include "comphelper/processfactory.hxx"
76cdf0e10cSrcweir 
77cdf0e10cSrcweir #include "dp_gui.h"
78cdf0e10cSrcweir #include "dp_gui_thread.hxx"
79cdf0e10cSrcweir #include "dp_gui_extensioncmdqueue.hxx"
80cdf0e10cSrcweir #include "dp_gui_dependencydialog.hxx"
81cdf0e10cSrcweir #include "dp_gui_dialog2.hxx"
82cdf0e10cSrcweir #include "dp_gui_shared.hxx"
83cdf0e10cSrcweir #include "dp_gui_theextmgr.hxx"
84cdf0e10cSrcweir #include "dp_gui_updatedialog.hxx"
85cdf0e10cSrcweir #include "dp_gui_updateinstalldialog.hxx"
86cdf0e10cSrcweir #include "dp_dependencies.hxx"
87cdf0e10cSrcweir #include "dp_identifier.hxx"
88cdf0e10cSrcweir #include "dp_version.hxx"
89cdf0e10cSrcweir 
90cdf0e10cSrcweir #include <queue>
91cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
92cdf0e10cSrcweir 
93cdf0e10cSrcweir #if (defined(_MSC_VER) && (_MSC_VER < 1400))
94cdf0e10cSrcweir #define _WIN32_WINNT 0x0400
95cdf0e10cSrcweir #endif
96cdf0e10cSrcweir 
97cdf0e10cSrcweir #ifdef WNT
98cdf0e10cSrcweir #include "tools/prewin.h"
99cdf0e10cSrcweir #include <objbase.h>
100cdf0e10cSrcweir #include "tools/postwin.h"
101cdf0e10cSrcweir #endif
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 
104cdf0e10cSrcweir using namespace ::com::sun::star;
105cdf0e10cSrcweir using ::rtl::OUString;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir namespace {
108cdf0e10cSrcweir 
109cdf0e10cSrcweir OUString getVersion( OUString const & sVersion )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     return ( sVersion.getLength() == 0 ) ? OUString( RTL_CONSTASCII_USTRINGPARAM( "0" ) ) : sVersion;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir OUString getVersion( const uno::Reference< deployment::XPackage > &rPackage )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir     return getVersion( rPackage->getVersion());
117cdf0e10cSrcweir }
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 
121cdf0e10cSrcweir namespace dp_gui {
122cdf0e10cSrcweir 
123cdf0e10cSrcweir //==============================================================================
124cdf0e10cSrcweir 
125cdf0e10cSrcweir class ProgressCmdEnv
126cdf0e10cSrcweir     : public ::cppu::WeakImplHelper3< ucb::XCommandEnvironment,
127cdf0e10cSrcweir                                       task::XInteractionHandler,
128cdf0e10cSrcweir                                       ucb::XProgressHandler >
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     uno::Reference< task::XInteractionHandler> m_xHandler;
131cdf0e10cSrcweir     uno::Reference< uno::XComponentContext > m_xContext;
132cdf0e10cSrcweir     uno::Reference< task::XAbortChannel> m_xAbortChannel;
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     DialogHelper   *m_pDialogHelper;
135cdf0e10cSrcweir     OUString        m_sTitle;
136cdf0e10cSrcweir     bool            m_bAborted;
137cdf0e10cSrcweir     bool            m_bWarnUser;
138cdf0e10cSrcweir     sal_Int32       m_nCurrentProgress;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     void updateProgress();
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     void update_( uno::Any const & Status ) throw ( uno::RuntimeException );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir public:
145cdf0e10cSrcweir     virtual ~ProgressCmdEnv();
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     /** When param bAskWhenInstalling = true, then the user is asked if he
148cdf0e10cSrcweir     agrees to install this extension. In case this extension is already installed
149cdf0e10cSrcweir     then the user is also notified and asked if he wants to replace that existing
150cdf0e10cSrcweir     extension. In first case an interaction request with an InstallException
151cdf0e10cSrcweir     will be handled and in the second case a VersionException will be handled.
152cdf0e10cSrcweir     */
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     ProgressCmdEnv( const uno::Reference< uno::XComponentContext > rContext,
155cdf0e10cSrcweir                     DialogHelper *pDialogHelper,
156cdf0e10cSrcweir                     const OUString &rTitle )
157cdf0e10cSrcweir         :   m_xContext( rContext ),
158cdf0e10cSrcweir             m_pDialogHelper( pDialogHelper ),
159cdf0e10cSrcweir             m_sTitle( rTitle ),
160cdf0e10cSrcweir             m_bAborted( false ),
161cdf0e10cSrcweir             m_bWarnUser( false )
162cdf0e10cSrcweir     {}
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     Dialog * activeDialog() { return m_pDialogHelper ? m_pDialogHelper->getWindow() : NULL; }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     void setTitle( const OUString& rNewTitle ) { m_sTitle = rNewTitle; }
167cdf0e10cSrcweir     void startProgress();
168cdf0e10cSrcweir     void stopProgress();
169cdf0e10cSrcweir     void progressSection( const OUString &rText,
170cdf0e10cSrcweir                           const uno::Reference< task::XAbortChannel > &xAbortChannel = 0 );
171cdf0e10cSrcweir     inline bool isAborted() const { return m_bAborted; }
172cdf0e10cSrcweir     inline void setWarnUser( bool bNewVal ) { m_bWarnUser = bNewVal; }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     // XCommandEnvironment
175cdf0e10cSrcweir     virtual uno::Reference< task::XInteractionHandler > SAL_CALL getInteractionHandler()
176cdf0e10cSrcweir         throw ( uno::RuntimeException );
177cdf0e10cSrcweir     virtual uno::Reference< ucb::XProgressHandler > SAL_CALL getProgressHandler()
178cdf0e10cSrcweir         throw ( uno::RuntimeException );
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     // XInteractionHandler
181cdf0e10cSrcweir     virtual void SAL_CALL handle( uno::Reference< task::XInteractionRequest > const & xRequest )
182cdf0e10cSrcweir         throw ( uno::RuntimeException );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     // XProgressHandler
185cdf0e10cSrcweir     virtual void SAL_CALL push( uno::Any const & Status )
186cdf0e10cSrcweir         throw ( uno::RuntimeException );
187cdf0e10cSrcweir     virtual void SAL_CALL update( uno::Any const & Status )
188cdf0e10cSrcweir         throw ( uno::RuntimeException );
189cdf0e10cSrcweir     virtual void SAL_CALL pop() throw ( uno::RuntimeException );
190cdf0e10cSrcweir };
191cdf0e10cSrcweir 
192cdf0e10cSrcweir //------------------------------------------------------------------------------
193cdf0e10cSrcweir struct ExtensionCmd
194cdf0e10cSrcweir {
195cdf0e10cSrcweir     enum E_CMD_TYPE { ADD, ENABLE, DISABLE, REMOVE, CHECK_FOR_UPDATES, ACCEPT_LICENSE };
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     E_CMD_TYPE  m_eCmdType;
198cdf0e10cSrcweir     bool        m_bWarnUser;
199cdf0e10cSrcweir     OUString    m_sExtensionURL;
200cdf0e10cSrcweir     OUString    m_sRepository;
201cdf0e10cSrcweir     uno::Reference< deployment::XPackage > m_xPackage;
202cdf0e10cSrcweir     std::vector< uno::Reference< deployment::XPackage > >        m_vExtensionList;
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     ExtensionCmd( const E_CMD_TYPE eCommand,
205cdf0e10cSrcweir                   const OUString &rExtensionURL,
206cdf0e10cSrcweir                   const OUString &rRepository,
207cdf0e10cSrcweir                   const bool bWarnUser )
208cdf0e10cSrcweir         : m_eCmdType( eCommand ),
209cdf0e10cSrcweir           m_bWarnUser( bWarnUser ),
210cdf0e10cSrcweir           m_sExtensionURL( rExtensionURL ),
211cdf0e10cSrcweir           m_sRepository( rRepository ) {};
212cdf0e10cSrcweir     ExtensionCmd( const E_CMD_TYPE eCommand,
213cdf0e10cSrcweir                   const uno::Reference< deployment::XPackage > &rPackage )
214cdf0e10cSrcweir         : m_eCmdType( eCommand ),
215cdf0e10cSrcweir           m_bWarnUser( false ),
216cdf0e10cSrcweir           m_xPackage( rPackage ) {};
217cdf0e10cSrcweir     ExtensionCmd( const E_CMD_TYPE eCommand,
218cdf0e10cSrcweir                   const std::vector<uno::Reference<deployment::XPackage > > &vExtensionList )
219cdf0e10cSrcweir         : m_eCmdType( eCommand ),
220cdf0e10cSrcweir           m_bWarnUser( false ),
221cdf0e10cSrcweir           m_vExtensionList( vExtensionList ) {};
222cdf0e10cSrcweir };
223cdf0e10cSrcweir 
224cdf0e10cSrcweir typedef ::boost::shared_ptr< ExtensionCmd > TExtensionCmd;
225cdf0e10cSrcweir 
226cdf0e10cSrcweir //------------------------------------------------------------------------------
227cdf0e10cSrcweir class ExtensionCmdQueue::Thread: public dp_gui::Thread
228cdf0e10cSrcweir {
229cdf0e10cSrcweir public:
230cdf0e10cSrcweir     Thread( DialogHelper *pDialogHelper,
231cdf0e10cSrcweir             TheExtensionManager *pManager,
232cdf0e10cSrcweir             const uno::Reference< uno::XComponentContext > & rContext );
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     void addExtension( const OUString &rExtensionURL,
235cdf0e10cSrcweir                        const OUString &rRepository,
236cdf0e10cSrcweir                        const bool bWarnUser );
237cdf0e10cSrcweir     void removeExtension( const uno::Reference< deployment::XPackage > &rPackage );
238cdf0e10cSrcweir     void enableExtension( const uno::Reference< deployment::XPackage > &rPackage,
239cdf0e10cSrcweir                           const bool bEnable );
240cdf0e10cSrcweir     void checkForUpdates( const std::vector<uno::Reference<deployment::XPackage > > &vExtensionList );
241cdf0e10cSrcweir     void acceptLicense( const uno::Reference< deployment::XPackage > &rPackage );
242cdf0e10cSrcweir     void stop();
243cdf0e10cSrcweir     bool isBusy();
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     static OUString searchAndReplaceAll( const OUString &rSource,
246cdf0e10cSrcweir                                          const OUString &rWhat,
247cdf0e10cSrcweir                                          const OUString &rWith );
248cdf0e10cSrcweir private:
249cdf0e10cSrcweir     Thread( Thread & ); // not defined
250cdf0e10cSrcweir     void operator =( Thread & ); // not defined
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     virtual ~Thread();
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     virtual void execute();
255cdf0e10cSrcweir     virtual void SAL_CALL onTerminated();
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     void _addExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
258cdf0e10cSrcweir                         const OUString &rPackageURL,
259cdf0e10cSrcweir                         const OUString &rRepository,
260cdf0e10cSrcweir                         const bool bWarnUser );
261cdf0e10cSrcweir     void _removeExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
262cdf0e10cSrcweir                            const uno::Reference< deployment::XPackage > &xPackage );
263cdf0e10cSrcweir     void _enableExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
264cdf0e10cSrcweir                            const uno::Reference< deployment::XPackage > &xPackage );
265cdf0e10cSrcweir     void _disableExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
266cdf0e10cSrcweir                             const uno::Reference< deployment::XPackage > &xPackage );
267cdf0e10cSrcweir     void _checkForUpdates( const std::vector<uno::Reference<deployment::XPackage > > &vExtensionList );
268cdf0e10cSrcweir     void _acceptLicense( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
269cdf0e10cSrcweir                            const uno::Reference< deployment::XPackage > &xPackage );
270cdf0e10cSrcweir 
271cdf0e10cSrcweir     enum Input { NONE, START, STOP };
272cdf0e10cSrcweir 
273cdf0e10cSrcweir     uno::Reference< uno::XComponentContext > m_xContext;
274cdf0e10cSrcweir     std::queue< TExtensionCmd >              m_queue;
275cdf0e10cSrcweir 
276cdf0e10cSrcweir     DialogHelper *m_pDialogHelper;
277cdf0e10cSrcweir     TheExtensionManager *m_pManager;
278cdf0e10cSrcweir 
279cdf0e10cSrcweir     const OUString   m_sEnablingPackages;
280cdf0e10cSrcweir     const OUString   m_sDisablingPackages;
281cdf0e10cSrcweir     const OUString   m_sAddingPackages;
282cdf0e10cSrcweir     const OUString   m_sRemovingPackages;
283cdf0e10cSrcweir     const OUString   m_sDefaultCmd;
284cdf0e10cSrcweir     const OUString   m_sAcceptLicense;
285cdf0e10cSrcweir     osl::Condition   m_wakeup;
286cdf0e10cSrcweir     osl::Mutex       m_mutex;
287cdf0e10cSrcweir     Input            m_eInput;
288cdf0e10cSrcweir     bool             m_bTerminated;
289cdf0e10cSrcweir     bool             m_bStopped;
290cdf0e10cSrcweir     bool             m_bWorking;
291cdf0e10cSrcweir };
292cdf0e10cSrcweir 
293cdf0e10cSrcweir //------------------------------------------------------------------------------
294cdf0e10cSrcweir void ProgressCmdEnv::startProgress()
295cdf0e10cSrcweir {
296cdf0e10cSrcweir     m_nCurrentProgress = 0;
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     if ( m_pDialogHelper )
299cdf0e10cSrcweir         m_pDialogHelper->showProgress( true );
300cdf0e10cSrcweir }
301cdf0e10cSrcweir 
302cdf0e10cSrcweir //------------------------------------------------------------------------------
303cdf0e10cSrcweir void ProgressCmdEnv::stopProgress()
304cdf0e10cSrcweir {
305cdf0e10cSrcweir     if ( m_pDialogHelper )
306cdf0e10cSrcweir         m_pDialogHelper->showProgress( false );
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir //------------------------------------------------------------------------------
310cdf0e10cSrcweir void ProgressCmdEnv::progressSection( const OUString &rText,
311cdf0e10cSrcweir                                       const uno::Reference< task::XAbortChannel > &xAbortChannel )
312cdf0e10cSrcweir {
313cdf0e10cSrcweir     m_xAbortChannel = xAbortChannel;
314cdf0e10cSrcweir     if (! m_bAborted)
315cdf0e10cSrcweir     {
316cdf0e10cSrcweir         m_nCurrentProgress = 0;
317cdf0e10cSrcweir         if ( m_pDialogHelper )
318cdf0e10cSrcweir         {
319cdf0e10cSrcweir             m_pDialogHelper->updateProgress( rText, xAbortChannel );
320cdf0e10cSrcweir             m_pDialogHelper->updateProgress( 5 );
321cdf0e10cSrcweir         }
322cdf0e10cSrcweir     }
323cdf0e10cSrcweir }
324cdf0e10cSrcweir 
325cdf0e10cSrcweir //------------------------------------------------------------------------------
326cdf0e10cSrcweir void ProgressCmdEnv::updateProgress()
327cdf0e10cSrcweir {
328cdf0e10cSrcweir     if ( ! m_bAborted )
329cdf0e10cSrcweir     {
330cdf0e10cSrcweir         long nProgress = ((m_nCurrentProgress*5) % 100) + 5;
331cdf0e10cSrcweir         if ( m_pDialogHelper )
332cdf0e10cSrcweir             m_pDialogHelper->updateProgress( nProgress );
333cdf0e10cSrcweir     }
334cdf0e10cSrcweir }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir //------------------------------------------------------------------------------
337cdf0e10cSrcweir ProgressCmdEnv::~ProgressCmdEnv()
338cdf0e10cSrcweir {
339cdf0e10cSrcweir     // TODO: stop all threads and wait
340cdf0e10cSrcweir }
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 
343cdf0e10cSrcweir //------------------------------------------------------------------------------
344cdf0e10cSrcweir // XCommandEnvironment
345cdf0e10cSrcweir //------------------------------------------------------------------------------
346cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > ProgressCmdEnv::getInteractionHandler()
347cdf0e10cSrcweir     throw ( uno::RuntimeException )
348cdf0e10cSrcweir {
349cdf0e10cSrcweir     return this;
350cdf0e10cSrcweir }
351cdf0e10cSrcweir 
352cdf0e10cSrcweir //------------------------------------------------------------------------------
353cdf0e10cSrcweir uno::Reference< ucb::XProgressHandler > ProgressCmdEnv::getProgressHandler()
354cdf0e10cSrcweir     throw ( uno::RuntimeException )
355cdf0e10cSrcweir {
356cdf0e10cSrcweir     return this;
357cdf0e10cSrcweir }
358cdf0e10cSrcweir 
359cdf0e10cSrcweir //------------------------------------------------------------------------------
360cdf0e10cSrcweir // XInteractionHandler
361cdf0e10cSrcweir //------------------------------------------------------------------------------
362cdf0e10cSrcweir void ProgressCmdEnv::handle( uno::Reference< task::XInteractionRequest > const & xRequest )
363cdf0e10cSrcweir     throw ( uno::RuntimeException )
364cdf0e10cSrcweir {
365cdf0e10cSrcweir     uno::Any request( xRequest->getRequest() );
366cdf0e10cSrcweir     OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
367cdf0e10cSrcweir     dp_misc::TRACE( OUSTR("[dp_gui_cmdenv.cxx] incoming request:\n")
368cdf0e10cSrcweir         + ::comphelper::anyToString(request) + OUSTR("\n"));
369cdf0e10cSrcweir 
370cdf0e10cSrcweir     lang::WrappedTargetException wtExc;
371cdf0e10cSrcweir     deployment::DependencyException depExc;
372cdf0e10cSrcweir 	deployment::LicenseException licExc;
373cdf0e10cSrcweir     deployment::VersionException verExc;
374cdf0e10cSrcweir 	deployment::InstallException instExc;
375cdf0e10cSrcweir     deployment::PlatformException platExc;
376cdf0e10cSrcweir 
377cdf0e10cSrcweir     // selections:
378cdf0e10cSrcweir     bool approve = false;
379cdf0e10cSrcweir     bool abort = false;
380cdf0e10cSrcweir 
381cdf0e10cSrcweir     if (request >>= wtExc) {
382cdf0e10cSrcweir         // handable deployment error signalled, e.g.
383cdf0e10cSrcweir         // bundle item registration failed, notify cause only:
384cdf0e10cSrcweir         uno::Any cause;
385cdf0e10cSrcweir         deployment::DeploymentException dpExc;
386cdf0e10cSrcweir         if (wtExc.TargetException >>= dpExc)
387cdf0e10cSrcweir             cause = dpExc.Cause;
388cdf0e10cSrcweir         else {
389cdf0e10cSrcweir             ucb::CommandFailedException cfExc;
390cdf0e10cSrcweir             if (wtExc.TargetException >>= cfExc)
391cdf0e10cSrcweir                 cause = cfExc.Reason;
392cdf0e10cSrcweir             else
393cdf0e10cSrcweir                 cause = wtExc.TargetException;
394cdf0e10cSrcweir         }
395cdf0e10cSrcweir         update_( cause );
396cdf0e10cSrcweir 
397cdf0e10cSrcweir         // ignore intermediate errors of legacy packages, i.e.
398cdf0e10cSrcweir         // former pkgchk behaviour:
399cdf0e10cSrcweir         const uno::Reference< deployment::XPackage > xPackage( wtExc.Context, uno::UNO_QUERY );
400cdf0e10cSrcweir         OSL_ASSERT( xPackage.is() );
401cdf0e10cSrcweir         if ( xPackage.is() )
402cdf0e10cSrcweir         {
403cdf0e10cSrcweir             const uno::Reference< deployment::XPackageTypeInfo > xPackageType( xPackage->getPackageType() );
404cdf0e10cSrcweir             OSL_ASSERT( xPackageType.is() );
405cdf0e10cSrcweir             if (xPackageType.is())
406cdf0e10cSrcweir             {
407cdf0e10cSrcweir                 approve = ( xPackage->isBundle() &&
408cdf0e10cSrcweir                             xPackageType->getMediaType().matchAsciiL(
409cdf0e10cSrcweir                                 RTL_CONSTASCII_STRINGPARAM(
410cdf0e10cSrcweir                                     "application/"
411cdf0e10cSrcweir                                     "vnd.sun.star.legacy-package-bundle") ));
412cdf0e10cSrcweir             }
413cdf0e10cSrcweir         }
414cdf0e10cSrcweir         abort = !approve;
415cdf0e10cSrcweir     }
416cdf0e10cSrcweir     else if (request >>= depExc)
417cdf0e10cSrcweir     {
418cdf0e10cSrcweir         std::vector< rtl::OUString > deps;
419cdf0e10cSrcweir         for (sal_Int32 i = 0; i < depExc.UnsatisfiedDependencies.getLength();
420cdf0e10cSrcweir              ++i)
421cdf0e10cSrcweir         {
422cdf0e10cSrcweir             deps.push_back(
423cdf0e10cSrcweir                 dp_misc::Dependencies::getErrorText( depExc.UnsatisfiedDependencies[i]) );
424cdf0e10cSrcweir         }
425cdf0e10cSrcweir         {
426cdf0e10cSrcweir             vos::OGuard guard(Application::GetSolarMutex());
427cdf0e10cSrcweir             short n = DependencyDialog( m_pDialogHelper? m_pDialogHelper->getWindow() : NULL, deps ).Execute();
428cdf0e10cSrcweir             // Distinguish between closing the dialog and programatically
429cdf0e10cSrcweir             // canceling the dialog (headless VCL):
430cdf0e10cSrcweir             approve = n == RET_OK
431cdf0e10cSrcweir                 || (n == RET_CANCEL && !Application::IsDialogCancelEnabled());
432cdf0e10cSrcweir         }
433cdf0e10cSrcweir     }
434cdf0e10cSrcweir 	else if (request >>= licExc)
435cdf0e10cSrcweir     {
436cdf0e10cSrcweir         uno::Reference< ui::dialogs::XExecutableDialog > xDialog(
437cdf0e10cSrcweir             deployment::ui::LicenseDialog::create(
438cdf0e10cSrcweir             m_xContext, VCLUnoHelper::GetInterface( m_pDialogHelper? m_pDialogHelper->getWindow() : NULL ),
439cdf0e10cSrcweir             licExc.ExtensionName, licExc.Text ) );
440cdf0e10cSrcweir         sal_Int16 res = xDialog->execute();
441cdf0e10cSrcweir         if ( res == ui::dialogs::ExecutableDialogResults::CANCEL )
442cdf0e10cSrcweir             abort = true;
443cdf0e10cSrcweir         else if ( res == ui::dialogs::ExecutableDialogResults::OK )
444cdf0e10cSrcweir             approve = true;
445cdf0e10cSrcweir         else
446cdf0e10cSrcweir         {
447cdf0e10cSrcweir             OSL_ASSERT(0);
448cdf0e10cSrcweir         }
449cdf0e10cSrcweir 	}
450cdf0e10cSrcweir     else if (request >>= verExc)
451cdf0e10cSrcweir     {
452cdf0e10cSrcweir         sal_uInt32 id;
453cdf0e10cSrcweir         switch (dp_misc::compareVersions(
454cdf0e10cSrcweir                     verExc.NewVersion, verExc.Deployed->getVersion() ))
455cdf0e10cSrcweir         {
456cdf0e10cSrcweir         case dp_misc::LESS:
457cdf0e10cSrcweir             id = RID_WARNINGBOX_VERSION_LESS;
458cdf0e10cSrcweir             break;
459cdf0e10cSrcweir         case dp_misc::EQUAL:
460cdf0e10cSrcweir             id = RID_WARNINGBOX_VERSION_EQUAL;
461cdf0e10cSrcweir             break;
462cdf0e10cSrcweir         default: // dp_misc::GREATER
463cdf0e10cSrcweir             id = RID_WARNINGBOX_VERSION_GREATER;
464cdf0e10cSrcweir             break;
465cdf0e10cSrcweir         }
466cdf0e10cSrcweir         OSL_ASSERT( verExc.Deployed.is() );
467cdf0e10cSrcweir         bool bEqualNames = verExc.NewDisplayName.equals(
468cdf0e10cSrcweir             verExc.Deployed->getDisplayName());
469cdf0e10cSrcweir         {
470cdf0e10cSrcweir             vos::OGuard guard(Application::GetSolarMutex());
471cdf0e10cSrcweir             WarningBox box( m_pDialogHelper? m_pDialogHelper->getWindow() : NULL, ResId(id, *DeploymentGuiResMgr::get()));
472cdf0e10cSrcweir             String s;
473cdf0e10cSrcweir             if (bEqualNames)
474cdf0e10cSrcweir             {
475cdf0e10cSrcweir                 s = box.GetMessText();
476cdf0e10cSrcweir             }
477cdf0e10cSrcweir             else if (id == RID_WARNINGBOX_VERSION_EQUAL)
478cdf0e10cSrcweir             {
479cdf0e10cSrcweir                 //hypothetical: requires two instances of an extension with the same
480cdf0e10cSrcweir                 //version to have different display names. Probably the developer forgot
481cdf0e10cSrcweir                 //to change the version.
482cdf0e10cSrcweir                 s = String(ResId(RID_STR_WARNINGBOX_VERSION_EQUAL_DIFFERENT_NAMES, *DeploymentGuiResMgr::get()));
483cdf0e10cSrcweir             }
484cdf0e10cSrcweir             else if (id == RID_WARNINGBOX_VERSION_LESS)
485cdf0e10cSrcweir             {
486cdf0e10cSrcweir                 s = String(ResId(RID_STR_WARNINGBOX_VERSION_LESS_DIFFERENT_NAMES, *DeploymentGuiResMgr::get()));
487cdf0e10cSrcweir             }
488cdf0e10cSrcweir             else if (id == RID_WARNINGBOX_VERSION_GREATER)
489cdf0e10cSrcweir             {
490cdf0e10cSrcweir                s = String(ResId(RID_STR_WARNINGBOX_VERSION_GREATER_DIFFERENT_NAMES, *DeploymentGuiResMgr::get()));
491cdf0e10cSrcweir             }
492cdf0e10cSrcweir             s.SearchAndReplaceAllAscii( "$NAME", verExc.NewDisplayName);
493cdf0e10cSrcweir             s.SearchAndReplaceAllAscii( "$OLDNAME", verExc.Deployed->getDisplayName());
494cdf0e10cSrcweir             s.SearchAndReplaceAllAscii( "$NEW", getVersion(verExc.NewVersion) );
495cdf0e10cSrcweir             s.SearchAndReplaceAllAscii( "$DEPLOYED", getVersion(verExc.Deployed) );
496cdf0e10cSrcweir             box.SetMessText(s);
497cdf0e10cSrcweir             approve = box.Execute() == RET_OK;
498cdf0e10cSrcweir             abort = !approve;
499cdf0e10cSrcweir         }
500cdf0e10cSrcweir     }
501cdf0e10cSrcweir 	else if (request >>= instExc)
502cdf0e10cSrcweir 	{
503cdf0e10cSrcweir         if ( ! m_bWarnUser )
504cdf0e10cSrcweir         {
505cdf0e10cSrcweir             approve = true;
506cdf0e10cSrcweir         }
507cdf0e10cSrcweir         else
508cdf0e10cSrcweir         {
509cdf0e10cSrcweir             if ( m_pDialogHelper )
510cdf0e10cSrcweir             {
511cdf0e10cSrcweir                 vos::OGuard guard(Application::GetSolarMutex());
512cdf0e10cSrcweir 
513cdf0e10cSrcweir                 approve = m_pDialogHelper->installExtensionWarn( instExc.displayName );
514cdf0e10cSrcweir             }
515cdf0e10cSrcweir             else
516cdf0e10cSrcweir                 approve = false;
517cdf0e10cSrcweir             abort = !approve;
518cdf0e10cSrcweir         }
519cdf0e10cSrcweir 	}
520cdf0e10cSrcweir     else if (request >>= platExc)
521cdf0e10cSrcweir     {
522cdf0e10cSrcweir         vos::OGuard guard( Application::GetSolarMutex() );
523cdf0e10cSrcweir         String sMsg( ResId( RID_STR_UNSUPPORTED_PLATFORM, *DeploymentGuiResMgr::get() ) );
524cdf0e10cSrcweir         sMsg.SearchAndReplaceAllAscii( "%Name", platExc.package->getDisplayName() );
525cdf0e10cSrcweir         ErrorBox box( m_pDialogHelper? m_pDialogHelper->getWindow() : NULL, WB_OK, sMsg );
526cdf0e10cSrcweir         box.Execute();
527cdf0e10cSrcweir         approve = true;
528cdf0e10cSrcweir     }
529cdf0e10cSrcweir 
530cdf0e10cSrcweir 	if (approve == false && abort == false)
531cdf0e10cSrcweir     {
532cdf0e10cSrcweir         // forward to UUI handler:
533cdf0e10cSrcweir         if (! m_xHandler.is()) {
534cdf0e10cSrcweir             // late init:
535cdf0e10cSrcweir             uno::Sequence< uno::Any > handlerArgs( 1 );
536cdf0e10cSrcweir             handlerArgs[ 0 ] <<= beans::PropertyValue(
537cdf0e10cSrcweir                 OUSTR("Context"), -1, uno::Any( m_sTitle ),
538cdf0e10cSrcweir                 beans::PropertyState_DIRECT_VALUE );
539cdf0e10cSrcweir              m_xHandler.set( m_xContext->getServiceManager()
540cdf0e10cSrcweir                             ->createInstanceWithArgumentsAndContext(
541cdf0e10cSrcweir                                 OUSTR("com.sun.star.uui.InteractionHandler"),
542cdf0e10cSrcweir                                 handlerArgs, m_xContext ), uno::UNO_QUERY_THROW );
543cdf0e10cSrcweir         }
544cdf0e10cSrcweir         m_xHandler->handle( xRequest );
545cdf0e10cSrcweir     }
546cdf0e10cSrcweir 	else
547cdf0e10cSrcweir 	{
548cdf0e10cSrcweir         // select:
549cdf0e10cSrcweir         uno::Sequence< uno::Reference< task::XInteractionContinuation > > conts(
550cdf0e10cSrcweir             xRequest->getContinuations() );
551cdf0e10cSrcweir         uno::Reference< task::XInteractionContinuation > const * pConts = conts.getConstArray();
552cdf0e10cSrcweir         sal_Int32 len = conts.getLength();
553cdf0e10cSrcweir         for ( sal_Int32 pos = 0; pos < len; ++pos )
554cdf0e10cSrcweir         {
555cdf0e10cSrcweir             if (approve) {
556cdf0e10cSrcweir                 uno::Reference< task::XInteractionApprove > xInteractionApprove( pConts[ pos ], uno::UNO_QUERY );
557cdf0e10cSrcweir                 if (xInteractionApprove.is()) {
558cdf0e10cSrcweir                     xInteractionApprove->select();
559cdf0e10cSrcweir                     // don't query again for ongoing continuations:
560cdf0e10cSrcweir                     approve = false;
561cdf0e10cSrcweir                 }
562cdf0e10cSrcweir             }
563cdf0e10cSrcweir             else if (abort) {
564cdf0e10cSrcweir                 uno::Reference< task::XInteractionAbort > xInteractionAbort( pConts[ pos ], uno::UNO_QUERY );
565cdf0e10cSrcweir                 if (xInteractionAbort.is()) {
566cdf0e10cSrcweir                     xInteractionAbort->select();
567cdf0e10cSrcweir                     // don't query again for ongoing continuations:
568cdf0e10cSrcweir                     abort = false;
569cdf0e10cSrcweir                 }
570cdf0e10cSrcweir             }
571cdf0e10cSrcweir         }
572cdf0e10cSrcweir 	}
573cdf0e10cSrcweir }
574cdf0e10cSrcweir 
575cdf0e10cSrcweir //------------------------------------------------------------------------------
576cdf0e10cSrcweir // XProgressHandler
577cdf0e10cSrcweir //------------------------------------------------------------------------------
578cdf0e10cSrcweir void ProgressCmdEnv::push( uno::Any const & rStatus )
579cdf0e10cSrcweir     throw( uno::RuntimeException )
580cdf0e10cSrcweir {
581cdf0e10cSrcweir     update_( rStatus );
582cdf0e10cSrcweir }
583cdf0e10cSrcweir 
584cdf0e10cSrcweir //------------------------------------------------------------------------------
585cdf0e10cSrcweir void ProgressCmdEnv::update_( uno::Any const & rStatus )
586cdf0e10cSrcweir     throw( uno::RuntimeException )
587cdf0e10cSrcweir {
588cdf0e10cSrcweir     OUString text;
589cdf0e10cSrcweir     if ( rStatus.hasValue() && !( rStatus >>= text) )
590cdf0e10cSrcweir     {
591cdf0e10cSrcweir         if ( rStatus.getValueTypeClass() == uno::TypeClass_EXCEPTION )
592cdf0e10cSrcweir             text = static_cast< uno::Exception const *>( rStatus.getValue() )->Message;
593cdf0e10cSrcweir         if ( text.getLength() == 0 )
594cdf0e10cSrcweir             text = ::comphelper::anyToString( rStatus ); // fallback
595cdf0e10cSrcweir 
596cdf0e10cSrcweir         const ::vos::OGuard aGuard( Application::GetSolarMutex() );
597cdf0e10cSrcweir         const ::std::auto_ptr< ErrorBox > aBox( new ErrorBox( m_pDialogHelper? m_pDialogHelper->getWindow() : NULL, WB_OK, text ) );
598cdf0e10cSrcweir         aBox->Execute();
599cdf0e10cSrcweir     }
600cdf0e10cSrcweir     ++m_nCurrentProgress;
601cdf0e10cSrcweir     updateProgress();
602cdf0e10cSrcweir }
603cdf0e10cSrcweir 
604cdf0e10cSrcweir //------------------------------------------------------------------------------
605cdf0e10cSrcweir void ProgressCmdEnv::update( uno::Any const & rStatus )
606cdf0e10cSrcweir     throw( uno::RuntimeException )
607cdf0e10cSrcweir {
608cdf0e10cSrcweir     update_( rStatus );
609cdf0e10cSrcweir }
610cdf0e10cSrcweir 
611cdf0e10cSrcweir //------------------------------------------------------------------------------
612cdf0e10cSrcweir void ProgressCmdEnv::pop()
613cdf0e10cSrcweir     throw( uno::RuntimeException )
614cdf0e10cSrcweir {
615cdf0e10cSrcweir     update_( uno::Any() ); // no message
616cdf0e10cSrcweir }
617cdf0e10cSrcweir 
618cdf0e10cSrcweir //------------------------------------------------------------------------------
619cdf0e10cSrcweir ExtensionCmdQueue::Thread::Thread( DialogHelper *pDialogHelper,
620cdf0e10cSrcweir                                    TheExtensionManager *pManager,
621cdf0e10cSrcweir                                    const uno::Reference< uno::XComponentContext > & rContext ) :
622cdf0e10cSrcweir     m_xContext( rContext ),
623cdf0e10cSrcweir     m_pDialogHelper( pDialogHelper ),
624cdf0e10cSrcweir     m_pManager( pManager ),
625cdf0e10cSrcweir     m_sEnablingPackages( DialogHelper::getResourceString( RID_STR_ENABLING_PACKAGES ) ),
626cdf0e10cSrcweir     m_sDisablingPackages( DialogHelper::getResourceString( RID_STR_DISABLING_PACKAGES ) ),
627cdf0e10cSrcweir     m_sAddingPackages( DialogHelper::getResourceString( RID_STR_ADDING_PACKAGES ) ),
628cdf0e10cSrcweir     m_sRemovingPackages( DialogHelper::getResourceString( RID_STR_REMOVING_PACKAGES ) ),
629cdf0e10cSrcweir     m_sDefaultCmd( DialogHelper::getResourceString( RID_STR_ADD_PACKAGES ) ),
630cdf0e10cSrcweir     m_sAcceptLicense( DialogHelper::getResourceString( RID_STR_ACCEPT_LICENSE ) ),
631cdf0e10cSrcweir     m_eInput( NONE ),
632cdf0e10cSrcweir     m_bTerminated( false ),
633cdf0e10cSrcweir     m_bStopped( false ),
634cdf0e10cSrcweir     m_bWorking( false )
635cdf0e10cSrcweir {
636cdf0e10cSrcweir     OSL_ASSERT( pDialogHelper );
637cdf0e10cSrcweir }
638cdf0e10cSrcweir 
639cdf0e10cSrcweir //------------------------------------------------------------------------------
640cdf0e10cSrcweir void ExtensionCmdQueue::Thread::addExtension( const ::rtl::OUString &rExtensionURL,
641cdf0e10cSrcweir                                               const ::rtl::OUString &rRepository,
642cdf0e10cSrcweir                                               const bool bWarnUser )
643cdf0e10cSrcweir {
644cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_mutex );
645cdf0e10cSrcweir 
646cdf0e10cSrcweir     //If someone called stop then we do not add the extension -> game over!
647cdf0e10cSrcweir     if ( m_bStopped )
648cdf0e10cSrcweir         return;
649cdf0e10cSrcweir 
650cdf0e10cSrcweir     if ( rExtensionURL.getLength() )
651cdf0e10cSrcweir     {
652cdf0e10cSrcweir         TExtensionCmd pEntry( new ExtensionCmd( ExtensionCmd::ADD, rExtensionURL, rRepository, bWarnUser ) );
653cdf0e10cSrcweir 
654cdf0e10cSrcweir         m_queue.push( pEntry );
655cdf0e10cSrcweir         m_eInput = START;
656cdf0e10cSrcweir         m_wakeup.set();
657cdf0e10cSrcweir     }
658cdf0e10cSrcweir }
659cdf0e10cSrcweir 
660cdf0e10cSrcweir //------------------------------------------------------------------------------
661cdf0e10cSrcweir void ExtensionCmdQueue::Thread::removeExtension( const uno::Reference< deployment::XPackage > &rPackage )
662cdf0e10cSrcweir {
663cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_mutex );
664cdf0e10cSrcweir 
665cdf0e10cSrcweir     //If someone called stop then we do not remove the extension -> game over!
666cdf0e10cSrcweir     if ( m_bStopped )
667cdf0e10cSrcweir         return;
668cdf0e10cSrcweir 
669cdf0e10cSrcweir     if ( rPackage.is() )
670cdf0e10cSrcweir     {
671cdf0e10cSrcweir         TExtensionCmd pEntry( new ExtensionCmd( ExtensionCmd::REMOVE, rPackage ) );
672cdf0e10cSrcweir 
673cdf0e10cSrcweir         m_queue.push( pEntry );
674cdf0e10cSrcweir         m_eInput = START;
675cdf0e10cSrcweir         m_wakeup.set();
676cdf0e10cSrcweir     }
677cdf0e10cSrcweir }
678cdf0e10cSrcweir 
679cdf0e10cSrcweir //------------------------------------------------------------------------------
680cdf0e10cSrcweir void ExtensionCmdQueue::Thread::acceptLicense( const uno::Reference< deployment::XPackage > &rPackage )
681cdf0e10cSrcweir {
682cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_mutex );
683cdf0e10cSrcweir 
684cdf0e10cSrcweir     //If someone called stop then we do not remove the extension -> game over!
685cdf0e10cSrcweir     if ( m_bStopped )
686cdf0e10cSrcweir         return;
687cdf0e10cSrcweir 
688cdf0e10cSrcweir     if ( rPackage.is() )
689cdf0e10cSrcweir     {
690cdf0e10cSrcweir         TExtensionCmd pEntry( new ExtensionCmd( ExtensionCmd::ACCEPT_LICENSE, rPackage ) );
691cdf0e10cSrcweir 
692cdf0e10cSrcweir         m_queue.push( pEntry );
693cdf0e10cSrcweir         m_eInput = START;
694cdf0e10cSrcweir         m_wakeup.set();
695cdf0e10cSrcweir     }
696cdf0e10cSrcweir }
697cdf0e10cSrcweir 
698cdf0e10cSrcweir //------------------------------------------------------------------------------
699cdf0e10cSrcweir void ExtensionCmdQueue::Thread::enableExtension( const uno::Reference< deployment::XPackage > &rPackage,
700cdf0e10cSrcweir                                                  const bool bEnable )
701cdf0e10cSrcweir {
702cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_mutex );
703cdf0e10cSrcweir 
704cdf0e10cSrcweir     //If someone called stop then we do not remove the extension -> game over!
705cdf0e10cSrcweir     if ( m_bStopped )
706cdf0e10cSrcweir         return;
707cdf0e10cSrcweir 
708cdf0e10cSrcweir     if ( rPackage.is() )
709cdf0e10cSrcweir     {
710cdf0e10cSrcweir         TExtensionCmd pEntry( new ExtensionCmd( bEnable ? ExtensionCmd::ENABLE :
711cdf0e10cSrcweir                                                           ExtensionCmd::DISABLE,
712cdf0e10cSrcweir                                                 rPackage ) );
713cdf0e10cSrcweir         m_queue.push( pEntry );
714cdf0e10cSrcweir         m_eInput = START;
715cdf0e10cSrcweir         m_wakeup.set();
716cdf0e10cSrcweir     }
717cdf0e10cSrcweir }
718cdf0e10cSrcweir 
719cdf0e10cSrcweir //------------------------------------------------------------------------------
720cdf0e10cSrcweir void ExtensionCmdQueue::Thread::checkForUpdates(
721cdf0e10cSrcweir     const std::vector<uno::Reference<deployment::XPackage > > &vExtensionList )
722cdf0e10cSrcweir {
723cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_mutex );
724cdf0e10cSrcweir 
725cdf0e10cSrcweir     //If someone called stop then we do not update the extension -> game over!
726cdf0e10cSrcweir     if ( m_bStopped )
727cdf0e10cSrcweir         return;
728cdf0e10cSrcweir 
729cdf0e10cSrcweir     TExtensionCmd pEntry( new ExtensionCmd( ExtensionCmd::CHECK_FOR_UPDATES, vExtensionList ) );
730cdf0e10cSrcweir     m_queue.push( pEntry );
731cdf0e10cSrcweir     m_eInput = START;
732cdf0e10cSrcweir     m_wakeup.set();
733cdf0e10cSrcweir }
734cdf0e10cSrcweir 
735cdf0e10cSrcweir //------------------------------------------------------------------------------
736cdf0e10cSrcweir //Stopping this thread will not abort the installation of extensions.
737cdf0e10cSrcweir void ExtensionCmdQueue::Thread::stop()
738cdf0e10cSrcweir {
739cdf0e10cSrcweir     osl::MutexGuard aGuard( m_mutex );
740cdf0e10cSrcweir     m_bStopped = true;
741cdf0e10cSrcweir     m_eInput = STOP;
742cdf0e10cSrcweir     m_wakeup.set();
743cdf0e10cSrcweir }
744cdf0e10cSrcweir 
745cdf0e10cSrcweir //------------------------------------------------------------------------------
746cdf0e10cSrcweir bool ExtensionCmdQueue::Thread::isBusy()
747cdf0e10cSrcweir {
748cdf0e10cSrcweir     osl::MutexGuard aGuard( m_mutex );
749cdf0e10cSrcweir     return m_bWorking;
750cdf0e10cSrcweir }
751cdf0e10cSrcweir 
752cdf0e10cSrcweir //------------------------------------------------------------------------------
753cdf0e10cSrcweir ExtensionCmdQueue::Thread::~Thread() {}
754cdf0e10cSrcweir 
755cdf0e10cSrcweir //------------------------------------------------------------------------------
756cdf0e10cSrcweir void ExtensionCmdQueue::Thread::execute()
757cdf0e10cSrcweir {
758cdf0e10cSrcweir #ifdef WNT
759cdf0e10cSrcweir     //Needed for use of the service "com.sun.star.system.SystemShellExecute" in
760cdf0e10cSrcweir     //DialogHelper::openWebBrowser
761cdf0e10cSrcweir     CoUninitialize();
762cdf0e10cSrcweir     HRESULT r = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
763cdf0e10cSrcweir #endif
764cdf0e10cSrcweir     for (;;)
765cdf0e10cSrcweir     {
766cdf0e10cSrcweir         if ( m_wakeup.wait() != osl::Condition::result_ok )
767cdf0e10cSrcweir         {
768cdf0e10cSrcweir             dp_misc::TRACE( "dp_gui::ExtensionCmdQueue::Thread::run: ignored "
769cdf0e10cSrcweir                        "osl::Condition::wait failure\n" );
770cdf0e10cSrcweir         }
771cdf0e10cSrcweir         m_wakeup.reset();
772cdf0e10cSrcweir 
773cdf0e10cSrcweir         int nSize;
774cdf0e10cSrcweir         Input eInput;
775cdf0e10cSrcweir         {
776cdf0e10cSrcweir             osl::MutexGuard aGuard( m_mutex );
777cdf0e10cSrcweir             eInput = m_eInput;
778cdf0e10cSrcweir             m_eInput = NONE;
779cdf0e10cSrcweir             nSize = m_queue.size();
780cdf0e10cSrcweir             m_bWorking = false;
781cdf0e10cSrcweir         }
782cdf0e10cSrcweir 
783cdf0e10cSrcweir         // If this thread has been woken up by anything else except start, stop
784cdf0e10cSrcweir         // then input is NONE and we wait again.
785cdf0e10cSrcweir         // We only install the extension which are currently in the queue.
786cdf0e10cSrcweir         // The progressbar will be set to show the progress of the current number
787cdf0e10cSrcweir         // of extensions. If we allowed to add extensions now then the progressbar may
788cdf0e10cSrcweir         // have reached the end while we still install newly added extensions.
789cdf0e10cSrcweir         if ( ( eInput == NONE ) || ( nSize == 0 ) )
790cdf0e10cSrcweir             continue;
791cdf0e10cSrcweir         if ( eInput == STOP )
792cdf0e10cSrcweir             break;
793cdf0e10cSrcweir 
794cdf0e10cSrcweir         ::rtl::Reference< ProgressCmdEnv > currentCmdEnv( new ProgressCmdEnv( m_xContext, m_pDialogHelper, m_sDefaultCmd ) );
795cdf0e10cSrcweir 
796cdf0e10cSrcweir         // Do not lock the following part with addExtension. addExtension may be called in the main thread.
797cdf0e10cSrcweir         // If the message box "Do you want to install the extension (or similar)" is shown and then
798cdf0e10cSrcweir         // addExtension is called, which then blocks the main thread, then we deadlock.
799cdf0e10cSrcweir         bool bStartProgress = true;
800cdf0e10cSrcweir 
801cdf0e10cSrcweir         while ( !currentCmdEnv->isAborted() && --nSize >= 0 )
802cdf0e10cSrcweir         {
803cdf0e10cSrcweir             {
804cdf0e10cSrcweir                 osl::MutexGuard aGuard( m_mutex );
805cdf0e10cSrcweir                 m_bWorking = true;
806cdf0e10cSrcweir             }
807cdf0e10cSrcweir 
808cdf0e10cSrcweir             try
809cdf0e10cSrcweir             {
810cdf0e10cSrcweir                 TExtensionCmd pEntry;
811cdf0e10cSrcweir                 {
812cdf0e10cSrcweir                     ::osl::MutexGuard queueGuard( m_mutex );
813cdf0e10cSrcweir                     pEntry = m_queue.front();
814cdf0e10cSrcweir                     m_queue.pop();
815cdf0e10cSrcweir                 }
816cdf0e10cSrcweir 
817cdf0e10cSrcweir                 if ( bStartProgress && ( pEntry->m_eCmdType != ExtensionCmd::CHECK_FOR_UPDATES ) )
818cdf0e10cSrcweir                 {
819cdf0e10cSrcweir                     currentCmdEnv->startProgress();
820cdf0e10cSrcweir                     bStartProgress = false;
821cdf0e10cSrcweir                 }
822cdf0e10cSrcweir 
823cdf0e10cSrcweir                 switch ( pEntry->m_eCmdType ) {
824cdf0e10cSrcweir                 case ExtensionCmd::ADD :
825cdf0e10cSrcweir                     _addExtension( currentCmdEnv, pEntry->m_sExtensionURL, pEntry->m_sRepository, pEntry->m_bWarnUser );
826cdf0e10cSrcweir                     break;
827cdf0e10cSrcweir                 case ExtensionCmd::REMOVE :
828cdf0e10cSrcweir                     _removeExtension( currentCmdEnv, pEntry->m_xPackage );
829cdf0e10cSrcweir                     break;
830cdf0e10cSrcweir                 case ExtensionCmd::ENABLE :
831cdf0e10cSrcweir                     _enableExtension( currentCmdEnv, pEntry->m_xPackage );
832cdf0e10cSrcweir                     break;
833cdf0e10cSrcweir                 case ExtensionCmd::DISABLE :
834cdf0e10cSrcweir                     _disableExtension( currentCmdEnv, pEntry->m_xPackage );
835cdf0e10cSrcweir                     break;
836cdf0e10cSrcweir                 case ExtensionCmd::CHECK_FOR_UPDATES :
837cdf0e10cSrcweir                     _checkForUpdates( pEntry->m_vExtensionList );
838cdf0e10cSrcweir                     break;
839cdf0e10cSrcweir                 case ExtensionCmd::ACCEPT_LICENSE :
840cdf0e10cSrcweir                     _acceptLicense( currentCmdEnv, pEntry->m_xPackage );
841cdf0e10cSrcweir                     break;
842cdf0e10cSrcweir                 }
843cdf0e10cSrcweir             }
844cdf0e10cSrcweir             //catch ( deployment::DeploymentException &)
845cdf0e10cSrcweir             //{
846cdf0e10cSrcweir             //}
847cdf0e10cSrcweir             //catch ( lang::IllegalArgumentException &)
848cdf0e10cSrcweir             //{
849cdf0e10cSrcweir             //}
850cdf0e10cSrcweir             catch ( ucb::CommandAbortedException & )
851cdf0e10cSrcweir             {
852cdf0e10cSrcweir                 //This exception is thrown when the user clicks cancel on the progressbar.
853cdf0e10cSrcweir                 //Then we cancel the installation of all extensions and remove them from
854cdf0e10cSrcweir                 //the queue.
855cdf0e10cSrcweir                 {
856cdf0e10cSrcweir                     ::osl::MutexGuard queueGuard2(m_mutex);
857cdf0e10cSrcweir                     while ( --nSize >= 0 )
858cdf0e10cSrcweir                         m_queue.pop();
859cdf0e10cSrcweir                 }
860cdf0e10cSrcweir                 break;
861cdf0e10cSrcweir             }
862cdf0e10cSrcweir             catch ( ucb::CommandFailedException & )
863cdf0e10cSrcweir             {
864cdf0e10cSrcweir                 //This exception is thrown when a user clicked cancel in the messagebox which was
865cdf0e10cSrcweir                 //startet by the interaction handler. For example the user will be asked if he/she
866cdf0e10cSrcweir                 //really wants to install the extension.
867cdf0e10cSrcweir                 //These interaction are run for exectly one extension at a time. Therefore we continue
868cdf0e10cSrcweir                 //with installing the remaining extensions.
869cdf0e10cSrcweir                 continue;
870cdf0e10cSrcweir             }
871cdf0e10cSrcweir             catch ( uno::Exception & )
872cdf0e10cSrcweir             {
873cdf0e10cSrcweir                 //Todo display the user an error
874cdf0e10cSrcweir                 //see also DialogImpl::SyncPushButton::Click()
875cdf0e10cSrcweir                 uno::Any exc( ::cppu::getCaughtException() );
876cdf0e10cSrcweir                 OUString msg;
877cdf0e10cSrcweir                 deployment::DeploymentException dpExc;
878cdf0e10cSrcweir                 if ((exc >>= dpExc) &&
879cdf0e10cSrcweir                     dpExc.Cause.getValueTypeClass() == uno::TypeClass_EXCEPTION)
880cdf0e10cSrcweir                 {
881cdf0e10cSrcweir                     // notify error cause only:
882cdf0e10cSrcweir                     msg = reinterpret_cast< uno::Exception const * >( dpExc.Cause.getValue() )->Message;
883cdf0e10cSrcweir                 }
884cdf0e10cSrcweir                 if (msg.getLength() == 0) // fallback for debugging purposes
885cdf0e10cSrcweir                     msg = ::comphelper::anyToString(exc);
886cdf0e10cSrcweir 
887cdf0e10cSrcweir                 const ::vos::OGuard guard( Application::GetSolarMutex() );
888cdf0e10cSrcweir                 ::std::auto_ptr<ErrorBox> box(
889cdf0e10cSrcweir                     new ErrorBox( currentCmdEnv->activeDialog(), WB_OK, msg ) );
890cdf0e10cSrcweir                 if ( m_pDialogHelper )
891cdf0e10cSrcweir                     box->SetText( m_pDialogHelper->getWindow()->GetText() );
892cdf0e10cSrcweir                 box->Execute();
893cdf0e10cSrcweir                     //Continue with installation of the remaining extensions
894cdf0e10cSrcweir             }
895cdf0e10cSrcweir             {
896cdf0e10cSrcweir                 osl::MutexGuard aGuard( m_mutex );
897cdf0e10cSrcweir                 m_bWorking = false;
898cdf0e10cSrcweir             }
899cdf0e10cSrcweir         }
900cdf0e10cSrcweir 
901cdf0e10cSrcweir         {
902cdf0e10cSrcweir             // when leaving the while loop with break, we should set working to false, too
903cdf0e10cSrcweir 			osl::MutexGuard aGuard( m_mutex );
904cdf0e10cSrcweir             m_bWorking = false;
905cdf0e10cSrcweir         }
906cdf0e10cSrcweir 
907cdf0e10cSrcweir 		if ( !bStartProgress )
908cdf0e10cSrcweir             currentCmdEnv->stopProgress();
909cdf0e10cSrcweir     }
910cdf0e10cSrcweir     //end for
911cdf0e10cSrcweir     //enable all buttons
912cdf0e10cSrcweir //     m_pDialog->m_bAddingExtensions = false;
913cdf0e10cSrcweir //     m_pDialog->updateButtonStates();
914cdf0e10cSrcweir #ifdef WNT
915cdf0e10cSrcweir     CoUninitialize();
916cdf0e10cSrcweir #endif
917cdf0e10cSrcweir }
918cdf0e10cSrcweir 
919cdf0e10cSrcweir //------------------------------------------------------------------------------
920cdf0e10cSrcweir void ExtensionCmdQueue::Thread::_addExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
921cdf0e10cSrcweir                                                const OUString &rPackageURL,
922cdf0e10cSrcweir                                                const OUString &rRepository,
923cdf0e10cSrcweir                                                const bool bWarnUser )
924cdf0e10cSrcweir {
925cdf0e10cSrcweir     //check if we have a string in anyTitle. For example "unopkg gui \" caused anyTitle to be void
926cdf0e10cSrcweir     //and anyTitle.get<OUString> throws as RuntimeException.
927cdf0e10cSrcweir     uno::Any anyTitle;
928cdf0e10cSrcweir 	try
929cdf0e10cSrcweir 	{
930cdf0e10cSrcweir 		anyTitle = ::ucbhelper::Content( rPackageURL, rCmdEnv.get() ).getPropertyValue( OUSTR("Title") );
931cdf0e10cSrcweir 	}
932cdf0e10cSrcweir 	catch ( uno::Exception & )
933cdf0e10cSrcweir 	{
934cdf0e10cSrcweir 		return;
935cdf0e10cSrcweir 	}
936cdf0e10cSrcweir 
937cdf0e10cSrcweir     OUString sName;
938cdf0e10cSrcweir     if ( ! (anyTitle >>= sName) )
939cdf0e10cSrcweir     {
940cdf0e10cSrcweir         OSL_ENSURE(0, "Could not get file name for extension.");
941cdf0e10cSrcweir         return;
942cdf0e10cSrcweir     }
943cdf0e10cSrcweir 
944cdf0e10cSrcweir     rCmdEnv->setWarnUser( bWarnUser );
945cdf0e10cSrcweir     uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager();
946cdf0e10cSrcweir     uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() );
947cdf0e10cSrcweir     OUString sTitle = searchAndReplaceAll( m_sAddingPackages, OUSTR("%EXTENSION_NAME"), sName );
948cdf0e10cSrcweir     rCmdEnv->progressSection( sTitle, xAbortChannel );
949cdf0e10cSrcweir 
950cdf0e10cSrcweir     try
951cdf0e10cSrcweir     {
952cdf0e10cSrcweir 		xExtMgr->addExtension(rPackageURL, uno::Sequence<beans::NamedValue>(),
953cdf0e10cSrcweir                               rRepository, xAbortChannel, rCmdEnv.get() );
954cdf0e10cSrcweir     }
955cdf0e10cSrcweir     catch ( ucb::CommandFailedException & )
956cdf0e10cSrcweir     {
957cdf0e10cSrcweir         // When the extension is already installed we'll get a dialog asking if we want to overwrite. If we then press
958cdf0e10cSrcweir         // cancel this exception is thrown.
959cdf0e10cSrcweir     }
960cdf0e10cSrcweir     catch ( ucb::CommandAbortedException & )
961cdf0e10cSrcweir     {
962cdf0e10cSrcweir         // User clicked the cancel button
963cdf0e10cSrcweir         // TODO: handle cancel
964cdf0e10cSrcweir     }
965cdf0e10cSrcweir     rCmdEnv->setWarnUser( false );
966cdf0e10cSrcweir }
967cdf0e10cSrcweir 
968cdf0e10cSrcweir //------------------------------------------------------------------------------
969cdf0e10cSrcweir void ExtensionCmdQueue::Thread::_removeExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
970cdf0e10cSrcweir                                                   const uno::Reference< deployment::XPackage > &xPackage )
971cdf0e10cSrcweir {
972cdf0e10cSrcweir     uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager();
973cdf0e10cSrcweir     uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() );
974cdf0e10cSrcweir     OUString sTitle = searchAndReplaceAll( m_sRemovingPackages, OUSTR("%EXTENSION_NAME"), xPackage->getDisplayName() );
975cdf0e10cSrcweir     rCmdEnv->progressSection( sTitle, xAbortChannel );
976cdf0e10cSrcweir 
977cdf0e10cSrcweir     OUString id( dp_misc::getIdentifier( xPackage ) );
978cdf0e10cSrcweir     try
979cdf0e10cSrcweir     {
980cdf0e10cSrcweir         xExtMgr->removeExtension( id, xPackage->getName(), xPackage->getRepositoryName(), xAbortChannel, rCmdEnv.get() );
981cdf0e10cSrcweir     }
982cdf0e10cSrcweir     catch ( deployment::DeploymentException & )
983cdf0e10cSrcweir     {}
984cdf0e10cSrcweir     catch ( ucb::CommandFailedException & )
985cdf0e10cSrcweir     {}
986cdf0e10cSrcweir     catch ( ucb::CommandAbortedException & )
987cdf0e10cSrcweir     {}
988cdf0e10cSrcweir 
989cdf0e10cSrcweir     // Check, if there are still updates to be notified via menu bar icon
990cdf0e10cSrcweir     uno::Sequence< uno::Sequence< rtl::OUString > > aItemList;
991cdf0e10cSrcweir     UpdateDialog::createNotifyJob( false, aItemList );
992cdf0e10cSrcweir }
993cdf0e10cSrcweir 
994cdf0e10cSrcweir //------------------------------------------------------------------------------
995cdf0e10cSrcweir void ExtensionCmdQueue::Thread::_checkForUpdates(
996cdf0e10cSrcweir     const std::vector<uno::Reference<deployment::XPackage > > &vExtensionList )
997cdf0e10cSrcweir {
998cdf0e10cSrcweir     UpdateDialog* pUpdateDialog;
999cdf0e10cSrcweir     std::vector< UpdateData > vData;
1000cdf0e10cSrcweir 
1001cdf0e10cSrcweir     const ::vos::OGuard guard( Application::GetSolarMutex() );
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir     pUpdateDialog = new UpdateDialog( m_xContext, m_pDialogHelper? m_pDialogHelper->getWindow() : NULL, vExtensionList, &vData );
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir     pUpdateDialog->notifyMenubar( true, false ); // prepare the checking, if there updates to be notified via menu bar icon
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir     if ( ( pUpdateDialog->Execute() == RET_OK ) && !vData.empty() )
1008cdf0e10cSrcweir     {
1009cdf0e10cSrcweir         // If there is at least one directly downloadable dialog then we
1010cdf0e10cSrcweir         // open the install dialog.
1011cdf0e10cSrcweir         ::std::vector< UpdateData > dataDownload;
1012cdf0e10cSrcweir         int countWebsiteDownload = 0;
1013cdf0e10cSrcweir         typedef std::vector< dp_gui::UpdateData >::const_iterator cit;
1014cdf0e10cSrcweir 
1015cdf0e10cSrcweir         for ( cit i = vData.begin(); i < vData.end(); i++ )
1016cdf0e10cSrcweir         {
1017cdf0e10cSrcweir             if ( i->sWebsiteURL.getLength() > 0 )
1018cdf0e10cSrcweir                 countWebsiteDownload ++;
1019cdf0e10cSrcweir             else
1020cdf0e10cSrcweir                 dataDownload.push_back( *i );
1021cdf0e10cSrcweir         }
1022cdf0e10cSrcweir 
1023cdf0e10cSrcweir         short nDialogResult = RET_OK;
1024cdf0e10cSrcweir         if ( !dataDownload.empty() )
1025cdf0e10cSrcweir         {
1026cdf0e10cSrcweir             nDialogResult = UpdateInstallDialog( m_pDialogHelper? m_pDialogHelper->getWindow() : NULL, dataDownload, m_xContext ).Execute();
1027cdf0e10cSrcweir             pUpdateDialog->notifyMenubar( false, true ); // Check, if there are still pending updates to be notified via menu bar icon
1028cdf0e10cSrcweir         }
1029cdf0e10cSrcweir         else
1030cdf0e10cSrcweir             pUpdateDialog->notifyMenubar( false, false ); // Check, if there are pending updates to be notified via menu bar icon
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir         //Now start the webbrowser and navigate to the websites where we get the updates
1033cdf0e10cSrcweir         if ( RET_OK == nDialogResult )
1034cdf0e10cSrcweir         {
1035cdf0e10cSrcweir             for ( cit i = vData.begin(); i < vData.end(); i++ )
1036cdf0e10cSrcweir             {
1037cdf0e10cSrcweir                 if ( m_pDialogHelper && ( i->sWebsiteURL.getLength() > 0 ) )
1038cdf0e10cSrcweir                     m_pDialogHelper->openWebBrowser( i->sWebsiteURL, m_pDialogHelper->getWindow()->GetText() );
1039cdf0e10cSrcweir             }
1040cdf0e10cSrcweir         }
1041cdf0e10cSrcweir     }
1042cdf0e10cSrcweir     else
1043cdf0e10cSrcweir         pUpdateDialog->notifyMenubar( false, false ); // check if there updates to be notified via menu bar icon
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir     delete pUpdateDialog;
1046cdf0e10cSrcweir }
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir //------------------------------------------------------------------------------
1049cdf0e10cSrcweir void ExtensionCmdQueue::Thread::_enableExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
1050cdf0e10cSrcweir                                                   const uno::Reference< deployment::XPackage > &xPackage )
1051cdf0e10cSrcweir {
1052cdf0e10cSrcweir     if ( !xPackage.is() )
1053cdf0e10cSrcweir         return;
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir     uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager();
1056cdf0e10cSrcweir     uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() );
1057cdf0e10cSrcweir     OUString sTitle = searchAndReplaceAll( m_sEnablingPackages, OUSTR("%EXTENSION_NAME"), xPackage->getDisplayName() );
1058cdf0e10cSrcweir     rCmdEnv->progressSection( sTitle, xAbortChannel );
1059cdf0e10cSrcweir 
1060cdf0e10cSrcweir     try
1061cdf0e10cSrcweir     {
1062cdf0e10cSrcweir         xExtMgr->enableExtension( xPackage, xAbortChannel, rCmdEnv.get() );
1063cdf0e10cSrcweir         if ( m_pDialogHelper )
1064cdf0e10cSrcweir             m_pDialogHelper->updatePackageInfo( xPackage );
1065cdf0e10cSrcweir     }
1066cdf0e10cSrcweir     catch ( ::ucb::CommandAbortedException & )
1067cdf0e10cSrcweir     {}
1068cdf0e10cSrcweir }
1069cdf0e10cSrcweir 
1070cdf0e10cSrcweir //------------------------------------------------------------------------------
1071cdf0e10cSrcweir void ExtensionCmdQueue::Thread::_disableExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
1072cdf0e10cSrcweir                                                    const uno::Reference< deployment::XPackage > &xPackage )
1073cdf0e10cSrcweir {
1074cdf0e10cSrcweir     if ( !xPackage.is() )
1075cdf0e10cSrcweir         return;
1076cdf0e10cSrcweir 
1077cdf0e10cSrcweir     uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager();
1078cdf0e10cSrcweir     uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() );
1079cdf0e10cSrcweir     OUString sTitle = searchAndReplaceAll( m_sDisablingPackages, OUSTR("%EXTENSION_NAME"), xPackage->getDisplayName() );
1080cdf0e10cSrcweir     rCmdEnv->progressSection( sTitle, xAbortChannel );
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir     try
1083cdf0e10cSrcweir     {
1084cdf0e10cSrcweir         xExtMgr->disableExtension( xPackage, xAbortChannel, rCmdEnv.get() );
1085cdf0e10cSrcweir         if ( m_pDialogHelper )
1086cdf0e10cSrcweir             m_pDialogHelper->updatePackageInfo( xPackage );
1087cdf0e10cSrcweir     }
1088cdf0e10cSrcweir     catch ( ::ucb::CommandAbortedException & )
1089cdf0e10cSrcweir     {}
1090cdf0e10cSrcweir }
1091cdf0e10cSrcweir 
1092cdf0e10cSrcweir //------------------------------------------------------------------------------
1093cdf0e10cSrcweir void ExtensionCmdQueue::Thread::_acceptLicense( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
1094cdf0e10cSrcweir                                                 const uno::Reference< deployment::XPackage > &xPackage )
1095cdf0e10cSrcweir {
1096cdf0e10cSrcweir     if ( !xPackage.is() )
1097cdf0e10cSrcweir         return;
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir     uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager();
1100cdf0e10cSrcweir     uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() );
1101cdf0e10cSrcweir     OUString sTitle = searchAndReplaceAll( m_sAcceptLicense, OUSTR("%EXTENSION_NAME"), xPackage->getDisplayName() );
1102cdf0e10cSrcweir     rCmdEnv->progressSection( sTitle, xAbortChannel );
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir     try
1105cdf0e10cSrcweir     {
1106cdf0e10cSrcweir         xExtMgr->checkPrerequisitesAndEnable( xPackage, xAbortChannel, rCmdEnv.get() );
1107cdf0e10cSrcweir         if ( m_pDialogHelper )
1108cdf0e10cSrcweir             m_pDialogHelper->updatePackageInfo( xPackage );
1109cdf0e10cSrcweir     }
1110cdf0e10cSrcweir     catch ( ::ucb::CommandAbortedException & )
1111cdf0e10cSrcweir     {}
1112cdf0e10cSrcweir }
1113cdf0e10cSrcweir 
1114cdf0e10cSrcweir //------------------------------------------------------------------------------
1115cdf0e10cSrcweir void ExtensionCmdQueue::Thread::onTerminated()
1116cdf0e10cSrcweir {
1117cdf0e10cSrcweir     ::osl::MutexGuard g(m_mutex);
1118cdf0e10cSrcweir     m_bTerminated = true;
1119cdf0e10cSrcweir }
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir //------------------------------------------------------------------------------
1122cdf0e10cSrcweir OUString ExtensionCmdQueue::Thread::searchAndReplaceAll( const OUString &rSource,
1123cdf0e10cSrcweir                                                          const OUString &rWhat,
1124cdf0e10cSrcweir                                                          const OUString &rWith )
1125cdf0e10cSrcweir {
1126cdf0e10cSrcweir     OUString aRet( rSource );
1127cdf0e10cSrcweir     sal_Int32 nLen = rWhat.getLength();
1128cdf0e10cSrcweir 
1129cdf0e10cSrcweir     if ( !nLen )
1130cdf0e10cSrcweir         return aRet;
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir     sal_Int32 nIndex = rSource.indexOf( rWhat );
1133cdf0e10cSrcweir     while ( nIndex != -1 )
1134cdf0e10cSrcweir     {
1135cdf0e10cSrcweir         aRet = aRet.replaceAt( nIndex, nLen, rWith );
1136cdf0e10cSrcweir         nIndex = aRet.indexOf( rWhat, nIndex + rWith.getLength() );
1137cdf0e10cSrcweir     }
1138cdf0e10cSrcweir     return aRet;
1139cdf0e10cSrcweir }
1140cdf0e10cSrcweir 
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir //------------------------------------------------------------------------------
1143cdf0e10cSrcweir //------------------------------------------------------------------------------
1144cdf0e10cSrcweir //------------------------------------------------------------------------------
1145cdf0e10cSrcweir ExtensionCmdQueue::ExtensionCmdQueue( DialogHelper * pDialogHelper,
1146cdf0e10cSrcweir                                       TheExtensionManager *pManager,
1147cdf0e10cSrcweir                                       const uno::Reference< uno::XComponentContext > &rContext )
1148cdf0e10cSrcweir   : m_thread( new Thread( pDialogHelper, pManager, rContext ) )
1149cdf0e10cSrcweir {
1150cdf0e10cSrcweir     m_thread->launch();
1151cdf0e10cSrcweir }
1152cdf0e10cSrcweir 
1153cdf0e10cSrcweir ExtensionCmdQueue::~ExtensionCmdQueue() {
1154cdf0e10cSrcweir     stop();
1155cdf0e10cSrcweir }
1156cdf0e10cSrcweir 
1157cdf0e10cSrcweir void ExtensionCmdQueue::addExtension( const ::rtl::OUString & extensionURL,
1158cdf0e10cSrcweir                                       const ::rtl::OUString & repository,
1159cdf0e10cSrcweir                                       const bool bWarnUser )
1160cdf0e10cSrcweir {
1161cdf0e10cSrcweir     m_thread->addExtension( extensionURL, repository, bWarnUser );
1162cdf0e10cSrcweir }
1163cdf0e10cSrcweir 
1164cdf0e10cSrcweir void ExtensionCmdQueue::removeExtension( const uno::Reference< deployment::XPackage > &rPackage )
1165cdf0e10cSrcweir {
1166cdf0e10cSrcweir     m_thread->removeExtension( rPackage );
1167cdf0e10cSrcweir }
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir void ExtensionCmdQueue::enableExtension( const uno::Reference< deployment::XPackage > &rPackage,
1170cdf0e10cSrcweir                                          const bool bEnable )
1171cdf0e10cSrcweir {
1172cdf0e10cSrcweir     m_thread->enableExtension( rPackage, bEnable );
1173cdf0e10cSrcweir }
1174cdf0e10cSrcweir 
1175cdf0e10cSrcweir void ExtensionCmdQueue::checkForUpdates( const std::vector<uno::Reference<deployment::XPackage > > &vExtensionList )
1176cdf0e10cSrcweir {
1177cdf0e10cSrcweir     m_thread->checkForUpdates( vExtensionList );
1178cdf0e10cSrcweir }
1179cdf0e10cSrcweir 
1180cdf0e10cSrcweir void ExtensionCmdQueue::acceptLicense( const uno::Reference< deployment::XPackage > &rPackage )
1181cdf0e10cSrcweir {
1182cdf0e10cSrcweir     m_thread->acceptLicense( rPackage );
1183cdf0e10cSrcweir }
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir void ExtensionCmdQueue::syncRepositories( const uno::Reference< uno::XComponentContext > &xContext )
1186cdf0e10cSrcweir {
1187cdf0e10cSrcweir     dp_misc::syncRepositories( new ProgressCmdEnv( xContext, NULL, OUSTR("Extension Manager") ) );
1188cdf0e10cSrcweir }
1189cdf0e10cSrcweir 
1190cdf0e10cSrcweir void ExtensionCmdQueue::stop()
1191cdf0e10cSrcweir {
1192cdf0e10cSrcweir     m_thread->stop();
1193cdf0e10cSrcweir }
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir bool ExtensionCmdQueue::isBusy()
1196cdf0e10cSrcweir {
1197cdf0e10cSrcweir     return m_thread->isBusy();
1198cdf0e10cSrcweir }
1199cdf0e10cSrcweir 
1200cdf0e10cSrcweir void handleInteractionRequest( const uno::Reference< uno::XComponentContext > & xContext,
1201cdf0e10cSrcweir                                const uno::Reference< task::XInteractionRequest > & xRequest )
1202cdf0e10cSrcweir {
1203cdf0e10cSrcweir     ::rtl::Reference< ProgressCmdEnv > xCmdEnv( new ProgressCmdEnv( xContext, NULL, OUSTR("Extension Manager") ) );
1204cdf0e10cSrcweir     xCmdEnv->handle( xRequest );
1205cdf0e10cSrcweir }
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir } //namespace dp_gui
1208cdf0e10cSrcweir 
1209