1 /*****************************************************************************
2 * main_inteface.cpp : Main interface
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 #include <QApplication>
26 #include <QSignalMapper>
27 #include <QFileDialog>
30 #include "dialogs_provider.hpp"
31 #include "main_interface.hpp"
33 #include <vlc_intf_strings.h>
36 #include "dialogs/playlist.hpp"
37 #include "dialogs/preferences.hpp"
38 #include "dialogs/mediainfo.hpp"
39 #include "dialogs/messages.hpp"
40 #include "dialogs/extended.hpp"
41 #include "dialogs/sout.hpp"
42 #include "dialogs/open.hpp"
43 #include "dialogs/help.hpp"
44 #include "dialogs/gototime.hpp"
46 DialogsProvider* DialogsProvider::instance = NULL;
48 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
49 QObject( NULL ), p_intf( _p_intf )
51 fixed_timer = new QTimer( this );
52 fixed_timer->start( 150 /* milliseconds */ );
54 menusMapper = new QSignalMapper();
55 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
57 menusUpdateMapper = new QSignalMapper();
58 CONNECT( menusUpdateMapper, mapped(QObject *),
59 this, menuUpdateAction( QObject *) );
61 SDMapper = new QSignalMapper();
62 CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
65 DialogsProvider::~DialogsProvider()
67 PlaylistDialog::killInstance();
68 MediaInfoDialog::killInstance();
71 void DialogsProvider::quit()
73 p_intf->b_die = VLC_TRUE;
77 void DialogsProvider::customEvent( QEvent *event )
79 if( event->type() == DialogEvent_Type )
81 DialogEvent *de = static_cast<DialogEvent*>(event);
82 switch( de->i_dialog )
84 case INTF_DIALOG_FILE_SIMPLE:
85 case INTF_DIALOG_FILE:
87 case INTF_DIALOG_DISC:
88 openDiscDialog(); break;
90 openNetDialog(); break;
92 case INTF_DIALOG_CAPTURE:
93 openCaptureDialog(); break;
94 case INTF_DIALOG_PLAYLIST:
95 playlistDialog(); break;
96 case INTF_DIALOG_MESSAGES:
97 messagesDialog(); break;
98 case INTF_DIALOG_FILEINFO:
99 mediaInfoDialog(); break;
100 case INTF_DIALOG_PREFS:
101 prefsDialog(); break;
102 case INTF_DIALOG_BOOKMARKS:
103 bookmarksDialog(); break;
104 case INTF_DIALOG_EXTENDED:
105 extendedDialog(); break;
106 /* We might want to make it better with custom functions */
107 case INTF_DIALOG_POPUPMENU:
108 QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0) ); break;
109 case INTF_DIALOG_AUDIOPOPUPMENU:
110 QVLCMenu::AudioPopupMenu( p_intf ); break;
111 case INTF_DIALOG_VIDEOPOPUPMENU:
112 QVLCMenu::VideoPopupMenu( p_intf ); break;
113 case INTF_DIALOG_MISCPOPUPMENU:
114 QVLCMenu::MiscPopupMenu( p_intf ); break;
115 case INTF_DIALOG_INTERACTION:
116 doInteraction( de->p_arg ); break;
117 case INTF_DIALOG_VLM:
118 case INTF_DIALOG_WIZARD:
119 case INTF_DIALOG_UPDATEVLC:
120 case INTF_DIALOG_EXIT:
122 msg_Warn( p_intf, "unimplemented dialog\n" );
127 /****************************************************************************
128 * Individual simple dialogs
129 ****************************************************************************/
130 void DialogsProvider::playlistDialog()
132 PlaylistDialog::getInstance( p_intf )->toggleVisible();
135 void DialogsProvider::prefsDialog()
137 PrefsDialog::getInstance( p_intf )->toggleVisible();
139 void DialogsProvider::extendedDialog()
141 ExtendedDialog::getInstance( p_intf )->toggleVisible();
144 void DialogsProvider::messagesDialog()
146 MessagesDialog::getInstance( p_intf )->toggleVisible();
149 void DialogsProvider::gotoTimeDialog()
151 GotoTimeDialog::getInstance( p_intf )->toggleVisible();
154 void DialogsProvider::helpDialog()
156 HelpDialog::getInstance( p_intf )->toggleVisible();
159 void DialogsProvider::aboutDialog()
161 AboutDialog::getInstance( p_intf )->toggleVisible();
164 void DialogsProvider::mediaInfoDialog()
166 MediaInfoDialog::getInstance( p_intf )->toggleVisible();
169 void DialogsProvider::mediaCodecDialog()
171 MediaInfoDialog::getInstance( p_intf )->showTab( 1 );
174 void DialogsProvider::bookmarksDialog()
178 /****************************************************************************
179 * All the open/add stuff
180 ****************************************************************************/
182 void DialogsProvider::openDialog()
184 openDialog( OPEN_FILE_TAB );
186 void DialogsProvider::openFileDialog()
188 openDialog( OPEN_FILE_TAB );
190 void DialogsProvider::openDiscDialog()
192 openDialog( OPEN_DISC_TAB );
194 void DialogsProvider::openNetDialog()
196 openDialog( OPEN_NETWORK_TAB );
198 void DialogsProvider::openCaptureDialog()
200 openDialog( OPEN_CAPTURE_TAB );
202 void DialogsProvider::openDialog( int i_tab )
204 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
207 void DialogsProvider::PLAppendDialog()
210 void DialogsProvider::MLAppendDialog()
214 /**** Simple open ****/
215 QStringList DialogsProvider::showSimpleOpen( QString help, int filters,
218 QString fileTypes = "";
219 if( filters & EXT_FILTER_MEDIA ) {
220 ADD_FILTER_MEDIA( fileTypes );
222 if( filters & EXT_FILTER_VIDEO ) {
223 ADD_FILTER_VIDEO( fileTypes );
225 if( filters & EXT_FILTER_AUDIO ) {
226 ADD_FILTER_AUDIO( fileTypes );
228 if( filters & EXT_FILTER_PLAYLIST ) {
229 ADD_FILTER_PLAYLIST( fileTypes );
231 if( filters & EXT_FILTER_SUBTITLE ) {
232 ADD_FILTER_SUBTITLE( fileTypes );
234 ADD_FILTER_ALL( fileTypes );
235 fileTypes.replace(QString(";*"), QString(" *"));
236 return QFileDialog::getOpenFileNames( NULL,
237 help.isNull() ? qfu(I_OP_SEL_FILES ) : help,
238 path.isNull() ? qfu( p_intf->p_libvlc->psz_homedir ) : path,
242 void DialogsProvider::addFromSimple( bool pl, bool go)
244 QStringList files = DialogsProvider::showSimpleOpen();
246 foreach( QString file, files )
248 const char * psz_utf8 = qtu( file );
249 playlist_Add( THEPL, psz_utf8, NULL,
250 go ? ( PLAYLIST_APPEND | ( i ? 0 : PLAYLIST_GO ) |
251 ( i ? PLAYLIST_PREPARSE : 0 ) )
252 : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
254 pl ? VLC_TRUE : VLC_FALSE, VLC_FALSE );
259 void DialogsProvider::simplePLAppendDialog()
261 addFromSimple( true, false );
264 void DialogsProvider::simpleMLAppendDialog()
266 addFromSimple( false, false );
269 void DialogsProvider::simpleOpenDialog()
271 addFromSimple( true, true );
274 void DialogsProvider::openPlaylist()
276 QStringList files = showSimpleOpen( qtr( "Open playlist file" ),
277 EXT_FILTER_PLAYLIST );
278 foreach( QString file, files )
280 playlist_Import( THEPL, qtu(file) );
284 void DialogsProvider::savePlaylist()
286 QFileDialog *qfd = new QFileDialog( NULL,
287 qtr("Choose a filename to save playlist"),
288 qfu( p_intf->p_libvlc->psz_homedir ),
289 qtr("XSPF playlist (*.xspf);; ") +
290 qtr("M3U playlist (*.m3u);; Any (*.*) ") );
291 qfd->setFileMode( QFileDialog::AnyFile );
292 qfd->setAcceptMode( QFileDialog::AcceptSave );
293 qfd->setConfirmOverwrite( true );
295 if( qfd->exec() == QDialog::Accepted )
297 if( qfd->selectedFiles().count() > 0 )
299 char *psz_module, *psz_m3u = "export-m3u",
300 *psz_xspf = "export-xspf";
302 QString file = qfd->selectedFiles().first();
303 QString filter = qfd->selectedFilter();
305 if( file.contains(".xsp") ||
306 ( filter.contains(".xspf") && !file.contains(".m3u") ) )
308 psz_module = psz_xspf;
309 if( !file.contains( ".xsp" ) )
310 file.append( ".xspf" );
314 psz_module = psz_m3u;
315 if( !file.contains( ".m3u" ) )
316 file.append( ".m3u" );
319 playlist_Export( THEPL, qtu(file), THEPL->p_local_category,
326 static void openDirectory( intf_thread_t* p_intf, bool pl, bool go )
328 QString dir = QFileDialog::getExistingDirectory ( 0,
329 _("Open directory") );
330 input_item_t *p_input = input_ItemNewExt( THEPL, qtu(dir), NULL,
332 playlist_AddInput( THEPL, p_input,
333 go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
334 PLAYLIST_END, pl, VLC_FALSE );
335 input_Read( THEPL, p_input, VLC_FALSE );
338 void DialogsProvider::PLAppendDir()
340 openDirectory( p_intf, true, false );
343 void DialogsProvider::MLAppendDir()
345 openDirectory( p_intf, false , false );
349 /****************************************************************************
351 ****************************************************************************/
353 void DialogsProvider::streamingDialog( QString mrl, bool b_transcode_only )
355 SoutDialog *s = new SoutDialog( p_intf->p_sys->p_mi, p_intf,
357 if( s->exec() == QDialog::Accepted )
359 msg_Err(p_intf, "mrl %s\n", qta(s->mrl));
361 int i_len = strlen( qtu(s->mrl) ) + 10;
362 char *psz_option = (char*)malloc(i_len);
363 snprintf( psz_option, i_len - 1, ":sout=%s", qtu(s->mrl));
365 playlist_AddExt( THEPL, qtu( mrl ), "Streaming",
366 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
367 -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
372 void DialogsProvider::openThenStreamingDialogs()
374 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_STREAM )
378 void DialogsProvider::openThenTranscodingDialogs()
380 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_SAVE )
384 void DialogsProvider::streamingDialog()
386 OpenDialog *o = new OpenDialog( p_intf->p_sys->p_mi, p_intf, true );
387 if ( o->exec() == QDialog::Accepted )
389 SoutDialog *s = new SoutDialog( p_intf->p_sys->p_mi, p_intf );
390 if( s->exec() == QDialog::Accepted )
392 msg_Err(p_intf, "mrl %s\n", qta(s->mrl));
394 int i_len = strlen( qtu(s->mrl) ) + 10;
395 char *psz_option = (char*)malloc(i_len);
396 snprintf( psz_option, i_len - 1, ":sout=%s", qtu(s->mrl));
398 playlist_AddExt( THEPL, qtu( o->mrl ), "Streaming",
399 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
400 -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
409 /****************************************************************************
410 * Menus / Interaction
411 ****************************************************************************/
413 void DialogsProvider::menuAction( QObject *data )
415 QVLCMenu::DoAction( p_intf, data );
418 void DialogsProvider::menuUpdateAction( QObject *data )
420 MenuFunc * f = qobject_cast<MenuFunc *>(data);
424 void DialogsProvider::SDMenuAction( QString data )
426 char *psz_sd = strdup( qtu( data ) );
427 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
428 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
430 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
436 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
438 InteractionDialog *qdialog;
439 interaction_dialog_t *p_dialog = p_arg->p_dialog;
440 switch( p_dialog->i_action )
443 qdialog = new InteractionDialog( p_intf, p_dialog );
444 p_dialog->p_private = (void*)qdialog;
445 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
448 case INTERACT_UPDATE:
449 qdialog = (InteractionDialog*)(p_dialog->p_private);
454 qdialog = (InteractionDialog*)(p_dialog->p_private);
457 p_dialog->i_status = HIDDEN_DIALOG;
459 case INTERACT_DESTROY:
460 qdialog = (InteractionDialog*)(p_dialog->p_private);
461 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
463 p_dialog->i_status = DESTROYED_DIALOG;
468 void DialogsProvider::switchToSkins()
470 var_SetString( p_intf, "intf-switch", "skins2" );