1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <config_extensions.h>
22 #include <strings.hrc>
26 #include "dp_gui_dialog2.hxx"
27 #include "dp_gui_extlistbox.hxx"
28 #include <dp_shared.hxx>
29 #include "dp_gui_theextmgr.hxx"
30 #include "dp_gui_extensioncmdqueue.hxx"
32 #include <dp_update.hxx>
33 #include <dp_identifier.hxx>
35 #include <fpicker/strings.hrc>
38 #include <vcl/commandevent.hxx>
39 #include <vcl/svapp.hxx>
41 #include <osl/mutex.hxx>
42 #include <sal/log.hxx>
43 #include <rtl/ustrbuf.hxx>
45 #include <svtools/restartdialog.hxx>
47 #include <sfx2/filedlghelper.hxx>
48 #include <sfx2/sfxdlg.hxx>
50 #include <comphelper/anytostring.hxx>
51 #include <cppuhelper/exc_hlp.hxx>
52 #include <cppuhelper/supportsservice.hxx>
54 #include <comphelper/processfactory.hxx>
55 #include <comphelper/diagnose_ex.hxx>
56 #include <unotools/configmgr.hxx>
58 #include <com/sun/star/deployment/DeploymentException.hpp>
59 #include <com/sun/star/lang/IllegalArgumentException.hpp>
60 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
61 #include <com/sun/star/system/SystemShellExecute.hpp>
63 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
64 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
65 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
67 #include <officecfg/Office/ExtensionManager.hxx>
73 using namespace ::com::sun::star
;
74 using namespace ::com::sun::star::system
;
79 constexpr OUStringLiteral USER_PACKAGE_MANAGER
= u
"user";
80 constexpr OUStringLiteral SHARED_PACKAGE_MANAGER
= u
"shared";
81 constexpr OUStringLiteral BUNDLED_PACKAGE_MANAGER
= u
"bundled";
83 // ExtBoxWithBtns_Impl
84 class ExtBoxWithBtns_Impl
: public ExtensionBox_Impl
86 bool m_bInterfaceLocked
;
88 ExtMgrDialog
* m_pParent
;
90 void SetButtonStatus( const TEntry_Impl
& rEntry
);
91 OUString
ShowPopupMenu( const Point
&rPos
, const tools::Long nPos
);
94 explicit ExtBoxWithBtns_Impl(std::unique_ptr
<weld::ScrolledWindow
> xScroll
);
96 void InitFromDialog(ExtMgrDialog
*pParentDialog
);
98 virtual bool MouseButtonDown( const MouseEvent
& rMEvt
) override
;
99 virtual bool Command( const CommandEvent
& rCEvt
) override
;
101 virtual void RecalcAll() override
;
102 virtual void selectEntry( const tools::Long nPos
) override
;
104 void enableButtons( bool bEnable
);
107 ExtBoxWithBtns_Impl::ExtBoxWithBtns_Impl(std::unique_ptr
<weld::ScrolledWindow
> xScroll
)
108 : ExtensionBox_Impl(std::move(xScroll
))
109 , m_bInterfaceLocked(false)
114 void ExtBoxWithBtns_Impl::InitFromDialog(ExtMgrDialog
*pParentDialog
)
116 setExtensionManager(pParentDialog
->getExtensionManager());
118 m_pParent
= pParentDialog
;
121 void ExtBoxWithBtns_Impl::RecalcAll()
123 const sal_Int32 nActive
= getSelIndex();
125 if ( nActive
!= ExtensionBox_Impl::ENTRY_NOTFOUND
)
127 SetButtonStatus( GetEntryData( nActive
) );
131 m_pParent
->enableOptionsButton( false );
132 m_pParent
->enableRemoveButton( false );
133 m_pParent
->enableEnableButton( false );
136 ExtensionBox_Impl::RecalcAll();
140 //This function may be called with nPos < 0
141 void ExtBoxWithBtns_Impl::selectEntry( const tools::Long nPos
)
143 if ( HasActive() && ( nPos
== getSelIndex() ) )
146 ExtensionBox_Impl::selectEntry( nPos
);
149 void ExtBoxWithBtns_Impl::SetButtonStatus(const TEntry_Impl
& rEntry
)
151 bool bShowOptionBtn
= true;
153 rEntry
->m_bHasButtons
= false;
154 if ( ( rEntry
->m_eState
== REGISTERED
) || ( rEntry
->m_eState
== NOT_AVAILABLE
) )
156 m_pParent
->enableButtontoEnable( false );
160 m_pParent
->enableButtontoEnable( true );
161 bShowOptionBtn
= false;
164 if ( ( !rEntry
->m_bUser
|| ( rEntry
->m_eState
== NOT_AVAILABLE
) || rEntry
->m_bMissingDeps
)
165 && !rEntry
->m_bMissingLic
)
167 m_pParent
->enableEnableButton( false );
171 m_pParent
->enableEnableButton( !rEntry
->m_bLocked
);
172 rEntry
->m_bHasButtons
= true;
175 if ( rEntry
->m_bHasOptions
&& bShowOptionBtn
)
177 m_pParent
->enableOptionsButton( true );
178 rEntry
->m_bHasButtons
= true;
182 m_pParent
->enableOptionsButton( false );
185 if ( rEntry
->m_bUser
|| rEntry
->m_bShared
)
187 m_pParent
->enableRemoveButton( !rEntry
->m_bLocked
);
188 rEntry
->m_bHasButtons
= true;
192 m_pParent
->enableRemoveButton( false );
196 bool ExtBoxWithBtns_Impl::Command(const CommandEvent
& rCEvt
)
198 if (rCEvt
.GetCommand() != CommandEventId::ContextMenu
)
199 return ExtensionBox_Impl::Command(rCEvt
);
201 const Point
aMousePos(rCEvt
.GetMousePosPixel());
202 const auto nPos
= PointToPos(aMousePos
);
203 OUString sCommand
= ShowPopupMenu(aMousePos
, nPos
);
205 if (sCommand
== "CMD_ENABLE")
206 m_pParent
->enablePackage( GetEntryData( nPos
)->m_xPackage
, true );
207 else if (sCommand
== "CMD_DISABLE")
208 m_pParent
->enablePackage( GetEntryData( nPos
)->m_xPackage
, false );
209 else if (sCommand
== "CMD_UPDATE")
210 m_pParent
->updatePackage( GetEntryData( nPos
)->m_xPackage
);
211 else if (sCommand
== "CMD_REMOVE")
212 m_pParent
->removePackage( GetEntryData( nPos
)->m_xPackage
);
213 else if (sCommand
== "CMD_SHOW_LICENSE")
215 m_pParent
->incBusy();
216 ShowLicenseDialog
aLicenseDlg(m_pParent
->getDialog(), GetEntryData(nPos
)->m_xPackage
);
218 m_pParent
->decBusy();
224 OUString
ExtBoxWithBtns_Impl::ShowPopupMenu( const Point
& rPos
, const tools::Long nPos
)
226 if ( nPos
>= static_cast<tools::Long
>(getItemCount()) )
229 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(nullptr, "desktop/ui/extensionmenu.ui"));
230 std::unique_ptr
<weld::Menu
> xPopup(xBuilder
->weld_menu("menu"));
232 #if ENABLE_EXTENSION_UPDATE
233 xPopup
->append("CMD_UPDATE", DpResId( RID_CTX_ITEM_CHECK_UPDATE
) );
236 if ( ! GetEntryData( nPos
)->m_bLocked
)
238 if ( GetEntryData( nPos
)->m_bUser
)
240 if ( GetEntryData( nPos
)->m_eState
== REGISTERED
)
241 xPopup
->append("CMD_DISABLE", DpResId(RID_CTX_ITEM_DISABLE
));
242 else if ( GetEntryData( nPos
)->m_eState
!= NOT_AVAILABLE
)
243 xPopup
->append("CMD_ENABLE", DpResId(RID_CTX_ITEM_ENABLE
));
245 if (!officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionRemoval::get())
247 xPopup
->append("CMD_REMOVE", DpResId(RID_CTX_ITEM_REMOVE
));
251 if ( !GetEntryData( nPos
)->m_sLicenseText
.isEmpty() )
252 xPopup
->append("CMD_SHOW_LICENSE", DpResId(RID_STR_SHOW_LICENSE_CMD
));
254 return xPopup
->popup_at_rect(GetDrawingArea(), tools::Rectangle(rPos
, Size(1, 1)));
257 bool ExtBoxWithBtns_Impl::MouseButtonDown( const MouseEvent
& rMEvt
)
259 if (m_bInterfaceLocked
)
261 return ExtensionBox_Impl::MouseButtonDown(rMEvt
);
264 void ExtBoxWithBtns_Impl::enableButtons( bool bEnable
)
266 m_bInterfaceLocked
= ! bEnable
;
270 sal_Int32 nIndex
= getSelIndex();
271 if ( nIndex
!= ExtensionBox_Impl::ENTRY_NOTFOUND
)
272 SetButtonStatus( GetEntryData( nIndex
) );
276 m_pParent
->enableEnableButton( false );
277 m_pParent
->enableOptionsButton( false );
278 m_pParent
->enableRemoveButton( false );
284 DialogHelper::DialogHelper(const uno::Reference
< uno::XComponentContext
> &xContext
,
285 weld::Window
* pWindow
)
287 , m_nEventID(nullptr)
289 m_xContext
= xContext
;
292 DialogHelper::~DialogHelper()
295 Application::RemoveUserEvent( m_nEventID
);
299 bool DialogHelper::IsSharedPkgMgr( const uno::Reference
< deployment::XPackage
> &xPackage
)
301 return xPackage
->getRepositoryName() == SHARED_PACKAGE_MANAGER
;
304 bool DialogHelper::continueOnSharedExtension( const uno::Reference
< deployment::XPackage
> &xPackage
,
305 weld::Widget
* pParent
,
309 if ( !bHadWarning
&& IsSharedPkgMgr( xPackage
) )
311 const SolarMutexGuard guard
;
313 std::unique_ptr
<weld::MessageDialog
> xBox(Application::CreateMessageDialog(pParent
,
314 VclMessageType::Warning
, VclButtonsType::OkCancel
, DpResId(pResID
)));
317 bool bRet
= RET_OK
== xBox
->run();
326 void DialogHelper::openWebBrowser(const OUString
& sURL
, const OUString
& sTitle
)
328 if ( sURL
.isEmpty() ) // Nothing to do, when the URL is empty
333 uno::Reference
< XSystemShellExecute
> xSystemShellExecute(
334 SystemShellExecute::create(m_xContext
));
335 //throws css::lang::IllegalArgumentException, css::system::SystemShellExecuteException
336 xSystemShellExecute
->execute( sURL
, OUString(), SystemShellExecuteFlags::URIS_ONLY
);
338 catch ( const uno::Exception
& )
340 uno::Any
exc( ::cppu::getCaughtException() );
341 OUString
msg( ::comphelper::anyToString( exc
) );
342 const SolarMutexGuard guard
;
344 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(getFrameWeld(),
345 VclMessageType::Warning
, VclButtonsType::Ok
, msg
));
346 xErrorBox
->set_title(sTitle
);
353 bool DialogHelper::installExtensionWarn(std::u16string_view rExtensionName
)
355 const SolarMutexGuard guard
;
357 // Check if extension installation is disabled in the expert configurations
358 if (officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionInstallation::get())
361 std::unique_ptr
<weld::MessageDialog
> xWarnBox(Application::CreateMessageDialog(getFrameWeld(),
362 VclMessageType::Warning
, VclButtonsType::Ok
,
363 DpResId(RID_STR_WARNING_INSTALL_EXTENSION_DISABLED
)));
372 std::unique_ptr
<weld::MessageDialog
> xInfoBox(Application::CreateMessageDialog(getFrameWeld(),
373 VclMessageType::Warning
, VclButtonsType::OkCancel
,
374 DpResId(RID_STR_WARNING_INSTALL_EXTENSION
)));
375 OUString
sText(xInfoBox
->get_primary_text());
376 sText
= sText
.replaceAll("%NAME", rExtensionName
);
377 xInfoBox
->set_primary_text(sText
);
379 bool bRet
= RET_OK
== xInfoBox
->run();
385 bool DialogHelper::installForAllUsers(bool &bInstallForAll
)
387 const SolarMutexGuard guard
;
389 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(getFrameWeld(), "desktop/ui/installforalldialog.ui"));
390 std::unique_ptr
<weld::MessageDialog
> xQuery(xBuilder
->weld_message_dialog("InstallForAllDialog"));
391 short nRet
= xQuery
->run();
394 if (nRet
== RET_CANCEL
)
397 bInstallForAll
= ( nRet
== RET_NO
);
401 void DialogHelper::PostUserEvent( const Link
<void*,void>& rLink
, void* pCaller
)
404 Application::RemoveUserEvent( m_nEventID
);
406 m_nEventID
= Application::PostUserEvent(rLink
, pCaller
);
410 ExtMgrDialog::ExtMgrDialog(weld::Window
*pParent
, TheExtensionManager
*pManager
)
411 : GenericDialogController(pParent
, "desktop/ui/extensionmanager.ui", "ExtensionManagerDialog")
412 , DialogHelper(pManager
->getContext(), m_xDialog
.get())
413 , m_sAddPackages(DpResId(RID_STR_ADD_PACKAGES
))
414 , m_bHasProgress(false)
415 , m_bProgressChanged(false)
416 , m_bStartProgress(false)
417 , m_bStopProgress(false)
418 , m_bEnableWarning(false)
419 , m_bDisableWarning(false)
420 , m_bDeleteWarning(false)
423 , m_aIdle( "ExtMgrDialog m_aIdle TimeOutHdl" )
424 , m_pManager(pManager
)
425 , m_xExtensionBox(new ExtBoxWithBtns_Impl(m_xBuilder
->weld_scrolled_window("scroll", true)))
426 , m_xExtensionBoxWnd(new weld::CustomWeld(*m_xBuilder
, "extensions", *m_xExtensionBox
))
427 , m_xOptionsBtn(m_xBuilder
->weld_button("optionsbtn"))
428 , m_xAddBtn(m_xBuilder
->weld_button("addbtn"))
429 , m_xRemoveBtn(m_xBuilder
->weld_button("removebtn"))
430 , m_xEnableBtn(m_xBuilder
->weld_button("enablebtn"))
431 , m_xUpdateBtn(m_xBuilder
->weld_button("updatebtn"))
432 , m_xCloseBtn(m_xBuilder
->weld_button("close"))
433 , m_xBundledCbx(m_xBuilder
->weld_check_button("bundled"))
434 , m_xSharedCbx(m_xBuilder
->weld_check_button("shared"))
435 , m_xUserCbx(m_xBuilder
->weld_check_button("user"))
436 , m_xGetExtensions(m_xBuilder
->weld_link_button("getextensions"))
437 , m_xProgressText(m_xBuilder
->weld_label("progressft"))
438 , m_xProgressBar(m_xBuilder
->weld_progress_bar("progressbar"))
439 , m_xCancelBtn(m_xBuilder
->weld_button("cancel"))
440 , m_xSearchEntry(m_xBuilder
->weld_entry("search"))
442 m_xExtensionBox
->InitFromDialog(this);
444 m_xEnableBtn
->set_help_id(HID_EXTENSION_MANAGER_LISTBOX_ENABLE
);
446 m_xOptionsBtn
->connect_clicked( LINK( this, ExtMgrDialog
, HandleOptionsBtn
) );
447 m_xAddBtn
->connect_clicked( LINK( this, ExtMgrDialog
, HandleAddBtn
) );
448 m_xRemoveBtn
->connect_clicked( LINK( this, ExtMgrDialog
, HandleRemoveBtn
) );
449 m_xEnableBtn
->connect_clicked( LINK( this, ExtMgrDialog
, HandleEnableBtn
) );
450 m_xCloseBtn
->connect_clicked( LINK( this, ExtMgrDialog
, HandleCloseBtn
) );
452 m_xCancelBtn
->connect_clicked( LINK( this, ExtMgrDialog
, HandleCancelBtn
) );
454 m_xBundledCbx
->connect_toggled( LINK( this, ExtMgrDialog
, HandleExtTypeCbx
) );
455 m_xSharedCbx
->connect_toggled( LINK( this, ExtMgrDialog
, HandleExtTypeCbx
) );
456 m_xUserCbx
->connect_toggled( LINK( this, ExtMgrDialog
, HandleExtTypeCbx
) );
458 m_xSearchEntry
->connect_changed( LINK( this, ExtMgrDialog
, HandleSearch
) );
460 m_xBundledCbx
->set_active(true);
461 m_xSharedCbx
->set_active(true);
462 m_xUserCbx
->set_active(true);
464 m_xProgressBar
->hide();
466 #if ENABLE_EXTENSION_UPDATE
467 m_xUpdateBtn
->connect_clicked( LINK( this, ExtMgrDialog
, HandleUpdateBtn
) );
468 m_xUpdateBtn
->set_sensitive(false);
470 m_xUpdateBtn
->hide();
473 if (officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionInstallation::get())
475 m_xAddBtn
->set_sensitive(false);
476 m_xAddBtn
->set_tooltip_text(DpResId(RID_STR_WARNING_INSTALL_EXTENSION_DISABLED
));
478 if (officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionRemoval::get())
480 m_xRemoveBtn
->set_sensitive(false);
481 m_xRemoveBtn
->set_tooltip_text(DpResId(RID_STR_WARNING_REMOVE_EXTENSION_DISABLED
));
484 m_aIdle
.SetPriority(TaskPriority::LOWEST
);
485 m_aIdle
.SetInvokeHandler( LINK( this, ExtMgrDialog
, TimeOutHdl
) );
488 ExtMgrDialog::~ExtMgrDialog()
493 void ExtMgrDialog::setGetExtensionsURL( const OUString
&rURL
)
495 m_xGetExtensions
->set_uri( rURL
);
498 void ExtMgrDialog::addPackageToList( const uno::Reference
< deployment::XPackage
> &xPackage
,
499 bool bLicenseMissing
)
501 const SolarMutexGuard aGuard
;
502 m_xUpdateBtn
->set_sensitive(true);
504 bool bSearchMatch
= m_xSearchEntry
->get_text().isEmpty();
505 if (!m_xSearchEntry
->get_text().isEmpty()
506 && xPackage
->getDisplayName().toAsciiLowerCase().indexOf(
507 m_xSearchEntry
->get_text().toAsciiLowerCase())
516 if (m_xBundledCbx
->get_active() && (xPackage
->getRepositoryName() == BUNDLED_PACKAGE_MANAGER
) )
518 m_xExtensionBox
->addEntry( xPackage
, bLicenseMissing
);
520 else if (m_xSharedCbx
->get_active() && (xPackage
->getRepositoryName() == SHARED_PACKAGE_MANAGER
) )
522 m_xExtensionBox
->addEntry( xPackage
, bLicenseMissing
);
524 else if (m_xUserCbx
->get_active() && (xPackage
->getRepositoryName() == USER_PACKAGE_MANAGER
))
526 m_xExtensionBox
->addEntry( xPackage
, bLicenseMissing
);
530 void ExtMgrDialog::updateList()
532 // re-creates the list of packages with addEntry selecting the packages
534 m_pManager
->createPackageList();
538 void ExtMgrDialog::prepareChecking()
540 m_xExtensionBox
->prepareChecking();
543 void ExtMgrDialog::checkEntries()
545 const SolarMutexGuard guard
;
546 m_xExtensionBox
->checkEntries();
549 bool ExtMgrDialog::removeExtensionWarn(std::u16string_view rExtensionName
)
551 const SolarMutexGuard guard
;
553 std::unique_ptr
<weld::MessageDialog
> xInfoBox(Application::CreateMessageDialog(m_xDialog
.get(),
554 VclMessageType::Warning
, VclButtonsType::OkCancel
,
555 DpResId(RID_STR_WARNING_REMOVE_EXTENSION
)));
557 OUString
sText(xInfoBox
->get_primary_text());
558 sText
= sText
.replaceAll("%NAME", rExtensionName
);
559 xInfoBox
->set_primary_text(sText
);
561 bool bRet
= RET_OK
== xInfoBox
->run();
568 void ExtMgrDialog::enablePackage( const uno::Reference
< deployment::XPackage
> &xPackage
,
571 if ( !xPackage
.is() )
576 if (!continueOnSharedExtension(xPackage
, m_xDialog
.get(), RID_STR_WARNING_ENABLE_SHARED_EXTENSION
, m_bEnableWarning
))
581 if (!continueOnSharedExtension(xPackage
, m_xDialog
.get(), RID_STR_WARNING_DISABLE_SHARED_EXTENSION
, m_bDisableWarning
))
585 m_pManager
->getCmdQueue()->enableExtension( xPackage
, bEnable
);
589 void ExtMgrDialog::removePackage( const uno::Reference
< deployment::XPackage
> &xPackage
)
591 if ( !xPackage
.is() )
594 if ( !IsSharedPkgMgr( xPackage
) || m_bDeleteWarning
)
596 if ( ! removeExtensionWarn( xPackage
->getDisplayName() ) )
600 if (!continueOnSharedExtension(xPackage
, m_xDialog
.get(), RID_STR_WARNING_REMOVE_SHARED_EXTENSION
, m_bDeleteWarning
))
603 m_pManager
->getCmdQueue()->removeExtension( xPackage
);
607 void ExtMgrDialog::updatePackage( const uno::Reference
< deployment::XPackage
> &xPackage
)
609 if ( !xPackage
.is() )
612 // get the extension with highest version
613 uno::Sequence
<uno::Reference
<deployment::XPackage
> > seqExtensions
=
614 m_pManager
->getExtensionManager()->getExtensionsWithSameIdentifier(
615 dp_misc::getIdentifier(xPackage
), xPackage
->getName(), uno::Reference
<ucb::XCommandEnvironment
>());
616 uno::Reference
<deployment::XPackage
> extension
=
617 dp_misc::getExtensionWithHighestVersion(seqExtensions
);
618 OSL_ASSERT(extension
.is());
619 std::vector
< css::uno::Reference
< css::deployment::XPackage
> > vEntries
{ extension
};
621 m_pManager
->getCmdQueue()->checkForUpdates( std::move(vEntries
) );
625 bool ExtMgrDialog::acceptLicense( const uno::Reference
< deployment::XPackage
> &xPackage
)
627 if ( !xPackage
.is() )
630 m_pManager
->getCmdQueue()->acceptLicense( xPackage
);
636 uno::Sequence
< OUString
> ExtMgrDialog::raiseAddPicker()
638 sfx2::FileDialogHelper
aDlgHelper(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
, FileDialogFlags::NONE
, m_xDialog
.get());
639 aDlgHelper
.SetContext(sfx2::FileDialogHelper::ExtensionManager
);
640 const uno::Reference
<ui::dialogs::XFilePicker3
>& xFilePicker
= aDlgHelper
.GetFilePicker();
641 xFilePicker
->setTitle( m_sAddPackages
);
643 // collect and set filter list:
644 typedef std::map
< OUString
, OUString
> t_string2string
;
645 t_string2string title2filter
;
646 OUStringBuffer supportedFilters
;
648 const uno::Sequence
< uno::Reference
< deployment::XPackageTypeInfo
> > packageTypes(
649 m_pManager
->getExtensionManager()->getSupportedPackageTypes() );
651 for ( uno::Reference
< deployment::XPackageTypeInfo
> const & xPackageType
: packageTypes
)
653 const OUString
filter( xPackageType
->getFileFilter() );
654 if (!filter
.isEmpty())
656 const OUString
title( xPackageType
->getShortDescription() );
657 const std::pair
< t_string2string::iterator
, bool > insertion(
658 title2filter
.emplace( title
, filter
) );
659 if (!supportedFilters
.isEmpty())
660 supportedFilters
.append(';');
661 supportedFilters
.append(filter
);
662 if ( ! insertion
.second
)
663 { // already existing, append extensions:
664 insertion
.first
->second
= insertion
.first
->second
+
670 static const OUString StrAllFiles
= []()
672 const SolarMutexGuard guard
;
673 std::locale loc
= Translate::Create("fps");
674 return Translate::get(STR_FILTERNAME_ALL
, loc
);
678 xFilePicker
->appendFilter( StrAllFiles
, "*.*" );
679 xFilePicker
->appendFilter( DpResId(RID_STR_ALL_SUPPORTED
), supportedFilters
.makeStringAndClear() );
680 // then supported ones:
681 for (auto const& elem
: title2filter
)
685 xFilePicker
->appendFilter( elem
.first
, elem
.second
);
687 catch (const lang::IllegalArgumentException
&)
689 TOOLS_WARN_EXCEPTION( "desktop", "" );
692 xFilePicker
->setCurrentFilter( DpResId(RID_STR_ALL_SUPPORTED
) );
694 if ( xFilePicker
->execute() != ui::dialogs::ExecutableDialogResults::OK
)
695 return uno::Sequence
<OUString
>(); // cancelled
697 uno::Sequence
< OUString
> files( xFilePicker
->getSelectedFiles() );
698 OSL_ASSERT( files
.hasElements() );
702 void ExtMgrDialog::enableOptionsButton( bool bEnable
)
704 m_xOptionsBtn
->set_sensitive( bEnable
);
707 void ExtMgrDialog::enableRemoveButton( bool bEnable
)
709 m_xRemoveBtn
->set_sensitive( bEnable
&& !officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionRemoval::get());
711 if (officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionRemoval::get())
713 m_xRemoveBtn
->set_tooltip_text(DpResId(RID_STR_WARNING_REMOVE_EXTENSION_DISABLED
));
717 m_xRemoveBtn
->set_tooltip_text("");
721 void ExtMgrDialog::enableEnableButton( bool bEnable
)
723 m_xEnableBtn
->set_sensitive( bEnable
);
726 void ExtMgrDialog::enableButtontoEnable( bool bEnable
)
730 m_xEnableBtn
->set_label( DpResId( RID_CTX_ITEM_ENABLE
) );
731 m_xEnableBtn
->set_help_id( HID_EXTENSION_MANAGER_LISTBOX_ENABLE
);
735 m_xEnableBtn
->set_label( DpResId( RID_CTX_ITEM_DISABLE
) );
736 m_xEnableBtn
->set_help_id( HID_EXTENSION_MANAGER_LISTBOX_DISABLE
);
740 IMPL_LINK_NOARG(ExtMgrDialog
, HandleCancelBtn
, weld::Button
&, void)
742 if ( m_xAbortChannel
.is() )
746 m_xAbortChannel
->sendAbort();
748 catch ( const uno::RuntimeException
& )
750 TOOLS_WARN_EXCEPTION( "dbaccess", "" );
755 IMPL_LINK_NOARG(ExtMgrDialog
, HandleCloseBtn
, weld::Button
&, void)
757 bool bCallClose
= true;
759 //only suggest restart if modified and this is the first close attempt
760 if (!m_bClosed
&& m_pManager
->isModified())
762 m_pManager
->clearModified();
764 //only suggest restart if we're actually running, e.g. not from standalone unopkg gui
765 if (dp_misc::office_is_running())
767 SolarMutexGuard aGuard
;
768 bCallClose
= !::svtools::executeRestartDialog(comphelper::getProcessComponentContext(),
770 svtools::RESTART_REASON_EXTENSION_INSTALL
);
775 m_xDialog
->response(RET_CANCEL
);
778 IMPL_LINK( ExtMgrDialog
, startProgress
, void*, _bLockInterface
, void )
780 std::unique_lock
aGuard( m_aMutex
);
781 bool bLockInterface
= static_cast<bool>(_bLockInterface
);
783 if ( m_bStartProgress
&& !m_bHasProgress
)
786 if ( m_bStopProgress
)
788 if ( m_xProgressBar
->get_visible() )
789 m_xProgressBar
->set_percentage( 100 );
790 m_xAbortChannel
.clear();
792 SAL_INFO( "desktop.deployment", " startProgress handler: stop" );
796 SAL_INFO( "desktop.deployment", " startProgress handler: start" );
799 m_xCancelBtn
->set_sensitive( bLockInterface
);
800 m_xAddBtn
->set_sensitive( !bLockInterface
&& !officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionInstallation::get());
801 if (officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionInstallation::get())
803 m_xAddBtn
->set_tooltip_text(DpResId(RID_STR_WARNING_INSTALL_EXTENSION_DISABLED
));
807 m_xAddBtn
->set_tooltip_text("");
810 m_xUpdateBtn
->set_sensitive( !bLockInterface
&& m_xExtensionBox
->getItemCount() );
811 m_xExtensionBox
->enableButtons( !bLockInterface
);
817 void ExtMgrDialog::showProgress( bool _bStart
)
819 std::unique_lock
aGuard( m_aMutex
);
821 bool bStart
= _bStart
;
826 m_bStartProgress
= true;
827 SAL_INFO( "desktop.deployment", "showProgress start" );
832 m_bStopProgress
= true;
833 SAL_INFO( "desktop.deployment", "showProgress stop!" );
836 DialogHelper::PostUserEvent( LINK( this, ExtMgrDialog
, startProgress
), reinterpret_cast<void*>(bStart
) );
841 void ExtMgrDialog::updateProgress( const tools::Long nProgress
)
843 if ( m_nProgress
!= nProgress
)
845 std::unique_lock
aGuard( m_aMutex
);
846 m_nProgress
= nProgress
;
852 void ExtMgrDialog::updateProgress( const OUString
&rText
,
853 const uno::Reference
< task::XAbortChannel
> &xAbortChannel
)
855 std::unique_lock
aGuard( m_aMutex
);
857 m_xAbortChannel
= xAbortChannel
;
858 m_sProgressText
= rText
;
859 m_bProgressChanged
= true;
864 void ExtMgrDialog::updatePackageInfo( const uno::Reference
< deployment::XPackage
> &xPackage
)
866 const SolarMutexGuard aGuard
;
867 m_xExtensionBox
->updateEntry( xPackage
);
870 IMPL_LINK_NOARG(ExtMgrDialog
, HandleOptionsBtn
, weld::Button
&, void)
872 const sal_Int32 nActive
= m_xExtensionBox
->getSelIndex();
874 if ( nActive
!= ExtensionBox_Impl::ENTRY_NOTFOUND
)
876 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
878 OUString sExtensionId
= m_xExtensionBox
->GetEntryData( nActive
)->m_xPackage
->getIdentifier().Value
;
879 ScopedVclPtr
<VclAbstractDialog
> pDlg(pFact
->CreateOptionsDialog(m_xDialog
.get(), sExtensionId
));
885 IMPL_LINK_NOARG(ExtMgrDialog
, HandleAddBtn
, weld::Button
&, void)
889 uno::Sequence
< OUString
> aFileList
= raiseAddPicker();
891 if ( aFileList
.hasElements() )
893 m_pManager
->installPackage( aFileList
[0] );
899 IMPL_LINK_NOARG(ExtMgrDialog
, HandleRemoveBtn
, weld::Button
&, void)
901 const sal_Int32 nActive
= m_xExtensionBox
->getSelIndex();
903 if ( nActive
!= ExtensionBox_Impl::ENTRY_NOTFOUND
)
905 TEntry_Impl pEntry
= m_xExtensionBox
->GetEntryData( nActive
);
906 removePackage( pEntry
->m_xPackage
);
910 IMPL_LINK_NOARG(ExtMgrDialog
, HandleEnableBtn
, weld::Button
&, void)
912 const sal_Int32 nActive
= m_xExtensionBox
->getSelIndex();
914 if ( nActive
!= ExtensionBox_Impl::ENTRY_NOTFOUND
)
916 TEntry_Impl pEntry
= m_xExtensionBox
->GetEntryData( nActive
);
918 if ( pEntry
->m_bMissingLic
)
919 acceptLicense( pEntry
->m_xPackage
);
922 const bool bEnable( pEntry
->m_eState
!= REGISTERED
);
923 enablePackage( pEntry
->m_xPackage
, bEnable
);
928 IMPL_LINK_NOARG(ExtMgrDialog
, HandleExtTypeCbx
, weld::Toggleable
&, void)
933 IMPL_LINK_NOARG(ExtMgrDialog
, HandleSearch
, weld::Entry
&, void)
938 IMPL_LINK_NOARG(ExtMgrDialog
, HandleUpdateBtn
, weld::Button
&, void)
940 #if ENABLE_EXTENSION_UPDATE
941 m_pManager
->checkUpdates();
947 IMPL_LINK_NOARG(ExtMgrDialog
, TimeOutHdl
, Timer
*, void)
949 if ( m_bStopProgress
)
951 m_bHasProgress
= false;
952 m_bStopProgress
= false;
953 m_xProgressText
->hide();
954 m_xProgressBar
->hide();
955 m_xCancelBtn
->hide();
959 if ( m_bProgressChanged
)
961 m_bProgressChanged
= false;
962 m_xProgressText
->set_label(m_sProgressText
);
965 if ( m_bStartProgress
)
967 m_bStartProgress
= false;
968 m_bHasProgress
= true;
969 m_xProgressBar
->show();
970 m_xProgressText
->show();
971 m_xCancelBtn
->set_sensitive(true);
972 m_xCancelBtn
->show();
975 if ( m_xProgressBar
->get_visible() )
976 m_xProgressBar
->set_percentage( static_cast<sal_uInt16
>(m_nProgress
) );
980 void ExtMgrDialog::Close()
982 m_pManager
->terminateDialog();
986 //UpdateRequiredDialog
987 UpdateRequiredDialog::UpdateRequiredDialog(weld::Window
*pParent
, TheExtensionManager
*pManager
)
988 : GenericDialogController(pParent
, "desktop/ui/updaterequireddialog.ui", "UpdateRequiredDialog")
989 , DialogHelper(pManager
->getContext(), m_xDialog
.get())
990 , m_sCloseText(DpResId(RID_STR_CLOSE_BTN
))
991 , m_bHasProgress(false)
992 , m_bProgressChanged(false)
993 , m_bStartProgress(false)
994 , m_bStopProgress(false)
995 , m_bHasLockedEntries(false)
997 , m_aIdle( "UpdateRequiredDialog m_aIdle TimeOutHdl" )
998 , m_pManager(pManager
)
999 , m_xExtensionBox(new ExtensionBox_Impl(m_xBuilder
->weld_scrolled_window("scroll", true)))
1000 , m_xExtensionBoxWnd(new weld::CustomWeld(*m_xBuilder
, "extensions", *m_xExtensionBox
))
1001 , m_xUpdateNeeded(m_xBuilder
->weld_label("updatelabel"))
1002 , m_xUpdateBtn(m_xBuilder
->weld_button("ok"))
1003 , m_xCloseBtn(m_xBuilder
->weld_button("disable"))
1004 , m_xCancelBtn(m_xBuilder
->weld_button("cancel"))
1005 , m_xProgressText(m_xBuilder
->weld_label("progresslabel"))
1006 , m_xProgressBar(m_xBuilder
->weld_progress_bar("progress"))
1008 m_xExtensionBox
->setExtensionManager(pManager
);
1010 m_xUpdateBtn
->connect_clicked( LINK( this, UpdateRequiredDialog
, HandleUpdateBtn
) );
1011 m_xCloseBtn
->connect_clicked( LINK( this, UpdateRequiredDialog
, HandleCloseBtn
) );
1012 m_xCancelBtn
->connect_clicked( LINK( this, UpdateRequiredDialog
, HandleCancelBtn
) );
1014 OUString aText
= m_xUpdateNeeded
->get_label();
1015 aText
= aText
.replaceAll(
1016 "%PRODUCTNAME", utl::ConfigManager::getProductName());
1017 m_xUpdateNeeded
->set_label(aText
);
1019 m_xProgressBar
->hide();
1020 m_xUpdateBtn
->set_sensitive( false );
1021 m_xCloseBtn
->grab_focus();
1023 m_aIdle
.SetPriority( TaskPriority::LOWEST
);
1024 m_aIdle
.SetInvokeHandler( LINK( this, UpdateRequiredDialog
, TimeOutHdl
) );
1027 UpdateRequiredDialog::~UpdateRequiredDialog()
1032 void UpdateRequiredDialog::addPackageToList( const uno::Reference
< deployment::XPackage
> &xPackage
,
1033 bool bLicenseMissing
)
1035 // We will only add entries to the list with unsatisfied dependencies
1036 if ( !bLicenseMissing
&& !checkDependencies( xPackage
) )
1038 m_bHasLockedEntries
|= m_pManager
->isReadOnly( xPackage
);
1039 const SolarMutexGuard aGuard
;
1040 m_xUpdateBtn
->set_sensitive(true);
1041 m_xExtensionBox
->addEntry( xPackage
);
1046 void UpdateRequiredDialog::prepareChecking()
1048 m_xExtensionBox
->prepareChecking();
1052 void UpdateRequiredDialog::checkEntries()
1054 const SolarMutexGuard guard
;
1055 m_xExtensionBox
->checkEntries();
1057 if ( ! hasActiveEntries() )
1059 m_xCloseBtn
->set_label( m_sCloseText
);
1060 m_xCloseBtn
->grab_focus();
1065 IMPL_LINK_NOARG(UpdateRequiredDialog
, HandleCancelBtn
, weld::Button
&, void)
1067 if ( m_xAbortChannel
.is() )
1071 m_xAbortChannel
->sendAbort();
1073 catch ( const uno::RuntimeException
& )
1075 TOOLS_WARN_EXCEPTION( "desktop", "" );
1081 IMPL_LINK( UpdateRequiredDialog
, startProgress
, void*, _bLockInterface
, void )
1083 std::unique_lock
aGuard( m_aMutex
);
1084 bool bLockInterface
= static_cast<bool>(_bLockInterface
);
1086 if ( m_bStartProgress
&& !m_bHasProgress
)
1089 if ( m_bStopProgress
)
1091 if ( m_xProgressBar
->get_visible() )
1092 m_xProgressBar
->set_percentage( 100 );
1093 m_xAbortChannel
.clear();
1094 SAL_INFO( "desktop.deployment", " startProgress handler: stop" );
1098 SAL_INFO( "desktop.deployment", " startProgress handler: start" );
1101 m_xCancelBtn
->set_sensitive( bLockInterface
);
1102 m_xUpdateBtn
->set_sensitive( false );
1107 void UpdateRequiredDialog::showProgress( bool _bStart
)
1109 std::unique_lock
aGuard( m_aMutex
);
1111 bool bStart
= _bStart
;
1116 m_bStartProgress
= true;
1117 SAL_INFO( "desktop.deployment", "showProgress start" );
1122 m_bStopProgress
= true;
1123 SAL_INFO( "desktop.deployment", "showProgress stop!" );
1126 DialogHelper::PostUserEvent( LINK( this, UpdateRequiredDialog
, startProgress
), reinterpret_cast<void*>(bStart
) );
1131 void UpdateRequiredDialog::updateProgress( const tools::Long nProgress
)
1133 if ( m_nProgress
!= nProgress
)
1135 std::unique_lock
aGuard( m_aMutex
);
1136 m_nProgress
= nProgress
;
1142 void UpdateRequiredDialog::updateProgress( const OUString
&rText
,
1143 const uno::Reference
< task::XAbortChannel
> &xAbortChannel
)
1145 std::unique_lock
aGuard( m_aMutex
);
1147 m_xAbortChannel
= xAbortChannel
;
1148 m_sProgressText
= rText
;
1149 m_bProgressChanged
= true;
1154 void UpdateRequiredDialog::updatePackageInfo( const uno::Reference
< deployment::XPackage
> &xPackage
)
1156 // We will remove all updated packages with satisfied dependencies, but
1157 // we will show all disabled entries so the user sees the result
1158 // of the 'disable all' button
1159 const SolarMutexGuard aGuard
;
1160 if ( isEnabled( xPackage
) && checkDependencies( xPackage
) )
1161 m_xExtensionBox
->removeEntry( xPackage
);
1163 m_xExtensionBox
->updateEntry( xPackage
);
1165 if ( ! hasActiveEntries() )
1167 m_xCloseBtn
->set_label( m_sCloseText
);
1168 m_xCloseBtn
->grab_focus();
1173 IMPL_LINK_NOARG(UpdateRequiredDialog
, HandleUpdateBtn
, weld::Button
&, void)
1175 std::unique_lock
aGuard( m_aMutex
);
1177 std::vector
< uno::Reference
< deployment::XPackage
> > vUpdateEntries
;
1178 sal_Int32 nCount
= m_xExtensionBox
->GetEntryCount();
1180 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
1182 TEntry_Impl pEntry
= m_xExtensionBox
->GetEntryData( i
);
1183 vUpdateEntries
.push_back( pEntry
->m_xPackage
);
1188 m_pManager
->getCmdQueue()->checkForUpdates( std::move(vUpdateEntries
) );
1192 IMPL_LINK_NOARG(UpdateRequiredDialog
, HandleCloseBtn
, weld::Button
&, void)
1194 std::unique_lock
aGuard( m_aMutex
);
1198 if ( m_bHasLockedEntries
)
1199 m_xDialog
->response(-1);
1200 else if ( hasActiveEntries() )
1201 disableAllEntries();
1203 m_xDialog
->response(RET_CANCEL
);
1208 IMPL_LINK_NOARG(UpdateRequiredDialog
, TimeOutHdl
, Timer
*, void)
1210 if ( m_bStopProgress
)
1212 m_bHasProgress
= false;
1213 m_bStopProgress
= false;
1214 m_xProgressText
->hide();
1215 m_xProgressBar
->hide();
1216 m_xCancelBtn
->hide();
1220 if ( m_bProgressChanged
)
1222 m_bProgressChanged
= false;
1223 m_xProgressText
->set_label( m_sProgressText
);
1226 if ( m_bStartProgress
)
1228 m_bStartProgress
= false;
1229 m_bHasProgress
= true;
1230 m_xProgressBar
->show();
1231 m_xProgressText
->show();
1232 m_xCancelBtn
->set_sensitive(true);
1233 m_xCancelBtn
->show();
1236 if (m_xProgressBar
->get_visible())
1237 m_xProgressBar
->set_percentage(m_nProgress
);
1242 short UpdateRequiredDialog::run()
1245 //I believe m_bHasLockedEntries was used to prevent showing extensions which cannot
1246 //be disabled because they are in a read only repository. However, disabling extensions
1247 //is now always possible because the registration data of all repositories
1248 //are in the user installation.
1249 //Therefore all extensions could be displayed and all the handling around m_bHasLockedEntries
1251 if ( m_bHasLockedEntries
)
1253 // Set other text, disable update btn, remove not shared entries from list;
1254 m_xUpdateNeeded
->set_label( DpResId( RID_STR_NO_ADMIN_PRIVILEGE
) );
1255 m_xCloseBtn
->set_label( DpResId( RID_STR_EXIT_BTN
) );
1256 m_xUpdateBtn
->set_sensitive( false );
1257 m_xExtensionBox
->RemoveUnlocked();
1260 return GenericDialogController::run();
1263 // Check dependencies of all packages
1265 bool UpdateRequiredDialog::isEnabled( const uno::Reference
< deployment::XPackage
> &xPackage
)
1267 bool bRegistered
= false;
1269 beans::Optional
< beans::Ambiguous
< sal_Bool
> > option( xPackage
->isRegistered( uno::Reference
< task::XAbortChannel
>(),
1270 uno::Reference
< ucb::XCommandEnvironment
>() ) );
1271 if ( option
.IsPresent
)
1273 ::beans::Ambiguous
< sal_Bool
> const & reg
= option
.Value
;
1274 if ( reg
.IsAmbiguous
)
1275 bRegistered
= false;
1277 bRegistered
= reg
.Value
;
1280 bRegistered
= false;
1282 catch ( const uno::RuntimeException
& ) { throw; }
1283 catch (const uno::Exception
& ) {
1284 TOOLS_WARN_EXCEPTION( "desktop", "" );
1285 bRegistered
= false;
1291 // Checks the dependencies no matter if the extension is enabled or disabled!
1292 bool UpdateRequiredDialog::checkDependencies( const uno::Reference
< deployment::XPackage
> &xPackage
)
1294 bool bDependenciesValid
= false;
1296 bDependenciesValid
= xPackage
->checkDependencies( uno::Reference
< ucb::XCommandEnvironment
>() );
1298 catch ( const deployment::DeploymentException
& ) {}
1299 return bDependenciesValid
;
1303 bool UpdateRequiredDialog::hasActiveEntries()
1305 std::unique_lock
aGuard( m_aMutex
);
1308 tools::Long nCount
= m_xExtensionBox
->GetEntryCount();
1309 for ( tools::Long nIndex
= 0; nIndex
< nCount
; nIndex
++ )
1311 TEntry_Impl pEntry
= m_xExtensionBox
->GetEntryData( nIndex
);
1313 if ( isEnabled(pEntry
->m_xPackage
) && !checkDependencies( pEntry
->m_xPackage
) )
1324 void UpdateRequiredDialog::disableAllEntries()
1326 std::unique_lock
aGuard( m_aMutex
);
1330 tools::Long nCount
= m_xExtensionBox
->GetEntryCount();
1331 for ( tools::Long nIndex
= 0; nIndex
< nCount
; nIndex
++ )
1333 TEntry_Impl pEntry
= m_xExtensionBox
->GetEntryData( nIndex
);
1334 m_pManager
->getCmdQueue()->enableExtension( pEntry
->m_xPackage
, false );
1339 if ( ! hasActiveEntries() )
1340 m_xCloseBtn
->set_label( m_sCloseText
);
1343 // ShowLicenseDialog
1344 ShowLicenseDialog::ShowLicenseDialog(weld::Window
* pParent
,
1345 const uno::Reference
< deployment::XPackage
> &xPackage
)
1346 : GenericDialogController(pParent
, "desktop/ui/showlicensedialog.ui", "ShowLicenseDialog")
1347 , m_xLicenseText(m_xBuilder
->weld_text_view("textview"))
1349 m_xLicenseText
->set_size_request(m_xLicenseText
->get_approximate_digit_width() * 72,
1350 m_xLicenseText
->get_height_rows(21));
1351 m_xLicenseText
->set_text(xPackage
->getLicenseText());
1354 ShowLicenseDialog::~ShowLicenseDialog()
1358 // UpdateRequiredDialogService
1360 UpdateRequiredDialogService::UpdateRequiredDialogService( SAL_UNUSED_PARAMETER
uno::Sequence
< uno::Any
> const&,
1361 uno::Reference
< uno::XComponentContext
> xComponentContext
)
1362 : m_xComponentContext(std::move( xComponentContext
))
1367 OUString
UpdateRequiredDialogService::getImplementationName()
1369 return "com.sun.star.comp.deployment.ui.UpdateRequiredDialog";
1372 sal_Bool
UpdateRequiredDialogService::supportsService( const OUString
& ServiceName
)
1374 return cppu::supportsService(this, ServiceName
);
1377 css::uno::Sequence
< OUString
> UpdateRequiredDialogService::getSupportedServiceNames()
1379 return { "com.sun.star.deployment.ui.UpdateRequiredDialog" };
1383 // XExecutableDialog
1385 void UpdateRequiredDialogService::setTitle( OUString
const & )
1390 sal_Int16
UpdateRequiredDialogService::execute()
1392 ::rtl::Reference
< ::dp_gui::TheExtensionManager
> xManager( TheExtensionManager::get(
1393 m_xComponentContext
) );
1394 xManager
->createDialog( true );
1395 sal_Int16 nRet
= xManager
->execute();
1401 } //namespace dp_gui
1403 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */