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