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