LibreOffice Module svx (master)  1
MediaPlaybackPanel.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #include "MediaPlaybackPanel.hxx"
20 #include <avmedia/mediaitem.hxx>
21 #include <sfx2/sfxsids.hrc>
22 #include <sfx2/dispatch.hxx>
24 
25 #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 
27 using namespace avmedia;
28 
29 namespace svx::sidebar {
30 
31 MediaPlaybackPanel::MediaPlaybackPanel (
32  weld::Widget* pParent,
33  SfxBindings* pBindings)
34  : PanelLayout(pParent, "MediaPlaybackPanel", "svx/ui/mediaplayback.ui"),
35  maMediaController(SID_AVMEDIA_TOOLBOX, *pBindings, *this),
36  maIdle("MediaPlaybackPanel"),
37  mpBindings(pBindings)
38 {
39  mxTimeEdit = m_xBuilder->weld_entry("timeedit");
40  mxPlayToolBox = m_xBuilder->weld_toolbar("playtoolbox");
41  mxMuteToolBox = m_xBuilder->weld_toolbar("mutetoolbox");
42  mxTimeSlider = m_xBuilder->weld_scale("timeslider");
43  mxVolumeSlider = m_xBuilder->weld_scale("volumeslider");
44  mxZoomListBox = m_xBuilder->weld_combo_box("zoombox");
45 
46  Initialize();
47 }
48 
49 std::unique_ptr<PanelLayout> MediaPlaybackPanel::Create(
50  weld::Widget* pParent,
51  SfxBindings* pBindings)
52 {
53  if (pParent == nullptr)
54  throw lang::IllegalArgumentException("no parent Window given to MediaPlaybackPanel::Create", nullptr, 0);
55  if (pBindings == nullptr)
56  throw lang::IllegalArgumentException("no SfxBindings given to MediaPlaybackPanel::Create", nullptr, 2);
57 
58  return std::make_unique<MediaPlaybackPanel>(pParent, pBindings);
59 }
60 
62 {
63  InitializeWidgets();
64  mxVolumeSlider->connect_value_changed(LINK(this, MediaPlaybackPanel, VolumeSlideHdl));
65  mxPlayToolBox->connect_clicked(LINK(this, MediaPlaybackPanel, PlayToolBoxSelectHdl));
66  mxMuteToolBox->connect_clicked(LINK(this, MediaPlaybackPanel, PlayToolBoxSelectHdl));
67  mxTimeSlider->connect_value_changed(LINK(this, MediaPlaybackPanel, SeekHdl));
68 
69  maIdle.SetPriority( TaskPriority::HIGHEST );
70  maIdle.SetInvokeHandler( LINK( this, MediaPlaybackPanel, TimeoutHdl ) );
71  maIdle.Start();
72  mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX);
73 }
74 
76 {
77  disposeWidgets();
78 }
79 
81  const sal_uInt16 nSID,
82  const SfxItemState eState,
83  const SfxPoolItem* pState)
84 {
85  if( nSID == SID_AVMEDIA_TOOLBOX )
86  {
87  if(eState >= SfxItemState::DEFAULT)
88  {
89  mpMediaItem.reset(pState ? static_cast< MediaItem* >(pState->Clone()) : nullptr);
90  Update();
91  }
92  }
93 }
94 
96 {
97  mxPlayToolBox->set_sensitive(false);
98  avmedia::MediaControlBase::UpdateToolBoxes(rMediaItem);
99 }
100 
102 {
103  if (mpMediaItem)
104  {
106  UpdateTimeSlider( *mpMediaItem );
107  UpdateVolumeSlider( *mpMediaItem );
108  UpdateTimeField( *mpMediaItem, mpMediaItem->getTime() );
109  }
110 }
111 
113 {
114  MediaItem aItem(SID_AVMEDIA_TOOLBOX);
115  aItem.setVolumeDB(mxVolumeSlider->get_value());
116  mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem });
117 }
118 
120 {
121  MediaItem aItem(SID_AVMEDIA_TOOLBOX);
122  double nTime = 0;
123  if (mpMediaItem)
124  nTime = mxTimeSlider->get_value() * mpMediaItem->getDuration() / AVMEDIA_TIME_RANGE;
125  aItem.setTime(nTime);
126  mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem });
127  mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX);
128 }
129 
131 {
132  mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX);
133 }
134 
135 IMPL_LINK( MediaPlaybackPanel, PlayToolBoxSelectHdl, const OString&, rId, void)
136 {
137  MediaItem aItem(SID_AVMEDIA_TOOLBOX);
138 
139  if (rId == "play")
140  {
141  aItem.setState( MediaState::Play );
142 
143  if( !mpMediaItem || (mpMediaItem->getTime() == mpMediaItem->getDuration() ))
144  aItem.setTime( 0.0 );
145  else
146  aItem.setTime( mpMediaItem->getTime());
147  }
148  else if (rId == "pause")
149  {
150  aItem.setState( MediaState::Pause );
151  }
152  else if (rId == "stop")
153  {
154  aItem.setState( MediaState::Stop );
155  aItem.setTime( 0.0 );
156  }
157  else if (rId == "mute")
158  {
159  aItem.setMute( mxMuteToolBox->get_item_active("mute") );
160  }
161  else if (rId == "loop")
162  {
163  aItem.setLoop( mxPlayToolBox->get_item_active("loop") );
164  }
165 
166  if(aItem.getMaskSet() != AVMediaSetMask::NONE)
167  {
168  mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem } );
169  mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX);
170  }
171 }
172 
173 } // end of namespace svx::sidebar
174 
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPL_LINK_NOARG(AreaPropertyPanelBase, ToolbarHdl_Impl, const OString &, void)
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
void setLoop(bool bLoop)
void Invalidate(sal_uInt16 nId)
std::unique_ptr< weld::Builder > m_xBuilder
void setState(MediaState eState)
void setTime(double fTime)
virtual void NotifyItemUpdate(const sal_uInt16 nSID, const SfxItemState eState, const SfxPoolItem *pState) override
#define AVMEDIA_TIME_RANGE
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
IMPL_LINK(MediaPlaybackPanel, PlayToolBoxSelectHdl, const OString &, rId, void)
AVMediaSetMask getMaskSet() const
void setVolumeDB(sal_Int16 nDB)
void setMute(bool bMute)
virtual void UpdateToolBoxes(const avmedia::MediaItem &rMediaItem) override
SfxItemState
void SetInvokeHandler(const Link< Timer *, void > &rLink)
std::unique_ptr< ::avmedia::MediaItem > mpMediaItem
virtual void Start(bool bStartTimer=true) override
void SetPriority(TaskPriority ePriority)
This panel provides media playback control in document.