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 *****************************************************************************/
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
)
46 ActionsManager::~ActionsManager()
49 vlc_rd_release( p_rd
);
52 void ActionsManager::doAction( int id_action
)
59 THEMIM
->stop(); break;
61 THEDP
->openDialog(); break;
63 THEMIM
->prev(); break;
65 THEMIM
->next(); break;
67 THEMIM
->getIM()->slower(); break;
69 THEMIM
->getIM()->faster(); break;
70 case FULLSCREEN_ACTION
:
73 THEDP
->extendedDialog(); break;
83 THEMIM
->getIM()->setAtoB(); break;
85 THEMIM
->getIM()->reverse(); break;
86 case SKIP_BACK_ACTION
:
95 THEMIM
->toggleRandom(); break;
97 THEDP
->mediaInfoDialog(); break;
99 THEDP
->loadSubtitlesFile(); break;
100 case FULLWIDTH_ACTION
:
101 if( p_intf
->p_sys
->p_mi
)
102 p_intf
->p_sys
->p_mi
->getFullscreenControllerWidget()->toggleFullwidth();
105 msg_Warn( p_intf
, "Action not supported: %i", id_action
);
110 void ActionsManager::play()
112 if( THEPL
->current
.i_size
== 0 && THEPL
->items
.i_size
== 0 )
114 /* The playlist is empty, open a file requester */
115 THEDP
->openFileDialog();
118 THEMIM
->togglePlayPause();
123 * This functions toggle the fullscreen mode
124 * If there is no video, it should first activate Visualisations...
125 * This has also to be fixed in enableVideo()
127 void ActionsManager::fullscreen()
129 bool fs
= var_ToggleBool( THEPL
, "fullscreen" );
130 vout_thread_t
*p_vout
= THEMIM
->getVout();
133 var_SetBool( p_vout
, "fullscreen", fs
);
134 vlc_object_release( p_vout
);
138 void ActionsManager::snapshot()
140 vout_thread_t
*p_vout
= THEMIM
->getVout();
143 var_TriggerCallback( p_vout
, "video-snapshot" );
144 vlc_object_release( p_vout
);
148 void ActionsManager::playlist()
150 if( p_intf
->p_sys
->p_mi
)
151 p_intf
->p_sys
->p_mi
->togglePlaylist();
154 void ActionsManager::record()
156 input_thread_t
*p_input
= THEMIM
->getInput();
159 /* This method won't work fine if the stream can't be cut anywhere */
160 var_ToggleBool( p_input
, "record" );
164 /* 'record' access-filter is not loaded, we open Save dialog */
165 input_item_t
*p_item
= input_GetItem( p_input
);
169 char *psz
= input_item_GetURI( p_item
);
171 THEDP
->streamingDialog( NULL
, qfu(psz
), true );
177 void ActionsManager::frame()
179 input_thread_t
*p_input
= THEMIM
->getInput();
181 var_TriggerCallback( p_input
, "frame-next" );
184 void ActionsManager::toggleMuteAudio()
186 playlist_MuteToggle( THEPL
);
189 void ActionsManager::AudioUp()
191 playlist_VolumeUp( THEPL
, 1, NULL
);
194 void ActionsManager::AudioDown()
196 playlist_VolumeDown( THEPL
, 1, NULL
);
199 void ActionsManager::skipForward()
201 input_thread_t
*p_input
= THEMIM
->getInput();
203 THEMIM
->getIM()->jumpFwd();
206 void ActionsManager::skipBackward()
208 input_thread_t
*p_input
= THEMIM
->getInput();
210 THEMIM
->getIM()->jumpBwd();
213 void ActionsManager::PPaction( QAction
*a
)
217 i_q
= a
->data().toInt();
219 ExtVideo::setPostprocessing( p_intf
, i_q
);
222 bool ActionsManager::isItemSout( QVariant
& m_obj
, const char *psz_sout
, bool as_output
)
224 if ( psz_sout
== NULL
)
226 if (!m_obj
.canConvert
<QVariantHash
>())
229 QVariantHash hash
= m_obj
.value
<QVariantHash
>();
230 QString
renderer(psz_sout
);
231 if ( as_output
&& renderer
.at(0) == '#' )
232 renderer
= renderer
.right( renderer
.length() - 1 );
233 return QString::compare( hash
["sout"].toString(), renderer
, Qt::CaseInsensitive
) == 0;
236 void ActionsManager::renderer_event_item_added(
237 vlc_renderer_discovery_t
*rd
, vlc_renderer_item_t
*p_item
)
239 intf_thread_t
*p_intf
= reinterpret_cast<intf_thread_t
*>(rd
->owner
.sys
);
240 QAction
*firstSeparator
= NULL
;
242 foreach (QAction
* action
, VLCMenuBar::rendererMenu
->actions())
244 if (action
->isSeparator())
246 firstSeparator
= action
;
249 QVariant v
= action
->data();
250 if ( isItemSout( v
, vlc_renderer_item_sout( p_item
), false ) )
251 return; /* we already have this item */
254 QHash
<QString
,QVariant
> itemData
;
255 itemData
.insert("sout", vlc_renderer_item_sout( p_item
));
256 itemData
.insert("filter", vlc_renderer_item_demux_filter( p_item
));
257 QVariant
data(itemData
);
259 QAction
*action
= new QAction( vlc_renderer_item_flags(p_item
) & VLC_RENDERER_CAN_VIDEO
? QIcon( ":/sidebar/movie" ) : QIcon( ":/sidebar/music" ),
260 vlc_renderer_item_name(p_item
), VLCMenuBar::rendererMenu
);
261 action
->setCheckable(true);
262 action
->setData(data
);
263 if (firstSeparator
!= NULL
)
265 VLCMenuBar::rendererMenu
->insertAction( firstSeparator
, action
);
266 VLCMenuBar::rendererGroup
->addAction(action
);
269 char *psz_renderer
= var_InheritString( THEPL
, "sout" );
270 if ( psz_renderer
!= NULL
)
272 if ( isItemSout( data
, psz_renderer
, true ) )
273 action
->setChecked( true );
274 free( psz_renderer
);
278 void ActionsManager::renderer_event_item_removed(
279 vlc_renderer_discovery_t
*rd
, vlc_renderer_item_t
*p_item
)
281 (void) rd
; (void) p_item
;
284 void ActionsManager::ScanRendererAction(bool checked
)
286 if (checked
== (p_rd
!= NULL
))
287 return; /* nothing changed */
291 /* reset the list of renderers */
292 foreach (QAction
* action
, VLCMenuBar::rendererMenu
->actions())
294 QVariant data
= action
->data();
295 if (!data
.canConvert
<QVariantHash
>())
297 VLCMenuBar::rendererMenu
->removeAction(action
);
298 VLCMenuBar::rendererGroup
->removeAction(action
);
300 char *psz_renderer
= var_InheritString( THEPL
, "sout" );
301 if ( psz_renderer
== NULL
|| *psz_renderer
== '\0' )
303 foreach (QAction
* action
, VLCMenuBar::rendererMenu
->actions())
305 if (!action
->data().canConvert
<QVariantHash
>())
307 if (!action
->isSeparator())
308 action
->setChecked(true);
312 free( psz_renderer
);
315 char **ppsz_longnames
;
317 if( vlc_rd_get_names( THEPL
, &ppsz_names
, &ppsz_longnames
) != VLC_SUCCESS
)
320 struct vlc_renderer_discovery_owner owner
=
323 renderer_event_item_added
,
324 renderer_event_item_removed
,
327 char **ppsz_name
= ppsz_names
, **ppsz_longname
= ppsz_longnames
;
328 for( ; *ppsz_name
; ppsz_name
++, ppsz_longname
++ )
330 /* TODO launch all discovery services for renderers */
331 msg_Dbg( p_intf
, "starting renderer discovery service %s", *ppsz_longname
);
334 p_rd
= vlc_rd_new( VLC_OBJECT(p_intf
), *ppsz_name
, &owner
);
336 msg_Err( p_intf
, "Could not start renderer discovery services" );
341 free( ppsz_longnames
);
345 if( vlc_rd_start( p_rd
) != VLC_SUCCESS
)
347 vlc_rd_release( p_rd
);
356 vlc_rd_release( p_rd
);
362 void ActionsManager::RendererSelected( QAction
*selected
)
364 QString s_sout
, s_demux_filter
;
365 QVariant data
= selected
->data();
366 if (data
.canConvert
<QVariantHash
>())
368 QVariantHash hash
= data
.value
<QVariantHash
>();
370 s_sout
.append(hash
["sout"].toString());
371 s_demux_filter
.append(hash
["filter"].toString());
373 msg_Dbg( p_intf
, "using sout: '%s'", s_sout
.toUtf8().constData() );
374 var_SetString( THEPL
, "sout", s_sout
.toUtf8().constData() );
375 var_SetString( THEPL
, "demux-filter", s_demux_filter
.toUtf8().constData() );