[Libreoffice-commits] core.git: cui/source
Yusuf Keten (via logerrit)
logerrit at kemper.freedesktop.org
Mon Aug 24 12:34:42 UTC 2020
cui/source/dialogs/AdditionsDialog.cxx | 139 ++++++++++++++++++++++++++++++++-
cui/source/inc/AdditionsDialog.hxx | 38 ++++++++-
2 files changed, 174 insertions(+), 3 deletions(-)
New commits:
commit 169cbf05aaa87b625387325a708c1f254499972b
Author: Yusuf Keten <ketenyusuf at gmail.com>
AuthorDate: Fri Aug 14 03:34:10 2020 +0300
Commit: Muhammet Kara <muhammet.kara at collabora.com>
CommitDate: Mon Aug 24 14:34:02 2020 +0200
tdf#133026: Additions: Install Extension Function
Change-Id: Ifcad25a85533833c7d05e5be46ea763e1eeaa5d4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100714
Tested-by: Jenkins
Reviewed-by: Muhammet Kara <muhammet.kara at collabora.com>
diff --git a/cui/source/dialogs/AdditionsDialog.cxx b/cui/source/dialogs/AdditionsDialog.cxx
index 9f8826dce6cc..b0a5421f54f2 100644
--- a/cui/source/dialogs/AdditionsDialog.cxx
+++ b/cui/source/dialogs/AdditionsDialog.cxx
@@ -50,6 +50,9 @@
#include <com/sun/star/ucb/CommandAbortedException.hpp>
#include <com/sun/star/ucb/CommandFailedException.hpp>
+#include <com/sun/star/task/XInteractionApprove.hpp>
+#include <cppuhelper/implbase.hxx>
+
//cURL
#include <curl/curl.h>
#include <orcus/json_document_tree.hpp>
@@ -74,6 +77,7 @@ using ::com::sun::star::graphic::XGraphicProvider;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::beans::PropertyValue;
using ::com::sun::star::graphic::XGraphic;
+
using namespace com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ucb;
@@ -264,7 +268,6 @@ bool getPreviewFile(const AdditionInfo& aAdditionInfo, OUString& sPreviewFile)
{
uno::Reference<ucb::XSimpleFileAccess3> xFileAccess
= ucb::SimpleFileAccess::create(comphelper::getProcessComponentContext());
- Reference<XComponentContext> xContext(::comphelper::getProcessComponentContext());
// copy the images to the user's additions folder
OUString userFolder = "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
@@ -595,6 +598,7 @@ AdditionsItem::AdditionsItem(weld::Widget* pParent, AdditionsDialog* pParentDial
, m_xButtonShowMore(m_xBuilder->weld_button("buttonShowMore"))
, m_pParentDialog(pParentDialog)
, m_sDownloadURL("")
+ , m_sExtensionID("")
{
SolarMutexGuard aGuard;
@@ -632,11 +636,41 @@ AdditionsItem::AdditionsItem(weld::Widget* pParent, AdditionsDialog* pParentDial
m_xLabelDownloadNumber->set_label(additionInfo.sDownloadNumber);
m_pParentDialog = pParentDialog;
m_sDownloadURL = additionInfo.sDownloadURL;
+ m_sExtensionID = additionInfo.sExtensionID;
m_xButtonShowMore->connect_clicked(LINK(this, AdditionsItem, ShowMoreHdl));
m_xButtonInstall->connect_clicked(LINK(this, AdditionsItem, InstallHdl));
}
+bool AdditionsItem::getExtensionFile(OUString& sExtensionFile)
+{
+ uno::Reference<ucb::XSimpleFileAccess3> xFileAccess
+ = ucb::SimpleFileAccess::create(comphelper::getProcessComponentContext());
+
+ // copy the extensions' files to the user's additions folder
+ OUString userFolder = "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
+ "/" SAL_CONFIGFILE("bootstrap") "::UserInstallation}";
+ rtl::Bootstrap::expandMacros(userFolder);
+ userFolder += "/user/additions/" + m_sExtensionID + "/";
+
+ OUString aExtesionsFile(INetURLObject(m_sDownloadURL).getName());
+ OString aExtesionsURL = OUStringToOString(m_sDownloadURL, RTL_TEXTENCODING_UTF8);
+
+ try
+ {
+ osl::Directory::createPath(userFolder);
+
+ if (!xFileAccess->exists(userFolder + aExtesionsFile))
+ curlDownload(aExtesionsURL, userFolder + aExtesionsFile);
+ }
+ catch (const uno::Exception&)
+ {
+ return false;
+ }
+ sExtensionFile = userFolder + aExtesionsFile;
+ return true;
+}
+
IMPL_LINK_NOARG(AdditionsDialog, ImplUpdateDataHdl, Timer*, void)
{
if (m_pSearchThread.is())
@@ -681,7 +715,108 @@ IMPL_LINK_NOARG(AdditionsItem, ShowMoreHdl, weld::Button&, void)
IMPL_LINK_NOARG(AdditionsItem, InstallHdl, weld::Button&, void)
{
- m_xButtonInstall->set_label("Success");
+ m_xButtonInstall->set_label("Installing");
+ m_xButtonInstall->set_sensitive(false);
+ OUString aExtensionFile;
+ bool bResult = getExtensionFile(aExtensionFile); // info vector json data
+
+ if (!bResult)
+ {
+ m_xButtonInstall->set_label("Install");
+ m_xButtonInstall->set_sensitive(true);
+
+ SAL_INFO("cui.dialogs", "Couldn't get the extension file.");
+ return;
+ }
+
+ TmpRepositoryCommandEnv* pCmdEnv = new TmpRepositoryCommandEnv();
+ uno::Reference<ucb::XCommandEnvironment> xCmdEnv(static_cast<cppu::OWeakObject*>(pCmdEnv),
+ uno::UNO_QUERY);
+ uno::Reference<task::XAbortChannel> xAbortChannel;
+ try
+ {
+ m_pParentDialog->m_xExtensionManager->addExtension(
+ aExtensionFile, uno::Sequence<beans::NamedValue>(), "user", xAbortChannel, xCmdEnv);
+ m_xButtonInstall->set_label("Installed");
+ }
+ catch (const ucb::CommandFailedException)
+ {
+ SAL_WARN("cui.dialogs", "Additions: addExtension CommandFailedException occured.");
+ m_xButtonInstall->set_label("Install");
+ m_xButtonInstall->set_sensitive(true);
+ }
+ catch (const ucb::CommandAbortedException)
+ {
+ SAL_WARN("cui.dialogs", "Additions: addExtension CommandAbortedException occured.");
+ m_xButtonInstall->set_label("Install");
+ m_xButtonInstall->set_sensitive(true);
+ }
+ catch (const deployment::DeploymentException)
+ {
+ SAL_WARN("cui.dialogs", "Additions: addExtension DeploymentException occured.");
+ m_xButtonInstall->set_label("Install");
+ m_xButtonInstall->set_sensitive(true);
+ }
+ catch (const lang::IllegalArgumentException)
+ {
+ SAL_WARN("cui.dialogs", "Additions: addExtension IllegalArgumentException occured.");
+ m_xButtonInstall->set_label("Install");
+ m_xButtonInstall->set_sensitive(true);
+ }
+ catch (const css::uno::Exception)
+ {
+ SAL_WARN("cui.dialogs", "Additions: addExtension Exception occured.");
+ m_xButtonInstall->set_label("Install");
+ m_xButtonInstall->set_sensitive(true);
+ }
+}
+
+// TmpRepositoryCommandEnv
+
+TmpRepositoryCommandEnv::TmpRepositoryCommandEnv() {}
+
+TmpRepositoryCommandEnv::~TmpRepositoryCommandEnv() {}
+// XCommandEnvironment
+
+uno::Reference<task::XInteractionHandler> TmpRepositoryCommandEnv::getInteractionHandler()
+{
+ return this;
+}
+
+uno::Reference<ucb::XProgressHandler> TmpRepositoryCommandEnv::getProgressHandler() { return this; }
+
+// XInteractionHandler
+void TmpRepositoryCommandEnv::handle(uno::Reference<task::XInteractionRequest> const& xRequest)
+{
+ OSL_ASSERT(xRequest->getRequest().getValueTypeClass() == uno::TypeClass_EXCEPTION);
+
+ bool approve = true;
+
+ // select:
+ uno::Sequence<Reference<task::XInteractionContinuation>> conts(xRequest->getContinuations());
+ Reference<task::XInteractionContinuation> const* pConts = conts.getConstArray();
+ sal_Int32 len = conts.getLength();
+ for (sal_Int32 pos = 0; pos < len; ++pos)
+ {
+ if (approve)
+ {
+ uno::Reference<task::XInteractionApprove> xInteractionApprove(pConts[pos],
+ uno::UNO_QUERY);
+ if (xInteractionApprove.is())
+ {
+ xInteractionApprove->select();
+ // don't query again for ongoing continuations:
+ approve = false;
+ }
+ }
+ }
}
+// XProgressHandler
+void TmpRepositoryCommandEnv::push(uno::Any const& /*Status*/) {}
+
+void TmpRepositoryCommandEnv::update(uno::Any const& /*Status */) {}
+
+void TmpRepositoryCommandEnv::pop() {}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/source/inc/AdditionsDialog.hxx b/cui/source/inc/AdditionsDialog.hxx
index 71df58c63b7f..5b7089b9b6c5 100644
--- a/cui/source/inc/AdditionsDialog.hxx
+++ b/cui/source/inc/AdditionsDialog.hxx
@@ -29,6 +29,17 @@
#include <com/sun/star/deployment/ExtensionManager.hpp>
#include <com/sun/star/deployment/XPackageManager.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/task/XJob.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
+#include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
+#include <com/sun/star/ucb/XCommandEnvironment.hpp>
+#include <com/sun/star/ucb/XProgressHandler.hpp>
+#include <cppuhelper/implbase.hxx>
+
class AdditionsDialog;
class SearchAndParseThread;
class AdditionsItem;
@@ -56,7 +67,6 @@ class AdditionsDialog : public weld::GenericDialogController
{
private:
Timer m_aSearchDataTimer;
- css::uno::Reference<css::deployment::XExtensionManager> m_xExtensionManager;
DECL_LINK(SearchUpdateHdl, weld::Entry&, void);
DECL_LINK(ImplUpdateDataHdl, Timer*, void);
@@ -64,6 +74,7 @@ private:
DECL_LINK(CloseButtonHdl, weld::Button&, void);
public:
+ css::uno::Reference<css::deployment::XExtensionManager> m_xExtensionManager;
std::unique_ptr<weld::Entry> m_xEntrySearch;
std::unique_ptr<weld::Button> m_xButtonClose;
std::unique_ptr<weld::MenuButton> m_xMenuButtonSettings;
@@ -98,6 +109,7 @@ class AdditionsItem
public:
AdditionsItem(weld::Widget* pParent, AdditionsDialog* pParentDialog,
AdditionInfo& additionInfo);
+ bool getExtensionFile(OUString& sExtensionFile);
DECL_LINK(ShowMoreHdl, weld::Button&, void);
DECL_LINK(InstallHdl, weld::Button&, void);
@@ -120,6 +132,7 @@ public:
std::unique_ptr<weld::Button> m_xButtonShowMore;
AdditionsDialog* m_pParentDialog;
OUString m_sDownloadURL;
+ OUString m_sExtensionID;
};
class SearchAndParseThread : public salhelper::Thread
@@ -142,4 +155,27 @@ public:
void StopExecution() { m_bExecute = false; }
};
+class TmpRepositoryCommandEnv
+ : public ::cppu::WeakImplHelper<css::ucb::XCommandEnvironment, css::task::XInteractionHandler,
+ css::ucb::XProgressHandler>
+{
+public:
+ virtual ~TmpRepositoryCommandEnv() override;
+ TmpRepositoryCommandEnv();
+
+ // XCommandEnvironment
+ virtual css::uno::Reference<css::task::XInteractionHandler>
+ SAL_CALL getInteractionHandler() override;
+ virtual css::uno::Reference<css::ucb::XProgressHandler> SAL_CALL getProgressHandler() override;
+
+ // XInteractionHandler
+ virtual void SAL_CALL
+ handle(css::uno::Reference<css::task::XInteractionRequest> const& xRequest) override;
+
+ // XProgressHandler
+ virtual void SAL_CALL push(css::uno::Any const& Status) override;
+ virtual void SAL_CALL update(css::uno::Any const& Status) override;
+ virtual void SAL_CALL pop() override;
+};
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list