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_PLAYLIST:
99 playlistDialog(); break;
100 case INTF_DIALOG_MESSAGES:
101 messagesDialog(); break;
102 case INTF_DIALOG_FILEINFO:
103 mediaInfoDialog(); break;
104 case INTF_DIALOG_PREFS:
105 prefsDialog(); break;
106 case INTF_DIALOG_BOOKMARKS:
107 bookmarksDialog(); break;
108 case INTF_DIALOG_EXTENDED:
109 extendedDialog(); break;
110 /* We might want to make it better with custom functions */
111 case INTF_DIALOG_POPUPMENU:
112 QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0) ); break;
113 case INTF_DIALOG_AUDIOPOPUPMENU:
114 QVLCMenu::AudioPopupMenu( p_intf ); break;
115 case INTF_DIALOG_VIDEOPOPUPMENU:
116 QVLCMenu::VideoPopupMenu( p_intf ); break;
117 case INTF_DIALOG_MISCPOPUPMENU:
118 QVLCMenu::MiscPopupMenu( p_intf ); break;
119 case INTF_DIALOG_INTERACTION:
120 doInteraction( de->p_arg ); break;
121 case INTF_DIALOG_VLM:
123 case INTF_DIALOG_WIZARD:
124 case INTF_DIALOG_UPDATEVLC:
125 case INTF_DIALOG_EXIT:
127 msg_Warn( p_intf, "unimplemented dialog\n" );
132 /****************************************************************************
133 * Individual simple dialogs
134 ****************************************************************************/
135 void DialogsProvider::playlistDialog()
137 PlaylistDialog::getInstance( p_intf )->toggleVisible();
140 void DialogsProvider::prefsDialog()
142 PrefsDialog::getInstance( p_intf )->toggleVisible();
144 void DialogsProvider::extendedDialog()
146 ExtendedDialog::getInstance( p_intf )->toggleVisible();
149 void DialogsProvider::messagesDialog()
151 MessagesDialog::getInstance( p_intf )->toggleVisible();
154 void DialogsProvider::gotoTimeDialog()
156 GotoTimeDialog::getInstance( p_intf )->toggleVisible();
159 void DialogsProvider::vlmDialog()
161 VLMDialog::getInstance( p_intf )->toggleVisible();
164 void DialogsProvider::helpDialog()
166 HelpDialog::getInstance( p_intf )->toggleVisible();
169 void DialogsProvider::aboutDialog()
171 AboutDialog::getInstance( p_intf )->toggleVisible();
174 void DialogsProvider::mediaInfoDialog()
176 MediaInfoDialog::getInstance( p_intf )->toggleVisible();
179 void DialogsProvider::mediaCodecDialog()
181 MediaInfoDialog::getInstance( p_intf )->showTab( 2 );
184 void DialogsProvider::bookmarksDialog()
186 /* FIXME - Implement me */
187 /* BookmarkDialog::getInstance( p_intf )->toggleVisible(); */
190 /****************************************************************************
191 * All the open/add stuff
192 * Open Dialog first - Simple Open then
193 ****************************************************************************/
195 void DialogsProvider::openDialog( int i_tab )
197 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
199 void DialogsProvider::openDialog()
201 openDialog( OPEN_FILE_TAB );
203 void DialogsProvider::openFileDialog()
205 openDialog( OPEN_FILE_TAB );
207 void DialogsProvider::openDiscDialog()
209 openDialog( OPEN_DISC_TAB );
211 void DialogsProvider::openNetDialog()
213 openDialog( OPEN_NETWORK_TAB );
215 void DialogsProvider::openCaptureDialog()
217 openDialog( OPEN_CAPTURE_TAB );
220 /* Same as the open one, but force the enqueue */
221 void DialogsProvider::PLAppendDialog()
223 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, ENQUEUE)->showTab(0);
226 /* Unimplemmented yet - Usefull ? */
227 void DialogsProvider::MLAppendDialog()
233 * Not used anymore. Let the code until we are sure we don't want it
234 * Two opens make it confusing for the user.
236 QStringList DialogsProvider::showSimpleOpen( QString help,
240 QString fileTypes = "";
241 if( filters & EXT_FILTER_MEDIA ) {
242 ADD_FILTER_MEDIA( fileTypes );
244 if( filters & EXT_FILTER_VIDEO ) {
245 ADD_FILTER_VIDEO( fileTypes );
247 if( filters & EXT_FILTER_AUDIO ) {
248 ADD_FILTER_AUDIO( fileTypes );
250 if( filters & EXT_FILTER_PLAYLIST ) {
251 ADD_FILTER_PLAYLIST( fileTypes );
253 if( filters & EXT_FILTER_SUBTITLE ) {
254 ADD_FILTER_SUBTITLE( fileTypes );
256 ADD_FILTER_ALL( fileTypes );
257 fileTypes.replace(QString(";*"), QString(" *"));
258 return QFileDialog::getOpenFileNames( NULL,
259 help.isNull() ? qfu(I_OP_SEL_FILES ) : help,
260 path.isNull() ? qfu( p_intf->p_libvlc->psz_homedir ) : path,
264 void DialogsProvider::addFromSimple( bool pl, bool go)
266 QStringList files = DialogsProvider::showSimpleOpen();
268 foreach( QString file, files )
270 const char * psz_utf8 = qtu( file );
271 playlist_Add( THEPL, psz_utf8, NULL,
272 go ? ( PLAYLIST_APPEND | ( i ? 0 : PLAYLIST_GO ) |
273 ( i ? PLAYLIST_PREPARSE : 0 ) )
274 : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
276 pl ? VLC_TRUE : VLC_FALSE, VLC_FALSE );
281 void DialogsProvider::simplePLAppendDialog()
283 addFromSimple( true, false );
286 void DialogsProvider::simpleMLAppendDialog()
288 addFromSimple( false, false );
291 void DialogsProvider::simpleOpenDialog()
293 addFromSimple( true, true );
300 * pl helps you to choose from playlist or media library,
301 * go to start or enqueue
303 static void openDirectory( intf_thread_t* p_intf, bool pl, bool go )
305 QString dir = QFileDialog::getExistingDirectory ( 0, qtr("Open directory") );
306 if (!dir.isEmpty()) {
307 input_item_t *p_input = input_ItemNewExt( THEPL, qtu(dir), NULL,
310 playlist_AddInput( THEPL, p_input,
311 go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
312 PLAYLIST_END, pl, VLC_FALSE );
313 input_Read( THEPL, p_input, VLC_FALSE );
317 void DialogsProvider::PLAppendDir()
319 openDirectory( p_intf, true, false );
322 void DialogsProvider::MLAppendDir()
324 openDirectory( p_intf, false , false );
330 void DialogsProvider::openPlaylist()
332 QStringList files = showSimpleOpen( qtr( "Open playlist file" ),
333 EXT_FILTER_PLAYLIST );
334 foreach( QString file, files )
336 playlist_Import( THEPL, qtu(file) );
340 void DialogsProvider::savePlaylist()
342 QFileDialog *qfd = new QFileDialog( NULL,
343 qtr("Choose a filename to save playlist"),
344 qfu( p_intf->p_libvlc->psz_homedir ),
345 qtr("XSPF playlist (*.xspf);; ") +
346 qtr("M3U playlist (*.m3u);; Any (*.*) ") );
347 qfd->setFileMode( QFileDialog::AnyFile );
348 qfd->setAcceptMode( QFileDialog::AcceptSave );
349 qfd->setConfirmOverwrite( true );
351 if( qfd->exec() == QDialog::Accepted )
353 if( qfd->selectedFiles().count() > 0 )
355 static const char psz_xspf[] = "export-xspf",
356 psz_m3u[] = "esport-m3u";
357 const char *psz_module;
359 QString file = qfd->selectedFiles().first();
360 QString filter = qfd->selectedFilter();
362 if( file.contains(".xsp") ||
363 ( filter.contains(".xspf") && !file.contains(".m3u") ) )
365 psz_module = psz_xspf;
366 if( !file.contains( ".xsp" ) )
367 file.append( ".xspf" );
371 psz_module = psz_m3u;
372 if( !file.contains( ".m3u" ) )
373 file.append( ".m3u" );
376 playlist_Export( THEPL, qtu(file), THEPL->p_local_category,
384 /****************************************************************************
386 ****************************************************************************/
389 void DialogsProvider::streamingDialog( QString mrl, bool b_transcode_only )
391 SoutDialog *s = new SoutDialog( p_intf->p_sys->p_mi, p_intf,
393 if( s->exec() == QDialog::Accepted )
395 msg_Err( p_intf, "mrl %s\n", qta( s->getMrl() ) );
397 int i_len = strlen( qtu( s->getMrl() ) ) + 10;
398 char *psz_option = (char*)malloc(i_len);
399 snprintf( psz_option, i_len - 1, "%s", qtu( s->getMrl() ) );
401 playlist_AddExt( THEPL, qtu( mrl ), "Streaming",
402 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
403 -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
408 void DialogsProvider::openThenStreamingDialogs()
410 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_STREAM )
414 void DialogsProvider::openThenTranscodingDialogs()
416 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_SAVE )
420 void DialogsProvider::streamingDialog()
422 OpenDialog *o = new OpenDialog( p_intf->p_sys->p_mi, p_intf, true );
423 if ( o->exec() == QDialog::Accepted )
425 SoutDialog *s = new SoutDialog( p_intf->p_sys->p_mi, p_intf );
426 if( s->exec() == QDialog::Accepted )
428 msg_Err(p_intf, "mrl %s\n", qta(s->mrl));
430 int i_len = strlen( qtu(s->mrl) ) + 10;
431 char *psz_option = (char*)malloc(i_len);
432 snprintf( psz_option, i_len - 1, ":sout=%s", qtu(s->mrl));
434 playlist_AddExt( THEPL, qtu( o->mrl ), "Streaming",
435 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
436 -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
445 /****************************************************************************
446 * Menus / Interaction
447 ****************************************************************************/
449 void DialogsProvider::menuAction( QObject *data )
451 QVLCMenu::DoAction( p_intf, data );
454 void DialogsProvider::menuUpdateAction( QObject *data )
456 MenuFunc * f = qobject_cast<MenuFunc *>(data);
460 void DialogsProvider::SDMenuAction( QString data )
462 char *psz_sd = strdup( qtu( data ) );
463 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
464 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
466 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
470 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
472 InteractionDialog *qdialog;
473 interaction_dialog_t *p_dialog = p_arg->p_dialog;
474 switch( p_dialog->i_action )
477 qdialog = new InteractionDialog( p_intf, p_dialog );
478 p_dialog->p_private = (void*)qdialog;
479 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
482 case INTERACT_UPDATE:
483 qdialog = (InteractionDialog*)(p_dialog->p_private);
488 qdialog = (InteractionDialog*)(p_dialog->p_private);
491 p_dialog->i_status = HIDDEN_DIALOG;
493 case INTERACT_DESTROY:
494 qdialog = (InteractionDialog*)(p_dialog->p_private);
495 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
497 p_dialog->i_status = DESTROYED_DIALOG;
502 void DialogsProvider::podcastConfigureDialog()
504 PodcastConfigurationDialog c( p_intf );
508 void DialogsProvider::switchToSkins()
510 var_SetString( p_intf, "intf-switch", "skins2" );