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 *****************************************************************************/
29 #include <QApplication>
30 #include <QSignalMapper>
31 #include <QFileDialog>
35 #include "dialogs_provider.hpp"
36 #include "main_interface.hpp"
38 #include <vlc_intf_strings.h>
41 #include "dialogs/playlist.hpp"
42 #include "dialogs/bookmarks.hpp"
43 #include "dialogs/preferences.hpp"
44 #include "dialogs/mediainfo.hpp"
45 #include "dialogs/messages.hpp"
46 #include "dialogs/extended.hpp"
47 #include "dialogs/vlm.hpp"
48 #include "dialogs/sout.hpp"
49 #include "dialogs/open.hpp"
50 #include "dialogs/help.hpp"
51 #include "dialogs/gototime.hpp"
52 #include "dialogs/podcast_configuration.hpp"
54 DialogsProvider* DialogsProvider::instance = NULL;
56 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
57 QObject( NULL ), p_intf( _p_intf )
59 fixed_timer = new QTimer( this );
60 fixed_timer->start( 150 /* milliseconds */ );
62 menusMapper = new QSignalMapper();
63 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
65 menusUpdateMapper = new QSignalMapper();
66 CONNECT( menusUpdateMapper, mapped(QObject *),
67 this, menuUpdateAction( QObject *) );
69 SDMapper = new QSignalMapper();
70 CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
73 DialogsProvider::~DialogsProvider()
75 msg_Dbg( p_intf, "Destroying the Dialog Provider" );
76 PlaylistDialog::killInstance();
77 MediaInfoDialog::killInstance();
78 MessagesDialog::killInstance();
79 ExtendedDialog::killInstance();
80 BookmarksDialog::killInstance();
81 HelpDialog::killInstance();
82 UpdateDialog::killInstance();
87 void DialogsProvider::quit()
89 vlc_object_kill( p_intf );
90 QApplication::closeAllWindows();
94 void DialogsProvider::customEvent( QEvent *event )
96 if( event->type() == DialogEvent_Type )
98 DialogEvent *de = static_cast<DialogEvent*>(event);
99 switch( de->i_dialog )
101 case INTF_DIALOG_FILE_SIMPLE:
102 case INTF_DIALOG_FILE:
104 case INTF_DIALOG_DISC:
105 openDiscDialog(); break;
106 case INTF_DIALOG_NET:
107 openNetDialog(); break;
108 case INTF_DIALOG_SAT:
109 case INTF_DIALOG_CAPTURE:
110 openCaptureDialog(); break;
111 case INTF_DIALOG_DIRECTORY:
112 PLAppendDir(); break;
113 case INTF_DIALOG_PLAYLIST:
114 playlistDialog(); break;
115 case INTF_DIALOG_MESSAGES:
116 messagesDialog(); break;
117 case INTF_DIALOG_FILEINFO:
118 mediaInfoDialog(); break;
119 case INTF_DIALOG_PREFS:
120 prefsDialog(); break;
121 case INTF_DIALOG_BOOKMARKS:
122 bookmarksDialog(); break;
123 case INTF_DIALOG_EXTENDED:
124 extendedDialog(); break;
126 case INTF_DIALOG_VLM:
129 case INTF_DIALOG_INTERACTION:
130 doInteraction( de->p_arg ); break;
131 case INTF_DIALOG_POPUPMENU:
132 QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0) ); break;
133 case INTF_DIALOG_AUDIOPOPUPMENU:
134 QVLCMenu::AudioPopupMenu( p_intf ); break;
135 case INTF_DIALOG_VIDEOPOPUPMENU:
136 QVLCMenu::VideoPopupMenu( p_intf ); break;
137 case INTF_DIALOG_MISCPOPUPMENU:
138 QVLCMenu::MiscPopupMenu( p_intf ); break;
139 case INTF_DIALOG_WIZARD:
140 case INTF_DIALOG_STREAMWIZARD:
141 openThenStreamingDialogs(); break;
143 case INTF_DIALOG_UPDATEVLC:
144 updateDialog(); break;
146 case INTF_DIALOG_EXIT:
149 msg_Warn( p_intf, "unimplemented dialog" );
154 /****************************************************************************
155 * Individual simple dialogs
156 ****************************************************************************/
157 void DialogsProvider::playlistDialog()
159 PlaylistDialog::getInstance( p_intf )->toggleVisible();
162 void DialogsProvider::prefsDialog()
164 PrefsDialog::getInstance( p_intf )->toggleVisible();
167 void DialogsProvider::extendedDialog()
169 ExtendedDialog::getInstance( p_intf )->toggleVisible();
172 void DialogsProvider::messagesDialog()
174 MessagesDialog::getInstance( p_intf )->toggleVisible();
177 void DialogsProvider::gotoTimeDialog()
179 GotoTimeDialog::getInstance( p_intf )->toggleVisible();
183 void DialogsProvider::vlmDialog()
185 VLMDialog::getInstance( p_intf )->toggleVisible();
189 void DialogsProvider::helpDialog()
191 HelpDialog::getInstance( p_intf )->toggleVisible();
195 void DialogsProvider::updateDialog()
197 UpdateDialog::getInstance( p_intf )->toggleVisible();
201 void DialogsProvider::aboutDialog()
203 AboutDialog::getInstance( p_intf )->toggleVisible();
206 void DialogsProvider::mediaInfoDialog()
208 MediaInfoDialog::getInstance( p_intf )->toggleVisible();
211 void DialogsProvider::mediaCodecDialog()
213 MediaInfoDialog::getInstance( p_intf )->showTab( 2 );
216 void DialogsProvider::bookmarksDialog()
218 BookmarksDialog::getInstance( p_intf )->toggleVisible();
221 void DialogsProvider::podcastConfigureDialog()
223 PodcastConfigDialog::getInstance( p_intf )->toggleVisible();
227 /****************************************************************************
228 * All the open/add stuff
229 * Open Dialog first - Simple Open then
230 ****************************************************************************/
232 void DialogsProvider::openDialog( int i_tab )
234 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
236 void DialogsProvider::openDialog()
238 openDialog( OPEN_FILE_TAB );
240 void DialogsProvider::openFileDialog()
242 openDialog( OPEN_FILE_TAB );
244 void DialogsProvider::openDiscDialog()
246 openDialog( OPEN_DISC_TAB );
248 void DialogsProvider::openNetDialog()
250 openDialog( OPEN_NETWORK_TAB );
252 void DialogsProvider::openCaptureDialog()
254 openDialog( OPEN_CAPTURE_TAB );
257 /* Same as the open one, but force the enqueue */
258 void DialogsProvider::PLAppendDialog()
260 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_ENQUEUE)
261 ->showTab( OPEN_FILE_TAB );
264 /* Unimplemmented yet - Usefull ? */
265 void DialogsProvider::MLAppendDialog()
270 * Not used anymore. Let the code until we are sure we don't want it
271 * Two opens make it confusing for the user.
273 QStringList DialogsProvider::showSimpleOpen( QString help,
277 QString fileTypes = "";
278 if( filters & EXT_FILTER_MEDIA ) {
279 ADD_FILTER_MEDIA( fileTypes );
281 if( filters & EXT_FILTER_VIDEO ) {
282 ADD_FILTER_VIDEO( fileTypes );
284 if( filters & EXT_FILTER_AUDIO ) {
285 ADD_FILTER_AUDIO( fileTypes );
287 if( filters & EXT_FILTER_PLAYLIST ) {
288 ADD_FILTER_PLAYLIST( fileTypes );
290 if( filters & EXT_FILTER_SUBTITLE ) {
291 ADD_FILTER_SUBTITLE( fileTypes );
293 ADD_FILTER_ALL( fileTypes );
294 fileTypes.replace(QString(";*"), QString(" *"));
295 return QFileDialog::getOpenFileNames( NULL,
296 help.isNull() ? qfu(I_OP_SEL_FILES ) : help,
297 path.isNull() ? qfu( p_intf->p_sys->psz_filepath ) : path,
303 * pl helps you to choose from playlist or media library,
304 * go to start or enqueue
306 void DialogsProvider::addFromSimple( bool pl, bool go)
308 QStringList files = DialogsProvider::showSimpleOpen();
310 foreach( QString file, files )
312 const char * psz_utf8 = qtu( file );
313 playlist_Add( THEPL, psz_utf8, NULL,
314 go ? ( PLAYLIST_APPEND | ( i ? 0 : PLAYLIST_GO ) |
315 ( i ? PLAYLIST_PREPARSE : 0 ) )
316 : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
318 pl ? VLC_TRUE : VLC_FALSE, VLC_FALSE );
323 void DialogsProvider::simpleOpenDialog()
325 addFromSimple( true, true ); /* Playlist and Go */
328 void DialogsProvider::simplePLAppendDialog()
330 addFromSimple( true, false );
333 void DialogsProvider::simpleMLAppendDialog()
335 addFromSimple( false, false );
341 * pl helps you to choose from playlist or media library,
342 * go to start or enqueue
344 static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
346 QString dir = QFileDialog::getExistingDirectory( 0, qtr(I_OP_OPDIR) );
347 if (!dir.isEmpty()) {
348 input_item_t *p_input = input_ItemNewExt( THEPL,
349 qtu( "directory://" + dir ), NULL,
352 playlist_AddInput( THEPL, p_input,
353 go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
354 PLAYLIST_END, pl, VLC_FALSE );
355 input_Read( THEPL, p_input, VLC_FALSE );
359 void DialogsProvider::PLAppendDir()
361 openDirectory( p_intf, true, false );
364 void DialogsProvider::MLAppendDir()
366 openDirectory( p_intf, false , false );
372 void DialogsProvider::openAPlaylist()
374 QStringList files = showSimpleOpen( qtr( "Open playlist file" ),
375 EXT_FILTER_PLAYLIST );
376 foreach( QString file, files )
378 playlist_Import( THEPL, qtu(file) );
382 void DialogsProvider::saveAPlaylist()
384 QFileDialog *qfd = new QFileDialog( NULL,
385 qtr( "Choose a filename to save playlist" ),
386 qfu( p_intf->p_sys->psz_filepath ),
387 qtr( "XSPF playlist (*.xspf);; " ) +
388 qtr( "M3U playlist (*.m3u);; Any (*.*) " ) );
389 qfd->setFileMode( QFileDialog::AnyFile );
390 qfd->setAcceptMode( QFileDialog::AcceptSave );
391 qfd->setConfirmOverwrite( true );
393 if( qfd->exec() == QDialog::Accepted )
395 if( qfd->selectedFiles().count() > 0 )
397 static const char psz_xspf[] = "export-xspf",
398 psz_m3u[] = "export-m3u";
399 const char *psz_module;
401 QString file = qfd->selectedFiles().first();
402 QString filter = qfd->selectedFilter();
404 if( file.contains( ".xsp" ) ||
405 ( filter.contains( ".xspf" ) && !file.contains( ".m3u" ) ) )
407 psz_module = psz_xspf;
408 if( !file.contains( ".xsp" ) )
409 file.append( ".xspf" );
413 psz_module = psz_m3u;
414 if( !file.contains( ".m3u" ) )
415 file.append( ".m3u" );
418 playlist_Export( THEPL, qtu( file ), THEPL->p_local_category,
426 /****************************************************************************
428 ****************************************************************************/
430 void DialogsProvider::streamingDialog( QWidget *parent, QString mrl,
431 bool b_transcode_only )
433 SoutDialog *s = SoutDialog::getInstance( parent, p_intf, b_transcode_only );
435 if( s->exec() == QDialog::Accepted )
437 msg_Err( p_intf, "Sout mrl %s", qta( s->getMrl() ) );
439 int i_len = strlen( qtu( s->getMrl() ) ) + 10;
440 char *psz_option = (char*)malloc( i_len );
441 snprintf( psz_option, i_len - 1, "%s", qtu( s->getMrl() ) );
443 playlist_AddExt( THEPL, qtu( mrl ), "Streaming",
444 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
445 -1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
449 void DialogsProvider::openThenStreamingDialogs()
451 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_STREAM )
455 void DialogsProvider::openThenTranscodingDialogs()
457 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, OPEN_AND_SAVE )
461 /****************************************************************************
462 * Menus / Interaction
463 ****************************************************************************/
465 void DialogsProvider::menuAction( QObject *data )
467 QVLCMenu::DoAction( p_intf, data );
470 void DialogsProvider::menuUpdateAction( QObject *data )
472 MenuFunc * f = qobject_cast<MenuFunc *>(data);
476 void DialogsProvider::SDMenuAction( QString data )
478 char *psz_sd = strdup( qtu( data ) );
479 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
480 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
482 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
486 void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
488 InteractionDialog *qdialog;
489 interaction_dialog_t *p_dialog = p_arg->p_dialog;
490 switch( p_dialog->i_action )
493 qdialog = new InteractionDialog( p_intf, p_dialog );
494 p_dialog->p_private = (void*)qdialog;
495 if( !(p_dialog->i_status == ANSWERED_DIALOG) )
498 case INTERACT_UPDATE:
499 qdialog = (InteractionDialog*)(p_dialog->p_private);
504 qdialog = (InteractionDialog*)(p_dialog->p_private);
507 p_dialog->i_status = HIDDEN_DIALOG;
509 case INTERACT_DESTROY:
510 qdialog = (InteractionDialog*)(p_dialog->p_private);
511 if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
513 p_dialog->i_status = DESTROYED_DIALOG;
518 void DialogsProvider::switchToSkins()
520 var_SetString( p_intf, "intf-switch", "skins2" );
523 void DialogsProvider::switchToWx()
525 var_SetString( p_intf, "intf-switch", "wxwidgets" );