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/source/viewer | |
parent | SdrMediaObj: copy/paste support (diff) | |
download | core-431604f9fa603a7acf67985c9e4851f37d9cd580.tar.gz core-431604f9fa603a7acf67985c9e4851f37d9cd580.zip |
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/source/viewer')
-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 |
3 files changed, 13 insertions, 118 deletions
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; |