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 *****************************************************************************/
29 #include <QApplication>
30 #include <QSignalMapper>
31 #include <QFileDialog>
33 #include <vlc_common.h>
35 #include "dialogs_provider.hpp"
36 #include "main_interface.hpp"
38 #include <vlc_intf_strings.h>
39 #include "input_manager.hpp"
42 #include "dialogs/playlist.hpp"
43 #include "dialogs/bookmarks.hpp"
44 #include "dialogs/preferences.hpp"
45 #include "dialogs/mediainfo.hpp"
46 #include "dialogs/messages.hpp"
47 #include "dialogs/extended.hpp"
48 #include "dialogs/vlm.hpp"
49 #include "dialogs/sout.hpp"
50 #include "dialogs/open.hpp"
51 #include "dialogs/help.hpp"
52 #include "dialogs/gototime.hpp"
53 #include "dialogs/podcast_configuration.hpp"
55 DialogsProvider* DialogsProvider::instance = NULL;
57 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
58 QObject( NULL ), p_intf( _p_intf )
60 fixed_timer = new QTimer( this );
61 fixed_timer->start( 150 /* milliseconds */ );
63 menusMapper = new QSignalMapper();
64 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
66 menusUpdateMapper = new QSignalMapper();
67 CONNECT( menusUpdateMapper, mapped(QObject *),
68 this, menuUpdateAction( QObject *) );
70 SDMapper = new QSignalMapper();
71 CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
74 DialogsProvider::~DialogsProvider()
76 msg_Dbg( p_intf, "Destroying the Dialog Provider" );
77 PlaylistDialog::killInstance();
78 MediaInfoDialog::killInstance();
79 MessagesDialog::killInstance();
80 ExtendedDialog::killInstance();
81 BookmarksDialog::killInstance();
82 HelpDialog::killInstance();
84 UpdateDialog::killInstance();
90 void DialogsProvider::quit()
92 vlc_object_kill( p_intf->p_libvlc );
93 QApplication::closeAllWindows();
97 void DialogsProvider::customEvent( QEvent *event )
99 if( event->type() == DialogEvent_Type )
101 DialogEvent *de = static_cast<DialogEvent*>(event);
102 switch( de->i_dialog )
104 case INTF_DIALOG_FILE_SIMPLE:
105 case INTF_DIALOG_FILE:
107 case INTF_DIALOG_DISC:
108 openDiscDialog(); break;
109 case INTF_DIALOG_NET:
110 openNetDialog(); break;
111 case INTF_DIALOG_SAT:
112 case INTF_DIALOG_CAPTURE:
113 openCaptureDialog(); break;
114 case INTF_DIALOG_DIRECTORY:
115 PLAppendDir(); break;
116 case INTF_DIALOG_PLAYLIST:
117 playlistDialog(); break;
118 case INTF_DIALOG_MESSAGES:
119 messagesDialog(); break;
120 case INTF_DIALOG_FILEINFO:
121 mediaInfoDialog(); break;
122 case INTF_DIALOG_PREFS:
123 prefsDialog(); break;
124 case INTF_DIALOG_BOOKMARKS:
125 bookmarksDialog(); break;
126 case INTF_DIALOG_EXTENDED:
127 extendedDialog(); break;
129 case INTF_DIALOG_VLM:
132 case INTF_DIALOG_INTERACTION:
133 doInteraction( de->p_arg ); break;
134 case INTF_DIALOG_POPUPMENU:
135 QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0) ); break;
136 case INTF_DIALOG_AUDIOPOPUPMENU:
137 QVLCMenu::AudioPopupMenu( p_intf ); break;
138 case INTF_DIALOG_VIDEOPOPUPMENU:
139 QVLCMenu::VideoPopupMenu( p_intf ); break;
140 case INTF_DIALOG_MISCPOPUPMENU:
141 QVLCMenu::MiscPopupMenu( p_intf ); break;
142 case INTF_DIALOG_WIZARD:
143 case INTF_DIALOG_STREAMWIZARD:
144 openThenStreamingDialogs(); break;
146 case INTF_DIALOG_UPDATEVLC:
147 updateDialog(); break;
149 case INTF_DIALOG_EXIT:
152 msg_Warn( p_intf, "unimplemented dialog" );
157 /****************************************************************************
158 * Individual simple dialogs
159 ****************************************************************************/
160 void DialogsProvider::playlistDialog()
162 PlaylistDialog::getInstance( p_intf )->toggleVisible();
165 void DialogsProvider::prefsDialog()
167 PrefsDialog::getInstance( p_intf )->toggleVisible();
170 void DialogsProvider::extendedDialog()
172 ExtendedDialog::getInstance( p_intf )->toggleVisible();
175 void DialogsProvider::messagesDialog()
177 MessagesDialog::getInstance( p_intf )->toggleVisible();
180 void DialogsProvider::gotoTimeDialog()
182 GotoTimeDialog::getInstance( p_intf )->toggleVisible();
186 void DialogsProvider::vlmDialog()
188 VLMDialog::getInstance( p_intf )->toggleVisible();
192 void DialogsProvider::helpDialog()
194 HelpDialog::getInstance( p_intf )->toggleVisible();
198 void DialogsProvider::updateDialog()
200 UpdateDialog::getInstance( p_intf )->toggleVisible();
204 void DialogsProvider::aboutDialog()
206 AboutDialog::getInstance( p_intf )->toggleVisible();
209 void DialogsProvider::mediaInfoDialog()
211 MediaInfoDialog::getInstance( p_intf )->toggleVisible();
214 void DialogsProvider::mediaCodecDialog()
216 MediaInfoDialog::getInstance( p_intf )->showTab( 2 );
219 void DialogsProvider::bookmarksDialog()
221 BookmarksDialog::getInstance( p_intf )->toggleVisible();
224 void DialogsProvider::podcastConfigureDialog()
226 PodcastConfigDialog::getInstance( p_intf )->toggleVisible();
230 /****************************************************************************
231 * All the open/add stuff
232 * Open Dialog first - Simple Open then
233 ****************************************************************************/
235 void DialogsProvider::openDialog( int i_tab )
237 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
239 void DialogsProvider::openDialog()
241 openDialog( OPEN_FILE_TAB );
243 void DialogsProvider::openFileDialog()
245 openDialog( OPEN_FILE_TAB );
247 void DialogsProvider::openDiscDialog()
249 openDialog( OPEN_DISC_TAB );
251 void DialogsProvider::openNetDialog()
253 openDialog( OPEN_NETWORK_TAB );
255 void DialogsProvider::openCaptureDialog()
257 openDialog( OPEN_CAPTURE_TAB );
260 /* Same as the open one, but force the enqueue */
261 void DialogsProvider::PLAppendDialog()
263 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_ENQUEUE)
264 ->showTab( OPEN_FILE_TAB );
267 /* Unimplemmented yet - Usefull ? */
268 void DialogsProvider::MLAppendDialog()
273 * Not used anymore. Let the code until we are sure we don't want it
274 * Two opens make it confusing for the user.
276 QStringList DialogsProvider::showSimpleOpen( QString help,
280 QString fileTypes = "";
281 if( filters & EXT_FILTER_MEDIA ) {
282 ADD_FILTER_MEDIA( fileTypes );
284 if( filters & EXT_FILTER_VIDEO ) {
285 ADD_FILTER_VIDEO( fileTypes );
287 if( filters & EXT_FILTER_AUDIO ) {
288 ADD_FILTER_AUDIO( fileTypes );
290 if( filters & EXT_FILTER_PLAYLIST ) {
291 ADD_FILTER_PLAYLIST( fileTypes );
293 if( filters & EXT_FILTER_SUBTITLE ) {
294 ADD_FILTER_SUBTITLE( fileTypes );
296 ADD_FILTER_ALL( fileTypes );
297 fileTypes.replace(QString(";*"), QString(" *"));
298 return QFileDialog::getOpenFileNames( NULL,
299 help.isNull() ? qfu(I_OP_SEL_FILES ) : help,
300 path.isNull() ? qfu( p_intf->p_sys->psz_filepath ) : path,
306 * pl helps you to choose from playlist or media library,
307 * go to start or enqueue
309 void DialogsProvider::addFromSimple( bool pl, bool go)
311 QStringList files = DialogsProvider::showSimpleOpen();
313 foreach( QString file, files )
315 const char * psz_utf8 = qtu( file );
316 playlist_Add( THEPL, psz_utf8, NULL,
317 go ? ( PLAYLIST_APPEND | ( i ? 0 : PLAYLIST_GO ) |
318 ( i ? PLAYLIST_PREPARSE : 0 ) )
319 : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
321 pl ? true : false, false );
326 void DialogsProvider::simpleOpenDialog()
328 addFromSimple( true, true ); /* Playlist and Go */
331 void DialogsProvider::simplePLAppendDialog()
333 addFromSimple( true, false );
336 void DialogsProvider::simpleMLAppendDialog()
338 addFromSimple( false, false );
344 * pl helps you to choose from playlist or media library,
345 * go to start or enqueue
347 static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
349 QString dir = QFileDialog::getExistingDirectory( 0, qtr("Open Directory") );
350 if (!dir.isEmpty()) {
351 input_item_t *p_input = input_ItemNewExt( THEPL,
352 qtu( "directory://" + dir ), NULL,
355 /* FIXME: playlist_AddInput() can fail */
356 playlist_AddInput( THEPL, p_input,
357 go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
358 PLAYLIST_END, pl, pl_Unlocked );
359 input_Read( THEPL, p_input, false );
360 vlc_gc_decref( p_input );
364 void DialogsProvider::PLAppendDir()
366 openDirectory( p_intf, true, false );
369 void DialogsProvider::MLAppendDir()
371 openDirectory( p_intf, false , false );
377 void DialogsProvider::openAPlaylist()
379 QStringList files = showSimpleOpen( qtr( "Open playlist file" ),
380 EXT_FILTER_PLAYLIST );
381 foreach( QString file, files )
383 playlist_Import( THEPL, qtu(file) );
387 void DialogsProvider::saveAPlaylist()
389 QFileDialog *qfd = new QFileDialog( NULL,
390 qtr( "Choose a filename to save playlist" ),
391 qfu( p_intf->p_sys->psz_filepath ),
392 qtr( "XSPF playlist (*.xspf);; " ) +
393 qtr( "M3U playlist (*.m3u);; Any (*.*) " ) );
394 qfd->setFileMode( QFileDialog::AnyFile );
395 qfd->setAcceptMode( QFileDialog::AcceptSave );
396 qfd->setConfirmOverwrite( true );
398 if( qfd->exec() == QDialog::Accepted )
400 if( qfd->selectedFiles().count() > 0 )
402 static const char psz_xspf[] = "export-xspf",
403 psz_m3u[] = "export-m3u";
404 const char *psz_module;
406 QString file = qfd->selectedFiles().first();
407 QString filter = qfd->selectedFilter();
409 if( file.contains( ".xsp" ) ||
410 ( filter.contains( ".xspf" ) && !file.contains( ".m3u" ) ) )
412 psz_module = psz_xspf;
413 if( !file.contains( ".xsp" ) )
414 file.append( ".xspf" );
418 psz_module = psz_m3u;
419 if( !file.contains( ".m3u" ) )
420 file.append( ".m3u" );
423 playlist_Export( THEPL, qtu( file ), THEPL->p_local_category,
431 /****************************************************************************
433 ****************************************************************************/
435 void DialogsProvider::streamingDialog( QWidget *parent, QString mrl,
436 bool b_transcode_only )
438 SoutDialog *s = SoutDialog::getInstance( parent, p_intf, b_transcode_only );
440 if( s->exec() == QDialog::Accepted )
442 msg_Dbg( p_intf, "Sout mrl %s", qta( s->getMrl() ) );
444 int i_len = strlen( qtu( s->getMrl() ) ) + 10;
445 char *psz_option = (char*)malloc( i_len );
446 snprintf( psz_option, i_len - 1, "%s", qtu( s->getMrl() ) );
448 playlist_AddExt( THEPL, qtu( mrl ), "Streaming",
449 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
450 -1, &psz_option, 1, true, pl_Unlocked );
454 void DialogsProvider::openThenStreamingDialogs()
456 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_STREAM )
460 void DialogsProvider::openThenTranscodingDialogs()
462 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_SAVE )
466 /****************************************************************************
467 * Menus / Interaction
468 ****************************************************************************/
470 void DialogsProvider::menuAction( QObject *data )
472 QVLCMenu::DoAction( p_intf, data );
475 void DialogsProvider::menuUpdateAction( QObject *data )
477 MenuFunc * f = qobject_cast<MenuFunc *>(data);
481 void DialogsProvider::SDMenuAction( QString data )
483 char *psz_sd = strdup( qtu( data ) );
484 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
485 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
487 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
491 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
493 InteractionDialog *qdialog;
494 interaction_dialog_t *p_dialog = p_arg->p_dialog;
495 switch( p_dialog->i_action )
498 qdialog = new InteractionDialog( p_intf, p_dialog );
499 p_dialog->p_private = (void*)qdialog;
500 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
503 case INTERACT_UPDATE:
504 qdialog = (InteractionDialog*)(p_dialog->p_private);
509 /* The INTERACT_NEW message was forgotten
510 so we must create the dialog and update it*/
511 qdialog = new InteractionDialog( p_intf, p_dialog );
512 p_dialog->p_private = (void*)qdialog;
513 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
520 qdialog = (InteractionDialog*)(p_dialog->p_private);
523 p_dialog->i_status = HIDDEN_DIALOG;
525 case INTERACT_DESTROY:
526 qdialog = (InteractionDialog*)(p_dialog->p_private);
527 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
529 p_dialog->i_status = DESTROYED_DIALOG;
534 void DialogsProvider::loadSubtitlesFile()
536 input_thread_t *p_input = THEMIM->getInput();
539 QString qsFile = QFileDialog::getOpenFileName(
541 qtr( "Choose subtitles file" ),
543 qtr( "Subtitles files (*.cdg *.idx *.srt *.sub *.utf);;"
545 if( !input_AddSubtitles( p_input, qtu( qsFile ), true ) )
546 msg_Warn( p_intf, "unable to load subtitles file..." );