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