From 767af37a0e9f88737690bf3456df28315cc3f477 Mon Sep 17 00:00:00 2001 From: Krisztian Pinter Date: Tue, 9 Jul 2013 02:51:16 +0200 Subject: Remove duplicate code for reading thumbnails Change-Id: I51de8d07a4dc51ba03d24a1a5805df051b6e09b4 Reviewed-on: https://gerrit.libreoffice.org/4779 Reviewed-by: Petr Mladek Tested-by: Petr Mladek --- .../ui/sidebar/MasterPageContainerProviders.cxx | 98 +--------------------- .../controls/MasterPageContainerProviders.cxx | 98 +--------------------- 2 files changed, 4 insertions(+), 192 deletions(-) (limited to 'sd') 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 #include #include +#include #include #include #include @@ -107,102 +108,7 @@ Image TemplatePreviewProvider::operator() ( (void)pPage; (void)rRenderer; - // Load the thumbnail from a template document. - uno::Reference xIStream; - - uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext()); - try - { - uno::Reference xStorageFactory = embed::StorageFactory::create(xContext); - - uno::Sequence aArgs (2); - aArgs[0] <<= msURL; - aArgs[1] <<= embed::ElementModes::READ; - uno::Reference xDocStorage ( - xStorageFactory->createInstanceWithArguments(aArgs), - uno::UNO_QUERY); - - try - { - if (xDocStorage.is()) - { - uno::Reference xStorage ( - xDocStorage->openStorageElement( - "Thumbnails", - embed::ElementModes::READ)); - if (xStorage.is()) - { - uno::Reference 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 xStorage ( - xDocStorage->openStorageElement( "Thumbnail", - embed::ElementModes::READ)); - if (xStorage.is()) - { - uno::Reference 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 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 #include #include +#include #include #include #include @@ -110,102 +111,7 @@ Image TemplatePreviewProvider::operator() ( (void)pPage; (void)rRenderer; - // Load the thumbnail from a template document. - uno::Reference xIStream; - - uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext()); - try - { - uno::Reference xStorageFactory = embed::StorageFactory::create(xContext); - - uno::Sequence aArgs (2); - aArgs[0] <<= msURL; - aArgs[1] <<= embed::ElementModes::READ; - uno::Reference xDocStorage ( - xStorageFactory->createInstanceWithArguments(aArgs), - uno::UNO_QUERY); - - try - { - if (xDocStorage.is()) - { - uno::Reference xStorage ( - xDocStorage->openStorageElement( - "Thumbnails", - embed::ElementModes::READ)); - if (xStorage.is()) - { - uno::Reference 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 xStorage ( - xDocStorage->openStorageElement( "Thumbnail", - embed::ElementModes::READ)); - if (xStorage.is()) - { - uno::Reference 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 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); } -- cgit