]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs_provider.cpp
* Made open and sout QDialogs
[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 "main_interface.hpp"
31 #include "menus.hpp"
32 #include <vlc_intf_strings.h>
33
34 /* The dialogs */
35 #include "dialogs/playlist.hpp"
36 #include "dialogs/prefs_dialog.hpp"
37 #include "dialogs/mediainfo.hpp"
38 #include "dialogs/messages.hpp"
39 #include "dialogs/extended.hpp"
40 #include "dialogs/sout.hpp"
41 #include "dialogs/open.hpp"
42 #include "dialogs/help.hpp"
43
44 DialogsProvider* DialogsProvider::instance = NULL;
45
46 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
47                                       QObject( NULL ), p_intf( _p_intf )
48 {
49     fixed_timer = new QTimer( this );
50     fixed_timer->start( 150 /* milliseconds */ );
51
52     menusMapper = new QSignalMapper();
53     CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
54
55     menusUpdateMapper = new QSignalMapper();
56     CONNECT( menusUpdateMapper, mapped(QObject *),
57              this, menuUpdateAction( QObject *) );
58
59     SDMapper = new QSignalMapper();
60     CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
61 }
62
63 DialogsProvider::~DialogsProvider()
64 {
65     PlaylistDialog::killInstance();
66     MediaInfoDialog::killInstance();
67 }
68
69 void DialogsProvider::customEvent( QEvent *event )
70 {
71     if( event->type() == DialogEvent_Type )
72     {
73         DialogEvent *de = static_cast<DialogEvent*>(event);
74         switch( de->i_dialog )
75         {
76             case INTF_DIALOG_FILE:
77             case INTF_DIALOG_DISC:
78             case INTF_DIALOG_NET:
79             case INTF_DIALOG_CAPTURE:
80                 openDialog( de->i_dialog ); break;
81             case INTF_DIALOG_PLAYLIST:
82                 playlistDialog(); break;
83             case INTF_DIALOG_MESSAGES:
84                 messagesDialog(); break;
85             case INTF_DIALOG_PREFS:
86                prefsDialog(); break;
87             case INTF_DIALOG_POPUPMENU:
88             case INTF_DIALOG_AUDIOPOPUPMENU:
89             case INTF_DIALOG_VIDEOPOPUPMENU:
90             case INTF_DIALOG_MISCPOPUPMENU:
91                popupMenu( de->i_dialog ); break;
92             case INTF_DIALOG_FILEINFO:
93                MediaInfoDialog(); break;
94             case INTF_DIALOG_INTERACTION:
95                doInteraction( de->p_arg ); break;
96             case INTF_DIALOG_VLM:
97             case INTF_DIALOG_BOOKMARKS:
98                bookmarksDialog(); break;
99             case INTF_DIALOG_WIZARD:
100             default:
101                msg_Warn( p_intf, "unimplemented dialog\n" );
102         }
103     }
104 }
105
106 void DialogsProvider::playlistDialog()
107 {
108     PlaylistDialog::getInstance( p_intf )->toggleVisible();
109 }
110
111 void DialogsProvider::openDialog()
112 {
113     openDialog( 0 );
114 }
115 void DialogsProvider::PLAppendDialog()
116 {
117 }
118 void DialogsProvider::MLAppendDialog()
119 {
120 }
121 void DialogsProvider::openDialog( int i_tab )
122 {
123     OpenDialog::getInstance( p_intf->p_sys->p_mi  , p_intf )->showTab( i_tab );
124 }
125
126 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
127 {
128     InteractionDialog *qdialog;
129     interaction_dialog_t *p_dialog = p_arg->p_dialog;
130     switch( p_dialog->i_action )
131     {
132     case INTERACT_NEW:
133         qdialog = new InteractionDialog( p_intf, p_dialog );
134         p_dialog->p_private = (void*)qdialog;
135         if( !(p_dialog->i_status == ANSWERED_DIALOG) )
136             qdialog->show();
137         break;
138     case INTERACT_UPDATE:
139         qdialog = (InteractionDialog*)(p_dialog->p_private);
140         if( qdialog)
141             qdialog->update();
142         break;
143     case INTERACT_HIDE:
144         qdialog = (InteractionDialog*)(p_dialog->p_private);
145         if( qdialog )
146             qdialog->hide();
147         p_dialog->i_status = HIDDEN_DIALOG;
148         break;
149     case INTERACT_DESTROY:
150         qdialog = (InteractionDialog*)(p_dialog->p_private);
151         if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
152             delete qdialog;
153         p_dialog->i_status = DESTROYED_DIALOG;
154         break;
155     }
156 }
157
158 void DialogsProvider::quit()
159 {
160     p_intf->b_die = VLC_TRUE;
161     QApplication::quit();
162 }
163
164 void DialogsProvider::MediaInfoDialog()
165 {
166     MediaInfoDialog::getInstance( p_intf )->toggleVisible();
167 }
168
169 void DialogsProvider::streamingDialog()
170 {
171     OpenDialog *o = new OpenDialog( p_intf->p_sys->p_mi, p_intf, true );
172     if ( o->exec() == QDialog::Accepted )
173     {
174         SoutDialog *s = new SoutDialog( p_intf->p_sys->p_mi, p_intf );
175         if( s->exec() == QDialog::Accepted )
176         {
177             msg_Err(p_intf, "mrl %s\n", qta(s->mrl));
178             /* Just do it */
179             int i_len = strlen( qtu(s->mrl) ) + 10;
180             char *psz_option = (char*)malloc(i_len);
181             snprintf( psz_option, i_len - 1, ":sout=%s", qtu(s->mrl));
182
183             playlist_AddExt( THEPL, qtu( o->mrl ), "Streaming",
184                              PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
185                              -1, &psz_option, 1, VLC_TRUE );
186         }
187         delete s;
188     }
189     delete o;
190 }
191
192 void DialogsProvider::prefsDialog()
193 {
194     PrefsDialog::getInstance( p_intf )->toggleVisible();
195 }
196 void DialogsProvider::extendedDialog()
197 {
198     ExtendedDialog::getInstance( p_intf )->toggleVisible();
199 }
200
201 void DialogsProvider::messagesDialog()
202 {
203     MessagesDialog::getInstance( p_intf )->toggleVisible();
204 }
205
206 void DialogsProvider::helpDialog()
207 {
208     HelpDialog::getInstance( p_intf )->toggleVisible();
209 }
210
211 void DialogsProvider::aboutDialog()
212 {
213     AboutDialog::getInstance( p_intf )->toggleVisible();
214 }
215
216 void DialogsProvider::menuAction( QObject *data )
217 {
218     QVLCMenu::DoAction( p_intf, data );
219 }
220
221 void DialogsProvider::menuUpdateAction( QObject *data )
222 {
223     MenuFunc * f = qobject_cast<MenuFunc *>(data);
224     f->doFunc( p_intf );
225 }
226
227 void DialogsProvider::SDMenuAction( QString data )
228 {
229     char *psz_sd = data.toUtf8().data();
230     if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
231         playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
232     else
233         playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
234 }
235
236
237 void DialogsProvider::simplePLAppendDialog()
238 {
239     QStringList files = showSimpleOpen();
240     QString file;
241     foreach( file, files )
242     {
243         const char * psz_utf8 = qtu( file );
244         playlist_Add( THEPL, psz_utf8, NULL,
245                 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END, VLC_TRUE );
246     }
247 }
248
249 void DialogsProvider::simpleMLAppendDialog()
250 {
251     QStringList files = showSimpleOpen();
252     QString file;
253     foreach( file, files )
254     {
255         const char * psz_utf8 =  qtu( file );
256         playlist_Add( THEPL, psz_utf8, psz_utf8,
257                       PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END,
258                       VLC_TRUE);
259     }
260 }
261
262 void DialogsProvider::simpleOpenDialog()
263 {
264     QStringList files = showSimpleOpen();
265     QString file;
266     for( size_t i = 0 ; i< files.size(); i++ )
267     {
268         const char * psz_utf8 = qtu( files[i] );
269         /* Play the first one, parse and enqueue the other ones */
270         playlist_Add( THEPL, psz_utf8, NULL,
271                       PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
272                       ( i ? PLAYLIST_PREPARSE : 0 ),
273                       PLAYLIST_END, VLC_TRUE );
274     }
275 }
276
277 void DialogsProvider::openPlaylist()
278 {
279     QStringList files = showSimpleOpen();
280     QString file;
281     for( size_t i = 0 ; i< files.size(); i++ )
282     {
283         const char * psz_utf8 = qtu( files[i] );
284         playlist_Import( THEPL, psz_utf8 );
285     }
286 }
287
288 void DialogsProvider::openDirectory()
289 {
290     QString dir = QFileDialog::getExistingDirectory ( 0,
291                                                      _("Open directory") );
292     const char *psz_utf8 = qtu( dir );
293     input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, NULL,
294                                                0, NULL, -1 );
295     playlist_AddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE);
296     input_Read( THEPL, p_input, VLC_FALSE );
297 }
298 void DialogsProvider::openMLDirectory()
299 {
300     QString dir = QFileDialog::getExistingDirectory ( 0,
301                                                      _("Open directory") );
302     const char *psz_utf8 = qtu( dir );
303     input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, NULL,
304                                                0, NULL, -1 );
305     playlist_AddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END,
306                         VLC_FALSE );
307     input_Read( THEPL, p_input, VLC_FALSE );
308 }
309
310 QStringList DialogsProvider::showSimpleOpen()
311 {
312     QString FileTypes;
313     FileTypes = _("Media Files");
314     FileTypes += " ( ";
315     FileTypes += EXTENSIONS_MEDIA;
316     FileTypes += ");;";
317     FileTypes += _("Video Files");
318     FileTypes += " ( ";
319     FileTypes += EXTENSIONS_VIDEO;
320     FileTypes += ");;";
321     FileTypes += _("Sound Files");
322     FileTypes += " ( ";
323     FileTypes += EXTENSIONS_AUDIO;
324     FileTypes += ");;";
325     FileTypes += _("PlayList Files");
326     FileTypes += " ( ";
327     FileTypes += EXTENSIONS_PLAYLIST;
328     FileTypes += ");;";
329     FileTypes += _("All Files");
330     FileTypes += " (*.*)";
331     FileTypes.replace(QString(";*"), QString(" *"));
332     return QFileDialog::getOpenFileNames( NULL, qfu(I_POP_SEL_FILES ),
333                     p_intf->p_libvlc->psz_homedir, FileTypes );
334 }
335
336 void DialogsProvider::switchToSkins()
337 {
338     var_SetString( p_intf, "intf-switch", "skins2" );
339 }
340
341 void DialogsProvider::bookmarksDialog()
342 {
343 }
344
345 void DialogsProvider::popupMenu( int i_dialog )
346 {
347
348 }