diff options
author | Michael Stahl <mstahl@redhat.com> | 2011-12-06 04:36:22 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2011-12-06 04:36:22 +0100 |
commit | 431604f9fa603a7acf67985c9e4851f37d9cd580 (patch) | |
tree | 2dbbe2e40af935229dbc8f2738dc446ab18a93b8 /avmedia | |
parent | f3c19f8263f3352ce4efff0965f8000d8347f6a5 (diff) |
refactor media embedding completely:
Do the tempfile handling in SdrMediaObj, not in the window;
this has the advantage that it works even in the presence of clipboard
documents without SfxBaseModels and thus without storage (sc, sw).
The SdrMediaObj instances share ownership of a temp file.
Diffstat (limited to 'avmedia')
-rw-r--r-- | avmedia/inc/avmedia/mediaitem.hxx | 7 | ||||
-rw-r--r-- | avmedia/source/framework/mediaitem.cxx | 16 | ||||
-rw-r--r-- | avmedia/source/viewer/mediawindow.cxx | 2 | ||||
-rw-r--r-- | avmedia/source/viewer/mediawindowbase_impl.cxx | 114 | ||||
-rw-r--r-- | avmedia/source/viewer/mediawindowbase_impl.hxx | 15 |
5 files changed, 23 insertions, 131 deletions
diff --git a/avmedia/inc/avmedia/mediaitem.hxx b/avmedia/inc/avmedia/mediaitem.hxx index 0e4af5c07507..c4121a123921 100644 --- a/avmedia/inc/avmedia/mediaitem.hxx +++ b/avmedia/inc/avmedia/mediaitem.hxx @@ -115,11 +115,10 @@ public: ::com::sun::star::media::ZoomLevel getZoom() const; void setURL( const ::rtl::OUString& rURL, - ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel> - const& xModel); + ::rtl::OUString const*const pTempURL); const ::rtl::OUString& getURL() const; - ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel> - getModel() const; + + const ::rtl::OUString& getTempURL() const; private: diff --git a/avmedia/source/framework/mediaitem.cxx b/avmedia/source/framework/mediaitem.cxx index f5150f659b79..2ec4ae574457 100644 --- a/avmedia/source/framework/mediaitem.cxx +++ b/avmedia/source/framework/mediaitem.cxx @@ -28,7 +28,6 @@ #include <avmedia/mediaitem.hxx> -#include <cppuhelper/weakref.hxx> #include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/beans/XPropertySet.hpp> @@ -61,8 +60,7 @@ TYPEINIT1_AUTOFACTORY( MediaItem, ::SfxPoolItem ); struct MediaItem::Impl { ::rtl::OUString m_URL; - // store a weak ref to the model so we can get at embedded media - uno::WeakReference<frame::XModel> m_wModel; + ::rtl::OUString m_TempFileURL; sal_uInt32 m_nMaskSet; MediaState m_eState; double m_fTime; @@ -85,7 +83,7 @@ struct MediaItem::Impl } Impl(Impl const& rOther) : m_URL( rOther.m_URL ) - , m_wModel( rOther.m_wModel ) + , m_TempFileURL( rOther.m_TempFileURL ) , m_nMaskSet( rOther.m_nMaskSet ) , m_eState( rOther.m_eState ) , m_fTime( rOther.m_fTime ) @@ -212,7 +210,7 @@ void MediaItem::merge( const MediaItem& rMediaItem ) const sal_uInt32 nMaskSet = rMediaItem.getMaskSet(); if( AVMEDIA_SETMASK_URL & nMaskSet ) - setURL( rMediaItem.getURL(), rMediaItem.getModel() ); + setURL( rMediaItem.getURL(), &rMediaItem.getTempURL() ); if( AVMEDIA_SETMASK_STATE & nMaskSet ) setState( rMediaItem.getState() ); @@ -246,11 +244,11 @@ sal_uInt32 MediaItem::getMaskSet() const //------------------------------------------------------------------------ void MediaItem::setURL( const ::rtl::OUString& rURL, - uno::Reference<frame::XModel> const & xModel) + ::rtl::OUString const*const pTempURL) { m_pImpl->m_URL = rURL; m_pImpl->m_nMaskSet |= AVMEDIA_SETMASK_URL; - m_pImpl->m_wModel = xModel; + m_pImpl->m_TempFileURL = (pTempURL) ? *pTempURL : ::rtl::OUString(); } //------------------------------------------------------------------------ @@ -260,9 +258,9 @@ const ::rtl::OUString& MediaItem::getURL() const return m_pImpl->m_URL; } -uno::Reference<frame::XModel> MediaItem::getModel() const +const ::rtl::OUString& MediaItem::getTempURL() const { - return m_pImpl->m_wModel; + return m_pImpl->m_TempFileURL; } //------------------------------------------------------------------------ diff --git a/avmedia/source/viewer/mediawindow.cxx b/avmedia/source/viewer/mediawindow.cxx index 9a3cab2da97e..713e9e9058e8 100644 --- a/avmedia/source/viewer/mediawindow.cxx +++ b/avmedia/source/viewer/mediawindow.cxx @@ -73,7 +73,7 @@ MediaWindow::~MediaWindow() void MediaWindow::setURL( const ::rtl::OUString& rURL ) { if( mpImpl ) - mpImpl->setURL( rURL, uno::Reference<frame::XModel>() ); + mpImpl->setURL( rURL, ::rtl::OUString() ); } // ------------------------------------------------------------------------- diff --git a/avmedia/source/viewer/mediawindowbase_impl.cxx b/avmedia/source/viewer/mediawindowbase_impl.cxx index d9e8fa60342a..370eb98d14ed 100644 --- a/avmedia/source/viewer/mediawindowbase_impl.cxx +++ b/avmedia/source/viewer/mediawindowbase_impl.cxx @@ -32,16 +32,11 @@ #include "mediawindow.hrc" #include <rtl/oustringostreaminserter.hxx> #include <sal/log.hxx> -#include <osl/file.hxx> #include <tools/urlobj.hxx> -#include <ucbhelper/content.hxx> #include <comphelper/processfactory.hxx> -#include <comphelper/storagehelper.hxx> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XComponent.hdl> #include <com/sun/star/media/XManager.hpp> -#include <com/sun/star/frame/XModel.hpp> -#include <com/sun/star/document/XStorageBasedDocument.hpp> #define MEDIA_TIMER_TIMEOUT 100 @@ -55,8 +50,7 @@ namespace avmedia { namespace priv { MediaWindowBaseImpl::MediaWindowBaseImpl( MediaWindow* pMediaWindow ) - : mpTempFileURL(0) - , mpMediaWindow( pMediaWindow ) + : mpMediaWindow( pMediaWindow ) { } @@ -106,88 +100,8 @@ uno::Reference< media::XPlayer > MediaWindowBaseImpl::createPlayer( const ::rtl: return xPlayer; } -// --------------------------------------------------------------------- -void MediaWindowBaseImpl::cleanupTempFile() -{ - if (mpTempFileURL) - { - ::osl::File::remove(*mpTempFileURL); - delete mpTempFileURL; - mpTempFileURL = 0; - } -} - -bool -MediaWindowBaseImpl::initPackageURL(::rtl::OUString const & rURL, - uno::Reference<frame::XModel> const& xModel) -{ - uno::Reference<document::XStorageBasedDocument> const xSBD( - xModel, uno::UNO_QUERY); - if (!xSBD.is()) - { - SAL_WARN("avmedia", "cannot get model"); - return false; - } - uno::Reference<embed::XStorage> const xStorage( - xSBD->getDocumentStorage()); - if (!xStorage.is()) - { - SAL_WARN("avmedia", "cannot get storage"); - return false; - } - ::comphelper::LifecycleProxy proxy; - uno::Reference<io::XInputStream> xInStream; - try { - uno::Reference<io::XStream> const xStream( - ::comphelper::OStorageHelper::GetStreamAtPackageURL( - xStorage, rURL, embed::ElementModes::READ, proxy)); - xInStream = (xStream.is()) ? xStream->getInputStream() : 0; - } - catch (container::NoSuchElementException const&) - { - SAL_INFO("avmedia", "not found: '" << ::rtl::OUString(rURL) << "'"); - return false; - } - catch (uno::Exception const& e) - { - SAL_WARN("avmedia", "exception: '" << e.Message << "'"); - return false; - } - if (!xInStream.is()) - { - SAL_WARN("avmedia", "no stream?"); - return false; - } - - mpTempFileURL = new ::rtl::OUString; - ::osl::FileBase::RC const err = - ::osl::FileBase::createTempFile(0, 0, mpTempFileURL); - if (::osl::FileBase::E_None != err) - { - SAL_INFO("avmedia", "cannot create temp file"); - delete mpTempFileURL; - mpTempFileURL = 0; - return false; - } - - try - { - ::ucbhelper::Content tempContent(*mpTempFileURL, - uno::Reference<ucb::XCommandEnvironment>()); - tempContent.writeStream(xInStream, true); // copy stream to file - } - catch (uno::Exception const& e) - { - SAL_WARN("avmedia", "exception: '" << e.Message << "'"); - return false; - } - return true; -} - -static char const s_PkgScheme[] = "vnd.sun.star.Package:"; - void MediaWindowBaseImpl::setURL( const ::rtl::OUString& rURL, - uno::Reference<frame::XModel> const& xModel ) + ::rtl::OUString const& rTempURL) { if( rURL != getURL() ) { @@ -201,16 +115,12 @@ void MediaWindowBaseImpl::setURL( const ::rtl::OUString& rURL, } mxPlayer.clear(); - cleanupTempFile(); + mTempFileURL = ::rtl::OUString(); - bool bSuccess(true); - if (0 == rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( - rURL.getStr(), rURL.getLength(), - s_PkgScheme, SAL_N_ELEMENTS(s_PkgScheme) - 1)) + if (rTempURL.getLength()) { - bSuccess = initPackageURL(rURL, xModel); - - maFileURL = (bSuccess) ? rURL : ::rtl::OUString(); + maFileURL = rURL; + mTempFileURL = rTempURL; } else { @@ -222,11 +132,8 @@ void MediaWindowBaseImpl::setURL( const ::rtl::OUString& rURL, maFileURL = rURL; } - if (bSuccess) - { - mxPlayer = createPlayer( - (mpTempFileURL) ? *mpTempFileURL : maFileURL ); - } + mxPlayer = createPlayer( + (mTempFileURL.getLength()) ? mTempFileURL : maFileURL ); onURLChanged(); } } @@ -304,7 +211,6 @@ void MediaWindowBaseImpl::cleanUp() mxPlayer.clear(); } - cleanupTempFile(); mpMediaWindow = NULL; } @@ -481,7 +387,7 @@ void MediaWindowBaseImpl::updateMediaItem( MediaItem& rItem ) const rItem.setMute( isMute() ); rItem.setVolumeDB( getVolumeDB() ); rItem.setZoom( getZoom() ); - rItem.setURL( getURL(), 0 ); + rItem.setURL( getURL(), &mTempFileURL ); } // ------------------------------------------------------------------------- @@ -492,7 +398,7 @@ void MediaWindowBaseImpl::executeMediaItem( const MediaItem& rItem ) // set URL first if( nMaskSet & AVMEDIA_SETMASK_URL ) - setURL( rItem.getURL(), rItem.getModel() ); + setURL( rItem.getURL(), rItem.getTempURL() ); // set different states next if( nMaskSet & AVMEDIA_SETMASK_TIME ) diff --git a/avmedia/source/viewer/mediawindowbase_impl.hxx b/avmedia/source/viewer/mediawindowbase_impl.hxx index 935b88a2aa65..d8244d90ed7d 100644 --- a/avmedia/source/viewer/mediawindowbase_impl.hxx +++ b/avmedia/source/viewer/mediawindowbase_impl.hxx @@ -35,10 +35,6 @@ #include <com/sun/star/media/XPlayerWindow.hpp> -namespace com { namespace sun { namespace star { - namespace frame { class XModel; } -}}} // namespace com::sun::star - namespace avmedia { namespace priv @@ -70,9 +66,7 @@ namespace avmedia static ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > createPlayer( const ::rtl::OUString& rURL); - void setURL( const ::rtl::OUString& rURL, - ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel> const& wModel); + void setURL( const ::rtl::OUString& rURL, ::rtl::OUString const& rTempURL ); const ::rtl::OUString& getURL() const; @@ -128,13 +122,8 @@ namespace avmedia ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayerWindow > getPlayerWindow() const; private: - void cleanupTempFile(); - bool initPackageURL( const ::rtl::OUString& rPath, - ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel> const& wModel); - ::rtl::OUString maFileURL; - ::rtl::OUString * mpTempFileURL; + ::rtl::OUString mTempFileURL; ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > mxPlayer; ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayerWindow > mxPlayerWindow; MediaWindow* mpMediaWindow; |