1 /*****************************************************************************
2 * main_inteface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
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.
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.
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. *****************************************************************************/
24 #include <QApplication>
25 #include <QSignalMapper>
26 #include <QFileDialog>
29 #include "dialogs_provider.hpp"
31 #include <vlc_intf_strings.h>
34 #include "dialogs/playlist.hpp"
35 #include "dialogs/prefs_dialog.hpp"
36 #include "dialogs/streaminfo.hpp"
37 #include "dialogs/messages.hpp"
39 DialogsProvider* DialogsProvider::instance = NULL;
41 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
42 QObject( NULL ), p_intf( _p_intf )
44 fixed_timer = new QTimer( this );
45 fixed_timer->start( 150 /* milliseconds */ );
47 menusMapper = new QSignalMapper();
48 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
50 menusUpdateMapper = new QSignalMapper();
51 CONNECT( menusUpdateMapper, mapped(QObject *),
52 this, menuUpdateAction( QObject *) );
55 void DialogsProvider::customEvent( QEvent *event )
57 if( event->type() == DialogEvent_Type )
59 DialogEvent *de = static_cast<DialogEvent*>(event);
60 switch( de->i_dialog )
62 case INTF_DIALOG_FILE:
63 case INTF_DIALOG_DISC:
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:
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;
83 case INTF_DIALOG_BOOKMARKS:
84 bookmarksDialog(); break;
85 case INTF_DIALOG_WIZARD:
87 msg_Warn( p_intf, "unimplemented dialog\n" );
92 void DialogsProvider::playlistDialog()
94 PlaylistDialog::getInstance( p_intf )->toggleVisible();
97 void DialogsProvider::openDialog()
101 void DialogsProvider::PLAppendDialog()
104 void DialogsProvider::MLAppendDialog()
107 void DialogsProvider::openDialog( int i_dialog )
111 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
113 InteractionDialog *qdialog;
114 interaction_dialog_t *p_dialog = p_arg->p_dialog;
115 switch( p_dialog->i_action )
118 qdialog = new InteractionDialog( p_intf, p_dialog );
119 p_dialog->p_private = (void*)qdialog;
120 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
123 case INTERACT_UPDATE:
124 qdialog = (InteractionDialog*)(p_dialog->p_private);
129 qdialog = (InteractionDialog*)(p_dialog->p_private);
132 p_dialog->i_status = HIDDEN_DIALOG;
134 case INTERACT_DESTROY:
135 qdialog = (InteractionDialog*)(p_dialog->p_private);
136 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
138 p_dialog->i_status = DESTROYED_DIALOG;
143 void DialogsProvider::quit()
145 p_intf->b_die = VLC_TRUE;
146 QApplication::quit();
149 void DialogsProvider::streaminfoDialog()
151 StreamInfoDialog::getInstance( p_intf, true )->toggleVisible();
154 void DialogsProvider::streamingDialog()
158 void DialogsProvider::prefsDialog()
160 PrefsDialog::getInstance( p_intf )->toggleVisible();
163 void DialogsProvider::messagesDialog()
165 MessagesDialog::getInstance( p_intf )->toggleVisible();
168 void DialogsProvider::menuAction( QObject *data )
170 QVLCMenu::DoAction( p_intf, data );
173 void DialogsProvider::menuUpdateAction( QObject *data )
175 MenuFunc * f = qobject_cast<MenuFunc *>(data);
179 void DialogsProvider::simplePLAppendDialog()
181 QStringList files = showSimpleOpen();
183 foreach( file, files )
185 const char * psz_utf8 = qtu( file );
186 playlist_PlaylistAdd( THEPL, psz_utf8, psz_utf8,
187 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
191 void DialogsProvider::simpleMLAppendDialog()
193 QStringList files = showSimpleOpen();
195 foreach( file, files )
197 const char * psz_utf8 = qtu( file );
198 playlist_MLAdd( THEPL, psz_utf8, psz_utf8,
199 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
203 void DialogsProvider::simpleOpenDialog()
205 QStringList files = showSimpleOpen();
207 for( size_t i = 0 ; i< files.size(); i++ )
209 const char * psz_utf8 = qtu( files[i] );
210 /* Play the first one, parse and enqueue the other ones */
211 playlist_PlaylistAdd( THEPL, psz_utf8, psz_utf8,
212 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
213 ( i ? PLAYLIST_PREPARSE : 0 ),
218 void DialogsProvider::openPlaylist()
220 QStringList files = showSimpleOpen();
222 for( size_t i = 0 ; i< files.size(); i++ )
224 const char * psz_utf8 = qtu( files[i] );
225 /* Play the first one, parse and enqueue the other ones */
226 playlist_Import( THEPL, psz_utf8, THEPL->p_root_category, VLC_FALSE );
230 void DialogsProvider::openDirectory()
232 QString dir = QFileDialog::getExistingDirectory ( 0,
233 _("Open directory") );
234 const char *psz_utf8 = qtu( dir );
235 input_item_t *p_input = input_ItemNewExt( THEPL, psz_utf8, psz_utf8,
237 playlist_PlaylistAddInput( THEPL, p_input,
238 PLAYLIST_APPEND, PLAYLIST_END );
239 input_Read( THEPL, p_input, VLC_FALSE );
241 void DialogsProvider::openMLDirectory()
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,
248 playlist_MLAddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END );
249 input_Read( THEPL, p_input, VLC_FALSE );
252 QStringList DialogsProvider::showSimpleOpen()
255 FileTypes = "Video Files ( ";
256 FileTypes += EXTENSIONS_VIDEO;
257 FileTypes += ");; Sound Files ( ";
258 FileTypes += EXTENSIONS_AUDIO;
259 FileTypes += ");; PlayList Files ( ";
260 FileTypes += EXTENSIONS_PLAYLIST;
261 FileTypes += ");; All Files (*.*)" ;
262 FileTypes.replace(QString(";*"), QString(" *"));
263 return QFileDialog::getOpenFileNames( NULL, qfu(I_POP_SEL_FILES ),
264 p_intf->p_vlc->psz_homedir, FileTypes );
267 void DialogsProvider::bookmarksDialog()
271 void DialogsProvider::popupMenu( int i_dialog )