Files
loongoffice/shell/source/sessioninstall/SyncDbusSessionHelper.cxx
Thomas Arnhold ba0a57702c remove OUString wrap for string literals
For some functions and all kinds of Exceptions.

CannotConvertException
CloseVetoException
DisposedException
EmptyUndoStackException
ErrorCodeIOException
Exception
GridInvalidDataException
GridInvalidModelException
IOException
IllegalAccessException
IllegalArgumentException
IllegalTypeException
IndexOutOfBoundsException
NoMasterException
NoSuchElementException
NoSupportException
PropertyVetoException
RuntimeException
SAXException
ScannerException
StorageWrappedTargetException
UnsupportedFlavorException
VetoException
WrappedTargetException
ZipIOException
throwGenericSQLException
throwIllegallArgumentException

createInstance
createInstanceWithContext
forName
getByName
getPackageManager
getPropertyValue
getUnpackedValueOrDefault
getValueByName
hasPropertyByName
openKey
setName
setPropertyValue
supportsService

bash command:

for i in `cat list`; do git grep "$i\s*(\s*OUString(\s*\"" -- '*.[hc]xx'
	| cut -d ':' -f1 | sort -u
	| xargs sed -i
		-e "s/\(\<$i\s*(\)\s*OUString(\s*\(\"[^\")\\]*\"\)\s*)\s*/\1\2/g"
		-e "s/\($i.*\)\"+ /\1\" + /g";
done

Change-Id: Iaf8e641b0abf28c082906014f87a183517630535
Reviewed-on: https://gerrit.libreoffice.org/4624
Tested-by: LibreOffice gerrit bot <gerrit@libreoffice.org>
Reviewed-by: Thomas Arnhold <thomas@arnhold.org>
Tested-by: Thomas Arnhold <thomas@arnhold.org>
2013-06-29 21:52:54 +00:00

116 lines
5.0 KiB
C++

/* -*- 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 <SyncDbusSessionHelper.hxx>
#include <comphelper/stlunosequence.hxx>
#include <gio/gio.h>
#include <vector>
#include <boost/shared_ptr.hpp>
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 <typename T> 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 = 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<const gchar*>(sFullInterface.getStr()),
NULL,
error.getRef());
if(!proxy)
throw RuntimeException("couldnt get a proxy!",NULL);
return proxy;
}
}
namespace shell { namespace sessioninstall
{
SyncDbusSessionHelper::SyncDbusSessionHelper(Reference<XComponentContext> const&)
{
#if !GLIB_CHECK_VERSION(2,36,0)
g_type_init ();
#endif
}
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<GVariantBuilder> 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(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<GDBusProxy> proxy(lcl_GetPackageKitProxy("Modify"), GObjectDeleter<GDBusProxy>());
GErrorWrapper error(NULL);
g_dbus_proxy_call_sync (proxy.get(),
"InstallPackageNames",
g_variant_new ("(uass)",
sal::static_int_cast<guint32>(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<GDBusProxy> proxy(lcl_GetPackageKitProxy("Query"), GObjectDeleter<GDBusProxy>());
GErrorWrapper error(NULL);
boost::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 */
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: */