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.
22 *****************************************************************************/
25 #include <QApplication>
26 #include <QSignalMapper>
27 #include <QFileDialog>
30 #include "dialogs_provider.hpp"
31 #include "main_interface.hpp"
33 #include <vlc_intf_strings.h>
36 #include "dialogs/playlist.hpp"
37 #include "dialogs/prefs_dialog.hpp"
38 #include "dialogs/mediainfo.hpp"
39 #include "dialogs/messages.hpp"
40 #include "dialogs/extended.hpp"
41 #include "dialogs/sout.hpp"
42 #include "dialogs/open.hpp"
43 #include "dialogs/help.hpp"
44 #include "dialogs/gototime.hpp"
46 DialogsProvider* DialogsProvider::instance = NULL;
48 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
49 QObject( NULL ), p_intf( _p_intf )
51 fixed_timer = new QTimer( this );
52 fixed_timer->start( 150 /* milliseconds */ );
54 menusMapper = new QSignalMapper();
55 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
57 menusUpdateMapper = new QSignalMapper();
58 CONNECT( menusUpdateMapper, mapped(QObject *),
59 this, menuUpdateAction( QObject *) );
61 SDMapper = new QSignalMapper();
62 CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
65 DialogsProvider::~DialogsProvider()
67 PlaylistDialog::killInstance();
68 MediaInfoDialog::killInstance();
71 void DialogsProvider::quit()
73 p_intf->b_die = VLC_TRUE;
77 void DialogsProvider::customEvent( QEvent *event )
79 if( event->type() == DialogEvent_Type )
81 DialogEvent *de = static_cast<DialogEvent*>(event);
82 switch( de->i_dialog )
84 case INTF_DIALOG_FILE:
86 case INTF_DIALOG_DISC:
87 openDiscDialog(); break;
89 openNetDialog(); break;
90 case INTF_DIALOG_CAPTURE:
91 openCaptureDialog(); break;
92 case INTF_DIALOG_PLAYLIST:
93 playlistDialog(); break;
94 case INTF_DIALOG_MESSAGES:
95 messagesDialog(); break;
96 case INTF_DIALOG_PREFS:
98 case INTF_DIALOG_POPUPMENU:
99 case INTF_DIALOG_AUDIOPOPUPMENU:
100 case INTF_DIALOG_VIDEOPOPUPMENU:
101 case INTF_DIALOG_MISCPOPUPMENU:
102 popupMenu( de->i_dialog ); break;
103 case INTF_DIALOG_FILEINFO:
104 mediaInfoDialog(); break;
105 case INTF_DIALOG_INTERACTION:
106 doInteraction( de->p_arg ); break;
107 case INTF_DIALOG_BOOKMARKS:
108 bookmarksDialog(); break;
109 case INTF_DIALOG_VLM:
110 case INTF_DIALOG_WIZARD:
112 msg_Warn( p_intf, "unimplemented dialog\n" );
117 /****************************************************************************
118 * Individual simple dialogs
119 ****************************************************************************/
120 void DialogsProvider::playlistDialog()
122 PlaylistDialog::getInstance( p_intf )->toggleVisible();
125 void DialogsProvider::prefsDialog()
127 PrefsDialog::getInstance( p_intf )->toggleVisible();
129 void DialogsProvider::extendedDialog()
131 ExtendedDialog::getInstance( p_intf )->toggleVisible();
134 void DialogsProvider::messagesDialog()
136 MessagesDialog::getInstance( p_intf )->toggleVisible();
139 void DialogsProvider::gotoTimeDialog()
141 GotoTimeDialog::getInstance( p_intf )->toggleVisible();
144 void DialogsProvider::helpDialog()
146 HelpDialog::getInstance( p_intf )->toggleVisible();
149 void DialogsProvider::aboutDialog()
151 AboutDialog::getInstance( p_intf )->toggleVisible();
154 void DialogsProvider::mediaInfoDialog()
156 MediaInfoDialog::getInstance( p_intf )->toggleVisible();
159 void DialogsProvider::mediaCodecDialog()
161 MediaInfoDialog::getInstance( p_intf )->showTab( 1 );
164 void DialogsProvider::bookmarksDialog()
168 /****************************************************************************
169 * All the open/add stuff
170 ****************************************************************************/
172 void DialogsProvider::openDialog()
176 void DialogsProvider::openFileDialog()
180 void DialogsProvider::openDiscDialog()
184 void DialogsProvider::openNetDialog()
188 void DialogsProvider::openCaptureDialog()
192 void DialogsProvider::openDialog( int i_tab )
194 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
197 void DialogsProvider::PLAppendDialog()
200 void DialogsProvider::MLAppendDialog()
204 /**** Simple open ****/
205 QStringList DialogsProvider::showSimpleOpen( QString help, int filters,
208 QString fileTypes = "";
209 if( filters & EXT_FILTER_MEDIA ) {
210 ADD_FILTER_MEDIA( fileTypes );
212 if( filters & EXT_FILTER_VIDEO ) {
213 ADD_FILTER_VIDEO( fileTypes );
215 if( filters & EXT_FILTER_AUDIO ) {
216 ADD_FILTER_AUDIO( fileTypes );
218 if( filters & EXT_FILTER_PLAYLIST ) {
219 ADD_FILTER_PLAYLIST( fileTypes );
221 if( filters & EXT_FILTER_SUBTITLE ) {
222 ADD_FILTER_SUBTITLE( fileTypes );
224 ADD_FILTER_ALL( fileTypes );
225 fileTypes.replace(QString(";*"), QString(" *"));
226 return QFileDialog::getOpenFileNames( NULL,
227 help.isNull() ? qfu(I_OP_SEL_FILES ) : help,
228 path.isNull() ? qfu( p_intf->p_libvlc->psz_homedir ) : path,
232 void DialogsProvider::addFromSimple( bool pl, bool go)
234 QStringList files = DialogsProvider::showSimpleOpen();
236 foreach( QString file, files )
238 const char * psz_utf8 = qtu( file );
239 playlist_Add( THEPL, psz_utf8, NULL,
240 go ? ( PLAYLIST_APPEND | ( i ? 0 : PLAYLIST_GO ) |
241 ( i ? PLAYLIST_PREPARSE : 0 ) )
242 : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
244 pl ? VLC_TRUE : VLC_FALSE, VLC_FALSE );
249 void DialogsProvider::simplePLAppendDialog()
251 addFromSimple( true, false );
254 void DialogsProvider::simpleMLAppendDialog()
256 addFromSimple( false, false );
259 void DialogsProvider::simpleOpenDialog()
261 addFromSimple( true, true );
264 void DialogsProvider::openPlaylist()
266 QStringList files = showSimpleOpen( qtr( "Open playlist file" ),
267 EXT_FILTER_PLAYLIST );
268 foreach( QString file, files )
270 playlist_Import( THEPL, qtu(file) );
274 void DialogsProvider::savePlaylist()
276 QFileDialog *qfd = new QFileDialog( NULL,
277 qtr("Choose a filename to save playlist"),
278 qfu( p_intf->p_libvlc->psz_homedir ),
279 qtr("XSPF playlist (*.xspf);; ") +
280 qtr("M3U playlist (*.m3u);; Any (*.*) ") );
281 qfd->setFileMode( QFileDialog::AnyFile );
282 qfd->setAcceptMode( QFileDialog::AcceptSave );
283 qfd->setConfirmOverwrite( true );
285 if( qfd->exec() == QDialog::Accepted )
287 if( qfd->selectedFiles().count() > 0 )
289 char *psz_module, *psz_m3u = "export-m3u",
290 *psz_xspf = "export-xspf";
292 QString file = qfd->selectedFiles().first();
293 QString filter = qfd->selectedFilter();
295 if( file.contains(".xsp") ||
296 ( filter.contains(".xspf") && !file.contains(".m3u") ) )
298 psz_module = psz_xspf;
299 if( !file.contains( ".xsp" ) )
300 file.append( ".xspf" );
304 psz_module = psz_m3u;
305 if( !file.contains( ".m3u" ) )
306 file.append( ".m3u" );
309 playlist_Export( THEPL, qtu(file), THEPL->p_local_category,
316 static void openDirectory( intf_thread_t* p_intf, bool pl, bool go )
318 QString dir = QFileDialog::getExistingDirectory ( 0,
319 _("Open directory") );
320 input_item_t *p_input = input_ItemNewExt( THEPL, qtu(dir), NULL,
322 playlist_AddInput( THEPL, p_input,
323 go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
324 PLAYLIST_END, pl, VLC_FALSE );
325 input_Read( THEPL, p_input, VLC_FALSE );
328 void DialogsProvider::PLAppendDir()
330 openDirectory( p_intf, true, false );
333 void DialogsProvider::MLAppendDir()
335 openDirectory( p_intf, false , false );
339 /****************************************************************************
341 ****************************************************************************/
343 void DialogsProvider::streamingDialog()
345 OpenDialog *o = new OpenDialog( p_intf->p_sys->p_mi, p_intf, true );
346 if ( o->exec() == QDialog::Accepted )
348 SoutDialog *s = new SoutDialog( p_intf->p_sys->p_mi, p_intf );
349 if( s->exec() == QDialog::Accepted )
351 msg_Err(p_intf, "mrl %s\n", qta(s->mrl));
353 int i_len = strlen( qtu(s->mrl) ) + 10;
354 char *psz_option = (char*)malloc(i_len);
355 snprintf( psz_option, i_len - 1, ":sout=%s", qtu(s->mrl));
357 playlist_AddExt( THEPL, qtu( o->mrl ), "Streaming",
358 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
359 -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
366 /****************************************************************************
367 * Menus / Interaction
368 ****************************************************************************/
370 void DialogsProvider::menuAction( QObject *data )
372 QVLCMenu::DoAction( p_intf, data );
375 void DialogsProvider::menuUpdateAction( QObject *data )
377 MenuFunc * f = qobject_cast<MenuFunc *>(data);
381 void DialogsProvider::SDMenuAction( QString data )
383 char *psz_sd = strdup( qtu( data ) );
384 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
385 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
387 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
393 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
395 InteractionDialog *qdialog;
396 interaction_dialog_t *p_dialog = p_arg->p_dialog;
397 switch( p_dialog->i_action )
400 qdialog = new InteractionDialog( p_intf, p_dialog );
401 p_dialog->p_private = (void*)qdialog;
402 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
405 case INTERACT_UPDATE:
406 qdialog = (InteractionDialog*)(p_dialog->p_private);
411 qdialog = (InteractionDialog*)(p_dialog->p_private);
414 p_dialog->i_status = HIDDEN_DIALOG;
416 case INTERACT_DESTROY:
417 qdialog = (InteractionDialog*)(p_dialog->p_private);
418 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
420 p_dialog->i_status = DESTROYED_DIALOG;
425 void DialogsProvider::switchToSkins()
427 var_SetString( p_intf, "intf-switch", "skins2" );
430 void DialogsProvider::popupMenu( int i_dialog )