[Libreoffice-commits] core.git: include/sfx2 sd/source sfx2/source
Krisztian Pinter
pin.terminator at gmail.com
Tue Jul 9 08:50:14 PDT 2013
include/sfx2/thumbnailview.hxx | 9
sd/source/ui/sidebar/MasterPageContainerProviders.cxx | 98 ---------
sd/source/ui/toolpanel/controls/MasterPageContainerProviders.cxx | 98 ---------
sfx2/source/control/templateabstractview.cxx | 98 ---------
sfx2/source/control/thumbnailview.cxx | 103 ++++++++++
5 files changed, 117 insertions(+), 289 deletions(-)
New commits:
commit 767af37a0e9f88737690bf3456df28315cc3f477
Author: Krisztian Pinter <pin.terminator at gmail.com>
Date: Tue Jul 9 02:51:16 2013 +0200
Remove duplicate code for reading thumbnails
Change-Id: I51de8d07a4dc51ba03d24a1a5805df051b6e09b4
Reviewed-on: https://gerrit.libreoffice.org/4779
Reviewed-by: Petr Mladek <pmladek at suse.cz>
Tested-by: Petr Mladek <pmladek at suse.cz>
diff --git a/include/sfx2/thumbnailview.hxx b/include/sfx2/thumbnailview.hxx
index dbbe57d..823e6ad 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 448b8c8..8d52d1f 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 a476219..6eb29ed 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 ae9a343..cd6e77f 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 cfefc1f..872299c 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: */
More information about the Libreoffice-commits
mailing list