24#include <osl/file.hxx>
30#include <com/sun/star/beans/NamedValue.hpp>
31#include <com/sun/star/lang/WrappedTargetException.hpp>
32#include <com/sun/star/ucb/NameClash.hpp>
33#include <com/sun/star/ucb/XCommandEnvironment.hpp>
34#include <com/sun/star/ucb/XProgressHandler.hpp>
35#include <com/sun/star/deployment/DeploymentException.hpp>
36#include <com/sun/star/deployment/ExtensionManager.hpp>
37#include <com/sun/star/deployment/LicenseException.hpp>
38#include <com/sun/star/deployment/VersionException.hpp>
39#include <com/sun/star/task/XInteractionHandler.hpp>
40#include <com/sun/star/task/XInteractionApprove.hpp>
50#include <rtl/ustrbuf.hxx>
53#include <com/sun/star/uno/Sequence.h>
66 Thread(css::uno::Reference< css::uno::XComponentContext >
const & ctx,
74 virtual void execute()
override;
83 css::uno::Reference< css::task::XAbortChannel >
m_abort;
96 :
public ::cppu::WeakImplHelper< css::ucb::XCommandEnvironment,
97 css::task::XInteractionHandler,
98 css::ucb::XProgressHandler >
103 css::uno::Reference< css::uno::XComponentContext >
m_xContext;
110 virtual css::uno::Reference<css::task::XInteractionHandler > SAL_CALL
112 virtual css::uno::Reference<css::ucb::XProgressHandler >
116 virtual void SAL_CALL
handle(
117 css::uno::Reference<css::task::XInteractionRequest >
const & xRequest )
override;
120 virtual void SAL_CALL
push( css::uno::Any
const &
Status )
override;
121 virtual void SAL_CALL
update( css::uno::Any
const &
Status )
override;
122 virtual void SAL_CALL
pop()
override;
127 css::uno::Reference< css::uno::XComponentContext>
const & xCtx,
129 std::vector< dp_gui::UpdateData > & aVecUpdateData):
133 m_aVecUpdateData(aVecUpdateData),
139 css::uno::Reference< css::task::XAbortChannel > abort;
155 downloadExtensions();
164 removeTempDownloads();
172 m_dialog.updateDone();
175 m_updateCmdEnv->m_installThread.clear();
180 std::vector<dp_gui::UpdateData> & aVecUpdateData,
181 css::uno::Reference< css::uno::XComponentContext >
const & xCtx)
183 "UpdateInstallDialog")
220 short nRet = GenericDialogController::run();
230 m_xOk->set_sensitive(
true);
238 std::u16string_view exceptionMessage)
260 sError = sError.replaceFirst(
"%NAME", sExtension);
269 if (!exceptionMessage.empty())
294 if (::osl::FileBase::getTempDirURL(sTempDir) != ::osl::FileBase::E_None)
295 throw css::uno::Exception(
"Could not get URL for the temp directory. No extensions will be installed.",
nullptr);
298 OUString tempEntry, destFolder;
299 if (::osl::File::createTempFile(&sTempDir,
nullptr, &tempEntry ) != ::osl::File::E_None)
300 throw css::uno::Exception(
"Could not create a temporary file in " + sTempDir +
301 ". No extensions will be installed",
nullptr );
303 tempEntry = tempEntry.copy( tempEntry.lastIndexOf(
'/' ) + 1 );
306 m_sDownloadFolder = destFolder;
310 }
catch (
const css::uno::Exception & e)
313 throw css::lang::WrappedTargetException( e.Message +
" No extensions will be installed",
318 sal_uInt16
count = 0;
319 for (
auto & updateData : m_aVecUpdateData)
321 if (!updateData.aUpdateInfo.is() || updateData.aUpdateSource.is())
325 OSL_ASSERT(updateData.sWebsiteURL.isEmpty());
333 m_dialog.m_xFt_extension_name->set_label(updateData.aInstalledPackage->getDisplayName());
334 sal_uInt16 prog = (sal::static_int_cast<sal_uInt16>(100) * ++
count) /
335 sal::static_int_cast<sal_uInt16>(m_aVecUpdateData.size());
336 m_dialog.m_xStatusbar->set_percentage(prog);
340 std::vector< std::pair<OUString, css::uno::Exception> > vecExceptions;
342 OSL_ENSURE(seqDownloadURLs.hasElements(),
"No download URL provided!");
343 for (sal_Int32 j = 0; j < seqDownloadURLs.getLength(); j++)
347 OSL_ENSURE(!seqDownloadURLs[j].isEmpty(),
"Download URL is empty!");
348 bool bCancelled = download(seqDownloadURLs[j], updateData);
349 if (bCancelled || !updateData.sLocalURL.isEmpty())
352 catch ( css::uno::Exception & e )
354 vecExceptions.emplace_back(seqDownloadURLs[j], e);
367 if (updateData.sLocalURL.isEmpty())
370 OUStringBuffer buf(256);
372 for (
auto const& elem : vecExceptions)
376 buf.append(
"Could not download " + elem.first +
". " + elem.second.Message);
386 catch (
const css::uno::Exception & e)
392 m_dialog.setError(e.Message);
404 m_dialog.m_xFt_action->set_label(m_dialog.m_sInstalling);
405 m_dialog.m_xStatusbar->set_percentage(0);
408 sal_uInt16
count = 0;
409 for (
auto const& updateData : m_aVecUpdateData)
419 m_dialog.m_xStatusbar->set_percentage(
420 (sal::static_int_cast<sal_uInt16>(100) *
count) /
421 sal::static_int_cast<sal_uInt16>(m_aVecUpdateData.size()));
423 m_dialog.m_xFt_extension_name->set_label(updateData.aInstalledPackage->getDisplayName());
426 bool bLicenseDeclined =
false;
427 css::uno::Reference<css::deployment::XPackage> xExtension;
428 css::uno::Exception exc;
431 css::uno::Reference< css::task::XAbortChannel > xAbortChannel(
432 updateData.aInstalledPackage->createAbortChannel() );
438 m_abort = xAbortChannel;
440 if (!updateData.aUpdateSource.is() && !updateData.sLocalURL.isEmpty())
442 css::beans::NamedValue prop(
"EXTENSION_UPDATE", css::uno::Any(OUString(
"1")));
443 if (!updateData.bIsShared)
444 xExtension = m_dialog.getExtensionManager()->addExtension(
445 updateData.sLocalURL, css::uno::Sequence<css::beans::NamedValue>(&prop, 1),
446 "user", xAbortChannel, m_updateCmdEnv);
448 xExtension = m_dialog.getExtensionManager()->addExtension(
449 updateData.sLocalURL, css::uno::Sequence<css::beans::NamedValue>(&prop, 1),
450 "shared", xAbortChannel, m_updateCmdEnv);
452 else if (updateData.aUpdateSource.is())
454 OSL_ASSERT(updateData.aUpdateSource.is());
459 css::beans::NamedValue prop(
"EXTENSION_UPDATE", css::uno::Any(OUString(
"1")));
460 if (!updateData.bIsShared)
461 xExtension = m_dialog.getExtensionManager()->addExtension(
462 updateData.aUpdateSource->getURL(), css::uno::Sequence<css::beans::NamedValue>(&prop, 1),
463 "user", xAbortChannel, m_updateCmdEnv);
465 xExtension = m_dialog.getExtensionManager()->addExtension(
466 updateData.aUpdateSource->getURL(), css::uno::Sequence<css::beans::NamedValue>(&prop, 1),
467 "shared", xAbortChannel, m_updateCmdEnv);
470 catch (css::deployment::DeploymentException & de)
472 if (de.Cause.has<css::deployment::LicenseException>())
474 bLicenseDeclined =
true;
478 exc = de.Cause.get<css::uno::Exception>();
482 catch (css::uno::Exception& e)
488 if (bLicenseDeclined)
495 updateData.aInstalledPackage->getDisplayName(), std::u16string_view());
497 else if (!xExtension.is() || bError)
504 updateData.aInstalledPackage->getDisplayName(), exc.Message);
513 m_dialog.m_xStatusbar->set_percentage(100);
514 m_dialog.m_xFt_extension_name->set_label(OUString());
515 m_dialog.m_xFt_action->set_label(m_dialog.m_sFinished);
521 if (!m_sDownloadFolder.isEmpty())
524 css::uno::Reference<css::ucb::XCommandEnvironment>(),
false );
526 OUString tempFile = m_sDownloadFolder.copy(0, m_sDownloadFolder.getLength() - 1);
528 m_sDownloadFolder.clear();
541 OSL_ASSERT(m_sDownloadFolder.getLength());
542 OUString destFolder, tempEntry;
543 if (::osl::File::createTempFile(
545 nullptr, &tempEntry ) != ::osl::File::E_None)
548 throw css::uno::Exception(
"Could not create temporary file in folder " + destFolder +
".",
nullptr);
550 tempEntry = tempEntry.copy( tempEntry.lastIndexOf(
'/' ) + 1 );
560 const OUString sTitle( StrTitle::getTitle( sourceContent ) );
564 sTitle, css::ucb::NameClash::OVERWRITE );
573 aUpdateData.
sLocalURL = destFolder +
"/" + sTitle;
581 : m_installThread(
std::move(thread)),
599 css::uno::Reference< css::task::XInteractionRequest>
const & xRequest )
601 css::uno::Any request( xRequest->getRequest() );
602 OSL_ASSERT( request.getValueTypeClass() == css::uno::TypeClass_EXCEPTION );
604 + ::comphelper::anyToString(request) +
"\n\n");
606 css::deployment::VersionException verExc;
607 bool approve =
false;
609 if (request >>= verExc)
626 css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > conts(
627 xRequest->getContinuations() );
628 css::uno::Reference< css::task::XInteractionContinuation >
const * pConts =
629 conts.getConstArray();
630 sal_Int32 len = conts.getLength();
631 for ( sal_Int32
pos = 0;
pos < len; ++
pos )
634 css::uno::Reference< css::task::XInteractionApprove > xInteractionApprove(
635 pConts[
pos ], css::uno::UNO_QUERY );
636 if (xInteractionApprove.is()) {
637 xInteractionApprove->select();
virtual void SAL_CALL handle(css::uno::Reference< css::task::XInteractionRequest > const &xRequest) override
virtual css::uno::Reference< css::ucb::XProgressHandler > SAL_CALL getProgressHandler() override
UpdateCommandEnv(css::uno::Reference< css::uno::XComponentContext > xCtx, ::rtl::Reference< UpdateInstallDialog::Thread > thread)
virtual void SAL_CALL update(css::uno::Any const &Status) override
virtual void SAL_CALL push(css::uno::Any const &Status) override
virtual void SAL_CALL pop() override
virtual css::uno::Reference< css::task::XInteractionHandler > SAL_CALL getInteractionHandler() override
css::uno::Reference< css::uno::XComponentContext > m_xContext
::rtl::Reference< UpdateInstallDialog::Thread > m_installThread
css::uno::Reference< css::uno::XComponentContext > m_xComponentContext
::rtl::Reference< UpdateCommandEnv > m_updateCmdEnv
bool download(OUString const &aUrls, UpdateData &aUpdatData)
Thread(css::uno::Reference< css::uno::XComponentContext > const &ctx, UpdateInstallDialog &dialog, std::vector< dp_gui::UpdateData > &aVecUpdateData)
virtual ~Thread() override
UpdateInstallDialog & m_dialog
void downloadExtensions()
css::uno::Reference< css::task::XAbortChannel > m_abort
std::vector< dp_gui::UpdateData > & m_aVecUpdateData
virtual void execute() override
void removeTempDownloads()
OUString m_sDownloadFolder
The modal “Download and Installation” dialog.
virtual short run() override
std::unique_ptr< weld::ProgressBar > m_xStatusbar
std::unique_ptr< weld::Label > m_xFt_extension_name
void setError(INSTALL_ERROR err, std::u16string_view sExtension, std::u16string_view exceptionMessage)
std::unique_ptr< weld::Button > m_xCancel
OUString m_sErrorInstallation
rtl::Reference< Thread > m_thread
std::unique_ptr< weld::Label > m_xFt_action
virtual ~UpdateInstallDialog() override
std::unique_ptr< weld::Button > m_xHelp
OUString m_sErrorDownload
OUString m_sThisErrorOccurred
std::unique_ptr< weld::TextView > m_xMle_info
std::unique_ptr< weld::Button > m_xOk
OUString m_sErrorLicenseDeclined
css::uno::Reference< css::deployment::XExtensionManager > m_xExtensionManager
UpdateInstallDialog(weld::Window *parent, std::vector< UpdateData > &aVecUpdateData, css::uno::Reference< css::uno::XComponentContext > const &xCtx)
Create an instance.
Access to the content of an XML description element.
css::uno::Sequence< OUString > getUpdateDownloadUrls() const
Return the download URLs from the update information.
void transferContent(const Content &rSourceContent, InsertOperation eOperation, const OUString &rTitle, const sal_Int32 nNameClashAction, const OUString &rMimeType=OUString(), bool bMajorVersion=false, const OUString &rCommentVersion=OUString(), OUString *pResultURL=nullptr, const OUString &rDocumentId=OUString()) const
std::shared_ptr< weld::Dialog > m_xDialog
GenericDialogController(weld::Widget *pParent, const OUString &rUIFile, const OUString &rDialogId, bool bMobile=false)
std::unique_ptr< weld::Builder > m_xBuilder
uno::Reference< uno::XComponentContext > m_xContext
Reference< XComponentContext > const m_xComponentContext
OUString DpResId(TranslateId aId)
#define LINK(Instance, Class, Member)
Any SAL_CALL getCaughtException()
void handleInteractionRequest(const uno::Reference< uno::XComponentContext > &xContext, const uno::Reference< task::XInteractionRequest > &xRequest)
IMPL_LINK_NOARG(ExtMgrDialog, HandleCancelBtn, weld::Button &, void)
OUString makeURL(std::u16string_view baseURL, OUString const &relPath_)
appends a relative path to a url.
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool create_folder(::ucbhelper::Content *ucb_content, OUString const &url, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv, bool throw_exc=true)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool erase_path(OUString const &url, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv, bool throw_exc=true)
void TRACE(OUString const &sText)
print the text to the console in a debug build.
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool create_ucb_content(::ucbhelper::Content *ucb_content, OUString const &url, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv, bool throw_exc=true)