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>
35 #include "dialogs_provider.hpp"
36 #include "main_interface.hpp"
38 #include <vlc_intf_strings.h>
41 #include "dialogs/playlist.hpp"
42 #include "dialogs/bookmarks.hpp"
43 #include "dialogs/preferences.hpp"
44 #include "dialogs/mediainfo.hpp"
45 #include "dialogs/messages.hpp"
46 #include "dialogs/extended.hpp"
47 #include "dialogs/vlm.hpp"
48 #include "dialogs/sout.hpp"
49 #include "dialogs/open.hpp"
50 #include "dialogs/help.hpp"
51 #include "dialogs/gototime.hpp"
52 #include "dialogs/podcast_configuration.hpp"
54 DialogsProvider* DialogsProvider::instance = NULL;
56 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
57 QObject( NULL ), p_intf( _p_intf )
59 fixed_timer = new QTimer( this );
60 fixed_timer->start( 150 /* milliseconds */ );
62 menusMapper = new QSignalMapper();
63 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
65 menusUpdateMapper = new QSignalMapper();
66 CONNECT( menusUpdateMapper, mapped(QObject *),
67 this, menuUpdateAction( QObject *) );
69 SDMapper = new QSignalMapper();
70 CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
73 DialogsProvider::~DialogsProvider()
75 msg_Dbg( p_intf, "Destroying the Dialog Provider" );
76 PlaylistDialog::killInstance();
77 MediaInfoDialog::killInstance();
78 MessagesDialog::killInstance();
82 void DialogsProvider::quit()
84 vlc_object_kill( p_intf );
85 QApplication::closeAllWindows();
89 void DialogsProvider::customEvent( QEvent *event )
91 if( event->type() == DialogEvent_Type )
93 DialogEvent *de = static_cast<DialogEvent*>(event);
94 switch( de->i_dialog )
96 case INTF_DIALOG_FILE_SIMPLE:
97 case INTF_DIALOG_FILE:
99 case INTF_DIALOG_DISC:
100 openDiscDialog(); break;
101 case INTF_DIALOG_NET:
102 openNetDialog(); break;
103 case INTF_DIALOG_SAT:
104 case INTF_DIALOG_CAPTURE:
105 openCaptureDialog(); break;
106 case INTF_DIALOG_DIRECTORY:
107 PLAppendDir(); break;
108 case INTF_DIALOG_PLAYLIST:
109 playlistDialog(); break;
110 case INTF_DIALOG_MESSAGES:
111 messagesDialog(); break;
112 case INTF_DIALOG_FILEINFO:
113 mediaInfoDialog(); break;
114 case INTF_DIALOG_PREFS:
115 prefsDialog(); break;
116 case INTF_DIALOG_BOOKMARKS:
117 bookmarksDialog(); break;
118 case INTF_DIALOG_EXTENDED:
119 extendedDialog(); break;
121 case INTF_DIALOG_VLM:
124 case INTF_DIALOG_INTERACTION:
125 doInteraction( de->p_arg ); break;
126 case INTF_DIALOG_POPUPMENU:
127 QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0) ); break;
128 case INTF_DIALOG_AUDIOPOPUPMENU:
129 QVLCMenu::AudioPopupMenu( p_intf ); break;
130 case INTF_DIALOG_VIDEOPOPUPMENU:
131 QVLCMenu::VideoPopupMenu( p_intf ); break;
132 case INTF_DIALOG_MISCPOPUPMENU:
133 QVLCMenu::MiscPopupMenu( p_intf ); break;
134 case INTF_DIALOG_WIZARD:
135 case INTF_DIALOG_STREAMWIZARD:
136 openThenStreamingDialogs(); break;
138 case INTF_DIALOG_UPDATEVLC:
139 updateDialog(); break;
141 case INTF_DIALOG_EXIT:
144 msg_Warn( p_intf, "unimplemented dialog" );
149 /****************************************************************************
150 * Individual simple dialogs
151 ****************************************************************************/
152 void DialogsProvider::playlistDialog()
154 PlaylistDialog::getInstance( p_intf )->toggleVisible();
157 void DialogsProvider::prefsDialog()
159 PrefsDialog::getInstance( p_intf )->toggleVisible();
162 void DialogsProvider::extendedDialog()
164 ExtendedDialog::getInstance( p_intf )->toggleVisible();
167 void DialogsProvider::messagesDialog()
169 MessagesDialog::getInstance( p_intf )->toggleVisible();
172 void DialogsProvider::gotoTimeDialog()
174 GotoTimeDialog::getInstance( p_intf )->toggleVisible();
178 void DialogsProvider::vlmDialog()
180 VLMDialog::getInstance( p_intf )->toggleVisible();
184 void DialogsProvider::helpDialog()
186 HelpDialog::getInstance( p_intf )->toggleVisible();
190 void DialogsProvider::updateDialog()
192 UpdateDialog::getInstance( p_intf )->toggleVisible();
196 void DialogsProvider::aboutDialog()
198 AboutDialog::getInstance( p_intf )->toggleVisible();
201 void DialogsProvider::mediaInfoDialog()
203 MediaInfoDialog::getInstance( p_intf )->toggleVisible();
206 void DialogsProvider::mediaCodecDialog()
208 MediaInfoDialog::getInstance( p_intf )->showTab( 2 );
211 void DialogsProvider::bookmarksDialog()
213 BookmarksDialog::getInstance( p_intf )->toggleVisible();
216 void DialogsProvider::podcastConfigureDialog()
218 PodcastConfigDialog::getInstance( p_intf )->toggleVisible();
222 /****************************************************************************
223 * All the open/add stuff
224 * Open Dialog first - Simple Open then
225 ****************************************************************************/
227 void DialogsProvider::openDialog( int i_tab )
229 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
231 void DialogsProvider::openDialog()
233 openDialog( OPEN_FILE_TAB );
235 void DialogsProvider::openFileDialog()
237 openDialog( OPEN_FILE_TAB );
239 void DialogsProvider::openDiscDialog()
241 openDialog( OPEN_DISC_TAB );
243 void DialogsProvider::openNetDialog()
245 openDialog( OPEN_NETWORK_TAB );
247 void DialogsProvider::openCaptureDialog()
249 openDialog( OPEN_CAPTURE_TAB );
252 /* Same as the open one, but force the enqueue */
253 void DialogsProvider::PLAppendDialog()
255 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_ENQUEUE)
256 ->showTab( OPEN_FILE_TAB );
259 /* Unimplemmented yet - Usefull ? */
260 void DialogsProvider::MLAppendDialog()
265 * Not used anymore. Let the code until we are sure we don't want it
266 * Two opens make it confusing for the user.
268 QStringList DialogsProvider::showSimpleOpen( QString help,
272 QString fileTypes = "";
273 if( filters & EXT_FILTER_MEDIA ) {
274 ADD_FILTER_MEDIA( fileTypes );
276 if( filters & EXT_FILTER_VIDEO ) {
277 ADD_FILTER_VIDEO( fileTypes );
279 if( filters & EXT_FILTER_AUDIO ) {
280 ADD_FILTER_AUDIO( fileTypes );
282 if( filters & EXT_FILTER_PLAYLIST ) {
283 ADD_FILTER_PLAYLIST( fileTypes );
285 if( filters & EXT_FILTER_SUBTITLE ) {
286 ADD_FILTER_SUBTITLE( fileTypes );
288 ADD_FILTER_ALL( fileTypes );
289 fileTypes.replace(QString(";*"), QString(" *"));
290 return QFileDialog::getOpenFileNames( NULL,
291 help.isNull() ? qfu(I_OP_SEL_FILES ) : help,
292 path.isNull() ? qfu( p_intf->p_sys->psz_filepath ) : path,
298 * pl helps you to choose from playlist or media library,
299 * go to start or enqueue
301 void DialogsProvider::addFromSimple( bool pl, bool go)
303 QStringList files = DialogsProvider::showSimpleOpen();
305 foreach( QString file, files )
307 const char * psz_utf8 = qtu( file );
308 playlist_Add( THEPL, psz_utf8, NULL,
309 go ? ( PLAYLIST_APPEND | ( i ? 0 : PLAYLIST_GO ) |
310 ( i ? PLAYLIST_PREPARSE : 0 ) )
311 : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
313 pl ? VLC_TRUE : VLC_FALSE, VLC_FALSE );
318 void DialogsProvider::simpleOpenDialog()
320 addFromSimple( true, true ); /* Playlist and Go */
323 void DialogsProvider::simplePLAppendDialog()
325 addFromSimple( true, false );
328 void DialogsProvider::simpleMLAppendDialog()
330 addFromSimple( false, false );
336 * pl helps you to choose from playlist or media library,
337 * go to start or enqueue
339 static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
341 QString dir = QFileDialog::getExistingDirectory( 0, qtr(I_OP_OPDIR) );
342 if (!dir.isEmpty()) {
343 input_item_t *p_input = input_ItemNewExt( THEPL,
344 qtu( "directory://" + dir ), NULL,
347 playlist_AddInput( THEPL, p_input,
348 go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
349 PLAYLIST_END, pl, VLC_FALSE );
350 input_Read( THEPL, p_input, VLC_FALSE );
354 void DialogsProvider::PLAppendDir()
356 openDirectory( p_intf, true, false );
359 void DialogsProvider::MLAppendDir()
361 openDirectory( p_intf, false , false );
367 void DialogsProvider::openAPlaylist()
369 QStringList files = showSimpleOpen( qtr( "Open playlist file" ),
370 EXT_FILTER_PLAYLIST );
371 foreach( QString file, files )
373 playlist_Import( THEPL, qtu(file) );
377 void DialogsProvider::saveAPlaylist()
379 QFileDialog *qfd = new QFileDialog( NULL,
380 qtr( "Choose a filename to save playlist" ),
381 qfu( p_intf->p_sys->psz_filepath ),
382 qtr( "XSPF playlist (*.xspf);; " ) +
383 qtr( "M3U playlist (*.m3u);; Any (*.*) " ) );
384 qfd->setFileMode( QFileDialog::AnyFile );
385 qfd->setAcceptMode( QFileDialog::AcceptSave );
386 qfd->setConfirmOverwrite( true );
388 if( qfd->exec() == QDialog::Accepted )
390 if( qfd->selectedFiles().count() > 0 )
392 static const char psz_xspf[] = "export-xspf",
393 psz_m3u[] = "export-m3u";
394 const char *psz_module;
396 QString file = qfd->selectedFiles().first();
397 QString filter = qfd->selectedFilter();
399 if( file.contains( ".xsp" ) ||
400 ( filter.contains( ".xspf" ) && !file.contains( ".m3u" ) ) )
402 psz_module = psz_xspf;
403 if( !file.contains( ".xsp" ) )
404 file.append( ".xspf" );
408 psz_module = psz_m3u;
409 if( !file.contains( ".m3u" ) )
410 file.append( ".m3u" );
413 playlist_Export( THEPL, qtu( file ), THEPL->p_local_category,
421 /****************************************************************************
423 ****************************************************************************/
425 void DialogsProvider::streamingDialog( QWidget *parent, QString mrl,
426 bool b_transcode_only )
428 SoutDialog *s = SoutDialog::getInstance( parent, p_intf, b_transcode_only );
430 if( s->exec() == QDialog::Accepted )
432 msg_Err( p_intf, "Sout mrl %s", qta( s->getMrl() ) );
434 int i_len = strlen( qtu( s->getMrl() ) ) + 10;
435 char *psz_option = (char*)malloc( i_len );
436 snprintf( psz_option, i_len - 1, "%s", qtu( s->getMrl() ) );
438 playlist_AddExt( THEPL, qtu( mrl ), "Streaming",
439 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
440 -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
444 void DialogsProvider::openThenStreamingDialogs()
446 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_STREAM )
450 void DialogsProvider::openThenTranscodingDialogs()
452 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_SAVE )
456 /****************************************************************************
457 * Menus / Interaction
458 ****************************************************************************/
460 void DialogsProvider::menuAction( QObject *data )
462 QVLCMenu::DoAction( p_intf, data );
465 void DialogsProvider::menuUpdateAction( QObject *data )
467 MenuFunc * f = qobject_cast<MenuFunc *>(data);
471 void DialogsProvider::SDMenuAction( QString data )
473 char *psz_sd = strdup( qtu( data ) );
474 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
475 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
477 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
481 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
483 InteractionDialog *qdialog;
484 interaction_dialog_t *p_dialog = p_arg->p_dialog;
485 switch( p_dialog->i_action )
488 qdialog = new InteractionDialog( p_intf, p_dialog );
489 p_dialog->p_private = (void*)qdialog;
490 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
493 case INTERACT_UPDATE:
494 qdialog = (InteractionDialog*)(p_dialog->p_private);
499 qdialog = (InteractionDialog*)(p_dialog->p_private);
502 p_dialog->i_status = HIDDEN_DIALOG;
504 case INTERACT_DESTROY:
505 qdialog = (InteractionDialog*)(p_dialog->p_private);
506 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
508 p_dialog->i_status = DESTROYED_DIALOG;
513 void DialogsProvider::switchToSkins()
515 var_SetString( p_intf, "intf-switch", "skins2" );
518 void DialogsProvider::switchToWx()
520 var_SetString( p_intf, "intf-switch", "wxwidgets" );