LCOV - code coverage report
Current view: top level - shell/source/sessioninstall - SyncDbusSessionHelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 2 44 4.5 %
Date: 2014-11-03 Functions: 1 10 10.0 %
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 <vector>
      14             : #include <boost/shared_ptr.hpp>
      15             : 
      16             : using namespace ::com::sun::star::lang;
      17             : using namespace ::com::sun::star::uno;
      18             : using namespace ::std;
      19             : 
      20             : namespace
      21             : {
      22           0 :     struct GVariantDeleter { void operator()(GVariant* pV) { g_variant_unref(pV); } };
      23           0 :     struct GVariantBuilderDeleter { void operator()(GVariantBuilder* pVB) { g_variant_builder_unref(pVB); } };
      24           0 :     template <typename T> struct GObjectDeleter { void operator()(T* pO) { g_object_unref(pO); } };
      25             :     class GErrorWrapper
      26             :     {
      27             :         GError* m_pError;
      28             :         public:
      29           0 :             GErrorWrapper(GError* pError) : m_pError(pError) {}
      30           0 :             ~GErrorWrapper()
      31             :             {
      32           0 :                 if(!m_pError)
      33           0 :                     return;
      34           0 :                 OUString sMsg = OUString::createFromAscii(m_pError->message);
      35           0 :                 g_error_free(m_pError);
      36           0 :                 throw RuntimeException(sMsg);
      37           0 :             }
      38           0 :             GError*& getRef() { return m_pError; }
      39             :     };
      40           0 :     static inline GDBusProxy* lcl_GetPackageKitProxy(const OUString& sInterface)
      41             :     {
      42           0 :         const OString sFullInterface = OUStringToOString("org.freedesktop.PackageKit." + sInterface, RTL_TEXTENCODING_ASCII_US);
      43           0 :         GErrorWrapper error(NULL);
      44           0 :         GDBusProxy* proxy = NULL;
      45             :         proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
      46             :                                G_DBUS_PROXY_FLAGS_NONE, NULL,
      47             :                                "org.freedesktop.PackageKit",
      48             :                                "/org/freedesktop/PackageKit",
      49           0 :                                reinterpret_cast<const gchar*>(sFullInterface.getStr()),
      50             :                                NULL,
      51           0 :                                &error.getRef());
      52           0 :         if(!proxy)
      53           0 :             throw RuntimeException("couldnt get a proxy!");
      54           0 :         return proxy;
      55             :     }
      56             : }
      57             : 
      58             : namespace shell { namespace sessioninstall
      59             : {
      60           2 :     SyncDbusSessionHelper::SyncDbusSessionHelper(Reference<XComponentContext> const&)
      61             :     {
      62             : #if !GLIB_CHECK_VERSION(2,36,0)
      63             :         g_type_init ();
      64             : #endif
      65           2 :     }
      66           0 :     void SAL_CALL SyncDbusSessionHelper::InstallPackageNames( const ::sal_uInt32 nXid, const Sequence< OUString >& vPackages, const OUString& sInteraction ) throw (RuntimeException, std::exception)
      67             :     {
      68           0 :         vector< OString > vPackagesOString;
      69           0 :         vPackagesOString.reserve(vPackages.getLength());
      70           0 :         boost::shared_ptr<GVariantBuilder> pBuilder(g_variant_builder_new(G_VARIANT_TYPE ("as")), GVariantBuilderDeleter());
      71           0 :         for( const OUString* pPackage = vPackages.begin(); pPackage != vPackages.end(); ++pPackage)
      72             :         {
      73           0 :             vPackagesOString.push_back(OUStringToOString(*pPackage, RTL_TEXTENCODING_ASCII_US));
      74           0 :             g_variant_builder_add(pBuilder.get(), "s", vPackagesOString.back().getStr());
      75             :         }
      76             : 
      77           0 :         const OString sInteractionAscii = OUStringToOString(sInteraction, RTL_TEXTENCODING_ASCII_US);
      78           0 :         boost::shared_ptr<GDBusProxy> proxy(lcl_GetPackageKitProxy("Modify"), GObjectDeleter<GDBusProxy>());
      79           0 :         GErrorWrapper error(NULL);
      80             :         g_dbus_proxy_call_sync (proxy.get(),
      81             :                          "InstallPackageNames",
      82             :                          g_variant_new ("(uass)",
      83             :                                 sal::static_int_cast<guint32>(nXid),
      84             :                                 pBuilder.get(),
      85             :                                 sInteractionAscii.getStr()),
      86             :                          G_DBUS_CALL_FLAGS_NONE,
      87             :                          -1, /* timeout */
      88             :                          NULL, /* cancellable */
      89           0 :                          &error.getRef());
      90           0 :     }
      91             : 
      92           0 :     void SAL_CALL SyncDbusSessionHelper::IsInstalled( const OUString& sPackagename, const OUString& sInteraction, sal_Bool& o_isInstalled ) throw (RuntimeException, std::exception)
      93             :     {
      94           0 :         const OString sPackagenameAscii = OUStringToOString(sPackagename, RTL_TEXTENCODING_ASCII_US);
      95           0 :         const OString sInteractionAscii = OUStringToOString(sInteraction, RTL_TEXTENCODING_ASCII_US);
      96           0 :         boost::shared_ptr<GDBusProxy> proxy(lcl_GetPackageKitProxy("Query"), GObjectDeleter<GDBusProxy>());
      97           0 :         GErrorWrapper error(NULL);
      98             :         boost::shared_ptr<GVariant> result(g_dbus_proxy_call_sync (proxy.get(),
      99             :                          "IsInstalled",
     100             :                          g_variant_new ("(ss)",
     101             :                                 sPackagenameAscii.getStr(),
     102             :                                 sInteractionAscii.getStr()),
     103             :                          G_DBUS_CALL_FLAGS_NONE,
     104             :                          -1, /* timeout */
     105             :                          NULL, /* cancellable */
     106           0 :                          &error.getRef()),GVariantDeleter());
     107           0 :         if(result.get())
     108           0 :             o_isInstalled = g_variant_get_boolean(g_variant_get_child_value(result.get(),0)) ? sal_True : sal_False;
     109           0 :     }
     110             : }}
     111             : 
     112             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10