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