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>
31 #include "dialogs_provider.hpp"
32 #include "main_interface.hpp"
34 #include <vlc_intf_strings.h>
37 #include "dialogs/playlist.hpp"
38 #include "dialogs/preferences.hpp"
39 #include "dialogs/mediainfo.hpp"
40 #include "dialogs/messages.hpp"
41 #include "dialogs/extended.hpp"
42 #include "dialogs/sout.hpp"
43 #include "dialogs/open.hpp"
44 #include "dialogs/vlm.hpp"
45 #include "dialogs/help.hpp"
46 #include "dialogs/gototime.hpp"
47 #include "dialogs/podcast_configuration.hpp"
50 DialogsProvider* DialogsProvider::instance = NULL;
52 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
53 QObject( NULL ), p_intf( _p_intf )
55 fixed_timer = new QTimer( this );
56 fixed_timer->start( 150 /* milliseconds */ );
58 menusMapper = new QSignalMapper();
59 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
61 menusUpdateMapper = new QSignalMapper();
62 CONNECT( menusUpdateMapper, mapped(QObject *),
63 this, menuUpdateAction( QObject *) );
65 SDMapper = new QSignalMapper();
66 CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
69 DialogsProvider::~DialogsProvider()
71 PlaylistDialog::killInstance();
72 MediaInfoDialog::killInstance();
75 void DialogsProvider::quit()
77 vlc_object_kill( p_intf );
81 void DialogsProvider::customEvent( QEvent *event )
83 if( event->type() == DialogEvent_Type )
85 DialogEvent *de = static_cast<DialogEvent*>(event);
86 switch( de->i_dialog )
88 case INTF_DIALOG_FILE_SIMPLE:
89 case INTF_DIALOG_FILE:
91 case INTF_DIALOG_DISC:
92 openDiscDialog(); break;
94 openNetDialog(); break;
96 case INTF_DIALOG_CAPTURE:
97 openCaptureDialog(); break;
98 case INTF_DIALOG_DIRECTORY:
100 case INTF_DIALOG_PLAYLIST:
101 playlistDialog(); break;
102 case INTF_DIALOG_MESSAGES:
103 messagesDialog(); break;
104 case INTF_DIALOG_FILEINFO:
105 mediaInfoDialog(); break;
106 case INTF_DIALOG_PREFS:
107 prefsDialog(); break;
108 case INTF_DIALOG_BOOKMARKS:
109 bookmarksDialog(); break;
110 case INTF_DIALOG_EXTENDED:
111 extendedDialog(); break;
112 /* We might want to make it better with custom functions */
113 case INTF_DIALOG_POPUPMENU:
114 QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0) ); break;
115 case INTF_DIALOG_AUDIOPOPUPMENU:
116 QVLCMenu::AudioPopupMenu( p_intf ); break;
117 case INTF_DIALOG_VIDEOPOPUPMENU:
118 QVLCMenu::VideoPopupMenu( p_intf ); break;
119 case INTF_DIALOG_MISCPOPUPMENU:
120 QVLCMenu::MiscPopupMenu( p_intf ); break;
121 case INTF_DIALOG_INTERACTION:
122 doInteraction( de->p_arg ); break;
123 case INTF_DIALOG_VLM:
125 case INTF_DIALOG_WIZARD:
126 case INTF_DIALOG_STREAMWIZARD:
127 case INTF_DIALOG_UPDATEVLC:
128 case INTF_DIALOG_EXIT:
130 msg_Warn( p_intf, "unimplemented dialog\n" );
135 /****************************************************************************
136 * Individual simple dialogs
137 ****************************************************************************/
138 void DialogsProvider::playlistDialog()
140 PlaylistDialog::getInstance( p_intf )->toggleVisible();
143 void DialogsProvider::prefsDialog()
145 PrefsDialog::getInstance( p_intf )->toggleVisible();
147 void DialogsProvider::extendedDialog()
149 ExtendedDialog::getInstance( p_intf )->toggleVisible();
152 void DialogsProvider::messagesDialog()
154 MessagesDialog::getInstance( p_intf )->toggleVisible();
157 void DialogsProvider::gotoTimeDialog()
159 GotoTimeDialog::getInstance( p_intf )->toggleVisible();
162 void DialogsProvider::vlmDialog()
164 VLMDialog::getInstance( p_intf )->toggleVisible();
167 void DialogsProvider::helpDialog()
169 HelpDialog::getInstance( p_intf )->toggleVisible();
172 void DialogsProvider::aboutDialog()
174 AboutDialog::getInstance( p_intf )->toggleVisible();
177 void DialogsProvider::mediaInfoDialog()
179 MediaInfoDialog::getInstance( p_intf )->toggleVisible();
182 void DialogsProvider::mediaCodecDialog()
184 MediaInfoDialog::getInstance( p_intf )->showTab( 2 );
187 void DialogsProvider::bookmarksDialog()
189 /* FIXME - Implement me */
190 /* BookmarkDialog::getInstance( p_intf )->toggleVisible(); */
193 /****************************************************************************
194 * All the open/add stuff
195 * Open Dialog first - Simple Open then
196 ****************************************************************************/
198 void DialogsProvider::openDialog( int i_tab )
200 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
202 void DialogsProvider::openDialog()
204 openDialog( OPEN_FILE_TAB );
206 void DialogsProvider::openFileDialog()
208 openDialog( OPEN_FILE_TAB );
210 void DialogsProvider::openDiscDialog()
212 openDialog( OPEN_DISC_TAB );
214 void DialogsProvider::openNetDialog()
216 openDialog( OPEN_NETWORK_TAB );
218 void DialogsProvider::openCaptureDialog()
220 openDialog( OPEN_CAPTURE_TAB );
223 /* Same as the open one, but force the enqueue */
224 void DialogsProvider::PLAppendDialog()
226 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, ENQUEUE)->showTab(0);
229 /* Unimplemmented yet - Usefull ? */
230 void DialogsProvider::MLAppendDialog()
236 * Not used anymore. Let the code until we are sure we don't want it
237 * Two opens make it confusing for the user.
239 QStringList DialogsProvider::showSimpleOpen( QString help,
243 QString fileTypes = "";
244 if( filters & EXT_FILTER_MEDIA ) {
245 ADD_FILTER_MEDIA( fileTypes );
247 if( filters & EXT_FILTER_VIDEO ) {
248 ADD_FILTER_VIDEO( fileTypes );
250 if( filters & EXT_FILTER_AUDIO ) {
251 ADD_FILTER_AUDIO( fileTypes );
253 if( filters & EXT_FILTER_PLAYLIST ) {
254 ADD_FILTER_PLAYLIST( fileTypes );
256 if( filters & EXT_FILTER_SUBTITLE ) {
257 ADD_FILTER_SUBTITLE( fileTypes );
259 ADD_FILTER_ALL( fileTypes );
260 fileTypes.replace(QString(";*"), QString(" *"));
261 return QFileDialog::getOpenFileNames( NULL,
262 help.isNull() ? qfu(I_OP_SEL_FILES ) : help,
263 path.isNull() ? qfu( p_intf->p_libvlc->psz_homedir ) : path,
267 void DialogsProvider::addFromSimple( bool pl, bool go)
269 QStringList files = DialogsProvider::showSimpleOpen();
271 foreach( QString file, files )
273 const char * psz_utf8 = qtu( file );
274 playlist_Add( THEPL, psz_utf8, NULL,
275 go ? ( PLAYLIST_APPEND | ( i ? 0 : PLAYLIST_GO ) |
276 ( i ? PLAYLIST_PREPARSE : 0 ) )
277 : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
279 pl ? VLC_TRUE : VLC_FALSE, VLC_FALSE );
284 void DialogsProvider::simplePLAppendDialog()
286 addFromSimple( true, false );
289 void DialogsProvider::simpleMLAppendDialog()
291 addFromSimple( false, false );
294 void DialogsProvider::simpleOpenDialog()
296 addFromSimple( true, true );
303 * pl helps you to choose from playlist or media library,
304 * go to start or enqueue
306 static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
308 QString dir = QFileDialog::getExistingDirectory ( 0, qtr("Open directory") );
309 if (!dir.isEmpty()) {
310 input_item_t *p_input = input_ItemNewExt( THEPL, qtu(dir), NULL,
313 playlist_AddInput( THEPL, p_input,
314 go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
315 PLAYLIST_END, pl, VLC_FALSE );
316 input_Read( THEPL, p_input, VLC_FALSE );
320 void DialogsProvider::PLAppendDir()
322 openDirectory( p_intf, true, false );
325 void DialogsProvider::MLAppendDir()
327 openDirectory( p_intf, false , false );
333 void DialogsProvider::openPlaylist()
335 QStringList files = showSimpleOpen( qtr( "Open playlist file" ),
336 EXT_FILTER_PLAYLIST );
337 foreach( QString file, files )
339 playlist_Import( THEPL, qtu(file) );
343 void DialogsProvider::savePlaylist()
345 QFileDialog *qfd = new QFileDialog( NULL,
346 qtr("Choose a filename to save playlist"),
347 qfu( p_intf->p_libvlc->psz_homedir ),
348 qtr("XSPF playlist (*.xspf);; ") +
349 qtr("M3U playlist (*.m3u);; Any (*.*) ") );
350 qfd->setFileMode( QFileDialog::AnyFile );
351 qfd->setAcceptMode( QFileDialog::AcceptSave );
352 qfd->setConfirmOverwrite( true );
354 if( qfd->exec() == QDialog::Accepted )
356 if( qfd->selectedFiles().count() > 0 )
358 static const char psz_xspf[] = "export-xspf",
359 psz_m3u[] = "esport-m3u";
360 const char *psz_module;
362 QString file = qfd->selectedFiles().first();
363 QString filter = qfd->selectedFilter();
365 if( file.contains(".xsp") ||
366 ( filter.contains(".xspf") && !file.contains(".m3u") ) )
368 psz_module = psz_xspf;
369 if( !file.contains( ".xsp" ) )
370 file.append( ".xspf" );
374 psz_module = psz_m3u;
375 if( !file.contains( ".m3u" ) )
376 file.append( ".m3u" );
379 playlist_Export( THEPL, qtu(file), THEPL->p_local_category,
387 /****************************************************************************
389 ****************************************************************************/
392 void DialogsProvider::streamingDialog( QString mrl, bool b_transcode_only )
394 SoutDialog *s = new SoutDialog( p_intf->p_sys->p_mi, p_intf,
396 if( s->exec() == QDialog::Accepted )
398 msg_Err( p_intf, "mrl %s\n", qta( s->getMrl() ) );
400 int i_len = strlen( qtu( s->getMrl() ) ) + 10;
401 char *psz_option = (char*)malloc(i_len);
402 snprintf( psz_option, i_len - 1, "%s", qtu( s->getMrl() ) );
404 playlist_AddExt( THEPL, qtu( mrl ), "Streaming",
405 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
406 -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
411 void DialogsProvider::openThenStreamingDialogs()
413 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_STREAM )
417 void DialogsProvider::openThenTranscodingDialogs()
419 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_SAVE )
423 void DialogsProvider::streamingDialog()
425 OpenDialog *o = new OpenDialog( p_intf->p_sys->p_mi, p_intf, true );
426 if ( o->exec() == QDialog::Accepted )
428 SoutDialog *s = new SoutDialog( p_intf->p_sys->p_mi, p_intf );
429 if( s->exec() == QDialog::Accepted )
431 msg_Err(p_intf, "mrl %s\n", qta(s->mrl));
433 int i_len = strlen( qtu(s->mrl) ) + 10;
434 char *psz_option = (char*)malloc(i_len);
435 snprintf( psz_option, i_len - 1, ":sout=%s", qtu(s->mrl));
437 playlist_AddExt( THEPL, qtu( o->mrl ), "Streaming",
438 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
439 -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
448 /****************************************************************************
449 * Menus / Interaction
450 ****************************************************************************/
452 void DialogsProvider::menuAction( QObject *data )
454 QVLCMenu::DoAction( p_intf, data );
457 void DialogsProvider::menuUpdateAction( QObject *data )
459 MenuFunc * f = qobject_cast<MenuFunc *>(data);
463 void DialogsProvider::SDMenuAction( QString data )
465 char *psz_sd = strdup( qtu( data ) );
466 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
467 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
469 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
473 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
475 InteractionDialog *qdialog;
476 interaction_dialog_t *p_dialog = p_arg->p_dialog;
477 switch( p_dialog->i_action )
480 qdialog = new InteractionDialog( p_intf, p_dialog );
481 p_dialog->p_private = (void*)qdialog;
482 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
485 case INTERACT_UPDATE:
486 qdialog = (InteractionDialog*)(p_dialog->p_private);
491 qdialog = (InteractionDialog*)(p_dialog->p_private);
494 p_dialog->i_status = HIDDEN_DIALOG;
496 case INTERACT_DESTROY:
497 qdialog = (InteractionDialog*)(p_dialog->p_private);
498 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
500 p_dialog->i_status = DESTROYED_DIALOG;
505 void DialogsProvider::podcastConfigureDialog()
507 PodcastConfigurationDialog c( p_intf );
511 void DialogsProvider::switchToSkins()
513 var_SetString( p_intf, "intf-switch", "skins2" );