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

Generated by: LCOV version 1.10