xref: /trunk/main/extensions/source/update/check/updatehdl.cxx (revision b838f7250280accb8f6cdc9cbe4a034b657b83c5)
12a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52a97ec55SAndrew Rist  * distributed with this work for additional information
62a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
82a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
92a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
112a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
132a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
142a97ec55SAndrew Rist  * software distributed under the License is distributed on an
152a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
172a97ec55SAndrew Rist  * specific language governing permissions and limitations
182a97ec55SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
202a97ec55SAndrew Rist  *************************************************************/
212a97ec55SAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_extensions.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include "updatehdl.hxx"
26cdf0e10cSrcweir #include "update.hrc"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "osl/diagnose.h"
29cdf0e10cSrcweir #include "osl/thread.hxx"
30cdf0e10cSrcweir #include "osl/file.hxx"
31cdf0e10cSrcweir #include "rtl/ustring.hxx"
32cdf0e10cSrcweir #include "rtl/bootstrap.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.h"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <com/sun/star/style/VerticalAlignment.hpp>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include "com/sun/star/awt/ActionEvent.hpp"
39cdf0e10cSrcweir #include "com/sun/star/awt/PushButtonType.hpp"
40cdf0e10cSrcweir #include "com/sun/star/awt/VclWindowPeerAttribute.hpp"
41cdf0e10cSrcweir #include "com/sun/star/awt/WindowAttribute.hpp"
42cdf0e10cSrcweir #include "com/sun/star/awt/XButton.hpp"
43cdf0e10cSrcweir #include "com/sun/star/awt/XControl.hpp"
44cdf0e10cSrcweir #include "com/sun/star/awt/XControlContainer.hpp"
45cdf0e10cSrcweir #include "com/sun/star/awt/XMessageBox.hpp"
46cdf0e10cSrcweir #include "com/sun/star/awt/XAnimation.hpp"
47cdf0e10cSrcweir #include "com/sun/star/awt/XTopWindow.hpp"
48cdf0e10cSrcweir #include "com/sun/star/awt/XVclWindowPeer.hpp"
49cdf0e10cSrcweir #include "com/sun/star/awt/XVclContainer.hpp"
50cdf0e10cSrcweir #include "com/sun/star/awt/XWindow.hpp"
51cdf0e10cSrcweir #include "com/sun/star/awt/XWindow2.hpp"
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
54cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp"
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #include "com/sun/star/container/XNameContainer.hpp"
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #include "com/sun/star/frame/XDesktop.hpp"
59cdf0e10cSrcweir 
60cdf0e10cSrcweir #include "com/sun/star/lang/XMultiServiceFactory.hpp"
61cdf0e10cSrcweir #include "com/sun/star/task/InteractionRequestStringResolver.hpp"
62cdf0e10cSrcweir 
63cdf0e10cSrcweir #include <com/sun/star/resource/XResourceBundleLoader.hpp>
64cdf0e10cSrcweir 
65cdf0e10cSrcweir #include "updatehdl.hrc"
66cdf0e10cSrcweir #include <tools/urlobj.hxx>
67cdf0e10cSrcweir 
68*b838f725SArrigo Marchiori #include <vcl/svapp.hxx>
69*b838f725SArrigo Marchiori #include <vos/mutex.hxx>
70*b838f725SArrigo Marchiori 
71cdf0e10cSrcweir #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
72cdf0e10cSrcweir 
73cdf0e10cSrcweir #define COMMAND_CLOSE       UNISTRING("close")
74cdf0e10cSrcweir 
75cdf0e10cSrcweir #define CTRL_THROBBER       UNISTRING("throbber")
76cdf0e10cSrcweir #define CTRL_PROGRESS       UNISTRING("progress")
77cdf0e10cSrcweir 
78cdf0e10cSrcweir #define TEXT_STATUS         UNISTRING("text_status")
79cdf0e10cSrcweir #define TEXT_PERCENT        UNISTRING("text_percent")
80cdf0e10cSrcweir #define TEXT_DESCRIPTION    UNISTRING("text_description")
81cdf0e10cSrcweir 
82cdf0e10cSrcweir #define FIXED_LINE_MODEL    UNISTRING("com.sun.star.awt.UnoControlFixedLineModel")
83cdf0e10cSrcweir #define FIXED_TEXT_MODEL    UNISTRING("com.sun.star.awt.UnoControlFixedTextModel")
84cdf0e10cSrcweir #define EDIT_FIELD_MODEL    UNISTRING("com.sun.star.awt.UnoControlEditModel")
85cdf0e10cSrcweir #define BUTTON_MODEL        UNISTRING("com.sun.star.awt.UnoControlButtonModel")
86cdf0e10cSrcweir #define GROUP_BOX_MODEL     UNISTRING("com.sun.star.awt.UnoControlGroupBoxModel")
87cdf0e10cSrcweir 
88cdf0e10cSrcweir using namespace com::sun::star;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir //--------------------------------------------------------------------
UpdateHandler(const uno::Reference<uno::XComponentContext> & rxContext,const rtl::Reference<IActionListener> & rxActionListener)91cdf0e10cSrcweir UpdateHandler::UpdateHandler( const uno::Reference< uno::XComponentContext > & rxContext,
92cdf0e10cSrcweir                               const rtl::Reference< IActionListener > & rxActionListener ) :
93cdf0e10cSrcweir     mxContext( rxContext ),
94cdf0e10cSrcweir     mxActionListener( rxActionListener ),
95cdf0e10cSrcweir     meCurState( UPDATESTATES_COUNT ),
96cdf0e10cSrcweir     meLastState( UPDATESTATES_COUNT ),
97cdf0e10cSrcweir     mnPercent( 0 ),
98cdf0e10cSrcweir     mnLastCtrlState( -1 ),
99cdf0e10cSrcweir     mbDownloadBtnHasDots( false ),
100cdf0e10cSrcweir     mbVisible( false ),
101cdf0e10cSrcweir     mbStringsLoaded( false ),
102cdf0e10cSrcweir     mbMinimized( false ),
103cdf0e10cSrcweir     mbListenerAdded(false),
104cdf0e10cSrcweir     mbShowsMessageBox(false)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir //--------------------------------------------------------------------
~UpdateHandler()109cdf0e10cSrcweir UpdateHandler::~UpdateHandler()
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     mxContext = NULL;
112cdf0e10cSrcweir     mxUpdDlg = NULL;
113cdf0e10cSrcweir     mxInteractionHdl = NULL;
114cdf0e10cSrcweir     mxActionListener = NULL;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir //--------------------------------------------------------------------
enableControls(short nCtrlState)118cdf0e10cSrcweir void UpdateHandler::enableControls( short nCtrlState )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     if ( nCtrlState == mnLastCtrlState )
123cdf0e10cSrcweir         return;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     bool bEnableControl;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     short nCurStateVal = nCtrlState;
128cdf0e10cSrcweir     short nOldStateVal = mnLastCtrlState;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     // the help button should always be the last button in the
1316ed1dc3eSmseidel     // enum list and must never be disabled
132cdf0e10cSrcweir     for ( int i=0; i<HELP_BUTTON; i++ )
133cdf0e10cSrcweir     {
134cdf0e10cSrcweir         nCurStateVal = (short)(nCtrlState >> i);
135cdf0e10cSrcweir         nOldStateVal = (short)(mnLastCtrlState >> i);
136cdf0e10cSrcweir         if ( ( nCurStateVal & 0x01 ) != ( nOldStateVal & 0x01 ) )
137cdf0e10cSrcweir         {
138cdf0e10cSrcweir             bEnableControl = ( ( nCurStateVal & 0x01 ) == 0x01 );
139cdf0e10cSrcweir             setControlProperty( msButtonIDs[i], UNISTRING("Enabled"), uno::Any( bEnableControl ) );
140cdf0e10cSrcweir         }
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     mnLastCtrlState = nCtrlState;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir //--------------------------------------------------------------------
setDownloadBtnLabel(bool bAppendDots)147cdf0e10cSrcweir void UpdateHandler::setDownloadBtnLabel( bool bAppendDots )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     if ( mbDownloadBtnHasDots != bAppendDots )
152cdf0e10cSrcweir     {
153cdf0e10cSrcweir         rtl::OUString aLabel( msDownload );
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         if ( bAppendDots )
156cdf0e10cSrcweir             aLabel += UNISTRING( "..." );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir         setControlProperty( msButtonIDs[DOWNLOAD_BUTTON], UNISTRING("Label"), uno::Any( aLabel ) );
159cdf0e10cSrcweir         setControlProperty( msButtonIDs[DOWNLOAD_BUTTON], UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_DOWNLOAD2 ) ) );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         mbDownloadBtnHasDots = bAppendDots;
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir //--------------------------------------------------------------------
setState(UpdateState eState)166cdf0e10cSrcweir void UpdateHandler::setState( UpdateState eState )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     meCurState = eState;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     if ( mxUpdDlg.is() && mbVisible )
173cdf0e10cSrcweir         updateState( meCurState );
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir //--------------------------------------------------------------------
isVisible() const177cdf0e10cSrcweir bool UpdateHandler::isVisible() const
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     if ( !mxUpdDlg.is() ) return false;
180cdf0e10cSrcweir 
181*b838f725SArrigo Marchiori     ::vos::OGuard aGuard( Application::GetSolarMutex() );
182cdf0e10cSrcweir     uno::Reference< awt::XWindow2 > xWindow( mxUpdDlg, uno::UNO_QUERY );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     if ( xWindow.is() )
185cdf0e10cSrcweir         return xWindow->isVisible();
186cdf0e10cSrcweir     else
187cdf0e10cSrcweir         return false;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir //--------------------------------------------------------------------
setVisible(bool bVisible)191cdf0e10cSrcweir void UpdateHandler::setVisible( bool bVisible )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     mbVisible = bVisible;
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     if ( bVisible )
198cdf0e10cSrcweir     {
199cdf0e10cSrcweir         if ( !mxUpdDlg.is() )
200cdf0e10cSrcweir             createDialog();
201cdf0e10cSrcweir 
202cdf0e10cSrcweir         // this should never happen, but if it happens we better return here
203cdf0e10cSrcweir         if ( !mxUpdDlg.is() )
204cdf0e10cSrcweir             return;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir         updateState( meCurState );
207cdf0e10cSrcweir 
208*b838f725SArrigo Marchiori         ::vos::OGuard aGuard( Application::GetSolarMutex() );
209cdf0e10cSrcweir         uno::Reference< awt::XWindow > xWindow( mxUpdDlg, uno::UNO_QUERY );
210cdf0e10cSrcweir 
211cdf0e10cSrcweir         if ( xWindow.is() )
212cdf0e10cSrcweir             xWindow->setVisible( bVisible );
213cdf0e10cSrcweir 
214cdf0e10cSrcweir         uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
215cdf0e10cSrcweir         if ( xTopWindow.is() )
216cdf0e10cSrcweir         {
217cdf0e10cSrcweir             xTopWindow->toFront();
218cdf0e10cSrcweir             if ( !mbListenerAdded )
219cdf0e10cSrcweir             {
220cdf0e10cSrcweir                 xTopWindow->addTopWindowListener( this );
221cdf0e10cSrcweir                 mbListenerAdded = true;
222cdf0e10cSrcweir             }
223cdf0e10cSrcweir         }
224cdf0e10cSrcweir     }
225cdf0e10cSrcweir     else if ( mxUpdDlg.is() )
226cdf0e10cSrcweir     {
227*b838f725SArrigo Marchiori         ::vos::OGuard aGuard( Application::GetSolarMutex() );
228cdf0e10cSrcweir         uno::Reference< awt::XWindow > xWindow( mxUpdDlg, uno::UNO_QUERY );
229cdf0e10cSrcweir 
230cdf0e10cSrcweir         if ( xWindow.is() )
231cdf0e10cSrcweir             xWindow->setVisible( bVisible );
232cdf0e10cSrcweir     }
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir //--------------------------------------------------------------------
setProgress(sal_Int32 nPercent)236cdf0e10cSrcweir void UpdateHandler::setProgress( sal_Int32 nPercent )
237cdf0e10cSrcweir {
238cdf0e10cSrcweir     if ( nPercent > 100 )
239cdf0e10cSrcweir         nPercent = 100;
240cdf0e10cSrcweir     else if ( nPercent < 0 )
241cdf0e10cSrcweir         nPercent = 0;
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     if ( nPercent != mnPercent )
244cdf0e10cSrcweir     {
245cdf0e10cSrcweir         osl::MutexGuard aGuard( maMutex );
246cdf0e10cSrcweir 
247cdf0e10cSrcweir         mnPercent = nPercent;
248cdf0e10cSrcweir         setControlProperty( CTRL_PROGRESS, UNISTRING("ProgressValue"), uno::Any( nPercent ) );
249cdf0e10cSrcweir         setControlProperty( TEXT_PERCENT, UNISTRING("Text"), uno::Any( substVariables(msPercent) ) );
250cdf0e10cSrcweir     }
251cdf0e10cSrcweir }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir //--------------------------------------------------------------------
setErrorMessage(const rtl::OUString & rErrorMsg)254cdf0e10cSrcweir void UpdateHandler::setErrorMessage( const rtl::OUString& rErrorMsg )
255cdf0e10cSrcweir {
256cdf0e10cSrcweir     setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( rErrorMsg ) );
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir //--------------------------------------------------------------------
setDownloadFile(const rtl::OUString & rFilePath)260cdf0e10cSrcweir void UpdateHandler::setDownloadFile( const rtl::OUString& rFilePath )
261cdf0e10cSrcweir {
262cdf0e10cSrcweir     sal_Int32 nLast = rFilePath.lastIndexOf( '/' );
263cdf0e10cSrcweir     if ( nLast != -1 )
264cdf0e10cSrcweir     {
265cdf0e10cSrcweir         msDownloadFile = rFilePath.copy( nLast+1 );
266cdf0e10cSrcweir         const rtl::OUString aDownloadURL = rFilePath.copy( 0, nLast );
267cdf0e10cSrcweir         osl::FileBase::getSystemPathFromFileURL( aDownloadURL, msDownloadPath );
268cdf0e10cSrcweir     }
269cdf0e10cSrcweir }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir //--------------------------------------------------------------------
getBubbleText(UpdateState eState)272cdf0e10cSrcweir rtl::OUString UpdateHandler::getBubbleText( UpdateState eState )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
275cdf0e10cSrcweir 
276cdf0e10cSrcweir     rtl::OUString sText;
277cdf0e10cSrcweir     sal_Int32 nIndex = (sal_Int32) eState;
278cdf0e10cSrcweir 
279cdf0e10cSrcweir     loadStrings();
280cdf0e10cSrcweir 
281cdf0e10cSrcweir     if ( ( UPDATESTATE_UPDATE_AVAIL <= nIndex ) && ( nIndex < UPDATESTATES_COUNT ) )
282cdf0e10cSrcweir         sText = substVariables( msBubbleTexts[ nIndex - UPDATESTATE_UPDATE_AVAIL ] );
283cdf0e10cSrcweir 
284cdf0e10cSrcweir     return sText;
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir //--------------------------------------------------------------------
getBubbleTitle(UpdateState eState)288cdf0e10cSrcweir rtl::OUString UpdateHandler::getBubbleTitle( UpdateState eState )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
291cdf0e10cSrcweir 
292cdf0e10cSrcweir     rtl::OUString sText;
293cdf0e10cSrcweir     sal_Int32 nIndex = (sal_Int32) eState;
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     loadStrings();
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     if ( ( UPDATESTATE_UPDATE_AVAIL <= nIndex ) && ( nIndex < UPDATESTATES_COUNT ) )
298cdf0e10cSrcweir         sText = substVariables( msBubbleTitles[ nIndex - UPDATESTATE_UPDATE_AVAIL] );
299cdf0e10cSrcweir 
300cdf0e10cSrcweir     return sText;
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir //--------------------------------------------------------------------
getDefaultInstErrMsg()304cdf0e10cSrcweir rtl::OUString UpdateHandler::getDefaultInstErrMsg()
305cdf0e10cSrcweir {
306cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     loadStrings();
309cdf0e10cSrcweir 
310cdf0e10cSrcweir     return substVariables( msInstallError );
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir // XActionListener
314cdf0e10cSrcweir //--------------------------------------------------------------------
disposing(const lang::EventObject & rEvt)315cdf0e10cSrcweir void SAL_CALL UpdateHandler::disposing( const lang::EventObject& rEvt )
316cdf0e10cSrcweir     throw( uno::RuntimeException )
317cdf0e10cSrcweir {
318cdf0e10cSrcweir     if ( rEvt.Source == mxUpdDlg )
319cdf0e10cSrcweir         mxUpdDlg.clear();
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir //--------------------------------------------------------------------
actionPerformed(awt::ActionEvent const & rEvent)323cdf0e10cSrcweir void SAL_CALL UpdateHandler::actionPerformed( awt::ActionEvent const & rEvent )
324cdf0e10cSrcweir     throw( uno::RuntimeException )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir     DialogControls eButton = BUTTON_COUNT;
327cdf0e10cSrcweir     for ( int i = 0; i < BUTTON_COUNT; i++ )
328cdf0e10cSrcweir     {
329cdf0e10cSrcweir         if ( rEvent.ActionCommand.equals( msButtonIDs[i] ) )
330cdf0e10cSrcweir         {
331cdf0e10cSrcweir             eButton = (DialogControls) i;
332cdf0e10cSrcweir             break;
333cdf0e10cSrcweir         }
334cdf0e10cSrcweir     }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     if ( rEvent.ActionCommand.equals( COMMAND_CLOSE ) )
337cdf0e10cSrcweir     {
338cdf0e10cSrcweir         if ( ( mnLastCtrlState & ( 1 << CLOSE_BUTTON ) ) == ( 1 << CLOSE_BUTTON ) )
339cdf0e10cSrcweir             eButton = CLOSE_BUTTON;
340cdf0e10cSrcweir         else
341cdf0e10cSrcweir             eButton = CANCEL_BUTTON;
342cdf0e10cSrcweir     }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir     switch ( eButton ) {
345cdf0e10cSrcweir         case CANCEL_BUTTON:
346cdf0e10cSrcweir         {
347cdf0e10cSrcweir             bool bCancel = true;
348cdf0e10cSrcweir 
349cdf0e10cSrcweir             if ( ( meCurState == UPDATESTATE_DOWNLOADING ) ||
350cdf0e10cSrcweir                  ( meCurState == UPDATESTATE_DOWNLOAD_PAUSED ) ||
351cdf0e10cSrcweir                  ( meCurState == UPDATESTATE_ERROR_DOWNLOADING ) )
352cdf0e10cSrcweir                 bCancel = showWarning( msCancelMessage );
353cdf0e10cSrcweir 
354cdf0e10cSrcweir             if ( bCancel )
355cdf0e10cSrcweir             {
356cdf0e10cSrcweir                 mxActionListener->cancel();
357cdf0e10cSrcweir                 setVisible( false );
358cdf0e10cSrcweir             }
359cdf0e10cSrcweir             break;
360cdf0e10cSrcweir         }
361cdf0e10cSrcweir         case CLOSE_BUTTON:
362cdf0e10cSrcweir             setVisible( false );
363cdf0e10cSrcweir             if ( meCurState == UPDATESTATE_ERROR_CHECKING )
364cdf0e10cSrcweir                 mxActionListener->closeAfterFailure();
365cdf0e10cSrcweir             break;
366cdf0e10cSrcweir         case DOWNLOAD_BUTTON:
367cdf0e10cSrcweir             mxActionListener->download();
368cdf0e10cSrcweir             break;
369cdf0e10cSrcweir         case INSTALL_BUTTON:
370cdf0e10cSrcweir             if ( showWarning( msInstallMessage ) )
371cdf0e10cSrcweir                 mxActionListener->install();
372cdf0e10cSrcweir             break;
373cdf0e10cSrcweir         case PAUSE_BUTTON:
374cdf0e10cSrcweir             mxActionListener->pause();
375cdf0e10cSrcweir             break;
376cdf0e10cSrcweir         case RESUME_BUTTON:
377cdf0e10cSrcweir             mxActionListener->resume();
378cdf0e10cSrcweir             break;
379cdf0e10cSrcweir         case HELP_BUTTON:
380cdf0e10cSrcweir             break;
381cdf0e10cSrcweir         default:
382cdf0e10cSrcweir             OSL_ENSURE( false, "UpdateHandler::actionPerformed: unknown command!" );
383cdf0e10cSrcweir     }
384cdf0e10cSrcweir }
385cdf0e10cSrcweir 
386cdf0e10cSrcweir // XTopWindowListener
387cdf0e10cSrcweir //--------------------------------------------------------------------
windowOpened(const lang::EventObject &)388cdf0e10cSrcweir void SAL_CALL UpdateHandler::windowOpened( const lang::EventObject& )
389cdf0e10cSrcweir     throw( uno::RuntimeException )
390cdf0e10cSrcweir {
391cdf0e10cSrcweir }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir //--------------------------------------------------------------------
windowClosing(const lang::EventObject & e)394cdf0e10cSrcweir void SAL_CALL UpdateHandler::windowClosing( const lang::EventObject& e )
395cdf0e10cSrcweir     throw( uno::RuntimeException )
396cdf0e10cSrcweir {
397*b838f725SArrigo Marchiori     ::vos::OGuard aGuard( Application::GetSolarMutex() );
398cdf0e10cSrcweir     awt::ActionEvent aActionEvt;
399cdf0e10cSrcweir     aActionEvt.ActionCommand = COMMAND_CLOSE;
400cdf0e10cSrcweir     aActionEvt.Source = e.Source;
401cdf0e10cSrcweir 
402cdf0e10cSrcweir     actionPerformed( aActionEvt );
403cdf0e10cSrcweir }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir //--------------------------------------------------------------------
windowClosed(const lang::EventObject &)406cdf0e10cSrcweir void SAL_CALL UpdateHandler::windowClosed( const lang::EventObject& )
407cdf0e10cSrcweir     throw( uno::RuntimeException )
408cdf0e10cSrcweir {
409cdf0e10cSrcweir }
410cdf0e10cSrcweir 
411cdf0e10cSrcweir //--------------------------------------------------------------------
windowMinimized(const lang::EventObject &)412cdf0e10cSrcweir void SAL_CALL UpdateHandler::windowMinimized( const lang::EventObject& )
413cdf0e10cSrcweir     throw( uno::RuntimeException )
414cdf0e10cSrcweir {
415cdf0e10cSrcweir     mbMinimized = true;
416cdf0e10cSrcweir }
417cdf0e10cSrcweir 
418cdf0e10cSrcweir //--------------------------------------------------------------------
windowNormalized(const lang::EventObject &)419cdf0e10cSrcweir void SAL_CALL UpdateHandler::windowNormalized( const lang::EventObject& )
420cdf0e10cSrcweir     throw( uno::RuntimeException )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir     mbMinimized = false;
423cdf0e10cSrcweir }
424cdf0e10cSrcweir 
425cdf0e10cSrcweir //--------------------------------------------------------------------
windowActivated(const lang::EventObject &)426cdf0e10cSrcweir void SAL_CALL UpdateHandler::windowActivated( const lang::EventObject& )
427cdf0e10cSrcweir     throw( uno::RuntimeException )
428cdf0e10cSrcweir {
429cdf0e10cSrcweir }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir //--------------------------------------------------------------------
windowDeactivated(const lang::EventObject &)432cdf0e10cSrcweir void SAL_CALL UpdateHandler::windowDeactivated( const lang::EventObject& )
433cdf0e10cSrcweir     throw( uno::RuntimeException )
434cdf0e10cSrcweir {
435cdf0e10cSrcweir }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir // XInteractionHandler
438cdf0e10cSrcweir //------------------------------------------------------------------------------
handle(uno::Reference<task::XInteractionRequest> const & rRequest)439cdf0e10cSrcweir void SAL_CALL UpdateHandler::handle( uno::Reference< task::XInteractionRequest > const & rRequest)
440cdf0e10cSrcweir     throw (uno::RuntimeException)
441cdf0e10cSrcweir {
442cdf0e10cSrcweir     if ( !mxInteractionHdl.is() )
443cdf0e10cSrcweir     {
444cdf0e10cSrcweir         if( !mxContext.is() )
445cdf0e10cSrcweir             throw uno::RuntimeException( UNISTRING( "UpdateHandler:: empty component context" ), *this );
446cdf0e10cSrcweir 
447cdf0e10cSrcweir         uno::Reference< lang::XMultiComponentFactory > xServiceManager(mxContext->getServiceManager());
448cdf0e10cSrcweir 
449cdf0e10cSrcweir         if( !xServiceManager.is() )
450cdf0e10cSrcweir             throw uno::RuntimeException( UNISTRING( "UpdateHandler: unable to obtain service manager from component context" ), *this );
451cdf0e10cSrcweir 
452cdf0e10cSrcweir         mxInteractionHdl = uno::Reference<task::XInteractionHandler> (
453cdf0e10cSrcweir                                 xServiceManager->createInstanceWithContext(
454cdf0e10cSrcweir                                     UNISTRING( "com.sun.star.task.InteractionHandler" ),
455cdf0e10cSrcweir                                     mxContext),
456cdf0e10cSrcweir                                 uno::UNO_QUERY_THROW);
457cdf0e10cSrcweir         if( !mxInteractionHdl.is() )
458cdf0e10cSrcweir             throw uno::RuntimeException( UNISTRING( "UpdateHandler:: could not get default interaction handler" ), *this );
459cdf0e10cSrcweir     }
460cdf0e10cSrcweir     uno::Reference< task::XInteractionRequestStringResolver > xStrResolver =
461cdf0e10cSrcweir             task::InteractionRequestStringResolver::create( mxContext );
462cdf0e10cSrcweir     beans::Optional< ::rtl::OUString > aErrorText = xStrResolver->getStringFromInformationalRequest( rRequest );
463cdf0e10cSrcweir     if ( aErrorText.IsPresent )
464cdf0e10cSrcweir     {
465cdf0e10cSrcweir         setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( aErrorText.Value ) );
466cdf0e10cSrcweir 
467cdf0e10cSrcweir         uno::Sequence< uno::Reference< task::XInteractionContinuation > > xContinuations = rRequest->getContinuations();
468cdf0e10cSrcweir         if ( xContinuations.getLength() == 1 )
469cdf0e10cSrcweir         {
470cdf0e10cSrcweir             if ( meCurState == UPDATESTATE_CHECKING )
471cdf0e10cSrcweir                 setState( UPDATESTATE_ERROR_CHECKING );
472cdf0e10cSrcweir             else if ( meCurState == UPDATESTATE_DOWNLOADING )
473cdf0e10cSrcweir                 setState( UPDATESTATE_ERROR_DOWNLOADING );
474cdf0e10cSrcweir 
475cdf0e10cSrcweir             xContinuations[0]->select();
476cdf0e10cSrcweir         }
477cdf0e10cSrcweir         else
478cdf0e10cSrcweir             mxInteractionHdl->handle( rRequest );
479cdf0e10cSrcweir     }
480cdf0e10cSrcweir     else
481cdf0e10cSrcweir         mxInteractionHdl->handle( rRequest );
482cdf0e10cSrcweir }
483cdf0e10cSrcweir 
484cdf0e10cSrcweir //------------------------------------------------------------------------------
485cdf0e10cSrcweir // XTerminateListener
486cdf0e10cSrcweir //------------------------------------------------------------------------------
queryTermination(const lang::EventObject &)487cdf0e10cSrcweir void SAL_CALL UpdateHandler::queryTermination( const lang::EventObject& )
488cdf0e10cSrcweir     throw ( frame::TerminationVetoException, uno::RuntimeException )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir     if ( mbShowsMessageBox )
491cdf0e10cSrcweir     {
492*b838f725SArrigo Marchiori         ::vos::OGuard aGuard( Application::GetSolarMutex() );
493cdf0e10cSrcweir         uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
494cdf0e10cSrcweir         if ( xTopWindow.is() )
495cdf0e10cSrcweir             xTopWindow->toFront();
496cdf0e10cSrcweir 
497cdf0e10cSrcweir         throw frame::TerminationVetoException(
498cdf0e10cSrcweir             UNISTRING("The office cannot be closed while displaying a warning!"),
499cdf0e10cSrcweir             uno::Reference<XInterface>(static_cast<frame::XTerminateListener*>(this), uno::UNO_QUERY));
500cdf0e10cSrcweir     }
501cdf0e10cSrcweir     else
502cdf0e10cSrcweir         setVisible( false );
503cdf0e10cSrcweir }
504cdf0e10cSrcweir 
505cdf0e10cSrcweir //------------------------------------------------------------------------------
notifyTermination(const lang::EventObject &)506cdf0e10cSrcweir void SAL_CALL UpdateHandler::notifyTermination( const lang::EventObject& )
507cdf0e10cSrcweir     throw ( uno::RuntimeException )
508cdf0e10cSrcweir {
509cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
510cdf0e10cSrcweir 
511cdf0e10cSrcweir     if ( mxUpdDlg.is() )
512cdf0e10cSrcweir     {
513*b838f725SArrigo Marchiori         ::vos::OGuard aGuard( Application::GetSolarMutex() );
514cdf0e10cSrcweir         uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
515cdf0e10cSrcweir         if ( xTopWindow.is() )
516cdf0e10cSrcweir             xTopWindow->removeTopWindowListener( this );
517cdf0e10cSrcweir 
518cdf0e10cSrcweir         uno::Reference< lang::XComponent > xComponent( mxUpdDlg, uno::UNO_QUERY );
519cdf0e10cSrcweir         if ( xComponent.is() )
520cdf0e10cSrcweir             xComponent->dispose();
521cdf0e10cSrcweir 
522cdf0e10cSrcweir         mxUpdDlg.clear();
523cdf0e10cSrcweir     }
524cdf0e10cSrcweir }
525cdf0e10cSrcweir 
526cdf0e10cSrcweir //--------------------------------------------------------------------
527cdf0e10cSrcweir //--------------------------------------------------------------------
528cdf0e10cSrcweir //--------------------------------------------------------------------
updateState(UpdateState eState)529cdf0e10cSrcweir void UpdateHandler::updateState( UpdateState eState )
530cdf0e10cSrcweir {
531cdf0e10cSrcweir     if ( meLastState == eState )
532cdf0e10cSrcweir         return;
533cdf0e10cSrcweir 
534cdf0e10cSrcweir     if ( isVisible() )
535cdf0e10cSrcweir         {} // ToTop();
536cdf0e10cSrcweir 
537cdf0e10cSrcweir     rtl::OUString sText;
538cdf0e10cSrcweir 
539cdf0e10cSrcweir     switch ( eState )
540cdf0e10cSrcweir     {
541cdf0e10cSrcweir         case UPDATESTATE_CHECKING:
542cdf0e10cSrcweir             showControls( (1<<CANCEL_BUTTON) + (1<<THROBBER_CTRL) );
543cdf0e10cSrcweir             enableControls( 1<<CANCEL_BUTTON );
544cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msChecking) ) );
545cdf0e10cSrcweir             setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( rtl::OUString() ) );
546cdf0e10cSrcweir             focusControl( CANCEL_BUTTON );
547cdf0e10cSrcweir             break;
548cdf0e10cSrcweir         case UPDATESTATE_ERROR_CHECKING:
549cdf0e10cSrcweir             showControls( 0 );
550cdf0e10cSrcweir             enableControls( 1 << CLOSE_BUTTON );
551cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msCheckingError) ) );
552cdf0e10cSrcweir             focusControl( CLOSE_BUTTON );
553cdf0e10cSrcweir             break;
554cdf0e10cSrcweir         case UPDATESTATE_UPDATE_AVAIL:
555cdf0e10cSrcweir             showControls( 0 );
556cdf0e10cSrcweir             enableControls( ( 1 << CLOSE_BUTTON ) + ( 1 << DOWNLOAD_BUTTON ) );
557cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msUpdFound) ) );
558cdf0e10cSrcweir 
559cdf0e10cSrcweir             sText = substVariables(msDownloadWarning);
560cdf0e10cSrcweir             if ( msDescriptionMsg.getLength() )
561cdf0e10cSrcweir                 sText += UNISTRING("\n\n") + msDescriptionMsg;
562cdf0e10cSrcweir             setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( sText ) );
563cdf0e10cSrcweir 
564cdf0e10cSrcweir             setDownloadBtnLabel( false );
565cdf0e10cSrcweir             focusControl( DOWNLOAD_BUTTON );
566cdf0e10cSrcweir             break;
567cdf0e10cSrcweir         case UPDATESTATE_UPDATE_NO_DOWNLOAD:
568cdf0e10cSrcweir             showControls( 0 );
569cdf0e10cSrcweir             enableControls( ( 1 << CLOSE_BUTTON ) + ( 1 << DOWNLOAD_BUTTON ) );
570cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msUpdFound) ) );
571cdf0e10cSrcweir 
572cdf0e10cSrcweir             sText = substVariables(msDownloadNotAvail);
573cdf0e10cSrcweir             if ( msDescriptionMsg.getLength() )
574cdf0e10cSrcweir                 sText += UNISTRING("\n\n") + msDescriptionMsg;
575cdf0e10cSrcweir             setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( sText ) );
576cdf0e10cSrcweir 
577cdf0e10cSrcweir             setDownloadBtnLabel( true );
578cdf0e10cSrcweir             focusControl( DOWNLOAD_BUTTON );
579cdf0e10cSrcweir             break;
580cdf0e10cSrcweir         case UPDATESTATE_NO_UPDATE_AVAIL:
581cdf0e10cSrcweir         case UPDATESTATE_EXT_UPD_AVAIL: // will only be set, when there are no office updates avail
582cdf0e10cSrcweir             showControls( 0 );
583cdf0e10cSrcweir             enableControls( 1 << CLOSE_BUTTON );
584cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msNoUpdFound) ) );
585cdf0e10cSrcweir             setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( rtl::OUString() ) );
586cdf0e10cSrcweir             focusControl( CLOSE_BUTTON );
587cdf0e10cSrcweir             break;
588cdf0e10cSrcweir         case UPDATESTATE_DOWNLOADING:
589cdf0e10cSrcweir             showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
590cdf0e10cSrcweir             enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) );
591cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msDownloading) ) );
592cdf0e10cSrcweir             setControlProperty( TEXT_PERCENT, UNISTRING("Text"), uno::Any( substVariables(msPercent) ) );
593cdf0e10cSrcweir             setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( substVariables(msDownloadWarning) ) );
594cdf0e10cSrcweir             setControlProperty( CTRL_PROGRESS, UNISTRING("ProgressValue"), uno::Any( mnPercent ) );
595cdf0e10cSrcweir             focusControl( CLOSE_BUTTON );
596cdf0e10cSrcweir             break;
597cdf0e10cSrcweir         case UPDATESTATE_DOWNLOAD_PAUSED:
598cdf0e10cSrcweir             showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
599cdf0e10cSrcweir             enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) + (1<<RESUME_BUTTON) );
600cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msDownloadPause) ) );
601cdf0e10cSrcweir             setControlProperty( TEXT_PERCENT, UNISTRING("Text"), uno::Any( substVariables(msPercent) ) );
602cdf0e10cSrcweir             setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( substVariables(msDownloadWarning) ) );
603cdf0e10cSrcweir             setControlProperty( CTRL_PROGRESS, UNISTRING("ProgressValue"), uno::Any( mnPercent ) );
604cdf0e10cSrcweir             focusControl( CLOSE_BUTTON );
605cdf0e10cSrcweir             break;
606cdf0e10cSrcweir         case UPDATESTATE_ERROR_DOWNLOADING:
607cdf0e10cSrcweir             showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
608cdf0e10cSrcweir             enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) );
609cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msDownloadError) ) );
610cdf0e10cSrcweir             focusControl( CLOSE_BUTTON );
611cdf0e10cSrcweir             break;
612cdf0e10cSrcweir         case UPDATESTATE_DOWNLOAD_AVAIL:
613cdf0e10cSrcweir             showControls( 0 );
614cdf0e10cSrcweir             enableControls( (1<<CLOSE_BUTTON) + (1<<INSTALL_BUTTON) );
615cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msReady2Install) ) );
616cdf0e10cSrcweir             setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( substVariables(msDownloadDescr) ) );
617cdf0e10cSrcweir             focusControl( INSTALL_BUTTON );
618cdf0e10cSrcweir             break;
619cdf0e10cSrcweir         case UPDATESTATE_AUTO_START:
620cdf0e10cSrcweir         case UPDATESTATES_COUNT:
621cdf0e10cSrcweir             //do nothing, only count!
622cdf0e10cSrcweir             break;
623cdf0e10cSrcweir     }
624cdf0e10cSrcweir 
625cdf0e10cSrcweir     meLastState = eState;
626cdf0e10cSrcweir }
627cdf0e10cSrcweir 
628cdf0e10cSrcweir //--------------------------------------------------------------------
searchAndReplaceAll(rtl::OUString & rText,const rtl::OUString & rWhat,const rtl::OUString & rWith) const629cdf0e10cSrcweir void UpdateHandler::searchAndReplaceAll( rtl::OUString &rText,
630cdf0e10cSrcweir                                          const rtl::OUString &rWhat,
631cdf0e10cSrcweir                                          const rtl::OUString &rWith ) const
632cdf0e10cSrcweir {
633cdf0e10cSrcweir     sal_Int32 nIndex = rText.indexOf( rWhat );
634cdf0e10cSrcweir 
635cdf0e10cSrcweir     while ( nIndex != -1 )
636cdf0e10cSrcweir     {
637cdf0e10cSrcweir         rText = rText.replaceAt( nIndex, rWhat.getLength(), rWith );
638cdf0e10cSrcweir         nIndex = rText.indexOf( rWhat, nIndex );
639cdf0e10cSrcweir     }
640cdf0e10cSrcweir }
641cdf0e10cSrcweir 
642cdf0e10cSrcweir //--------------------------------------------------------------------
loadString(const uno::Reference<resource::XResourceBundle> xBundle,sal_Int32 nResourceId) const643cdf0e10cSrcweir rtl::OUString UpdateHandler::loadString( const uno::Reference< resource::XResourceBundle > xBundle,
644cdf0e10cSrcweir                                          sal_Int32 nResourceId ) const
645cdf0e10cSrcweir {
646cdf0e10cSrcweir     rtl::OUString sString;
647cdf0e10cSrcweir     rtl::OUString sKey = UNISTRING( "string:" ) + rtl::OUString::valueOf( nResourceId );
648cdf0e10cSrcweir 
649cdf0e10cSrcweir     try
650cdf0e10cSrcweir     {
651cdf0e10cSrcweir         OSL_VERIFY( xBundle->getByName( sKey ) >>= sString );
652cdf0e10cSrcweir     }
653cdf0e10cSrcweir     catch( const uno::Exception& )
654cdf0e10cSrcweir     {
655cdf0e10cSrcweir         OSL_ENSURE( false, "UpdateHandler::loadString: caught an exception!" );
656cdf0e10cSrcweir         sString = UNISTRING("Missing ") + sKey;
657cdf0e10cSrcweir     }
658cdf0e10cSrcweir 
659cdf0e10cSrcweir     return sString;
660cdf0e10cSrcweir }
661cdf0e10cSrcweir 
substVariables(const rtl::OUString & rSource) const662cdf0e10cSrcweir rtl::OUString UpdateHandler::substVariables( const rtl::OUString &rSource ) const
663cdf0e10cSrcweir {
664cdf0e10cSrcweir     rtl::OUString sString( rSource );
665cdf0e10cSrcweir 
666cdf0e10cSrcweir     searchAndReplaceAll( sString, UNISTRING( "%NEXTVERSION" ), msNextVersion );
667cdf0e10cSrcweir     searchAndReplaceAll( sString, UNISTRING( "%DOWNLOAD_PATH" ), msDownloadPath );
668cdf0e10cSrcweir     searchAndReplaceAll( sString, UNISTRING( "%FILE_NAME" ), msDownloadFile );
669cdf0e10cSrcweir     searchAndReplaceAll( sString, UNISTRING( "%PERCENT" ), rtl::OUString::valueOf( mnPercent ) );
670cdf0e10cSrcweir 
671cdf0e10cSrcweir     return sString;
672cdf0e10cSrcweir }
673cdf0e10cSrcweir 
674cdf0e10cSrcweir //--------------------------------------------------------------------
loadStrings()675cdf0e10cSrcweir void UpdateHandler::loadStrings()
676cdf0e10cSrcweir {
677cdf0e10cSrcweir     if ( mbStringsLoaded )
678cdf0e10cSrcweir         return;
679cdf0e10cSrcweir     else
680cdf0e10cSrcweir         mbStringsLoaded = true;
681cdf0e10cSrcweir 
682cdf0e10cSrcweir     uno::Reference< resource::XResourceBundleLoader > xLoader;
683cdf0e10cSrcweir     try
684cdf0e10cSrcweir     {
685cdf0e10cSrcweir         uno::Any aValue( mxContext->getValueByName(
686cdf0e10cSrcweir                 UNISTRING( "/singletons/com.sun.star.resource.OfficeResourceLoader" ) ) );
687cdf0e10cSrcweir         OSL_VERIFY( aValue >>= xLoader );
688cdf0e10cSrcweir     }
689cdf0e10cSrcweir     catch( const uno::Exception& )
690cdf0e10cSrcweir     {
691cdf0e10cSrcweir         OSL_ENSURE( false, "UpdateHandler::loadStrings: could not create the resource loader!" );
692cdf0e10cSrcweir     }
693cdf0e10cSrcweir 
694cdf0e10cSrcweir     if ( !xLoader.is() ) return;
695cdf0e10cSrcweir 
696cdf0e10cSrcweir     uno::Reference< resource::XResourceBundle > xBundle;
697cdf0e10cSrcweir 
698cdf0e10cSrcweir     try
699cdf0e10cSrcweir     {
700cdf0e10cSrcweir         xBundle = xLoader->loadBundle_Default( UNISTRING( "upd" ) );
701cdf0e10cSrcweir     }
702cdf0e10cSrcweir     catch( const resource::MissingResourceException& )
703cdf0e10cSrcweir     {
704cdf0e10cSrcweir         OSL_ENSURE( false, "UpdateHandler::loadStrings: missing the resource bundle!" );
705cdf0e10cSrcweir     }
706cdf0e10cSrcweir 
707cdf0e10cSrcweir     if ( !xBundle.is() ) return;
708cdf0e10cSrcweir 
709cdf0e10cSrcweir     msChecking      = loadString( xBundle, RID_UPDATE_STR_CHECKING );
710cdf0e10cSrcweir     msCheckingError = loadString( xBundle, RID_UPDATE_STR_CHECKING_ERR );
711cdf0e10cSrcweir     msNoUpdFound    = loadString( xBundle, RID_UPDATE_STR_NO_UPD_FOUND );
712cdf0e10cSrcweir 
713cdf0e10cSrcweir     msUpdFound      = loadString( xBundle, RID_UPDATE_STR_UPD_FOUND );
714cdf0e10cSrcweir     setFullVersion( msUpdFound );
715cdf0e10cSrcweir 
716cdf0e10cSrcweir     msDlgTitle      = loadString( xBundle, RID_UPDATE_STR_DLG_TITLE );
717cdf0e10cSrcweir     msDownloadPause = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_PAUSE );
718cdf0e10cSrcweir     msDownloadError = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_ERR );
719cdf0e10cSrcweir     msDownloadWarning = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_WARN );
720cdf0e10cSrcweir     msDownloadDescr =  loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_DESCR );
721cdf0e10cSrcweir     msDownloadNotAvail = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_UNAVAIL );
722cdf0e10cSrcweir     msDownloading   = loadString( xBundle, RID_UPDATE_STR_DOWNLOADING );
723cdf0e10cSrcweir     msReady2Install = loadString( xBundle, RID_UPDATE_STR_READY_INSTALL );
724cdf0e10cSrcweir     msCancelTitle   = loadString( xBundle, RID_UPDATE_STR_CANCEL_TITLE );
725cdf0e10cSrcweir     msCancelMessage = loadString( xBundle, RID_UPDATE_STR_CANCEL_DOWNLOAD );
726cdf0e10cSrcweir     msInstallMessage = loadString( xBundle, RID_UPDATE_STR_BEGIN_INSTALL );
727cdf0e10cSrcweir     msInstallNow    = loadString( xBundle, RID_UPDATE_STR_INSTALL_NOW );
728cdf0e10cSrcweir     msInstallLater  = loadString( xBundle, RID_UPDATE_STR_INSTALL_LATER );
729cdf0e10cSrcweir     msInstallError  = loadString( xBundle, RID_UPDATE_STR_INSTALL_ERROR );
730cdf0e10cSrcweir     msOverwriteWarning = loadString( xBundle, RID_UPDATE_STR_OVERWRITE_WARNING );
731cdf0e10cSrcweir     msPercent       = loadString( xBundle, RID_UPDATE_STR_PERCENT );
732cdf0e10cSrcweir     msReloadWarning = loadString( xBundle, RID_UPDATE_STR_RELOAD_WARNING );
733cdf0e10cSrcweir     msReloadReload  = loadString( xBundle, RID_UPDATE_STR_RELOAD_RELOAD );
734cdf0e10cSrcweir     msReloadContinue = loadString( xBundle, RID_UPDATE_STR_RELOAD_CONTINUE );
735cdf0e10cSrcweir 
736cdf0e10cSrcweir     msStatusFL      = loadString( xBundle, RID_UPDATE_FT_STATUS );
737cdf0e10cSrcweir     msDescription   = loadString( xBundle, RID_UPDATE_FT_DESCRIPTION );
738cdf0e10cSrcweir 
739cdf0e10cSrcweir     msClose         = loadString( xBundle, RID_UPDATE_BTN_CLOSE );
740cdf0e10cSrcweir     msDownload      = loadString( xBundle, RID_UPDATE_BTN_DOWNLOAD );
741cdf0e10cSrcweir     msInstall       = loadString( xBundle, RID_UPDATE_BTN_INSTALL );
742cdf0e10cSrcweir     msPauseBtn      = loadString( xBundle, RID_UPDATE_BTN_PAUSE );
743cdf0e10cSrcweir     msResumeBtn     = loadString( xBundle, RID_UPDATE_BTN_RESUME );
744cdf0e10cSrcweir     msCancelBtn     = loadString( xBundle, RID_UPDATE_BTN_CANCEL );
745cdf0e10cSrcweir 
746cdf0e10cSrcweir     // all update states before UPDATESTATE_UPDATE_AVAIL don't have a bubble
747cdf0e10cSrcweir     // so we can ignore them
748cdf0e10cSrcweir     for ( int i=0; i < (int)(UPDATESTATES_COUNT - UPDATESTATE_UPDATE_AVAIL); i++ )
749cdf0e10cSrcweir     {
750cdf0e10cSrcweir         msBubbleTexts[ i ] = loadString( xBundle, RID_UPDATE_BUBBLE_TEXT_START + i );
751cdf0e10cSrcweir         msBubbleTitles[ i ] = loadString( xBundle, RID_UPDATE_BUBBLE_T_TEXT_START + i );
752cdf0e10cSrcweir     }
753cdf0e10cSrcweir 
754cdf0e10cSrcweir     for ( int i=0; i < BUTTON_COUNT; i++ )
755cdf0e10cSrcweir     {
756cdf0e10cSrcweir         msButtonIDs[ i ] = UNISTRING("BUTTON_") + rtl::OUString::valueOf( (sal_Int32) i );
757cdf0e10cSrcweir     }
758cdf0e10cSrcweir }
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 
761cdf0e10cSrcweir //--------------------------------------------------------------------
startThrobber(bool bStart)762cdf0e10cSrcweir void UpdateHandler::startThrobber( bool bStart )
763cdf0e10cSrcweir {
764*b838f725SArrigo Marchiori     ::vos::OGuard aGuard( Application::GetSolarMutex() );
765cdf0e10cSrcweir     uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
766cdf0e10cSrcweir     uno::Reference< awt::XAnimation > xThrobber( xContainer->getControl( CTRL_THROBBER ), uno::UNO_QUERY );
767cdf0e10cSrcweir 
768cdf0e10cSrcweir     if ( xThrobber.is() )
769cdf0e10cSrcweir     {
770cdf0e10cSrcweir         if ( bStart )
771cdf0e10cSrcweir             xThrobber->startAnimation();
772cdf0e10cSrcweir         else
773cdf0e10cSrcweir             xThrobber->stopAnimation();
774cdf0e10cSrcweir     }
775cdf0e10cSrcweir 
776cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow( xContainer->getControl( CTRL_THROBBER ), uno::UNO_QUERY );
777cdf0e10cSrcweir     if (xWindow.is() )
778cdf0e10cSrcweir         xWindow->setVisible( bStart );
779cdf0e10cSrcweir }
780cdf0e10cSrcweir 
781cdf0e10cSrcweir //--------------------------------------------------------------------
setControlProperty(const rtl::OUString & rCtrlName,const rtl::OUString & rPropName,const uno::Any & rPropValue)782cdf0e10cSrcweir void UpdateHandler::setControlProperty( const rtl::OUString &rCtrlName,
783cdf0e10cSrcweir                                         const rtl::OUString &rPropName,
784cdf0e10cSrcweir                                         const uno::Any &rPropValue )
785cdf0e10cSrcweir {
786cdf0e10cSrcweir     if ( !mxUpdDlg.is() ) return;
787cdf0e10cSrcweir 
788*b838f725SArrigo Marchiori     ::vos::OGuard aGuard( Application::GetSolarMutex() );
789cdf0e10cSrcweir     uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
790cdf0e10cSrcweir     uno::Reference< awt::XControl > xControl( xContainer->getControl( rCtrlName ), uno::UNO_QUERY_THROW );
791cdf0e10cSrcweir     uno::Reference< awt::XControlModel > xControlModel( xControl->getModel(), uno::UNO_QUERY_THROW );
792cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY_THROW );
793cdf0e10cSrcweir 
794cdf0e10cSrcweir     try {
795cdf0e10cSrcweir         xPropSet->setPropertyValue( rPropName, rPropValue );
796cdf0e10cSrcweir     }
797cdf0e10cSrcweir     catch( const beans::UnknownPropertyException& )
798cdf0e10cSrcweir     {
799cdf0e10cSrcweir         OSL_ENSURE( false, "UpdateHandler::setControlProperty: caught an exception!" );
800cdf0e10cSrcweir     }
801cdf0e10cSrcweir }
802cdf0e10cSrcweir 
803cdf0e10cSrcweir //--------------------------------------------------------------------
showControl(const rtl::OUString & rCtrlName,bool bShow)804cdf0e10cSrcweir void UpdateHandler::showControl( const rtl::OUString &rCtrlName, bool bShow )
805cdf0e10cSrcweir {
806*b838f725SArrigo Marchiori     ::vos::OGuard aGuard( Application::GetSolarMutex() );
807cdf0e10cSrcweir     uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
808cdf0e10cSrcweir 
809cdf0e10cSrcweir     if ( !xContainer.is() )
810cdf0e10cSrcweir     {
811cdf0e10cSrcweir         OSL_ENSURE( false, "UpdateHandler::showControl: could not get control container!" );
812cdf0e10cSrcweir         return;
813cdf0e10cSrcweir     }
814cdf0e10cSrcweir 
815cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow( xContainer->getControl( rCtrlName ), uno::UNO_QUERY );
816cdf0e10cSrcweir     if ( xWindow.is() )
817cdf0e10cSrcweir         xWindow->setVisible( bShow );
818cdf0e10cSrcweir }
819cdf0e10cSrcweir 
820cdf0e10cSrcweir //--------------------------------------------------------------------
focusControl(DialogControls eID)821cdf0e10cSrcweir void UpdateHandler::focusControl( DialogControls eID )
822cdf0e10cSrcweir {
823*b838f725SArrigo Marchiori     ::vos::OGuard aGuard( Application::GetSolarMutex() );
824cdf0e10cSrcweir     uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
825cdf0e10cSrcweir 
826cdf0e10cSrcweir     if ( !xContainer.is() )
827cdf0e10cSrcweir     {
828cdf0e10cSrcweir         OSL_ENSURE( false, "UpdateHandler::focusControl: could not get control container!" );
829cdf0e10cSrcweir         return;
830cdf0e10cSrcweir     }
831cdf0e10cSrcweir 
832cdf0e10cSrcweir     OSL_ENSURE( (eID < BUTTON_COUNT), "UpdateHandler::focusControl: id to big!" );
833cdf0e10cSrcweir 
834cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow( xContainer->getControl( msButtonIDs[(short)eID] ), uno::UNO_QUERY );
835cdf0e10cSrcweir     if ( xWindow.is() )
836cdf0e10cSrcweir         xWindow->setFocus();
837cdf0e10cSrcweir }
838cdf0e10cSrcweir 
839cdf0e10cSrcweir //--------------------------------------------------------------------
840*b838f725SArrigo Marchiori // Requires the Solar Mutex to be locked
insertControlModel(uno::Reference<awt::XControlModel> & rxDialogModel,rtl::OUString const & rServiceName,rtl::OUString const & rControlName,awt::Rectangle const & rPosSize,uno::Sequence<beans::NamedValue> const & rProps)841cdf0e10cSrcweir void UpdateHandler::insertControlModel( uno::Reference< awt::XControlModel > & rxDialogModel,
842cdf0e10cSrcweir                                         rtl::OUString const & rServiceName,
843cdf0e10cSrcweir                                         rtl::OUString const & rControlName,
844cdf0e10cSrcweir                                         awt::Rectangle const & rPosSize,
845cdf0e10cSrcweir                                         uno::Sequence< beans::NamedValue > const & rProps )
846cdf0e10cSrcweir {
847cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xFactory (rxDialogModel, uno::UNO_QUERY_THROW);
848cdf0e10cSrcweir     uno::Reference< awt::XControlModel > xModel (xFactory->createInstance (rServiceName), uno::UNO_QUERY_THROW);
849cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xPropSet (xModel, uno::UNO_QUERY_THROW);
850cdf0e10cSrcweir 
851cdf0e10cSrcweir     for (sal_Int32 i = 0, n = rProps.getLength(); i < n; i++)
852cdf0e10cSrcweir     {
853cdf0e10cSrcweir         xPropSet->setPropertyValue (rProps[i].Name, rProps[i].Value);
854cdf0e10cSrcweir     }
855cdf0e10cSrcweir 
856cdf0e10cSrcweir     // @see awt/UnoControlDialogElement.idl
857cdf0e10cSrcweir     xPropSet->setPropertyValue( UNISTRING("Name"), uno::Any (rControlName) );
858cdf0e10cSrcweir     xPropSet->setPropertyValue( UNISTRING("PositionX"), uno::Any (rPosSize.X) );
859cdf0e10cSrcweir     xPropSet->setPropertyValue( UNISTRING("PositionY"), uno::Any (rPosSize.Y) );
860cdf0e10cSrcweir     xPropSet->setPropertyValue( UNISTRING("Height"), uno::Any (rPosSize.Height) );
861cdf0e10cSrcweir     xPropSet->setPropertyValue( UNISTRING("Width"), uno::Any (rPosSize.Width) );
862cdf0e10cSrcweir 
863cdf0e10cSrcweir     // insert by Name into DialogModel container
864cdf0e10cSrcweir     uno::Reference< container::XNameContainer > xContainer (rxDialogModel, uno::UNO_QUERY_THROW);
865cdf0e10cSrcweir     xContainer->insertByName( rControlName, uno::Any (uno::Reference< uno::XInterface >(xModel, uno::UNO_QUERY)));
866cdf0e10cSrcweir }
867cdf0e10cSrcweir 
868cdf0e10cSrcweir //--------------------------------------------------------------------
setFullVersion(rtl::OUString & rString)869cdf0e10cSrcweir void UpdateHandler::setFullVersion( rtl::OUString& rString )
870cdf0e10cSrcweir {
871cdf0e10cSrcweir     if( !mxContext.is() )
872cdf0e10cSrcweir         throw uno::RuntimeException( UNISTRING( "getProductName: empty component context" ), *this );
873cdf0e10cSrcweir 
874cdf0e10cSrcweir     uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager() );
875cdf0e10cSrcweir 
876cdf0e10cSrcweir     if( !xServiceManager.is() )
877cdf0e10cSrcweir         throw uno::RuntimeException( UNISTRING( "getProductName: unable to obtain service manager from component context" ), *this );
878cdf0e10cSrcweir 
879cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider(
880cdf0e10cSrcweir         xServiceManager->createInstanceWithContext( UNISTRING( "com.sun.star.configuration.ConfigurationProvider" ), mxContext ),
881cdf0e10cSrcweir         uno::UNO_QUERY_THROW);
882cdf0e10cSrcweir 
883cdf0e10cSrcweir     beans::PropertyValue aProperty;
884cdf0e10cSrcweir     aProperty.Name  = UNISTRING( "nodepath" );
885cdf0e10cSrcweir     aProperty.Value = uno::makeAny( UNISTRING("org.openoffice.Setup/Product") );
886cdf0e10cSrcweir 
887cdf0e10cSrcweir     uno::Sequence< uno::Any > aArgumentList( 1 );
888cdf0e10cSrcweir     aArgumentList[0] = uno::makeAny( aProperty );
889cdf0e10cSrcweir 
890cdf0e10cSrcweir     uno::Reference< uno::XInterface > xConfigAccess;
891cdf0e10cSrcweir     xConfigAccess = xConfigurationProvider->createInstanceWithArguments( UNISTRING("com.sun.star.configuration.ConfigurationAccess"),
892cdf0e10cSrcweir                                                                          aArgumentList );
893cdf0e10cSrcweir 
894cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xNameAccess( xConfigAccess, uno::UNO_QUERY_THROW );
895cdf0e10cSrcweir 
896cdf0e10cSrcweir     rtl::OUString aProductVersion;
897cdf0e10cSrcweir     rtl::OUString aProductFullVersion;
898cdf0e10cSrcweir 
899cdf0e10cSrcweir     xNameAccess->getByName(UNISTRING("ooSetupVersion")) >>= aProductVersion;
900cdf0e10cSrcweir     aProductFullVersion = aProductVersion;
901cdf0e10cSrcweir 
902cdf0e10cSrcweir     sal_Int32 nVerIndex = rString.indexOf( aProductVersion );
903cdf0e10cSrcweir     if ( nVerIndex != -1 )
904cdf0e10cSrcweir     {
905cdf0e10cSrcweir         rtl::OUString aPackageVersion = UNISTRING( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("version") ":OOOPackageVersion}" );
906cdf0e10cSrcweir         rtl::Bootstrap::expandMacros( aPackageVersion );
907cdf0e10cSrcweir 
908cdf0e10cSrcweir         if ( aPackageVersion.getLength() )
909cdf0e10cSrcweir         {
910cdf0e10cSrcweir             sal_Int32 nTokIndex = 0;
911cdf0e10cSrcweir             rtl::OUString aVersionMinor = aPackageVersion.getToken( 1, '.', nTokIndex );
912cdf0e10cSrcweir             rtl::OUString aVersionMicro;
913cdf0e10cSrcweir 
914cdf0e10cSrcweir             if ( nTokIndex > 0 )
915cdf0e10cSrcweir                 aVersionMicro = aPackageVersion.getToken( 0, '.', nTokIndex );
916cdf0e10cSrcweir 
917cdf0e10cSrcweir             if ( aVersionMinor.getLength() == 0 )
918cdf0e10cSrcweir                 aVersionMinor = UNISTRING( "0" );
919cdf0e10cSrcweir             if ( aVersionMicro.getLength() == 0 )
920cdf0e10cSrcweir                 aVersionMicro = UNISTRING( "0" );
921cdf0e10cSrcweir 
922cdf0e10cSrcweir             sal_Int32 nIndex = aProductFullVersion.indexOf( '.' );
923cdf0e10cSrcweir             if ( nIndex == -1 )
924cdf0e10cSrcweir             {
925cdf0e10cSrcweir                 aProductFullVersion += UNISTRING( "." );
926cdf0e10cSrcweir                 aProductFullVersion += aVersionMinor;
927cdf0e10cSrcweir             }
928cdf0e10cSrcweir             else
929cdf0e10cSrcweir             {
930cdf0e10cSrcweir                 nIndex = aProductFullVersion.indexOf( '.', nIndex+1 );
931cdf0e10cSrcweir             }
932cdf0e10cSrcweir             if ( nIndex == -1 )
933cdf0e10cSrcweir             {
934cdf0e10cSrcweir                 aProductFullVersion += UNISTRING( "." );
935cdf0e10cSrcweir                 aProductFullVersion += aVersionMicro;
936cdf0e10cSrcweir             }
937cdf0e10cSrcweir             else
938cdf0e10cSrcweir             {
939cdf0e10cSrcweir                 aProductFullVersion = aProductFullVersion.replaceAt( nIndex+1, aProductFullVersion.getLength()-nIndex-1, aVersionMicro );
940cdf0e10cSrcweir             }
941cdf0e10cSrcweir         }
942cdf0e10cSrcweir         rString = rString.replaceAt( nVerIndex, aProductVersion.getLength(), aProductFullVersion );
943cdf0e10cSrcweir     }
944cdf0e10cSrcweir }
945cdf0e10cSrcweir 
946cdf0e10cSrcweir //--------------------------------------------------------------------
showWarning(const rtl::OUString & rWarningText) const947cdf0e10cSrcweir bool UpdateHandler::showWarning( const rtl::OUString &rWarningText ) const
948cdf0e10cSrcweir {
949cdf0e10cSrcweir     bool bRet = false;
950cdf0e10cSrcweir 
951*b838f725SArrigo Marchiori     ::vos::OGuard aGuard( Application::GetSolarMutex() );
952cdf0e10cSrcweir     uno::Reference< awt::XControl > xControl( mxUpdDlg, uno::UNO_QUERY );
953cdf0e10cSrcweir     if ( !xControl.is() ) return bRet;
954cdf0e10cSrcweir 
955cdf0e10cSrcweir     uno::Reference< awt::XWindowPeer > xPeer = xControl->getPeer();
956cdf0e10cSrcweir     if ( !xPeer.is() ) return bRet;
957cdf0e10cSrcweir 
958cdf0e10cSrcweir     uno::Reference< awt::XToolkit > xToolkit = xPeer->getToolkit();
959cdf0e10cSrcweir     if ( !xToolkit.is() ) return bRet;
960cdf0e10cSrcweir 
961cdf0e10cSrcweir     awt::WindowDescriptor aDescriptor;
962cdf0e10cSrcweir 
963cdf0e10cSrcweir     sal_Int32 nWindowAttributes = awt::WindowAttribute::BORDER | awt::WindowAttribute::MOVEABLE | awt::WindowAttribute::CLOSEABLE;
964cdf0e10cSrcweir     nWindowAttributes |= awt::VclWindowPeerAttribute::YES_NO;
965cdf0e10cSrcweir     nWindowAttributes |= awt::VclWindowPeerAttribute::DEF_NO;
966cdf0e10cSrcweir 
967cdf0e10cSrcweir     aDescriptor.Type              = awt::WindowClass_MODALTOP;
968cdf0e10cSrcweir     aDescriptor.WindowServiceName = UNISTRING( "warningbox" );
969cdf0e10cSrcweir     aDescriptor.ParentIndex       = -1;
970cdf0e10cSrcweir     aDescriptor.Parent            = xPeer;
971cdf0e10cSrcweir     aDescriptor.Bounds            = awt::Rectangle( 10, 10, 250, 150 );
972cdf0e10cSrcweir     aDescriptor.WindowAttributes  = nWindowAttributes;
973cdf0e10cSrcweir 
974cdf0e10cSrcweir     uno::Reference< awt::XMessageBox > xMsgBox( xToolkit->createWindow( aDescriptor ), uno::UNO_QUERY );
975cdf0e10cSrcweir     if ( xMsgBox.is() )
976cdf0e10cSrcweir     {
977cdf0e10cSrcweir         mbShowsMessageBox = true;
978cdf0e10cSrcweir         sal_Int16 nRet;
979cdf0e10cSrcweir         // xMsgBox->setCaptionText( msCancelTitle );
980cdf0e10cSrcweir         xMsgBox->setMessageText( rWarningText );
981cdf0e10cSrcweir         nRet = xMsgBox->execute();
982cdf0e10cSrcweir         if ( nRet == 2 ) // RET_YES == 2
983cdf0e10cSrcweir             bRet = true;
984cdf0e10cSrcweir         mbShowsMessageBox = false;
985cdf0e10cSrcweir     }
986cdf0e10cSrcweir 
987cdf0e10cSrcweir     uno::Reference< lang::XComponent > xComponent( xMsgBox, uno::UNO_QUERY );
988cdf0e10cSrcweir     if ( xComponent.is() )
989cdf0e10cSrcweir         xComponent->dispose();
990cdf0e10cSrcweir 
991cdf0e10cSrcweir     return bRet;
992cdf0e10cSrcweir }
993cdf0e10cSrcweir 
994cdf0e10cSrcweir //--------------------------------------------------------------------
showWarning(const rtl::OUString & rWarningText,const rtl::OUString & rBtnText_1,const rtl::OUString & rBtnText_2) const995cdf0e10cSrcweir bool UpdateHandler::showWarning( const rtl::OUString &rWarningText,
996cdf0e10cSrcweir                                  const rtl::OUString &rBtnText_1,
997cdf0e10cSrcweir                                  const rtl::OUString &rBtnText_2 ) const
998cdf0e10cSrcweir {
999cdf0e10cSrcweir     bool bRet = false;
1000cdf0e10cSrcweir 
1001*b838f725SArrigo Marchiori     ::vos::OGuard aGuard( Application::GetSolarMutex() );
1002cdf0e10cSrcweir     uno::Reference< awt::XControl > xControl( mxUpdDlg, uno::UNO_QUERY );
1003cdf0e10cSrcweir     if ( !xControl.is() ) return bRet;
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir     uno::Reference< awt::XWindowPeer > xPeer = xControl->getPeer();
1006cdf0e10cSrcweir     if ( !xPeer.is() ) return bRet;
1007cdf0e10cSrcweir 
1008cdf0e10cSrcweir     uno::Reference< awt::XToolkit > xToolkit = xPeer->getToolkit();
1009cdf0e10cSrcweir     if ( !xToolkit.is() ) return bRet;
1010cdf0e10cSrcweir 
1011cdf0e10cSrcweir     awt::WindowDescriptor aDescriptor;
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir     sal_Int32 nWindowAttributes = awt::WindowAttribute::BORDER | awt::WindowAttribute::MOVEABLE | awt::WindowAttribute::CLOSEABLE;
1014cdf0e10cSrcweir     nWindowAttributes |= awt::VclWindowPeerAttribute::YES_NO;
1015cdf0e10cSrcweir     nWindowAttributes |= awt::VclWindowPeerAttribute::DEF_NO;
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir     aDescriptor.Type              = awt::WindowClass_MODALTOP;
1018cdf0e10cSrcweir     aDescriptor.WindowServiceName = UNISTRING( "warningbox" );
1019cdf0e10cSrcweir     aDescriptor.ParentIndex       = -1;
1020cdf0e10cSrcweir     aDescriptor.Parent            = xPeer;
1021cdf0e10cSrcweir     aDescriptor.Bounds            = awt::Rectangle( 10, 10, 250, 150 );
1022cdf0e10cSrcweir     aDescriptor.WindowAttributes  = nWindowAttributes;
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir     uno::Reference< awt::XMessageBox > xMsgBox( xToolkit->createWindow( aDescriptor ), uno::UNO_QUERY );
1025cdf0e10cSrcweir     if ( xMsgBox.is() )
1026cdf0e10cSrcweir     {
1027cdf0e10cSrcweir         uno::Reference< awt::XVclContainer > xMsgBoxCtrls( xMsgBox, uno::UNO_QUERY );
1028cdf0e10cSrcweir         if ( xMsgBoxCtrls.is() )
1029cdf0e10cSrcweir         {
1030cdf0e10cSrcweir             uno::Sequence< uno::Reference< awt::XWindow > > xChildren = xMsgBoxCtrls->getWindows();
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir             for ( long i=0; i < xChildren.getLength(); i++ )
1033cdf0e10cSrcweir             {
1034cdf0e10cSrcweir                 uno::Reference< awt::XVclWindowPeer > xMsgBoxCtrl( xChildren[i], uno::UNO_QUERY );
1035cdf0e10cSrcweir                 if ( xMsgBoxCtrl.is() )
1036cdf0e10cSrcweir                 {
1037cdf0e10cSrcweir                     bool bIsDefault = true;
1038cdf0e10cSrcweir                     uno::Any aValue = xMsgBoxCtrl->getProperty( UNISTRING("DefaultButton") );
1039cdf0e10cSrcweir                     aValue >>= bIsDefault;
1040cdf0e10cSrcweir                     if ( bIsDefault )
1041cdf0e10cSrcweir                         xMsgBoxCtrl->setProperty( UNISTRING("Text"), uno::Any( rBtnText_1 ) );
1042cdf0e10cSrcweir                     else
1043cdf0e10cSrcweir                         xMsgBoxCtrl->setProperty( UNISTRING("Text"), uno::Any( rBtnText_2 ) );
1044cdf0e10cSrcweir                 }
1045cdf0e10cSrcweir             }
1046cdf0e10cSrcweir         }
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir         sal_Int16 nRet;
1049cdf0e10cSrcweir         // xMsgBox->setCaptionText( msCancelTitle );
1050cdf0e10cSrcweir         mbShowsMessageBox = true;
1051cdf0e10cSrcweir         xMsgBox->setMessageText( rWarningText );
1052cdf0e10cSrcweir         nRet = xMsgBox->execute();
1053cdf0e10cSrcweir         if ( nRet == 2 ) // RET_YES == 2
1054cdf0e10cSrcweir             bRet = true;
1055cdf0e10cSrcweir 
1056cdf0e10cSrcweir         mbShowsMessageBox = false;
1057cdf0e10cSrcweir     }
1058cdf0e10cSrcweir 
1059cdf0e10cSrcweir     uno::Reference< lang::XComponent > xComponent( xMsgBox, uno::UNO_QUERY );
1060cdf0e10cSrcweir     if ( xComponent.is() )
1061cdf0e10cSrcweir         xComponent->dispose();
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir     return bRet;
1064cdf0e10cSrcweir }
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir //--------------------------------------------------------------------
showOverwriteWarning(const rtl::OUString & rFileName) const1067cdf0e10cSrcweir bool UpdateHandler::showOverwriteWarning( const rtl::OUString& rFileName ) const
1068cdf0e10cSrcweir {
1069cdf0e10cSrcweir     rtl::OUString aMsg( msReloadWarning );
1070cdf0e10cSrcweir     searchAndReplaceAll( aMsg, UNISTRING( "%FILENAME" ), rFileName );
1071cdf0e10cSrcweir     searchAndReplaceAll( aMsg, UNISTRING( "%DOWNLOAD_PATH" ), msDownloadPath );
1072cdf0e10cSrcweir     return showWarning( aMsg, msReloadContinue, msReloadReload );
1073cdf0e10cSrcweir }
1074cdf0e10cSrcweir 
1075cdf0e10cSrcweir //--------------------------------------------------------------------
showOverwriteWarning() const1076cdf0e10cSrcweir bool UpdateHandler::showOverwriteWarning() const
1077cdf0e10cSrcweir {
1078cdf0e10cSrcweir     return showWarning( msOverwriteWarning );
1079cdf0e10cSrcweir }
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir //--------------------------------------------------------------------
1082cdf0e10cSrcweir #define BUTTON_HEIGHT       14
1083cdf0e10cSrcweir #define BUTTON_WIDTH        50
1084cdf0e10cSrcweir #define BUTTON_X_OFFSET      7
1085cdf0e10cSrcweir #define BUTTON_Y_OFFSET      3
1086cdf0e10cSrcweir #define LABEL_HEIGHT        10
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir #define DIALOG_WIDTH       300
1089cdf0e10cSrcweir #define DIALOG_BORDER        5
1090cdf0e10cSrcweir #define INNER_BORDER         3
1091cdf0e10cSrcweir #define TEXT_OFFSET          1
1092cdf0e10cSrcweir #define BOX_HEIGHT1          ( LABEL_HEIGHT + 3 * BUTTON_HEIGHT + 2 * BUTTON_Y_OFFSET + 2 * INNER_BORDER )
1093cdf0e10cSrcweir #define BOX_HEIGHT2         50
1094cdf0e10cSrcweir #define EDIT_WIDTH          ( DIALOG_WIDTH - 2 * DIALOG_BORDER )
1095cdf0e10cSrcweir #define BOX1_BTN_X          ( DIALOG_BORDER + EDIT_WIDTH - BUTTON_WIDTH - INNER_BORDER )
1096cdf0e10cSrcweir #define BOX1_BTN_Y          ( DIALOG_BORDER + LABEL_HEIGHT + INNER_BORDER)
1097d2971da9Smseidel #define THROBBER_WIDTH      32
1098d2971da9Smseidel #define THROBBER_HEIGHT     32
1099d2971da9Smseidel #define THROBBER_X_POS      ( DIALOG_BORDER + 3 )
1100cdf0e10cSrcweir #define THROBBER_Y_POS      ( DIALOG_BORDER + 23 )
1101cdf0e10cSrcweir #define BUTTON_BAR_HEIGHT   24
1102cdf0e10cSrcweir #define LABEL_OFFSET        ( LABEL_HEIGHT + 4 )
1103cdf0e10cSrcweir #define DIALOG_HEIGHT       ( BOX_HEIGHT1 + BOX_HEIGHT2 + LABEL_OFFSET + BUTTON_BAR_HEIGHT + 3 * DIALOG_BORDER )
1104cdf0e10cSrcweir #define LABEL_Y_POS         ( 2 * DIALOG_BORDER + BOX_HEIGHT1 )
1105cdf0e10cSrcweir #define EDIT2_Y_POS         ( LABEL_Y_POS + LABEL_HEIGHT )
1106cdf0e10cSrcweir #define BUTTON_BAR_Y_POS    ( EDIT2_Y_POS + DIALOG_BORDER + BOX_HEIGHT2 )
1107cdf0e10cSrcweir #define BUTTON_Y_POS        ( BUTTON_BAR_Y_POS + 8 )
1108cdf0e10cSrcweir #define CLOSE_BTN_X         ( DIALOG_WIDTH - DIALOG_BORDER - BUTTON_WIDTH )
1109cdf0e10cSrcweir #define INSTALL_BTN_X       ( CLOSE_BTN_X - 2 * BUTTON_X_OFFSET - BUTTON_WIDTH )
1110cdf0e10cSrcweir #define DOWNLOAD_BTN_X      ( INSTALL_BTN_X - BUTTON_X_OFFSET - BUTTON_WIDTH )
1111cdf0e10cSrcweir #define PROGRESS_WIDTH      80
1112cdf0e10cSrcweir #define PROGRESS_HEIGHT     10
1113cdf0e10cSrcweir #define PROGRESS_X_POS      ( DIALOG_BORDER + 8 )
1114cdf0e10cSrcweir #define PROGRESS_Y_POS      ( DIALOG_BORDER + 2 * LABEL_OFFSET )
1115cdf0e10cSrcweir 
1116cdf0e10cSrcweir //--------------------------------------------------------------------
showControls(short nControls)1117cdf0e10cSrcweir void UpdateHandler::showControls( short nControls )
1118cdf0e10cSrcweir {
1119cdf0e10cSrcweir     // The buttons from CANCEL_BUTTON to RESUME_BUTTON will be shown or
1120cdf0e10cSrcweir     // hidden on demand
1121cdf0e10cSrcweir     short nShiftMe;
1122cdf0e10cSrcweir     for ( int i = 0; i <= (int)RESUME_BUTTON; i++ )
1123cdf0e10cSrcweir     {
1124cdf0e10cSrcweir         nShiftMe = (short)(nControls >> i);
1125cdf0e10cSrcweir         showControl( msButtonIDs[i], (bool)(nShiftMe & 0x01) );
1126cdf0e10cSrcweir     }
1127cdf0e10cSrcweir 
1128cdf0e10cSrcweir     nShiftMe = (short)(nControls >> THROBBER_CTRL);
1129cdf0e10cSrcweir     startThrobber( (bool)(nShiftMe & 0x01) );
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir     nShiftMe = (short)(nControls >> PROGRESS_CTRL);
1132cdf0e10cSrcweir     showControl( CTRL_PROGRESS, (bool)(nShiftMe & 0x01) );
1133cdf0e10cSrcweir     showControl( TEXT_PERCENT, (bool)(nShiftMe & 0x01) );
1134cdf0e10cSrcweir 
1135cdf0e10cSrcweir     // Status text needs to be smaller, when there are buttons at the right side of the dialog
1136cdf0e10cSrcweir     if ( ( nControls & ( (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) ) ) != 0 )
1137cdf0e10cSrcweir         setControlProperty( TEXT_STATUS, UNISTRING("Width"), uno::Any( sal_Int32(EDIT_WIDTH - BUTTON_WIDTH - 2 * INNER_BORDER - TEXT_OFFSET ) ) );
1138cdf0e10cSrcweir     else
1139cdf0e10cSrcweir         setControlProperty( TEXT_STATUS, UNISTRING("Width"), uno::Any( sal_Int32(EDIT_WIDTH - 2 * TEXT_OFFSET ) ) );
1140cdf0e10cSrcweir 
1141cdf0e10cSrcweir     // Status text needs to be taller, when we show the progress bar
1142cdf0e10cSrcweir     if ( ( nControls & ( 1<<PROGRESS_CTRL ) ) != 0 )
1143cdf0e10cSrcweir         setControlProperty( TEXT_STATUS, UNISTRING("Height"), uno::Any( sal_Int32(LABEL_HEIGHT) ) );
1144cdf0e10cSrcweir     else
1145cdf0e10cSrcweir         setControlProperty( TEXT_STATUS, UNISTRING("Height"), uno::Any( sal_Int32(BOX_HEIGHT1 - 4 * TEXT_OFFSET - LABEL_HEIGHT ) ) );
1146cdf0e10cSrcweir }
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir //--------------------------------------------------------------------
createDialog()1149cdf0e10cSrcweir void UpdateHandler::createDialog()
1150cdf0e10cSrcweir {
1151cdf0e10cSrcweir     if ( !mxContext.is() )
1152cdf0e10cSrcweir     {
1153cdf0e10cSrcweir         OSL_ASSERT( false );
1154cdf0e10cSrcweir         return;
1155cdf0e10cSrcweir     }
1156cdf0e10cSrcweir 
1157cdf0e10cSrcweir     uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager() );
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir     if( xServiceManager.is() )
1160cdf0e10cSrcweir     {
1161cdf0e10cSrcweir         uno::Reference< frame::XDesktop > xDesktop(
1162cdf0e10cSrcweir                 xServiceManager->createInstanceWithContext( UNISTRING( "com.sun.star.frame.Desktop"), mxContext ),
1163cdf0e10cSrcweir                 uno::UNO_QUERY );
1164cdf0e10cSrcweir         if ( xDesktop.is() )
1165cdf0e10cSrcweir             xDesktop->addTerminateListener( this );
1166cdf0e10cSrcweir     }
1167cdf0e10cSrcweir 
1168cdf0e10cSrcweir     loadStrings();
1169cdf0e10cSrcweir 
1170*b838f725SArrigo Marchiori     ::vos::OGuard aGuard( Application::GetSolarMutex() );
1171cdf0e10cSrcweir     uno::Reference< lang::XMultiComponentFactory > xFactory( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
1172cdf0e10cSrcweir     uno::Reference< awt::XControlModel > xControlModel( xFactory->createInstanceWithContext(
1173cdf0e10cSrcweir                                                          UNISTRING("com.sun.star.awt.UnoControlDialogModel"),
1174cdf0e10cSrcweir                                                          mxContext), uno::UNO_QUERY_THROW );
1175cdf0e10cSrcweir     {
1176cdf0e10cSrcweir         // @see awt/UnoControlDialogModel.idl
1177cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY_THROW );
1178cdf0e10cSrcweir 
1179cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("Title"), uno::Any( msDlgTitle ) );
1180cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("Closeable"), uno::Any( true ) );
1181cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("Enabled"), uno::Any( true ) );
1182cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("Moveable"), uno::Any( true ) );
1183cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("Sizeable"), uno::Any( true ) );
1184cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("DesktopAsParent"), uno::Any( true ) );
1185cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("PositionX"), uno::Any(sal_Int32( 100 )) );
1186cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("PositionY"), uno::Any(sal_Int32( 100 )) );
1187cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("Width"), uno::Any(sal_Int32( DIALOG_WIDTH )) );
1188cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("Height"), uno::Any(sal_Int32( DIALOG_HEIGHT )) );
1189cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_DLG ) ) );
1190cdf0e10cSrcweir     }
1191cdf0e10cSrcweir     {   // Label (fixed text) <status>
1192cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(1);
1193cdf0e10cSrcweir 
1194cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("Label"), uno::Any( msStatusFL ) );
1195cdf0e10cSrcweir 
1196cdf0e10cSrcweir         insertControlModel( xControlModel, FIXED_TEXT_MODEL, UNISTRING( "fixedLineStatus" ),
1197cdf0e10cSrcweir                             awt::Rectangle( DIALOG_BORDER+1, DIALOG_BORDER, EDIT_WIDTH-2, LABEL_HEIGHT ),
1198cdf0e10cSrcweir                             aProps );
1199cdf0e10cSrcweir     }
1200cdf0e10cSrcweir     {   // box around <status> text
1201cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps;
1202cdf0e10cSrcweir 
1203cdf0e10cSrcweir         insertControlModel( xControlModel, GROUP_BOX_MODEL, UNISTRING( "StatusBox" ),
1204cdf0e10cSrcweir                             awt::Rectangle( DIALOG_BORDER, DIALOG_BORDER + LABEL_HEIGHT, EDIT_WIDTH, BOX_HEIGHT1 - LABEL_HEIGHT ),
1205cdf0e10cSrcweir                             aProps );
1206cdf0e10cSrcweir     }
1207cdf0e10cSrcweir     {   // Text (multiline edit) <status>
1208cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(7);
1209cdf0e10cSrcweir 
1210cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("Text"), uno::Any( substVariables(msChecking) ) );
1211cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Border"), uno::Any( sal_Int16( 0 ) ) );
1212cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PaintTransparent"), uno::Any( true ) );
1213cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("MultiLine"), uno::Any( true ) );
1214cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("ReadOnly"), uno::Any( true ) );
1215cdf0e10cSrcweir         setProperty( aProps, 5, UNISTRING("AutoVScroll"), uno::Any( true ) );
1216cdf0e10cSrcweir         setProperty( aProps, 6, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_STATUS ) ) );
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir         insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_STATUS,
1219cdf0e10cSrcweir                             awt::Rectangle( DIALOG_BORDER + TEXT_OFFSET,
1220cdf0e10cSrcweir                                             DIALOG_BORDER + LABEL_HEIGHT + TEXT_OFFSET,
1221cdf0e10cSrcweir                                             EDIT_WIDTH - 2*TEXT_OFFSET,
1222cdf0e10cSrcweir                                             BOX_HEIGHT1 - 4*TEXT_OFFSET - LABEL_HEIGHT ),
1223cdf0e10cSrcweir                             aProps );
1224cdf0e10cSrcweir     }
1225cdf0e10cSrcweir     {   // Text (edit) <percent>
1226cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(4);
1227cdf0e10cSrcweir 
1228cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("Text"), uno::Any( msPercent ) );
1229cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Border"), uno::Any( sal_Int16( 0 ) ) );
1230cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PaintTransparent"), uno::Any( true ) );
1231cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("ReadOnly"), uno::Any( true ) );
1232cdf0e10cSrcweir 
1233cdf0e10cSrcweir         insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_PERCENT,
1234cdf0e10cSrcweir                             awt::Rectangle( PROGRESS_X_POS + PROGRESS_WIDTH + DIALOG_BORDER,
1235cdf0e10cSrcweir                                             PROGRESS_Y_POS,
1236cdf0e10cSrcweir                                             EDIT_WIDTH - PROGRESS_WIDTH - BUTTON_WIDTH - 2*DIALOG_BORDER,
1237cdf0e10cSrcweir                                             LABEL_HEIGHT ),
1238cdf0e10cSrcweir                             aProps );
1239cdf0e10cSrcweir     }
1240cdf0e10cSrcweir     {   // pause button
1241cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(5);
1242cdf0e10cSrcweir 
1243cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1244cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1245cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1246cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msPauseBtn ) );
1247cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_PAUSE ) ) );
1248cdf0e10cSrcweir 
1249cdf0e10cSrcweir         insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[PAUSE_BUTTON],
1250cdf0e10cSrcweir                              awt::Rectangle( BOX1_BTN_X, BOX1_BTN_Y, BUTTON_WIDTH, BUTTON_HEIGHT ),
1251cdf0e10cSrcweir                              aProps );
1252cdf0e10cSrcweir     }
1253cdf0e10cSrcweir     {   // resume button
1254cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(5);
1255cdf0e10cSrcweir 
1256cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1257cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1258cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1259cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msResumeBtn ) );
1260cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_RESUME ) ) );
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir         insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[RESUME_BUTTON],
1263cdf0e10cSrcweir                              awt::Rectangle( BOX1_BTN_X,
1264cdf0e10cSrcweir                                              BOX1_BTN_Y + BUTTON_Y_OFFSET + BUTTON_HEIGHT,
1265cdf0e10cSrcweir                                              BUTTON_WIDTH,
1266cdf0e10cSrcweir                                              BUTTON_HEIGHT ),
1267cdf0e10cSrcweir                              aProps );
1268cdf0e10cSrcweir     }
1269cdf0e10cSrcweir     {   // abort button
1270cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(5);
1271cdf0e10cSrcweir 
1272cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1273cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1274cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1275cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msCancelBtn ) );
1276cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_CANCEL ) ) );
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir         insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[CANCEL_BUTTON],
1279cdf0e10cSrcweir                              awt::Rectangle( BOX1_BTN_X,
1280cdf0e10cSrcweir                                              BOX1_BTN_Y + (2 * (BUTTON_HEIGHT+BUTTON_Y_OFFSET)),
1281cdf0e10cSrcweir                                              BUTTON_WIDTH,
1282cdf0e10cSrcweir                                              BUTTON_HEIGHT ),
1283cdf0e10cSrcweir                              aProps );
1284cdf0e10cSrcweir     }
1285cdf0e10cSrcweir     {   // Label (FixedText) <description>
1286cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(1);
1287cdf0e10cSrcweir 
1288cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("Label"), uno::Any( msDescription ) );
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir         insertControlModel( xControlModel, FIXED_TEXT_MODEL, UNISTRING( "fixedTextDescription" ),
1291cdf0e10cSrcweir                             awt::Rectangle( DIALOG_BORDER+1, LABEL_Y_POS, EDIT_WIDTH-2, LABEL_HEIGHT ),
1292cdf0e10cSrcweir                             aProps );
1293cdf0e10cSrcweir     }
1294cdf0e10cSrcweir     {   // box around <description> text
1295cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps;
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir         insertControlModel( xControlModel, GROUP_BOX_MODEL, UNISTRING( "DescriptionBox" ),
1298cdf0e10cSrcweir                             awt::Rectangle( DIALOG_BORDER, EDIT2_Y_POS, EDIT_WIDTH, BOX_HEIGHT2 ),
1299cdf0e10cSrcweir                             aProps );
1300cdf0e10cSrcweir     }
1301cdf0e10cSrcweir     {   // Text (MultiLineEdit) <description>
1302cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(7);
1303cdf0e10cSrcweir 
1304cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("Text"), uno::Any( rtl::OUString() ) );
1305cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Border"), uno::Any( sal_Int16( 0 ) ) );
1306cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PaintTransparent"), uno::Any( true ) );
1307cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("MultiLine"), uno::Any( true ) );
1308cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("ReadOnly"), uno::Any( true ) );
1309cdf0e10cSrcweir         setProperty( aProps, 5, UNISTRING("AutoVScroll"), uno::Any( true ) );
1310cdf0e10cSrcweir         setProperty( aProps, 6, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_DESCRIPTION ) ) );
1311cdf0e10cSrcweir 
1312cdf0e10cSrcweir         insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_DESCRIPTION,
1313cdf0e10cSrcweir                             awt::Rectangle( DIALOG_BORDER + TEXT_OFFSET,
1314cdf0e10cSrcweir                                             EDIT2_Y_POS + 2*TEXT_OFFSET,
1315cdf0e10cSrcweir                                             EDIT_WIDTH - 3*TEXT_OFFSET,
1316cdf0e10cSrcweir                                             BOX_HEIGHT2 - 3*TEXT_OFFSET ),
1317cdf0e10cSrcweir                             aProps );
1318cdf0e10cSrcweir     }
1319cdf0e10cSrcweir     {   // @see awt/UnoControlFixedLineModel.idl
1320cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(1);
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("Orientation"), uno::Any( sal_Int32( 0 ) ) );
1323cdf0e10cSrcweir 
1324cdf0e10cSrcweir         insertControlModel( xControlModel, FIXED_LINE_MODEL, UNISTRING("fixedLine"),
1325cdf0e10cSrcweir                             awt::Rectangle( 0, BUTTON_BAR_Y_POS, DIALOG_WIDTH, 5 ),
1326cdf0e10cSrcweir                             aProps );
1327cdf0e10cSrcweir     }
1328cdf0e10cSrcweir     {   // close button // @see awt/UnoControlButtonModel.idl
1329cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(5);
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1332cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1333cdf0e10cSrcweir         // [property] short PushButtonType
1334cdf0e10cSrcweir         // with own "ButtonActionListener"
1335cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1336cdf0e10cSrcweir         // with default ActionListener => endDialog().
1337cdf0e10cSrcweir         // setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_CANCEL) ) );
1338cdf0e10cSrcweir         // [property] string Label // only if PushButtonType_STANDARD
1339cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msClose ) );
1340cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_CLOSE ) ) );
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir         insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[ CLOSE_BUTTON ],
1343cdf0e10cSrcweir                              awt::Rectangle( CLOSE_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1344cdf0e10cSrcweir                              aProps );
1345cdf0e10cSrcweir     }
1346cdf0e10cSrcweir     {   // install button
1347cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(5);
1348cdf0e10cSrcweir 
1349cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1350cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1351cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1352cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msInstall ) );
1353cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_INSTALL ) ) );
1354cdf0e10cSrcweir 
1355cdf0e10cSrcweir         insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[INSTALL_BUTTON],
1356cdf0e10cSrcweir                              awt::Rectangle( INSTALL_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1357cdf0e10cSrcweir                              aProps );
1358cdf0e10cSrcweir     }
1359cdf0e10cSrcweir     {   // download button
1360cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(5);
1361cdf0e10cSrcweir 
1362cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1363cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1364cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1365cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msDownload ) );
1366cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_DOWNLOAD ) ) );
1367cdf0e10cSrcweir 
1368cdf0e10cSrcweir         insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[DOWNLOAD_BUTTON],
1369cdf0e10cSrcweir                              awt::Rectangle( DOWNLOAD_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1370cdf0e10cSrcweir                              aProps );
1371cdf0e10cSrcweir     }
1372cdf0e10cSrcweir     {   // help button
1373cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(3);
1374cdf0e10cSrcweir 
1375cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1376cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1377cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_HELP) ) );
1378cdf0e10cSrcweir 
1379cdf0e10cSrcweir         insertControlModel( xControlModel, BUTTON_MODEL, msButtonIDs[HELP_BUTTON],
1380cdf0e10cSrcweir                             awt::Rectangle( DIALOG_BORDER, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1381cdf0e10cSrcweir                             aProps );
1382cdf0e10cSrcweir     }
1383cdf0e10cSrcweir     {   // @see awt/UnoControlThrobberModel.idl
1384cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps;
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir         insertControlModel( xControlModel, UNISTRING("com.sun.star.awt.SpinningProgressControlModel"), CTRL_THROBBER,
1387cdf0e10cSrcweir                             awt::Rectangle( THROBBER_X_POS, THROBBER_Y_POS, THROBBER_WIDTH, THROBBER_HEIGHT),
1388cdf0e10cSrcweir                             aProps );
1389cdf0e10cSrcweir     }
1390cdf0e10cSrcweir     {    // @see awt/UnoControlProgressBarModel.idl
1391cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(4);
1392cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("Enabled"), uno::Any( true ) );
1393cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("ProgressValue"), uno::Any( sal_Int32( 0 ) ) );
1394cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("ProgressValueMax"), uno::Any( sal_Int32( 100 ) ) );
1395cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("ProgressValueMin"), uno::Any( sal_Int32( 0 ) ) );
1396cdf0e10cSrcweir 
1397cdf0e10cSrcweir         insertControlModel( xControlModel, UNISTRING("com.sun.star.awt.UnoControlProgressBarModel"), CTRL_PROGRESS,
1398cdf0e10cSrcweir                             awt::Rectangle( PROGRESS_X_POS, PROGRESS_Y_POS, PROGRESS_WIDTH, PROGRESS_HEIGHT ),
1399cdf0e10cSrcweir                             aProps);
1400cdf0e10cSrcweir     }
1401cdf0e10cSrcweir 
1402cdf0e10cSrcweir     uno::Reference< awt::XControl > xControl(
1403cdf0e10cSrcweir         xFactory->createInstanceWithContext( UNISTRING("com.sun.star.awt.UnoControlDialog"), mxContext),
1404cdf0e10cSrcweir         uno::UNO_QUERY_THROW );
1405cdf0e10cSrcweir     xControl->setModel( xControlModel );
1406cdf0e10cSrcweir 
1407cdf0e10cSrcweir     if ( mbVisible == false )
1408cdf0e10cSrcweir     {
1409cdf0e10cSrcweir         uno::Reference< awt::XWindow > xWindow( xControl, uno::UNO_QUERY );
1410cdf0e10cSrcweir 
1411cdf0e10cSrcweir         if ( xWindow.is() )
1412cdf0e10cSrcweir             xWindow->setVisible( false );
1413cdf0e10cSrcweir     }
1414cdf0e10cSrcweir 
1415cdf0e10cSrcweir     xControl->createPeer( NULL, NULL );
1416cdf0e10cSrcweir     {
1417cdf0e10cSrcweir         uno::Reference< awt::XControlContainer > xContainer (xControl, uno::UNO_QUERY);
1418cdf0e10cSrcweir         for ( int i = 0; i < HELP_BUTTON; i++ )
1419cdf0e10cSrcweir         {
1420cdf0e10cSrcweir             uno::Reference< awt::XButton > xButton ( xContainer->getControl( msButtonIDs[i] ), uno::UNO_QUERY);
1421cdf0e10cSrcweir             if (xButton.is())
1422cdf0e10cSrcweir             {
1423cdf0e10cSrcweir                 xButton->setActionCommand( msButtonIDs[i] );
1424cdf0e10cSrcweir                 xButton->addActionListener( this );
1425cdf0e10cSrcweir             }
1426cdf0e10cSrcweir         }
1427cdf0e10cSrcweir     }
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir     mxUpdDlg.set( xControl, uno::UNO_QUERY_THROW );
1430cdf0e10cSrcweir     mnLastCtrlState = -1;
1431cdf0e10cSrcweir }
14326ed1dc3eSmseidel 
1433d2971da9Smseidel /* vim: set noet sw=4 ts=4: */
1434