1 /*****************************************************************************
2 * main_inteface.cpp : Main interface
3 *****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
26 #include <QApplication>
27 #include <QSignalMapper>
28 #include <QFileDialog>
32 #include "dialogs_provider.hpp"
33 #include "main_interface.hpp"
35 #include <vlc_intf_strings.h>
38 #include "dialogs/playlist.hpp"
39 #include "dialogs/preferences.hpp"
40 #include "dialogs/mediainfo.hpp"
41 #include "dialogs/messages.hpp"
42 #include "dialogs/extended.hpp"
43 #include "dialogs/sout.hpp"
44 #include "dialogs/open.hpp"
45 #include "dialogs/vlm.hpp"
46 #include "dialogs/help.hpp"
47 #include "dialogs/gototime.hpp"
48 #include "dialogs/podcast_configuration.hpp"
49 #include "dialogs/vlm.hpp"
52 DialogsProvider* DialogsProvider::instance = NULL;
54 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
55 QObject( NULL ), p_intf( _p_intf )
57 fixed_timer = new QTimer( this );
58 fixed_timer->start( 150 /* milliseconds */ );
60 menusMapper = new QSignalMapper();
61 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
63 menusUpdateMapper = new QSignalMapper();
64 CONNECT( menusUpdateMapper, mapped(QObject *),
65 this, menuUpdateAction( QObject *) );
67 SDMapper = new QSignalMapper();
68 CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
71 DialogsProvider::~DialogsProvider()
73 PlaylistDialog::killInstance();
74 MediaInfoDialog::killInstance();
78 void DialogsProvider::quit()
80 vlc_object_kill( p_intf );
81 QApplication::closeAllWindows();
85 void DialogsProvider::customEvent( QEvent *event )
87 if( event->type() == DialogEvent_Type )
89 DialogEvent *de = static_cast<DialogEvent*>(event);
90 switch( de->i_dialog )
92 case INTF_DIALOG_FILE_SIMPLE:
93 case INTF_DIALOG_FILE:
95 case INTF_DIALOG_DISC:
96 openDiscDialog(); break;
98 openNetDialog(); break;
100 case INTF_DIALOG_CAPTURE:
101 openCaptureDialog(); break;
102 case INTF_DIALOG_DIRECTORY:
103 PLAppendDir(); break;
104 case INTF_DIALOG_PLAYLIST:
105 playlistDialog(); break;
106 case INTF_DIALOG_MESSAGES:
107 messagesDialog(); break;
108 case INTF_DIALOG_FILEINFO:
109 mediaInfoDialog(); break;
110 case INTF_DIALOG_PREFS:
111 prefsDialog(); break;
112 case INTF_DIALOG_BOOKMARKS:
113 bookmarksDialog(); break;
114 case INTF_DIALOG_EXTENDED:
115 extendedDialog(); break;
116 case INTF_DIALOG_VLM:
118 case INTF_DIALOG_INTERACTION:
119 doInteraction( de->p_arg ); break;
120 case INTF_DIALOG_POPUPMENU:
121 QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0) ); break;
122 case INTF_DIALOG_AUDIOPOPUPMENU:
123 QVLCMenu::AudioPopupMenu( p_intf ); break;
124 case INTF_DIALOG_VIDEOPOPUPMENU:
125 QVLCMenu::VideoPopupMenu( p_intf ); break;
126 case INTF_DIALOG_MISCPOPUPMENU:
127 QVLCMenu::MiscPopupMenu( p_intf ); break;
128 case INTF_DIALOG_WIZARD:
129 case INTF_DIALOG_STREAMWIZARD:
131 case INTF_DIALOG_UPDATEVLC:
132 updateDialog(); break;
134 case INTF_DIALOG_EXIT:
136 msg_Warn( p_intf, "unimplemented dialog" );
141 /****************************************************************************
142 * Individual simple dialogs
143 ****************************************************************************/
144 void DialogsProvider::playlistDialog()
146 PlaylistDialog::getInstance( p_intf )->toggleVisible();
149 void DialogsProvider::prefsDialog()
151 PrefsDialog::getInstance( p_intf )->toggleVisible();
154 void DialogsProvider::extendedDialog()
156 ExtendedDialog::getInstance( p_intf )->toggleVisible();
159 void DialogsProvider::messagesDialog()
161 MessagesDialog::getInstance( p_intf )->toggleVisible();
164 void DialogsProvider::gotoTimeDialog()
166 GotoTimeDialog::getInstance( p_intf )->toggleVisible();
169 void DialogsProvider::vlmDialog()
171 VLMDialog::getInstance( p_intf )->toggleVisible();
174 void DialogsProvider::helpDialog()
176 HelpDialog::getInstance( p_intf )->toggleVisible();
180 void DialogsProvider::updateDialog()
182 UpdateDialog::getInstance( p_intf )->toggleVisible();
186 void DialogsProvider::aboutDialog()
188 AboutDialog::getInstance( p_intf )->toggleVisible();
191 void DialogsProvider::mediaInfoDialog()
193 MediaInfoDialog::getInstance( p_intf )->toggleVisible();
196 void DialogsProvider::mediaCodecDialog()
198 MediaInfoDialog::getInstance( p_intf )->showTab( 2 );
201 void DialogsProvider::bookmarksDialog()
203 /* TODO - Implement me */
204 /* BookmarkDialog::getInstance( p_intf )->toggleVisible(); */
207 void DialogsProvider::podcastConfigureDialog()
209 PodcastConfigDialog::getInstance( p_intf )->toggleVisible();
213 /****************************************************************************
214 * All the open/add stuff
215 * Open Dialog first - Simple Open then
216 ****************************************************************************/
218 void DialogsProvider::openDialog( int i_tab )
220 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
222 void DialogsProvider::openDialog()
224 openDialog( OPEN_FILE_TAB );
226 void DialogsProvider::openFileDialog()
228 openDialog( OPEN_FILE_TAB );
230 void DialogsProvider::openDiscDialog()
232 openDialog( OPEN_DISC_TAB );
234 void DialogsProvider::openNetDialog()
236 openDialog( OPEN_NETWORK_TAB );
238 void DialogsProvider::openCaptureDialog()
240 openDialog( OPEN_CAPTURE_TAB );
243 /* Same as the open one, but force the enqueue */
244 void DialogsProvider::PLAppendDialog()
246 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_ENQUEUE)
247 ->showTab( OPEN_FILE_TAB );
250 /* Unimplemmented yet - Usefull ? */
251 void DialogsProvider::MLAppendDialog()
257 * Not used anymore. Let the code until we are sure we don't want it
258 * Two opens make it confusing for the user.
260 QStringList DialogsProvider::showSimpleOpen( QString help,
264 QString fileTypes = "";
265 if( filters & EXT_FILTER_MEDIA ) {
266 ADD_FILTER_MEDIA( fileTypes );
268 if( filters & EXT_FILTER_VIDEO ) {
269 ADD_FILTER_VIDEO( fileTypes );
271 if( filters & EXT_FILTER_AUDIO ) {
272 ADD_FILTER_AUDIO( fileTypes );
274 if( filters & EXT_FILTER_PLAYLIST ) {
275 ADD_FILTER_PLAYLIST( fileTypes );
277 if( filters & EXT_FILTER_SUBTITLE ) {
278 ADD_FILTER_SUBTITLE( fileTypes );
280 ADD_FILTER_ALL( fileTypes );
281 fileTypes.replace(QString(";*"), QString(" *"));
282 return QFileDialog::getOpenFileNames( NULL,
283 help.isNull() ? qfu(I_OP_SEL_FILES ) : help,
284 path.isNull() ? qfu( p_intf->p_libvlc->psz_homedir ) : path,
290 * pl helps you to choose from playlist or media library,
291 * go to start or enqueue
293 void DialogsProvider::addFromSimple( bool pl, bool go)
295 QStringList files = DialogsProvider::showSimpleOpen();
297 foreach( QString file, files )
299 const char * psz_utf8 = qtu( file );
300 playlist_Add( THEPL, psz_utf8, NULL,
301 go ? ( PLAYLIST_APPEND | ( i ? 0 : PLAYLIST_GO ) |
302 ( i ? PLAYLIST_PREPARSE : 0 ) )
303 : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
305 pl ? VLC_TRUE : VLC_FALSE, VLC_FALSE );
310 void DialogsProvider::simpleOpenDialog()
312 addFromSimple( true, true ); /* Playlist and Go */
315 void DialogsProvider::simplePLAppendDialog()
317 addFromSimple( true, false );
320 void DialogsProvider::simpleMLAppendDialog()
322 addFromSimple( false, false );
328 * pl helps you to choose from playlist or media library,
329 * go to start or enqueue
331 static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
333 QString dir = QFileDialog::getExistingDirectory( 0, qtr(I_OP_OPDIR) );
334 if (!dir.isEmpty()) {
335 input_item_t *p_input = input_ItemNewExt( THEPL,
336 qtu( "directory://" + dir ), NULL,
339 playlist_AddInput( THEPL, p_input,
340 go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
341 PLAYLIST_END, pl, VLC_FALSE );
342 input_Read( THEPL, p_input, VLC_FALSE );
346 void DialogsProvider::PLAppendDir()
348 openDirectory( p_intf, true, false );
351 void DialogsProvider::MLAppendDir()
353 openDirectory( p_intf, false , false );
359 void DialogsProvider::openAPlaylist()
361 QStringList files = showSimpleOpen( qtr( "Open playlist file" ),
362 EXT_FILTER_PLAYLIST );
363 foreach( QString file, files )
365 playlist_Import( THEPL, qtu(file) );
369 void DialogsProvider::saveAPlaylist()
371 QFileDialog *qfd = new QFileDialog( NULL,
372 qtr( "Choose a filename to save playlist" ),
373 qfu( p_intf->p_libvlc->psz_homedir ),
374 qtr( "XSPF playlist (*.xspf);; " ) +
375 qtr( "M3U playlist (*.m3u);; Any (*.*) " ) );
376 qfd->setFileMode( QFileDialog::AnyFile );
377 qfd->setAcceptMode( QFileDialog::AcceptSave );
378 qfd->setConfirmOverwrite( true );
380 if( qfd->exec() == QDialog::Accepted )
382 if( qfd->selectedFiles().count() > 0 )
384 static const char psz_xspf[] = "export-xspf",
385 psz_m3u[] = "export-m3u";
386 const char *psz_module;
388 QString file = qfd->selectedFiles().first();
389 QString filter = qfd->selectedFilter();
391 if( file.contains( ".xsp" ) ||
392 ( filter.contains( ".xspf" ) && !file.contains( ".m3u" ) ) )
394 psz_module = psz_xspf;
395 if( !file.contains( ".xsp" ) )
396 file.append( ".xspf" );
400 psz_module = psz_m3u;
401 if( !file.contains( ".m3u" ) )
402 file.append( ".m3u" );
405 playlist_Export( THEPL, qtu( file ), THEPL->p_local_category,
413 /****************************************************************************
415 ****************************************************************************/
418 void DialogsProvider::streamingDialog( QString mrl, bool b_transcode_only )
420 SoutDialog *s = new SoutDialog( p_intf->p_sys->p_mi, p_intf,
422 if( s->exec() == QDialog::Accepted )
424 msg_Err( p_intf, "mrl %s", qta( s->getMrl() ) );
426 int i_len = strlen( qtu( s->getMrl() ) ) + 10;
427 char *psz_option = (char*)malloc( i_len );
428 snprintf( psz_option, i_len - 1, "%s", qtu( s->getMrl() ) );
430 playlist_AddExt( THEPL, qtu( mrl ), "Streaming",
431 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
432 -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
437 void DialogsProvider::openThenStreamingDialogs()
439 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_STREAM )
443 void DialogsProvider::openThenTranscodingDialogs()
445 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_SAVE )
449 void DialogsProvider::streamingDialog()
451 OpenDialog *o = new OpenDialog( p_intf->p_sys->p_mi, p_intf, true );
452 if ( o->exec() == QDialog::Accepted )
454 SoutDialog *s = new SoutDialog( p_intf->p_sys->p_mi, p_intf );
455 if( s->exec() == QDialog::Accepted )
457 msg_Err(p_intf, "mrl %s\n", qta(s->mrl));
459 int i_len = strlen( qtu(s->mrl) ) + 10;
460 char *psz_option = (char*)malloc(i_len);
461 snprintf( psz_option, i_len - 1, ":sout=%s", qtu(s->mrl));
463 playlist_AddExt( THEPL, qtu( o->mrl ), "Streaming",
464 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
465 -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
473 /****************************************************************************
474 * Menus / Interaction
475 ****************************************************************************/
477 void DialogsProvider::menuAction( QObject *data )
479 QVLCMenu::DoAction( p_intf, data );
482 void DialogsProvider::menuUpdateAction( QObject *data )
484 MenuFunc * f = qobject_cast<MenuFunc *>(data);
488 void DialogsProvider::SDMenuAction( QString data )
490 char *psz_sd = strdup( qtu( data ) );
491 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
492 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
494 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
498 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
500 InteractionDialog *qdialog;
501 interaction_dialog_t *p_dialog = p_arg->p_dialog;
502 switch( p_dialog->i_action )
505 qdialog = new InteractionDialog( p_intf, p_dialog );
506 p_dialog->p_private = (void*)qdialog;
507 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
510 case INTERACT_UPDATE:
511 qdialog = (InteractionDialog*)(p_dialog->p_private);
516 qdialog = (InteractionDialog*)(p_dialog->p_private);
519 p_dialog->i_status = HIDDEN_DIALOG;
521 case INTERACT_DESTROY:
522 qdialog = (InteractionDialog*)(p_dialog->p_private);
523 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
525 p_dialog->i_status = DESTROYED_DIALOG;
530 void DialogsProvider::switchToSkins()
532 var_SetString( p_intf, "intf-switch", "skins2" );