xref: /AOO41X/main/desktop/source/deployment/gui/dp_gui_updatedialog.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_desktop.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "sal/config.h"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <cstddef>
34*cdf0e10cSrcweir #include <limits>
35*cdf0e10cSrcweir #include <map>
36*cdf0e10cSrcweir #include <memory>
37*cdf0e10cSrcweir #include <utility>
38*cdf0e10cSrcweir #include <vector>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include "boost/optional.hpp"
42*cdf0e10cSrcweir #include "com/sun/star/awt/Rectangle.hpp"
43*cdf0e10cSrcweir #include "com/sun/star/awt/WindowAttribute.hpp"
44*cdf0e10cSrcweir #include "com/sun/star/awt/WindowClass.hpp"
45*cdf0e10cSrcweir #include "com/sun/star/awt/WindowDescriptor.hpp"
46*cdf0e10cSrcweir #include "com/sun/star/awt/XToolkit.hpp"
47*cdf0e10cSrcweir #include "com/sun/star/awt/XWindow.hpp"
48*cdf0e10cSrcweir #include "com/sun/star/awt/XWindowPeer.hpp"
49*cdf0e10cSrcweir #include "com/sun/star/beans/NamedValue.hpp"
50*cdf0e10cSrcweir #include "com/sun/star/beans/Optional.hpp"
51*cdf0e10cSrcweir #include "com/sun/star/beans/PropertyValue.hpp"
52*cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp"
53*cdf0e10cSrcweir #include "com/sun/star/container/XNameAccess.hpp"
54*cdf0e10cSrcweir #include "com/sun/star/container/XNameContainer.hpp"
55*cdf0e10cSrcweir #include "com/sun/star/deployment/DeploymentException.hpp"
56*cdf0e10cSrcweir #include "com/sun/star/deployment/UpdateInformationProvider.hpp"
57*cdf0e10cSrcweir #include "com/sun/star/deployment/XPackage.hpp"
58*cdf0e10cSrcweir #include "com/sun/star/deployment/XExtensionManager.hpp"
59*cdf0e10cSrcweir #include "com/sun/star/deployment/ExtensionManager.hpp"
60*cdf0e10cSrcweir #include "com/sun/star/deployment/XUpdateInformationProvider.hpp"
61*cdf0e10cSrcweir #include "com/sun/star/frame/XDesktop.hpp"
62*cdf0e10cSrcweir #include "com/sun/star/frame/XDispatch.hpp"
63*cdf0e10cSrcweir #include "com/sun/star/frame/XDispatchProvider.hpp"
64*cdf0e10cSrcweir #include "com/sun/star/lang/IllegalArgumentException.hpp"
65*cdf0e10cSrcweir #include "com/sun/star/lang/XMultiComponentFactory.hpp"
66*cdf0e10cSrcweir #include "com/sun/star/lang/XSingleServiceFactory.hpp"
67*cdf0e10cSrcweir #include "com/sun/star/system/SystemShellExecuteFlags.hpp"
68*cdf0e10cSrcweir #include "com/sun/star/system/XSystemShellExecute.hpp"
69*cdf0e10cSrcweir #include "com/sun/star/task/XAbortChannel.hpp"
70*cdf0e10cSrcweir #include "com/sun/star/task/XJob.hpp"
71*cdf0e10cSrcweir #include "com/sun/star/ucb/CommandAbortedException.hpp"
72*cdf0e10cSrcweir #include "com/sun/star/ucb/CommandFailedException.hpp"
73*cdf0e10cSrcweir #include "com/sun/star/ucb/XCommandEnvironment.hpp"
74*cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx"
75*cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
76*cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
77*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
78*cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
79*cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
80*cdf0e10cSrcweir #include "com/sun/star/util/URL.hpp"
81*cdf0e10cSrcweir #include "com/sun/star/util/XChangesBatch.hpp"
82*cdf0e10cSrcweir #include "com/sun/star/util/XURLTransformer.hpp"
83*cdf0e10cSrcweir #include "com/sun/star/xml/dom/XElement.hpp"
84*cdf0e10cSrcweir #include "com/sun/star/xml/dom/XNode.hpp"
85*cdf0e10cSrcweir #include "osl/diagnose.h"
86*cdf0e10cSrcweir #include "rtl/bootstrap.hxx"
87*cdf0e10cSrcweir #include "rtl/ref.hxx"
88*cdf0e10cSrcweir #include "rtl/string.h"
89*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
90*cdf0e10cSrcweir #include "rtl/ustring.h"
91*cdf0e10cSrcweir #include "rtl/ustring.hxx"
92*cdf0e10cSrcweir #include "sal/types.h"
93*cdf0e10cSrcweir #include "svtools/svlbitm.hxx"
94*cdf0e10cSrcweir #include "svtools/svlbox.hxx"
95*cdf0e10cSrcweir #include <svtools/controldims.hrc>
96*cdf0e10cSrcweir #include "svx/checklbx.hxx"
97*cdf0e10cSrcweir #include "tools/gen.hxx"
98*cdf0e10cSrcweir #include "tools/link.hxx"
99*cdf0e10cSrcweir #include "tools/resid.hxx"
100*cdf0e10cSrcweir #include "tools/resmgr.hxx"
101*cdf0e10cSrcweir #include "tools/solar.h"
102*cdf0e10cSrcweir #include "tools/string.hxx"
103*cdf0e10cSrcweir #include "vcl/button.hxx"
104*cdf0e10cSrcweir #include "vcl/dialog.hxx"
105*cdf0e10cSrcweir #include "vcl/fixed.hxx"
106*cdf0e10cSrcweir #include "vcl/image.hxx"
107*cdf0e10cSrcweir #include "vcl/msgbox.hxx"
108*cdf0e10cSrcweir #include "vcl/svapp.hxx"
109*cdf0e10cSrcweir #include "vos/mutex.hxx"
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir #include "comphelper/processfactory.hxx"
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir #include "dp_dependencies.hxx"
114*cdf0e10cSrcweir #include "dp_descriptioninfoset.hxx"
115*cdf0e10cSrcweir #include "dp_identifier.hxx"
116*cdf0e10cSrcweir #include "dp_version.hxx"
117*cdf0e10cSrcweir #include "dp_misc.h"
118*cdf0e10cSrcweir #include "dp_update.hxx"
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir #include "dp_gui.h"
121*cdf0e10cSrcweir #include "dp_gui.hrc"
122*cdf0e10cSrcweir #include "dp_gui_thread.hxx"
123*cdf0e10cSrcweir #include "dp_gui_updatedata.hxx"
124*cdf0e10cSrcweir #include "dp_gui_updatedialog.hxx"
125*cdf0e10cSrcweir #include "dp_gui_shared.hxx"
126*cdf0e10cSrcweir #include "dp_gui_system.hxx"
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir class KeyEvent;
129*cdf0e10cSrcweir class MouseEvent;
130*cdf0e10cSrcweir class Window;
131*cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace uno {
132*cdf0e10cSrcweir     class XComponentContext;
133*cdf0e10cSrcweir } } } }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir using namespace ::com::sun::star;
136*cdf0e10cSrcweir using dp_gui::UpdateDialog;
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir namespace {
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir static sal_Unicode const LF = 0x000A;
141*cdf0e10cSrcweir static sal_Unicode const CR = 0x000D;
142*cdf0e10cSrcweir static const sal_uInt16 CMD_ENABLE_UPDATE = 1;
143*cdf0e10cSrcweir static const sal_uInt16 CMD_IGNORE_UPDATE = 2;
144*cdf0e10cSrcweir static const sal_uInt16 CMD_IGNORE_ALL_UPDATES = 3;
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir #define IGNORED_UPDATES     OUSTR("/org.openoffice.Office.ExtensionManager/ExtensionUpdateData/IgnoredUpdates")
149*cdf0e10cSrcweir #define PROPERTY_VERSION    OUSTR("Version")
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir enum Kind { ENABLED_UPDATE, DISABLED_UPDATE, SPECIFIC_ERROR };
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir rtl::OUString confineToParagraph(rtl::OUString const & text) {
154*cdf0e10cSrcweir     // Confine arbitrary text to a single paragraph in a dp_gui::AutoScrollEdit.
155*cdf0e10cSrcweir     // This assumes that U+000A and U+000D are the only paragraph separators in
156*cdf0e10cSrcweir     // a dp_gui::AutoScrollEdit, and that replacing them with a single space
157*cdf0e10cSrcweir     // each is acceptable:
158*cdf0e10cSrcweir     return text.replace(LF, ' ').replace(CR, ' ');
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir struct UpdateDialog::DisabledUpdate {
163*cdf0e10cSrcweir     rtl::OUString name;
164*cdf0e10cSrcweir     uno::Sequence< rtl::OUString > unsatisfiedDependencies;
165*cdf0e10cSrcweir     // We also want to show release notes and publisher for disabled updates
166*cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XNode > aUpdateInfo;
167*cdf0e10cSrcweir     sal_uInt16 m_nID;
168*cdf0e10cSrcweir };
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir struct UpdateDialog::SpecificError {
171*cdf0e10cSrcweir     rtl::OUString name;
172*cdf0e10cSrcweir     rtl::OUString message;
173*cdf0e10cSrcweir     sal_uInt16 m_nID;
174*cdf0e10cSrcweir };
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir //------------------------------------------------------------------------------
177*cdf0e10cSrcweir struct UpdateDialog::IgnoredUpdate {
178*cdf0e10cSrcweir     rtl::OUString sExtensionID;
179*cdf0e10cSrcweir     rtl::OUString sVersion;
180*cdf0e10cSrcweir     bool          bRemoved;
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir     IgnoredUpdate( const rtl::OUString &rExtensionID, const rtl::OUString &rVersion );
183*cdf0e10cSrcweir };
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir //------------------------------------------------------------------------------
186*cdf0e10cSrcweir UpdateDialog::IgnoredUpdate::IgnoredUpdate( const rtl::OUString &rExtensionID, const rtl::OUString &rVersion ):
187*cdf0e10cSrcweir     sExtensionID( rExtensionID ),
188*cdf0e10cSrcweir     sVersion( rVersion ),
189*cdf0e10cSrcweir     bRemoved( false )
190*cdf0e10cSrcweir {}
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir //------------------------------------------------------------------------------
193*cdf0e10cSrcweir struct UpdateDialog::Index
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir     Kind          m_eKind;
196*cdf0e10cSrcweir     bool          m_bIgnored;
197*cdf0e10cSrcweir     sal_uInt16        m_nID;
198*cdf0e10cSrcweir     sal_uInt16        m_nIndex;
199*cdf0e10cSrcweir     rtl::OUString m_aName;
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir     Index( Kind theKind, sal_uInt16 nID, sal_uInt16 nIndex, const rtl::OUString &rName );
202*cdf0e10cSrcweir };
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir //------------------------------------------------------------------------------
205*cdf0e10cSrcweir UpdateDialog::Index::Index( Kind theKind, sal_uInt16 nID, sal_uInt16 nIndex, const rtl::OUString &rName ):
206*cdf0e10cSrcweir     m_eKind( theKind ),
207*cdf0e10cSrcweir     m_bIgnored( false ),
208*cdf0e10cSrcweir     m_nID( nID ),
209*cdf0e10cSrcweir     m_nIndex( nIndex ),
210*cdf0e10cSrcweir     m_aName( rName )
211*cdf0e10cSrcweir {}
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir //------------------------------------------------------------------------------
214*cdf0e10cSrcweir //------------------------------------------------------------------------------
215*cdf0e10cSrcweir //------------------------------------------------------------------------------
216*cdf0e10cSrcweir class UpdateDialog::Thread: public dp_gui::Thread {
217*cdf0e10cSrcweir public:
218*cdf0e10cSrcweir     Thread(
219*cdf0e10cSrcweir         uno::Reference< uno::XComponentContext > const & context,
220*cdf0e10cSrcweir         UpdateDialog & dialog,
221*cdf0e10cSrcweir         const std::vector< uno::Reference< deployment::XPackage >  > & vExtensionList);
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir     void stop();
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir private:
226*cdf0e10cSrcweir     Thread(UpdateDialog::Thread &); // not defined
227*cdf0e10cSrcweir     void operator =(UpdateDialog::Thread &); // not defined
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir     struct Entry {
230*cdf0e10cSrcweir         explicit Entry(
231*cdf0e10cSrcweir             uno::Reference< deployment::XPackage > const & thePackage,
232*cdf0e10cSrcweir             rtl::OUString const & theVersion);
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir         uno::Reference< deployment::XPackage > package;
235*cdf0e10cSrcweir         rtl::OUString version;
236*cdf0e10cSrcweir         //Indicates that the extension provides its own update URLs.
237*cdf0e10cSrcweir         //If this is true, then we must not use the default update
238*cdf0e10cSrcweir         //URL to find the update information.
239*cdf0e10cSrcweir         bool bProvidesOwnUpdate;
240*cdf0e10cSrcweir         uno::Reference< xml::dom::XNode > info;
241*cdf0e10cSrcweir 	    UpdateDialog::DisabledUpdate disableUpdate;
242*cdf0e10cSrcweir 	    dp_gui::UpdateData updateData;
243*cdf0e10cSrcweir     };
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir     // A multimap in case an extension is installed in "user", "shared" or "bundled"
246*cdf0e10cSrcweir     typedef std::map< rtl::OUString, Entry > Map;
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir     virtual ~Thread();
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir     virtual void execute();
251*cdf0e10cSrcweir #if 0
252*cdf0e10cSrcweir     void handleGeneralError(uno::Any const & exception) const;
253*cdf0e10cSrcweir #endif
254*cdf0e10cSrcweir     void handleSpecificError(
255*cdf0e10cSrcweir         uno::Reference< deployment::XPackage > const & package,
256*cdf0e10cSrcweir         uno::Any const & exception) const;
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir     uno::Sequence< uno::Reference< xml::dom::XElement > >
259*cdf0e10cSrcweir     getUpdateInformation(
260*cdf0e10cSrcweir         uno::Reference< deployment::XPackage > const & package,
261*cdf0e10cSrcweir         uno::Sequence< rtl::OUString > const & urls,
262*cdf0e10cSrcweir         rtl::OUString const & identifier) const;
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     void getOwnUpdateInformation(
265*cdf0e10cSrcweir         uno::Reference< deployment::XPackage > const & package,
266*cdf0e10cSrcweir         Map * map);
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir     ::rtl::OUString getUpdateDisplayString(
269*cdf0e10cSrcweir         dp_gui::UpdateData const & data, ::rtl::OUString const & version = ::rtl::OUString()) const;
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir     void prepareUpdateData(
272*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XNode > const & updateInfo,
273*cdf0e10cSrcweir         UpdateDialog::DisabledUpdate & out_du,
274*cdf0e10cSrcweir         dp_gui::UpdateData & out_data) const;
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir     bool update(
277*cdf0e10cSrcweir         UpdateDialog::DisabledUpdate & du,
278*cdf0e10cSrcweir         dp_gui::UpdateData & data) const;
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir     uno::Reference< uno::XComponentContext > m_context;
281*cdf0e10cSrcweir     UpdateDialog & m_dialog;
282*cdf0e10cSrcweir     std::vector< uno::Reference< deployment::XPackage > > m_vExtensionList;
283*cdf0e10cSrcweir     uno::Reference< deployment::XUpdateInformationProvider > m_updateInformation;
284*cdf0e10cSrcweir     uno::Reference< task::XInteractionHandler > m_xInteractionHdl;
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir     // guarded by Application::GetSolarMutex():
287*cdf0e10cSrcweir     uno::Reference< task::XAbortChannel > m_abort;
288*cdf0e10cSrcweir     bool m_stop;
289*cdf0e10cSrcweir };
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir UpdateDialog::Thread::Thread(
292*cdf0e10cSrcweir     uno::Reference< uno::XComponentContext > const & context,
293*cdf0e10cSrcweir     UpdateDialog & dialog,
294*cdf0e10cSrcweir     const std::vector< uno::Reference< deployment::XPackage > > &vExtensionList):
295*cdf0e10cSrcweir     m_context(context),
296*cdf0e10cSrcweir     m_dialog(dialog),
297*cdf0e10cSrcweir     m_vExtensionList(vExtensionList),
298*cdf0e10cSrcweir     m_updateInformation(
299*cdf0e10cSrcweir         deployment::UpdateInformationProvider::create(context)),
300*cdf0e10cSrcweir     m_stop(false)
301*cdf0e10cSrcweir {
302*cdf0e10cSrcweir     if( m_context.is() )
303*cdf0e10cSrcweir     {
304*cdf0e10cSrcweir         uno::Reference< lang::XMultiComponentFactory > xServiceManager( m_context->getServiceManager() );
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir         if( xServiceManager.is() )
307*cdf0e10cSrcweir         {
308*cdf0e10cSrcweir             m_xInteractionHdl = uno::Reference< task::XInteractionHandler > (
309*cdf0e10cSrcweir                                 xServiceManager->createInstanceWithContext( OUSTR( "com.sun.star.task.InteractionHandler" ), m_context),
310*cdf0e10cSrcweir                                 uno::UNO_QUERY );
311*cdf0e10cSrcweir             if ( m_xInteractionHdl.is() )
312*cdf0e10cSrcweir                 m_updateInformation->setInteractionHandler( m_xInteractionHdl );
313*cdf0e10cSrcweir         }
314*cdf0e10cSrcweir     }
315*cdf0e10cSrcweir }
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir void UpdateDialog::Thread::stop() {
318*cdf0e10cSrcweir     uno::Reference< task::XAbortChannel > abort;
319*cdf0e10cSrcweir     {
320*cdf0e10cSrcweir         vos::OGuard g(Application::GetSolarMutex());
321*cdf0e10cSrcweir         abort = m_abort;
322*cdf0e10cSrcweir         m_stop = true;
323*cdf0e10cSrcweir     }
324*cdf0e10cSrcweir     if (abort.is()) {
325*cdf0e10cSrcweir         abort->sendAbort();
326*cdf0e10cSrcweir     }
327*cdf0e10cSrcweir     m_updateInformation->cancel();
328*cdf0e10cSrcweir }
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir UpdateDialog::Thread::Entry::Entry(
331*cdf0e10cSrcweir     uno::Reference< deployment::XPackage > const & thePackage,
332*cdf0e10cSrcweir     rtl::OUString const & theVersion):
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir     package(thePackage),
335*cdf0e10cSrcweir     version(theVersion),
336*cdf0e10cSrcweir     bProvidesOwnUpdate(false),
337*cdf0e10cSrcweir     updateData(thePackage)
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir }
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir UpdateDialog::Thread::~Thread()
342*cdf0e10cSrcweir {
343*cdf0e10cSrcweir     if ( m_xInteractionHdl.is() )
344*cdf0e10cSrcweir         m_updateInformation->setInteractionHandler( uno::Reference< task::XInteractionHandler > () );
345*cdf0e10cSrcweir }
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir void UpdateDialog::Thread::execute()
348*cdf0e10cSrcweir {
349*cdf0e10cSrcweir     {
350*cdf0e10cSrcweir         vos::OGuard g( Application::GetSolarMutex() );
351*cdf0e10cSrcweir         if ( m_stop ) {
352*cdf0e10cSrcweir             return;
353*cdf0e10cSrcweir         }
354*cdf0e10cSrcweir     }
355*cdf0e10cSrcweir     uno::Reference<deployment::XExtensionManager> extMgr =
356*cdf0e10cSrcweir         deployment::ExtensionManager::get(m_context);
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir     std::vector<std::pair<uno::Reference<deployment::XPackage>, uno::Any > > errors;
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir     dp_misc::UpdateInfoMap updateInfoMap = dp_misc::getOnlineUpdateInfos(
361*cdf0e10cSrcweir         m_context, extMgr, m_updateInformation, &m_vExtensionList, errors);
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir     typedef std::vector<std::pair<uno::Reference<deployment::XPackage>,
364*cdf0e10cSrcweir         uno::Any> >::const_iterator ITERROR;
365*cdf0e10cSrcweir     for (ITERROR ite = errors.begin(); ite != errors.end(); ite ++)
366*cdf0e10cSrcweir         handleSpecificError(ite->first, ite->second);
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir     for (dp_misc::UpdateInfoMap::iterator i(updateInfoMap.begin()); i != updateInfoMap.end(); i++)
369*cdf0e10cSrcweir     {
370*cdf0e10cSrcweir         dp_misc::UpdateInfo const & info = i->second;
371*cdf0e10cSrcweir         UpdateData updateData(info.extension);
372*cdf0e10cSrcweir         DisabledUpdate disableUpdate;
373*cdf0e10cSrcweir         //determine if online updates meet the requirements
374*cdf0e10cSrcweir         prepareUpdateData(info.info, disableUpdate, updateData);
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir         //determine if the update is installed in the user or shared repository
377*cdf0e10cSrcweir         rtl::OUString sOnlineVersion;
378*cdf0e10cSrcweir         if (info.info.is())
379*cdf0e10cSrcweir             sOnlineVersion = info.version;
380*cdf0e10cSrcweir         rtl::OUString sVersionUser;
381*cdf0e10cSrcweir         rtl::OUString sVersionShared;
382*cdf0e10cSrcweir         rtl::OUString sVersionBundled;
383*cdf0e10cSrcweir         uno::Sequence< uno::Reference< deployment::XPackage> > extensions;
384*cdf0e10cSrcweir         try {
385*cdf0e10cSrcweir             extensions = extMgr->getExtensionsWithSameIdentifier(
386*cdf0e10cSrcweir                 dp_misc::getIdentifier(info.extension), info.extension->getName(),
387*cdf0e10cSrcweir                 uno::Reference<ucb::XCommandEnvironment>());
388*cdf0e10cSrcweir         } catch (lang::IllegalArgumentException& ) {
389*cdf0e10cSrcweir             OSL_ASSERT(0);
390*cdf0e10cSrcweir             continue;
391*cdf0e10cSrcweir         } catch (css::ucb::CommandFailedException& ) {
392*cdf0e10cSrcweir             OSL_ASSERT(0);
393*cdf0e10cSrcweir             continue;
394*cdf0e10cSrcweir         }
395*cdf0e10cSrcweir         OSL_ASSERT(extensions.getLength() == 3);
396*cdf0e10cSrcweir         if (extensions[0].is() )
397*cdf0e10cSrcweir             sVersionUser = extensions[0]->getVersion();
398*cdf0e10cSrcweir         if (extensions[1].is() )
399*cdf0e10cSrcweir             sVersionShared = extensions[1]->getVersion();
400*cdf0e10cSrcweir         if (extensions[2].is() )
401*cdf0e10cSrcweir             sVersionBundled = extensions[2]->getVersion();
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir         bool bSharedReadOnly = extMgr->isReadOnlyRepository(OUSTR("shared"));
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir         dp_misc::UPDATE_SOURCE sourceUser = dp_misc::isUpdateUserExtension(
406*cdf0e10cSrcweir             bSharedReadOnly, sVersionUser, sVersionShared, sVersionBundled, sOnlineVersion);
407*cdf0e10cSrcweir         dp_misc::UPDATE_SOURCE sourceShared = dp_misc::isUpdateSharedExtension(
408*cdf0e10cSrcweir             bSharedReadOnly, sVersionShared, sVersionBundled, sOnlineVersion);
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir         uno::Reference<deployment::XPackage> updateSource;
411*cdf0e10cSrcweir         if (sourceUser != dp_misc::UPDATE_SOURCE_NONE)
412*cdf0e10cSrcweir         {
413*cdf0e10cSrcweir             if (sourceUser == dp_misc::UPDATE_SOURCE_SHARED)
414*cdf0e10cSrcweir             {
415*cdf0e10cSrcweir                 updateData.aUpdateSource = extensions[1];
416*cdf0e10cSrcweir                 updateData.updateVersion = extensions[1]->getVersion();
417*cdf0e10cSrcweir             }
418*cdf0e10cSrcweir             else if (sourceUser == dp_misc::UPDATE_SOURCE_BUNDLED)
419*cdf0e10cSrcweir             {
420*cdf0e10cSrcweir                 updateData.aUpdateSource = extensions[2];
421*cdf0e10cSrcweir                 updateData.updateVersion = extensions[2]->getVersion();
422*cdf0e10cSrcweir             }
423*cdf0e10cSrcweir             if (!update(disableUpdate, updateData))
424*cdf0e10cSrcweir                 return;
425*cdf0e10cSrcweir         }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir         if (sourceShared != dp_misc::UPDATE_SOURCE_NONE)
428*cdf0e10cSrcweir         {
429*cdf0e10cSrcweir 			if (sourceShared == dp_misc::UPDATE_SOURCE_BUNDLED)
430*cdf0e10cSrcweir 			{
431*cdf0e10cSrcweir 				updateData.aUpdateSource = extensions[2];
432*cdf0e10cSrcweir 				updateData.updateVersion = extensions[2]->getVersion();
433*cdf0e10cSrcweir 			}
434*cdf0e10cSrcweir             updateData.bIsShared = true;
435*cdf0e10cSrcweir             if (!update(disableUpdate, updateData))
436*cdf0e10cSrcweir                 return;
437*cdf0e10cSrcweir         }
438*cdf0e10cSrcweir     }
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir     vos::OGuard g(Application::GetSolarMutex());
442*cdf0e10cSrcweir     if (!m_stop) {
443*cdf0e10cSrcweir         m_dialog.checkingDone();
444*cdf0e10cSrcweir     }
445*cdf0e10cSrcweir }
446*cdf0e10cSrcweir #if 0
447*cdf0e10cSrcweir void UpdateDialog::Thread::handleGeneralError(uno::Any const & exception)
448*cdf0e10cSrcweir     const
449*cdf0e10cSrcweir {
450*cdf0e10cSrcweir     rtl::OUString message;
451*cdf0e10cSrcweir     uno::Exception e;
452*cdf0e10cSrcweir     if (exception >>= e) {
453*cdf0e10cSrcweir         message = e.Message;
454*cdf0e10cSrcweir     }
455*cdf0e10cSrcweir     vos::OGuard g(Application::GetSolarMutex());
456*cdf0e10cSrcweir     if (!m_stop) {
457*cdf0e10cSrcweir         m_dialog.addGeneralError(message);
458*cdf0e10cSrcweir     }
459*cdf0e10cSrcweir }
460*cdf0e10cSrcweir #endif
461*cdf0e10cSrcweir //Parameter package can be null
462*cdf0e10cSrcweir void UpdateDialog::Thread::handleSpecificError(
463*cdf0e10cSrcweir     uno::Reference< deployment::XPackage > const & package,
464*cdf0e10cSrcweir     uno::Any const & exception) const
465*cdf0e10cSrcweir {
466*cdf0e10cSrcweir     UpdateDialog::SpecificError data;
467*cdf0e10cSrcweir     if (package.is())
468*cdf0e10cSrcweir         data.name = package->getDisplayName();
469*cdf0e10cSrcweir     uno::Exception e;
470*cdf0e10cSrcweir     if (exception >>= e) {
471*cdf0e10cSrcweir         data.message = e.Message;
472*cdf0e10cSrcweir     }
473*cdf0e10cSrcweir     vos::OGuard g(Application::GetSolarMutex());
474*cdf0e10cSrcweir     if (!m_stop) {
475*cdf0e10cSrcweir         m_dialog.addSpecificError(data);
476*cdf0e10cSrcweir     }
477*cdf0e10cSrcweir }
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir ::rtl::OUString UpdateDialog::Thread::getUpdateDisplayString(
480*cdf0e10cSrcweir     dp_gui::UpdateData const & data, ::rtl::OUString const & version) const
481*cdf0e10cSrcweir {
482*cdf0e10cSrcweir     OSL_ASSERT(data.aInstalledPackage.is());
483*cdf0e10cSrcweir     rtl::OUStringBuffer b(data.aInstalledPackage->getDisplayName());
484*cdf0e10cSrcweir     b.append(static_cast< sal_Unicode >(' '));
485*cdf0e10cSrcweir     {
486*cdf0e10cSrcweir         vos::OGuard g( Application::GetSolarMutex() );
487*cdf0e10cSrcweir 		if(!m_stop)
488*cdf0e10cSrcweir 			b.append(m_dialog.m_version);
489*cdf0e10cSrcweir     }
490*cdf0e10cSrcweir     b.append(static_cast< sal_Unicode >(' '));
491*cdf0e10cSrcweir     if (version.getLength())
492*cdf0e10cSrcweir         b.append(version);
493*cdf0e10cSrcweir     else
494*cdf0e10cSrcweir         b.append(data.updateVersion);
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir     if (data.sWebsiteURL.getLength())
497*cdf0e10cSrcweir     {
498*cdf0e10cSrcweir         b.append(static_cast< sal_Unicode >(' '));
499*cdf0e10cSrcweir         {
500*cdf0e10cSrcweir             vos::OGuard g( Application::GetSolarMutex() );
501*cdf0e10cSrcweir 			if(!m_stop)
502*cdf0e10cSrcweir 				b.append(m_dialog.m_browserbased);
503*cdf0e10cSrcweir         }
504*cdf0e10cSrcweir     }
505*cdf0e10cSrcweir     return  b.makeStringAndClear();
506*cdf0e10cSrcweir }
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir /** out_data will only be filled if all dependencies are ok.
509*cdf0e10cSrcweir  */
510*cdf0e10cSrcweir void UpdateDialog::Thread::prepareUpdateData(
511*cdf0e10cSrcweir     uno::Reference< xml::dom::XNode > const & updateInfo,
512*cdf0e10cSrcweir     UpdateDialog::DisabledUpdate & out_du,
513*cdf0e10cSrcweir     dp_gui::UpdateData & out_data) const
514*cdf0e10cSrcweir {
515*cdf0e10cSrcweir     if (!updateInfo.is())
516*cdf0e10cSrcweir         return;
517*cdf0e10cSrcweir     dp_misc::DescriptionInfoset infoset(m_context, updateInfo);
518*cdf0e10cSrcweir     OSL_ASSERT(infoset.getVersion().getLength() != 0);
519*cdf0e10cSrcweir     uno::Sequence< uno::Reference< xml::dom::XElement > > ds(
520*cdf0e10cSrcweir         dp_misc::Dependencies::check(infoset));
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir     out_du.aUpdateInfo = updateInfo;
523*cdf0e10cSrcweir     out_du.unsatisfiedDependencies.realloc(ds.getLength());
524*cdf0e10cSrcweir     for (sal_Int32 i = 0; i < ds.getLength(); ++i) {
525*cdf0e10cSrcweir         out_du.unsatisfiedDependencies[i] = dp_misc::Dependencies::getErrorText(ds[i]);
526*cdf0e10cSrcweir     }
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir     const ::boost::optional< ::rtl::OUString> updateWebsiteURL(infoset.getLocalizedUpdateWebsiteURL());
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir     out_du.name = getUpdateDisplayString(out_data, infoset.getVersion());
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir     if (out_du.unsatisfiedDependencies.getLength() == 0)
533*cdf0e10cSrcweir     {
534*cdf0e10cSrcweir         out_data.aUpdateInfo = updateInfo;
535*cdf0e10cSrcweir         out_data.updateVersion = infoset.getVersion();
536*cdf0e10cSrcweir         if (updateWebsiteURL)
537*cdf0e10cSrcweir             out_data.sWebsiteURL = *updateWebsiteURL;
538*cdf0e10cSrcweir     }
539*cdf0e10cSrcweir }
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir bool UpdateDialog::Thread::update(
542*cdf0e10cSrcweir     UpdateDialog::DisabledUpdate & du,
543*cdf0e10cSrcweir     dp_gui::UpdateData & data) const
544*cdf0e10cSrcweir {
545*cdf0e10cSrcweir     bool ret = false;
546*cdf0e10cSrcweir     if (du.unsatisfiedDependencies.getLength() == 0)
547*cdf0e10cSrcweir     {
548*cdf0e10cSrcweir         vos::OGuard g(Application::GetSolarMutex());
549*cdf0e10cSrcweir         if (!m_stop) {
550*cdf0e10cSrcweir             m_dialog.addEnabledUpdate(getUpdateDisplayString(data), data);
551*cdf0e10cSrcweir         }
552*cdf0e10cSrcweir         ret = !m_stop;
553*cdf0e10cSrcweir     } else {
554*cdf0e10cSrcweir         vos::OGuard g(Application::GetSolarMutex());
555*cdf0e10cSrcweir         if (!m_stop) {
556*cdf0e10cSrcweir                 m_dialog.addDisabledUpdate(du);
557*cdf0e10cSrcweir         }
558*cdf0e10cSrcweir         ret = !m_stop;
559*cdf0e10cSrcweir     }
560*cdf0e10cSrcweir     return ret;
561*cdf0e10cSrcweir }
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir // UpdateDialog ----------------------------------------------------------
564*cdf0e10cSrcweir UpdateDialog::UpdateDialog(
565*cdf0e10cSrcweir     uno::Reference< uno::XComponentContext > const & context,
566*cdf0e10cSrcweir     Window * parent,
567*cdf0e10cSrcweir     const std::vector<uno::Reference< deployment::XPackage > > &vExtensionList,
568*cdf0e10cSrcweir     std::vector< dp_gui::UpdateData > * updateData):
569*cdf0e10cSrcweir     ModalDialog(parent,DpGuiResId(RID_DLG_UPDATE)),
570*cdf0e10cSrcweir     m_context(context),
571*cdf0e10cSrcweir     m_checking(this, DpGuiResId(RID_DLG_UPDATE_CHECKING)),
572*cdf0e10cSrcweir     m_throbber(this, DpGuiResId(RID_DLG_UPDATE_THROBBER)),
573*cdf0e10cSrcweir     m_update(this, DpGuiResId(RID_DLG_UPDATE_UPDATE)),
574*cdf0e10cSrcweir     m_updates(
575*cdf0e10cSrcweir         *this, DpGuiResId(RID_DLG_UPDATE_UPDATES),
576*cdf0e10cSrcweir         Image(DpGuiResId(RID_DLG_UPDATE_NORMALALERT)),
577*cdf0e10cSrcweir         Image(DpGuiResId(RID_DLG_UPDATE_HIGHCONTRASTALERT))),
578*cdf0e10cSrcweir     m_all(this, DpGuiResId(RID_DLG_UPDATE_ALL)),
579*cdf0e10cSrcweir     m_description(this, DpGuiResId(RID_DLG_UPDATE_DESCRIPTION)),
580*cdf0e10cSrcweir     m_PublisherLabel(this, DpGuiResId(RID_DLG_UPDATE_PUBLISHER_LABEL)),
581*cdf0e10cSrcweir     m_PublisherLink(this, DpGuiResId(RID_DLG_UPDATE_PUBLISHER_LINK)),
582*cdf0e10cSrcweir     m_ReleaseNotesLabel(this, DpGuiResId(RID_DLG_UPDATE_RELEASENOTES_LABEL)),
583*cdf0e10cSrcweir     m_ReleaseNotesLink(this, DpGuiResId(RID_DLG_UPDATE_RELEASENOTES_LINK)),
584*cdf0e10cSrcweir     m_descriptions(this, DpGuiResId(RID_DLG_UPDATE_DESCRIPTIONS)),
585*cdf0e10cSrcweir     m_line(this, DpGuiResId(RID_DLG_UPDATE_LINE)),
586*cdf0e10cSrcweir     m_help(this, DpGuiResId(RID_DLG_UPDATE_HELP)),
587*cdf0e10cSrcweir     m_ok(this, DpGuiResId(RID_DLG_UPDATE_OK)),
588*cdf0e10cSrcweir     m_close(this, DpGuiResId(RID_DLG_UPDATE_CLOSE)),
589*cdf0e10cSrcweir     m_error(String(DpGuiResId(RID_DLG_UPDATE_ERROR))),
590*cdf0e10cSrcweir     m_none(String(DpGuiResId(RID_DLG_UPDATE_NONE))),
591*cdf0e10cSrcweir     m_noInstallable(String(DpGuiResId(RID_DLG_UPDATE_NOINSTALLABLE))),
592*cdf0e10cSrcweir     m_failure(String(DpGuiResId(RID_DLG_UPDATE_FAILURE))),
593*cdf0e10cSrcweir     m_unknownError(String(DpGuiResId(RID_DLG_UPDATE_UNKNOWNERROR))),
594*cdf0e10cSrcweir     m_noDescription(String(DpGuiResId(RID_DLG_UPDATE_NODESCRIPTION))),
595*cdf0e10cSrcweir     m_noInstall(String(DpGuiResId(RID_DLG_UPDATE_NOINSTALL))),
596*cdf0e10cSrcweir     m_noDependency(String(DpGuiResId(RID_DLG_UPDATE_NODEPENDENCY))),
597*cdf0e10cSrcweir     m_noDependencyCurVer(String(DpGuiResId(RID_DLG_UPDATE_NODEPENDENCY_CUR_VER))),
598*cdf0e10cSrcweir     m_browserbased(String(DpGuiResId(RID_DLG_UPDATE_BROWSERBASED))),
599*cdf0e10cSrcweir     m_version(String(DpGuiResId(RID_DLG_UPDATE_VERSION))),
600*cdf0e10cSrcweir     m_ignoredUpdate(String(DpGuiResId(RID_DLG_UPDATE_IGNORED_UPDATE))),
601*cdf0e10cSrcweir     m_updateData(*updateData),
602*cdf0e10cSrcweir     m_thread(
603*cdf0e10cSrcweir         new UpdateDialog::Thread(
604*cdf0e10cSrcweir             context, *this, vExtensionList)),
605*cdf0e10cSrcweir     m_nFirstLineDelta(0),
606*cdf0e10cSrcweir     m_nOneLineMissing(0),
607*cdf0e10cSrcweir     m_nLastID(1),
608*cdf0e10cSrcweir     m_bModified( false )
609*cdf0e10cSrcweir     // TODO: check!
610*cdf0e10cSrcweir //    ,
611*cdf0e10cSrcweir //    m_extensionManagerDialog(extensionManagerDialog)
612*cdf0e10cSrcweir {
613*cdf0e10cSrcweir     OSL_ASSERT(updateData != NULL);
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir     m_xExtensionManager = deployment::ExtensionManager::get( context );
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir     uno::Reference< awt::XToolkit > toolkit;
618*cdf0e10cSrcweir     try {
619*cdf0e10cSrcweir         toolkit = uno::Reference< awt::XToolkit >(
620*cdf0e10cSrcweir             (uno::Reference< lang::XMultiComponentFactory >(
621*cdf0e10cSrcweir                 m_context->getServiceManager(),
622*cdf0e10cSrcweir                 uno::UNO_QUERY_THROW)->
623*cdf0e10cSrcweir              createInstanceWithContext(
624*cdf0e10cSrcweir                  rtl::OUString(
625*cdf0e10cSrcweir                      RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.Toolkit")),
626*cdf0e10cSrcweir                  m_context)),
627*cdf0e10cSrcweir             uno::UNO_QUERY_THROW);
628*cdf0e10cSrcweir     } catch (uno::RuntimeException &) {
629*cdf0e10cSrcweir         throw;
630*cdf0e10cSrcweir     } catch (uno::Exception & e) {
631*cdf0e10cSrcweir         throw uno::RuntimeException(e.Message, e.Context);
632*cdf0e10cSrcweir     }
633*cdf0e10cSrcweir     m_updates.SetSelectHdl(LINK(this, UpdateDialog, selectionHandler));
634*cdf0e10cSrcweir     m_all.SetToggleHdl(LINK(this, UpdateDialog, allHandler));
635*cdf0e10cSrcweir     m_ok.SetClickHdl(LINK(this, UpdateDialog, okHandler));
636*cdf0e10cSrcweir     m_close.SetClickHdl(LINK(this, UpdateDialog, closeHandler));
637*cdf0e10cSrcweir     if ( ! dp_misc::office_is_running())
638*cdf0e10cSrcweir         m_help.Disable();
639*cdf0e10cSrcweir     FreeResource();
640*cdf0e10cSrcweir 
641*cdf0e10cSrcweir     initDescription();
642*cdf0e10cSrcweir     getIgnoredUpdates();
643*cdf0e10cSrcweir }
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir //------------------------------------------------------------------------------
646*cdf0e10cSrcweir UpdateDialog::~UpdateDialog()
647*cdf0e10cSrcweir {
648*cdf0e10cSrcweir     storeIgnoredUpdates();
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir     for ( std::vector< UpdateDialog::Index* >::iterator i( m_ListboxEntries.begin() ); i != m_ListboxEntries.end(); ++i )
651*cdf0e10cSrcweir     {
652*cdf0e10cSrcweir         delete (*i);
653*cdf0e10cSrcweir     }
654*cdf0e10cSrcweir     for ( std::vector< UpdateDialog::IgnoredUpdate* >::iterator i( m_ignoredUpdates.begin() ); i != m_ignoredUpdates.end(); ++i )
655*cdf0e10cSrcweir     {
656*cdf0e10cSrcweir         delete (*i);
657*cdf0e10cSrcweir     }
658*cdf0e10cSrcweir }
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir //------------------------------------------------------------------------------
661*cdf0e10cSrcweir sal_Bool UpdateDialog::Close() {
662*cdf0e10cSrcweir     m_thread->stop();
663*cdf0e10cSrcweir     return ModalDialog::Close();
664*cdf0e10cSrcweir }
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir short UpdateDialog::Execute() {
667*cdf0e10cSrcweir     m_throbber.start();
668*cdf0e10cSrcweir     m_thread->launch();
669*cdf0e10cSrcweir     return ModalDialog::Execute();
670*cdf0e10cSrcweir }
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir //------------------------------------------------------------------------------
673*cdf0e10cSrcweir //------------------------------------------------------------------------------
674*cdf0e10cSrcweir //------------------------------------------------------------------------------
675*cdf0e10cSrcweir UpdateDialog::CheckListBox::CheckListBox( UpdateDialog & dialog, ResId const & resource,
676*cdf0e10cSrcweir                                           Image const & normalStaticImage,
677*cdf0e10cSrcweir                                           Image const & highContrastStaticImage ):
678*cdf0e10cSrcweir     SvxCheckListBox( &dialog, resource, normalStaticImage, highContrastStaticImage ),
679*cdf0e10cSrcweir     m_ignoreUpdate( String( DpGuiResId( RID_DLG_UPDATE_IGNORE ) ) ),
680*cdf0e10cSrcweir     m_ignoreAllUpdates( String( DpGuiResId( RID_DLG_UPDATE_IGNORE_ALL ) ) ),
681*cdf0e10cSrcweir     m_enableUpdate( String( DpGuiResId( RID_DLG_UPDATE_ENABLE ) ) ),
682*cdf0e10cSrcweir     m_dialog(dialog)
683*cdf0e10cSrcweir {}
684*cdf0e10cSrcweir 
685*cdf0e10cSrcweir //------------------------------------------------------------------------------
686*cdf0e10cSrcweir UpdateDialog::CheckListBox::~CheckListBox() {}
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir //------------------------------------------------------------------------------
689*cdf0e10cSrcweir sal_uInt16 UpdateDialog::CheckListBox::getItemCount() const {
690*cdf0e10cSrcweir     sal_uLong i = GetEntryCount();
691*cdf0e10cSrcweir     OSL_ASSERT(i <= std::numeric_limits< sal_uInt16 >::max());
692*cdf0e10cSrcweir     return sal::static_int_cast< sal_uInt16 >(i);
693*cdf0e10cSrcweir }
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir //------------------------------------------------------------------------------
696*cdf0e10cSrcweir void UpdateDialog::CheckListBox::MouseButtonDown( MouseEvent const & event )
697*cdf0e10cSrcweir {
698*cdf0e10cSrcweir     // When clicking on a selected entry in an SvxCheckListBox, the entry's
699*cdf0e10cSrcweir     // checkbox is toggled on mouse button down:
700*cdf0e10cSrcweir     SvxCheckListBox::MouseButtonDown( event );
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir     if ( event.IsRight() )
703*cdf0e10cSrcweir     {
704*cdf0e10cSrcweir         handlePopupMenu( event.GetPosPixel() );
705*cdf0e10cSrcweir     }
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir     m_dialog.enableOk();
708*cdf0e10cSrcweir }
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir //------------------------------------------------------------------------------
711*cdf0e10cSrcweir void UpdateDialog::CheckListBox::MouseButtonUp(MouseEvent const & event) {
712*cdf0e10cSrcweir     // When clicking on an entry's checkbox in an SvxCheckListBox, the entry's
713*cdf0e10cSrcweir     // checkbox is toggled on mouse button up:
714*cdf0e10cSrcweir     SvxCheckListBox::MouseButtonUp(event);
715*cdf0e10cSrcweir     m_dialog.enableOk();
716*cdf0e10cSrcweir }
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir void UpdateDialog::CheckListBox::KeyInput(KeyEvent const & event) {
719*cdf0e10cSrcweir     SvxCheckListBox::KeyInput(event);
720*cdf0e10cSrcweir     m_dialog.enableOk();
721*cdf0e10cSrcweir }
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir //------------------------------------------------------------------------------
724*cdf0e10cSrcweir void UpdateDialog::CheckListBox::handlePopupMenu( const Point &rPos )
725*cdf0e10cSrcweir {
726*cdf0e10cSrcweir     SvListEntry *pData = GetEntry( rPos );
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir     if ( pData )
729*cdf0e10cSrcweir     {
730*cdf0e10cSrcweir         sal_uInt16 nEntryPos = GetSelectEntryPos();
731*cdf0e10cSrcweir         UpdateDialog::Index * p = static_cast< UpdateDialog::Index * >( GetEntryData( nEntryPos ) );
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir         if ( ( p->m_eKind == ENABLED_UPDATE ) || ( p->m_eKind == DISABLED_UPDATE ) )
734*cdf0e10cSrcweir         {
735*cdf0e10cSrcweir             PopupMenu aPopup;
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir             if ( p->m_bIgnored )
738*cdf0e10cSrcweir                 aPopup.InsertItem( CMD_ENABLE_UPDATE, m_enableUpdate );
739*cdf0e10cSrcweir             else
740*cdf0e10cSrcweir             {
741*cdf0e10cSrcweir                 aPopup.InsertItem( CMD_IGNORE_UPDATE, m_ignoreUpdate );
742*cdf0e10cSrcweir                 aPopup.InsertItem( CMD_IGNORE_ALL_UPDATES, m_ignoreAllUpdates );
743*cdf0e10cSrcweir             }
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir             sal_uInt16 aCmd = aPopup.Execute( this, rPos );
746*cdf0e10cSrcweir             if ( ( aCmd == CMD_IGNORE_UPDATE ) || ( aCmd == CMD_IGNORE_ALL_UPDATES ) )
747*cdf0e10cSrcweir             {
748*cdf0e10cSrcweir                 p->m_bIgnored = true;
749*cdf0e10cSrcweir                 if ( p->m_eKind == ENABLED_UPDATE )
750*cdf0e10cSrcweir                 {
751*cdf0e10cSrcweir                     RemoveEntry( nEntryPos );
752*cdf0e10cSrcweir                     m_dialog.addAdditional( p, SvLBoxButtonKind_disabledCheckbox );
753*cdf0e10cSrcweir                 }
754*cdf0e10cSrcweir                 if ( aCmd == CMD_IGNORE_UPDATE )
755*cdf0e10cSrcweir                     m_dialog.setIgnoredUpdate( p, true, false );
756*cdf0e10cSrcweir                 else
757*cdf0e10cSrcweir                     m_dialog.setIgnoredUpdate( p, true, true );
758*cdf0e10cSrcweir                 // TODO: reselect entry to display new description!
759*cdf0e10cSrcweir             }
760*cdf0e10cSrcweir             else if ( aCmd == CMD_ENABLE_UPDATE )
761*cdf0e10cSrcweir             {
762*cdf0e10cSrcweir                 p->m_bIgnored = false;
763*cdf0e10cSrcweir                 if ( p->m_eKind == ENABLED_UPDATE )
764*cdf0e10cSrcweir                 {
765*cdf0e10cSrcweir                     RemoveEntry( nEntryPos );
766*cdf0e10cSrcweir                     m_dialog.insertItem( p, SvLBoxButtonKind_enabledCheckbox );
767*cdf0e10cSrcweir                 }
768*cdf0e10cSrcweir                 m_dialog.setIgnoredUpdate( p, false, false );
769*cdf0e10cSrcweir             }
770*cdf0e10cSrcweir         }
771*cdf0e10cSrcweir     }
772*cdf0e10cSrcweir }
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir //------------------------------------------------------------------------------
775*cdf0e10cSrcweir //------------------------------------------------------------------------------
776*cdf0e10cSrcweir //------------------------------------------------------------------------------
777*cdf0e10cSrcweir sal_uInt16 UpdateDialog::insertItem( UpdateDialog::Index *pEntry, SvLBoxButtonKind kind )
778*cdf0e10cSrcweir {
779*cdf0e10cSrcweir     m_updates.InsertEntry( pEntry->m_aName, LISTBOX_APPEND, static_cast< void * >( pEntry ), kind );
780*cdf0e10cSrcweir 
781*cdf0e10cSrcweir     for ( sal_uInt16 i = m_updates.getItemCount(); i != 0 ; )
782*cdf0e10cSrcweir     {
783*cdf0e10cSrcweir         i -= 1;
784*cdf0e10cSrcweir         UpdateDialog::Index const * p = static_cast< UpdateDialog::Index const * >( m_updates.GetEntryData( i ) );
785*cdf0e10cSrcweir         if ( p == pEntry )
786*cdf0e10cSrcweir             return i;
787*cdf0e10cSrcweir     }
788*cdf0e10cSrcweir     OSL_ASSERT(0);
789*cdf0e10cSrcweir     return 0;
790*cdf0e10cSrcweir }
791*cdf0e10cSrcweir 
792*cdf0e10cSrcweir //------------------------------------------------------------------------------
793*cdf0e10cSrcweir void UpdateDialog::addAdditional( UpdateDialog::Index * index, SvLBoxButtonKind kind )
794*cdf0e10cSrcweir {
795*cdf0e10cSrcweir     m_all.Enable();
796*cdf0e10cSrcweir     if (m_all.IsChecked())
797*cdf0e10cSrcweir     {
798*cdf0e10cSrcweir         insertItem( index, kind );
799*cdf0e10cSrcweir         m_update.Enable();
800*cdf0e10cSrcweir         m_updates.Enable();
801*cdf0e10cSrcweir         m_description.Enable();
802*cdf0e10cSrcweir         m_descriptions.Enable();
803*cdf0e10cSrcweir     }
804*cdf0e10cSrcweir }
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir //------------------------------------------------------------------------------
807*cdf0e10cSrcweir void UpdateDialog::addEnabledUpdate( rtl::OUString const & name,
808*cdf0e10cSrcweir                                      dp_gui::UpdateData & data )
809*cdf0e10cSrcweir {
810*cdf0e10cSrcweir     sal_uInt16 nIndex = sal::static_int_cast< sal_uInt16 >( m_enabledUpdates.size() );
811*cdf0e10cSrcweir     UpdateDialog::Index *pEntry = new UpdateDialog::Index( ENABLED_UPDATE, m_nLastID, nIndex, name );
812*cdf0e10cSrcweir 
813*cdf0e10cSrcweir     data.m_nID = m_nLastID;
814*cdf0e10cSrcweir     m_nLastID += 1;
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir     m_enabledUpdates.push_back( data );
817*cdf0e10cSrcweir     m_ListboxEntries.push_back( pEntry );
818*cdf0e10cSrcweir 
819*cdf0e10cSrcweir     if ( ! isIgnoredUpdate( pEntry ) )
820*cdf0e10cSrcweir     {
821*cdf0e10cSrcweir         sal_uInt16 nPos = insertItem( pEntry, SvLBoxButtonKind_enabledCheckbox );
822*cdf0e10cSrcweir         m_updates.CheckEntryPos( nPos );
823*cdf0e10cSrcweir     }
824*cdf0e10cSrcweir     else
825*cdf0e10cSrcweir         addAdditional( pEntry, SvLBoxButtonKind_disabledCheckbox );
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir     m_update.Enable();
828*cdf0e10cSrcweir     m_updates.Enable();
829*cdf0e10cSrcweir     m_description.Enable();
830*cdf0e10cSrcweir     m_descriptions.Enable();
831*cdf0e10cSrcweir }
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir //------------------------------------------------------------------------------
834*cdf0e10cSrcweir void UpdateDialog::addDisabledUpdate( UpdateDialog::DisabledUpdate & data )
835*cdf0e10cSrcweir {
836*cdf0e10cSrcweir     sal_uInt16 nIndex = sal::static_int_cast< sal_uInt16 >( m_disabledUpdates.size() );
837*cdf0e10cSrcweir     UpdateDialog::Index *pEntry = new UpdateDialog::Index( DISABLED_UPDATE, m_nLastID, nIndex, data.name );
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir     data.m_nID = m_nLastID;
840*cdf0e10cSrcweir     m_nLastID += 1;
841*cdf0e10cSrcweir 
842*cdf0e10cSrcweir     m_disabledUpdates.push_back( data );
843*cdf0e10cSrcweir     m_ListboxEntries.push_back( pEntry );
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir     isIgnoredUpdate( pEntry );
846*cdf0e10cSrcweir     addAdditional( pEntry, SvLBoxButtonKind_disabledCheckbox );
847*cdf0e10cSrcweir }
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir //------------------------------------------------------------------------------
850*cdf0e10cSrcweir void UpdateDialog::addSpecificError( UpdateDialog::SpecificError & data )
851*cdf0e10cSrcweir {
852*cdf0e10cSrcweir     sal_uInt16 nIndex = sal::static_int_cast< sal_uInt16 >( m_specificErrors.size() );
853*cdf0e10cSrcweir     UpdateDialog::Index *pEntry = new UpdateDialog::Index( DISABLED_UPDATE, m_nLastID, nIndex, data.name );
854*cdf0e10cSrcweir 
855*cdf0e10cSrcweir     data.m_nID = m_nLastID;
856*cdf0e10cSrcweir     m_nLastID += 1;
857*cdf0e10cSrcweir 
858*cdf0e10cSrcweir     m_specificErrors.push_back( data );
859*cdf0e10cSrcweir     m_ListboxEntries.push_back( pEntry );
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir     addAdditional( pEntry, SvLBoxButtonKind_staticImage);
862*cdf0e10cSrcweir }
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir void UpdateDialog::checkingDone() {
865*cdf0e10cSrcweir     m_checking.Hide();
866*cdf0e10cSrcweir     m_throbber.stop();
867*cdf0e10cSrcweir     m_throbber.Hide();
868*cdf0e10cSrcweir     if (m_updates.getItemCount() == 0)
869*cdf0e10cSrcweir     {
870*cdf0e10cSrcweir         clearDescription();
871*cdf0e10cSrcweir         m_description.Enable();
872*cdf0e10cSrcweir         m_descriptions.Enable();
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir         if ( m_disabledUpdates.empty() && m_specificErrors.empty() && m_ignoredUpdates.empty() )
875*cdf0e10cSrcweir             showDescription( m_none, false );
876*cdf0e10cSrcweir         else
877*cdf0e10cSrcweir             showDescription( m_noInstallable, false );
878*cdf0e10cSrcweir     }
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir     enableOk();
881*cdf0e10cSrcweir }
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir void UpdateDialog::enableOk() {
884*cdf0e10cSrcweir     if (!m_checking.IsVisible()) {
885*cdf0e10cSrcweir         m_ok.Enable(m_updates.GetCheckedEntryCount() != 0);
886*cdf0e10cSrcweir     }
887*cdf0e10cSrcweir }
888*cdf0e10cSrcweir 
889*cdf0e10cSrcweir // *********************************************************************************
890*cdf0e10cSrcweir void UpdateDialog::createNotifyJob( bool bPrepareOnly,
891*cdf0e10cSrcweir     uno::Sequence< uno::Sequence< rtl::OUString > > &rItemList )
892*cdf0e10cSrcweir {
893*cdf0e10cSrcweir     if ( !dp_misc::office_is_running() )
894*cdf0e10cSrcweir         return;
895*cdf0e10cSrcweir 
896*cdf0e10cSrcweir     // notify update check job
897*cdf0e10cSrcweir     try
898*cdf0e10cSrcweir     {
899*cdf0e10cSrcweir         uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
900*cdf0e10cSrcweir         uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
901*cdf0e10cSrcweir             xFactory->createInstance( OUSTR( "com.sun.star.configuration.ConfigurationProvider" )),
902*cdf0e10cSrcweir             uno::UNO_QUERY_THROW);
903*cdf0e10cSrcweir 
904*cdf0e10cSrcweir         beans::PropertyValue aProperty;
905*cdf0e10cSrcweir         aProperty.Name  = OUSTR( "nodepath" );
906*cdf0e10cSrcweir         aProperty.Value = uno::makeAny( OUSTR("org.openoffice.Office.Addons/AddonUI/OfficeHelp/UpdateCheckJob") );
907*cdf0e10cSrcweir 
908*cdf0e10cSrcweir         uno::Sequence< uno::Any > aArgumentList( 1 );
909*cdf0e10cSrcweir         aArgumentList[0] = uno::makeAny( aProperty );
910*cdf0e10cSrcweir 
911*cdf0e10cSrcweir         uno::Reference< container::XNameAccess > xNameAccess(
912*cdf0e10cSrcweir             xConfigProvider->createInstanceWithArguments(
913*cdf0e10cSrcweir                 OUSTR("com.sun.star.configuration.ConfigurationAccess"), aArgumentList ),
914*cdf0e10cSrcweir             uno::UNO_QUERY_THROW );
915*cdf0e10cSrcweir 
916*cdf0e10cSrcweir         util::URL aURL;
917*cdf0e10cSrcweir         xNameAccess->getByName(OUSTR("URL")) >>= aURL.Complete;
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir         uno::Reference < util::XURLTransformer > xTransformer( xFactory->createInstance( OUSTR( "com.sun.star.util.URLTransformer" ) ),
920*cdf0e10cSrcweir             uno::UNO_QUERY_THROW );
921*cdf0e10cSrcweir 
922*cdf0e10cSrcweir         xTransformer->parseStrict(aURL);
923*cdf0e10cSrcweir 
924*cdf0e10cSrcweir         uno::Reference < frame::XDesktop > xDesktop( xFactory->createInstance( OUSTR( "com.sun.star.frame.Desktop" ) ),
925*cdf0e10cSrcweir             uno::UNO_QUERY_THROW );
926*cdf0e10cSrcweir         uno::Reference< frame::XDispatchProvider > xDispatchProvider( xDesktop->getCurrentFrame(),
927*cdf0e10cSrcweir             uno::UNO_QUERY_THROW );
928*cdf0e10cSrcweir         uno::Reference< frame::XDispatch > xDispatch = xDispatchProvider->queryDispatch(aURL, rtl::OUString(), 0);
929*cdf0e10cSrcweir 
930*cdf0e10cSrcweir         if( xDispatch.is() )
931*cdf0e10cSrcweir         {
932*cdf0e10cSrcweir             uno::Sequence< beans::PropertyValue > aPropList(2);
933*cdf0e10cSrcweir             aProperty.Name  = OUSTR( "updateList" );
934*cdf0e10cSrcweir             aProperty.Value = uno::makeAny( rItemList );
935*cdf0e10cSrcweir             aPropList[0] = aProperty;
936*cdf0e10cSrcweir             aProperty.Name  = OUSTR( "prepareOnly" );
937*cdf0e10cSrcweir             aProperty.Value = uno::makeAny( bPrepareOnly );
938*cdf0e10cSrcweir             aPropList[1] = aProperty;
939*cdf0e10cSrcweir 
940*cdf0e10cSrcweir             xDispatch->dispatch(aURL, aPropList );
941*cdf0e10cSrcweir         }
942*cdf0e10cSrcweir     }
943*cdf0e10cSrcweir     catch( const uno::Exception& e )
944*cdf0e10cSrcweir     {
945*cdf0e10cSrcweir         dp_misc::TRACE( OUSTR("Caught exception: ")
946*cdf0e10cSrcweir             + e.Message + OUSTR("\n thread terminated.\n\n"));
947*cdf0e10cSrcweir     }
948*cdf0e10cSrcweir }
949*cdf0e10cSrcweir 
950*cdf0e10cSrcweir // *********************************************************************************
951*cdf0e10cSrcweir void UpdateDialog::notifyMenubar( bool bPrepareOnly, bool bRecheckOnly )
952*cdf0e10cSrcweir {
953*cdf0e10cSrcweir     if ( !dp_misc::office_is_running() )
954*cdf0e10cSrcweir         return;
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir     uno::Sequence< uno::Sequence< rtl::OUString > > aItemList;
957*cdf0e10cSrcweir     sal_Int32 nCount = 0;
958*cdf0e10cSrcweir 
959*cdf0e10cSrcweir     if ( ! bRecheckOnly )
960*cdf0e10cSrcweir     {
961*cdf0e10cSrcweir         for ( sal_Int16 i = 0; i < m_updates.getItemCount(); ++i )
962*cdf0e10cSrcweir         {
963*cdf0e10cSrcweir             uno::Sequence< rtl::OUString > aItem(2);
964*cdf0e10cSrcweir 
965*cdf0e10cSrcweir             UpdateDialog::Index const * p = static_cast< UpdateDialog::Index const * >(m_updates.GetEntryData(i));
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir             if ( p->m_eKind == ENABLED_UPDATE )
968*cdf0e10cSrcweir             {
969*cdf0e10cSrcweir                 dp_gui::UpdateData aUpdData = m_enabledUpdates[ p->m_nIndex ];
970*cdf0e10cSrcweir                 aItem[0] = dp_misc::getIdentifier( aUpdData.aInstalledPackage );
971*cdf0e10cSrcweir 
972*cdf0e10cSrcweir                 dp_misc::DescriptionInfoset aInfoset( m_context, aUpdData.aUpdateInfo );
973*cdf0e10cSrcweir                 aItem[1] = aInfoset.getVersion();
974*cdf0e10cSrcweir             }
975*cdf0e10cSrcweir             else if ( p->m_eKind == DISABLED_UPDATE )
976*cdf0e10cSrcweir                 continue;
977*cdf0e10cSrcweir             else
978*cdf0e10cSrcweir                 continue;
979*cdf0e10cSrcweir 
980*cdf0e10cSrcweir             aItemList.realloc( nCount + 1 );
981*cdf0e10cSrcweir             aItemList[ nCount ] = aItem;
982*cdf0e10cSrcweir             nCount += 1;
983*cdf0e10cSrcweir         }
984*cdf0e10cSrcweir     }
985*cdf0e10cSrcweir 
986*cdf0e10cSrcweir     storeIgnoredUpdates();
987*cdf0e10cSrcweir     createNotifyJob( bPrepareOnly, aItemList );
988*cdf0e10cSrcweir }
989*cdf0e10cSrcweir 
990*cdf0e10cSrcweir // *********************************************************************************
991*cdf0e10cSrcweir 
992*cdf0e10cSrcweir void UpdateDialog::initDescription()
993*cdf0e10cSrcweir {
994*cdf0e10cSrcweir     m_PublisherLabel.Hide();
995*cdf0e10cSrcweir     m_PublisherLink.Hide();
996*cdf0e10cSrcweir     m_ReleaseNotesLabel.Hide();
997*cdf0e10cSrcweir     m_ReleaseNotesLink.Hide();
998*cdf0e10cSrcweir     m_descriptions.Hide();
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir     Link aLink = LINK( this, UpdateDialog, hyperlink_clicked );
1001*cdf0e10cSrcweir     m_PublisherLink.SetClickHdl( aLink );
1002*cdf0e10cSrcweir     m_ReleaseNotesLink.SetClickHdl( aLink );
1003*cdf0e10cSrcweir 
1004*cdf0e10cSrcweir     long nTextWidth = m_PublisherLabel.GetCtrlTextWidth( m_PublisherLabel.GetText() );
1005*cdf0e10cSrcweir     long nTemp = m_ReleaseNotesLabel.GetTextWidth( m_ReleaseNotesLabel.GetText() );
1006*cdf0e10cSrcweir     if ( nTemp > nTextWidth )
1007*cdf0e10cSrcweir         nTextWidth = nTemp;
1008*cdf0e10cSrcweir     nTextWidth = nTextWidth * 110 / 100;
1009*cdf0e10cSrcweir 
1010*cdf0e10cSrcweir     Size aNewSize = m_PublisherLabel.GetSizePixel();
1011*cdf0e10cSrcweir     if ( nTextWidth > aNewSize.Width() )
1012*cdf0e10cSrcweir     {
1013*cdf0e10cSrcweir         long nDelta = nTextWidth - aNewSize.Width();
1014*cdf0e10cSrcweir         aNewSize.Width() = nTextWidth;
1015*cdf0e10cSrcweir         m_PublisherLabel.SetSizePixel( aNewSize );
1016*cdf0e10cSrcweir         m_ReleaseNotesLabel.SetSizePixel( aNewSize );
1017*cdf0e10cSrcweir 
1018*cdf0e10cSrcweir         aNewSize = m_PublisherLink.GetSizePixel();
1019*cdf0e10cSrcweir         aNewSize.Width() = aNewSize.Width() - nDelta;
1020*cdf0e10cSrcweir         Point aNewPos = m_PublisherLink.GetPosPixel();
1021*cdf0e10cSrcweir         aNewPos.X() = aNewPos.X() + nDelta;
1022*cdf0e10cSrcweir         m_PublisherLink.SetPosSizePixel( aNewPos, aNewSize );
1023*cdf0e10cSrcweir         aNewPos.Y() = m_ReleaseNotesLink.GetPosPixel().Y();
1024*cdf0e10cSrcweir         m_ReleaseNotesLink.SetPosSizePixel( aNewPos, aNewSize );
1025*cdf0e10cSrcweir     }
1026*cdf0e10cSrcweir 
1027*cdf0e10cSrcweir     m_aFirstLinePos = m_descriptions.GetPosPixel();
1028*cdf0e10cSrcweir     m_aFirstLineSize = m_descriptions.GetSizePixel();
1029*cdf0e10cSrcweir     Size aMarginSize = LogicToPixel( Size( RSC_SP_CTRL_GROUP_X, RSC_SP_CTRL_GROUP_Y ), MAP_APPFONT );
1030*cdf0e10cSrcweir     Point aThirdLinePos = m_ReleaseNotesLabel.GetPosPixel();
1031*cdf0e10cSrcweir     aThirdLinePos.Y() = aThirdLinePos.Y() + m_ReleaseNotesLabel.GetSizePixel().Height() + aMarginSize.Height();
1032*cdf0e10cSrcweir     m_nFirstLineDelta = aThirdLinePos.Y() - m_aFirstLinePos.Y();
1033*cdf0e10cSrcweir     m_nOneLineMissing = m_ReleaseNotesLabel.GetPosPixel().Y() - m_PublisherLabel.GetPosPixel().Y();
1034*cdf0e10cSrcweir }
1035*cdf0e10cSrcweir 
1036*cdf0e10cSrcweir void UpdateDialog::clearDescription()
1037*cdf0e10cSrcweir {
1038*cdf0e10cSrcweir     String sEmpty;
1039*cdf0e10cSrcweir     m_PublisherLabel.Hide();
1040*cdf0e10cSrcweir     m_PublisherLink.Hide();
1041*cdf0e10cSrcweir     m_PublisherLink.SetDescription( sEmpty );
1042*cdf0e10cSrcweir     m_PublisherLink.SetURL( sEmpty );
1043*cdf0e10cSrcweir     m_ReleaseNotesLabel.Hide();
1044*cdf0e10cSrcweir     m_ReleaseNotesLink.Hide();
1045*cdf0e10cSrcweir     m_ReleaseNotesLink.SetURL( sEmpty );
1046*cdf0e10cSrcweir     if ( m_PublisherLabel.GetPosPixel().Y() == m_ReleaseNotesLabel.GetPosPixel().Y() )
1047*cdf0e10cSrcweir     {
1048*cdf0e10cSrcweir         Point aNewPos = m_ReleaseNotesLabel.GetPosPixel();
1049*cdf0e10cSrcweir         aNewPos.Y() += m_nOneLineMissing;
1050*cdf0e10cSrcweir         m_ReleaseNotesLabel.SetPosPixel( aNewPos );
1051*cdf0e10cSrcweir         aNewPos = m_ReleaseNotesLink.GetPosPixel();
1052*cdf0e10cSrcweir         aNewPos.Y() += m_nOneLineMissing;
1053*cdf0e10cSrcweir         m_ReleaseNotesLink.SetPosPixel( aNewPos );
1054*cdf0e10cSrcweir     }
1055*cdf0e10cSrcweir     m_descriptions.Hide();
1056*cdf0e10cSrcweir     m_descriptions.Clear();
1057*cdf0e10cSrcweir     m_descriptions.SetPosSizePixel( m_aFirstLinePos, m_aFirstLineSize );
1058*cdf0e10cSrcweir }
1059*cdf0e10cSrcweir 
1060*cdf0e10cSrcweir bool UpdateDialog::showDescription(uno::Reference< xml::dom::XNode > const & aUpdateInfo)
1061*cdf0e10cSrcweir {
1062*cdf0e10cSrcweir     dp_misc::DescriptionInfoset infoset(m_context, aUpdateInfo);
1063*cdf0e10cSrcweir     return showDescription(infoset.getLocalizedPublisherNameAndURL(),
1064*cdf0e10cSrcweir                            infoset.getLocalizedReleaseNotesURL());
1065*cdf0e10cSrcweir }
1066*cdf0e10cSrcweir 
1067*cdf0e10cSrcweir bool UpdateDialog::showDescription(uno::Reference< deployment::XPackage > const & aExtension)
1068*cdf0e10cSrcweir {
1069*cdf0e10cSrcweir     OSL_ASSERT(aExtension.is());
1070*cdf0e10cSrcweir     beans::StringPair pubInfo = aExtension->getPublisherInfo();
1071*cdf0e10cSrcweir     return showDescription(std::make_pair(pubInfo.First, pubInfo.Second),
1072*cdf0e10cSrcweir                            OUSTR(""));
1073*cdf0e10cSrcweir }
1074*cdf0e10cSrcweir 
1075*cdf0e10cSrcweir bool UpdateDialog::showDescription(std::pair< rtl::OUString, rtl::OUString > const & pairPublisher,
1076*cdf0e10cSrcweir                                    rtl::OUString const & sReleaseNotes)
1077*cdf0e10cSrcweir {
1078*cdf0e10cSrcweir     rtl::OUString sPub = pairPublisher.first;
1079*cdf0e10cSrcweir     rtl::OUString sURL = pairPublisher.second;
1080*cdf0e10cSrcweir 
1081*cdf0e10cSrcweir     if ( sPub.getLength() == 0 && sURL.getLength() == 0 && sReleaseNotes.getLength() == 0 )
1082*cdf0e10cSrcweir         // nothing to show
1083*cdf0e10cSrcweir         return false;
1084*cdf0e10cSrcweir 
1085*cdf0e10cSrcweir     bool bPublisher = false;
1086*cdf0e10cSrcweir     if ( sPub.getLength() > 0 )
1087*cdf0e10cSrcweir     {
1088*cdf0e10cSrcweir         m_PublisherLabel.Show();
1089*cdf0e10cSrcweir         m_PublisherLink.Show();
1090*cdf0e10cSrcweir         m_PublisherLink.SetDescription( sPub );
1091*cdf0e10cSrcweir         m_PublisherLink.SetURL( sURL );
1092*cdf0e10cSrcweir         bPublisher = true;
1093*cdf0e10cSrcweir     }
1094*cdf0e10cSrcweir 
1095*cdf0e10cSrcweir     if ( sReleaseNotes.getLength() > 0 )
1096*cdf0e10cSrcweir     {
1097*cdf0e10cSrcweir         if ( !bPublisher )
1098*cdf0e10cSrcweir         {
1099*cdf0e10cSrcweir             m_ReleaseNotesLabel.SetPosPixel( m_PublisherLabel.GetPosPixel() );
1100*cdf0e10cSrcweir             m_ReleaseNotesLink.SetPosPixel( m_PublisherLink.GetPosPixel() );
1101*cdf0e10cSrcweir         }
1102*cdf0e10cSrcweir         m_ReleaseNotesLabel.Show();
1103*cdf0e10cSrcweir         m_ReleaseNotesLink.Show();
1104*cdf0e10cSrcweir         m_ReleaseNotesLink.SetURL( sReleaseNotes );
1105*cdf0e10cSrcweir     }
1106*cdf0e10cSrcweir     return true;
1107*cdf0e10cSrcweir }
1108*cdf0e10cSrcweir 
1109*cdf0e10cSrcweir bool UpdateDialog::showDescription( const String& rDescription, bool bWithPublisher )
1110*cdf0e10cSrcweir {
1111*cdf0e10cSrcweir     if ( rDescription.Len() == 0 )
1112*cdf0e10cSrcweir         // nothing to show
1113*cdf0e10cSrcweir         return false;
1114*cdf0e10cSrcweir 
1115*cdf0e10cSrcweir     if ( bWithPublisher )
1116*cdf0e10cSrcweir     {
1117*cdf0e10cSrcweir         bool bOneLineMissing = !m_ReleaseNotesLabel.IsVisible() || !m_PublisherLabel.IsVisible();
1118*cdf0e10cSrcweir         Point aNewPos = m_aFirstLinePos;
1119*cdf0e10cSrcweir         aNewPos.Y() += m_nFirstLineDelta;
1120*cdf0e10cSrcweir         if ( bOneLineMissing )
1121*cdf0e10cSrcweir             aNewPos.Y() -= m_nOneLineMissing;
1122*cdf0e10cSrcweir         Size aNewSize = m_aFirstLineSize;
1123*cdf0e10cSrcweir         aNewSize.Height() -= m_nFirstLineDelta;
1124*cdf0e10cSrcweir         if ( bOneLineMissing )
1125*cdf0e10cSrcweir             aNewSize.Height() += m_nOneLineMissing;
1126*cdf0e10cSrcweir         m_descriptions.SetPosSizePixel( aNewPos, aNewSize );
1127*cdf0e10cSrcweir     }
1128*cdf0e10cSrcweir     m_descriptions.Show();
1129*cdf0e10cSrcweir     m_descriptions.SetDescription( rDescription );
1130*cdf0e10cSrcweir     return true;
1131*cdf0e10cSrcweir }
1132*cdf0e10cSrcweir 
1133*cdf0e10cSrcweir bool UpdateDialog::isReadOnly( const uno::Reference< deployment::XPackage > &xPackage ) const
1134*cdf0e10cSrcweir {
1135*cdf0e10cSrcweir     if ( m_xExtensionManager.is() && xPackage.is() )
1136*cdf0e10cSrcweir     {
1137*cdf0e10cSrcweir         return m_xExtensionManager->isReadOnlyRepository( xPackage->getRepositoryName() );
1138*cdf0e10cSrcweir     }
1139*cdf0e10cSrcweir     else
1140*cdf0e10cSrcweir         return true;
1141*cdf0e10cSrcweir }
1142*cdf0e10cSrcweir 
1143*cdf0e10cSrcweir //------------------------------------------------------------------------------
1144*cdf0e10cSrcweir void UpdateDialog::getIgnoredUpdates()
1145*cdf0e10cSrcweir {
1146*cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xConfig( m_context->getServiceManager()->createInstanceWithContext(
1147*cdf0e10cSrcweir         OUSTR("com.sun.star.configuration.ConfigurationProvider"), m_context ), uno::UNO_QUERY_THROW);
1148*cdf0e10cSrcweir     beans::NamedValue aValue( OUSTR("nodepath"), uno::Any( IGNORED_UPDATES ) );
1149*cdf0e10cSrcweir     uno::Sequence< uno::Any > args(1);
1150*cdf0e10cSrcweir     args[0] <<= aValue;
1151*cdf0e10cSrcweir 
1152*cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xNameAccess( xConfig->createInstanceWithArguments( OUSTR("com.sun.star.configuration.ConfigurationAccess"), args), uno::UNO_QUERY_THROW );
1153*cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aElementNames = xNameAccess->getElementNames();
1154*cdf0e10cSrcweir 
1155*cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < aElementNames.getLength(); i++ )
1156*cdf0e10cSrcweir     {
1157*cdf0e10cSrcweir         ::rtl::OUString aIdentifier = aElementNames[i];
1158*cdf0e10cSrcweir         ::rtl::OUString aVersion;
1159*cdf0e10cSrcweir 
1160*cdf0e10cSrcweir         uno::Any aPropValue( uno::Reference< beans::XPropertySet >( xNameAccess->getByName( aIdentifier ), uno::UNO_QUERY_THROW )->getPropertyValue( PROPERTY_VERSION ) );
1161*cdf0e10cSrcweir         aPropValue >>= aVersion;
1162*cdf0e10cSrcweir         IgnoredUpdate *pData = new IgnoredUpdate( aIdentifier, aVersion );
1163*cdf0e10cSrcweir         m_ignoredUpdates.push_back( pData );
1164*cdf0e10cSrcweir     }
1165*cdf0e10cSrcweir }
1166*cdf0e10cSrcweir 
1167*cdf0e10cSrcweir //------------------------------------------------------------------------------
1168*cdf0e10cSrcweir void UpdateDialog::storeIgnoredUpdates()
1169*cdf0e10cSrcweir {
1170*cdf0e10cSrcweir     if ( m_bModified && ( m_ignoredUpdates.size() != 0 ) )
1171*cdf0e10cSrcweir     {
1172*cdf0e10cSrcweir         uno::Reference< lang::XMultiServiceFactory > xConfig( m_context->getServiceManager()->createInstanceWithContext(
1173*cdf0e10cSrcweir             OUSTR("com.sun.star.configuration.ConfigurationProvider"), m_context ), uno::UNO_QUERY_THROW );
1174*cdf0e10cSrcweir         beans::NamedValue aValue( OUSTR("nodepath"), uno::Any( IGNORED_UPDATES ) );
1175*cdf0e10cSrcweir         uno::Sequence< uno::Any > args(1);
1176*cdf0e10cSrcweir         args[0] <<= aValue;
1177*cdf0e10cSrcweir 
1178*cdf0e10cSrcweir         uno::Reference< container::XNameContainer > xNameContainer( xConfig->createInstanceWithArguments(
1179*cdf0e10cSrcweir             OUSTR("com.sun.star.configuration.ConfigurationUpdateAccess"), args ), uno::UNO_QUERY_THROW );
1180*cdf0e10cSrcweir 
1181*cdf0e10cSrcweir         for ( std::vector< UpdateDialog::IgnoredUpdate* >::iterator i( m_ignoredUpdates.begin() ); i != m_ignoredUpdates.end(); ++i )
1182*cdf0e10cSrcweir         {
1183*cdf0e10cSrcweir             if ( xNameContainer->hasByName( (*i)->sExtensionID ) )
1184*cdf0e10cSrcweir             {
1185*cdf0e10cSrcweir                 if ( (*i)->bRemoved )
1186*cdf0e10cSrcweir                     xNameContainer->removeByName( (*i)->sExtensionID );
1187*cdf0e10cSrcweir                 else
1188*cdf0e10cSrcweir                     uno::Reference< beans::XPropertySet >( xNameContainer->getByName( (*i)->sExtensionID ), uno::UNO_QUERY_THROW )->setPropertyValue( PROPERTY_VERSION, uno::Any( (*i)->sVersion ) );
1189*cdf0e10cSrcweir             }
1190*cdf0e10cSrcweir             else if ( ! (*i)->bRemoved )
1191*cdf0e10cSrcweir             {
1192*cdf0e10cSrcweir                 uno::Reference< beans::XPropertySet > elem( uno::Reference< lang::XSingleServiceFactory >( xNameContainer, uno::UNO_QUERY_THROW )->createInstance(), uno::UNO_QUERY_THROW );
1193*cdf0e10cSrcweir                 elem->setPropertyValue( PROPERTY_VERSION, uno::Any( (*i)->sVersion ) );
1194*cdf0e10cSrcweir                 xNameContainer->insertByName( (*i)->sExtensionID, uno::Any( elem ) );
1195*cdf0e10cSrcweir             }
1196*cdf0e10cSrcweir         }
1197*cdf0e10cSrcweir 
1198*cdf0e10cSrcweir         uno::Reference< util::XChangesBatch > xChangesBatch( xNameContainer, uno::UNO_QUERY );
1199*cdf0e10cSrcweir         if ( xChangesBatch.is() && xChangesBatch->hasPendingChanges() )
1200*cdf0e10cSrcweir             xChangesBatch->commitChanges();
1201*cdf0e10cSrcweir     }
1202*cdf0e10cSrcweir 
1203*cdf0e10cSrcweir     m_bModified = false;
1204*cdf0e10cSrcweir }
1205*cdf0e10cSrcweir 
1206*cdf0e10cSrcweir //------------------------------------------------------------------------------
1207*cdf0e10cSrcweir bool UpdateDialog::isIgnoredUpdate( UpdateDialog::Index * index )
1208*cdf0e10cSrcweir {
1209*cdf0e10cSrcweir     bool bIsIgnored = false;
1210*cdf0e10cSrcweir 
1211*cdf0e10cSrcweir     if ( m_ignoredUpdates.size() != 0 )
1212*cdf0e10cSrcweir     {
1213*cdf0e10cSrcweir         rtl::OUString aExtensionID;
1214*cdf0e10cSrcweir         rtl::OUString aVersion;
1215*cdf0e10cSrcweir 
1216*cdf0e10cSrcweir         if ( index->m_eKind == ENABLED_UPDATE )
1217*cdf0e10cSrcweir         {
1218*cdf0e10cSrcweir             dp_gui::UpdateData aUpdData = m_enabledUpdates[ index->m_nIndex ];
1219*cdf0e10cSrcweir             aExtensionID = dp_misc::getIdentifier( aUpdData.aInstalledPackage );
1220*cdf0e10cSrcweir             aVersion = aUpdData.updateVersion;
1221*cdf0e10cSrcweir         }
1222*cdf0e10cSrcweir         else if ( index->m_eKind == DISABLED_UPDATE )
1223*cdf0e10cSrcweir         {
1224*cdf0e10cSrcweir             DisabledUpdate &rData = m_disabledUpdates[ index->m_nIndex ];
1225*cdf0e10cSrcweir             dp_misc::DescriptionInfoset aInfoset( m_context, rData.aUpdateInfo );
1226*cdf0e10cSrcweir             ::boost::optional< ::rtl::OUString > aID( aInfoset.getIdentifier() );
1227*cdf0e10cSrcweir             if ( aID )
1228*cdf0e10cSrcweir                 aExtensionID = *aID;
1229*cdf0e10cSrcweir             aVersion = aInfoset.getVersion();
1230*cdf0e10cSrcweir         }
1231*cdf0e10cSrcweir 
1232*cdf0e10cSrcweir         for ( std::vector< UpdateDialog::IgnoredUpdate* >::iterator i( m_ignoredUpdates.begin() ); i != m_ignoredUpdates.end(); ++i )
1233*cdf0e10cSrcweir         {
1234*cdf0e10cSrcweir             if ( (*i)->sExtensionID == aExtensionID )
1235*cdf0e10cSrcweir             {
1236*cdf0e10cSrcweir                 if ( ( (*i)->sVersion.getLength() == 0 ) || ( (*i)->sVersion == aVersion ) )
1237*cdf0e10cSrcweir                 {
1238*cdf0e10cSrcweir                     bIsIgnored = true;
1239*cdf0e10cSrcweir                     index->m_bIgnored = true;
1240*cdf0e10cSrcweir                 }
1241*cdf0e10cSrcweir                 else // when we find another update of an ignored version, we will remove the old one to keep the ignored list small
1242*cdf0e10cSrcweir                     (*i)->bRemoved = true;
1243*cdf0e10cSrcweir                 break;
1244*cdf0e10cSrcweir             }
1245*cdf0e10cSrcweir         }
1246*cdf0e10cSrcweir     }
1247*cdf0e10cSrcweir 
1248*cdf0e10cSrcweir     return bIsIgnored;
1249*cdf0e10cSrcweir }
1250*cdf0e10cSrcweir 
1251*cdf0e10cSrcweir //------------------------------------------------------------------------------
1252*cdf0e10cSrcweir void UpdateDialog::setIgnoredUpdate( UpdateDialog::Index *pIndex, bool bIgnore, bool bIgnoreAll )
1253*cdf0e10cSrcweir {
1254*cdf0e10cSrcweir     rtl::OUString aExtensionID;
1255*cdf0e10cSrcweir     rtl::OUString aVersion;
1256*cdf0e10cSrcweir 
1257*cdf0e10cSrcweir     m_bModified = true;
1258*cdf0e10cSrcweir 
1259*cdf0e10cSrcweir     if ( pIndex->m_eKind == ENABLED_UPDATE )
1260*cdf0e10cSrcweir     {
1261*cdf0e10cSrcweir         dp_gui::UpdateData aUpdData = m_enabledUpdates[ pIndex->m_nIndex ];
1262*cdf0e10cSrcweir         aExtensionID = dp_misc::getIdentifier( aUpdData.aInstalledPackage );
1263*cdf0e10cSrcweir         if ( !bIgnoreAll )
1264*cdf0e10cSrcweir             aVersion = aUpdData.updateVersion;
1265*cdf0e10cSrcweir     }
1266*cdf0e10cSrcweir     else if ( pIndex->m_eKind == DISABLED_UPDATE )
1267*cdf0e10cSrcweir     {
1268*cdf0e10cSrcweir         DisabledUpdate &rData = m_disabledUpdates[ pIndex->m_nIndex ];
1269*cdf0e10cSrcweir         dp_misc::DescriptionInfoset aInfoset( m_context, rData.aUpdateInfo );
1270*cdf0e10cSrcweir         ::boost::optional< ::rtl::OUString > aID( aInfoset.getIdentifier() );
1271*cdf0e10cSrcweir         if ( aID )
1272*cdf0e10cSrcweir             aExtensionID = *aID;
1273*cdf0e10cSrcweir         if ( !bIgnoreAll )
1274*cdf0e10cSrcweir             aVersion = aInfoset.getVersion();
1275*cdf0e10cSrcweir     }
1276*cdf0e10cSrcweir 
1277*cdf0e10cSrcweir     if ( aExtensionID.getLength() )
1278*cdf0e10cSrcweir     {
1279*cdf0e10cSrcweir         bool bFound = false;
1280*cdf0e10cSrcweir         for ( std::vector< UpdateDialog::IgnoredUpdate* >::iterator i( m_ignoredUpdates.begin() ); i != m_ignoredUpdates.end(); ++i )
1281*cdf0e10cSrcweir         {
1282*cdf0e10cSrcweir             if ( (*i)->sExtensionID == aExtensionID )
1283*cdf0e10cSrcweir             {
1284*cdf0e10cSrcweir                 (*i)->sVersion = aVersion;
1285*cdf0e10cSrcweir                 (*i)->bRemoved = !bIgnore;
1286*cdf0e10cSrcweir                 bFound = true;
1287*cdf0e10cSrcweir                 break;
1288*cdf0e10cSrcweir             }
1289*cdf0e10cSrcweir         }
1290*cdf0e10cSrcweir         if ( bIgnore && !bFound )
1291*cdf0e10cSrcweir         {
1292*cdf0e10cSrcweir             IgnoredUpdate *pData = new IgnoredUpdate( aExtensionID, aVersion );
1293*cdf0e10cSrcweir             m_ignoredUpdates.push_back( pData );
1294*cdf0e10cSrcweir         }
1295*cdf0e10cSrcweir     }
1296*cdf0e10cSrcweir }
1297*cdf0e10cSrcweir 
1298*cdf0e10cSrcweir //------------------------------------------------------------------------------
1299*cdf0e10cSrcweir IMPL_LINK(UpdateDialog, selectionHandler, void *, EMPTYARG)
1300*cdf0e10cSrcweir {
1301*cdf0e10cSrcweir     rtl::OUStringBuffer b;
1302*cdf0e10cSrcweir     bool bInserted = false;
1303*cdf0e10cSrcweir     UpdateDialog::Index const * p = static_cast< UpdateDialog::Index const * >(
1304*cdf0e10cSrcweir         m_updates.GetEntryData(m_updates.GetSelectEntryPos()));
1305*cdf0e10cSrcweir     clearDescription();
1306*cdf0e10cSrcweir 
1307*cdf0e10cSrcweir     if ( p != NULL )
1308*cdf0e10cSrcweir     {
1309*cdf0e10cSrcweir         sal_uInt16 pos = p->m_nIndex;
1310*cdf0e10cSrcweir 
1311*cdf0e10cSrcweir         switch (p->m_eKind)
1312*cdf0e10cSrcweir         {
1313*cdf0e10cSrcweir             case ENABLED_UPDATE:
1314*cdf0e10cSrcweir             {
1315*cdf0e10cSrcweir                 if ( m_enabledUpdates[ pos ].aUpdateSource.is() )
1316*cdf0e10cSrcweir                     bInserted = showDescription( m_enabledUpdates[ pos ].aUpdateSource );
1317*cdf0e10cSrcweir                 else
1318*cdf0e10cSrcweir                     bInserted = showDescription( m_enabledUpdates[ pos ].aUpdateInfo );
1319*cdf0e10cSrcweir 
1320*cdf0e10cSrcweir                 if ( p->m_bIgnored )
1321*cdf0e10cSrcweir                     b.append( m_ignoredUpdate );
1322*cdf0e10cSrcweir 
1323*cdf0e10cSrcweir                 break;
1324*cdf0e10cSrcweir             }
1325*cdf0e10cSrcweir             case DISABLED_UPDATE:
1326*cdf0e10cSrcweir             {
1327*cdf0e10cSrcweir                 bInserted = showDescription( m_disabledUpdates[pos].aUpdateInfo );
1328*cdf0e10cSrcweir 
1329*cdf0e10cSrcweir                 if ( p->m_bIgnored )
1330*cdf0e10cSrcweir                     b.append( m_ignoredUpdate );
1331*cdf0e10cSrcweir 
1332*cdf0e10cSrcweir                 UpdateDialog::DisabledUpdate & data = m_disabledUpdates[ pos ];
1333*cdf0e10cSrcweir                 if (data.unsatisfiedDependencies.getLength() != 0)
1334*cdf0e10cSrcweir                 {
1335*cdf0e10cSrcweir                     // create error string for version mismatch
1336*cdf0e10cSrcweir                     ::rtl::OUString sVersion( RTL_CONSTASCII_USTRINGPARAM("%VERSION") );
1337*cdf0e10cSrcweir                     sal_Int32 nPos = m_noDependencyCurVer.indexOf( sVersion );
1338*cdf0e10cSrcweir                     if ( nPos >= 0 )
1339*cdf0e10cSrcweir                     {
1340*cdf0e10cSrcweir                         ::rtl::OUString sCurVersion( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("version") ":Version:OOOPackageVersion}"));
1341*cdf0e10cSrcweir                         ::rtl::Bootstrap::expandMacros(sCurVersion);
1342*cdf0e10cSrcweir                         m_noDependencyCurVer = m_noDependencyCurVer.replaceAt( nPos, sVersion.getLength(), sCurVersion );
1343*cdf0e10cSrcweir                     }
1344*cdf0e10cSrcweir 
1345*cdf0e10cSrcweir                     b.append(m_noInstall);
1346*cdf0e10cSrcweir                     b.append(LF);
1347*cdf0e10cSrcweir                     b.append(m_noDependency);
1348*cdf0e10cSrcweir                     for (sal_Int32 i = 0;
1349*cdf0e10cSrcweir                          i < data.unsatisfiedDependencies.getLength(); ++i)
1350*cdf0e10cSrcweir                     {
1351*cdf0e10cSrcweir                         b.append(LF);
1352*cdf0e10cSrcweir                         b.appendAscii(RTL_CONSTASCII_STRINGPARAM("  "));
1353*cdf0e10cSrcweir                             // U+2003 EM SPACE would be better than two spaces,
1354*cdf0e10cSrcweir                             // but some fonts do not contain it
1355*cdf0e10cSrcweir                         b.append(
1356*cdf0e10cSrcweir                             confineToParagraph(
1357*cdf0e10cSrcweir                                 data.unsatisfiedDependencies[i]));
1358*cdf0e10cSrcweir                     }
1359*cdf0e10cSrcweir                     b.append(LF);
1360*cdf0e10cSrcweir                     b.appendAscii(RTL_CONSTASCII_STRINGPARAM("  "));
1361*cdf0e10cSrcweir                     b.append(m_noDependencyCurVer);
1362*cdf0e10cSrcweir                 }
1363*cdf0e10cSrcweir                 break;
1364*cdf0e10cSrcweir             }
1365*cdf0e10cSrcweir             case SPECIFIC_ERROR:
1366*cdf0e10cSrcweir             {
1367*cdf0e10cSrcweir                 UpdateDialog::SpecificError & data = m_specificErrors[ pos ];
1368*cdf0e10cSrcweir                 b.append(m_failure);
1369*cdf0e10cSrcweir                 b.append(LF);
1370*cdf0e10cSrcweir                 b.append( data.message.getLength() == 0 ? m_unknownError : data.message );
1371*cdf0e10cSrcweir                 break;
1372*cdf0e10cSrcweir             }
1373*cdf0e10cSrcweir             default:
1374*cdf0e10cSrcweir                 OSL_ASSERT(false);
1375*cdf0e10cSrcweir                 break;
1376*cdf0e10cSrcweir         }
1377*cdf0e10cSrcweir     }
1378*cdf0e10cSrcweir 
1379*cdf0e10cSrcweir     if ( b.getLength() == 0 )
1380*cdf0e10cSrcweir         b.append( m_noDescription );
1381*cdf0e10cSrcweir 
1382*cdf0e10cSrcweir     showDescription( b.makeStringAndClear(), bInserted );
1383*cdf0e10cSrcweir     return 0;
1384*cdf0e10cSrcweir }
1385*cdf0e10cSrcweir 
1386*cdf0e10cSrcweir IMPL_LINK(UpdateDialog, allHandler, void *, EMPTYARG)
1387*cdf0e10cSrcweir {
1388*cdf0e10cSrcweir     if (m_all.IsChecked())
1389*cdf0e10cSrcweir     {
1390*cdf0e10cSrcweir         m_update.Enable();
1391*cdf0e10cSrcweir         m_updates.Enable();
1392*cdf0e10cSrcweir         m_description.Enable();
1393*cdf0e10cSrcweir         m_descriptions.Enable();
1394*cdf0e10cSrcweir 
1395*cdf0e10cSrcweir         for (std::vector< UpdateDialog::Index* >::iterator i( m_ListboxEntries.begin() );
1396*cdf0e10cSrcweir              i != m_ListboxEntries.end(); ++i )
1397*cdf0e10cSrcweir         {
1398*cdf0e10cSrcweir             if ( (*i)->m_bIgnored || ( (*i)->m_eKind != ENABLED_UPDATE ) )
1399*cdf0e10cSrcweir                 insertItem( (*i), SvLBoxButtonKind_disabledCheckbox );
1400*cdf0e10cSrcweir         }
1401*cdf0e10cSrcweir     }
1402*cdf0e10cSrcweir     else
1403*cdf0e10cSrcweir     {
1404*cdf0e10cSrcweir         for ( sal_uInt16 i = 0; i < m_updates.getItemCount(); )
1405*cdf0e10cSrcweir         {
1406*cdf0e10cSrcweir             UpdateDialog::Index const * p = static_cast< UpdateDialog::Index const * >( m_updates.GetEntryData(i) );
1407*cdf0e10cSrcweir             if ( p->m_bIgnored || ( p->m_eKind != ENABLED_UPDATE ) )
1408*cdf0e10cSrcweir             {
1409*cdf0e10cSrcweir                 m_updates.RemoveEntry(i);
1410*cdf0e10cSrcweir             } else {
1411*cdf0e10cSrcweir                 ++i;
1412*cdf0e10cSrcweir             }
1413*cdf0e10cSrcweir         }
1414*cdf0e10cSrcweir 
1415*cdf0e10cSrcweir         if (m_updates.getItemCount() == 0)
1416*cdf0e10cSrcweir         {
1417*cdf0e10cSrcweir             clearDescription();
1418*cdf0e10cSrcweir             m_update.Disable();
1419*cdf0e10cSrcweir             m_updates.Disable();
1420*cdf0e10cSrcweir             if (m_checking.IsVisible())
1421*cdf0e10cSrcweir                 m_description.Disable();
1422*cdf0e10cSrcweir             else
1423*cdf0e10cSrcweir                 showDescription(m_noInstallable,false);
1424*cdf0e10cSrcweir         }
1425*cdf0e10cSrcweir     }
1426*cdf0e10cSrcweir     return 0;
1427*cdf0e10cSrcweir }
1428*cdf0e10cSrcweir 
1429*cdf0e10cSrcweir IMPL_LINK(UpdateDialog, okHandler, void *, EMPTYARG)
1430*cdf0e10cSrcweir {
1431*cdf0e10cSrcweir     //If users are going to update a shared extension then we need
1432*cdf0e10cSrcweir     //to warn them
1433*cdf0e10cSrcweir     typedef ::std::vector<UpdateData>::const_iterator CIT;
1434*cdf0e10cSrcweir     for (CIT i = m_enabledUpdates.begin(); i < m_enabledUpdates.end(); i++)
1435*cdf0e10cSrcweir     {
1436*cdf0e10cSrcweir         OSL_ASSERT(i->aInstalledPackage.is());
1437*cdf0e10cSrcweir         //If the user has no write access to the shared folder then the update
1438*cdf0e10cSrcweir         //for a shared extension is disable, that is it cannot be in m_enabledUpdates
1439*cdf0e10cSrcweir //        OSL_ASSERT(isReadOnly(i->aInstalledPackage) == sal_False);
1440*cdf0e10cSrcweir #if 0
1441*cdf0e10cSrcweir         // TODO: check!
1442*cdf0e10cSrcweir         OSL_ASSERT(m_extensionManagerDialog.get());
1443*cdf0e10cSrcweir         if (RET_CANCEL == m_extensionManagerDialog->continueUpdateForSharedExtension(
1444*cdf0e10cSrcweir             this, i->aPackageManager))
1445*cdf0e10cSrcweir         {
1446*cdf0e10cSrcweir             EndDialog(RET_CANCEL);
1447*cdf0e10cSrcweir         }
1448*cdf0e10cSrcweir #endif
1449*cdf0e10cSrcweir     }
1450*cdf0e10cSrcweir 
1451*cdf0e10cSrcweir 
1452*cdf0e10cSrcweir     for (sal_uInt16 i = 0; i < m_updates.getItemCount(); ++i) {
1453*cdf0e10cSrcweir         UpdateDialog::Index const * p =
1454*cdf0e10cSrcweir             static_cast< UpdateDialog::Index const * >(
1455*cdf0e10cSrcweir                 m_updates.GetEntryData(i));
1456*cdf0e10cSrcweir         if (p->m_eKind == ENABLED_UPDATE && m_updates.IsChecked(i)) {
1457*cdf0e10cSrcweir             m_updateData.push_back( m_enabledUpdates[ p->m_nIndex ] );
1458*cdf0e10cSrcweir         }
1459*cdf0e10cSrcweir     }
1460*cdf0e10cSrcweir 
1461*cdf0e10cSrcweir     EndDialog(RET_OK);
1462*cdf0e10cSrcweir     return 0;
1463*cdf0e10cSrcweir }
1464*cdf0e10cSrcweir 
1465*cdf0e10cSrcweir IMPL_LINK(UpdateDialog, closeHandler, void *, EMPTYARG) {
1466*cdf0e10cSrcweir     m_thread->stop();
1467*cdf0e10cSrcweir     EndDialog(RET_CANCEL);
1468*cdf0e10cSrcweir     return 0;
1469*cdf0e10cSrcweir }
1470*cdf0e10cSrcweir 
1471*cdf0e10cSrcweir IMPL_LINK( UpdateDialog, hyperlink_clicked, svt::FixedHyperlink*, pHyperlink )
1472*cdf0e10cSrcweir {
1473*cdf0e10cSrcweir     ::rtl::OUString sURL;
1474*cdf0e10cSrcweir     if ( pHyperlink )
1475*cdf0e10cSrcweir         sURL = ::rtl::OUString( pHyperlink->GetURL() );
1476*cdf0e10cSrcweir     if ( sURL.getLength() == 0 )
1477*cdf0e10cSrcweir         return 0;
1478*cdf0e10cSrcweir 
1479*cdf0e10cSrcweir     try
1480*cdf0e10cSrcweir     {
1481*cdf0e10cSrcweir         uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
1482*cdf0e10cSrcweir             m_context->getServiceManager()->createInstanceWithContext(
1483*cdf0e10cSrcweir                 OUSTR( "com.sun.star.system.SystemShellExecute" ),
1484*cdf0e10cSrcweir                 m_context), uno::UNO_QUERY_THROW);
1485*cdf0e10cSrcweir         //throws lang::IllegalArgumentException, system::SystemShellExecuteException
1486*cdf0e10cSrcweir         xSystemShellExecute->execute(
1487*cdf0e10cSrcweir                                      sURL, ::rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS);
1488*cdf0e10cSrcweir     }
1489*cdf0e10cSrcweir     catch (uno::Exception& )
1490*cdf0e10cSrcweir     {
1491*cdf0e10cSrcweir     }
1492*cdf0e10cSrcweir 
1493*cdf0e10cSrcweir     return 1;
1494*cdf0e10cSrcweir }
1495