summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorKrisztian Pinter <pin.terminator@gmail.com>2013-07-09 02:51:16 +0200
committerPetr Mladek <pmladek@suse.cz>2013-07-09 15:49:53 +0000
commit767af37a0e9f88737690bf3456df28315cc3f477 (patch)
tree0899236319abe23408ac7f55e2f09ddc1290bd5c /sfx2
parent3a5cc4e322f1a1d5365a7455750b59e004c1b789 (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 'sfx2')
-rw-r--r--sfx2/source/control/templateabstractview.cxx98
-rw-r--r--sfx2/source/control/thumbnailview.cxx103
2 files changed, 104 insertions, 97 deletions
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: */