LCOV - code coverage report
Current view: top level - shell/source/sessioninstall - SyncDbusSessionHelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 2 72 2.8 %
Date: 2015-06-13 12:38:46 Functions: 1 19 5.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  */
       9             : 
      10             : #include <SyncDbusSessionHelper.hxx>
      11             : 
      12             : #include <gio/gio.h>
      13             : #include <memory>
      14             : #include <vector>
      15             : 
      16             : using namespace ::com::sun::star::lang;
      17             : using namespace ::com::sun::star::uno;
      18             : 
      19             : namespace
      20             : {
      21           0 :     struct GVariantDeleter { void operator()(GVariant* pV) { g_variant_unref(pV); } };
      22           0 :     struct GVariantBuilderDeleter { void operator()(GVariantBuilder* pVB) { g_variant_builder_unref(pVB); } };
      23           0 :     template <typename T> struct GObjectDeleter { void operator()(T* pO) { g_object_unref(pO); } };
      24             :     class GErrorWrapper
      25             :     {
      26             :         GError* m_pError;
      27             :         public:
      28           0 :             GErrorWrapper(GError* pError) : m_pError(pError) {}
      29           0 :             ~GErrorWrapper()
      30             :             {
      31           0 :                 if(!m_pError)
      32           0 :                     return;
      33           0 :                 OUString sMsg = OUString::createFromAscii(m_pError->message);
      34           0 :                 g_error_free(m_pError);
      35           0 :                 throw RuntimeException(sMsg);
      36           0 :             }
      37           0 :             GError*& getRef() { return m_pError; }
      38             :     };
      39           0 :     static inline GDBusProxy* lcl_GetPackageKitProxy(const OUString& sInterface)
      40             :     {
      41           0 :         const OString sFullInterface = OUStringToOString("org.freedesktop.PackageKit." + sInterface, RTL_TEXTENCODING_ASCII_US);
      42           0 :         GErrorWrapper error(NULL);
      43           0 :         GDBusProxy* proxy = NULL;
      44             :         proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
      45             :                                G_DBUS_PROXY_FLAGS_NONE, NULL,
      46             :                                "org.freedesktop.PackageKit",
      47             :                                "/org/freedesktop/PackageKit",
      48           0 :                                reinterpret_cast<const gchar*>(sFullInterface.getStr()),
      49             :                                NULL,
      50           0 :                                &error.getRef());
      51           0 :         if(!proxy)
      52           0 :             throw RuntimeException("couldnt get a proxy!");
      53           0 :         return proxy;
      54             :     }
      55             : 
      56           0 : void request(
      57             :     char const * method, sal_uInt32 xid,
      58             :     css::uno::Sequence<OUString> const & resources,
      59             :     OUString const & interaction)
      60             : {
      61           0 :     std::vector<OString> resUtf8;
      62             :     std::shared_ptr<GVariantBuilder> builder(
      63           0 :         g_variant_builder_new(G_VARIANT_TYPE ("as")), GVariantBuilderDeleter());
      64           0 :     for (auto & i: resources) {
      65           0 :         auto s(OUStringToOString(i, RTL_TEXTENCODING_UTF8));
      66           0 :         resUtf8.push_back(s);
      67           0 :         g_variant_builder_add(builder.get(), "s", s.getStr());
      68           0 :     }
      69           0 :     auto iactUtf8(OUStringToOString(interaction, RTL_TEXTENCODING_UTF8));
      70             :     std::shared_ptr<GDBusProxy> proxy(
      71           0 :         lcl_GetPackageKitProxy("Modify"), GObjectDeleter<GDBusProxy>());
      72           0 :     GErrorWrapper error(nullptr);
      73             :     g_dbus_proxy_call_sync(
      74             :         proxy.get(), method,
      75             :         g_variant_new(
      76             :             "(uass)", static_cast<guint32>(xid), builder.get(),
      77             :             iactUtf8.getStr()),
      78           0 :         G_DBUS_CALL_FLAGS_NONE, -1, nullptr, &error.getRef());
      79           0 : }
      80             : 
      81             : }
      82             : 
      83             : namespace shell { namespace sessioninstall
      84             : {
      85           1 :     SyncDbusSessionHelper::SyncDbusSessionHelper(Reference<XComponentContext> const&)
      86             :     {
      87             : #if !GLIB_CHECK_VERSION(2,36,0)
      88             :         g_type_init ();
      89             : #endif
      90           1 :     }
      91             : 
      92           0 : void SyncDbusSessionHelper::InstallPackageFiles(
      93             :     sal_uInt32 xid, css::uno::Sequence<OUString> const & files,
      94             :     OUString const & interaction)
      95             :     throw (css::uno::RuntimeException, std::exception)
      96             : {
      97           0 :     request("InstallPackageFiles", xid, files, interaction);
      98           0 : }
      99             : 
     100           0 : void SyncDbusSessionHelper::InstallProvideFiles(
     101             :     sal_uInt32 xid, css::uno::Sequence<OUString> const & files,
     102             :     OUString const & interaction)
     103             :     throw (css::uno::RuntimeException, std::exception)
     104             : {
     105           0 :     request("InstallProvideFiles", xid, files, interaction);
     106           0 : }
     107             : 
     108           0 : void SyncDbusSessionHelper::InstallCatalogs(
     109             :     sal_uInt32 xid, css::uno::Sequence<OUString> const & files,
     110             :     OUString const & interaction)
     111             :     throw (css::uno::RuntimeException, std::exception)
     112             : {
     113           0 :     request("InstallCatalogs", xid, files, interaction);
     114           0 : }
     115             : 
     116           0 : void SyncDbusSessionHelper::InstallPackageNames(
     117             :     sal_uInt32 xid, css::uno::Sequence<OUString> const & packages,
     118             :     OUString const & interaction)
     119             :     throw (css::uno::RuntimeException, std::exception)
     120             : {
     121           0 :     request("InstallPackageNames", xid, packages, interaction);
     122           0 : }
     123             : 
     124           0 : void SyncDbusSessionHelper::InstallMimeTypes(
     125             :     sal_uInt32 xid, css::uno::Sequence<OUString> const & mimeTypes,
     126             :     OUString const & interaction)
     127             :     throw (css::uno::RuntimeException, std::exception)
     128             : {
     129           0 :     request("InstallMimeTypes", xid, mimeTypes, interaction);
     130           0 : }
     131             : 
     132           0 : void SyncDbusSessionHelper::InstallFontconfigResources(
     133             :     sal_uInt32 xid, css::uno::Sequence<OUString> const & resources,
     134             :     OUString const & interaction)
     135             :     throw (css::uno::RuntimeException, std::exception)
     136             : {
     137           0 :     request("InstallFontconfigResources", xid, resources, interaction);
     138           0 : }
     139             : 
     140           0 : void SyncDbusSessionHelper::InstallGStreamerResources(
     141             :     sal_uInt32 xid, css::uno::Sequence<OUString> const & resources,
     142             :     OUString const & interaction)
     143             :     throw (css::uno::RuntimeException, std::exception)
     144             : {
     145           0 :     request("InstallGStreamerResources", xid, resources, interaction);
     146           0 : }
     147             : 
     148           0 : void SyncDbusSessionHelper::RemovePackageByFiles(
     149             :     sal_uInt32 xid, css::uno::Sequence<OUString> const & files,
     150             :     OUString const & interaction)
     151             :     throw (css::uno::RuntimeException, std::exception)
     152             : {
     153           0 :     request("RemovePackageByFiles", xid, files, interaction);
     154           0 : }
     155             : 
     156           0 : void SyncDbusSessionHelper::InstallPrinterDrivers(
     157             :     sal_uInt32 xid, css::uno::Sequence<OUString> const & files,
     158             :     OUString const & interaction)
     159             :     throw (css::uno::RuntimeException, std::exception)
     160             : {
     161           0 :     request("InstallPrinteDrivers", xid, files, interaction);
     162           0 : }
     163             : 
     164           0 :     void SAL_CALL SyncDbusSessionHelper::IsInstalled( const OUString& sPackagename, const OUString& sInteraction, sal_Bool& o_isInstalled ) throw (RuntimeException, std::exception)
     165             :     {
     166           0 :         const OString sPackagenameAscii = OUStringToOString(sPackagename, RTL_TEXTENCODING_ASCII_US);
     167           0 :         const OString sInteractionAscii = OUStringToOString(sInteraction, RTL_TEXTENCODING_ASCII_US);
     168           0 :         std::shared_ptr<GDBusProxy> proxy(lcl_GetPackageKitProxy("Query"), GObjectDeleter<GDBusProxy>());
     169           0 :         GErrorWrapper error(NULL);
     170             :         std::shared_ptr<GVariant> result(g_dbus_proxy_call_sync (proxy.get(),
     171             :                          "IsInstalled",
     172             :                          g_variant_new ("(ss)",
     173             :                                 sPackagenameAscii.getStr(),
     174             :                                 sInteractionAscii.getStr()),
     175             :                          G_DBUS_CALL_FLAGS_NONE,
     176             :                          -1, /* timeout */
     177             :                          NULL, /* cancellable */
     178           0 :                          &error.getRef()),GVariantDeleter());
     179           0 :         if(result.get())
     180           0 :             o_isInstalled = g_variant_get_boolean(g_variant_get_child_value(result.get(),0)) ? sal_True : sal_False;
     181           0 :     }
     182             : }}
     183             : 
     184             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11