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:
130 openThenStreamingDialogs(); break;
132 case INTF_DIALOG_UPDATEVLC:
133 updateDialog(); break;
135 case INTF_DIALOG_EXIT:
138 msg_Warn( p_intf, "unimplemented dialog" );
143 /****************************************************************************
144 * Individual simple dialogs
145 ****************************************************************************/
146 void DialogsProvider::playlistDialog()
148 PlaylistDialog::getInstance( p_intf )->toggleVisible();
151 void DialogsProvider::prefsDialog()
153 PrefsDialog::getInstance( p_intf )->toggleVisible();
156 void DialogsProvider::extendedDialog()
158 ExtendedDialog::getInstance( p_intf )->toggleVisible();
161 void DialogsProvider::messagesDialog()
163 MessagesDialog::getInstance( p_intf )->toggleVisible();
166 void DialogsProvider::gotoTimeDialog()
168 GotoTimeDialog::getInstance( p_intf )->toggleVisible();
171 void DialogsProvider::vlmDialog()
173 VLMDialog::getInstance( p_intf )->toggleVisible();
176 void DialogsProvider::helpDialog()
178 HelpDialog::getInstance( p_intf )->toggleVisible();
182 void DialogsProvider::updateDialog()
184 UpdateDialog::getInstance( p_intf )->toggleVisible();
188 void DialogsProvider::aboutDialog()
190 AboutDialog::getInstance( p_intf )->toggleVisible();
193 void DialogsProvider::mediaInfoDialog()
195 MediaInfoDialog::getInstance( p_intf )->toggleVisible();
198 void DialogsProvider::mediaCodecDialog()
200 MediaInfoDialog::getInstance( p_intf )->showTab( 2 );
203 void DialogsProvider::bookmarksDialog()
205 /* TODO - Implement me */
206 /* BookmarkDialog::getInstance( p_intf )->toggleVisible(); */
209 void DialogsProvider::podcastConfigureDialog()
211 PodcastConfigDialog::getInstance( p_intf )->toggleVisible();
215 /****************************************************************************
216 * All the open/add stuff
217 * Open Dialog first - Simple Open then
218 ****************************************************************************/
220 void DialogsProvider::openDialog( int i_tab )
222 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
224 void DialogsProvider::openDialog()
226 openDialog( OPEN_FILE_TAB );
228 void DialogsProvider::openFileDialog()
230 openDialog( OPEN_FILE_TAB );
232 void DialogsProvider::openDiscDialog()
234 openDialog( OPEN_DISC_TAB );
236 void DialogsProvider::openNetDialog()
238 openDialog( OPEN_NETWORK_TAB );
240 void DialogsProvider::openCaptureDialog()
242 openDialog( OPEN_CAPTURE_TAB );
245 /* Same as the open one, but force the enqueue */
246 void DialogsProvider::PLAppendDialog()
248 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_ENQUEUE)
249 ->showTab( OPEN_FILE_TAB );
252 /* Unimplemmented yet - Usefull ? */
253 void DialogsProvider::MLAppendDialog()
258 * Not used anymore. Let the code until we are sure we don't want it
259 * Two opens make it confusing for the user.
261 QStringList DialogsProvider::showSimpleOpen( QString help,
265 QString fileTypes = "";
266 if( filters & EXT_FILTER_MEDIA ) {
267 ADD_FILTER_MEDIA( fileTypes );
269 if( filters & EXT_FILTER_VIDEO ) {
270 ADD_FILTER_VIDEO( fileTypes );
272 if( filters & EXT_FILTER_AUDIO ) {
273 ADD_FILTER_AUDIO( fileTypes );
275 if( filters & EXT_FILTER_PLAYLIST ) {
276 ADD_FILTER_PLAYLIST( fileTypes );
278 if( filters & EXT_FILTER_SUBTITLE ) {
279 ADD_FILTER_SUBTITLE( fileTypes );
281 ADD_FILTER_ALL( fileTypes );
282 fileTypes.replace(QString(";*"), QString(" *"));
283 return QFileDialog::getOpenFileNames( NULL,
284 help.isNull() ? qfu(I_OP_SEL_FILES ) : help,
285 path.isNull() ? qfu( p_intf->p_libvlc->psz_homedir ) : path,
291 * pl helps you to choose from playlist or media library,
292 * go to start or enqueue
294 void DialogsProvider::addFromSimple( bool pl, bool go)
296 QStringList files = DialogsProvider::showSimpleOpen();
298 foreach( QString file, files )
300 const char * psz_utf8 = qtu( file );
301 playlist_Add( THEPL, psz_utf8, NULL,
302 go ? ( PLAYLIST_APPEND | ( i ? 0 : PLAYLIST_GO ) |
303 ( i ? PLAYLIST_PREPARSE : 0 ) )
304 : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
306 pl ? VLC_TRUE : VLC_FALSE, VLC_FALSE );
311 void DialogsProvider::simpleOpenDialog()
313 addFromSimple( true, true ); /* Playlist and Go */
316 void DialogsProvider::simplePLAppendDialog()
318 addFromSimple( true, false );
321 void DialogsProvider::simpleMLAppendDialog()
323 addFromSimple( false, false );
329 * pl helps you to choose from playlist or media library,
330 * go to start or enqueue
332 static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
334 QString dir = QFileDialog::getExistingDirectory( 0, qtr(I_OP_OPDIR) );
335 if (!dir.isEmpty()) {
336 input_item_t *p_input = input_ItemNewExt( THEPL,
337 qtu( "directory://" + dir ), NULL,
340 playlist_AddInput( THEPL, p_input,
341 go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
342 PLAYLIST_END, pl, VLC_FALSE );
343 input_Read( THEPL, p_input, VLC_FALSE );
347 void DialogsProvider::PLAppendDir()
349 openDirectory( p_intf, true, false );
352 void DialogsProvider::MLAppendDir()
354 openDirectory( p_intf, false , false );
360 void DialogsProvider::openAPlaylist()
362 QStringList files = showSimpleOpen( qtr( "Open playlist file" ),
363 EXT_FILTER_PLAYLIST );
364 foreach( QString file, files )
366 playlist_Import( THEPL, qtu(file) );
370 void DialogsProvider::saveAPlaylist()
372 QFileDialog *qfd = new QFileDialog( NULL,
373 qtr( "Choose a filename to save playlist" ),
374 qfu( p_intf->p_libvlc->psz_homedir ),
375 qtr( "XSPF playlist (*.xspf);; " ) +
376 qtr( "M3U playlist (*.m3u);; Any (*.*) " ) );
377 qfd->setFileMode( QFileDialog::AnyFile );
378 qfd->setAcceptMode( QFileDialog::AcceptSave );
379 qfd->setConfirmOverwrite( true );
381 if( qfd->exec() == QDialog::Accepted )
383 if( qfd->selectedFiles().count() > 0 )
385 static const char psz_xspf[] = "export-xspf",
386 psz_m3u[] = "export-m3u";
387 const char *psz_module;
389 QString file = qfd->selectedFiles().first();
390 QString filter = qfd->selectedFilter();
392 if( file.contains( ".xsp" ) ||
393 ( filter.contains( ".xspf" ) && !file.contains( ".m3u" ) ) )
395 psz_module = psz_xspf;
396 if( !file.contains( ".xsp" ) )
397 file.append( ".xspf" );
401 psz_module = psz_m3u;
402 if( !file.contains( ".m3u" ) )
403 file.append( ".m3u" );
406 playlist_Export( THEPL, qtu( file ), THEPL->p_local_category,
414 /****************************************************************************
416 ****************************************************************************/
418 void DialogsProvider::streamingDialog( QWidget *parent, QString mrl,
419 bool b_transcode_only )
421 SoutDialog *s = SoutDialog::getInstance( parent, p_intf, b_transcode_only );
423 if( s->exec() == QDialog::Accepted )
425 msg_Err( p_intf, "Sout mrl %s", qta( s->getMrl() ) );
427 int i_len = strlen( qtu( s->getMrl() ) ) + 10;
428 char *psz_option = (char*)malloc( i_len );
429 snprintf( psz_option, i_len - 1, "%s", qtu( s->getMrl() ) );
431 playlist_AddExt( THEPL, qtu( mrl ), "Streaming",
432 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
433 -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 /****************************************************************************
450 * Menus / Interaction
451 ****************************************************************************/
453 void DialogsProvider::menuAction( QObject *data )
455 QVLCMenu::DoAction( p_intf, data );
458 void DialogsProvider::menuUpdateAction( QObject *data )
460 MenuFunc * f = qobject_cast<MenuFunc *>(data);
464 void DialogsProvider::SDMenuAction( QString data )
466 char *psz_sd = strdup( qtu( data ) );
467 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
468 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
470 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
474 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
476 InteractionDialog *qdialog;
477 interaction_dialog_t *p_dialog = p_arg->p_dialog;
478 switch( p_dialog->i_action )
481 qdialog = new InteractionDialog( p_intf, p_dialog );
482 p_dialog->p_private = (void*)qdialog;
483 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
486 case INTERACT_UPDATE:
487 qdialog = (InteractionDialog*)(p_dialog->p_private);
492 qdialog = (InteractionDialog*)(p_dialog->p_private);
495 p_dialog->i_status = HIDDEN_DIALOG;
497 case INTERACT_DESTROY:
498 qdialog = (InteractionDialog*)(p_dialog->p_private);
499 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
501 p_dialog->i_status = DESTROYED_DIALOG;
506 void DialogsProvider::switchToSkins()
508 var_SetString( p_intf, "intf-switch", "skins2" );