2012-11-09 19:10:38 +01:00
|
|
|
/* -*- 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/.
|
|
|
|
*/
|
|
|
|
|
2017-10-23 22:32:26 +02:00
|
|
|
#include "SyncDbusSessionHelper.hxx"
|
2012-11-09 19:10:38 +01:00
|
|
|
|
|
|
|
#include <gio/gio.h>
|
2015-05-18 12:16:13 +02:00
|
|
|
#include <memory>
|
2012-11-09 19:10:38 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2017-12-22 11:01:14 +00:00
|
|
|
struct GVariantDeleter { void operator()(GVariant* pV) { if (pV) g_variant_unref(pV); } };
|
2012-11-09 19:10:38 +01:00
|
|
|
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:
|
2016-09-09 13:26:44 +02:00
|
|
|
explicit GErrorWrapper() : m_pError(nullptr) {}
|
2016-01-19 10:37:55 +01:00
|
|
|
~GErrorWrapper() noexcept(false)
|
2012-11-09 19:10:38 +01:00
|
|
|
{
|
|
|
|
if(!m_pError)
|
|
|
|
return;
|
|
|
|
OUString sMsg = OUString::createFromAscii(m_pError->message);
|
|
|
|
g_error_free(m_pError);
|
2014-05-28 10:25:22 +02:00
|
|
|
throw RuntimeException(sMsg);
|
2012-11-09 19:10:38 +01:00
|
|
|
}
|
2014-06-18 12:14:29 +02:00
|
|
|
GError*& getRef() { return m_pError; }
|
2012-11-09 19:10:38 +01:00
|
|
|
};
|
2018-10-09 10:28:48 +02:00
|
|
|
GDBusProxy* lcl_GetPackageKitProxy(const OUString& sInterface)
|
2012-11-09 19:10:38 +01:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
const OString sFullInterface = OUStringToOString("org.freedesktop.PackageKit." + sInterface, RTL_TEXTENCODING_ASCII_US);
|
2015-11-10 10:23:46 +01:00
|
|
|
GDBusProxy* proxy = nullptr;
|
2016-01-19 10:37:55 +01:00
|
|
|
{
|
2016-09-09 13:26:44 +02:00
|
|
|
GErrorWrapper error;
|
2016-01-19 10:37:55 +01:00
|
|
|
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
|
2015-11-10 10:23:46 +01:00
|
|
|
G_DBUS_PROXY_FLAGS_NONE, nullptr,
|
2012-11-09 19:10:38 +01:00
|
|
|
"org.freedesktop.PackageKit",
|
|
|
|
"/org/freedesktop/PackageKit",
|
|
|
|
reinterpret_cast<const gchar*>(sFullInterface.getStr()),
|
2015-11-10 10:23:46 +01:00
|
|
|
nullptr,
|
2014-06-18 12:14:29 +02:00
|
|
|
&error.getRef());
|
2016-01-19 10:37:55 +01:00
|
|
|
}
|
2012-11-09 19:10:38 +01:00
|
|
|
if(!proxy)
|
2017-11-13 00:20:20 +01:00
|
|
|
throw RuntimeException("couldn't get a proxy!");
|
2012-11-09 19:10:38 +01:00
|
|
|
return proxy;
|
2012-11-10 08:46:53 +01:00
|
|
|
}
|
2015-05-13 16:29:38 +02:00
|
|
|
|
2018-01-09 12:07:50 +00:00
|
|
|
GVariant* pk_make_platform_data()
|
|
|
|
{
|
|
|
|
GVariantBuilder builder;
|
|
|
|
g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
|
|
|
|
return g_variant_builder_end(&builder);
|
|
|
|
}
|
|
|
|
|
2015-05-13 16:29:38 +02:00
|
|
|
void request(
|
2018-01-09 12:07:50 +00:00
|
|
|
char const * method,
|
2015-05-13 16:29:38 +02:00
|
|
|
css::uno::Sequence<OUString> const & resources,
|
|
|
|
OUString const & interaction)
|
|
|
|
{
|
2018-04-12 09:11:03 +02:00
|
|
|
// Keep strings alive until after call to g_dbus_proxy_call_sync
|
|
|
|
std::vector<OString> resUtf8;
|
2015-05-13 16:29:38 +02:00
|
|
|
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));
|
2018-04-12 09:11:03 +02:00
|
|
|
resUtf8.push_back(s);
|
2015-05-13 16:29:38 +02:00
|
|
|
g_variant_builder_add(builder.get(), "s", s.getStr());
|
|
|
|
}
|
|
|
|
auto iactUtf8(OUStringToOString(interaction, RTL_TEXTENCODING_UTF8));
|
|
|
|
std::shared_ptr<GDBusProxy> proxy(
|
2018-01-09 12:07:50 +00:00
|
|
|
lcl_GetPackageKitProxy("Modify2"), GObjectDeleter<GDBusProxy>());
|
2016-09-09 13:26:44 +02:00
|
|
|
GErrorWrapper error;
|
2017-12-22 11:01:14 +00:00
|
|
|
std::shared_ptr<GVariant> result(g_dbus_proxy_call_sync(
|
2015-05-13 16:29:38 +02:00
|
|
|
proxy.get(), method,
|
|
|
|
g_variant_new(
|
2018-01-09 12:07:50 +00:00
|
|
|
"(asss@a{sv})", builder.get(), iactUtf8.getStr(),
|
|
|
|
"libreoffice-startcenter.desktop", pk_make_platform_data()),
|
2017-12-22 11:01:14 +00:00
|
|
|
G_DBUS_CALL_FLAGS_NONE, -1, nullptr, &error.getRef()), GVariantDeleter());
|
2015-05-13 16:29:38 +02:00
|
|
|
}
|
|
|
|
|
2012-11-09 19:10:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace shell { namespace sessioninstall
|
|
|
|
{
|
|
|
|
SyncDbusSessionHelper::SyncDbusSessionHelper(Reference<XComponentContext> const&)
|
|
|
|
{
|
2013-04-19 17:41:20 +04:00
|
|
|
#if !GLIB_CHECK_VERSION(2,36,0)
|
2012-11-09 19:10:38 +01:00
|
|
|
g_type_init ();
|
2013-04-17 20:04:45 +04:00
|
|
|
#endif
|
2012-11-09 19:10:38 +01:00
|
|
|
}
|
2015-05-13 16:29:38 +02:00
|
|
|
|
|
|
|
void SyncDbusSessionHelper::InstallPackageFiles(
|
2018-01-09 12:07:50 +00:00
|
|
|
css::uno::Sequence<OUString> const & files,
|
2015-05-13 16:29:38 +02:00
|
|
|
OUString const & interaction)
|
|
|
|
{
|
2018-01-09 12:07:50 +00:00
|
|
|
request("InstallPackageFiles", files, interaction);
|
2015-05-13 16:29:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SyncDbusSessionHelper::InstallProvideFiles(
|
2018-01-09 12:07:50 +00:00
|
|
|
css::uno::Sequence<OUString> const & files,
|
2015-05-13 16:29:38 +02:00
|
|
|
OUString const & interaction)
|
|
|
|
{
|
2018-01-09 12:07:50 +00:00
|
|
|
request("InstallProvideFiles", files, interaction);
|
2015-05-13 16:29:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SyncDbusSessionHelper::InstallCatalogs(
|
2018-01-09 12:07:50 +00:00
|
|
|
css::uno::Sequence<OUString> const & files,
|
2015-05-13 16:29:38 +02:00
|
|
|
OUString const & interaction)
|
|
|
|
{
|
2018-01-09 12:07:50 +00:00
|
|
|
request("InstallCatalogs", files, interaction);
|
2015-05-13 16:29:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SyncDbusSessionHelper::InstallPackageNames(
|
2018-01-09 12:07:50 +00:00
|
|
|
css::uno::Sequence<OUString> const & packages,
|
2015-05-13 16:29:38 +02:00
|
|
|
OUString const & interaction)
|
|
|
|
{
|
2018-01-09 12:07:50 +00:00
|
|
|
request("InstallPackageNames", packages, interaction);
|
2015-05-13 16:29:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SyncDbusSessionHelper::InstallMimeTypes(
|
2018-01-09 12:07:50 +00:00
|
|
|
css::uno::Sequence<OUString> const & mimeTypes,
|
2015-05-13 16:29:38 +02:00
|
|
|
OUString const & interaction)
|
|
|
|
{
|
2018-01-09 12:07:50 +00:00
|
|
|
request("InstallMimeTypes", mimeTypes, interaction);
|
2015-05-13 16:29:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SyncDbusSessionHelper::InstallFontconfigResources(
|
2018-01-09 12:07:50 +00:00
|
|
|
css::uno::Sequence<OUString> const & resources,
|
2015-05-13 16:29:38 +02:00
|
|
|
OUString const & interaction)
|
|
|
|
{
|
2018-01-09 12:07:50 +00:00
|
|
|
request("InstallFontconfigResources", resources, interaction);
|
2015-05-13 16:29:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SyncDbusSessionHelper::InstallGStreamerResources(
|
2018-01-09 12:07:50 +00:00
|
|
|
css::uno::Sequence<OUString> const & resources,
|
2015-05-13 16:29:38 +02:00
|
|
|
OUString const & interaction)
|
|
|
|
{
|
2018-01-09 12:07:50 +00:00
|
|
|
request("InstallGStreamerResources", resources, interaction);
|
2015-05-13 16:29:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SyncDbusSessionHelper::RemovePackageByFiles(
|
2018-01-09 12:07:50 +00:00
|
|
|
css::uno::Sequence<OUString> const & files,
|
2015-05-13 16:29:38 +02:00
|
|
|
OUString const & interaction)
|
|
|
|
{
|
2018-01-09 12:07:50 +00:00
|
|
|
request("RemovePackageByFiles", files, interaction);
|
2015-05-13 16:29:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SyncDbusSessionHelper::InstallPrinterDrivers(
|
2018-01-09 12:07:50 +00:00
|
|
|
css::uno::Sequence<OUString> const & files,
|
2015-05-13 16:29:38 +02:00
|
|
|
OUString const & interaction)
|
|
|
|
{
|
2018-01-09 15:40:25 +00:00
|
|
|
request("InstallPrinterDrivers", files, interaction);
|
2015-05-13 16:29:38 +02:00
|
|
|
}
|
2012-11-09 19:10:38 +01:00
|
|
|
|
2017-12-22 11:25:29 +00:00
|
|
|
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.get())
|
|
|
|
o_isInstalled = bool(g_variant_get_boolean(g_variant_get_child_value(result.get(),0)));
|
|
|
|
}
|
|
|
|
|
2012-11-09 19:10:38 +01:00
|
|
|
}}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|