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 | |
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>
-rw-r--r-- | include/sfx2/thumbnailview.hxx | 9 | ||||
-rw-r--r-- | sd/source/ui/sidebar/MasterPageContainerProviders.cxx | 98 | ||||
-rw-r--r-- | sd/source/ui/toolpanel/controls/MasterPageContainerProviders.cxx | 98 | ||||
-rw-r--r-- | sfx2/source/control/templateabstractview.cxx | 98 | ||||
-rw-r--r-- | sfx2/source/control/thumbnailview.cxx | 103 |
5 files changed, 117 insertions, 289 deletions
diff --git a/include/sfx2/thumbnailview.hxx b/include/sfx2/thumbnailview.hxx index dbbe57dc820a..823e6ada66b0 100644 --- a/include/sfx2/thumbnailview.hxx +++ b/include/sfx2/thumbnailview.hxx @@ -15,9 +15,16 @@ #include <vector> #include <boost/function.hpp> +#include <comphelper/processfactory.hxx> +#include <unotools/ucbstreamhelper.hxx> #include <sfx2/thumbnailviewitem.hxx> #include <vcl/ctrl.hxx> #include <vcl/timer.hxx> +#include <vcl/pngread.hxx> + +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/embed/StorageFactory.hpp> class BitmapEx; class MouseEvent; @@ -242,6 +249,8 @@ public: virtual bool renameItem(ThumbnailViewItem* pItem, OUString sNewTitle); + static BitmapEx readThumbnail(const OUString &msURL); + protected: virtual void KeyInput( const KeyEvent& rKEvt ); 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); } diff --git a/sfx2/source/control/templateabstractview.cxx b/sfx2/source/control/templateabstractview.cxx index ae9a343754d9..cd6e77fd0521 100644 --- a/sfx2/source/control/templateabstractview.cxx +++ b/sfx2/source/control/templateabstractview.cxx @@ -285,103 +285,7 @@ BitmapEx TemplateAbstractView::getDefaultThumbnail( const OUString& rPath ) BitmapEx TemplateAbstractView::fetchThumbnail (const OUString &msURL, long width, long height) { - using namespace ::com::sun::star; - using namespace ::com::sun::star::uno; - - // 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 (); - } - - return TemplateAbstractView::scaleImg(aThumbnail,width,height); + return TemplateAbstractView::scaleImg(ThumbnailView::readThumbnail(msURL), width, height); } IMPL_LINK_NOARG(TemplateAbstractView, ShowRootRegionHdl) diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx index cfefc1f62d51..872299c5b242 100644 --- a/sfx2/source/control/thumbnailview.cxx +++ b/sfx2/source/control/thumbnailview.cxx @@ -1285,6 +1285,109 @@ bool ThumbnailView::renameItem(ThumbnailViewItem*, OUString) return false; } +BitmapEx ThumbnailView::readThumbnail(const OUString &msURL) +{ + using namespace ::com::sun::star; + using namespace ::com::sun::star::uno; + + // 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; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |