/src/libreoffice/svx/source/sidebar/media/MediaPlaybackPanel.cxx
Line | Count | Source |
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> |
23 | | #include <avmedia/MediaControlBase.hxx> |
24 | | #include <svl/itemset.hxx> |
25 | | #include <vcl/weld/Builder.hxx> |
26 | | |
27 | | #include <com/sun/star/lang/IllegalArgumentException.hpp> |
28 | | |
29 | | using namespace avmedia; |
30 | | |
31 | | namespace svx::sidebar { |
32 | | |
33 | | MediaPlaybackPanel::MediaPlaybackPanel ( |
34 | | weld::Widget* pParent, |
35 | | SfxBindings* pBindings) |
36 | 0 | : PanelLayout(pParent, u"MediaPlaybackPanel"_ustr, u"svx/ui/mediaplayback.ui"_ustr), |
37 | 0 | maMediaController(SID_AVMEDIA_TOOLBOX, *pBindings, *this), |
38 | 0 | maIdle("MediaPlaybackPanel"), |
39 | 0 | mpBindings(pBindings) |
40 | 0 | { |
41 | 0 | mxTimeEdit = m_xBuilder->weld_entry(u"timeedit"_ustr); |
42 | 0 | mxPlayToolBox = m_xBuilder->weld_toolbar(u"playtoolbox"_ustr); |
43 | 0 | mxMuteToolBox = m_xBuilder->weld_toolbar(u"mutetoolbox"_ustr); |
44 | 0 | mxTimeSlider = m_xBuilder->weld_scale(u"timeslider"_ustr); |
45 | 0 | mxVolumeSlider = m_xBuilder->weld_scale(u"volumeslider"_ustr); |
46 | 0 | mxZoomListBox = m_xBuilder->weld_combo_box(u"zoombox"_ustr); |
47 | |
|
48 | 0 | Initialize(); |
49 | 0 | } |
50 | | |
51 | | std::unique_ptr<PanelLayout> MediaPlaybackPanel::Create( |
52 | | weld::Widget* pParent, |
53 | | SfxBindings* pBindings) |
54 | 0 | { |
55 | 0 | if (pParent == nullptr) |
56 | 0 | throw lang::IllegalArgumentException(u"no parent Window given to MediaPlaybackPanel::Create"_ustr, nullptr, 0); |
57 | 0 | if (pBindings == nullptr) |
58 | 0 | throw lang::IllegalArgumentException(u"no SfxBindings given to MediaPlaybackPanel::Create"_ustr, nullptr, 2); |
59 | | |
60 | 0 | return std::make_unique<MediaPlaybackPanel>(pParent, pBindings); |
61 | 0 | } |
62 | | |
63 | | void MediaPlaybackPanel::Initialize() |
64 | 0 | { |
65 | 0 | InitializeWidgets(); |
66 | 0 | mxVolumeSlider->connect_value_changed(LINK(this, MediaPlaybackPanel, VolumeSlideHdl)); |
67 | 0 | mxPlayToolBox->connect_clicked(LINK(this, MediaPlaybackPanel, PlayToolBoxSelectHdl)); |
68 | 0 | mxMuteToolBox->connect_clicked(LINK(this, MediaPlaybackPanel, PlayToolBoxSelectHdl)); |
69 | 0 | mxTimeSlider->connect_value_changed(LINK(this, MediaPlaybackPanel, SeekHdl)); |
70 | |
|
71 | 0 | maIdle.SetPriority( TaskPriority::HIGHEST ); |
72 | 0 | maIdle.SetInvokeHandler( LINK( this, MediaPlaybackPanel, TimeoutHdl ) ); |
73 | 0 | maIdle.Start(); |
74 | 0 | mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX); |
75 | 0 | } |
76 | | |
77 | | MediaPlaybackPanel::~MediaPlaybackPanel() |
78 | 0 | { |
79 | 0 | disposeWidgets(); |
80 | 0 | } |
81 | | |
82 | | void MediaPlaybackPanel::NotifyItemUpdate( |
83 | | const sal_uInt16 nSID, |
84 | | const SfxItemState eState, |
85 | | const SfxPoolItem* pState) |
86 | 0 | { |
87 | 0 | if( nSID == SID_AVMEDIA_TOOLBOX ) |
88 | 0 | { |
89 | 0 | if(eState >= SfxItemState::DEFAULT) |
90 | 0 | { |
91 | 0 | mpMediaItem.reset(pState ? static_cast< MediaItem* >(pState->Clone()) : nullptr); |
92 | 0 | Update(); |
93 | 0 | } |
94 | 0 | } |
95 | 0 | } |
96 | | |
97 | | void MediaPlaybackPanel::UpdateToolBoxes(const MediaItem& rMediaItem) |
98 | 0 | { |
99 | 0 | mxPlayToolBox->set_sensitive(false); |
100 | 0 | avmedia::MediaControlBase::UpdateToolBoxes(rMediaItem); |
101 | 0 | } |
102 | | |
103 | | void MediaPlaybackPanel::Update() |
104 | 0 | { |
105 | 0 | if (mpMediaItem) |
106 | 0 | { |
107 | 0 | UpdateToolBoxes( *mpMediaItem ); |
108 | 0 | UpdateTimeSlider( *mpMediaItem ); |
109 | 0 | UpdateVolumeSlider( *mpMediaItem ); |
110 | 0 | UpdateTimeField( *mpMediaItem, mpMediaItem->getTime() ); |
111 | 0 | } |
112 | 0 | } |
113 | | |
114 | | IMPL_LINK_NOARG( MediaPlaybackPanel, VolumeSlideHdl, weld::Scale&, void) |
115 | 0 | { |
116 | 0 | MediaItem aItem(SID_AVMEDIA_TOOLBOX); |
117 | 0 | aItem.setVolumeDB(mxVolumeSlider->get_value()); |
118 | 0 | mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem }); |
119 | 0 | } |
120 | | |
121 | | IMPL_LINK_NOARG( MediaPlaybackPanel, SeekHdl, weld::Scale&, void) |
122 | 0 | { |
123 | 0 | MediaItem aItem(SID_AVMEDIA_TOOLBOX); |
124 | 0 | double nTime = 0; |
125 | 0 | if (mpMediaItem) |
126 | 0 | nTime = mxTimeSlider->get_value() * mpMediaItem->getDuration() / AVMEDIA_TIME_RANGE; |
127 | 0 | aItem.setTime(nTime); |
128 | 0 | mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem }); |
129 | 0 | mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX); |
130 | 0 | } |
131 | | |
132 | | IMPL_LINK_NOARG( MediaPlaybackPanel, TimeoutHdl, Timer*, void) |
133 | 0 | { |
134 | 0 | mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX); |
135 | 0 | } |
136 | | |
137 | | IMPL_LINK( MediaPlaybackPanel, PlayToolBoxSelectHdl, const OUString&, rId, void) |
138 | 0 | { |
139 | 0 | MediaItem aItem(SID_AVMEDIA_TOOLBOX); |
140 | |
|
141 | 0 | if (rId == "play") |
142 | 0 | { |
143 | 0 | aItem.setState( MediaState::Play ); |
144 | |
|
145 | 0 | if( !mpMediaItem || (mpMediaItem->getTime() == mpMediaItem->getDuration() )) |
146 | 0 | aItem.setTime( 0.0 ); |
147 | 0 | else |
148 | 0 | aItem.setTime( mpMediaItem->getTime()); |
149 | 0 | } |
150 | 0 | else if (rId == "pause") |
151 | 0 | { |
152 | 0 | aItem.setState( MediaState::Pause ); |
153 | 0 | } |
154 | 0 | else if (rId == "stop") |
155 | 0 | { |
156 | 0 | aItem.setState( MediaState::Stop ); |
157 | 0 | aItem.setTime( 0.0 ); |
158 | 0 | } |
159 | 0 | else if (rId == "mute") |
160 | 0 | { |
161 | 0 | aItem.setMute( mxMuteToolBox->get_item_active(u"mute"_ustr) ); |
162 | 0 | } |
163 | 0 | else if (rId == "loop") |
164 | 0 | { |
165 | 0 | aItem.setLoop( mxPlayToolBox->get_item_active(u"loop"_ustr) ); |
166 | 0 | } |
167 | |
|
168 | 0 | if(aItem.getMaskSet() != AVMediaSetMask::NONE) |
169 | 0 | { |
170 | 0 | mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem } ); |
171 | 0 | mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX); |
172 | 0 | } |
173 | 0 | } |
174 | | |
175 | | } // end of namespace svx::sidebar |
176 | | |
177 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |