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