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