diff options
author | Krisztian Pinter <pin.terminator@gmail.com> | 2013-07-09 02:51:16 +0200 |
---|---|---|
committer | Petr Mladek <pmladek@suse.cz> | 2013-07-09 15:49:53 +0000 |
commit | 767af37a0e9f88737690bf3456df28315cc3f477 (patch) | |
tree | 0899236319abe23408ac7f55e2f09ddc1290bd5c /sd | |
parent | 3a5cc4e322f1a1d5365a7455750b59e004c1b789 (diff) |
Remove duplicate code for reading thumbnails
Change-Id: I51de8d07a4dc51ba03d24a1a5805df051b6e09b4
Reviewed-on: https://gerrit.libreoffice.org/4779
Reviewed-by: Petr Mladek <pmladek@suse.cz>
Tested-by: Petr Mladek <pmladek@suse.cz>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/source/ui/sidebar/MasterPageContainerProviders.cxx | 98 | ||||
-rw-r--r-- | sd/source/ui/toolpanel/controls/MasterPageContainerProviders.cxx | 98 |
2 files changed, 4 insertions, 192 deletions
diff --git a/sd/source/ui/sidebar/MasterPageContainerProviders.cxx b/sd/source/ui/sidebar/MasterPageContainerProviders.cxx index 448b8c8d60c7..8d52d1fe2b73 100644 --- a/sd/source/ui/sidebar/MasterPageContainerProviders.cxx +++ b/sd/source/ui/sidebar/MasterPageContainerProviders.cxx @@ -25,6 +25,7 @@ #include <comphelper/processfactory.hxx> #include <sfx2/app.hxx> #include <sfx2/sfxsids.hrc> +#include <sfx2/thumbnailview.hxx> #include <unotools/ucbstreamhelper.hxx> #include <vcl/image.hxx> #include <vcl/pngread.hxx> @@ -107,102 +108,7 @@ Image TemplatePreviewProvider::operator() ( (void)pPage; (void)rRenderer; - // Load the thumbnail from a template document. - uno::Reference<io::XInputStream> xIStream; - - uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext()); - try - { - uno::Reference<lang::XSingleServiceFactory> xStorageFactory = embed::StorageFactory::create(xContext); - - uno::Sequence<uno::Any> aArgs (2); - aArgs[0] <<= msURL; - aArgs[1] <<= embed::ElementModes::READ; - uno::Reference<embed::XStorage> xDocStorage ( - xStorageFactory->createInstanceWithArguments(aArgs), - uno::UNO_QUERY); - - try - { - if (xDocStorage.is()) - { - uno::Reference<embed::XStorage> xStorage ( - xDocStorage->openStorageElement( - "Thumbnails", - embed::ElementModes::READ)); - if (xStorage.is()) - { - uno::Reference<io::XStream> xThumbnailCopy ( - xStorage->cloneStreamElement("thumbnail.png")); - if (xThumbnailCopy.is()) - xIStream = xThumbnailCopy->getInputStream(); - } - } - } - catch (const uno::Exception& rException) - { - OSL_TRACE ( - "caught exception while trying to access Thumbnail/thumbnail.png of %s: %s", - OUStringToOString(msURL, - RTL_TEXTENCODING_UTF8).getStr(), - OUStringToOString(rException.Message, - RTL_TEXTENCODING_UTF8).getStr()); - } - - try - { - // An (older) implementation had a bug - The storage - // name was "Thumbnail" instead of "Thumbnails". The - // old name is still used as fallback but this code can - // be removed soon. - if ( ! xIStream.is()) - { - uno::Reference<embed::XStorage> xStorage ( - xDocStorage->openStorageElement( "Thumbnail", - embed::ElementModes::READ)); - if (xStorage.is()) - { - uno::Reference<io::XStream> xThumbnailCopy ( - xStorage->cloneStreamElement("thumbnail.png")); - if (xThumbnailCopy.is()) - xIStream = xThumbnailCopy->getInputStream(); - } - } - } - catch (const uno::Exception& rException) - { - OSL_TRACE ( - "caught exception while trying to access Thumbnails/thumbnail.png of %s: %s", - OUStringToOString(msURL, - RTL_TEXTENCODING_UTF8).getStr(), - OUStringToOString(rException.Message, - RTL_TEXTENCODING_UTF8).getStr()); - } - } - catch (const uno::Exception& rException) - { - OSL_TRACE ( - "caught exception while trying to access tuhmbnail of %s: %s", - OUStringToOString(msURL, - RTL_TEXTENCODING_UTF8).getStr(), - OUStringToOString(rException.Message, - RTL_TEXTENCODING_UTF8).getStr()); - } - - // Extract the image from the stream. - BitmapEx aThumbnail; - if (xIStream.is()) - { - ::std::auto_ptr<SvStream> pStream ( - ::utl::UcbStreamHelper::CreateStream (xIStream)); - ::vcl::PNGReader aReader (*pStream); - aThumbnail = aReader.Read (); - } - - // Note that the preview is returned without scaling it to the desired - // width. This gives the caller the chance to take advantage of a - // possibly larger resolution then was asked for. - return aThumbnail; + return ThumbnailView::readThumbnail(msURL); } diff --git a/sd/source/ui/toolpanel/controls/MasterPageContainerProviders.cxx b/sd/source/ui/toolpanel/controls/MasterPageContainerProviders.cxx index a476219297a3..6eb29ed27714 100644 --- a/sd/source/ui/toolpanel/controls/MasterPageContainerProviders.cxx +++ b/sd/source/ui/toolpanel/controls/MasterPageContainerProviders.cxx @@ -26,6 +26,7 @@ #include <comphelper/processfactory.hxx> #include <sfx2/app.hxx> #include <sfx2/sfxsids.hrc> +#include <sfx2/thumbnailview.hxx> #include <unotools/ucbstreamhelper.hxx> #include <vcl/image.hxx> #include <vcl/pngread.hxx> @@ -110,102 +111,7 @@ Image TemplatePreviewProvider::operator() ( (void)pPage; (void)rRenderer; - // Load the thumbnail from a template document. - uno::Reference<io::XInputStream> xIStream; - - uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext()); - try - { - uno::Reference<lang::XSingleServiceFactory> xStorageFactory = embed::StorageFactory::create(xContext); - - uno::Sequence<uno::Any> aArgs (2); - aArgs[0] <<= msURL; - aArgs[1] <<= embed::ElementModes::READ; - uno::Reference<embed::XStorage> xDocStorage ( - xStorageFactory->createInstanceWithArguments(aArgs), - uno::UNO_QUERY); - - try - { - if (xDocStorage.is()) - { - uno::Reference<embed::XStorage> xStorage ( - xDocStorage->openStorageElement( - "Thumbnails", - embed::ElementModes::READ)); - if (xStorage.is()) - { - uno::Reference<io::XStream> xThumbnailCopy ( - xStorage->cloneStreamElement("thumbnail.png")); - if (xThumbnailCopy.is()) - xIStream = xThumbnailCopy->getInputStream(); - } - } - } - catch (const uno::Exception& rException) - { - OSL_TRACE ( - "caught exception while trying to access Thumbnail/thumbnail.png of %s: %s", - OUStringToOString(msURL, - RTL_TEXTENCODING_UTF8).getStr(), - OUStringToOString(rException.Message, - RTL_TEXTENCODING_UTF8).getStr()); - } - - try - { - // An (older) implementation had a bug - The storage - // name was "Thumbnail" instead of "Thumbnails". The - // old name is still used as fallback but this code can - // be removed soon. - if ( ! xIStream.is()) - { - uno::Reference<embed::XStorage> xStorage ( - xDocStorage->openStorageElement( "Thumbnail", - embed::ElementModes::READ)); - if (xStorage.is()) - { - uno::Reference<io::XStream> xThumbnailCopy ( - xStorage->cloneStreamElement("thumbnail.png")); - if (xThumbnailCopy.is()) - xIStream = xThumbnailCopy->getInputStream(); - } - } - } - catch (const uno::Exception& rException) - { - OSL_TRACE ( - "caught exception while trying to access Thumbnails/thumbnail.png of %s: %s", - OUStringToOString(msURL, - RTL_TEXTENCODING_UTF8).getStr(), - OUStringToOString(rException.Message, - RTL_TEXTENCODING_UTF8).getStr()); - } - } - catch (const uno::Exception& rException) - { - OSL_TRACE ( - "caught exception while trying to access tuhmbnail of %s: %s", - OUStringToOString(msURL, - RTL_TEXTENCODING_UTF8).getStr(), - OUStringToOString(rException.Message, - RTL_TEXTENCODING_UTF8).getStr()); - } - - // Extract the image from the stream. - BitmapEx aThumbnail; - if (xIStream.is()) - { - ::std::auto_ptr<SvStream> pStream ( - ::utl::UcbStreamHelper::CreateStream (xIStream)); - ::vcl::PNGReader aReader (*pStream); - aThumbnail = aReader.Read (); - } - - // Note that the preview is returned without scaling it to the desired - // width. This gives the caller the chance to take advantage of a - // possibly larger resolution then was asked for. - return aThumbnail; + return ThumbnailView::readThumbnail(msURL); } |