summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2018-03-15 20:09:41 +0900
committerTomaž Vajngerl <quikee@gmail.com>2018-03-16 01:54:44 +0100
commite4db2bcaef12877258f691febab1a1260dcf9916 (patch)
treed1afe9f829ce469c298b4892c8edb86a0bd0adfb
parent8f61b382a776b2e241be0e3743c38fea53a6a729 (diff)
more robust method to load a Graphic from URL, +clean up
Change-Id: Ib7fb107a56a3cc9fffb6cfaa9bbc2117434902df Reviewed-on: https://gerrit.libreoffice.org/51329 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--vcl/source/graphic/GraphicLoader.cxx42
1 files changed, 20 insertions, 22 deletions
diff --git a/vcl/source/graphic/GraphicLoader.cxx b/vcl/source/graphic/GraphicLoader.cxx
index 03ca2a6f56a3..b07b345cb982 100644
--- a/vcl/source/graphic/GraphicLoader.cxx
+++ b/vcl/source/graphic/GraphicLoader.cxx
@@ -14,10 +14,7 @@
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/graphic/GraphicProvider.hpp>
#include <com/sun/star/graphic/XGraphicProvider.hpp>
-//#include <com/sun/star/lang/XUnoTunnel.hpp>
-//#include <com/sun/star/lang/XTypeProvider.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
-//#include <cppuhelper/typeprovider.hxx>
using namespace css;
@@ -27,31 +24,32 @@ namespace graphic
{
Graphic loadFromURL(OUString const& rURL)
{
- uno::Reference<css::graphic::XGraphic> xGraphic;
+ Graphic aGraphic;
- uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
- uno::Reference<css::graphic::XGraphicProvider> xProv(
- css::graphic::GraphicProvider::create(xContext));
-
- uno::Sequence<beans::PropertyValue> aLoadProps(1);
- aLoadProps[0].Name = "URL";
- aLoadProps[0].Value <<= rURL;
-
- xGraphic = xProv->queryGraphic(aLoadProps);
-
- std::unique_ptr<Graphic> pGraphic;
- if (xGraphic.is())
+ try
{
- pGraphic.reset(new Graphic(xGraphic));
+ uno::Reference<css::graphic::XGraphic> xGraphic;
+ uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
+ uno::Reference<css::graphic::XGraphicProvider> xProvider;
+ xProvider.set(css::graphic::GraphicProvider::create(xContext));
+
+ uno::Sequence<beans::PropertyValue> aLoadProps(1);
+ aLoadProps[0].Name = "URL";
+ aLoadProps[0].Value <<= rURL;
+
+ xGraphic = xProvider->queryGraphic(aLoadProps);
+
+ if (xGraphic.is())
+ aGraphic = Graphic(xGraphic);
+ else
+ aGraphic.SetDefaultType();
+ aGraphic.setOriginURL(rURL);
}
- else
+ catch (uno::Exception const&)
{
- pGraphic.reset(new Graphic);
- pGraphic->SetDefaultType();
}
- pGraphic->setOriginURL(rURL);
- return *pGraphic.get();
+ return aGraphic;
}
}
} // end vcl::graphic