fix filename self-references
[vlc.git] / 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_aout_intf.h>
31 #include <vlc_keys.h>
32
33 #include "actions_manager.hpp"
34 #include "dialogs_provider.hpp" /* Opening Dialogs */
35 #include "input_manager.hpp"
36 #include "main_interface.hpp" /* Show playlist */
37 #include "components/controller.hpp" /* Toggle FSC controller width */
38
39 ActionsManager * ActionsManager::instance = NULL;
40
41 ActionsManager::ActionsManager( intf_thread_t * _p_i, QObject *_parent )
42                : QObject( _parent )
43 {
44     p_intf = _p_i;
45 }
46
47 ActionsManager::~ActionsManager(){}
48
49 void ActionsManager::doAction( int id_action )
50 {
51     switch( id_action )
52     {
53         case PLAY_ACTION:
54             play(); break;
55         case STOP_ACTION:
56             THEMIM->stop(); break;
57         case OPEN_ACTION:
58             THEDP->openDialog(); break;
59         case PREVIOUS_ACTION:
60             THEMIM->prev(); break;
61         case NEXT_ACTION:
62             THEMIM->next(); break;
63         case SLOWER_ACTION:
64             THEMIM->getIM()->slower(); break;
65         case FASTER_ACTION:
66             THEMIM->getIM()->faster(); break;
67         case FULLSCREEN_ACTION:
68             fullscreen(); break;
69         case EXTENDED_ACTION:
70             THEDP->extendedDialog(); break;
71         case PLAYLIST_ACTION:
72             playlist(); break;
73         case SNAPSHOT_ACTION:
74             snapshot(); break;
75         case RECORD_ACTION:
76             record(); break;
77         case FRAME_ACTION:
78             frame(); break;
79         case ATOB_ACTION:
80             THEMIM->getIM()->setAtoB(); break;
81         case REVERSE_ACTION:
82             THEMIM->getIM()->reverse(); break;
83         case SKIP_BACK_ACTION:
84             skipBackward();
85             break;
86         case SKIP_FW_ACTION:
87             skipForward();
88             break;
89         case QUIT_ACTION:
90             THEDP->quit();  break;
91         case RANDOM_ACTION:
92             THEMIM->toggleRandom(); break;
93         case INFO_ACTION:
94             THEDP->mediaInfoDialog(); break;
95         case OPEN_SUB_ACTION:
96             THEDP->loadSubtitlesFile(); break;
97         case FULLWIDTH_ACTION:
98             if( p_intf->p_sys->p_mi )
99                 p_intf->p_sys->p_mi->getFullscreenControllerWidget()->toggleFullwidth();
100             break;
101         default:
102             msg_Dbg( p_intf, "Action: %i", id_action );
103             break;
104     }
105 }
106
107 void ActionsManager::play()
108 {
109     if( THEPL->current.i_size == 0 )
110     {
111         /* The playlist is empty, open a file requester */
112         THEDP->openFileDialog();
113         return;
114     }
115     THEMIM->togglePlayPause();
116 }
117
118 /**
119   * TODO
120  * This functions toggle the fullscreen mode
121  * If there is no video, it should first activate Visualisations...
122  *  This has also to be fixed in enableVideo()
123  */
124 void ActionsManager::fullscreen()
125 {
126     bool fs = var_ToggleBool( THEPL, "fullscreen" );
127     vout_thread_t *p_vout = THEMIM->getVout();
128     if( p_vout)
129     {
130         var_SetBool( p_vout, "fullscreen", fs );
131         vlc_object_release( p_vout );
132     }
133 }
134
135 void ActionsManager::snapshot()
136 {
137     vout_thread_t *p_vout = THEMIM->getVout();
138     if( p_vout )
139     {
140         var_TriggerCallback( p_vout, "video-snapshot" );
141         vlc_object_release( p_vout );
142     }
143 }
144
145 void ActionsManager::playlist()
146 {
147     if( p_intf->p_sys->p_mi ) p_intf->p_sys->p_mi->togglePlaylist();
148 }
149
150 void ActionsManager::record()
151 {
152     input_thread_t *p_input = THEMIM->getInput();
153     if( p_input )
154     {
155         /* This method won't work fine if the stream can't be cut anywhere */
156         var_ToggleBool( p_input, "record" );
157 #if 0
158         else
159         {
160             /* 'record' access-filter is not loaded, we open Save dialog */
161             input_item_t *p_item = input_GetItem( p_input );
162             if( !p_item )
163                 return;
164
165             char *psz = input_item_GetURI( p_item );
166             if( psz )
167                 THEDP->streamingDialog( NULL, qfu(psz), true );
168         }
169 #endif
170     }
171 }
172
173 void ActionsManager::frame()
174 {
175     input_thread_t *p_input = THEMIM->getInput();
176     if( p_input )
177         var_TriggerCallback( p_input, "frame-next" );
178 }
179
180 void ActionsManager::toggleMuteAudio()
181 {
182      aout_ToggleMute( THEPL, NULL );
183 }
184
185 void ActionsManager::AudioUp()
186 {
187     aout_VolumeUp( THEPL, 1, NULL );
188 }
189
190 void ActionsManager::AudioDown()
191 {
192     aout_VolumeDown( THEPL, 1, NULL );
193 }
194
195 void ActionsManager::skipForward()
196 {
197     THEMIM->getIM()->jumpFwd();
198 }
199
200 void ActionsManager::skipBackward()
201 {
202     THEMIM->getIM()->jumpBwd();
203 }
204