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/help.hpp"
45 #include "dialogs/gototime.hpp"
46 #include "dialogs/podcast_configuration.hpp"
48 DialogsProvider* DialogsProvider::instance = NULL;
50 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
51 QObject( NULL ), p_intf( _p_intf )
53 fixed_timer = new QTimer( this );
54 fixed_timer->start( 150 /* milliseconds */ );
56 menusMapper = new QSignalMapper();
57 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
59 menusUpdateMapper = new QSignalMapper();
60 CONNECT( menusUpdateMapper, mapped(QObject *),
61 this, menuUpdateAction( QObject *) );
63 SDMapper = new QSignalMapper();
64 CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
67 DialogsProvider::~DialogsProvider()
69 PlaylistDialog::killInstance();
70 MediaInfoDialog::killInstance();
73 void DialogsProvider::quit()
75 vlc_object_kill( p_intf );
79 void DialogsProvider::customEvent( QEvent *event )
81 if( event->type() == DialogEvent_Type )
83 DialogEvent *de = static_cast<DialogEvent*>(event);
84 switch( de->i_dialog )
86 case INTF_DIALOG_FILE_SIMPLE:
87 case INTF_DIALOG_FILE:
89 case INTF_DIALOG_DISC:
90 openDiscDialog(); break;
92 openNetDialog(); break;
94 case INTF_DIALOG_CAPTURE:
95 openCaptureDialog(); break;
96 case INTF_DIALOG_PLAYLIST:
97 playlistDialog(); break;
98 case INTF_DIALOG_MESSAGES:
99 messagesDialog(); break;
100 case INTF_DIALOG_FILEINFO:
101 mediaInfoDialog(); break;
102 case INTF_DIALOG_PREFS:
103 prefsDialog(); break;
104 case INTF_DIALOG_BOOKMARKS:
105 bookmarksDialog(); break;
106 case INTF_DIALOG_EXTENDED:
107 extendedDialog(); break;
108 /* We might want to make it better with custom functions */
109 case INTF_DIALOG_POPUPMENU:
110 QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0) ); break;
111 case INTF_DIALOG_AUDIOPOPUPMENU:
112 QVLCMenu::AudioPopupMenu( p_intf ); break;
113 case INTF_DIALOG_VIDEOPOPUPMENU:
114 QVLCMenu::VideoPopupMenu( p_intf ); break;
115 case INTF_DIALOG_MISCPOPUPMENU:
116 QVLCMenu::MiscPopupMenu( p_intf ); break;
117 case INTF_DIALOG_INTERACTION:
118 doInteraction( de->p_arg ); break;
119 case INTF_DIALOG_VLM:
121 case INTF_DIALOG_WIZARD:
122 case INTF_DIALOG_UPDATEVLC:
123 case INTF_DIALOG_EXIT:
125 msg_Warn( p_intf, "unimplemented dialog\n" );
130 /****************************************************************************
131 * Individual simple dialogs
132 ****************************************************************************/
133 void DialogsProvider::playlistDialog()
135 PlaylistDialog::getInstance( p_intf )->toggleVisible();
138 void DialogsProvider::prefsDialog()
140 PrefsDialog::getInstance( p_intf )->toggleVisible();
142 void DialogsProvider::extendedDialog()
144 ExtendedDialog::getInstance( p_intf )->toggleVisible();
147 void DialogsProvider::messagesDialog()
149 MessagesDialog::getInstance( p_intf )->toggleVisible();
152 void DialogsProvider::gotoTimeDialog()
154 GotoTimeDialog::getInstance( p_intf )->toggleVisible();
157 void DialogsProvider::vlmDialog()
159 /* FIXME - Implement me */
160 /* VLMDialog::getInstance( p_intf )->toggleVisible(); */
163 void DialogsProvider::helpDialog()
165 HelpDialog::getInstance( p_intf )->toggleVisible();
168 void DialogsProvider::aboutDialog()
170 AboutDialog::getInstance( p_intf )->toggleVisible();
173 void DialogsProvider::mediaInfoDialog()
175 MediaInfoDialog::getInstance( p_intf )->toggleVisible();
178 void DialogsProvider::mediaCodecDialog()
180 MediaInfoDialog::getInstance( p_intf )->showTab( 2 );
183 void DialogsProvider::bookmarksDialog()
185 /* FIXME - Implement me */
186 /* BookmarkDialog::getInstance( p_intf )->toggleVisible(); */
189 /****************************************************************************
190 * All the open/add stuff
191 * Open Dialog first - Simple Open then
192 ****************************************************************************/
194 void DialogsProvider::openDialog( int i_tab )
196 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
198 void DialogsProvider::openDialog()
200 openDialog( OPEN_FILE_TAB );
202 void DialogsProvider::openFileDialog()
204 openDialog( OPEN_FILE_TAB );
206 void DialogsProvider::openDiscDialog()
208 openDialog( OPEN_DISC_TAB );
210 void DialogsProvider::openNetDialog()
212 openDialog( OPEN_NETWORK_TAB );
214 void DialogsProvider::openCaptureDialog()
216 openDialog( OPEN_CAPTURE_TAB );
219 /* Same as the open one, but force the enqueue */
220 void DialogsProvider::PLAppendDialog()
222 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, ENQUEUE)->showTab(0);
225 /* Unimplemmented yet - Usefull ? */
226 void DialogsProvider::MLAppendDialog()
232 * Not used anymore. Let the code until we are sure we don't want it
233 * Two opens make it confusing for the user.
235 QStringList DialogsProvider::showSimpleOpen( QString help,
239 QString fileTypes = "";
240 if( filters & EXT_FILTER_MEDIA ) {
241 ADD_FILTER_MEDIA( fileTypes );
243 if( filters & EXT_FILTER_VIDEO ) {
244 ADD_FILTER_VIDEO( fileTypes );
246 if( filters & EXT_FILTER_AUDIO ) {
247 ADD_FILTER_AUDIO( fileTypes );
249 if( filters & EXT_FILTER_PLAYLIST ) {
250 ADD_FILTER_PLAYLIST( fileTypes );
252 if( filters & EXT_FILTER_SUBTITLE ) {
253 ADD_FILTER_SUBTITLE( fileTypes );
255 ADD_FILTER_ALL( fileTypes );
256 fileTypes.replace(QString(";*"), QString(" *"));
257 return QFileDialog::getOpenFileNames( NULL,
258 help.isNull() ? qfu(I_OP_SEL_FILES ) : help,
259 path.isNull() ? qfu( p_intf->p_libvlc->psz_homedir ) : path,
263 void DialogsProvider::addFromSimple( bool pl, bool go)
265 QStringList files = DialogsProvider::showSimpleOpen();
267 foreach( QString file, files )
269 const char * psz_utf8 = qtu( file );
270 playlist_Add( THEPL, psz_utf8, NULL,
271 go ? ( PLAYLIST_APPEND | ( i ? 0 : PLAYLIST_GO ) |
272 ( i ? PLAYLIST_PREPARSE : 0 ) )
273 : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
275 pl ? VLC_TRUE : VLC_FALSE, VLC_FALSE );
280 void DialogsProvider::simplePLAppendDialog()
282 addFromSimple( true, false );
285 void DialogsProvider::simpleMLAppendDialog()
287 addFromSimple( false, false );
290 void DialogsProvider::simpleOpenDialog()
292 addFromSimple( true, true );
299 * pl helps you to choose from playlist or media library,
300 * go to start or enqueue
302 static void openDirectory( intf_thread_t* p_intf, bool pl, bool go )
304 QString dir = QFileDialog::getExistingDirectory ( 0, qtr("Open directory") );
305 if (!dir.isEmpty()) {
306 input_item_t *p_input = input_ItemNewExt( THEPL, qtu(dir), NULL,
309 playlist_AddInput( THEPL, p_input,
310 go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
311 PLAYLIST_END, pl, VLC_FALSE );
312 input_Read( THEPL, p_input, VLC_FALSE );
316 void DialogsProvider::PLAppendDir()
318 openDirectory( p_intf, true, false );
321 void DialogsProvider::MLAppendDir()
323 openDirectory( p_intf, false , false );
329 void DialogsProvider::openPlaylist()
331 QStringList files = showSimpleOpen( qtr( "Open playlist file" ),
332 EXT_FILTER_PLAYLIST );
333 foreach( QString file, files )
335 playlist_Import( THEPL, qtu(file) );
339 void DialogsProvider::savePlaylist()
341 QFileDialog *qfd = new QFileDialog( NULL,
342 qtr("Choose a filename to save playlist"),
343 qfu( p_intf->p_libvlc->psz_homedir ),
344 qtr("XSPF playlist (*.xspf);; ") +
345 qtr("M3U playlist (*.m3u);; Any (*.*) ") );
346 qfd->setFileMode( QFileDialog::AnyFile );
347 qfd->setAcceptMode( QFileDialog::AcceptSave );
348 qfd->setConfirmOverwrite( true );
350 if( qfd->exec() == QDialog::Accepted )
352 if( qfd->selectedFiles().count() > 0 )
354 static const char psz_xspf[] = "export-xspf",
355 psz_m3u[] = "esport-m3u";
356 const char *psz_module;
358 QString file = qfd->selectedFiles().first();
359 QString filter = qfd->selectedFilter();
361 if( file.contains(".xsp") ||
362 ( filter.contains(".xspf") && !file.contains(".m3u") ) )
364 psz_module = psz_xspf;
365 if( !file.contains( ".xsp" ) )
366 file.append( ".xspf" );
370 psz_module = psz_m3u;
371 if( !file.contains( ".m3u" ) )
372 file.append( ".m3u" );
375 playlist_Export( THEPL, qtu(file), THEPL->p_local_category,
383 /****************************************************************************
385 ****************************************************************************/
388 void DialogsProvider::streamingDialog( QString mrl, bool b_transcode_only )
390 SoutDialog *s = new SoutDialog( p_intf->p_sys->p_mi, p_intf,
392 if( s->exec() == QDialog::Accepted )
394 msg_Err( p_intf, "mrl %s\n", qta( s->getMrl() ) );
396 int i_len = strlen( qtu( s->getMrl() ) ) + 10;
397 char *psz_option = (char*)malloc(i_len);
398 snprintf( psz_option, i_len - 1, "%s", qtu( s->getMrl() ) );
400 playlist_AddExt( THEPL, qtu( mrl ), "Streaming",
401 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
402 -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
407 void DialogsProvider::openThenStreamingDialogs()
409 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_STREAM )
413 void DialogsProvider::openThenTranscodingDialogs()
415 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_SAVE )
419 void DialogsProvider::streamingDialog()
421 OpenDialog *o = new OpenDialog( p_intf->p_sys->p_mi, p_intf, true );
422 if ( o->exec() == QDialog::Accepted )
424 SoutDialog *s = new SoutDialog( p_intf->p_sys->p_mi, p_intf );
425 if( s->exec() == QDialog::Accepted )
427 msg_Err(p_intf, "mrl %s\n", qta(s->mrl));
429 int i_len = strlen( qtu(s->mrl) ) + 10;
430 char *psz_option = (char*)malloc(i_len);
431 snprintf( psz_option, i_len - 1, ":sout=%s", qtu(s->mrl));
433 playlist_AddExt( THEPL, qtu( o->mrl ), "Streaming",
434 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
435 -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
444 /****************************************************************************
445 * Menus / Interaction
446 ****************************************************************************/
448 void DialogsProvider::menuAction( QObject *data )
450 QVLCMenu::DoAction( p_intf, data );
453 void DialogsProvider::menuUpdateAction( QObject *data )
455 MenuFunc * f = qobject_cast<MenuFunc *>(data);
459 void DialogsProvider::SDMenuAction( QString data )
461 char *psz_sd = strdup( qtu( data ) );
462 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
463 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
465 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
469 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
471 InteractionDialog *qdialog;
472 interaction_dialog_t *p_dialog = p_arg->p_dialog;
473 switch( p_dialog->i_action )
476 qdialog = new InteractionDialog( p_intf, p_dialog );
477 p_dialog->p_private = (void*)qdialog;
478 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
481 case INTERACT_UPDATE:
482 qdialog = (InteractionDialog*)(p_dialog->p_private);
487 qdialog = (InteractionDialog*)(p_dialog->p_private);
490 p_dialog->i_status = HIDDEN_DIALOG;
492 case INTERACT_DESTROY:
493 qdialog = (InteractionDialog*)(p_dialog->p_private);
494 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
496 p_dialog->i_status = DESTROYED_DIALOG;
501 void DialogsProvider::podcastConfigureDialog()
503 PodcastConfigurationDialog c( p_intf );
507 void DialogsProvider::switchToSkins()
509 var_SetString( p_intf, "intf-switch", "skins2" );