ee5bcb6adb30f7da82f39ecfca1c85b62c6c0ed4
[vlc.git] / modules / gui / qt4 / actions_manager.cpp
1 /*****************************************************************************
2  * Controller.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.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
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             var_SetInteger( p_intf->p_libvlc, "key-pressed",
84                     ACTIONID_JUMP_BACKWARD_SHORT );
85             break;
86         case SKIP_FW_ACTION:
87             var_SetInteger( p_intf->p_libvlc, "key-pressed",
88                     ACTIONID_JUMP_FORWARD_SHORT );
89             break;
90         case QUIT_ACTION:
91             THEDP->quit();  break;
92         default:
93             msg_Dbg( p_intf, "Action: %i", id_action );
94             break;
95     }
96 }
97
98 void ActionsManager::play()
99 {
100     if( THEPL->current.i_size == 0 )
101     {
102         /* The playlist is empty, open a file requester */
103         THEDP->openFileDialog();
104         return;
105     }
106     THEMIM->togglePlayPause();
107 }
108
109 /**
110   * TODO
111  * This functions toggle the fullscreen mode
112  * If there is no video, it should first activate Visualisations...
113  *  This has also to be fixed in enableVideo()
114  */
115 void ActionsManager::fullscreen()
116 {
117     vout_thread_t *p_vout = THEMIM->getVout();
118     if( p_vout)
119     {
120         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
121         vlc_object_release( p_vout );
122     }
123 }
124
125 void ActionsManager::snapshot()
126 {
127     vout_thread_t *p_vout = THEMIM->getVout();
128     if( p_vout )
129     {
130         vout_Control( p_vout, VOUT_SNAPSHOT );
131         vlc_object_release( p_vout );
132     }
133 }
134
135 void ActionsManager::playlist()
136 {
137     if( p_intf->p_sys->p_mi ) p_intf->p_sys->p_mi->togglePlaylist();
138 }
139
140 void ActionsManager::record()
141 {
142     input_thread_t *p_input = THEMIM->getInput();
143     if( p_input )
144     {
145         /* This method won't work fine if the stream can't be cut anywhere */
146         const bool b_recording = var_GetBool( p_input, "record" );
147         var_SetBool( p_input, "record", !b_recording );
148 #if 0
149         else
150         {
151             /* 'record' access-filter is not loaded, we open Save dialog */
152             input_item_t *p_item = input_GetItem( p_input );
153             if( !p_item )
154                 return;
155
156             char *psz = input_item_GetURI( p_item );
157             if( psz )
158                 THEDP->streamingDialog( NULL, psz, true );
159         }
160 #endif
161     }
162 }
163
164 void ActionsManager::frame()
165 {
166     input_thread_t *p_input = THEMIM->getInput();
167     if( p_input )
168         var_SetVoid( p_input, "frame-next" );
169 }
170
171 void ActionsManager::toggleMuteAudio()
172 {
173      aout_VolumeMute( p_intf, NULL );
174 }
175
176 void ActionsManager::AudioUp()
177 {
178     aout_VolumeUp( p_intf, 1, NULL );
179 }
180
181 void ActionsManager::AudioDown()
182 {
183     aout_VolumeDown( p_intf, 2, NULL );
184 }
185