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