]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs_provider.cpp
Fix a number of problems with interaction dialogs
[vlc] / modules / gui / qt4 / dialogs_provider.cpp
1 /*****************************************************************************
2  * main_inteface.cpp : Main interface
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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
23 #include <QEvent>
24 #include <QApplication>
25 #include <QSignalMapper>
26 #include <QFileDialog>
27
28 #include "qt4.hpp"
29 #include "dialogs_provider.hpp"
30 #include "menus.hpp"
31 #include <vlc_intf_strings.h>
32
33 /* The dialogs */
34 #include "dialogs/playlist.hpp"
35 #include "dialogs/prefs_dialog.hpp"
36 #include "dialogs/streaminfo.hpp"
37 #include "dialogs/messages.hpp"
38
39 DialogsProvider* DialogsProvider::instance = NULL;
40
41 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
42                                       QObject( NULL ), p_intf( _p_intf )
43 {
44     fixed_timer = new QTimer( this );
45     fixed_timer->start( 150 /* milliseconds */ );
46
47     menusMapper = new QSignalMapper();
48     CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
49
50     menusUpdateMapper = new QSignalMapper();
51     CONNECT( menusUpdateMapper, mapped(QObject *),
52              this, menuUpdateAction( QObject *) );
53 }
54
55 void DialogsProvider::customEvent( QEvent *event )
56 {
57     if( event->type() == DialogEvent_Type )
58     {
59         DialogEvent *de = static_cast<DialogEvent*>(event);
60         switch( de->i_dialog )
61         {
62             case INTF_DIALOG_FILE:
63             case INTF_DIALOG_DISC:
64             case INTF_DIALOG_NET:
65             case INTF_DIALOG_CAPTURE:
66                 openDialog( de->i_dialog ); break;
67             case INTF_DIALOG_PLAYLIST:
68                 playlistDialog(); break;
69             case INTF_DIALOG_MESSAGES:
70                 messagesDialog(); break;
71             case INTF_DIALOG_PREFS:
72                prefsDialog(); break;
73             case INTF_DIALOG_POPUPMENU:
74             case INTF_DIALOG_AUDIOPOPUPMENU:
75             case INTF_DIALOG_VIDEOPOPUPMENU:
76             case INTF_DIALOG_MISCPOPUPMENU:
77                popupMenu( de->i_dialog ); break;
78             case INTF_DIALOG_FILEINFO:
79                streaminfoDialog(); break;
80             case INTF_DIALOG_INTERACTION:
81                doInteraction( de->p_arg ); break;
82             case INTF_DIALOG_VLM:
83             case INTF_DIALOG_BOOKMARKS:
84                bookmarksDialog(); break;
85             case INTF_DIALOG_WIZARD:
86             default:
87                msg_Warn( p_intf, "unimplemented dialog\n" );
88         }
89     }
90 }
91
92 void DialogsProvider::playlistDialog()
93 {
94     PlaylistDialog::getInstance( p_intf )->toggleVisible();
95 }
96
97 void DialogsProvider::openDialog()
98 {
99     openDialog( 0 );
100 }
101 void DialogsProvider::PLAppendDialog()
102 {
103 }
104 void DialogsProvider::MLAppendDialog()
105 {
106 }
107 void DialogsProvider::openDialog( int i_dialog )
108 {
109 }
110
111 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
112 {
113     InteractionDialog *qdialog;
114     interaction_dialog_t *p_dialog = p_arg->p_dialog;
115     switch( p_dialog->i_action )
116     {
117     case INTERACT_NEW:
118         qdialog = new InteractionDialog( p_intf, p_dialog );
119         p_dialog->p_private = (void*)qdialog;
120         if( !(p_dialog->i_status == ANSWERED_DIALOG) )
121             qdialog->show();
122         break;
123     case INTERACT_UPDATE:
124         qdialog = (InteractionDialog*)(p_dialog->p_private);
125         if( qdialog)
126             qdialog->update();
127         break;
128     case INTERACT_HIDE:
129         qdialog = (InteractionDialog*)(p_dialog->p_private);
130         if( qdialog )
131             qdialog->hide();
132         p_dialog->i_status = HIDDEN_DIALOG;
133         break;
134     case INTERACT_DESTROY:
135         qdialog = (InteractionDialog*)(p_dialog->p_private);
136         if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
137             delete qdialog;
138         p_dialog->i_status = DESTROYED_DIALOG;
139         break;
140     }
141 }
142
143 void DialogsProvider::quit()
144 {
145     p_intf->b_die = VLC_TRUE;
146     QApplication::quit();
147 }
148
149 void DialogsProvider::streaminfoDialog()
150 {
151     StreamInfoDialog::getInstance( p_intf, true )->toggleVisible();
152 }
153
154 void DialogsProvider::streamingDialog()
155 {
156 }
157
158 void DialogsProvider::prefsDialog()
159 {
160     PrefsDialog::getInstance( p_intf )->toggleVisible();
161 }
162
163 void DialogsProvider::messagesDialog()
164 {
165     MessagesDialog::getInstance( p_intf )->toggleVisible();
166 }
167
168 void DialogsProvider::menuAction( QObject *data )
169 {
170     QVLCMenu::DoAction( p_intf, data );
171 }
172
173 void DialogsProvider::menuUpdateAction( QObject *data )
174 {
175     MenuFunc * f = qobject_cast<MenuFunc *>(data);
176     f->doFunc( p_intf );
177 }
178
179 void DialogsProvider::simplePLAppendDialog()
180 {
181     QStringList files = showSimpleOpen();
182     QString file;
183     foreach( file, files )
184     {
185         const char * psz_utf8 = qtu( file );
186         playlist_PlaylistAdd( THEPL, psz_utf8, psz_utf8,
187                      PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
188     }
189 }
190
191 void DialogsProvider::simpleMLAppendDialog()
192 {
193     QStringList files = showSimpleOpen();
194     QString file;
195     foreach( file, files )
196     {
197         const char * psz_utf8 =  qtu( file );
198         playlist_MLAdd( THEPL, psz_utf8, psz_utf8,
199                         PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
200     }
201 }
202
203 void DialogsProvider::simpleOpenDialog()
204 {
205     QStringList files = showSimpleOpen();
206     QString file;
207     for( size_t i = 0 ; i< files.size(); i++ )
208     {
209         const char * psz_utf8 = qtu( files[i] );
210         /* Play the first one, parse and enqueue the other ones */
211         playlist_PlaylistAdd( THEPL, psz_utf8, psz_utf8,
212                      PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
213                      ( i ? PLAYLIST_PREPARSE : 0 ),
214                      PLAYLIST_END );
215     }
216 }
217
218 void DialogsProvider::openPlaylist()
219 {
220     QStringList files = showSimpleOpen();
221     QString file;
222     for( size_t i = 0 ; i< files.size(); i++ )
223     {
224         const char * psz_utf8 = qtu( files[i] );
225         /* Play the first one, parse and enqueue the other ones */
226         playlist_Import( THEPL, psz_utf8, THEPL->p_root_category, VLC_FALSE );
227     }
228 }
229
230 void DialogsProvider::openDirectory()
231 {
232     QString dir = QFileDialog::getExistingDirectory ( 0,
233                                                      _("Open directory") );
234     const char *psz_utf8 = qtu( dir );
235     input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, psz_utf8,
236                                                0, NULL, -1 );
237     playlist_PlaylistAddInput( THEPL, p_input,
238                                PLAYLIST_APPEND, PLAYLIST_END );
239     input_Read( THEPL, p_input, VLC_FALSE );
240 }
241 void DialogsProvider::openMLDirectory()
242 {
243     QString dir = QFileDialog::getExistingDirectory ( 0,
244                                                      _("Open directory") );
245     const char *psz_utf8 = qtu( dir );
246     input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, psz_utf8,
247                                                0, NULL, -1 );
248     playlist_MLAddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END );
249     input_Read( THEPL, p_input, VLC_FALSE );
250 }
251
252 QStringList DialogsProvider::showSimpleOpen()
253 {
254     QString FileTypes;
255     FileTypes = "Video Files ( ";
256     FileTypes += EXTENSIONS_VIDEO;
257     FileTypes += ");; Sound Files ( ";
258     FileTypes += EXTENSIONS_AUDIO;
259     FileTypes += ");; PlayList Files ( ";
260     FileTypes += EXTENSIONS_PLAYLIST;
261     FileTypes += ");; All Files (*.*)" ;
262     FileTypes.replace(QString(";*"), QString(" *"));
263     return QFileDialog::getOpenFileNames( NULL, qfu(I_POP_SEL_FILES ),
264                     p_intf->p_vlc->psz_homedir, FileTypes );
265 }
266
267 void DialogsProvider::bookmarksDialog()
268 {
269 }
270
271 void DialogsProvider::popupMenu( int i_dialog )
272 {
273
274 }