bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / sidebar / media / MediaPlaybackPanel.cxx
blob8909ead9669a63a3fb4956a638d6c40e61145df7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include "MediaPlaybackPanel.hxx"
20 #include <avmedia/mediaitem.hxx>
21 #include <sfx2/sfxsids.hrc>
22 #include <sfx2/dispatch.hxx>
23 #include <avmedia/MediaControlBase.hxx>
25 #include <com/sun/star/lang/IllegalArgumentException.hpp>
27 using namespace avmedia;
29 namespace svx::sidebar {
31 MediaPlaybackPanel::MediaPlaybackPanel (
32 weld::Widget* pParent,
33 SfxBindings* pBindings)
34 : PanelLayout(pParent, "MediaPlaybackPanel", "svx/ui/mediaplayback.ui"),
35 MediaControlBase(),
36 maMediaController(SID_AVMEDIA_TOOLBOX, *pBindings, *this),
37 maIdle("MediaPlaybackPanel"),
38 mpBindings(pBindings)
40 mxTimeEdit = m_xBuilder->weld_entry("timeedit");
41 mxPlayToolBox = m_xBuilder->weld_toolbar("playtoolbox");
42 mxMuteToolBox = m_xBuilder->weld_toolbar("mutetoolbox");
43 mxTimeSlider = m_xBuilder->weld_scale("timeslider");
44 mxVolumeSlider = m_xBuilder->weld_scale("volumeslider");
45 mxZoomListBox = m_xBuilder->weld_combo_box("zoombox");
47 Initialize();
50 std::unique_ptr<PanelLayout> MediaPlaybackPanel::Create(
51 weld::Widget* pParent,
52 SfxBindings* pBindings)
54 if (pParent == nullptr)
55 throw lang::IllegalArgumentException("no parent Window given to MediaPlaybackPanel::Create", nullptr, 0);
56 if (pBindings == nullptr)
57 throw lang::IllegalArgumentException("no SfxBindings given to MediaPlaybackPanel::Create", nullptr, 2);
59 return std::make_unique<MediaPlaybackPanel>(pParent, pBindings);
62 void MediaPlaybackPanel::Initialize()
64 InitializeWidgets();
65 mxVolumeSlider->connect_value_changed(LINK(this, MediaPlaybackPanel, VolumeSlideHdl));
66 mxPlayToolBox->connect_clicked(LINK(this, MediaPlaybackPanel, PlayToolBoxSelectHdl));
67 mxMuteToolBox->connect_clicked(LINK(this, MediaPlaybackPanel, PlayToolBoxSelectHdl));
68 mxTimeSlider->connect_value_changed(LINK(this, MediaPlaybackPanel, SeekHdl));
70 maIdle.SetPriority( TaskPriority::HIGHEST );
71 maIdle.SetInvokeHandler( LINK( this, MediaPlaybackPanel, TimeoutHdl ) );
72 maIdle.Start();
73 mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX);
76 MediaPlaybackPanel::~MediaPlaybackPanel()
78 disposeWidgets();
81 void MediaPlaybackPanel::NotifyItemUpdate(
82 const sal_uInt16 nSID,
83 const SfxItemState eState,
84 const SfxPoolItem* pState)
86 if( nSID == SID_AVMEDIA_TOOLBOX )
88 if(eState >= SfxItemState::DEFAULT)
90 mpMediaItem.reset(pState ? static_cast< MediaItem* >(pState->Clone()) : nullptr);
91 Update();
96 void MediaPlaybackPanel::UpdateToolBoxes(const MediaItem& rMediaItem)
98 mxPlayToolBox->set_sensitive(false);
99 avmedia::MediaControlBase::UpdateToolBoxes(rMediaItem);
102 void MediaPlaybackPanel::Update()
104 if (mpMediaItem)
106 UpdateToolBoxes( *mpMediaItem );
107 UpdateTimeSlider( *mpMediaItem );
108 UpdateVolumeSlider( *mpMediaItem );
109 UpdateTimeField( *mpMediaItem, mpMediaItem->getTime() );
113 IMPL_LINK_NOARG( MediaPlaybackPanel, VolumeSlideHdl, weld::Scale&, void)
115 MediaItem aItem(SID_AVMEDIA_TOOLBOX);
116 aItem.setVolumeDB(mxVolumeSlider->get_value());
117 mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem });
120 IMPL_LINK_NOARG( MediaPlaybackPanel, SeekHdl, weld::Scale&, void)
122 MediaItem aItem(SID_AVMEDIA_TOOLBOX);
123 double nTime = 0;
124 if (mpMediaItem)
125 nTime = mxTimeSlider->get_value() * mpMediaItem->getDuration() / AVMEDIA_TIME_RANGE;
126 aItem.setTime(nTime);
127 mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem });
128 mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX);
131 IMPL_LINK_NOARG( MediaPlaybackPanel, TimeoutHdl, Timer*, void)
133 mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX);
136 IMPL_LINK( MediaPlaybackPanel, PlayToolBoxSelectHdl, const OString&, rId, void)
138 MediaItem aItem(SID_AVMEDIA_TOOLBOX);
140 if (rId == "play")
142 aItem.setState( MediaState::Play );
144 if( !mpMediaItem || (mpMediaItem->getTime() == mpMediaItem->getDuration() ))
145 aItem.setTime( 0.0 );
146 else
147 aItem.setTime( mpMediaItem->getTime());
149 else if (rId == "pause")
151 aItem.setState( MediaState::Pause );
153 else if (rId == "stop")
155 aItem.setState( MediaState::Stop );
156 aItem.setTime( 0.0 );
158 else if (rId == "mute")
160 aItem.setMute( mxMuteToolBox->get_item_active("mute") );
162 else if (rId == "loop")
164 aItem.setLoop( mxPlayToolBox->get_item_active("loop") );
167 if(aItem.getMaskSet() != AVMediaSetMask::NONE)
169 mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem } );
170 mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX);
174 } // end of namespace svx::sidebar
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */