Files
libreoffice/avmedia/source/viewer/mediawindow.cxx

462 lines
12 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2004-08-23 08:04:42 +00:00
#include <stdio.h>
#include <avmedia/mediawindow.hxx>
#include <boost/scoped_ptr.hpp>
2004-08-23 08:04:42 +00:00
#include "mediawindow_impl.hxx"
#include "mediamisc.hxx"
#include "mediawindow.hrc"
#include <tools/urlobj.hxx>
#include <vcl/layout.hxx>
#include <unotools/pathoptions.hxx>
2004-08-23 08:04:42 +00:00
#include <sfx2/filedlghelper.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/media/XManager.hpp>
#include "com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp"
#include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
#include "com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp"
2004-08-23 08:04:42 +00:00
#define AVMEDIA_FRAMEGRABBER_DEFAULTFRAME_MEDIATIME 3.0
2004-08-23 08:04:42 +00:00
using namespace ::com::sun::star;
namespace avmedia {
2004-08-23 08:04:42 +00:00
// - MediaWindow -
2004-08-23 08:04:42 +00:00
MediaWindow::MediaWindow( Window* parent, bool bInternalMediaControl ) :
mpImpl( new priv::MediaWindowImpl( parent, this, bInternalMediaControl ) )
{
mpImpl->Show();
}
2004-08-23 08:04:42 +00:00
MediaWindow::~MediaWindow() {}
2004-08-23 08:04:42 +00:00
2004-08-23 08:04:42 +00:00
void MediaWindow::setURL( const OUString& rURL, const OUString& rReferer )
2004-08-23 08:04:42 +00:00
{
mpImpl->setURL( rURL, OUString(), rReferer );
2004-08-23 08:04:42 +00:00
}
2004-08-23 08:04:42 +00:00
const OUString& MediaWindow::getURL() const
2004-08-23 08:04:42 +00:00
{
return mpImpl->getURL();
}
2004-08-23 08:04:42 +00:00
bool MediaWindow::isValid() const
{
return mpImpl->isValid();
2004-08-23 08:04:42 +00:00
}
2004-08-23 08:04:42 +00:00
void MediaWindow::MouseMove( const MouseEvent& /* rMEvt */ )
2004-08-23 08:04:42 +00:00
{
}
2004-08-23 08:04:42 +00:00
void MediaWindow::MouseButtonDown( const MouseEvent& /* rMEvt */ )
2004-08-23 08:04:42 +00:00
{
}
2004-08-23 08:04:42 +00:00
void MediaWindow::MouseButtonUp( const MouseEvent& /* rMEvt */ )
2004-08-23 08:04:42 +00:00
{
}
2004-08-23 08:04:42 +00:00
void MediaWindow::KeyInput( const KeyEvent& /* rKEvt */ )
2004-08-23 08:04:42 +00:00
{
}
2004-08-23 08:04:42 +00:00
void MediaWindow::KeyUp( const KeyEvent& /* rKEvt */ )
2004-08-23 08:04:42 +00:00
{
}
2004-08-23 08:04:42 +00:00
void MediaWindow::Command( const CommandEvent& /* rCEvt */ )
2004-08-23 08:04:42 +00:00
{
}
2004-08-23 08:04:42 +00:00
sal_Int8 MediaWindow::AcceptDrop( const AcceptDropEvent& /* rEvt */ )
2004-08-23 08:04:42 +00:00
{
return 0;
}
2004-08-23 08:04:42 +00:00
sal_Int8 MediaWindow::ExecuteDrop( const ExecuteDropEvent& /* rEvt */ )
2004-08-23 08:04:42 +00:00
{
return 0;
}
2004-08-23 08:04:42 +00:00
void MediaWindow::StartDrag( sal_Int8 /* nAction */, const Point& /* rPosPixel */ )
2004-08-23 08:04:42 +00:00
{
}
2004-08-23 08:04:42 +00:00
Size MediaWindow::getPreferredSize() const
{
return mpImpl->getPreferredSize();
}
2004-08-23 08:04:42 +00:00
void MediaWindow::setPosSize( const Rectangle& rNewRect )
{
mpImpl->setPosSize( rNewRect );
2004-08-23 08:04:42 +00:00
}
2004-08-23 08:04:42 +00:00
void MediaWindow::setPointer( const Pointer& rPointer )
{
mpImpl->setPointer( rPointer );
2004-08-23 08:04:42 +00:00
}
2004-08-23 08:04:42 +00:00
bool MediaWindow::start()
{
return mpImpl->start();
2004-08-23 08:04:42 +00:00
}
2004-08-23 08:04:42 +00:00
void MediaWindow::updateMediaItem( MediaItem& rItem ) const
{
mpImpl->updateMediaItem( rItem );
2004-08-23 08:04:42 +00:00
}
2004-08-23 08:04:42 +00:00
void MediaWindow::executeMediaItem( const MediaItem& rItem )
{
mpImpl->executeMediaItem( rItem );
2004-08-23 08:04:42 +00:00
}
2004-08-23 08:04:42 +00:00
void MediaWindow::show()
{
mpImpl->Show();
2004-08-23 08:04:42 +00:00
}
2004-08-23 08:04:42 +00:00
void MediaWindow::hide()
{
mpImpl->Hide();
2004-08-23 08:04:42 +00:00
}
2004-08-23 08:04:42 +00:00
Window* MediaWindow::getWindow() const
{
return mpImpl.get();
2004-08-23 08:04:42 +00:00
}
2004-08-23 08:04:42 +00:00
void MediaWindow::getMediaFilters( FilterNameVector& rFilterNameVector )
{
static const char* pFilters[] = { "Advanced Audio Coding", "aac",
"AIF Audio", "aif;aiff",
"Advanced Systems Format", "asf;wma;wmv",
2011-04-01 09:38:38 +01:00
"AU Audio", "au",
"AC3 Audio", "ac3",
2011-04-01 09:38:38 +01:00
"AVI", "avi",
"CD Audio", "cda",
"Digital Video", "dv",
2011-04-01 09:38:38 +01:00
"FLAC Audio", "flac",
"Flash Video", "flv",
2011-04-01 09:38:38 +01:00
"Matroska Media", "mkv",
"MIDI Audio", "mid;midi",
"MPEG Audio", "mp2;mp3;mpa;m4a",
"MPEG Video", "mpg;mpeg;mpv;mp4;m4v",
"Ogg Audio", "ogg;oga;opus",
"Ogg Video", "ogv;ogx",
"Real Audio", "ra",
"Real Media", "rm",
"RMI MIDI Audio", "rmi",
"SND (SouND) Audio", "snd",
2011-04-01 09:38:38 +01:00
"Quicktime Video", "mov",
"Vivo Video", "viv",
"WAVE Audio", "wav",
"WebM Video", "webm",
"Windows Media Audio", "wma",
"Windows Media Video", "wmv"};
2011-04-01 09:38:38 +01:00
2011-04-01 10:06:58 +01:00
for( size_t i = 0; i < SAL_N_ELEMENTS(pFilters); i += 2 )
2004-08-23 08:04:42 +00:00
{
rFilterNameVector.push_back( ::std::make_pair< OUString, OUString >(
OUString::createFromAscii(pFilters[i]),
OUString::createFromAscii(pFilters[i+1]) ) );
2004-08-23 08:04:42 +00:00
}
}
2004-08-23 08:04:42 +00:00
bool MediaWindow::executeMediaURLDialog(Window* /* pParent */,
OUString& rURL, bool *const o_pbLink)
2004-08-23 08:04:42 +00:00
{
::sfx2::FileDialogHelper aDlg( (o_pbLink)
? ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW
: ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
static const OUString aWildcard( "*." );
2004-08-23 08:04:42 +00:00
FilterNameVector aFilters;
const OUString aSeparator( ";" );
OUString aAllTypes;
2004-08-23 08:04:42 +00:00
aDlg.SetTitle( AVMEDIA_RESSTR( (o_pbLink)
? AVMEDIA_STR_INSERTMEDIA_DLG : AVMEDIA_STR_OPENMEDIA_DLG ) );
2004-08-23 08:04:42 +00:00
getMediaFilters( aFilters );
unsigned int i;
for( i = 0; i < aFilters.size(); ++i )
2004-08-23 08:04:42 +00:00
{
for( sal_Int32 nIndex = 0; nIndex >= 0; )
{
if( !aAllTypes.isEmpty() )
2004-08-23 08:04:42 +00:00
aAllTypes += aSeparator;
( aAllTypes += aWildcard ) += aFilters[ i ].second.getToken( 0, ';', nIndex );
}
}
// add filter for all media types
aDlg.AddFilter( AVMEDIA_RESSTR( AVMEDIA_STR_ALL_MEDIAFILES ), aAllTypes );
2004-08-23 08:04:42 +00:00
for( i = 0; i < aFilters.size(); ++i )
2004-08-23 08:04:42 +00:00
{
OUString aTypes;
2004-08-23 08:04:42 +00:00
for( sal_Int32 nIndex = 0; nIndex >= 0; )
{
if( !aTypes.isEmpty() )
2004-08-23 08:04:42 +00:00
aTypes += aSeparator;
( aTypes += aWildcard ) += aFilters[ i ].second.getToken( 0, ';', nIndex );
}
// add single filters
aDlg.AddFilter( aFilters[ i ].first, aTypes );
}
// add filter for all types
aDlg.AddFilter( AVMEDIA_RESSTR( AVMEDIA_STR_ALL_FILES ), OUString( "*.*" ) );
2004-08-23 08:04:42 +00:00
uno::Reference<ui::dialogs::XFilePicker> const xFP(aDlg.GetFilePicker());
uno::Reference<ui::dialogs::XFilePickerControlAccess> const xCtrlAcc(xFP,
uno::UNO_QUERY_THROW);
if (o_pbLink)
{
// for video link should be the default
xCtrlAcc->setValue(
ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK, 0,
uno::makeAny(sal_True) );
// disabled for now: TODO: preview?
xCtrlAcc->enableControl(
ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PREVIEW,
sal_False);
}
2004-08-23 08:04:42 +00:00
if( aDlg.Execute() == ERRCODE_NONE )
{
const INetURLObject aURL( aDlg.GetPath() );
rURL = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
if (o_pbLink)
{
uno::Any const any = xCtrlAcc->getValue(
ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK, 0);
if (!(any >>= *o_pbLink))
{
SAL_WARN("avmedia", "invalid link property");
*o_pbLink = true;
}
}
2004-08-23 08:04:42 +00:00
}
else if( !rURL.isEmpty() )
rURL = OUString();
2004-08-23 08:04:42 +00:00
return !rURL.isEmpty();
2004-08-23 08:04:42 +00:00
}
2004-08-23 08:04:42 +00:00
void MediaWindow::executeFormatErrorBox( Window* pParent )
{
MessageDialog aErrBox( pParent, AVMEDIA_RESID( AVMEDIA_STR_ERR_URL ) );
2004-08-23 08:04:42 +00:00
aErrBox.Execute();
}
2004-08-23 08:04:42 +00:00
bool MediaWindow::isMediaURL( const OUString& rURL, const OUString& rReferer, bool bDeep, Size* pPreferredSizePixel )
2004-08-23 08:04:42 +00:00
{
const INetURLObject aURL( rURL );
bool bRet = false;
if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
{
if( bDeep || pPreferredSizePixel )
{
try
2004-08-23 08:04:42 +00:00
{
uno::Reference< media::XPlayer > xPlayer( priv::MediaWindowImpl::createPlayer(
aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ),
rReferer ) );
if( xPlayer.is() )
{
bRet = true;
2004-08-23 08:04:42 +00:00
if( pPreferredSizePixel )
2004-08-23 08:04:42 +00:00
{
const awt::Size aAwtSize( xPlayer->getPreferredPlayerWindowSize() );
2004-08-23 08:04:42 +00:00
pPreferredSizePixel->Width() = aAwtSize.Width;
pPreferredSizePixel->Height() = aAwtSize.Height;
2004-08-23 08:04:42 +00:00
}
}
}
catch( ... )
{
2004-08-23 08:04:42 +00:00
}
}
else
{
FilterNameVector aFilters;
const OUString aExt( aURL.getExtension() );
2004-08-23 08:04:42 +00:00
getMediaFilters( aFilters );
unsigned int i;
for( i = 0; ( i < aFilters.size() ) && !bRet; ++i )
2004-08-23 08:04:42 +00:00
{
for( sal_Int32 nIndex = 0; nIndex >= 0 && !bRet; )
{
if( aExt.equalsIgnoreAsciiCase( aFilters[ i ].second.getToken( 0, ';', nIndex ) ) )
bRet = true;
}
}
}
}
return bRet;
}
2004-08-23 08:04:42 +00:00
uno::Reference< media::XPlayer > MediaWindow::createPlayer( const OUString& rURL, const OUString& rReferer, const OUString* pMimeType )
2004-08-23 08:04:42 +00:00
{
return priv::MediaWindowImpl::createPlayer( rURL, rReferer, pMimeType );
2004-08-23 08:04:42 +00:00
}
uno::Reference< graphic::XGraphic > MediaWindow::grabFrame( const OUString& rURL,
const OUString& rReferer,
const OUString& sMimeType,
double fMediaTime )
{
uno::Reference< media::XPlayer > xPlayer( createPlayer( rURL, rReferer, &sMimeType ) );
uno::Reference< graphic::XGraphic > xRet;
boost::scoped_ptr< Graphic > apGraphic;
if( xPlayer.is() )
{
uno::Reference< media::XFrameGrabber > xGrabber( xPlayer->createFrameGrabber() );
if( xGrabber.is() )
{
if( AVMEDIA_FRAMEGRABBER_DEFAULTFRAME == fMediaTime )
fMediaTime = AVMEDIA_FRAMEGRABBER_DEFAULTFRAME_MEDIATIME;
if( fMediaTime >= xPlayer->getDuration() )
fMediaTime = ( xPlayer->getDuration() * 0.5 );
xRet = xGrabber->grabFrame( fMediaTime );
}
if( !xRet.is() )
{
awt::Size aPrefSize( xPlayer->getPreferredPlayerWindowSize() );
if( !aPrefSize.Width && !aPrefSize.Height )
{
const BitmapEx aBmpEx( getAudioLogo() );
apGraphic.reset( new Graphic( aBmpEx ) );
}
}
}
if( !xRet.is() && !apGraphic.get() )
{
const BitmapEx aBmpEx( getEmptyLogo() );
apGraphic.reset( new Graphic( aBmpEx ) );
}
if( apGraphic.get() )
xRet = apGraphic->GetXGraphic();
return xRet;
}
BitmapEx MediaWindow::getAudioLogo()
{
return BitmapEx(AVMEDIA_RESID(AVMEDIA_BMP_AUDIOLOGO));
}
BitmapEx MediaWindow::getEmptyLogo()
{
return BitmapEx(AVMEDIA_RESID(AVMEDIA_BMP_EMPTYLOGO));
}
2004-08-23 08:04:42 +00:00
} // namespace avemdia
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */