1 /*****************************************************************************
2 * actions_manager.cpp : Controller for the main interface
3 ****************************************************************************
4 * Copyright © 2009-2014 VideoLAN and VLC authors
7 * Authors: Jean-Baptiste Kempf <jb@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * ( at your option ) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
29 #include <vlc_actions.h>
30 #include <vlc_renderer_discovery.h>
32 #include "actions_manager.hpp"
34 #include "dialogs_provider.hpp" /* Opening Dialogs */
35 #include "input_manager.hpp" /* THEMIM */
36 #include "main_interface.hpp" /* Show playlist */
37 #include "components/controller.hpp" /* Toggle FSC controller width */
38 #include "components/extended_panels.hpp"
41 ActionsManager::ActionsManager( intf_thread_t
* _p_i
)
45 ActionsManager::~ActionsManager()
47 foreach ( vlc_renderer_discovery_t
* p_rd
, m_rds
)
48 vlc_rd_release( p_rd
);
51 void ActionsManager::doAction( int id_action
)
58 THEMIM
->stop(); break;
60 THEDP
->openDialog(); break;
62 THEMIM
->prev(); break;
64 THEMIM
->next(); break;
66 THEMIM
->getIM()->slower(); break;
68 THEMIM
->getIM()->faster(); break;
69 case FULLSCREEN_ACTION
:
72 THEDP
->extendedDialog(); break;
82 THEMIM
->getIM()->setAtoB(); break;
84 THEMIM
->getIM()->reverse(); break;
85 case SKIP_BACK_ACTION
:
94 THEMIM
->toggleRandom(); break;
96 THEDP
->mediaInfoDialog(); break;
98 THEDP
->loadSubtitlesFile(); break;
99 case FULLWIDTH_ACTION
:
100 if( p_intf
->p_sys
->p_mi
)
101 p_intf
->p_sys
->p_mi
->getFullscreenControllerWidget()->toggleFullwidth();
104 msg_Warn( p_intf
, "Action not supported: %i", id_action
);
109 void ActionsManager::play()
111 if( THEPL
->current
.i_size
== 0 && THEPL
->items
.i_size
== 0 )
113 /* The playlist is empty, open a file requester */
114 THEDP
->openFileDialog();
117 THEMIM
->togglePlayPause();
122 * This functions toggle the fullscreen mode
123 * If there is no video, it should first activate Visualisations...
124 * This has also to be fixed in enableVideo()
126 void ActionsManager::fullscreen()
128 bool fs
= var_ToggleBool( THEPL
, "fullscreen" );
129 vout_thread_t
*p_vout
= THEMIM
->getVout();
132 var_SetBool( p_vout
, "fullscreen", fs
);
133 vlc_object_release( p_vout
);
137 void ActionsManager::snapshot()
139 vout_thread_t
*p_vout
= THEMIM
->getVout();
142 var_TriggerCallback( p_vout
, "video-snapshot" );
143 vlc_object_release( p_vout
);
147 void ActionsManager::playlist()
149 if( p_intf
->p_sys
->p_mi
)
150 p_intf
->p_sys
->p_mi
->togglePlaylist();
153 void ActionsManager::record()
155 input_thread_t
*p_input
= THEMIM
->getInput();
158 /* This method won't work fine if the stream can't be cut anywhere */
159 var_ToggleBool( p_input
, "record" );
163 /* 'record' access-filter is not loaded, we open Save dialog */
164 input_item_t
*p_item
= input_GetItem( p_input
);
168 char *psz
= input_item_GetURI( p_item
);
170 THEDP
->streamingDialog( NULL
, qfu(psz
), true );
176 void ActionsManager::frame()
178 input_thread_t
*p_input
= THEMIM
->getInput();
180 var_TriggerCallback( p_input
, "frame-next" );
183 void ActionsManager::toggleMuteAudio()
185 playlist_MuteToggle( THEPL
);
188 void ActionsManager::AudioUp()
190 playlist_VolumeUp( THEPL
, 1, NULL
);
193 void ActionsManager::AudioDown()
195 playlist_VolumeDown( THEPL
, 1, NULL
);
198 void ActionsManager::skipForward()
200 input_thread_t
*p_input
= THEMIM
->getInput();
202 THEMIM
->getIM()->jumpFwd();
205 void ActionsManager::skipBackward()
207 input_thread_t
*p_input
= THEMIM
->getInput();
209 THEMIM
->getIM()->jumpBwd();
212 bool ActionsManager::compareRenderers( const QVariant
&obj
, vlc_renderer_item_t
* p_item
)
214 if (!obj
.canConvert
<QVariantHash
>())
216 QVariantHash qvh
= obj
.value
<QVariantHash
>();
217 if (!qvh
.contains( "sout" ))
219 vlc_renderer_item_t
* p_existing
=
220 reinterpret_cast<vlc_renderer_item_t
*>( qvh
["sout"].value
<void*>() );
221 return !strcasecmp(vlc_renderer_item_sout( p_existing
),
222 vlc_renderer_item_sout( p_item
) );
225 void ActionsManager::renderer_event_item_added( vlc_renderer_discovery_t
*,
226 vlc_renderer_item_t
*p_item
)
228 QAction
*firstSeparator
= NULL
;
230 foreach (QAction
* action
, VLCMenuBar::rendererMenu
->actions())
232 if (action
->isSeparator())
234 firstSeparator
= action
;
237 QVariant v
= action
->data();
238 if (compareRenderers( action
->data(), p_item
))
239 return; /* we already have this item */
242 QAction
*action
= new QAction( vlc_renderer_item_flags(p_item
) & VLC_RENDERER_CAN_VIDEO
? QIcon( ":/sidebar/movie.svg" ) : QIcon( ":/sidebar/music.svg" ),
243 vlc_renderer_item_name(p_item
), VLCMenuBar::rendererMenu
);
244 action
->setCheckable(true);
246 vlc_renderer_item_hold( p_item
);
248 data
.insert( "sout", QVariant::fromValue( reinterpret_cast<void*>( p_item
) ) );
249 action
->setData( data
);
250 if (firstSeparator
!= NULL
)
252 VLCMenuBar::rendererMenu
->insertAction( firstSeparator
, action
);
253 VLCMenuBar::rendererGroup
->addAction(action
);
257 void ActionsManager::renderer_event_item_removed(
258 vlc_renderer_discovery_t
*, vlc_renderer_item_t
*p_item
)
260 foreach (QAction
* action
, VLCMenuBar::rendererMenu
->actions())
262 if (action
->isSeparator())
264 if (compareRenderers( action
->data(), p_item
))
266 VLCMenuBar::rendererMenu
->removeAction( action
);
267 VLCMenuBar::rendererGroup
->removeAction( action
);
268 vlc_renderer_item_release( p_item
);
274 void ActionsManager::ScanRendererAction(bool checked
)
276 if (checked
== !m_rds
.empty())
277 return; /* nothing changed */
281 /* reset the list of renderers */
282 foreach (QAction
* action
, VLCMenuBar::rendererMenu
->actions())
284 QVariant data
= action
->data();
285 if (!data
.canConvert
<QVariantHash
>())
287 VLCMenuBar::rendererMenu
->removeAction(action
);
288 VLCMenuBar::rendererGroup
->removeAction(action
);
292 char **ppsz_longnames
;
294 if( vlc_rd_get_names( THEPL
, &ppsz_names
, &ppsz_longnames
) != VLC_SUCCESS
)
297 struct vlc_renderer_discovery_owner owner
=
300 renderer_event_item_added
,
301 renderer_event_item_removed
,
304 char **ppsz_name
= ppsz_names
, **ppsz_longname
= ppsz_longnames
;
305 for( ; *ppsz_name
; ppsz_name
++, ppsz_longname
++ )
307 msg_Dbg( p_intf
, "starting renderer discovery service %s", *ppsz_longname
);
308 vlc_renderer_discovery_t
* p_rd
= vlc_rd_new( VLC_OBJECT(p_intf
), *ppsz_name
, &owner
);
310 m_rds
.push_back( p_rd
);
312 free( *ppsz_longname
);
315 free( ppsz_longnames
);
319 foreach ( vlc_renderer_discovery_t
* p_rd
, m_rds
)
320 vlc_rd_release( p_rd
);
325 void ActionsManager::RendererSelected( QAction
*selected
)
327 QVariant data
= selected
->data();
328 vlc_renderer_item_t
*p_item
= NULL
;
329 if (data
.canConvert
<QVariantHash
>())
331 QVariantHash hash
= data
.value
<QVariantHash
>();
332 if ( hash
.contains( "sout" ) )
333 p_item
= reinterpret_cast<vlc_renderer_item_t
*>(
334 hash
["sout"].value
<void*>() );
336 // If we failed to convert the action data to a vlc_renderer_item_t,
337 // assume the selected item was invalid, or most likely that "Local" was selected
338 playlist_SetRenderer( THEPL
, p_item
);