summaryrefslogtreecommitdiffstats
path: root/shell/source/sessioninstall
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--shell/source/sessioninstall/SyncDbusSessionHelper.cxx186
-rw-r--r--shell/source/sessioninstall/SyncDbusSessionHelper.hxx60
-rw-r--r--shell/source/sessioninstall/losessioninstall.component15
-rw-r--r--shell/source/sessioninstall/services.cxx37
4 files changed, 298 insertions, 0 deletions
diff --git a/shell/source/sessioninstall/SyncDbusSessionHelper.cxx b/shell/source/sessioninstall/SyncDbusSessionHelper.cxx
new file mode 100644
index 000000000..6e35a069f
--- /dev/null
+++ b/shell/source/sessioninstall/SyncDbusSessionHelper.cxx
@@ -0,0 +1,186 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "SyncDbusSessionHelper.hxx"
+
+#include <gio/gio.h>
+#include <memory>
+#include <vector>
+
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::uno;
+
+namespace
+{
+ struct GVariantDeleter { void operator()(GVariant* pV) { if (pV) g_variant_unref(pV); } };
+ struct GVariantBuilderDeleter { void operator()(GVariantBuilder* pVB) { g_variant_builder_unref(pVB); } };
+ template <typename T> struct GObjectDeleter { void operator()(T* pO) { g_object_unref(pO); } };
+ class GErrorWrapper
+ {
+ GError* m_pError;
+ public:
+ explicit GErrorWrapper() : m_pError(nullptr) {}
+ ~GErrorWrapper() noexcept(false)
+ {
+ if(!m_pError)
+ return;
+ OUString sMsg = OUString::createFromAscii(m_pError->message);
+ g_error_free(m_pError);
+ throw RuntimeException(sMsg);
+ }
+ GError*& getRef() { return m_pError; }
+ };
+ GDBusProxy* lcl_GetPackageKitProxy(const OUString& sInterface)
+ {
+ const OString sFullInterface = OUStringToOString("org.freedesktop.PackageKit." + sInterface, RTL_TEXTENCODING_ASCII_US);
+ GDBusProxy* proxy = nullptr;
+ {
+ GErrorWrapper error;
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE, nullptr,
+ "org.freedesktop.PackageKit",
+ "/org/freedesktop/PackageKit",
+ reinterpret_cast<const gchar*>(sFullInterface.getStr()),
+ nullptr,
+ &error.getRef());
+ }
+ if(!proxy)
+ throw RuntimeException("couldn't get a proxy!");
+ return proxy;
+ }
+
+ GVariant* pk_make_platform_data()
+ {
+ GVariantBuilder builder;
+ g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
+ return g_variant_builder_end(&builder);
+ }
+
+void request(
+ char const * method,
+ css::uno::Sequence<OUString> const & resources,
+ OUString const & interaction)
+{
+ // Keep strings alive until after call to g_dbus_proxy_call_sync
+ std::vector<OString> resUtf8;
+ std::shared_ptr<GVariantBuilder> builder(
+ g_variant_builder_new(G_VARIANT_TYPE ("as")), GVariantBuilderDeleter());
+ for (auto & i: resources) {
+ auto s(OUStringToOString(i, RTL_TEXTENCODING_UTF8));
+ resUtf8.push_back(s);
+ g_variant_builder_add(builder.get(), "s", s.getStr());
+ }
+ auto iactUtf8(OUStringToOString(interaction, RTL_TEXTENCODING_UTF8));
+ std::shared_ptr<GDBusProxy> proxy(
+ lcl_GetPackageKitProxy("Modify2"), GObjectDeleter<GDBusProxy>());
+ GErrorWrapper error;
+ std::shared_ptr<GVariant> result(g_dbus_proxy_call_sync(
+ proxy.get(), method,
+ g_variant_new(
+ "(asss@a{sv})", builder.get(), iactUtf8.getStr(),
+ "libreoffice-startcenter.desktop", pk_make_platform_data()),
+ G_DBUS_CALL_FLAGS_NONE, -1, nullptr, &error.getRef()), GVariantDeleter());
+}
+
+}
+
+namespace shell::sessioninstall
+{
+ SyncDbusSessionHelper::SyncDbusSessionHelper(Reference<XComponentContext> const&)
+ {
+#if !GLIB_CHECK_VERSION(2,36,0)
+ g_type_init ();
+#endif
+ }
+
+void SyncDbusSessionHelper::InstallPackageFiles(
+ css::uno::Sequence<OUString> const & files,
+ OUString const & interaction)
+{
+ request("InstallPackageFiles", files, interaction);
+}
+
+void SyncDbusSessionHelper::InstallProvideFiles(
+ css::uno::Sequence<OUString> const & files,
+ OUString const & interaction)
+{
+ request("InstallProvideFiles", files, interaction);
+}
+
+void SyncDbusSessionHelper::InstallCatalogs(
+ css::uno::Sequence<OUString> const & files,
+ OUString const & interaction)
+{
+ request("InstallCatalogs", files, interaction);
+}
+
+void SyncDbusSessionHelper::InstallPackageNames(
+ css::uno::Sequence<OUString> const & packages,
+ OUString const & interaction)
+{
+ request("InstallPackageNames", packages, interaction);
+}
+
+void SyncDbusSessionHelper::InstallMimeTypes(
+ css::uno::Sequence<OUString> const & mimeTypes,
+ OUString const & interaction)
+{
+ request("InstallMimeTypes", mimeTypes, interaction);
+}
+
+void SyncDbusSessionHelper::InstallFontconfigResources(
+ css::uno::Sequence<OUString> const & resources,
+ OUString const & interaction)
+{
+ request("InstallFontconfigResources", resources, interaction);
+}
+
+void SyncDbusSessionHelper::InstallGStreamerResources(
+ css::uno::Sequence<OUString> const & resources,
+ OUString const & interaction)
+{
+ request("InstallGStreamerResources", resources, interaction);
+}
+
+void SyncDbusSessionHelper::RemovePackageByFiles(
+ css::uno::Sequence<OUString> const & files,
+ OUString const & interaction)
+{
+ request("RemovePackageByFiles", files, interaction);
+}
+
+void SyncDbusSessionHelper::InstallPrinterDrivers(
+ css::uno::Sequence<OUString> const & files,
+ OUString const & interaction)
+{
+ request("InstallPrinterDrivers", files, interaction);
+}
+
+void SAL_CALL SyncDbusSessionHelper::IsInstalled( const OUString& sPackagename, const OUString& sInteraction, sal_Bool& o_isInstalled )
+{
+ const OString sPackagenameAscii = OUStringToOString(sPackagename, RTL_TEXTENCODING_ASCII_US);
+ const OString sInteractionAscii = OUStringToOString(sInteraction, RTL_TEXTENCODING_ASCII_US);
+ std::shared_ptr<GDBusProxy> proxy(lcl_GetPackageKitProxy("Query"), GObjectDeleter<GDBusProxy>());
+ GErrorWrapper error;
+ std::shared_ptr<GVariant> result(g_dbus_proxy_call_sync (proxy.get(),
+ "IsInstalled",
+ g_variant_new ("(ss)",
+ sPackagenameAscii.getStr(),
+ sInteractionAscii.getStr()),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, /* timeout */
+ nullptr, /* cancellable */
+ &error.getRef()),GVariantDeleter());
+ if(result)
+ o_isInstalled = bool(g_variant_get_boolean(g_variant_get_child_value(result.get(),0)));
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/sessioninstall/SyncDbusSessionHelper.hxx b/shell/source/sessioninstall/SyncDbusSessionHelper.hxx
new file mode 100644
index 000000000..0db9a1d8e
--- /dev/null
+++ b/shell/source/sessioninstall/SyncDbusSessionHelper.hxx
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SHELL_SOURCE_SESSIONINSTALL_SYNCDBUSSESSIONHELPER_HXX
+#define INCLUDED_SHELL_SOURCE_SESSIONINSTALL_SYNCDBUSSESSIONHELPER_HXX
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <org/freedesktop/PackageKit/SyncDbusSessionHelper.hpp>
+#include <cppuhelper/implbase.hxx>
+
+namespace shell::sessioninstall
+{
+ class SyncDbusSessionHelper : public ::cppu::WeakImplHelper< ::org::freedesktop::PackageKit::XSyncDbusSessionHelper >
+ {
+ public:
+ SyncDbusSessionHelper(css::uno::Reference< css::uno::XComponentContext> const&);
+
+ // XModify Methods
+ virtual void SAL_CALL InstallPackageFiles( const css::uno::Sequence< OUString >& files, const OUString& interaction ) override;
+
+ virtual void SAL_CALL InstallProvideFiles( const css::uno::Sequence< OUString >& files, const OUString& interaction ) override;
+
+ virtual void SAL_CALL InstallCatalogs( const css::uno::Sequence< OUString >& files, const OUString& interaction ) override;
+
+ virtual void SAL_CALL InstallPackageNames( const css::uno::Sequence< OUString >& packages, const OUString& interaction ) override;
+
+ virtual void SAL_CALL InstallMimeTypes( const css::uno::Sequence< OUString >& mimeTypes, const OUString& interaction ) override;
+
+ virtual void SAL_CALL InstallFontconfigResources( const css::uno::Sequence< OUString >& resources, const OUString& interaction ) override;
+
+ virtual void SAL_CALL InstallGStreamerResources( const css::uno::Sequence< OUString >& resources, const OUString& interaction ) override;
+
+ virtual void SAL_CALL InstallResources( const css::uno::Sequence< OUString >& /* types */, const css::uno::Sequence< OUString >& /* resources */, const OUString& /* interaction */ ) override
+ { throw css::uno::RuntimeException(); } // not implemented
+
+ virtual void SAL_CALL RemovePackageByFiles( const css::uno::Sequence< OUString >& files, const OUString& interaction ) override;
+
+ virtual void SAL_CALL InstallPrinterDrivers( const css::uno::Sequence< OUString >& files, const OUString& interaction ) override;
+
+ // XQuery Methods
+ virtual void SAL_CALL IsInstalled( const OUString& /* package_name */, const OUString& /* interaction */, sal_Bool& /* installed */ ) override;
+
+ virtual void SAL_CALL SearchFile( const OUString& /* file_name */, const OUString& /* interaction */, sal_Bool& /* installed */, OUString& /* package_name */ ) override
+ { throw css::uno::RuntimeException(); } // not implemented
+
+ private:
+ SyncDbusSessionHelper( const SyncDbusSessionHelper& ) = delete;
+ SyncDbusSessionHelper& operator=( const SyncDbusSessionHelper& ) = delete;
+ };
+}
+
+#endif // INCLUDED_SHELL_SOURCE_SESSIONINSTALL_SYNCDBUSSESSIONHELPER_HXX
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/sessioninstall/losessioninstall.component b/shell/source/sessioninstall/losessioninstall.component
new file mode 100644
index 000000000..9d63cd5ec
--- /dev/null
+++ b/shell/source/sessioninstall/losessioninstall.component
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+-->
+<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
+ prefix="sessioninstall" xmlns="http://openoffice.org/2010/uno-components">
+ <implementation name="org.libreoffice.comp.shell.sessioninstall.SyncDbusSessionHelper">
+ <service name="org.freedesktop.PackageKit.SyncDbusSessionHelper"/>
+ </implementation>
+</component>
diff --git a/shell/source/sessioninstall/services.cxx b/shell/source/sessioninstall/services.cxx
new file mode 100644
index 000000000..4b72bff19
--- /dev/null
+++ b/shell/source/sessioninstall/services.cxx
@@ -0,0 +1,37 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "SyncDbusSessionHelper.hxx"
+#include <comphelper/servicedecl.hxx>
+#include <uno/environment.h>
+
+namespace sdecl = ::comphelper::service_decl;
+
+sdecl::class_< ::shell::sessioninstall::SyncDbusSessionHelper> const SyncDbusSessionHelperServiceImpl;
+
+const sdecl::ServiceDecl SyncDbusSessionHelperServiceDecl(
+ SyncDbusSessionHelperServiceImpl,
+ "org.libreoffice.comp.shell.sessioninstall.SyncDbusSessionHelper",
+ "org.freedesktop.PackageKit.SyncDbusSessionHelper");
+
+extern "C"
+SAL_DLLPUBLIC_EXPORT void* losessioninstall_component_getFactory( char const* pImplName,
+ void*, void* )
+{
+ return sdecl::component_getFactoryHelper( pImplName, {&SyncDbusSessionHelperServiceDecl} );
+}
+
+extern "C"
+SAL_DLLPUBLIC_EXPORT void* sessioninstall_component_getFactory( char const* pImplName, void* pServiceManager, void* pRegistryKey )
+{
+ return losessioninstall_component_getFactory(pImplName, pServiceManager, pRegistryKey);
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */