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