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"
38 #include "dialogs/extended.hpp"
40 DialogsProvider* DialogsProvider::instance = NULL;
42 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
43 QObject( NULL ), p_intf( _p_intf )
45 fixed_timer = new QTimer( this );
46 fixed_timer->start( 150 /* milliseconds */ );
48 menusMapper = new QSignalMapper();
49 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
51 menusUpdateMapper = new QSignalMapper();
52 CONNECT( menusUpdateMapper, mapped(QObject *),
53 this, menuUpdateAction( QObject *) );
56 DialogsProvider::~DialogsProvider()
58 PlaylistDialog::killInstance();
59 StreamInfoDialog::killInstance();
62 void DialogsProvider::customEvent( QEvent *event )
64 if( event->type() == DialogEvent_Type )
66 DialogEvent *de = static_cast<DialogEvent*>(event);
67 switch( de->i_dialog )
69 case INTF_DIALOG_FILE:
70 case INTF_DIALOG_DISC:
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:
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;
90 case INTF_DIALOG_BOOKMARKS:
91 bookmarksDialog(); break;
92 case INTF_DIALOG_WIZARD:
94 msg_Warn( p_intf, "unimplemented dialog\n" );
99 void DialogsProvider::playlistDialog()
101 PlaylistDialog::getInstance( p_intf )->toggleVisible();
104 void DialogsProvider::openDialog()
108 void DialogsProvider::PLAppendDialog()
111 void DialogsProvider::MLAppendDialog()
114 void DialogsProvider::openDialog( int i_dialog )
118 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
120 InteractionDialog *qdialog;
121 interaction_dialog_t *p_dialog = p_arg->p_dialog;
122 switch( p_dialog->i_action )
125 qdialog = new InteractionDialog( p_intf, p_dialog );
126 p_dialog->p_private = (void*)qdialog;
127 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
130 case INTERACT_UPDATE:
131 qdialog = (InteractionDialog*)(p_dialog->p_private);
136 qdialog = (InteractionDialog*)(p_dialog->p_private);
139 p_dialog->i_status = HIDDEN_DIALOG;
141 case INTERACT_DESTROY:
142 qdialog = (InteractionDialog*)(p_dialog->p_private);
143 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
145 p_dialog->i_status = DESTROYED_DIALOG;
150 void DialogsProvider::quit()
152 p_intf->b_die = VLC_TRUE;
153 QApplication::quit();
156 void DialogsProvider::streaminfoDialog()
158 StreamInfoDialog::getInstance( p_intf )->toggleVisible();
161 void DialogsProvider::streamingDialog()
165 void DialogsProvider::prefsDialog()
167 PrefsDialog::getInstance( p_intf )->toggleVisible();
169 void DialogsProvider::extendedDialog()
171 ExtendedDialog::getInstance( p_intf )->toggleVisible();
174 void DialogsProvider::messagesDialog()
176 MessagesDialog::getInstance( p_intf )->toggleVisible();
179 void DialogsProvider::menuAction( QObject *data )
181 QVLCMenu::DoAction( p_intf, data );
184 void DialogsProvider::menuUpdateAction( QObject *data )
186 MenuFunc * f = qobject_cast<MenuFunc *>(data);
190 void DialogsProvider::simplePLAppendDialog()
192 QStringList files = showSimpleOpen();
194 foreach( file, files )
196 const char * psz_utf8 = qtu( file );
197 playlist_PlaylistAdd( THEPL, psz_utf8, psz_utf8,
198 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
202 void DialogsProvider::simpleMLAppendDialog()
204 QStringList files = showSimpleOpen();
206 foreach( file, files )
208 const char * psz_utf8 = qtu( file );
209 playlist_MLAdd( THEPL, psz_utf8, psz_utf8,
210 PLAYLIST_APPEND | PLAYLIST_PREPARSE, PLAYLIST_END );
214 void DialogsProvider::simpleOpenDialog()
216 QStringList files = showSimpleOpen();
218 for( size_t i = 0 ; i< files.size(); i++ )
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 ),
229 void DialogsProvider::openPlaylist()
231 QStringList files = showSimpleOpen();
233 for( size_t i = 0 ; i< files.size(); i++ )
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 );
241 void DialogsProvider::openDirectory()
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_PlaylistAddInput( THEPL, p_input,
249 PLAYLIST_APPEND, PLAYLIST_END );
250 input_Read( THEPL, p_input, VLC_FALSE );
252 void DialogsProvider::openMLDirectory()
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,
259 playlist_MLAddInput( THEPL, p_input, PLAYLIST_APPEND, PLAYLIST_END );
260 input_Read( THEPL, p_input, VLC_FALSE );
263 QStringList DialogsProvider::showSimpleOpen()
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 );
278 void DialogsProvider::bookmarksDialog()
282 void DialogsProvider::popupMenu( int i_dialog )