From 8cd6a947d92a5657e4133693df5392c34bf115ca Mon Sep 17 00:00:00 2001 From: Bjoern Michaelsen Date: Fri, 9 Nov 2012 19:10:38 +0100 Subject: making org.freedesktop.PackageKit.Query and .Modify available - partial implementation of the SessionInstaller interfaces - accessable via service: org.freedesktop.PackageKit.SyncDbusSessionHelper Change-Id: Ica91f481d041a066215fba3e808bf587e1271f1b --- shell/Library_losessioninstall.mk | 41 ++++++++ shell/Module_shell.mk | 1 + .../sessioninstall/SyncDbusSessionHelper.cxx | 113 +++++++++++++++++++++ .../sessioninstall/SyncDbusSessionHelper.hxx | 60 +++++++++++ .../sessioninstall/losessioninstall.component | 15 +++ shell/source/sessioninstall/services.cxx | 31 ++++++ 6 files changed, 261 insertions(+) create mode 100644 shell/Library_losessioninstall.mk create mode 100644 shell/source/sessioninstall/SyncDbusSessionHelper.cxx create mode 100644 shell/source/sessioninstall/SyncDbusSessionHelper.hxx create mode 100644 shell/source/sessioninstall/losessioninstall.component create mode 100644 shell/source/sessioninstall/services.cxx (limited to 'shell') diff --git a/shell/Library_losessioninstall.mk b/shell/Library_losessioninstall.mk new file mode 100644 index 000000000000..eb5f1232e384 --- /dev/null +++ b/shell/Library_losessioninstall.mk @@ -0,0 +1,41 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# 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/. +# + +$(eval $(call gb_Library_Library,losessioninstall)) + +$(eval $(call gb_Library_set_componentfile,losessioninstall,shell/source/sessioninstall/losessioninstall)) + +$(eval $(call gb_Library_use_api,losessioninstall,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_Library_use_libraries,losessioninstall,\ + comphelper \ + cppu \ + cppuhelper \ + sal \ + $(gb_STDLIBS) \ +)) + +ifeq ($(RTL_OS),Linux) +ifeq ($(ENABLE_GIO),TRUE) +$(eval $(call gb_Library_use_externals,losessioninstall,\ + dbus \ + gio \ +)) + +$(eval $(call gb_Library_add_exception_objects,losessioninstall,\ + shell/source/sessioninstall/SyncDbusSessionHelper \ + shell/source/sessioninstall/services \ +)) +endif +endif + +# vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/shell/Module_shell.mk b/shell/Module_shell.mk index f520aea372a7..50687acc4e4c 100644 --- a/shell/Module_shell.mk +++ b/shell/Module_shell.mk @@ -30,6 +30,7 @@ $(eval $(call gb_Module_Module,shell)) $(eval $(call gb_Module_add_targets,shell,\ Library_desktopbe \ Library_localebe \ + Library_losessioninstall \ )) ifeq ($(ENABLE_GCONF),TRUE) diff --git a/shell/source/sessioninstall/SyncDbusSessionHelper.cxx b/shell/source/sessioninstall/SyncDbusSessionHelper.cxx new file mode 100644 index 000000000000..1653cb3f8603 --- /dev/null +++ b/shell/source/sessioninstall/SyncDbusSessionHelper.cxx @@ -0,0 +1,113 @@ +/* -*- 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 + +#include +#include +#include +#include + +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::comphelper; +using namespace ::std;; +using namespace ::rtl;; + +namespace +{ + struct GVariantDeleter { void operator()(GVariant* pV) { g_variant_unref(pV); } }; + struct GVariantBuilderDeleter { void operator()(GVariantBuilder* pVB) { g_variant_builder_unref(pVB); } }; + template struct GObjectDeleter { void operator()(T* pO) { g_object_unref(pO); } }; + class GErrorWrapper + { + GError* m_pError; + public: + GErrorWrapper(GError* pError) : m_pError(pError) {}; + ~GErrorWrapper() + { + if(!m_pError) + return; + OUString sMsg = OUString::createFromAscii(m_pError->message); + g_error_free(m_pError); + throw RuntimeException(sMsg, NULL); + } + GError** getRef() { return &m_pError; } + }; + static inline GDBusProxy* lcl_GetPackageKitProxy(const OUString sInterface) + { + const OString sFullInterface = rtl::OUStringToOString("org.freedesktop.PackageKit." + sInterface, RTL_TEXTENCODING_ASCII_US); + GErrorWrapper error(NULL); + GDBusProxy* proxy = NULL; + proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, NULL, + "org.freedesktop.PackageKit", + "/org/freedesktop/PackageKit", + reinterpret_cast(sFullInterface.getStr()), + NULL, + error.getRef()); + if(!proxy) + throw RuntimeException(OUString("couldnt get a proxy!"),NULL); + return proxy; + }; +} + +namespace shell { namespace sessioninstall +{ + SyncDbusSessionHelper::SyncDbusSessionHelper(Reference const&) + { + g_type_init (); + } + void SAL_CALL SyncDbusSessionHelper::InstallPackageNames( const ::sal_uInt32 nXid, const Sequence< OUString >& vPackages, const OUString& sInteraction ) throw (RuntimeException) + { + vector< OString > vPackagesOString; + vPackagesOString.reserve(vPackages.getLength()); + boost::shared_ptr pBuilder(g_variant_builder_new(G_VARIANT_TYPE ("as")), GVariantBuilderDeleter()); + for( const OUString* pPackage = stl_begin(vPackages); pPackage != stl_end(vPackages); ++pPackage) + { + vPackagesOString.push_back(rtl::OUStringToOString(*pPackage, RTL_TEXTENCODING_ASCII_US)); + g_variant_builder_add(pBuilder.get(), "s", vPackagesOString.back().getStr()); + } + + const OString sInteractionAscii = OUStringToOString(sInteraction, RTL_TEXTENCODING_ASCII_US); + boost::shared_ptr proxy(lcl_GetPackageKitProxy("Modify"), GObjectDeleter()); + GErrorWrapper error(NULL); + g_dbus_proxy_call_sync (proxy.get(), + "InstallPackageNames", + g_variant_new ("(uass)", + sal::static_int_cast(nXid), + pBuilder.get(), + sInteractionAscii.getStr()), + G_DBUS_CALL_FLAGS_NONE, + -1, /* timeout */ + NULL, /* cancellable */ + error.getRef()); + } + + void SAL_CALL SyncDbusSessionHelper::IsInstalled( const OUString& sPackagename, const OUString& sInteraction, ::sal_Bool& o_isInstalled ) throw (RuntimeException) + { + const OString sPackagenameAscii = OUStringToOString(sPackagename, RTL_TEXTENCODING_ASCII_US); + const OString sInteractionAscii = OUStringToOString(sInteraction, RTL_TEXTENCODING_ASCII_US); + boost::shared_ptr proxy(lcl_GetPackageKitProxy("Query"), GObjectDeleter()); + GErrorWrapper error(NULL); + boost::shared_ptr result(g_dbus_proxy_call_sync (proxy.get(), + "IsInstalled", + g_variant_new ("(ss)", + sPackagenameAscii.getStr(), + sInteractionAscii.getStr()), + G_DBUS_CALL_FLAGS_NONE, + -1, /* timeout */ + NULL, /* cancellable */ + error.getRef()),GVariantDeleter()); + if(result.get()) + o_isInstalled = g_variant_get_boolean(g_variant_get_child_value(result.get(),0)) ? sal_True : sal_False; + } +}} + +/* 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 000000000000..bbb1201246fb --- /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 SHELL_SESSIONINSTALL_SYNCDBUSSESSIONHELPER_HXX +#define SHELL_SESSIONINSTALL_SYNCDBUSSESSIONHELPER_HXX + +#include +#include +#include +#include + +namespace shell { namespace sessioninstall +{ + class SyncDbusSessionHelper : public ::cppu::WeakImplHelper1< ::org::freedesktop::PackageKit::XSyncDbusSessionHelper > + { + public: + SyncDbusSessionHelper(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> const&); + virtual ~SyncDbusSessionHelper() {}; + // XModify Methods + virtual void SAL_CALL InstallPackageNames( ::sal_uInt32 xid, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& packages, const ::rtl::OUString& interaction ) throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL InstallPackageFiles( ::sal_uInt32 xid, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& files, const ::rtl::OUString& interaction ) throw (::com::sun::star::uno::RuntimeException) + { throw ::com::sun::star::uno::RuntimeException(); }; // not implemented + virtual void SAL_CALL InstallProvideFiles( ::sal_uInt32 xid, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& files, const ::rtl::OUString& interaction ) throw (::com::sun::star::uno::RuntimeException) + { throw ::com::sun::star::uno::RuntimeException(); }; // not implemented + virtual void SAL_CALL InstallCatalogs( ::sal_uInt32 xid, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& files, const ::rtl::OUString& interaction ) throw (::com::sun::star::uno::RuntimeException) + { throw ::com::sun::star::uno::RuntimeException(); }; // not implemented + virtual void SAL_CALL InstallMimeTypes( ::sal_uInt32 xid, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& mime_types, const ::rtl::OUString& interaction ) throw (::com::sun::star::uno::RuntimeException) + { throw ::com::sun::star::uno::RuntimeException(); }; // not implemented + virtual void SAL_CALL InstallFontconfigRessources( ::sal_uInt32 xid, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& resources, const ::rtl::OUString& interaction ) throw (::com::sun::star::uno::RuntimeException) + { throw ::com::sun::star::uno::RuntimeException(); }; // not implemented + virtual void SAL_CALL InstalliGStreamerRessources( ::sal_uInt32 xid, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& resources, const ::rtl::OUString& interaction ) throw (::com::sun::star::uno::RuntimeException) + { throw ::com::sun::star::uno::RuntimeException(); }; // not implemented + virtual void SAL_CALL InstallRessources( ::sal_uInt32 xid, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& types, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& resources, const ::rtl::OUString& interaction ) throw (::com::sun::star::uno::RuntimeException) + { throw ::com::sun::star::uno::RuntimeException(); }; // not implemented + virtual void SAL_CALL RemovePackageByFiles( ::sal_uInt32 xid, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& files, const ::rtl::OUString& interaction ) throw (::com::sun::star::uno::RuntimeException) + { throw ::com::sun::star::uno::RuntimeException(); }; // not implemented + virtual void SAL_CALL InstallPrinterDrivers( ::sal_uInt32 xid, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& files, const ::rtl::OUString& interaction ) throw (::com::sun::star::uno::RuntimeException) + { throw ::com::sun::star::uno::RuntimeException(); }; // not implemented + // XQuery Methods + virtual void SAL_CALL IsInstalled( const ::rtl::OUString& package_name, const ::rtl::OUString& interaction, ::sal_Bool& installed ) throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL SearchFile( const ::rtl::OUString& file_name, const ::rtl::OUString& interaction, ::sal_Bool& installed, ::rtl::OUString& package_name ) throw (::com::sun::star::uno::RuntimeException) + { throw ::com::sun::star::uno::RuntimeException(); }; // not implemented + + private: + SyncDbusSessionHelper(); // never implemented + SyncDbusSessionHelper( const SyncDbusSessionHelper& ); // never implemented + SyncDbusSessionHelper& operator=( const SyncDbusSessionHelper& ); // never implemented + }; +}} + +#endif // SHELL_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 000000000000..d01c357ef6cb --- /dev/null +++ b/shell/source/sessioninstall/losessioninstall.component @@ -0,0 +1,15 @@ + + + + + + + diff --git a/shell/source/sessioninstall/services.cxx b/shell/source/sessioninstall/services.cxx new file mode 100644 index 000000000000..caf332197a96 --- /dev/null +++ b/shell/source/sessioninstall/services.cxx @@ -0,0 +1,31 @@ +/* -*- 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 +#include +#include + +namespace sdecl = ::comphelper::service_decl; + +sdecl::class_< ::shell::sessioninstall::SyncDbusSessionHelper> SyncDbusSessionHelperServiceImpl; + +const sdecl::ServiceDecl SyncDbusSessionHelperServiceDecl( + SyncDbusSessionHelperServiceImpl, + "org.libreoffice.comp.shell.sessioninstall.SyncDbusSessionHelper", + "org.freedesktop.PackageKit.SyncDbusSessionHelper"); + +COMPHELPER_SERVICEDECL_EXPORTS1(losessioninstall, SyncDbusSessionHelperServiceDecl); +extern "C" +{ + SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( sal_Char const* pImplName, ::com::sun::star::lang::XMultiServiceFactory* pServiceManager, ::com::sun::star::registry::XRegistryKey* pRegistryKey ) + { return losessioninstall_component_getFactory(pImplName, pServiceManager, pRegistryKey); } +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit