]> git.sesse.net Git - vlc/blob - modules/gui/qt4/actions_manager.cpp
Qt4: remove useless alive check on input
[vlc] / modules / gui / qt4 / actions_manager.cpp
1 /*****************************************************************************
2  * actions_manager.cpp : Controller for the main interface
3  ****************************************************************************
4  * Copyright (C) 2006-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Baptiste Kempf <jb@videolan.org>
8  *          Ilkka Ollakka <ileoo@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * ( at your option ) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <vlc_vout.h>
30 #include <vlc_keys.h>
31
32 #include "actions_manager.hpp"
33 #include "dialogs_provider.hpp" /* Opening Dialogs */
34 #include "input_manager.hpp"
35 #include "main_interface.hpp" /* Show playlist */
36 #include "components/controller.hpp" /* Toggle FSC controller width */
37
38 ActionsManager * ActionsManager::instance = NULL;
39
40 ActionsManager::ActionsManager( intf_thread_t * _p_i, QObject *_parent )
41                : QObject( _parent )
42 {
43     p_intf = _p_i;
44 }
45
46 ActionsManager::~ActionsManager(){}
47
48 void ActionsManager::doAction( int id_action )
49 {
50     switch( id_action )
51     {
52         case PLAY_ACTION:
53             play(); break;
54         case STOP_ACTION:
55             THEMIM->stop(); break;
56         case OPEN_ACTION:
57             THEDP->openDialog(); break;
58         case PREVIOUS_ACTION:
59             THEMIM->prev(); break;
60         case NEXT_ACTION:
61             THEMIM->next(); break;
62         case SLOWER_ACTION:
63             THEMIM->getIM()->slower(); break;
64         case FASTER_ACTION:
65             THEMIM->getIM()->faster(); break;
66         case FULLSCREEN_ACTION:
67             fullscreen(); break;
68         case EXTENDED_ACTION:
69             THEDP->extendedDialog(); break;
70         case PLAYLIST_ACTION:
71             playlist(); break;
72         case SNAPSHOT_ACTION:
73             snapshot(); break;
74         case RECORD_ACTION:
75             record(); break;
76         case FRAME_ACTION:
77             frame(); break;
78         case ATOB_ACTION:
79             THEMIM->getIM()->setAtoB(); break;
80         case REVERSE_ACTION:
81             THEMIM->getIM()->reverse(); break;
82         case SKIP_BACK_ACTION:
83             skipBackward();
84             break;
85         case SKIP_FW_ACTION:
86             skipForward();
87             break;
88         case QUIT_ACTION:
89             THEDP->quit();  break;
90         case RANDOM_ACTION:
91             THEMIM->toggleRandom(); break;
92         case INFO_ACTION:
93             THEDP->mediaInfoDialog(); break;
94         case OPEN_SUB_ACTION:
95             THEDP->loadSubtitlesFile(); break;
96         case FULLWIDTH_ACTION:
97             if( p_intf->p_sys->p_mi )
98                 p_intf->p_sys->p_mi->getFullscreenControllerWidget()->toggleFullwidth();
99             break;
100         default:
101             msg_Dbg( p_intf, "Action: %i", id_action );
102             break;
103     }
104 }
105
106 void ActionsManager::play()
107 {
108     if( THEPL->current.i_size == 0 )
109     {
110         /* The playlist is empty, open a file requester */
111         THEDP->openFileDialog();
112         return;
113     }
114     THEMIM->togglePlayPause();
115 }
116
117 /**
118   * TODO
119  * This functions toggle the fullscreen mode
120  * If there is no video, it should first activate Visualisations...
121  *  This has also to be fixed in enableVideo()
122  */
123 void ActionsManager::fullscreen()
124 {
125     bool fs = var_ToggleBool( THEPL, "fullscreen" );
126     vout_thread_t *p_vout = THEMIM->getVout();
127     if( p_vout)
128     {
129         var_SetBool( p_vout, "fullscreen", fs );
130         vlc_object_release( p_vout );
131     }
132 }
133
134 void ActionsManager::snapshot()
135 {
136     vout_thread_t *p_vout = THEMIM->getVout();
137     if( p_vout )
138     {
139         var_TriggerCallback( p_vout, "video-snapshot" );
140         vlc_object_release( p_vout );
141     }
142 }
143
144 void ActionsManager::playlist()
145 {
146     if( p_intf->p_sys->p_mi ) p_intf->p_sys->p_mi->togglePlaylist();
147 }
148
149 void ActionsManager::record()
150 {
151     input_thread_t *p_input = THEMIM->getInput();
152     if( p_input )
153     {
154         /* This method won't work fine if the stream can't be cut anywhere */
155         var_ToggleBool( p_input, "record" );
156 #if 0
157         else
158         {
159             /* 'record' access-filter is not loaded, we open Save dialog */
160             input_item_t *p_item = input_GetItem( p_input );
161             if( !p_item )
162                 return;
163
164             char *psz = input_item_GetURI( p_item );
165             if( psz )
166                 THEDP->streamingDialog( NULL, qfu(psz), true );
167         }
168 #endif
169     }
170 }
171
172 void ActionsManager::frame()
173 {
174     input_thread_t *p_input = THEMIM->getInput();
175     if( p_input )
176         var_TriggerCallback( p_input, "frame-next" );
177 }
178
179 void ActionsManager::toggleMuteAudio()
180 {
181      playlist_MuteToggle( THEPL );
182 }
183
184 void ActionsManager::AudioUp()
185 {
186     playlist_VolumeUp( THEPL, 1, NULL );
187 }
188
189 void ActionsManager::AudioDown()
190 {
191     playlist_VolumeDown( THEPL, 1, NULL );
192 }
193
194 void ActionsManager::skipForward()
195 {
196     input_thread_t *p_input = THEMIM->getInput();
197     if( p_input )
198         THEMIM->getIM()->jumpFwd();
199 }
200
201 void ActionsManager::skipBackward()
202 {
203     input_thread_t *p_input = THEMIM->getInput();
204     if( p_input )
205         THEMIM->getIM()->jumpBwd();
206 }
207